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