12 #include "Riostream.h"
17 #include "TVirtualPad.h"
19 #include "TGeometry.h"
20 #include "TRotMatrix.h"
24 #include "X3DBuffer.h"
26 #include "TTablePadView3D.h"
29 #include "TRotMatrix.h"
30 #include "TVolumePosition.h"
31 #include "TVirtualViewer3D.h"
32 #include "TBuffer3D.h"
35 const Int_t kVectorSize = 3;
36 const Int_t kMatrixSize = kVectorSize*kVectorSize;
37 const Int_t kMAXLEVELS = 20;
39 static Double_t gTranslation[kMAXLEVELS][kVectorSize];
40 static Double_t gRotMatrix[kMAXLEVELS][kMatrixSize];
41 static Int_t gGeomLevel = 0;
46 static TRotMatrix *gIdentity = 0;
51 TDataSet::Add(dataset);
79 fVisibility = kBothVisible;
80 if (!gGeometry)
new TGeometry;
90 TVolume::TVolume(
const char *name,
const char *title,
const char *shapename, Option_t *option)
91 :
TObjectSet(name),TAttLine(), TAttFill(),fShape(0),fListOfShapes(0)
98 static Int_t counter = 0;
101 if(!(counter%1000))std::cout<<
"TVolume count="<<counter<<
" name="<<name<<std::endl;
102 if (!gGeometry)
new TGeometry;
103 Add(gGeometry->GetShape(shapename),kTRUE);
106 fVisibility = kBothVisible;
108 if(fShape) ImportShapeAttributes();
118 TVolume::TVolume(
const char *name,
const char *title, TShape *shape, Option_t *option)
119 :
TObjectSet(name),TAttLine(),TAttFill(),fShape(0),fListOfShapes(0)
124 SetLineColor(lcolor);
127 if (!gGeometry)
new TGeometry;
130 fVisibility = kBothVisible;
132 if(shape) ImportShapeAttributes();
144 const Int_t mapVis[4] = {1, -2, 0, -1 };
154 const Int_t mapVis[4] = {1, -2, 0, -1 };
157 for (i =0; i<3;i++)
if (mapVis[i] == vis)
return i;
166 SetName(rootNode.GetName());
167 SetTitle(rootNode.GetTitle());
169 fOption = rootNode.GetOption();
170 Add(rootNode.GetShape(),kTRUE);
172 SetLineColor(rootNode.GetLineColor());
173 SetLineStyle(rootNode.GetLineStyle());
174 SetLineWidth(rootNode.GetLineWidth());
175 SetFillColor(rootNode.GetFillColor());
176 SetFillStyle(rootNode.GetFillStyle());
178 TList *nodes = rootNode.GetListOfNodes();
182 while ( (node = (TNode *) next()) ){
184 Add(nextNode,node->GetX(),node->GetY(),node->GetZ(),node->GetMatrix());
192 void TVolume::Add(TShape *shape, Bool_t IsMaster)
195 if (!fListOfShapes) fListOfShapes =
new TList;
196 fListOfShapes->Add(shape);
197 if (IsMaster) fShape = shape;
208 const TRotMatrix* matrix = 0;
213 matrix = position->GetMatrix();
217 TNode *newNode =
new TNode(GetName(),GetTitle(),GetShape(),x,y,z,(TRotMatrix* )matrix,GetOption());
220 newNode->SetLineColor(GetLineColor());
221 newNode->SetLineStyle(GetLineStyle());
222 newNode->SetLineWidth(GetLineWidth());
223 newNode->SetFillColor(GetFillColor());
224 newNode->SetFillStyle(GetFillStyle());
226 TList *positions = GetListOfPositions();
228 TIter next(positions);
231 TVolume *node = pos->GetNode();
238 newNode->ImportShapeAttributes();
250 if (GetListOfPositions()) {
251 GetListOfPositions()->Delete();
254 SafeDelete(fListOfShapes);
257 ROOT::CallRecursiveRemoveIfNeeded(*
this);
265 if (!GetListOfPositions()) SetPositionsList(
new TList);
266 if ( GetListOfPositions()) GetListOfPositions()->Add(position);
267 else Error(
"Add",
"Can not create list of positions for the current node <%s>:<%s>",GetName(),GetTitle());
279 if (!(GetCollection() && GetCollection()->FindObject(node)) ) TDataSet::Add(node);
292 TRotMatrix *matrix, UInt_t
id, Option_t *)
294 if (!volume)
return 0;
295 TRotMatrix *rotation = matrix;
299 return Add(volume,position);
310 const char *matrixname, UInt_t
id, Option_t *)
312 if (!volume)
return 0;
313 TRotMatrix *rotation = 0;
314 if (matrixname && strlen(matrixname)) rotation = gGeometry->GetRotMatrix(matrixname);
318 return Add(volume,position);
326 if (GetListOfPositions()){
328 TIter next(GetListOfPositions());
331 posNumber = nodePosition->GetId();
332 TString posName =
"*";
333 posName += nodePosition->GetNode()->GetTitle();
336 snprintf(num,10,
"%d",posNumber);
338 b->Add(nodePosition,posName.Data());
361 const Int_t big = 9999;
362 if ( GetVisibility() == kNoneVisible )
return big;
364 const Int_t inaxis = 7;
365 const Int_t maxdist = 5;
367 Int_t puxmin = gPad->XtoAbsPixel(gPad->GetUxmin());
368 Int_t puymin = gPad->YtoAbsPixel(gPad->GetUymin());
369 Int_t puxmax = gPad->XtoAbsPixel(gPad->GetUxmax());
370 Int_t puymax = gPad->YtoAbsPixel(gPad->GetUymax());
373 if (px < puxmin - inaxis)
return big;
374 if (py > puymin + inaxis)
return big;
375 if (px > puxmax + inaxis)
return big;
376 if (py < puymax - inaxis)
return big;
378 TView *view =gPad->GetView();
379 if (!view)
return big;
383 if (!position) position = &nullPosition;
386 if ( !(GetVisibility() & kThisUnvisible ) ) {
388 TIter nextShape(fListOfShapes);
389 while ((shape = (TShape *)nextShape())) {
391 if (shape->GetVisibility()) {
392 Int_t dshape = shape->DistancetoPrimitive(px,py);
393 if (dshape < maxdist) {
394 gPad->SetSelected(
this);
397 if (dshape < dist) dist = dshape;
402 if ( (GetVisibility() & kSonUnvisible) )
return dist;
405 TList *posList = GetListOfPositions();
407 if (posList && posList->GetSize()) {
408 gGeometry->PushLevel();
412 while ((obj = next())) {
414 TVolume *node = thisPosition->GetNode();
416 if (dnode <= 0)
break;
417 if (dnode < dist) dist = dnode;
418 if (gGeometry->GeomLevel() > 2)
break;
420 gGeometry->PopLevel();
423 if (gGeometry->GeomLevel()==0 && dnode > maxdist) {
424 gPad->SetSelected(view);
435 TString opt = option;
439 gROOT->MakeDefCanvas();
441 if (!opt.Contains(
"same")) gPad->Clear();
445 Int_t iopt = atoi(option);
450 snprintf(buffer,12,
"%d",-iopt);
454 do parent = parent->GetParent();
455 while (parent && ++iopt);
457 if (parent) parent->AppendPad(option);
458 else AppendPad(option);
459 #if ROOT_VERSION_CODE >= ROOT_VERSION(4,03,05)
462 TView *view = gPad->GetView();
464 view = TView::CreateView(1,0,0);
467 view->SetAutoRange(kTRUE);
482 void TVolume::DrawOnly(Option_t *option)
495 void TVolume::ExecuteEvent(Int_t, Int_t, Int_t)
501 gPad->SetCursor(kHand);
509 Double_t *identityMatrix = 0;
511 gIdentity = gGeometry->GetRotMatrix(
"Identity");
513 gIdentity =
new TRotMatrix();
514 gIdentity->SetName(
"Identity");
515 gIdentity->SetTitle(
"Identity matrix");
516 gIdentity->SetMatrix((Double_t *)0);
517 identityMatrix = gIdentity->GetMatrix();
518 memset(identityMatrix,0,9*
sizeof(Double_t));
520 identityMatrix += 4; *identityMatrix = 1;
521 identityMatrix += 4; *identityMatrix = 1;
522 gGeometry->GetListOfMatrices()->AddFirst(gIdentity);
534 static char info[512];
535 snprintf(info,512,
"%s/%s",GetName(),GetTitle());
537 ((TPad *)gPad)->AbsPixeltoXY(px,py,x[0],x[1]);
539 TView *view =gPad->GetView();
540 if (view) view->NDCtoWC(x, x);
542 TIter nextShape(fListOfShapes);
544 while( (shape = (TShape *)nextShape()) ) {
545 Int_t nchi = strlen(info);
546 snprintf(&info[nchi],512-nchi,
" %6.2f/%6.2f: shape=%s/%s",x[0],x[1],shape->GetName(),shape->ClassName());
554 void TVolume::ImportShapeAttributes()
557 SetLineColor(fShape->GetLineColor());
558 SetLineStyle(fShape->GetLineStyle());
559 SetLineWidth(fShape->GetLineWidth());
560 SetFillColor(fShape->GetFillColor());
561 SetFillStyle(fShape->GetFillStyle());
564 if (!GetCollection())
return;
566 TIter next(GetCollection());
567 while ( (volume = (
TVolume *)next()) )
568 volume->ImportShapeAttributes();
574 void TVolume::Paint(Option_t *opt)
576 gGeometry->SetGeomLevel();
577 gGeometry->UpdateTempMatrix();
593 if ( GetVisibility() == kNoneVisible )
return;
598 Int_t level = gGeometry->GeomLevel();
600 if ((!(GetVisibility() & kThisUnvisible)) && option && option[0]==
'r' && level > 3 )
return;
602 if (option) iopt = atoi(option);
603 if ( (0 < iopt) && (iopt <= level) )
return;
606 TVirtualViewer3D * viewer3D = gPad->GetViewer3D();
609 if (!position) position = &nullPosition;
615 if ( viewer3D && !(GetVisibility() & kThisUnvisible))
PaintShape(option);
617 if (GetVisibility() & kSonUnvisible)
return;
620 TList *posList = GetListOfPositions();
621 if (posList && posList->GetSize()) {
622 gGeometry->PushLevel();
626 if (view3D) view3D->PushMatrix();
628 TVolume *volume = thisPosition->GetNode();
631 if (view3D) view3D->PopMatrix();
633 gGeometry->PopLevel();
643 Bool_t rangeView = option && option[0]==
'r';
649 if ( (GetVisibility() & kThisUnvisible) )
return;
651 TIter nextShape(fListOfShapes);
653 while( (shape = (TShape *)nextShape()) ) {
655 shape->SetLineColor(GetLineColor());
656 shape->SetLineStyle(GetLineStyle());
657 shape->SetLineWidth(GetLineWidth());
658 shape->SetFillColor(GetFillColor());
659 shape->SetFillStyle(GetFillStyle());
663 view3D->SetLineAttr(GetLineColor(),GetLineWidth(),option);
666 #if ROOT_VERSION_CODE >= ROOT_VERSION(4,03,05)
668 Bool_t viewerWantsSons = kTRUE;
669 TVirtualViewer3D * viewer3D = gPad->GetViewer3D();
676 const TBuffer3D & buffer =
677 fShape->GetBuffer3D(TBuffer3D::kCore|TBuffer3D::kBoundingBox|TBuffer3D::kShapeSpecific);
681 const_cast<TBuffer3D &
>(buffer).fID =
this;
683 Int_t reqSections = viewer3D->AddObject(buffer, &viewerWantsSons);
684 if (reqSections != TBuffer3D::kNone) {
685 fShape->GetBuffer3D(reqSections);
686 viewer3D->AddObject(buffer);
690 shape->Paint(option);
701 if (!position)
return;
703 if (GetListOfPositions()) {
704 TObjLink *lnk = GetListOfPositions()->FirstLink();
707 if (nextPosition && nextPosition == position) {
708 TVolume *node = nextPosition->GetNode();
709 GetListOfPositions()->Remove(lnk);
729 TVirtualPad *savePad = gPad;
731 TCanvas dummyPad(
"--Dumm--",
"dum",1,1);
733 TView *view = TView::CreateView(1,0,0);
735 gGeometry->SetGeomLevel();
736 gGeometry->UpdateTempMatrix();
737 view->SetAutoRange(kTRUE);
739 view->GetRange(&min[0],&max[0]);
742 if (savePad) savePad->cd();
761 void TVolume::Sizeof3D()
const
763 if (!(GetVisibility() & kThisUnvisible) ) {
764 TIter nextShape(fListOfShapes);
766 while( (shape = (TShape *)nextShape()) ) {
767 if (shape->GetVisibility()) shape->Sizeof3D();
771 if ( GetVisibility() & kSonUnvisible )
return;
773 if (!Nodes())
return;
777 while ((obj = next())) {
virtual void DeletePosition(TVolumePosition *position)
static Int_t MapGEANT2StNodeVis(Int_t vis)
static Int_t MapStNode2GEANTVis(ENodeSEEN vis)
virtual void Draw(Option_t *depth="3")
virtual void Remove(TDataSet *set)
Remiove the "set" from this TDataSet.
virtual void PaintShape(Option_t *option="")
virtual void SetVisibility(ENodeSEEN vis=TVolume::kBothVisible)
static TRotMatrix * GetIdentity()
Return a pointer the "identity" matrix.
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
to be documented
virtual void PaintNodePosition(Option_t *option="", TVolumePosition *postion=0)
virtual void Browse(TBrowser *b)
to be documented
virtual void UpdatePosition(Option_t *option="")
to be documented
virtual TNode * CreateTNode(const TVolumePosition *position=0)
Convert a TVolume object into a TNode.
virtual char * GetObjectInfo(Int_t px, Int_t py) const
to be documented
virtual Int_t DistancetoNodePrimitive(Int_t px, Int_t py, TVolumePosition *position=0)
virtual void GetLocalRange(Float_t *min, Float_t *max)