ROOT  6.06/09
Reference Guide
TNode.cxx
Go to the documentation of this file.
1 // @(#)root/g3d:$Id$
2 // Author: Rene Brun 14/09/95
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, 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 "Riostream.h"
13 #include "TROOT.h"
14 #include "TClass.h"
15 #include "TVirtualPad.h"
16 #include "TView.h"
17 #include "TGeometry.h"
18 #include "TRotMatrix.h"
19 #include "TShape.h"
20 #include "TNode.h"
21 #include "TBrowser.h"
22 #include "X3DBuffer.h"
23 #include "TVirtualViewer3D.h"
24 #include "TBuffer3D.h"
25 
26 #if 0
27 const Int_t kMAXLEVELS = 20;
28 const Int_t kVectorSize = 3;
29 const Int_t kMatrixSize = kVectorSize*kVectorSize;
30 #endif
31 
34 static Int_t gGeomLevel = 0;
35 
37 
39 
40 /** \class TNode
41 \ingroup g3d
42 TNode description
43 
44 A TNode object is used to build the geometry hierarchy (see TGeometry).
45 A node may contain other nodes.
46 
47 A geometry node has attributes:
48 
49  - name and title
50  - pointer to the referenced shape (see TShape).
51  - x,y,z offset with respect to the mother node.
52  - pointer to the rotation matrix (see TRotMatrix).
53 
54 A node can be drawn.
55 */
56 
57 ////////////////////////////////////////////////////////////////////////////////
58 /// Node default constructor.
59 
60 TNode::TNode()
61 {
62  fMatrix = 0;
63  fParent = 0;
64  fShape = 0;
65  fNodes = 0;
66  fVisibility = 1;
67  fX = fY = fZ = 0;
68 }
69 
70 ////////////////////////////////////////////////////////////////////////////////
71 /// Node normal constructor.
72 ///
73 /// - name is the name of the node
74 /// - title is title
75 /// - shapename is the name of the referenced shape
76 /// - x,y,z are the offsets of the volume with respect to his mother
77 /// - matrixname is the name of the rotation matrix
78 ///
79 /// This new node is added into the list of sons of the current node
80 
81 TNode::TNode(const char *name, const char *title, const char *shapename, Double_t x, Double_t y, Double_t z, const char *matrixname, Option_t *option)
82  :TNamed(name,title),TAttLine(), TAttFill()
83 {
84 #ifdef WIN32
85  // The color "1" - default produces a very bad 3D image with OpenGL
86  Color_t lcolor = 16;
87  SetLineColor(lcolor);
88 #endif
89  static Int_t counter = 0;
90  counter++;
91  fX = x;
92  fY = y;
93  fZ = z;
94  fNodes = 0;
95  fShape = gGeometry->GetShape(shapename);
96  fParent = gGeometry->GetCurrentNode();
97  fOption = option;
98  fVisibility = 1;
99 
100  if (strlen(matrixname)) fMatrix = gGeometry->GetRotMatrix(matrixname);
101  else {
102  fMatrix = gGeometry->GetRotMatrix("Identity");
103  if (!fMatrix)
104  fMatrix = new TRotMatrix("Identity","Identity matrix",90,0,90,90,0,0);
105  }
106 
107  if (!fShape) {
108  Printf("Error Referenced shape does not exist: %s",shapename);
109  return;
110  }
111 
113  if (fParent) {
114  fParent->BuildListOfNodes();
115  fParent->GetListOfNodes()->Add(this);
116  } else {
117  gGeometry->GetListOfNodes()->Add(this);
118  cd();
119  }
120 }
121 
122 ////////////////////////////////////////////////////////////////////////////////
123 /// Node normal constructor.
124 ///
125 /// - name is the name of the node
126 /// - title is title
127 /// - shape is the pointer to the shape definition
128 /// - x,y,z are the offsets of the volume with respect to his mother
129 /// - matrix is the pointer to the rotation matrix
130 ///
131 /// This new node is added into the list of sons of the current node
132 
133 TNode::TNode(const char *name, const char *title, TShape *shape, Double_t x, Double_t y, Double_t z, TRotMatrix *matrix, Option_t *option)
134  :TNamed(name,title),TAttLine(),TAttFill()
135 {
136 #ifdef WIN32
137 // The color "1" - default produces a very bad 3D image with OpenGL
138  Color_t lcolor = 16;
139  SetLineColor(lcolor);
140 #endif
141 
142  fX = x;
143  fY = y;
144  fZ = z;
145  fNodes = 0;
146  fShape = shape;
147  fMatrix = matrix;
148  fOption = option;
149  fVisibility = 1;
150  fParent = gGeometry->GetCurrentNode();
151  if(!fMatrix) {
152  fMatrix =gGeometry->GetRotMatrix("Identity");
153  if (!fMatrix)
154  fMatrix = new TRotMatrix("Identity","Identity matrix",90,0,90,90,0,0);
155  }
156 
157  if(!shape) {Printf("Illegal referenced shape"); return;}
158 
159  if (fParent) {
160  fParent->BuildListOfNodes();
161  fParent->GetListOfNodes()->Add(this);
163  } else {
164  gGeometry->GetListOfNodes()->Add(this);
165  cd();
166  }
167 
168 }
169 
170 ////////////////////////////////////////////////////////////////////////////////
171 /// copy constructor
172 
173 TNode::TNode(const TNode& no) :
174  TNamed(no),
175  TAttLine(no),
176  TAttFill(no),
177  TAtt3D(no),
178  fX(no.fX),
179  fY(no.fY),
180  fZ(no.fZ),
181  fMatrix(no.fMatrix),
182  fShape(no.fShape),
183  fParent(no.fParent),
184  fNodes(no.fNodes),
185  fOption(no.fOption),
186  fVisibility(no.fVisibility)
187 {
188 }
189 
190 ////////////////////////////////////////////////////////////////////////////////
191 /// assignment operator
192 
194 {
195  if(this!=&no) {
196  TNamed::operator=(no);
199  TAtt3D::operator=(no);
200  fX=no.fX;
201  fY=no.fY;
202  fZ=no.fZ;
203  fMatrix=no.fMatrix;
204  fShape=no.fShape;
205  fParent=no.fParent;
206  fNodes=no.fNodes;
207  fOption=no.fOption;
208  fVisibility=no.fVisibility;
209  }
210  return *this;
211 }
212 
213 ////////////////////////////////////////////////////////////////////////////////
214 /// Node default destructor.
215 
217 {
218  if (fParent) fParent->GetListOfNodes()->Remove(this);
219  else {if (gGeometry) gGeometry->GetListOfNodes()->Remove(this);}
220  if (fNodes) fNodes->Delete();
222  delete fNodes;
223  fNodes = 0;
224 }
225 
226 ////////////////////////////////////////////////////////////////////////////////
227 /// Browse.
228 
230 {
231  if( fNodes ) {
232  fNodes->Browse( b );
233  } else {
234  Draw();
235  gPad->Update();
236  }
237 }
238 
239 ////////////////////////////////////////////////////////////////////////////////
240 /// Create the list to support sons of this node.
241 
243 {
244  if (!fNodes) fNodes = new TList;
245 }
246 
247 ////////////////////////////////////////////////////////////////////////////////
248 /// Change Current Reference node to this.
249 
250 void TNode::cd(const char *)
251 {
252  gGeometry->SetCurrentNode(this);
253 }
254 
255 ////////////////////////////////////////////////////////////////////////////////
256 /// Compute distance from point px,py to a Node.
257 ///
258 /// Compute the closest distance of approach from point px,py to this node.
259 /// The distance is computed in pixels units.
260 
262 {
263  const Int_t big = 9999;
264  const Int_t inaxis = 7;
265  const Int_t maxdist = 5;
266 
267  Int_t puxmin = gPad->XtoAbsPixel(gPad->GetUxmin());
268  Int_t puymin = gPad->YtoAbsPixel(gPad->GetUymin());
269  Int_t puxmax = gPad->XtoAbsPixel(gPad->GetUxmax());
270  Int_t puymax = gPad->YtoAbsPixel(gPad->GetUymax());
271 
272  // return if point is not in the user area
273  if (px < puxmin - inaxis) return big;
274  if (py > puymin + inaxis) return big;
275  if (px > puxmax + inaxis) return big;
276  if (py < puymax - inaxis) return big;
277 
278  TView *view =gPad->GetView();
279  if (!view) return big;
280 
281  // Update translation vector and rotation matrix for new level
282  if (fMatrix && gGeometry) {
283  gGeometry->UpdateTempMatrix(fX,fY,fZ,fMatrix->GetMatrix(),fMatrix->IsReflection());
284  }
285 
286  // Paint Referenced shape
287  Int_t dist = big;
288  if (fVisibility && fShape->GetVisibility()) {
289  gNode = this;
290  dist = fShape->DistancetoPrimitive(px,py);
291  if (dist < maxdist) {
292  gPad->SetSelected(this);
293  return 0;
294  }
295  }
296  if ( TestBit(kSonsInvisible) ) return dist;
297  if (!gGeometry) return dist;
298 
299  // Loop on all sons
300  Int_t nsons = 0;
301  if (fNodes) nsons = fNodes->GetSize();
302  Int_t dnode = dist;
303  if (nsons) {
304  gGeometry->PushLevel();
305  TNode *node;
306  TObject *obj;
307  TIter next(fNodes);
308  while ((obj = next())) {
309  node = (TNode*)obj;
310  dnode = node->DistancetoPrimitive(px,py);
311  if (dnode <= 0) break;
312  if (dnode < dist) dist = dnode;
313  }
314  gGeometry->PopLevel();
315  }
316 
317  return dnode;
318 }
319 
320 ////////////////////////////////////////////////////////////////////////////////
321 /// Draw Referenced node with current parameters.
322 
323 void TNode::Draw(Option_t *option)
324 {
325  TString opt = option;
326  opt.ToLower();
327 
328  // Clear pad if option "same" not given
329  if (!gPad) {
330  gROOT->MakeDefCanvas();
331  }
332  if (!opt.Contains("same")) gPad->Clear();
333 
334  // Draw Referenced node
335  if (!gGeometry) new TGeometry;
338 
339  AppendPad(option);
340 
341  // Create a 3-D view
342  TView *view = gPad->GetView();
343  if (!view) {
344  view = TView::CreateView(11,0,0);
345  // Set the view to perform a first autorange (frame) draw.
346  // TViewer3DPad will revert view to normal painting after this
347  if (view) view->SetAutoRange(kTRUE);
348  }
349 
350  // Create a 3D viewer to draw us
351  gPad->GetViewer3D(option);
352 }
353 
354 ////////////////////////////////////////////////////////////////////////////////
355 /// Draw only Sons of this node.
356 
358 {
359  SetVisibility(2);
360  Draw(option);
361 }
362 
363 ////////////////////////////////////////////////////////////////////////////////
364 /// Execute action corresponding to one event.
365 ///
366 /// This member function must be implemented to realize the action
367 /// corresponding to the mouse click on the object in the window
368 
370 {
371  if (!gPad) return;
372  gPad->SetCursor(kHand);
373 }
374 
375 ////////////////////////////////////////////////////////////////////////////////
376 /// Return pointer to node with name in the node tree.
377 
378 TNode *TNode::GetNode(const char *name) const
379 {
380  if (!strcmp(name, GetName())) return (TNode*)this;
381  TNode *node, *nodefound;
382  if (!fNodes) return 0;
383  TObjLink *lnk = fNodes->FirstLink();
384  while (lnk) {
385  node = (TNode *)lnk->GetObject();
386  if (node->TestBit(kNotDeleted)) {
387  nodefound = node->GetNode(name);
388  if (nodefound) return nodefound;
389  }
390  lnk = lnk->Next();
391  }
392  return 0;
393 }
394 
395 ////////////////////////////////////////////////////////////////////////////////
396 /// Get object info.
397 
399 {
400  const char *snull = "";
401  if (!gPad) return (char*)snull;
402  static TString info;
403  info.Form("%s/%s, shape=%s/%s",GetName(),GetTitle(),fShape->GetName(),fShape->ClassName());
404  return const_cast<char*>(info.Data());
405 }
406 
407 ////////////////////////////////////////////////////////////////////////////////
408 /// Copy shape attributes as node attributes.
409 
411 {
412  SetLineColor(fShape->GetLineColor());
413  SetLineStyle(fShape->GetLineStyle());
414  SetLineWidth(fShape->GetLineWidth());
415  SetFillColor(fShape->GetFillColor());
416  SetFillStyle(fShape->GetFillStyle());
417 
418  if (!fNodes) return;
419  TNode *node;
420 
421  TObjLink *lnk = fNodes->FirstLink();
422  while (lnk) {
423  node = (TNode *)lnk->GetObject();
424  node->ImportShapeAttributes();
425  lnk = lnk->Next();
426  }
427 }
428 
429 ////////////////////////////////////////////////////////////////////////////////
430 /// Return TRUE if node contains nodes, FALSE otherwise.
431 
433 {
434  if (fNodes) return kTRUE;
435  else return kFALSE;
436 }
437 
438 ////////////////////////////////////////////////////////////////////////////////
439 /// Convert one point from local system to master reference system.
440 ///
441 /// Note that before invoking this function, the global rotation matrix
442 /// and translation vector for this node must have been computed.
443 /// This is automatically done by the Paint functions.
444 /// Otherwise TNode::UpdateMatrix should be called before.
445 
446 void TNode::Local2Master(const Double_t *local, Double_t *master)
447 {
448  Double_t x,y,z;
449  Float_t bomb = gGeometry->GetBomb();
450 
451  Double_t *matrix = &gRotMatrix[gGeomLevel][0];
452  Double_t *translation = &gTranslation[gGeomLevel][0];
453 
454  x = bomb*translation[0]
455  + local[0]*matrix[0]
456  + local[1]*matrix[3]
457  + local[2]*matrix[6];
458 
459  y = bomb*translation[1]
460  + local[0]*matrix[1]
461  + local[1]*matrix[4]
462  + local[2]*matrix[7];
463 
464  z = bomb*translation[2]
465  + local[0]*matrix[2]
466  + local[1]*matrix[5]
467  + local[2]*matrix[8];
468 
469  master[0] = x; master[1] = y; master[2] = z;
470 }
471 
472 ////////////////////////////////////////////////////////////////////////////////
473 /// Convert one point from local system to master reference system.
474 ///
475 /// Note that before invoking this function, the global rotation matrix
476 /// and translation vector for this node must have been computed.
477 /// This is automatically done by the Paint functions.
478 /// Otherwise TNode::UpdateMatrix should be called before.
479 
480 void TNode::Local2Master(const Float_t *local, Float_t *master)
481 {
482  Float_t x,y,z;
483  Float_t bomb = gGeometry->GetBomb();
484 
485  Double_t *matrix = &gRotMatrix[gGeomLevel][0];
486  Double_t *translation = &gTranslation[gGeomLevel][0];
487 
488  x = bomb*translation[0]
489  + local[0]*matrix[0]
490  + local[1]*matrix[3]
491  + local[2]*matrix[6];
492 
493  y = bomb*translation[1]
494  + local[0]*matrix[1]
495  + local[1]*matrix[4]
496  + local[2]*matrix[7];
497 
498  z = bomb*translation[2]
499  + local[0]*matrix[2]
500  + local[1]*matrix[5]
501  + local[2]*matrix[8];
502 
503  master[0] = x; master[1] = y; master[2] = z;
504 }
505 
506 ////////////////////////////////////////////////////////////////////////////////
507 /// List Referenced object with current parameters.
508 
509 void TNode::ls(Option_t *option) const
510 {
511  Int_t sizeX3D = 0;
512  TString opt = option;
513  opt.ToLower();
514 
515  if (!gGeometry) new TGeometry;
516 
517  Int_t maxlevel = 15;
518  if (opt.Contains("1")) maxlevel = 1;
519  if (opt.Contains("2")) maxlevel = 2;
520  if (opt.Contains("3")) maxlevel = 3;
521  if (opt.Contains("4")) maxlevel = 4;
522  if (opt.Contains("5")) maxlevel = 5;
523  if (opt.Contains("x")) sizeX3D = 1;
524 
526 
527  Int_t nsons = 0;
528  if (fNodes) nsons = fNodes->GetSize();
529  const char *shapename, *matrixname;
530  if (fShape) shapename = fShape->IsA()->GetName();
531  else shapename = "????";
532  std::cout<<GetName()<<":"<<GetTitle()<<" is a "<<shapename;
533  if (sizeX3D) {
534  gSize3D.numPoints = 0;
535  gSize3D.numSegs = 0;
536  gSize3D.numPolys = 0;
537  Sizeof3D();
538  std::cout<<" NumPoints="<<gSize3D.numPoints;
539  std::cout<<" NumSegs ="<<gSize3D.numSegs;
540  std::cout<<" NumPolys ="<<gSize3D.numPolys;
541  } else {
542  std::cout<<" X="<<fX<<" Y="<<fY<<" Z="<<fZ;
543  if (nsons) std::cout<<" Sons="<<nsons;
544  if (fMatrix) matrixname = fMatrix->GetName();
545  else matrixname = "Identity";
546  if(strcmp(matrixname,"Identity")) std::cout<<" Rot="<<matrixname;
547  }
548  std::cout<<std::endl;
549  if(!nsons) return;
550  if (gGeomLevel >= maxlevel) return;
551 
553  gGeomLevel++;
554  fNodes->ls(option);
555  gGeomLevel--;
557 
558 }
559 
560 ////////////////////////////////////////////////////////////////////////////////
561 /// Convert one point from master system to local reference system.
562 ///
563 /// Note that before invoking this function, the global rotation matrix
564 /// and translation vector for this node must have been computed.
565 /// This is automatically done by the Paint functions.
566 /// Otherwise TNode::UpdateMatrix should be called before.
567 
568 void TNode::Master2Local(const Double_t *master, Double_t *local)
569 {
570  Double_t x,y,z;
571  Float_t bomb = gGeometry->GetBomb();
572 
573  Double_t *matrix = &gRotMatrix[gGeomLevel][0];
574  Double_t *translation = &gTranslation[gGeomLevel][0];
575 
576  Double_t xms = master[0] - bomb*translation[0];
577  Double_t yms = master[1] - bomb*translation[1];
578  Double_t zms = master[2] - bomb*translation[2];
579 
580  x = xms*matrix[0] + yms*matrix[1] + zms*matrix[2];
581  y = xms*matrix[3] + yms*matrix[4] + zms*matrix[5];
582  z = xms*matrix[6] + yms*matrix[7] + zms*matrix[8];
583 
584  local[0] = x; local[1] = y; local[2] = z;
585 }
586 
587 ////////////////////////////////////////////////////////////////////////////////
588 /// Convert one point from master system to local reference system.
589 ///
590 /// Note that before invoking this function, the global rotation matrix
591 /// and translation vector for this node must have been computed.
592 /// This is automatically done by the Paint functions.
593 /// Otherwise TNode::UpdateMatrix should be called before.
594 
595 void TNode::Master2Local(const Float_t *master, Float_t *local)
596 {
597  Float_t x,y,z;
598  Float_t bomb = gGeometry->GetBomb();
599 
600  Double_t *matrix = &gRotMatrix[gGeomLevel][0];
601  Double_t *translation = &gTranslation[gGeomLevel][0];
602 
603  Double_t xms = master[0] - bomb*translation[0];
604  Double_t yms = master[1] - bomb*translation[1];
605  Double_t zms = master[2] - bomb*translation[2];
606 
607  x = xms*matrix[0] + yms*matrix[1] + zms*matrix[2];
608  y = xms*matrix[3] + yms*matrix[4] + zms*matrix[5];
609  z = xms*matrix[6] + yms*matrix[7] + zms*matrix[8];
610 
611  local[0] = x; local[1] = y; local[2] = z;
612 }
613 
614 ////////////////////////////////////////////////////////////////////////////////
615 /// Paint Referenced node with current parameters.
616 ///
617 /// - vis = 1 (default) shape is drawn
618 /// - vis = 0 shape is not drawn but its sons may be not drawn
619 /// - vis = -1 shape is not drawn. Its sons are not drawn
620 /// - vis = -2 shape is drawn. Its sons are not drawn
621 
622 void TNode::Paint(Option_t *option)
623 {
624  Int_t level = 0;
625  if (gGeometry) level = gGeometry->GeomLevel();
626 
627  // Update translation vector and rotation matrix for new level
628  if (level) {
629  gGeometry->UpdateTempMatrix(fX,fY,fZ,fMatrix->GetMatrix(),fMatrix->IsReflection());
630  }
631 
632  // Paint Referenced shape
633  Int_t nsons = 0;
634  if (fNodes) nsons = fNodes->GetSize();
635 
638 
639  Bool_t viewerWantsSons = kTRUE;
640 
641  if (fVisibility && fShape->GetVisibility()) {
642  gNode = this;
643  fShape->SetLineColor(GetLineColor());
644  fShape->SetLineStyle(GetLineStyle());
645  fShape->SetLineWidth(GetLineWidth());
646  fShape->SetFillColor(GetFillColor());
647  fShape->SetFillStyle(GetFillStyle());
648 
649  TVirtualViewer3D * viewer3D = gPad->GetViewer3D();
650  if (viewer3D) {
651  // We only provide master frame positions in these shapes
652  // so don't ask viewer preference
653 
654  // Ask all shapes for kCore/kBoundingBox/kShapeSpecific
655  // Not all will support the last two - which is fine
656  const TBuffer3D & buffer =
658 
659  Int_t reqSections = viewer3D->AddObject(buffer, &viewerWantsSons);
660  if (reqSections != TBuffer3D::kNone)
661  {
662  fShape->GetBuffer3D(reqSections);
663  viewer3D->AddObject(buffer, &viewerWantsSons);
664  }
665  }
666  }
667  if ( TestBit(kSonsInvisible) ) return;
668 
669  // Paint all sons
670  if(!nsons || !viewerWantsSons) return;
671 
672  gGeometry->PushLevel();
673  TNode *node;
674  TObject *obj;
675  TIter next(fNodes);
676  while ((obj = next())) {
677  node = (TNode*)obj;
678  node->Paint(option);
679  }
680  gGeometry->PopLevel();
681 }
682 
683 ////////////////////////////////////////////////////////////////////////////////
684 /// Recursively remove object from the list of nodes of this node.
685 
687 {
688  if (fNodes && dynamic_cast<TNode*>(obj) ) fNodes->RecursiveRemove(obj);
689 }
690 
691 ////////////////////////////////////////////////////////////////////////////////
692 /// Change the name of this Node
693 
694 void TNode::SetName(const char *name)
695 {
696  if (gPad) gPad->Modified();
697 
698  // Nodes are named objects in a THashList.
699  // We must update the hashlist if we change the name
700  if (fParent) fParent->GetListOfNodes()->Remove(this);
701  fName = name;
702  if (fParent) fParent->GetListOfNodes()->Add(this);
703 }
704 
705 ////////////////////////////////////////////////////////////////////////////////
706 /// Change the name and title of this Node
707 
708 void TNode::SetNameTitle(const char *name, const char *title)
709 {
710  if (gPad) gPad->Modified();
711 
712  // Nodes are named objects in a THashList.
713  // We must update the hashlist if we change the name
714  if (fParent) fParent->GetListOfNodes()->Remove(this);
715  fName = name;
716  fTitle = title;
717  if (fParent) fParent->GetListOfNodes()->Add(this);
718 }
719 
720 ////////////////////////////////////////////////////////////////////////////////
721 /// Set the pointer to the parent, keep parents informed about who they have
722 
723 void TNode::SetParent(TNode *parent)
724 {
725  TNode *pp = parent;
726  while(pp) {
727  if (pp == this) {
728  printf("Error: Cannot set parent node to be a child node:%s\n",GetName());
729  printf(" Operation not performed!\n");
730  return;
731  }
732  pp = pp->GetParent();
733  }
734 
735  if (fParent) fParent->GetListOfNodes()->Remove(this);
736  else gGeometry->GetListOfNodes()->Remove(this);
737 
738  fParent = parent;
739 
740  if (fParent) {
741  fParent->BuildListOfNodes(); // new parent might not have list
742  fParent->GetListOfNodes()->Add(this);
743  }
744  else gGeometry->GetListOfNodes()->Add(this);
745 }
746 
747 ////////////////////////////////////////////////////////////////////////////////
748 /// Set visibility for this node and its sons.
749 ///
750 /// - vis = 3 node is drawn and its sons are drawn
751 /// - vis = 2 node is not drawn but its sons are drawn
752 /// - vis = 1 (default) node is drawn
753 /// - vis = 0 node is not drawn
754 /// - vis = -1 node is not drawn. Its sons are not drawn
755 /// - vis = -2 node is drawn. Its sons are not drawn
756 /// - vis = -3 Only node leaves are drawn
757 /// - vis = -4 Node is not drawn. Its immediate sons are drawn
758 
760 {
762  TNode *node;
763  if (vis == -4 ) { //Node is not drawn. Its immediate sons are drawn
764  fVisibility = 0;
765  if (!fNodes) { fVisibility = 1; return;}
766  TIter next(fNodes); while ((node = (TNode*)next())) { node->SetVisibility(-2); }
767  } else if (vis == -3 ) { //Only node leaves are drawn
768  fVisibility = 0;
769  if (!fNodes) { fVisibility = 1; return;}
770  TIter next(fNodes); while ((node = (TNode*)next())) { node->SetVisibility(-3); }
771 
772  } else if (vis == -2) { //node is drawn. Its sons are not drawn
773  fVisibility = 1; SetBit(kSonsInvisible); if (!fNodes) return;
774  TIter next(fNodes); while ((node = (TNode*)next())) { node->SetVisibility(-1); }
775 
776  } else if (vis == -1) { //node is not drawn. Its sons are not drawn
777  fVisibility = 0; SetBit(kSonsInvisible); if (!fNodes) return;
778  TIter next(fNodes); while ((node = (TNode*)next())) { node->SetVisibility(-1); }
779 
780  } else if (vis == 0) { //node is not drawn
781  fVisibility = 0;
782 
783  } else if (vis == 1) { //node is drawn
784  fVisibility = 1;
785 
786  } else if (vis == 2) { //node is not drawn but its sons are drawn
787  fVisibility = 0; if (!fNodes) return;
788  TIter next(fNodes); while ((node = (TNode*)next())) { node->SetVisibility(3); }
789 
790  } else if (vis == 3) { //node is drawn and its sons are drawn
791  fVisibility = 1; if (!fNodes) return;
792  TIter next(fNodes); while ((node = (TNode*)next())) { node->SetVisibility(3); }
793  }
794 }
795 
796 ////////////////////////////////////////////////////////////////////////////////
797 /// Return total size of this 3-D Node with its attributes.
798 
799 void TNode::Sizeof3D() const
800 {
801  if (fVisibility && fShape && fShape->GetVisibility()) {
802  fShape->Sizeof3D();
803  }
804  if ( TestBit(kSonsInvisible) ) return;
805 
806  if (!fNodes) return;
807  TNode *node;
808  TObject *obj;
809  TIter next(fNodes);
810  while ((obj = next())) {
811  node = (TNode*)obj;
812  node->Sizeof3D();
813  }
814 }
815 
816 ////////////////////////////////////////////////////////////////////////////////
817 /// Stream a class object.
818 
819 void TNode::Streamer(TBuffer &b)
820 {
821  if (b.IsReading()) {
822  UInt_t R__s, R__c;
823  Version_t R__v = b.ReadVersion(&R__s, &R__c);
824  if (R__v > 2) {
825  b.ReadClassBuffer(TNode::Class(), this, R__v, R__s, R__c);
826  return;
827  }
828  //====process old versions before automatic schema evolution
829  TNamed::Streamer(b);
830  TAttLine::Streamer(b);
831  TAttFill::Streamer(b);
832  b >> fX;
833  b >> fY;
834  b >> fZ;
835  b >> fMatrix;
836  b >> fShape;
837  b >> fParent;
838  b >> fNodes;
839  fOption.Streamer(b);
840  if (R__v > 1) b >> fVisibility;
841  else fVisibility = fShape->GetVisibility();
842  b.CheckByteCount(R__s, R__c, TNode::IsA());
843  //====end of old versions
844 
845  } else {
846  b.WriteClassBuffer(TNode::Class(),this);
847  }
848 }
849 
850 ////////////////////////////////////////////////////////////////////////////////
851 /// Update global rotation matrix/translation vector for this node
852 /// this function must be called before invoking Local2Master
853 
855 {
856  TNode *nodes[kMAXLEVELS], *node;
857  Int_t i;
858  for (i=0;i<kVectorSize;i++) gTranslation[0][i] = 0;
859  for (i=0;i<kMatrixSize;i++) gRotMatrix[0][i] = 0;
860  gRotMatrix[0][0] = 1; gRotMatrix[0][4] = 1; gRotMatrix[0][8] = 1;
861 
862  node = this;
863  gGeomLevel = 0;
864  //build array of parent nodes
865  while (node) {
866  nodes[gGeomLevel] = node;
867  node = node->GetParent();
868  gGeomLevel++;
869  }
870  gGeomLevel--;
871  //Update matrices in the hierarchy
872  for (i=1;i<=gGeomLevel;i++) {
873  node = nodes[gGeomLevel-i];
874  UpdateTempMatrix(&(gTranslation[i-1][0]),&gRotMatrix[i-1][0]
875  ,node->GetX(),node->GetY(),node->GetZ(),node->GetMatrix()->GetMatrix()
876  ,&gTranslation[i][0],&gRotMatrix[i][0]);
877  }
878 }
879 
880 ////////////////////////////////////////////////////////////////////////////////
881 /// Compute new translation vector and global matrix.
882 ///
883 /// - dx old translation vector
884 /// - rmat old global matrix
885 /// - x,y,z offset of new local system with respect to mother
886 /// - dxnew new translation vector
887 /// - rmatnew new global rotation matrix
888 
889 void TNode::UpdateTempMatrix(const Double_t *dx,const Double_t *rmat
890  , Double_t x, Double_t y, Double_t z, Double_t *matrix
891  , Double_t *dxnew, Double_t *rmatnew)
892 {
893  dxnew[0] = dx[0] + x*rmat[0] + y*rmat[3] + z*rmat[6];
894  dxnew[1] = dx[1] + x*rmat[1] + y*rmat[4] + z*rmat[7];
895  dxnew[2] = dx[2] + x*rmat[2] + y*rmat[5] + z*rmat[8];
896 
897  rmatnew[0] = rmat[0]*matrix[0] + rmat[3]*matrix[1] + rmat[6]*matrix[2];
898  rmatnew[1] = rmat[1]*matrix[0] + rmat[4]*matrix[1] + rmat[7]*matrix[2];
899  rmatnew[2] = rmat[2]*matrix[0] + rmat[5]*matrix[1] + rmat[8]*matrix[2];
900  rmatnew[3] = rmat[0]*matrix[3] + rmat[3]*matrix[4] + rmat[6]*matrix[5];
901  rmatnew[4] = rmat[1]*matrix[3] + rmat[4]*matrix[4] + rmat[7]*matrix[5];
902  rmatnew[5] = rmat[2]*matrix[3] + rmat[5]*matrix[4] + rmat[8]*matrix[5];
903  rmatnew[6] = rmat[0]*matrix[6] + rmat[3]*matrix[7] + rmat[6]*matrix[8];
904  rmatnew[7] = rmat[1]*matrix[6] + rmat[4]*matrix[7] + rmat[7]*matrix[8];
905  rmatnew[8] = rmat[2]*matrix[6] + rmat[5]*matrix[7] + rmat[8]*matrix[8];
906 }
TString fTitle
Definition: TNamed.h:37
TList * GetListOfNodes() const
Definition: TGeometry.h:80
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:52
virtual Double_t * GetMatrix()
Definition: TRotMatrix.h:56
virtual Style_t GetLineStyle() const
Definition: TAttLine.h:48
virtual Style_t GetFillStyle() const
Definition: TAttFill.h:44
virtual void SetLineWidth(Width_t lwidth)
Definition: TAttLine.h:57
virtual void Draw(Option_t *option="")
Draw Referenced node with current parameters.
Definition: TNode.cxx:323
virtual Double_t GetY() const
Definition: TNode.h:84
static Double_t gTranslation[kMAXLEVELS][kVectorSize]
Definition: TNode.cxx:32
double dist(Rotation3D const &r1, Rotation3D const &r2)
Definition: 3DDistances.cxx:48
static Int_t DecreaseDirLevel()
Decrease the indentation level for ls().
Definition: TROOT.cxx:2390
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
virtual void RecursiveRemove(TObject *obj)
Recursively remove object from the list of nodes of this node.
Definition: TNode.cxx:686
Bool_t IsReading() const
Definition: TBuffer.h:81
short Version_t
Definition: RtypesCore.h:61
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
float Float_t
Definition: RtypesCore.h:53
static Int_t gGeomLevel
Definition: TNode.cxx:34
const char Option_t
Definition: RtypesCore.h:62
Int_t fVisibility
Definition: TNode.h:56
virtual void Local2Master(const Double_t *local, Double_t *master)
Convert one point from local system to master reference system.
Definition: TNode.cxx:446
virtual void SetNameTitle(const char *name, const char *title)
Change the name and title of this Node.
Definition: TNode.cxx:708
virtual void SetAutoRange(Bool_t autorange=kTRUE)=0
virtual void cd(const char *path=0)
Change Current Reference node to this.
Definition: TNode.cxx:250
See TView3D.
Definition: TView.h:36
Use this attribute class when an object should have 3D capabilities.
Definition: TAtt3D.h:29
const Int_t kMAXLEVELS
Definition: TGeometry.h:31
Buffer base class used for serializing objects.
Definition: TBuffer.h:40
TNode description.
Definition: TNode.h:43
virtual void DrawOnly(Option_t *option="")
Draw only Sons of this node.
Definition: TNode.cxx:357
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
#define gROOT
Definition: TROOT.h:340
Basic string class.
Definition: TString.h:137
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1088
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual void SetFillStyle(Style_t fstyle)
Definition: TAttFill.h:52
virtual TNode * GetNode(const char *name) const
Return pointer to node with name in the node tree.
Definition: TNode.cxx:378
virtual ~TNode()
Node default destructor.
Definition: TNode.cxx:216
virtual void Modify()
Change current line attributes if necessary.
Definition: TAttLine.cxx:229
virtual void Paint(Option_t *option="")
Paint Referenced node with current parameters.
Definition: TNode.cxx:622
virtual void Sizeof3D() const
Return total size of this 3-D Node with its attributes.
Definition: TNode.cxx:799
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:732
TNode * gNode
Definition: TNode.cxx:36
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition: TObject.cxx:164
const char * Data() const
Definition: TString.h:349
Fill Area Attributes class.
Definition: TAttFill.h:32
Double_t x[n]
Definition: legend1.C:17
const Int_t kVectorSize
Definition: TGeometry.h:32
void Class()
Definition: Class.C:29
virtual void SetVisibility(Int_t vis=1)
Set visibility for this node and its sons.
Definition: TNode.cxx:759
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
TRotMatrix * GetRotMatrix(const char *name) const
Return pointer to RotMatrix with name.
Definition: TGeometry.cxx:356
TShape * GetShape(const char *name) const
Return pointer to Shape with name.
Definition: TGeometry.cxx:379
virtual void Modify()
Change current fill area attributes if necessary.
Definition: TAttFill.cxx:206
Double_t fX
Definition: TNode.h:48
TList * fNodes
Definition: TNode.h:54
virtual void SetParent(TNode *parent)
Set the pointer to the parent, keep parents informed about who they have.
Definition: TNode.cxx:723
virtual Int_t PushLevel()
Definition: TGeometry.h:103
Double_t fZ
Definition: TNode.h:50
Abstract 3D shapes viewer.
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute action corresponding to one event.
Definition: TNode.cxx:369
TNode * GetCurrentNode() const
Definition: TGeometry.h:83
TShape * fShape
Definition: TNode.h:52
short Color_t
Definition: RtypesCore.h:79
A doubly linked list.
Definition: TList.h:47
virtual Double_t GetX() const
Definition: TNode.h:83
TGeometry description.
Definition: TGeometry.h:43
TRotMatrix * fMatrix
Definition: TNode.h:51
virtual void SetLineColor(Color_t lcolor)
Definition: TAttLine.h:54
Bool_t IsFolder() const
Return TRUE if node contains nodes, FALSE otherwise.
Definition: TNode.cxx:432
virtual void Delete(Option_t *option="")
Delete this object.
Definition: TObject.cxx:228
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:41
virtual void UpdateMatrix()
Update global rotation matrix/translation vector for this node this function must be called before in...
Definition: TNode.cxx:854
This is the base class for all geometry shapes.
Definition: TShape.h:47
TNamed & operator=(const TNamed &rhs)
TNamed assignment operator.
Definition: TNamed.cxx:40
Manages a detector rotation matrix.
Definition: TRotMatrix.h:30
#define gSize3D
Definition: X3DBuffer.h:42
virtual void SetFillColor(Color_t fcolor)
Definition: TAttFill.h:50
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:674
virtual void BuildListOfNodes()
Create the list to support sons of this node.
Definition: TNode.cxx:242
virtual Color_t GetFillColor() const
Definition: TAttFill.h:43
virtual Double_t GetZ() const
Definition: TNode.h:85
TClass * IsA() const
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition: TString.cxx:2321
virtual Int_t AddObject(const TBuffer3D &buffer, Bool_t *addChildren=0)=0
unsigned int UInt_t
Definition: RtypesCore.h:42
Bool_t TestBit(UInt_t f) const
Definition: TObject.h:173
TString fOption
Definition: TNode.h:55
TList * GetListOfNodes() const
Definition: TNode.h:75
virtual void UpdateTempMatrix(const Double_t *dx1, const Double_t *rmat1, Double_t x, Double_t y, Double_t z, Double_t *matrix, Double_t *dxnew, Double_t *rmatnew)
Compute new translation vector and global matrix.
Definition: TNode.cxx:889
Generic 3D primitive description class.
Definition: TBuffer3D.h:19
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
virtual void ImportShapeAttributes()
Copy shape attributes as node attributes.
Definition: TNode.cxx:410
virtual Color_t GetLineColor() const
Definition: TAttLine.h:47
TString fName
Definition: TNamed.h:36
#define Printf
Definition: TGeoToOCC.h:18
Int_t GeomLevel() const
Definition: TGeometry.h:78
virtual void SetCurrentNode(TNode *node)
Definition: TGeometry.h:107
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=0
#define ClassImp(name)
Definition: Rtypes.h:279
double Double_t
Definition: RtypesCore.h:55
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
Double_t y[n]
Definition: legend1.C:17
const Int_t kMatrixSize
Definition: TGeometry.h:33
virtual void SetGeomLevel(Int_t level=0)
Definition: TGeometry.h:108
virtual void SetLineStyle(Style_t lstyle)
Definition: TAttLine.h:56
static TView * CreateView(Int_t system=1, const Double_t *rmin=0, const Double_t *rmax=0)
Create a concrete default 3-d view via the plug-in manager.
Definition: TView.cxx:36
#define name(a, b)
Definition: linkTestLib0.cpp:5
Binding & operator=(OUT(*fun)(void))
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Compute distance from point px,py to a Node.
Definition: TNode.cxx:261
Mother of all ROOT objects.
Definition: TObject.h:58
virtual void UpdateTempMatrix(Double_t x=0, Double_t y=0, Double_t z=0, TRotMatrix *matrix=0)
Update temp matrix.
Definition: TGeometry.cxx:661
static Int_t IncreaseDirLevel()
Increase the indentation level for ls().
Definition: TROOT.cxx:2453
virtual TRotMatrix * GetMatrix() const
Definition: TNode.h:76
virtual void ls(Option_t *option="2") const
List Referenced object with current parameters.
Definition: TNode.cxx:509
virtual void Add(TObject *obj)
Definition: TList.h:81
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:567
TNode * fParent
Definition: TNode.h:53
static Double_t gRotMatrix[kMAXLEVELS][kMatrixSize]
Definition: TNode.cxx:33
#define gPad
Definition: TVirtualPad.h:288
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition: TROOT.cxx:2461
virtual void Master2Local(const Double_t *master, Double_t *local)
Convert one point from master system to local reference system.
Definition: TNode.cxx:568
void ResetBit(UInt_t f)
Definition: TObject.h:172
virtual TNode * GetParent() const
Definition: TNode.h:80
virtual void Browse(TBrowser *b)
Browse.
Definition: TNode.cxx:229
const Bool_t kTRUE
Definition: Rtypes.h:91
virtual Width_t GetLineWidth() const
Definition: TAttLine.h:49
virtual void SetName(const char *name)
Change the name of this Node.
Definition: TNode.cxx:694
R__EXTERN TGeometry * gGeometry
Definition: TGeometry.h:162
virtual char * GetObjectInfo(Int_t px, Int_t py) const
Get object info.
Definition: TNode.cxx:398
TObject * obj
TNode & operator=(const TNode &)
assignment operator
Definition: TNode.cxx:193
virtual Int_t PopLevel()
Definition: TGeometry.h:104
Double_t fY
Definition: TNode.h:49
Line Attributes class.
Definition: TAttLine.h:32
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0
Float_t GetBomb() const
Definition: TGeometry.h:77