Logo ROOT   master
Reference Guide
TStructNode.cxx
Go to the documentation of this file.
1 // @(#)root/gviz3d:$Id$
2 // Author: Tomasz Sosnicki 18/09/09
3 
4 /************************************************************************
5 * Copyright (C) 1995-2009, 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 "TStructNode.h"
13 #include <TList.h>
14 #include <TGeoManager.h>
15 
17 
18 //________________________________________________________________________
19 //////////////////////////////////////////////////////////////////////////
20 //
21 // TStructNode - class which represent a node. Node has all information
22 // about some pointer. It keeps information such as name of object, type,
23 // size of pointers class, size of node and daughter nodes, number of child
24 // nodes. It is also used to store information needed to draw TGeoVolume.
25 // It is for example x, y and z coordinates.
26 // Condition fVisible tells us that node is visible and should be drawn.
27 // fCollapsed tells us that we can see daughter nodes.
28 //
29 //////////////////////////////////////////////////////////////////////////
30 
32 
33 ////////////////////////////////////////////////////////////////////////////////
34 /// Constructs node with name "name" of class "typeName" and given parent "parent" which represents pointer "pointer".
35 /// Size of node is set to "size" and type is set to "type"
36 
37 TStructNode::TStructNode(TString name, TString typeName, void* pointer, TStructNode* parent, ULong_t size, ENodeType type)
38 {
39  fName = name;
40  fTypeName = typeName;
41  fTotalSize = fSize = size;
42  fMembers = new TList();
44  fLevel = 1;
45  fX = fY = fWidth = fHeight = 0;
46  fParent = parent;
47  if (parent) {
48  fLevel = parent->GetLevel()+1;
49  parent->fMembers->Add(this);
50  }
51 
52  fNodeType = type;
53  fPointer = pointer;
54  fCollapsed = false;
55  fVisible = false;
56  fMaxLevel = 3;
57  fMaxObjects = 100;
58 }
59 
60 ////////////////////////////////////////////////////////////////////////////////
61 /// Destructs list of nodes
62 
64 {
65  delete fMembers;
66 }
67 
68 ////////////////////////////////////////////////////////////////////////////////
69 /// Overrided method. Compare to objects of TStructNode class.
70 
72 {
73  TStructNode* node = (TStructNode*)obj;
74 
75  if (GetVolume() < node->GetVolume()) {
76  return -1;
77  }
78  if(GetVolume() > node->GetVolume()) {
79  return 1;
80  }
81 
82  if (this > node) {
83  return 1;
84  }
85  if (this < node) {
86  return -1;
87  }
88 
89  return 0;
90 }
91 
92 ////////////////////////////////////////////////////////////////////////////////
93 /// Returns number of all members in node
94 
96 {
97  return fAllMembersCount;
98 }
99 
100 ////////////////////////////////////////////////////////////////////////////////
101 /// Returns center of outlining box on x-axis
102 
104 {
105  return (fX + fWidth /2);
106 }
107 
108 ////////////////////////////////////////////////////////////////////////////////
109 /// Returns height of outlining box
110 
112 {
113  return fHeight;
114 }
115 
116 ////////////////////////////////////////////////////////////////////////////////
117 /// Returns actual level of node
118 
120 {
121  return fLevel;
122 }
123 
124 ////////////////////////////////////////////////////////////////////////////////
125 /// Returns name of object
126 
127 const char* TStructNode::GetName() const
128 {
129  return fName.Data();
130 }
131 
132 ////////////////////////////////////////////////////////////////////////////////
133 /// Returns type of node
134 
136 {
137  return fNodeType;
138 }
139 
140 ////////////////////////////////////////////////////////////////////////////////
141 /// Returns maximum number of leves displayed when the node is top node on scene
142 
144 {
145  return fMaxLevel;
146 }
147 
148 ////////////////////////////////////////////////////////////////////////////////
149 /// Returns maximum number of objects displayed when the node is top node on scene
150 
152 {
153  return fMaxObjects;
154 }
155 
156 ////////////////////////////////////////////////////////////////////////////////
157 /// Returns list with pointers to daughter nodes.
158 
160 {
161  return fMembers;
162 }
163 
164 ////////////////////////////////////////////////////////////////////////////////
165 /// Returns numbers of members of node
166 
168 {
169  return fMembersCount;
170 }
171 
172 ////////////////////////////////////////////////////////////////////////////////
173 /// Returns center of outlining box on y-axis
174 
176 {
177  return (fY + fHeight/2);
178 }
179 
180 ////////////////////////////////////////////////////////////////////////////////
181 /// Returns pointer to parent node
182 
184 {
185  return fParent;
186 }
187 
188 ////////////////////////////////////////////////////////////////////////////////
189 /// Returns main pointer
190 
192 {
193  return fPointer;
194 }
195 
196 ////////////////////////////////////////////////////////////////////////////////
197 /// Returns relative numbers of members. If node is collapsed, then method returns number of all members,
198 /// it's node and its daughters, otherwise it returns number of members of node
199 
201 {
202  if (fCollapsed) {
203  return fAllMembersCount;
204  }
205  return fMembersCount;
206 }
207 
208 ////////////////////////////////////////////////////////////////////////////////
209 /// Returns relative size of node. If node is collapsed, then function returns size of node and dauthers,
210 /// otherwise returns size of node only.
211 
213 {
214  if (fCollapsed) {
215  return fTotalSize;
216  }
217  return fSize;
218 }
219 
220 ////////////////////////////////////////////////////////////////////////////////
221 /// Returns size or number of members. If ScaleBy is set to kMembers and node is collapsed, then it
222 /// returns all number of members. If node isn't collapsed it returns number of members.
223 /// If Scaleby is set to kSize and node is collapsed, then it returns total size of node and daughters,
224 /// else it returns size of node, otherwise it returns 0.
225 
227 {
228  if (fgScalBy == kMembers) {
229  if (fCollapsed) {
230  return GetAllMembersCount();
231  } else {
232  return GetMembersCount();
233  }
234  } else if (fgScalBy == kSize) {
235  if (fCollapsed) {
236  return GetTotalSize();
237  } else {
238  return GetSize();
239  }
240  } else {
241  return 0;
242  }
243 }
244 
245 ////////////////////////////////////////////////////////////////////////////////
246 /// Returns ratio - relative volume to area taken by utlining box.
247 
249 {
250  return ((Float_t)(GetRelativeVolume())/(fWidth*fHeight));
251 }
252 
253 ////////////////////////////////////////////////////////////////////////////////
254 /// Returns size of node
255 
257 {
258  return fSize;
259 }
260 
261 ////////////////////////////////////////////////////////////////////////////////
262 /// Returns total size of allocated memory in bytes
263 
265 {
266  return fTotalSize;
267 }
268 
269 ////////////////////////////////////////////////////////////////////////////////
270 /// Returns name of class
271 
273 {
274  return fTypeName;
275 }
276 
277 ////////////////////////////////////////////////////////////////////////////////
278 /// Returns size or number of members. If ScaleBy is set to kMembers it returns all number of members.
279 /// If Scaleby is set to kSize then it returns total size of node and daughters, otherwise it returns 0.
280 
282 {
283  if (fgScalBy == kMembers) {
284  return GetAllMembersCount();
285  } else if (fgScalBy == kSize) {
286  return GetTotalSize();
287  } else {
288  return 0;
289  }
290 
291 }
292 
293 ////////////////////////////////////////////////////////////////////////////////
294 /// Returns ratio - volme of node to area taken by outlining box
295 
297 {
298  return ((Float_t)(GetVolume())/(fWidth*fHeight));
299 }
300 
301 ////////////////////////////////////////////////////////////////////////////////
302 /// Returns width of outlining box
303 
305 {
306  return fWidth;
307 }
308 
309 ////////////////////////////////////////////////////////////////////////////////
310 /// Returns X coordinate
311 
313 {
314  return fX;
315 }
316 
317 ////////////////////////////////////////////////////////////////////////////////
318 /// Returns Y coordinate
319 
321 {
322  return fY;
323 }
324 
325 ////////////////////////////////////////////////////////////////////////////////
326 /// Returns true if node is colllapsed
327 
329 {
330  return fCollapsed;
331 }
332 
333 ////////////////////////////////////////////////////////////////////////////////
334 /// Returns true, because we have overrided method Compare
335 
337 {
338  return kTRUE;
339 }
340 
341 ////////////////////////////////////////////////////////////////////////////////
342 /// Returns true if node is visible
343 
345 {
346  return fVisible;
347 }
348 
349 ////////////////////////////////////////////////////////////////////////////////
350 /// Sets numbers of all members to "number"
351 
353 {
354  fAllMembersCount = number;
355 }
356 
357 ////////////////////////////////////////////////////////////////////////////////
358 /// Sets collapsing of node to "collapse"
359 
361 {
362  fCollapsed = collapse;
363 }
364 
365 ////////////////////////////////////////////////////////////////////////////////
366 /// Sets width of outlining box to "w"
367 
369 {
370  fHeight = val;
371 }
372 
373 ////////////////////////////////////////////////////////////////////////////////
374 /// Sets maximum number of leves displayed when the node is top node on scene
375 
377 {
378  fMaxLevel = level;
379 }
380 
381 ////////////////////////////////////////////////////////////////////////////////
382 /// Sets maximum number of objects displayed when the node is top node on scene
383 
385 {
386  fMaxObjects = max;
387 }
388 
389 ////////////////////////////////////////////////////////////////////////////////
390 /// Sets list of dauther nodes to "list"
391 
393 {
394  fMembers = list;
395 }
396 
397 ////////////////////////////////////////////////////////////////////////////////
398 /// Sets number of members to "number"
399 
401 {
402  fMembersCount = number;
403 }
404 
405 ////////////////////////////////////////////////////////////////////////////////
406 /// Sets type of node to "type"
407 
409 {
410  fNodeType = type;
411 }
412 
413 ////////////////////////////////////////////////////////////////////////////////
414 /// Sets main pointer to "pointer"
415 
416 void TStructNode::SetPointer(void* pointer)
417 {
418  fPointer = pointer;
419 }
420 
421 ////////////////////////////////////////////////////////////////////////////////
422 /// Sets scaling by to "type"
423 
425 {
426  fgScalBy = type;
427 }
428 
429 ////////////////////////////////////////////////////////////////////////////////
430 /// Sets size of node to "size"
431 
433 {
434  fSize = size;
435 }
436 
437 ////////////////////////////////////////////////////////////////////////////////
438 /// Sets total size of allocated memory in bytes to value "size"
439 
441 {
442  fTotalSize = size;
443 }
444 
445 ////////////////////////////////////////////////////////////////////////////////
446 /// Sets visibility of node to "visible"
447 
448 void TStructNode::SetVisible(bool visible)
449 {
450  fVisible = visible;
451 }
452 
453 ////////////////////////////////////////////////////////////////////////////////
454 /// Sets width of outlining box to "w"
455 
457 {
458  fWidth = w;
459 }
460 
461 ////////////////////////////////////////////////////////////////////////////////
462 /// Sets X coordinate to "x"
463 
465 {
466  fX = x;
467 }
468 
469 ////////////////////////////////////////////////////////////////////////////////
470 /// Sets Y coordinate to "y"
471 
473 {
474  fY = y;
475 }
Float_t GetWidth() const
Returns width of outlining box.
void SetNodeType(ENodeType type)
Sets type of node to "type".
float Float_t
Definition: RtypesCore.h:53
Float_t GetCenter() const
Returns center of outlining box on x-axis.
Bool_t fVisible
Definition: TStructNode.h:48
~TStructNode()
Destructs list of nodes.
Definition: TStructNode.cxx:63
ULong_t GetVolume() const
Returns size or number of members.
void SetY(Float_t y)
Sets Y coordinate to "y".
Float_t GetRelativeVolumeRatio()
Returns ratio - relative volume to area taken by utlining box.
ULong_t fMembersCount
Definition: TStructNode.h:44
ULong_t GetRelativeVolume() const
Returns size or number of members.
UInt_t GetMaxLevel() const
Returns maximum number of leves displayed when the node is top node on scene.
Float_t fHeight
Definition: TStructNode.h:53
Basic string class.
Definition: TString.h:131
void SetMembersCount(ULong_t count)
Sets number of members to "number".
ULong_t GetSize() const
Returns size of node.
UInt_t GetMaxObjects() const
Returns maximum number of objects displayed when the node is top node on scene.
ULong_t GetRelativeMembersCount() const
Returns relative numbers of members.
TList * fMembers
Definition: TStructNode.h:49
TList * GetMembers() const
Returns list with pointers to daughter nodes.
void SetAllMembersCount(ULong_t count)
Sets numbers of all members to "number".
void SetSize(ULong_t size)
Sets size of node to "size".
Float_t GetX() const
Returns X coordinate.
void SetMembers(TList *list)
Sets list of dauther nodes to "list".
void * GetPointer() const
Returns main pointer.
Double_t x[n]
Definition: legend1.C:17
Float_t fY
Definition: TStructNode.h:51
TStructNode * fParent
Definition: TStructNode.h:42
void SetWidth(Float_t w)
Sets width of outlining box to "w".
ULong_t fAllMembersCount
Definition: TStructNode.h:45
Float_t GetMiddle() const
Returns center of outlining box on y-axis.
A doubly linked list.
Definition: TList.h:44
bool IsVisible() const
Returns true if node is visible.
void SetPointer(void *pointer)
Sets main pointer to "pointer".
TString GetTypeName() const
Returns name of class.
const char * GetName() const
Returns name of object.
void SetCollapsed(Bool_t collapsed)
Sets collapsing of node to "collapse".
static EScalingType fgScalBy
Definition: TStructNode.h:37
UInt_t fMaxObjects
Definition: TStructNode.h:56
Float_t fX
Definition: TStructNode.h:50
ENodeType GetNodeType() const
Returns type of node.
TString fName
Definition: TStructNode.h:38
void SetMaxObjects(UInt_t max)
Sets maximum number of objects displayed when the node is top node on scene.
void SetVisible(bool visible)
Sets visibility of node to "visible".
ENodeType fNodeType
Definition: TStructNode.h:54
unsigned int UInt_t
Definition: RtypesCore.h:42
Float_t GetY() const
Returns Y coordinate.
void SetHeight(Float_t h)
Sets width of outlining box to "w".
UInt_t GetLevel() const
Returns actual level of node.
ULong_t GetTotalSize() const
Returns total size of allocated memory in bytes.
ENodeType
Definition: TStructNode.h:18
TString fTypeName
Definition: TStructNode.h:39
virtual Int_t Compare(const TObject *obj) const
Overrided method. Compare to objects of TStructNode class.
Definition: TStructNode.cxx:71
Float_t GetHeight() const
Returns height of outlining box.
static void SetScaleBy(EScalingType type)
Sets scaling by to "type".
#define ClassImp(name)
Definition: Rtypes.h:365
virtual Bool_t IsSortable() const
Returns true, because we have overrided method Compare.
ULong_t fSize
Definition: TStructNode.h:40
void * fPointer
Definition: TStructNode.h:46
EScalingType
Definition: TStructNode.h:25
Float_t fWidth
Definition: TStructNode.h:52
int type
Definition: TGX11.cxx:120
void SetTotalSize(ULong_t size)
Sets total size of allocated memory in bytes to value "size".
unsigned long ULong_t
Definition: RtypesCore.h:51
Double_t y[n]
Definition: legend1.C:17
UInt_t fMaxLevel
Definition: TStructNode.h:55
TStructNode * GetParent() const
Returns pointer to parent node.
Mother of all ROOT objects.
Definition: TObject.h:37
void SetMaxLevel(UInt_t level)
Sets maximum number of leves displayed when the node is top node on scene.
virtual void Add(TObject *obj)
Definition: TList.h:87
TStructNode(TString name, TString typeName, void *pointer, TStructNode *parent, ULong_t size, ENodeType type)
Constructs node with name "name" of class "typeName" and given parent "parent" which represents point...
Definition: TStructNode.cxx:37
ULong_t GetAllMembersCount() const
Returns number of all members in node.
Definition: TStructNode.cxx:95
Float_t GetVolumeRatio()
Returns ratio - volme of node to area taken by outlining box.
UInt_t fLevel
Definition: TStructNode.h:43
void SetX(Float_t x)
Sets X coordinate to "x".
Bool_t IsCollapsed() const
Returns true if node is colllapsed.
const Bool_t kTRUE
Definition: RtypesCore.h:87
ULong_t GetMembersCount() const
Returns numbers of members of node.
char name[80]
Definition: TGX11.cxx:109
ULong_t GetRelativeSize() const
Returns relative size of node.
Bool_t fCollapsed
Definition: TStructNode.h:47
ULong_t fTotalSize
Definition: TStructNode.h:41
const char * Data() const
Definition: TString.h:364