ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TVolume.cxx
Go to the documentation of this file.
1 // @(#)root/table:$Id$
2 // Author: Valery Fine 10/12/98
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 <stdlib.h>
14 
15 #include "TROOT.h"
16 #include "TClass.h"
17 #include "TVirtualPad.h"
18 #include "TView.h"
19 #include "TGeometry.h"
20 #include "TRotMatrix.h"
21 #include "TShape.h"
22 #include "TVolume.h"
23 #include "TBrowser.h"
24 #include "X3DBuffer.h"
25 
26 #include "TTablePadView3D.h"
27 #include "TCanvas.h"
28 
29 #include "TRotMatrix.h"
30 #include "TVolumePosition.h"
31 #include "TVirtualViewer3D.h"
32 #include "TBuffer3D.h"
33 
34 #if 0
35 const Int_t kVectorSize = 3;
37 const Int_t kMAXLEVELS = 20;
38 
41 static Int_t gGeomLevel = 0;
42 
43 TVolume *gNode;
44 #endif
45 //R__EXTERN Size3D gSize3D;
46 static TRotMatrix *gIdentity = 0;
47 
49 
50 //______________________________________________________________________________
51 //*-*-*-*-*-*-*-*-*-*-*-* T V O L U M E description *-*-*-*-*-*-*-*-*-*-*-*-*
52 //*-* ==========================
53 //*-*
54 //*-* A TVolume object is used to build the geometry hierarchy.
55 //*-* Since TVolume is derived from TDataSet class it may contain other volumes.
56 //*-*
57 //*-* A geometry volume has attributes:
58 //*-* - name and title
59 //*-* - pointer to the referenced shape (see TShape).
60 //*-* - list of TVolumePosition object defining the position of the nested volumes
61 //*-* with respect to the mother node.
62 //*-*
63 //*-*
64 //*-* A volume can be drawn.
65 //*-*
66 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
67 
68 
69 ////////////////////////////////////////////////////////////////////////////////
70 ///*-*-*-*-*-*-*-*-*-*-*Volume default constructor*-*-*-*-*-*-*-*-*-*-*-*-*
71 ///*-* ========================
72 
74 {
75  fShape = 0;
76  fListOfShapes = 0;
77  fVisibility = kBothVisible;
78  if (!gGeometry) new TGeometry;
79 }
80 
81 ////////////////////////////////////////////////////////////////////////////////
82 ///*-*-*-*-*-*-*-*-*-*-*Volume normal constructor*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
83 ///*-* =========================
84 ///*-*
85 ///*-* name is the name of the node
86 ///*-* title is title
87 ///*-* shapename is the name of the referenced shape
88 ///*-*
89 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
90 
91 TVolume::TVolume(const char *name, const char *title, const char *shapename, Option_t *option)
92  :TObjectSet(name),TAttLine(), TAttFill(),fShape(0),fListOfShapes(0)
93 {
94 #ifdef WIN32
95 //*-* The color "1" - default produces a very bad 3D image with OpenGL
96  Color_t lcolor = 16;
97  SetLineColor(lcolor);
98 #endif
99  static Int_t counter = 0;
100  counter++;
101  SetTitle(title);
102  if(!(counter%1000))std::cout<<"TVolume count="<<counter<<" name="<<name<<std::endl;
103  if (!gGeometry) new TGeometry;
104  Add(gGeometry->GetShape(shapename),kTRUE);
105 // fParent = gGeometry->GetCurrenTVolume();
106  fOption = option;
108 
110 }
111 
112 
113 ////////////////////////////////////////////////////////////////////////////////
114 ///*-*-*-*-*-*-*-*-*-*-*Volume normal constructor*-*-*-*-*-*-*-*-*-*-*
115 ///*-* ================================
116 ///*-*
117 ///*-* name is the name of the node
118 ///*-* title is title
119 ///*-* shape is the pointer to the shape definition
120 ///*-*
121 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
122 
123 TVolume::TVolume(const char *name, const char *title, TShape *shape, Option_t *option)
124  :TObjectSet(name),TAttLine(),TAttFill(),fShape(0),fListOfShapes(0)
125 {
126 #ifdef WIN32
127 //*-* The color "1" - default produces a very bad 3D image with OpenGL
128  Color_t lcolor = 16;
129  SetLineColor(lcolor);
130 #endif
131 
132  if (!gGeometry) new TGeometry;
133  Add(shape,kTRUE);
134  fOption = option;
136  SetTitle(title);
137  if(shape) ImportShapeAttributes();
138 }
139 
140 ////////////////////////////////////////////////////////////////////////////////
141 /// ENodeSEEN Visibility flag 00 - everything visible,
142 /// 10 - this unvisible, but sons are visible
143 /// 01 - this visible but sons
144 /// 11 - neither this nor its sons are visible
145 /// Maps the value of the visibility flag to begin_html <a href="http://wwwinfo.cern.ch/asdoc/geant_html3/node128.html#SECTION056000000000000000000000">GEANT 3.21 "volume attributes"</a>end_html
146 
148 {
149  const Int_t mapVis[4] = {1, -2, 0, -1 };
150  return mapVis[vis];
151 }
152 
153 //______________________________________________________________________________
154 //ENodeSEEN TVolume::MapGEANT2StNodeVis(Int_t vis)
156 {
157 // Maps the value of begin_html <a href="http://wwwinfo.cern.ch/asdoc/geant_html3/node128.html#SECTION056000000000000000000000">GEANT 3.21 "volume attributes"</a>end_html to the visibility flag
158  const Int_t mapVis[4] = {1, -2, 0, -1 };
159  Int_t i;
160 // for (i =0; i<3;i++) if (mapVis[i] == vis) return (ENodeSEEN)i;
161  for (i =0; i<3;i++) if (mapVis[i] == vis) return i;
162  return kBothVisible;
163 }
164 
165 ////////////////////////////////////////////////////////////////////////////////
166 /// Convert a TNode object into a TVolume
167 
168 TVolume::TVolume(TNode &rootNode):fShape(0),fListOfShapes(0)
169 {
170  SetName(rootNode.GetName());
171  SetTitle(rootNode.GetTitle());
173  fOption = rootNode.GetOption();
174  Add(rootNode.GetShape(),kTRUE);
175 
176  SetLineColor(rootNode.GetLineColor());
177  SetLineStyle(rootNode.GetLineStyle());
178  SetLineWidth(rootNode.GetLineWidth());
179  SetFillColor(rootNode.GetFillColor());
180  SetFillStyle(rootNode.GetFillStyle());
181 
182  TList *nodes = rootNode.GetListOfNodes();
183  if (nodes) {
184  TIter next(nodes);
185  TNode *node = 0;
186  while ( (node = (TNode *) next()) ){
187  TVolume *nextNode = new TVolume(*node);
188  Add(nextNode,node->GetX(),node->GetY(),node->GetZ(),node->GetMatrix());
189  }
190  }
191 }
192 
193 ////////////////////////////////////////////////////////////////////////////////
194 ///to be documented
195 
196 void TVolume::Add(TShape *shape, Bool_t IsMaster)
197 {
198  if (!shape) return;
199  if (!fListOfShapes) fListOfShapes = new TList;
200  fListOfShapes->Add(shape);
201  if (IsMaster) fShape = shape;
202 }
203 
204 ////////////////////////////////////////////////////////////////////////////////
205 /// Convert a TVolume object into a TNode
206 
208 {
209  Double_t x=0;
210  Double_t y=0;
211  Double_t z=0;
212  const TRotMatrix* matrix = 0;
213  if (position) {
214  x=position->GetX();
215  y=position->GetY();
216  z=position->GetZ();
217  matrix = position->GetMatrix();
218  }
219 // const Char_t *path = Path();
220 // printf("%s: %s/%s, shape=%s/%s\n",path,GetName(),GetTitle(),GetShape()->GetName(),GetShape()->ClassName());
221  TNode *newNode = new TNode(GetName(),GetTitle(),GetShape(),x,y,z,(TRotMatrix* )matrix,GetOption());
223 
224  newNode->SetLineColor(GetLineColor());
225  newNode->SetLineStyle(GetLineStyle());
226  newNode->SetLineWidth(GetLineWidth());
227  newNode->SetFillColor(GetFillColor());
228  newNode->SetFillStyle(GetFillStyle());
229 
230  TList *positions = GetListOfPositions();
231  if (positions) {
232  TIter next(positions);
233  TVolumePosition *pos = 0;
234  while ( (pos = (TVolumePosition *) next()) ){
235  TVolume *node = pos->GetNode();
236  if (node) {
237  newNode->cd();
238  node->CreateTNode(pos);
239  }
240  }
241  }
242  newNode->ImportShapeAttributes();
243  return newNode;
244 }
245 
246 ////////////////////////////////////////////////////////////////////////////////
247 ///*-*-*-*-*-*-*-*-*-*-*Volume default destructor*-*-*-*-*-*-*-*-*-*-*-*-*-*
248 ///*-* ======================
249 
251 {
252  // Hmm, here we are in the troubles, in theory we have to find all
253  // place where this node is sitting but we don't (yet :-()
254 
255  if (GetListOfPositions()) {
258  }
260 }
261 
262 ////////////////////////////////////////////////////////////////////////////////
263 ///to be documented
264 
266 {
268  if ( GetListOfPositions()) GetListOfPositions()->Add(position);
269  else Error("Add","Can not create list of positions for the current node <%s>:<%s>",GetName(),GetTitle());
270 }
271 
272 ////////////////////////////////////////////////////////////////////////////////
273 ///to be documented
274 
276 {
277  TVolumePosition *position = nodePosition;
278  if (!node) return 0;
279  if (!position) position = new TVolumePosition(node); // Create default position
280  // The object must be placed at once. Check it:
281  if (!(GetCollection() && GetCollection()->FindObject(node)) ) TDataSet::Add(node);
282  Add(position);
283  return position;
284 }
285 
286 ////////////////////////////////////////////////////////////////////////////////
287 ///*-*
288 ///*-* volume the pointer to the volume to be placed
289 ///*-* x,y,z are the offsets of the volume with respect to his mother
290 ///*-* matrix is the pointer to the rotation matrix
291 ///*-* id is a unique position id
292 ///*-*
293 
295  TRotMatrix *matrix, UInt_t id, Option_t *)
296 {
297  if (!volume) return 0;
298  TRotMatrix *rotation = matrix;
299  if(!rotation) rotation = GetIdentity();
300  TVolumePosition *position = new TVolumePosition(volume,x,y,z,rotation);
301  position->SetId(id);
302  return Add(volume,position);
303 }
304 
305 ////////////////////////////////////////////////////////////////////////////////
306 ///*-*
307 ///*-* volume the pointer to the volume to be placed
308 ///*-* x,y,z are the offsets of the volume with respect to his mother
309 ///*-* matrixname is the name of the rotation matrix
310 ///*-* id is a unique position id
311 ///*-*
312 
314  const char *matrixname, UInt_t id, Option_t *)
315 {
316  if (!volume) return 0;
317  TRotMatrix *rotation = 0;
318  if (matrixname && strlen(matrixname)) rotation = gGeometry->GetRotMatrix(matrixname);
319  if (!rotation) rotation = GetIdentity();
320  TVolumePosition *position = new TVolumePosition(volume,x,y,z,rotation);
321  position->SetId(id);
322  return Add(volume,position);
323 }
324 
325 ////////////////////////////////////////////////////////////////////////////////
326 ///to be documented
327 
329 {
330  if (GetListOfPositions()){
331  TVolumePosition *nodePosition = 0;
333  Int_t posNumber = 0;
334  while ( (nodePosition = (TVolumePosition *)next()) ) {
335  posNumber = nodePosition->GetId();
336  TString posName = "*";
337  posName += nodePosition->GetNode()->GetTitle();
338  char num[10];
339  posName += ";";
340  snprintf(num,10,"%d",posNumber);
341  posName += num;
342  b->Add(nodePosition,posName.Data());
343  }
344  }
345 }
346 ////////////////////////////////////////////////////////////////////////////////
347 ///to be documented
348 
350 {
351  return DistancetoNodePrimitive(px,py);
352 }
353 
354 ////////////////////////////////////////////////////////////////////////////////
355 ///*-*-*-*-*-*-*-*-*Compute distance from point px,py to a TVolumeView*-*-*-*-*-*
356 ///*-* ===========================================
357 ///*-* Compute the closest distance of approach from point px,py to the position of
358 ///*-* this volume.
359 ///*-* The distance is computed in pixels units.
360 ///*-*
361 ///*-* It is restricted by 2 levels of TVolumes
362 ///*-*
363 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
364 
366 {
367  const Int_t big = 9999;
368  if ( GetVisibility() == kNoneVisible ) return big;
369 
370  const Int_t inaxis = 7;
371  const Int_t maxdist = 5;
372 
373  Int_t puxmin = gPad->XtoAbsPixel(gPad->GetUxmin());
374  Int_t puymin = gPad->YtoAbsPixel(gPad->GetUymin());
375  Int_t puxmax = gPad->XtoAbsPixel(gPad->GetUxmax());
376  Int_t puymax = gPad->YtoAbsPixel(gPad->GetUymax());
377 
378 //*-*- return if point is not in the user area
379  if (px < puxmin - inaxis) return big;
380  if (py > puymin + inaxis) return big;
381  if (px > puxmax + inaxis) return big;
382  if (py < puymax - inaxis) return big;
383 
384  TView *view =gPad->GetView();
385  if (!view) return big;
386 
387  static TVolumePosition nullPosition;
388  TVolumePosition *position = pos;
389  if (!position) position = &nullPosition;
390  if (pos) position->UpdatePosition();
391  Int_t dist = big;
392  if ( !(GetVisibility() & kThisUnvisible ) ) {
393  TShape *shape = 0;
394  TIter nextShape(fListOfShapes);
395  while ((shape = (TShape *)nextShape())) {
396  //*-*- Distnance to the next referenced shape if visible
397  if (shape->GetVisibility()) {
398  Int_t dshape = shape->DistancetoPrimitive(px,py);
399  if (dshape < maxdist) {
400  gPad->SetSelected(this);
401  return 0;
402  }
403  if (dshape < dist) dist = dshape;
404  }
405  }
406  }
407 
408  if ( (GetVisibility() & kSonUnvisible) ) return dist;
409 
410 //*-*- Loop on all sons
411  TList *posList = GetListOfPositions();
412  Int_t dnode = dist;
413  if (posList && posList->GetSize()) {
414  gGeometry->PushLevel();
415  TVolumePosition *thisPosition;
416  TObject *obj;
417  TIter next(posList);
418  while ((obj = next())) {
419  thisPosition = (TVolumePosition*)obj;
420  TVolume *node = thisPosition->GetNode();
421  dnode = node->DistancetoNodePrimitive(px,py,thisPosition);
422  if (dnode <= 0) break;
423  if (dnode < dist) dist = dnode;
424  if (gGeometry->GeomLevel() > 2) break;
425  }
426  gGeometry->PopLevel();
427  }
428 
429  if (gGeometry->GeomLevel()==0 && dnode > maxdist) {
430  gPad->SetSelected(view);
431  return 0;
432  } else
433  return dnode;
434 }
435 
436 ////////////////////////////////////////////////////////////////////////////////
437 ///*-*-*-*-*-*-*-*-*-*-*-*Draw Referenced node with current parameters*-*-*-*
438 ///*-* =============================================
439 
440 void TVolume::Draw(Option_t *option)
441 {
442  TString opt = option;
443  opt.ToLower();
444 //*-*- Clear pad if option "same" not given
445  if (!gPad) {
446  gROOT->MakeDefCanvas();
447  }
448  if (!opt.Contains("same")) gPad->Clear();
449 
450  // Check geometry level
451 
452  Int_t iopt = atoi(option);
453  TDataSet *parent = 0;
454  char buffer[10];
455  if (iopt < 0) {
456  // set the "positive option"
457  snprintf(buffer,10,"%d",-iopt);
458  option = buffer;
459  // select parent to draw
460  parent = this;
461  do parent = parent->GetParent();
462  while (parent && ++iopt);
463  }
464  if (parent) parent->AppendPad(option);
465  else AppendPad(option);
466 #if ROOT_VERSION_CODE >= ROOT_VERSION(4,03,05)
467  // the new (4.03/05) way to active 3D viewer
468  // Create a 3-D view
469  TView *view = gPad->GetView();
470  if (!view) {
471  view = TView::CreateView(1,0,0);
472  // Set the view to perform a first autorange (frame) draw.
473  // TViewer3DPad will revert view to normal painting after this
474  view->SetAutoRange(kTRUE);
475  }
476 
477  // Create a 3D viewer to draw us
478 // gPad->GetViewer3D(option);
479  gPad->GetViewer3D();
480 #else
481  Paint(option);
482 #endif
483 }
484 
485 
486 ////////////////////////////////////////////////////////////////////////////////
487 ///*-*-*-*-*-*-*-*-*-*Draw only Sons of this node*-*-*-*-*-*-*-*-*-*-*-*-*
488 ///*-* ===========================
489 
491 {
493  Draw(option);
494 }
495 
496 
497 ////////////////////////////////////////////////////////////////////////////////
498 ///*-*-*-*-*-*-*-*-*-*-*Execute action corresponding to one event*-*-*-*
499 ///*-* =========================================
500 ///*-* This member function must be implemented to realize the action
501 ///*-* corresponding to the mouse click on the object in the window
502 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
503 
505 {
506 // if (gPad->GetView())
507 // gPad->GetView()->ExecuteRotateView(event, px, py);
508 
509 // if (!gPad->GetListOfPrimitives()->FindObject(this)) gPad->SetCursor(kCross);
510  gPad->SetCursor(kHand);
511 }
512 
513 ////////////////////////////////////////////////////////////////////////////////
514 /// Return a pointer the "identity" matrix
515 
517 {
518  Double_t *identityMatrix = 0;
519  if (!gIdentity) {
520  gIdentity = gGeometry->GetRotMatrix("Identity");
521  if (!gIdentity) {
522  gIdentity = new TRotMatrix();
523  gIdentity->SetName("Identity");
524  gIdentity->SetTitle("Identity matrix");
525  gIdentity->SetMatrix((Double_t *)0);
526  identityMatrix = gIdentity->GetMatrix();
527  memset(identityMatrix,0,9*sizeof(Double_t));
528  *identityMatrix = 1;
529  identityMatrix += 4; *identityMatrix = 1;
530  identityMatrix += 4; *identityMatrix = 1;
531  gGeometry->GetListOfMatrices()->AddFirst(gIdentity);
532  }
533  }
534  return gIdentity;
535 }
536 
537 ////////////////////////////////////////////////////////////////////////////////
538 ///to be documented
539 
541 {
542  if (!gPad) return 0;
543  static char info[512];
544  snprintf(info,512,"%s/%s",GetName(),GetTitle());
545  Double_t x[3];
546  ((TPad *)gPad)->AbsPixeltoXY(px,py,x[0],x[1]);
547  x[2] = 0;
548  TView *view =gPad->GetView();
549  if (view) view->NDCtoWC(x, x);
550 
551  TIter nextShape(fListOfShapes);
552  TShape *shape = 0;
553  while( (shape = (TShape *)nextShape()) ) {
554  Int_t nchi = strlen(info);
555  snprintf(&info[nchi],512-nchi," %6.2f/%6.2f: shape=%s/%s",x[0],x[1],shape->GetName(),shape->ClassName());
556  }
557  return info;
558 }
559 
560 ////////////////////////////////////////////////////////////////////////////////
561 ///*-*-*-*-*-*-*Copy shape attributes as node attributes*-*-*-*-*--*-*-*-*-*-*
562 ///*-* ========================================
563 
565 {
566  if (fShape) {
572  }
573 
574  if (!GetCollection()) return;
575  TVolume *volume;
577  while ( (volume = (TVolume *)next()) )
578  volume->ImportShapeAttributes();
579 }
580 
581 ////////////////////////////////////////////////////////////////////////////////
582 ///*-*- Draw Referenced node
583 
585 {
588  PaintNodePosition(opt);
589  return;
590 }
591 
592 ////////////////////////////////////////////////////////////////////////////////
593 ///*-*-*-*-*-*-*-*-*-*-*-*Paint Referenced volume with current parameters*-*-*-*
594 ///*-* ==============================================
595 ///*-*
596 ///*-* vis = 1 (default) shape is drawn
597 ///*-* vis = 0 shape is not drawn but its sons may be not drawn
598 ///*-* vis = -1 shape is not drawn. Its sons are not drawn
599 ///*-* vis = -2 shape is drawn. Its sons are not drawn
600 ///*-*
601 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
602 
604 {
605  if ( GetVisibility() == kNoneVisible ) return;
606 
607  static TVolumePosition nullPosition;
608 
609 // restrict the levels for "range" option
610  Int_t level = gGeometry->GeomLevel();
611 // if (option && option[0]=='r' && level > 3 && strcmp(option,"range") == 0) return;
612  if ((!(GetVisibility() & kThisUnvisible)) && option && option[0]=='r' && level > 3 ) return;
613  Int_t iopt = 0;
614  if (option) iopt = atoi(option);
615  if ( (0 < iopt) && (iopt <= level) ) return;
616 
617  TTablePadView3D *view3D = (TTablePadView3D*)gPad->GetView3D();
618  TVirtualViewer3D * viewer3D = gPad->GetViewer3D();
619 
620  TVolumePosition *position = pos;
621  if (!position) position = &nullPosition;
622 
623  // PaintPosition does change the current matrix and it MUST be callled FIRST !!!
624 
625  position->UpdatePosition(option);
626 
627  if ( viewer3D && !(GetVisibility() & kThisUnvisible)) PaintShape(option);
628 
629  if (GetVisibility() & kSonUnvisible) return;
630 
631 //*-*- Paint all sons
632  TList *posList = GetListOfPositions();
633  if (posList && posList->GetSize()) {
634  gGeometry->PushLevel();
635  TVolumePosition *thisPosition;
636  TIter next(posList);
637  while ((thisPosition = (TVolumePosition *)next())) {
638  if (view3D) view3D->PushMatrix();
639 
640  TVolume *volume = thisPosition->GetNode();
641  if (volume) volume->PaintNodePosition(option,thisPosition);
642 
643  if (view3D) view3D->PopMatrix();
644  }
645  gGeometry->PopLevel();
646  }
647 }
648 
649 ////////////////////////////////////////////////////////////////////////////////
650 /// Paint shape of the volume
651 /// To be called from the TObject::Paint method only
652 
654 {
655  Bool_t rangeView = option && option[0]=='r';
656  if (!rangeView) {
659  }
660 
661  if ( (GetVisibility() & kThisUnvisible) ) return;
662 
663  TIter nextShape(fListOfShapes);
664  TShape *shape = 0;
665  while( (shape = (TShape *)nextShape()) ) {
666  if (!rangeView) {
667  shape->SetLineColor(GetLineColor());
668  shape->SetLineStyle(GetLineStyle());
669  shape->SetLineWidth(GetLineWidth());
670  shape->SetFillColor(GetFillColor());
671  shape->SetFillStyle(GetFillStyle());
672  TTablePadView3D *view3D = (TTablePadView3D*)gPad->GetView3D();
673  gPad->GetViewer3D();
674  if (view3D)
675  view3D->SetLineAttr(GetLineColor(),GetLineWidth(),option);
676  }
677 
678 #if ROOT_VERSION_CODE >= ROOT_VERSION(4,03,05)
679  // It MUST be the TShape::Paint method:
680  Bool_t viewerWantsSons = kTRUE;
681  TVirtualViewer3D * viewer3D = gPad->GetViewer3D();
682  if (viewer3D) {
683  // We only provide master frame positions in these shapes
684  // so don't ask viewer preference
685 
686  // Ask all shapes for kCore/kBoundingBox/kShapeSpecific
687  // Not all will support the last two - which is fine
688  const TBuffer3D & buffer =
690 
691  // TShape sets buffer id based on TNode * gNode
692  // As we not using TNode we need to override this
693  const_cast<TBuffer3D &>(buffer).fID = this;
694 
695  Int_t reqSections = viewer3D->AddObject(buffer, &viewerWantsSons);
696  if (reqSections != TBuffer3D::kNone) {
697  fShape->GetBuffer3D(reqSections);
698  viewer3D->AddObject(buffer);
699  }
700  }
701 #else
702  shape->Paint(option);
703 #endif
704  }
705 }
706 
707 ////////////////////////////////////////////////////////////////////////////////
708 /// DeletePosition deletes the position of the TVolume *node from this TVolume
709 /// and removes that volume from the list of the nodes of this TVolume
710 
712 {
713  if (!position) return;
714 
715  if (GetListOfPositions()) {
717  while (lnk) {
718  TVolumePosition *nextPosition = (TVolumePosition *)(lnk->GetObject());
719  if (nextPosition && nextPosition == position) {
720  TVolume *node = nextPosition->GetNode();
721  GetListOfPositions()->Remove(lnk);
722  delete nextPosition;
723  Remove(node);
724  break;
725  }
726  lnk = lnk->Next();
727  }
728  }
729 }
730 
731 ////////////////////////////////////////////////////////////////////////////////
732 /// GetRange
733 ///
734 /// Calculates the size of 3 box the volume occupies,
735 /// Return:
736 /// two floating point arrays with the bound of box
737 /// surroundind all shapes of this TVolumeView
738 ///
739 
741 {
742  TVirtualPad *savePad = gPad;
743  // Create a dummy TPad;
744  TCanvas dummyPad("--Dumm--","dum",1,1);
745  // Assing 3D TView
746  TView *view = TView::CreateView(1,0,0);
747 
750  view->SetAutoRange(kTRUE);
751  Paint("range");
752  view->GetRange(&min[0],&max[0]);
753  delete view;
754  // restore "current pad"
755  if (savePad) savePad->cd();
756 }
757 
758 ////////////////////////////////////////////////////////////////////////////////
759 ///*-*-*-*-*-*-*Set visibility for this volume and its sons*-*-*-*-*--*-*-*-*-*-*
760 ///*-* =========================================
761 /// ENodeSEEN Visibility flag 00 - everything visible,
762 /// 10 - this unvisible, but sons are visible
763 /// 01 - this visible but sons
764 /// 11 - neither this nor its sons are visible
765 ///*-*
766 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
767 
769 {
770  fVisibility = vis;
771 }
772 
773 ////////////////////////////////////////////////////////////////////////////////
774 ///*-*-*-*-*-*-*Return total size of this 3-D volume with its attributes*-*-*
775 ///*-* ==========================================================
776 
777 void TVolume::Sizeof3D() const
778 {
779  if (!(GetVisibility() & kThisUnvisible) ) {
780  TIter nextShape(fListOfShapes);
781  TShape *shape = 0;
782  while( (shape = (TShape *)nextShape()) ) {
783  if (shape->GetVisibility()) shape->Sizeof3D();
784  }
785  }
786 
787  if ( GetVisibility() & kSonUnvisible ) return;
788 
789  if (!Nodes()) return;
790  TVolume *node;
791  TObject *obj;
792  TIter next(Nodes());
793  while ((obj = next())) {
794  node = (TVolume*)obj;
795  node->Sizeof3D();
796  }
797 }
virtual void DeletePosition(TVolumePosition *position)
DeletePosition deletes the position of the TVolume *node from this TVolume and removes that volume fr...
Definition: TVolume.cxx:711
void Add(TObject *obj, const char *name=0, Int_t check=-1)
Add object with name to browser.
Definition: TBrowser.cxx:259
THashList * GetListOfMatrices() const
Definition: TGeometry.h:82
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 Double_t GetY() const
Definition: TNode.h:84
void AddFirst(TObject *obj)
Add object at the beginning of the list.
Definition: THashList.cxx:68
static Double_t gTranslation[kMAXLEVELS][kVectorSize]
Definition: TNode.cxx:32
double dist(Rotation3D const &r1, Rotation3D const &r2)
Definition: 3DDistances.cxx:48
virtual void Add(TDataSet *dataset)
Definition: TDataSet.h:150
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:405
tuple buffer
Definition: tree.py:99
static Vc_ALWAYS_INLINE int_v min(const int_v &x, const int_v &y)
Definition: vector.h:433
virtual Double_t GetY() const
static Int_t MapGEANT2StNodeVis(Int_t vis)
Definition: TVolume.cxx:155
virtual TVolume * GetNode() const
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Computes distance from point (px,py) to the object.
Definition: TObject.cxx:245
float Float_t
Definition: RtypesCore.h:53
static Int_t MapStNode2GEANTVis(ENodeSEEN vis)
ENodeSEEN Visibility flag 00 - everything visible, 10 - this unvisible, but sons are visible 01 - thi...
Definition: TVolume.cxx:147
static Int_t gGeomLevel
Definition: TNode.cxx:34
const char Option_t
Definition: RtypesCore.h:62
ENodeSEEN
Definition: TVolume.h:44
virtual UInt_t GetId() const
virtual void SetName(const char *name)
Change (i.e.
Definition: TNamed.cxx:128
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
const Int_t kMAXLEVELS
Definition: TGeometry.h:31
TNode description.
Definition: TNode.h:43
#define gROOT
Definition: TROOT.h:344
TList * fListOfShapes
Definition: TVolume.h:50
const Option_t * GetOption() const
Definition: TVolume.h:84
ENodeSEEN fVisibility
Definition: TVolume.h:52
Basic string class.
Definition: TString.h:137
virtual Double_t GetZ() const
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1075
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual void SetFillStyle(Style_t fstyle)
Definition: TAttFill.h:52
virtual void Draw(Option_t *depth="3")
*-*-*-*-*-*-*-*-*-*-*-*Draw Referenced node with current parameters*-*-*-* *-* ======================...
Definition: TVolume.cxx:440
virtual void Remove(TDataSet *set)
Remiove the "set" from this TDataSet.
Definition: TDataSet.cxx:641
virtual void Modify()
Change current line attributes if necessary.
Definition: TAttLine.cxx:229
Float_t py
Definition: hprod.C:33
virtual TDataSet * GetParent() const
Definition: TDataSet.h:111
virtual void SetMatrix(const Double_t *matrix)
copy predefined 3x3 matrix into TRotMatrix object
Definition: TRotMatrix.cxx:216
virtual void NDCtoWC(const Float_t *pn, Float_t *pw)=0
virtual TVirtualPad * cd(Int_t subpadnumber=0)=0
virtual TSeqCollection * GetCollection() const
Definition: TDataSet.h:105
virtual void PaintShape(Option_t *option="")
Paint shape of the volume To be called from the TObject::Paint method only.
Definition: TVolume.cxx:653
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition: TObject.cxx:164
const char * Data() const
Definition: TString.h:349
#define SafeDelete(p)
Definition: RConfig.h:436
Fill Area Attributes class.
Definition: TAttFill.h:32
Double_t x[n]
Definition: legend1.C:17
virtual void Paint(Option_t *option="")
*-*- Draw Referenced node
Definition: TVolume.cxx:584
virtual void Add(TDataSet *dataset)
Definition: TVolume.h:103
const Int_t kVectorSize
Definition: TGeometry.h:32
virtual void SetVisibility(Int_t vis=1)
Set visibility for this node and its sons.
Definition: TNode.cxx:759
TRotMatrix * GetRotMatrix(const char *name) const
Return pointer to RotMatrix with name.
Definition: TGeometry.cxx:356
virtual void SetVisibility(ENodeSEEN vis=TVolume::kBothVisible)
*-*-*-*-*-*-*Set visibility for this volume and its sons*-*-*-*-*–*-*-*-*-*-* *-* ===================...
Definition: TVolume.cxx:768
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
virtual void ImportShapeAttributes()
*-*-*-*-*-*-*Copy shape attributes as node attributes*-*-*-*-*–*-*-*-*-*-* *-* ======================...
Definition: TVolume.cxx:564
virtual void Sizeof3D() const
virtual TList * GetListOfPositions()
Definition: TVolume.h:89
virtual Int_t PushLevel()
Definition: TGeometry.h:103
TShape * fShape
Definition: TVolume.h:49
const TRotMatrix * GetMatrix() const
Abstract 3D shapes viewer.
virtual void Sizeof3D() const
*-*-*-*-*-*-*Return total size of this 3-D volume with its attributes*-*-* *-* ======================...
Definition: TVolume.cxx:777
static TRotMatrix * GetIdentity()
Return a pointer the "identity" matrix.
Definition: TVolume.cxx:516
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:918
Int_t GetVisibility() const
Definition: TNode.h:82
Float_t z[5]
Definition: Ifit.C:16
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition: TVirtualPad.h:59
short Color_t
Definition: RtypesCore.h:79
virtual const TBuffer3D & GetBuffer3D(Int_t reqSections) const
Stub to avoid forcing implementation at this stage.
Definition: TShape.cxx:253
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
to be documented
Definition: TVolume.cxx:349
A doubly linked list.
Definition: TList.h:47
virtual Double_t GetX() const
Definition: TNode.h:83
TGeometry description.
Definition: TGeometry.h:43
virtual void SetLineColor(Color_t lcolor)
Definition: TAttLine.h:54
const Option_t * GetOption() const
Definition: TNode.h:79
R__EXTERN TNode * gNode
Definition: TShape.h:80
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:41
TShape * GetShape() const
Definition: TNode.h:81
virtual void SetName(const char *name)
Change (i.e.
Definition: TRotMatrix.h:71
virtual ~TVolume()
*-*-*-*-*-*-*-*-*-*-*Volume default destructor*-*-*-*-*-*-*-*-*-*-*-*-*-* *-* ====================== ...
Definition: TVolume.cxx:250
static TRotMatrix * gIdentity
Definition: TVolume.cxx:46
This is the base class for all geometry shapes.
Definition: TShape.h:47
Manages a detector rotation matrix.
Definition: TRotMatrix.h:30
virtual void PaintNodePosition(Option_t *option="", TVolumePosition *postion=0)
*-*-*-*-*-*-*-*-*-*-*-*Paint Referenced volume with current parameters*-*-*-* *-* ===================...
Definition: TVolume.cxx:603
TPaveLabel title(3, 27.1, 15, 28.7,"ROOT Environment and Tools")
virtual void SetFillColor(Color_t fcolor)
Definition: TAttFill.h:50
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:187
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:675
virtual void Browse(TBrowser *b)
to be documented
Definition: TVolume.cxx:328
virtual Color_t GetFillColor() const
Definition: TAttFill.h:43
virtual Double_t GetZ() const
Definition: TNode.h:85
Int_t GetVisibility() const
Definition: TShape.h:70
virtual void UpdatePosition(Option_t *option="")
to be documented
virtual Int_t AddObject(const TBuffer3D &buffer, Bool_t *addChildren=0)=0
virtual TNode * CreateTNode(const TVolumePosition *position=0)
Convert a TVolume object into a TNode.
Definition: TVolume.cxx:207
unsigned int UInt_t
Definition: RtypesCore.h:42
The most important graphics class in the ROOT system.
Definition: TPad.h:46
TList * GetListOfNodes() const
Definition: TNode.h:75
Generic 3D primitive description class.
Definition: TBuffer3D.h:19
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
virtual Double_t GetX(Int_t indx=0) const
virtual TObjLink * FirstLink() const
Definition: TList.h:101
virtual void ImportShapeAttributes()
Copy shape attributes as node attributes.
Definition: TNode.cxx:410
virtual Color_t GetLineColor() const
Definition: TAttLine.h:47
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
*-*-*-*-*-*-*-*-*-*-*Execute action corresponding to one event*-*-*-* *-* ===========================...
Definition: TVolume.cxx:504
Int_t GeomLevel() const
Definition: TGeometry.h:78
TShape * GetShape() const
Definition: TVolume.h:85
virtual void SetId(UInt_t id)
virtual void DrawOnly(Option_t *option="")
*-*-*-*-*-*-*-*-*-*Draw only Sons of this node*-*-*-*-*-*-*-*-*-*-*-*-* *-* =========================...
Definition: TVolume.cxx:490
virtual void Paint(Option_t *option="")
This method is used only when a shape is painted outside a TNode.
Definition: TShape.cxx:143
The Canvas class.
Definition: TCanvas.h:48
virtual ENodeSEEN GetVisibility() const
Definition: TVolume.h:88
virtual Int_t GetSize() const
Definition: TCollection.h:95
double Double_t
Definition: RtypesCore.h:55
virtual char * GetObjectInfo(Int_t px, Int_t py) const
to be documented
Definition: TVolume.cxx:540
Double_t y[n]
Definition: legend1.C:17
TString fOption
Definition: TVolume.h:51
void SetPositionsList(TList *list=0)
Definition: TVolume.h:61
virtual Int_t DistancetoNodePrimitive(Int_t px, Int_t py, TVolumePosition *position=0)
*-*-*-*-*-*-*-*-*Compute distance from point px,py to a TVolumeView*-*-*-*-*-* *-* ==================...
Definition: TVolume.cxx:365
const Int_t kMatrixSize
Definition: TGeometry.h:33
tuple view
Definition: tornado.py:20
virtual void SetLineAttr(Color_t color, Int_t width, Option_t *opt="")
virtual void SetGeomLevel(Int_t level=0)
Definition: TGeometry.h:108
virtual void SetLineStyle(Style_t lstyle)
Definition: TAttLine.h:56
static Vc_ALWAYS_INLINE int_v max(const int_v &x, const int_v &y)
Definition: vector.h:440
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
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
Float_t px
Definition: hprod.C:33
virtual TRotMatrix * GetMatrix() const
Definition: TNode.h:76
virtual void Add(TObject *obj)
Definition: TList.h:81
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:567
virtual void GetLocalRange(Float_t *min, Float_t *max)
GetRange.
Definition: TVolume.cxx:740
virtual void GetRange(Float_t *min, Float_t *max)=0
static Double_t gRotMatrix[kMAXLEVELS][kMatrixSize]
Definition: TNode.cxx:33
#define gPad
Definition: TVirtualPad.h:288
virtual TList * Nodes() const
Definition: TVolume.h:94
virtual void PopMatrix()
const Bool_t kTRUE
Definition: Rtypes.h:91
virtual Width_t GetLineWidth() const
Definition: TAttLine.h:49
virtual void SetTitle(const char *title="")
Change (i.e. set) the title of the TNamed.
Definition: TNamed.cxx:152
R__EXTERN TGeometry * gGeometry
Definition: TGeometry.h:162
TObject * obj
virtual Int_t PopLevel()
Definition: TGeometry.h:104
Line Attributes class.
Definition: TAttLine.h:32
virtual void PushMatrix()
ClassImp(TVolume) TVolume
*-*-*-*-*-*-*-*-*-*-*Volume default constructor*-*-*-*-*-*-*-*-*-*-*-*-* *-* ========================...
Definition: TVolume.cxx:48
TObject * FindObject(const char *name) const
Must be redefined in derived classes.
Definition: TDataSet.h:101