Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TGLSelectRecord.cxx
Go to the documentation of this file.
1 // @(#)root/gl:$Id$
2 // Author: Matevz Tadel, Jun 2007
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #include "TGLSelectRecord.h"
13 #include <TObject.h>
14 
15 #include <string.h>
16 
17 /** \class TGLSelectRecordBase
18 \ingroup opengl TGLSelectRecordBase
19 Base class for select records.
20 Supports initialization from a raw GL record (UInt_t*) and
21 copies the name-data into internal array.
22 */
23 
24 ClassImp(TGLSelectRecordBase);
25 
26 ////////////////////////////////////////////////////////////////////////////////
27 /// Default constructor.
28 
29 TGLSelectRecordBase::TGLSelectRecordBase() :
30  fN (0),
31  fItems (0),
32  fMinZ (0),
33  fMaxZ (0),
34  fPos (0)
35 {
36 }
37 
38 ////////////////////////////////////////////////////////////////////////////////
39 /// Constructor from raw GL-select record.
40 
41 TGLSelectRecordBase::TGLSelectRecordBase(UInt_t* data) :
42  fN (data[0]),
43  fItems (0),
44  fMinZ ((Float_t)data[1] / (Float_t)0x7fffffff),
45  fMaxZ ((Float_t)data[2] / (Float_t)0x7fffffff),
46  fPos (0)
47 {
48  CopyItems(&data[3]);
49 }
50 
51 ////////////////////////////////////////////////////////////////////////////////
52 /// Copy constructor.
53 
54 TGLSelectRecordBase::TGLSelectRecordBase(const TGLSelectRecordBase& rec) :
55  fN (rec.fN),
56  fItems (0),
57  fMinZ (rec.fMinZ),
58  fMaxZ (rec.fMaxZ),
59  fPos (rec.fPos)
60 {
61  CopyItems(rec.fItems);
62 }
63 
64 ////////////////////////////////////////////////////////////////////////////////
65 /// Destructor.
66 
67 TGLSelectRecordBase::~TGLSelectRecordBase()
68 {
69  delete [] fItems;
70 }
71 
72 ////////////////////////////////////////////////////////////////////////////////
73 /// Copy operator.
74 
75 TGLSelectRecordBase& TGLSelectRecordBase::operator=(const TGLSelectRecordBase& rec)
76 {
77  if (this != &rec)
78  {
79  fN = rec.fN;
80  fMinZ = rec.fMinZ;
81  fMaxZ = rec.fMaxZ;
82  fPos = rec.fPos;
83  CopyItems(rec.fItems);
84  }
85  return *this;
86 }
87 
88 ////////////////////////////////////////////////////////////////////////////////
89 /// Copy data from names. fN must already be set.
90 
91 void TGLSelectRecordBase::CopyItems(UInt_t* items)
92 {
93  delete [] fItems;
94  if (fN > 0) {
95  fItems = new UInt_t[fN];
96  memcpy(fItems, items, fN*sizeof(UInt_t));
97  } else {
98  fItems = 0;
99  }
100 }
101 
102 ////////////////////////////////////////////////////////////////////////////////
103 /// Setup the record from raw buffer.
104 
105 void TGLSelectRecordBase::SetRawOnly(UInt_t* data)
106 {
107  fN = data[0];
108  fMinZ = (Float_t)data[1] / (Float_t)0x7fffffff;
109  fMaxZ = (Float_t)data[2] / (Float_t)0x7fffffff;
110  CopyItems(&data[3]);
111 }
112 
113 ////////////////////////////////////////////////////////////////////////////////
114 /// Setup the record from raw buffer.
115 
116 void TGLSelectRecordBase::Set(UInt_t* data)
117 {
118  fN = data[0];
119  fMinZ = (Float_t)data[1] / (Float_t)0x7fffffff;
120  fMaxZ = (Float_t)data[2] / (Float_t)0x7fffffff;
121  fPos = 0;
122  CopyItems(&data[3]);
123 }
124 
125 ////////////////////////////////////////////////////////////////////////////////
126 /// Reinitialise all data to null values.
127 
128 void TGLSelectRecordBase::Reset()
129 {
130  delete [] fItems;
131  fN = 0;
132  fItems = 0;
133  fMinZ = 0;
134  fMaxZ = 0;
135  fPos = 0;
136 }
137 
138 
139 /** \class TGLSelectRecord
140 \ingroup opengl
141 Standard selection record including information about containing
142 scene and details ob out selected object (TGLPhysicalShape*,
143 TObject* or simply a void* for foreign scenes).
144 */
145 
146 ClassImp(TGLSelectRecord);
147 
148 ////////////////////////////////////////////////////////////////////////////////
149 /// Default constructor.
150 
151 TGLSelectRecord::TGLSelectRecord() :
152  TGLSelectRecordBase(),
153  fTransparent (kFALSE),
154  fSceneInfo (0),
155  fPhysShape (0),
156  fLogShape (0),
157  fObject (0),
158  fSpecific (0),
159  fMultiple (kFALSE),
160  fHighlight (kFALSE),
161  fSecSelRes (kNone)
162 {
163 }
164 
165 ////////////////////////////////////////////////////////////////////////////////
166 /// Constructor from raw GL-select record.
167 
168 TGLSelectRecord::TGLSelectRecord(UInt_t* data) :
169  TGLSelectRecordBase(data),
170  fTransparent (kFALSE),
171  fSceneInfo (0),
172  fPhysShape (0),
173  fLogShape (0),
174  fObject (0),
175  fSpecific (0),
176  fMultiple (kFALSE),
177  fHighlight (kFALSE),
178  fSecSelRes (kNone)
179 {
180 }
181 
182 ////////////////////////////////////////////////////////////////////////////////
183 /// Copy constructor.
184 
185 TGLSelectRecord::TGLSelectRecord(const TGLSelectRecord& rec) :
186  TGLSelectRecordBase(rec),
187  fTransparent (rec.fTransparent),
188  fSceneInfo (rec.fSceneInfo),
189  fPhysShape (rec.fPhysShape),
190  fLogShape (rec.fLogShape),
191  fObject (rec.fObject),
192  fSpecific (rec.fSpecific),
193  fMultiple (rec.fMultiple),
194  fHighlight (rec.fHighlight),
195  fSecSelRes (kNone)
196 {
197 }
198 
199 ////////////////////////////////////////////////////////////////////////////////
200 /// Destructor.
201 
202 TGLSelectRecord::~TGLSelectRecord()
203 {
204 }
205 
206 ////////////////////////////////////////////////////////////////////////////////
207 /// Copy operator.
208 
209 TGLSelectRecord& TGLSelectRecord::operator=(const TGLSelectRecord& rec)
210 {
211  if (this != &rec)
212  {
213  TGLSelectRecordBase::operator=(rec);
214  fTransparent = rec.fTransparent;
215  fSceneInfo = rec.fSceneInfo;
216  fPhysShape = rec.fPhysShape;
217  fLogShape = rec.fLogShape;
218  fObject = rec.fObject;
219  fSpecific = rec.fSpecific;
220  fMultiple = rec.fMultiple;
221  fHighlight = rec.fHighlight;
222  fSecSelRes = rec.fSecSelRes;
223  }
224  return *this;
225 }
226 
227 ////////////////////////////////////////////////////////////////////////////////
228 /// Setup the record from raw buffer.
229 /// Non-core members are reset.
230 
231 void TGLSelectRecord::Set(UInt_t* data)
232 {
233  TGLSelectRecordBase::Set(data);
234  fTransparent = kFALSE;
235  fSceneInfo = 0;
236  fPhysShape = 0;
237  fLogShape = 0;
238  fObject = 0;
239  fSpecific = 0;
240  fMultiple = kFALSE;
241  fHighlight = kFALSE;
242  fSecSelRes = kNone;
243 }
244 
245 ////////////////////////////////////////////////////////////////////////////////
246 /// Reinitialise all data to null values.
247 
248 void TGLSelectRecord::Reset()
249 {
250  TGLSelectRecordBase::Reset();
251  fTransparent = kFALSE;
252  fSceneInfo = 0;
253  fPhysShape = 0;
254  fLogShape = 0;
255  fObject = 0;
256  fSpecific = 0;
257  fMultiple = kFALSE;
258  fHighlight = kFALSE;
259  fSecSelRes = kNone;
260 }
261 
262 ////////////////////////////////////////////////////////////////////////////////
263 /// Print contents of the select record to stdout.
264 
265 void TGLSelectRecord::Print()
266 {
267  printf("SelectRecord N=%d, miZ=%.4f, maxZ=%.4f\n"
268  " sceneinfo=%p, pshp=%p, transp=%d, mult=%d, hilite=%d\n"
269  " tobj=%p (name='%s'), spec=%p\n",
270  fN, fMinZ, fMaxZ,
271  fSceneInfo, fPhysShape, fTransparent, fMultiple, fHighlight,
272  fObject, fObject ? fObject->GetName() : "",
273  fSpecific);
274 }
275 
276 ////////////////////////////////////////////////////////////////////////////////
277 /// Check if the records imply the same selection result, that is,
278 /// their secondary members are all equal.
279 
280 Bool_t TGLSelectRecord::AreSameSelectionWise(const TGLSelectRecord& r1,
281  const TGLSelectRecord& r2)
282 {
283  return r1.fSceneInfo == r2.fSceneInfo && r1.fPhysShape == r2.fPhysShape &&
284  r1.fObject == r2.fObject && r1.fSpecific == r2.fSpecific;
285 }
286 
287 
288 /** \class TGLOvlSelectRecord
289 \ingroup opengl
290 Selection record for overlay objects.
291 */
292 
293 ClassImp(TGLOvlSelectRecord);
294 
295 ////////////////////////////////////////////////////////////////////////////////
296 /// Default constructor.
297 
298 TGLOvlSelectRecord::TGLOvlSelectRecord() :
299  TGLSelectRecordBase(),
300  fOvlElement (0)
301 {
302 }
303 
304 ////////////////////////////////////////////////////////////////////////////////
305 /// Constructor from raw GL-select record.
306 
307 TGLOvlSelectRecord::TGLOvlSelectRecord(UInt_t* data) :
308  TGLSelectRecordBase(data),
309  fOvlElement (0)
310 {
311 }
312 
313 ////////////////////////////////////////////////////////////////////////////////
314 /// Copy constructor.
315 
316 TGLOvlSelectRecord::TGLOvlSelectRecord(const TGLOvlSelectRecord& rec) :
317  TGLSelectRecordBase(rec),
318  fOvlElement (rec.fOvlElement)
319 {
320 }
321 
322 ////////////////////////////////////////////////////////////////////////////////
323 /// Destructor.
324 
325 TGLOvlSelectRecord::~TGLOvlSelectRecord()
326 {
327 }
328 
329 ////////////////////////////////////////////////////////////////////////////////
330 /// Copy operator.
331 
332 TGLOvlSelectRecord& TGLOvlSelectRecord::operator=(const TGLOvlSelectRecord& rec)
333 {
334  if (this != &rec)
335  {
336  TGLSelectRecordBase::operator=(rec);
337  fOvlElement = rec.fOvlElement;
338  }
339  return *this;
340 }
341 
342 ////////////////////////////////////////////////////////////////////////////////
343 /// Setup the record from raw buffer.
344 /// Non-core members are reset.
345 
346 void TGLOvlSelectRecord::Set(UInt_t* data)
347 {
348  TGLSelectRecordBase::Set(data);
349  fOvlElement = 0;
350 }
351 
352 ////////////////////////////////////////////////////////////////////////////////
353 /// Reinitialise all data to null values.
354 
355 void TGLOvlSelectRecord::Reset()
356 {
357  TGLSelectRecordBase::Reset();
358  fOvlElement = 0;
359 }
360