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