Logo ROOT   6.10/09
Reference Guide
TVolumeView.cxx
Go to the documentation of this file.
1 // @(#)root/table:$Id$
2 // Author: Valery Fine(fine@bnl.gov) 25/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 
13 #include "Riostream.h"
14 #include <assert.h>
15 #include <stdlib.h>
16 
17 #include "TCanvas.h"
18 #include "TPad.h"
19 #include "TCernLib.h"
20 #include "TBrowser.h"
21 #include "TVolumeView.h"
22 #include "TVolumeViewIter.h"
23 #include "TVolumePosition.h"
24 #include "TROOT.h"
25 #include "TView.h"
26 #include "TTablePadView3D.h"
27 #include "TGeometry.h"
28 #include "TVirtualPad.h"
29 #include "TObjArray.h"
30 #include "TVirtualViewer3D.h"
31 #include "TBuffer3D.h"
32 
33 //////////////////////////////////////////////////////////////////////////
34 // //
35 // TVolumeView //
36 // //
37 // TVolumeView class is a special kind of TDataSet with one extra //
38 // pointer to wrap any TObject onto TDataSet object //
39 // //
40 // BE CAREFUL !!! //
41 // One has to use it carefully no control over that extra object //
42 // is performed. This means: the object m_Obj data-member points to can//
43 // be destroyed with no this kbject notifying. //
44 // There is no tool /protection to check whether m_Obj is till alive. //
45 // It is one's code responsilitiy //
46 // //
47 //////////////////////////////////////////////////////////////////////////
48 
50 
51 ////////////////////////////////////////////////////////////////////////////////
52 
54  : TObjectSet(viewNode->GetName(),(TObject *)nodePosition),fListOfShapes(0)
55  // ,fListOfAttributes(0)
56 {
57  //
58  // This ctor creates a TVolumeView structure from the "marked" nodes
59  // of the "viewNode" input structure
60  // It re-calculates all positions according of the new topology
61  // All new TVolume became UNMARKED though
62  //
63  if (!gGeometry) new TGeometry;
64  if (viewNode) {
65  SetTitle(viewNode->GetTitle());
66  EDataSetPass mode = kContinue;
67  TVolumeViewIter next(viewNode,0);
68  TVolumeView *nextView = 0;
69  while ( (nextView = (TVolumeView *)next(mode)) ){
70  mode = kContinue;
71  if (nextView->IsMarked()) {
72  TVolumePosition *position =next[0];
73  if (!position->GetNode()) {
74  Error("TVolumeView ctor","%s %s ",GetName(),nextView->GetName());
75  }
76  Add(new TVolumeView(nextView,position));
77  mode = kPrune;
78  }
79  }
80  }
81 }
82 
83 ////////////////////////////////////////////////////////////////////////////////
84 
86  : TObjectSet(viewNode->GetName(),(TObject *)0),fListOfShapes(0)
87  // ,fListOfAttributes(0)
88 {
89  //
90  // This ctor creates a TVolumeView structure containing:
91  //
92  // - viewNode on the top
93  // - skip ALL node from the original viewNode untill topNode found
94  // - include all "marked" node below "topNode" if any
95  // topNode is always included
96  //
97  // It re-calculates all positions according of the new topology
98  //
99  if (!gGeometry) new TGeometry;
100  if (viewNode && topNode) {
101  SetTitle(viewNode->GetTitle());
102  // define the depth of the "top" Node
103  EDataSetPass mode = kContinue;
104  TVolumeViewIter next(viewNode,0);
105  TVolumeView *nextView = 0;
106  while ( (nextView = (TVolumeView *)next(mode)) ){
107  mode = kContinue;
108  // Skip till "top Node" found
109  if (topNode != nextView) continue;
110  TVolumePosition *position = next[0];
111  if (!position->GetNode()) {
112  Error("TVolumeView ctor","%s %s ",GetName(),nextView->GetName());
113  }
114  Add(new TVolumeView(nextView,position));
115  break;
116  }
117  }
118 }
119 
120 ////////////////////////////////////////////////////////////////////////////////
121 
122 TVolumeView::TVolumeView(TVolumeView *viewNode,const Char_t *nodeName1,const Char_t *nodeName2)
123  : TObjectSet(viewNode->GetName(),(TObject *)0),fListOfShapes(0)
124  // ,fListOfAttributes(0)
125 {
126  //
127  // This ctor creates a TVolumeView structure containing:
128  //
129  // - viewNode on the top
130  // - skip ALL node from the original viewNode untill topNodeName found
131  // - include all "marked" node below "topNodename" if any
132  // topNodeName is always included
133  //
134  // It re-calculates all positions according of the new topology
135  //
136  const Char_t *foundName[2] = {nodeName1, nodeName2};
137  Bool_t found = kFALSE;
138  if (!gGeometry) new TGeometry;
139  if (viewNode && nodeName1 && nodeName1[0]) {
140  SetTitle(viewNode->GetTitle());
141  // define the depth of the "top" Node
142  EDataSetPass mode = kContinue;
143  TVolumeViewIter next(viewNode,0);
144  TVolumeView *nextView = 0;
145  while ( (nextView = (TVolumeView *)next(mode)) ){
146  mode = kContinue;
147  // Skip till "top Node" found
148  Int_t i = 0;
149  found = kFALSE;
150  for (i=0;i<2;i++) {
151  if (foundName[i]) {
152  if (strcmp(nextView->GetName(),foundName[i])) continue;
153  foundName[i] = 0;
154  found = kTRUE;
155  break;
156  }
157  }
158  if (!found) continue;
159  TVolumePosition *position = next[0];
160  if (!position->GetNode()) {
161  Error("TVolumeView ctor","%s %s ",GetName(),nextView->GetName());
162  }
163  Add(new TVolumeView(nextView,position));
164  mode = kPrune;
165  }
166  }
167 }
168 
169 ////////////////////////////////////////////////////////////////////////////////
170 
171 TVolumeView::TVolumeView(TVolumeView *viewNode,const TVolumeView *node1,const TVolumeView *node2)
172  : TObjectSet(viewNode->GetName(),(TObject *)0),fListOfShapes(0)
173  // ,fListOfAttributes(0)
174 {
175  //
176  // This ctor creates a TVolumeView structure containing:
177  //
178  // - viewNode on the top
179  // - skip ALL node from the original viewNode untill topNodeName found
180  // - include all "marked" node below "topNodename" if any
181  // topNodeName is always included
182  //
183  // It re-calculates all positions according of the new topology
184  //
185  const TVolumeView *foundView[2] = {node1, node2};
186  const Int_t nViews = sizeof(foundView)/sizeof(const TVolumeView *);
187  Bool_t found = kFALSE;
188  if (!gGeometry) new TGeometry;
189  if (viewNode) {
190  SetTitle(viewNode->GetTitle());
191  // define the depth of the "top" Node
192  EDataSetPass mode = kContinue;
193  TVolumeViewIter next(viewNode,0);
194  TVolumeView *nextView = 0;
195  while ( (nextView = (TVolumeView *)next(mode)) ){
196  mode = kContinue;
197  // Skip till "top Node" found
198  Int_t i = 0;
199  found = kFALSE;
200  for (i=0;i<nViews;i++) {
201  if (foundView[i]) {
202  if (nextView != foundView[i]) continue;
203  foundView[i] = 0;
204  found = kTRUE;
205  break;
206  }
207  }
208  if (!found) continue;
209  TVolumePosition *position = next[0];
210  if (!position->GetNode()) {
211  Error("TVolumeView ctor","%s %s ",GetName(),nextView->GetName());
212  }
213  Add(new TVolumeView(nextView,position));
214  mode = kPrune;
215  }
216  }
217 }
218 
219 ////////////////////////////////////////////////////////////////////////////////
220 ///
221 /// Creates TVolumeView (view) with a topology similar with TVolume *pattern
222 ///
223 /// Parameters:
224 /// -----------
225 /// pattern - the pattern dataset
226 /// iopt = kStruct - clone only my structural links
227 /// kAll - clone all links
228 /// kRefs - clone only refs
229 /// kMarked - clone marked (not implemented yet) only
230 ///
231 /// All new-created sets become the structural ones anyway.
232 ///
233 /// std::cout << "ctor for " << GetName() << " - " << GetTitle() << std::endl;
234 
236  const TVolumePosition *nodePosition,EDataSetPass iopt, TVolumeView *rootVolume)
237  : TObjectSet(pattern.GetName(),(TObject *)nodePosition),fListOfShapes(0)
238 {
239  if (!gGeometry) new TGeometry;
240  if (!nodePosition) {
241  // Create the trivial position if any
242  nodePosition = new TVolumePosition(&pattern);
243  SetObject((TObject*)nodePosition);
244  }
245  if (!rootVolume) {
246  rootVolume = this;
247  nodePosition = 0;
248  }
249  SetTitle(pattern.GetTitle());
250  if ( pattern.IsMarked() ) Mark();
251  TVolumePosition *position = 0;
252  const TList *list = pattern.GetListOfPositions();
253  if (!list || maxDepLevel == 1 || maxDepLevel < 0) return;
254 
255  TIter nextPosition(list);
256  Bool_t optSel = (iopt == kStruct);
257 // Bool_t optAll = (iopt == kAll);
258  Bool_t optMarked = (iopt == kMarked);
259 
260  const TRotMatrix *thisMatrix = 0;
261  Double_t thisTranslation[3] = {0,0,0};
262  if (nodePosition ) {
263  thisMatrix = nodePosition->GetMatrix();
264  for (int i =0; i< 3; i++) thisTranslation[i]= nodePosition->GetX(i);
265  }
266  while ( (position = (TVolumePosition *)nextPosition()) ) {
267  // define the the related TVolume
268  TVolume *node = position->GetNode();
269  Double_t *positionMatrix = ((TRotMatrix *)position->GetMatrix())->GetMatrix();
270  if (node) {
271  UInt_t positionId = position->GetId();
272  Double_t newTranslation[3] = {position->GetX(),position->GetY(),position->GetZ()};
273  Double_t newMatrix[9];
274  TRotMatrix currentMatrix;
275 
276  if (nodePosition) {
277  if (positionMatrix) {
278  TGeometry::UpdateTempMatrix(thisTranslation,thisMatrix?((TRotMatrix *)thisMatrix)->GetMatrix():0
279  ,position->GetX(),position->GetY(),position->GetZ(),positionMatrix
280  ,newTranslation,newMatrix);
281  currentMatrix.SetMatrix(newMatrix);
282  } else {
283  TCL::vadd(thisTranslation, newTranslation,newTranslation,3);
284  currentMatrix.SetMatrix(((TRotMatrix *)thisMatrix)->GetMatrix());
285  }
286  } else {
287  if (positionMatrix)
288  currentMatrix.SetMatrix(positionMatrix);
289  else {
290  TCL::ucopy(thisTranslation,newTranslation,3);
291  currentMatrix.SetMatrix(TVolume::GetIdentity()->GetMatrix());
292  }
293  }
294  TVolumePosition nextPos(node,newTranslation[0],newTranslation[1],
295  newTranslation[2], &currentMatrix);
296  nextPos.SetId(positionId);
297  if (optMarked && !node->IsMarked()) {
298  TVolumeView fakeView(*node,maxDepLevel,&nextPos,iopt,rootVolume);
299  fakeView.DoOwner(kFALSE);
300  continue;
301  }
302 
303  if (optSel) {
304  TDataSet *parent = node->GetParent();
305  if ( parent && (parent != (TDataSet *)&pattern) ) continue;
306  }
307  TRotMatrix *newRotation = new TRotMatrix();
308  newRotation->SetMatrix(currentMatrix.GetMatrix());
309  TVolumePosition *nP = new TVolumePosition(node,newTranslation[0],newTranslation[1],
310  newTranslation[2], newRotation);
311  nP->SetId(positionId);
312  rootVolume->Add(new TVolumeView(*node,maxDepLevel?maxDepLevel-1:0,nP,iopt));
313  } else
314  Error("TVolumeView ctor","Position with NO node attached has been supplied");
315 
316  }
317 }
318 ////////////////////////////////////////////////////////////////////////////////
319 ///to be documented
320 
322  TObjectSet(viewNode.GetName(),(TObject *)viewNode.GetPosition())
323  ,TAtt3D()
324  ,fListOfShapes(viewNode.GetListOfShapes())
325 {
326  if (viewNode.IsOwner()) {
327  viewNode.DoOwner(kFALSE); DoOwner();
328  }
329 }
330 
331 ////////////////////////////////////////////////////////////////////////////////
332 
333 TVolumeView::TVolumeView(Double_t *translate, Double_t *rotate, UInt_t positionId, TVolume *topNode,
334  const Char_t *thisNodePath, const Char_t *matrixName, Int_t matrixType)
335  // : fListOfAttributes(0)
336 {
337  // Special ctor to back TVolumeView::SavePrimitive() method
338  if (!gGeometry) new TGeometry;
339  fListOfShapes = 0;
340  TVolume *thisNode = 0;
341  Double_t thisX = translate[0];
342  Double_t thisY = translate[1];
343  Double_t thisZ = translate[2];
344 
345  // Find TVolume by path;
346  if (topNode) {
347  thisNode = (TVolume *)topNode->Find(thisNodePath);
348  if (!thisNode->InheritsFrom(TVolume::Class())) {
349  Error("TVolumeView","wrong node <%s> on path: \"%s\"",thisNode->GetName(),thisNodePath);
350  thisNode = 0;
351  }
352  }
353 
354  TRotMatrix *thisRotMatrix = 0;
355  if (matrixName && strlen(matrixName)) thisRotMatrix = gGeometry->GetRotMatrix(matrixName);
356  TVolumePosition *thisPosition = 0;
357  if (thisRotMatrix)
358  thisPosition = new TVolumePosition(thisNode,thisX, thisY, thisZ, matrixName);
359  else if (matrixType==2)
360  thisPosition = new TVolumePosition(thisNode,thisX, thisY, thisZ);
361  else if (rotate) {
362  const Char_t *title = "rotation";
363  thisRotMatrix = new TRotMatrix((char *)matrixName,(char *)title,rotate);
364  thisPosition = new TVolumePosition(thisNode,thisX, thisY, thisZ, thisRotMatrix);
365  } else
366  Error("TVolumeView"," No rotation matrix is defined");
367  if (thisPosition) thisPosition->SetId(positionId);
368  SetObject(thisPosition);
369  if (thisNode) {
370  SetName(thisNode->GetName());
371  SetTitle(thisNode->GetTitle());
372  }
373 }
374 
375 ////////////////////////////////////////////////////////////////////////////////
376 ///to be documented
377 
379  : TObjectSet(thisNode?thisNode->GetName():"",(TObject *)nodePosition),fListOfShapes(0)
380 {
381  if (!gGeometry) new TGeometry;
383  if (thisNode)
384  SetTitle(thisNode->GetTitle());
385 }
386 
387 ////////////////////////////////////////////////////////////////////////////////
388 /// default dtor (empty for this class)
389 
391 {
392 }
393 
394 ////////////////////////////////////////////////////////////////////////////////
395 /// Add the TVolume in the Tnode data-structure refered
396 /// by this TVolumeView object
397 /// Return TVolume * the input TVolume * was attached to
398 
400 {
401  TVolume *closedNode = 0;
402  TVolumePosition *pos ;
403  if ( node && (pos = GetPosition() ) && (closedNode = pos->GetNode()) )
404  closedNode->Add(node);
405  return closedNode;
406 }
407 
408 ////////////////////////////////////////////////////////////////////////////////
409 ///to be documented
410 
411 void TVolumeView::Add(TShape *shape, Bool_t IsMaster)
412 {
413  if (!shape) return;
414  if (!fListOfShapes) fListOfShapes = new TList;
415  if (IsMaster)
416  fListOfShapes->AddFirst(shape);
417  else
418  fListOfShapes->Add(shape);
419 }
420 
421 ////////////////////////////////////////////////////////////////////////////////
422 ///to be documented
423 
425 {
427 // TVolumePosition *pos = GetPosition();
428 // if (pos) pos->Browse(b);
429 // b->Add(pos);
430 }
431 
432 ////////////////////////////////////////////////////////////////////////////////
433 ///*-*-*-*-*-*-*-*-*Compute distance from point px,py to a TVolumeView*-*-*-*-*-*
434 ///*-* ===========================================
435 ///*-* Compute the closest distance of approach from point px,py to the position of
436 ///*-* this node.
437 ///*-* The distance is computed in pixels units.
438 ///*-*
439 ///*-* It is restricted by 2 levels of TVolumes
440 ///*-*
441 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
442 
444 {
445  const Int_t big = 9999;
446  const Int_t inaxis = 7;
447  const Int_t maxdist = 5;
448 
449  Int_t dist = big;
450 
451  Int_t puxmin = gPad->XtoAbsPixel(gPad->GetUxmin());
452  Int_t puymin = gPad->YtoAbsPixel(gPad->GetUymin());
453  Int_t puxmax = gPad->XtoAbsPixel(gPad->GetUxmax());
454  Int_t puymax = gPad->YtoAbsPixel(gPad->GetUymax());
455 
456 //*-*- return if point is not in the user area
457  if (px < puxmin - inaxis) return big;
458  if (py > puymin + inaxis) return big;
459  if (px > puxmax + inaxis) return big;
460  if (py < puymax - inaxis) return big;
461 
462  TView *view =gPad->GetView();
463  if (!view) return big;
464 
465  TVolumePosition *position = GetPosition();
466  TVolume *thisNode = 0;
467  TShape *thisShape = 0;
468  if (position) {
469  thisNode = position->GetNode();
470  position->UpdatePosition();
471  if (thisNode) {
472  thisShape = thisNode->GetShape();
473  if (!(thisNode->GetVisibility() & TVolume::kThisUnvisible) &&
474  thisShape && thisShape->GetVisibility()) {
475  dist = thisShape->DistancetoPrimitive(px,py);
476  if (dist < maxdist) {
477  gPad->SetSelected(this);
478  return 0;
479  }
480  }
481  }
482  }
483 
484 // if ( TestBit(kSonsInvisible) ) return dist;
485 
486 //*-*- Loop on all sons
487  TSeqCollection *fNodes = GetCollection();
488  Int_t nsons = fNodes?fNodes->GetSize():0;
489  Int_t dnode = dist;
490  if (nsons) {
491  gGeometry->PushLevel();
492  TVolume *node;
493  TIter next(fNodes);
494  while ((node = (TVolume *)next())) {
495  dnode = node->DistancetoPrimitive(px,py);
496  if (dnode <= 0) break;
497  if (dnode < dist) dist = dnode;
498  if (gGeometry->GeomLevel() > 2) break;
499  }
500  gGeometry->PopLevel();
501  }
502 
503  if (gGeometry->GeomLevel()==0 && dnode > maxdist) {
504  gPad->SetSelected(view);
505  return 0;
506  } else
507  return dnode;
508 }
509 
510 ////////////////////////////////////////////////////////////////////////////////
511 ///*-*-*-*-*-*-*-*-*-*-*-*Draw Referenced node with current parameters*-*-*-*
512 ///*-* =============================================
513 
515 {
516  TString opt = option;
517  opt.ToLower();
518 //*-*- Clear pad if option "same" not given
519  if (!gPad) {
520  gROOT->MakeDefCanvas();
521  }
522  if (!opt.Contains("same")) gPad->Clear();
523 
524 //*-*- Draw Referenced node
527 
528  // Check geometry level
529 
530  Int_t iopt = atoi(option);
531  TDataSet *parent = 0;
532  char buffer[12];
533  if (iopt < 0) {
534  snprintf(buffer,12,"%d",-iopt);
535  option = buffer;
536  // select parent to draw
537  parent = this;
538  do parent = parent->GetParent();
539  while (parent && ++iopt);
540  }
541  if (parent) parent->AppendPad(option);
542  else AppendPad(option);
543 
544 #if ROOT_VERSION_CODE >= ROOT_VERSION(4,03,05)
545  // the new (4.03/05) way to active 3D viewer
546  // Create a 3-D view
547  TView *view = gPad->GetView();
548  if (!view) {
549  view = TView::CreateView(1,0,0);
550  // Set the view to perform a first autorange (frame) draw.
551  // TViewer3DPad will revert view to normal painting after this
552  view->SetAutoRange(kTRUE);
553  }
554 
555  // Create a 3D viewer to draw us
556  gPad->GetViewer3D(option);
557 #else
558  Paint(option);
559 #endif
560 }
561 
562 ////////////////////////////////////////////////////////////////////////////////
563 ///to be documented
564 
566 {
567  TVolumePosition *pos = GetPosition();
568  if (pos)
569  return pos->GetNode();
570  return 0;
571 }
572 
573 ////////////////////////////////////////////////////////////////////////////////
574 ///
575 /// Calculate the position of the vertrex of the outlined cube in repect
576 /// of the given TVolumeView object
577 ///
578 
579 Int_t TVolumeView::GetGlobalRange(const TVolumeView *rootNode,Float_t *globalMin,Float_t *globalMax)
580 {
581  if (rootNode) {
582  SetTitle(rootNode->GetTitle());
583  EDataSetPass mode = kContinue;
584  TVolumeViewIter next((TVolumeView *)rootNode,0);
585  TVolumeView *nextView = 0;
586  // Find itself.
587  while ( (nextView = (TVolumeView *)next(mode)) && nextView != this ){}
588  if (nextView == this) {
589  TVolumePosition *position = next[0];
590  if (!position->GetNode()) {
591  Error("TVolumeView ctor","%s %s ",GetName(),nextView->GetName());
592  }
593  // Calculate the range of the outlined cube verteces.
594  GetLocalRange(globalMin,globalMax);
595  Float_t offSet[3] = {Float_t(position->GetX()),Float_t(position->GetY()),Float_t(position->GetZ())};
596  for (Int_t i=0;i<3;i++) {
597  globalMin[i] += offSet[i];
598  globalMax[i] += offSet[i];
599  }
600  }
601  return next.GetDepth();
602  }
603  else return -1;
604 }
605 
606 ////////////////////////////////////////////////////////////////////////////////
607 /// GetRange
608 ///
609 /// Calculates the size of 3 box the node occupies.
610 /// Return:
611 /// two floating point arrays with the bound of box
612 /// surroundind all shapes of this TModeView
613 ///
614 
616 {
617  TVirtualPad *savePad = gPad;
618  // Create a dummy TPad;
619  TCanvas dummyPad("--Dumm--","dum",1,1);
620  // Assing 3D TView
621  TView *view = TView::CreateView(1,0,0);
622 
625  view->SetAutoRange(kTRUE);
626  Paint("range");
627  view->GetRange(&min[0],&max[0]);
628  delete view;
629  // restore "current pad"
630  if (savePad) savePad->cd();
631 }
632 
633 ////////////////////////////////////////////////////////////////////////////////
634 ///to be documented
635 
637 {
638  if (!gPad) return 0;
639  static char info[512];
640  Double_t x[3] = {0,0,0.5};
641  ((TPad *)gPad)->AbsPixeltoXY(px,py,x[0],x[1]);
642  TView *view =gPad->GetView();
643  if (view) {
644  Double_t min[3], max[3];
645  view->GetRange(min,max);
646  for (int i =0; i<3;i++) min[i] = (max[i]+min[i])/2;
647  view->WCtoNDC(min,max);
648  min[0] = x[0]; min[1] = x[1];
649  min[2] = max[2];
650  view->NDCtoWC(min, x);
651  }
652  TShape *shape = GetShape();
653  if (shape)
654  snprintf(info,512,"%6.2f/%6.2f/%6.2f: %s/%s, shape=%s/%s",x[0],x[1],x[2],GetName(),GetTitle(),shape->GetName(),shape->ClassName());
655  else
656  snprintf(info,512,"%6.2f/%6.2f/%6.2f: %s/%s",x[0],x[1],x[2],GetName(),GetTitle());
657  return info;
658 }
659 
660 ////////////////////////////////////////////////////////////////////////////////
661 ///to be documented
662 
663 TVolumePosition *TVolumeView::Local2Master(const Char_t *localName, const Char_t *masterName)
664 {
665  TVolumeView *masterNode = this;
666  TVolumePosition *position = 0;
667  if (masterName && masterName[0]) masterNode = (TVolumeView *)Find(masterName);
668  if (masterNode) {
669  TVolumeViewIter transform(masterNode,0);
670  if (transform(localName)) position = transform[0];
671  }
672  return position;
673 }
674 
675 ////////////////////////////////////////////////////////////////////////////////
676 ///to be documented
677 
679 {
680  TVolumePosition *position = 0;
681  if (!masterNode) masterNode = this;
682  if (masterNode && localNode) {
683  TVolumeViewIter transform((TVolumeView *)masterNode,0);
684  TVolumeView *nextNode = 0;
685  while ((nextNode = (TVolumeView *)transform()) && nextNode != localNode) { }
686  if (nextNode) position = transform[0];
687  }
688  return position;
689 }
690 
691 ////////////////////////////////////////////////////////////////////////////////
692 ///
693 /// calculate transformation master = (M-local->master )*local + (T-local->master )
694 /// where
695 /// M-local->master - rotation matrix 3 x 3 from the master node to the local node
696 /// T-local->master - trasport vector 3 from the master node to the local node
697 ///
698 /// returns a "master" pointer if transformation has been found
699 /// otherwise 0;
700 ///
701 
703  const Char_t *localName, const Char_t *masterName, Int_t nVector)
704 {
705  Float_t *trans = 0;
706  TVolumePosition *position = 0;
707  TVolumeView *masterNode = this;
708  if (masterName && masterName[0]) masterNode = (TVolumeView *)Find(masterName);
709  if (masterNode) {
710  TVolumeViewIter transform(masterNode,0);
711  if (transform(localName) && (position = (TVolumePosition *) transform.GetPosition()) )
712  trans = position->Local2Master(local,master,nVector);
713  }
714  return trans;
715 }
716 
717 ////////////////////////////////////////////////////////////////////////////////
718 ///
719 /// calculate transformation master = (M-local->master )*local + (T-local->master )
720 /// where
721 /// M-local->master - rotation matrix 3 x 3 from the master node to the local node
722 /// T-local->master - trasport vector 3 from the master node to the local node
723 ///
724 /// returns a "master" pointer if transformation has been found
725 /// otherwise 0;
726 ///
727 
729  const TVolumeView *localNode,
730  const TVolumeView *masterNode, Int_t nVector)
731 {
732  Float_t *trans = 0;
733  TVolumePosition *position = 0;
734  if (!masterNode) masterNode = this;
735  if (masterNode && localNode) {
736  TVolumeViewIter transform((TVolumeView *)masterNode,0);
737  TVolumeView *nextNode = 0;
738  while ((nextNode = (TVolumeView *)transform()) && nextNode != localNode) { }
739  if (nextNode && (position = (TVolumePosition *) transform.GetPosition()) )
740  trans = position->Local2Master(local,master,nVector);
741  }
742  return trans;
743 }
744 
745 ////////////////////////////////////////////////////////////////////////////////
746 ///*-*-*-*-*-*-*-*-*-*-*-*Paint Referenced node with current parameters*-*-*-*
747 ///*-* ==============================================
748 ///*-*
749 ///*-* vis = 1 (default) shape is drawn
750 ///*-* vis = 0 shape is not drawn but its sons may be not drawn
751 ///*-* vis = -1 shape is not drawn. Its sons are not drawn
752 ///*-* vis = -2 shape is drawn. Its sons are not drawn
753 ///*-*
754 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
755 ///
756 /// It draw the TVolumeView layers from the iFirst one (form the zero) till
757 /// iLast one reached.
758 ///
759 /// restrict the levels for "range" option
760 
762 {
763  Int_t level = gGeometry->GeomLevel();
764  if (!option) return;
765  if (option[0]=='r' && level > 3 ) return;
766 
767  Int_t iFirst = atoi(option);
768  Int_t iLast = 0;
769  const char *delim = strpbrk( option,":-,");
770  if (delim) iLast = atoi(delim+1);
771  if (iLast < iFirst) {
772  iLast = iFirst-1;
773  iFirst = 0;
774  }
775 
776  if ( (0 < iLast) && (iLast < level) ) return;
777 
778  TTablePadView3D *view3D = (TTablePadView3D*)gPad->GetView3D();
779 
780  TVolume *thisNode = 0;
781  TVolumePosition *position = GetPosition();
782 
783  // UpdatePosition does change the current matrix and it MUST be called FIRST !!!
784  if (position) {
785  thisNode = position->GetNode();
786  position->UpdatePosition(option);
787  }
788 
789  // if (option[0] !='r' ) printf(" Level %d first = %d iLast %d \n",level, iFirst, iLast);
790  if (level >= iFirst) {
791  PaintShape(option);
792  if (thisNode) thisNode->PaintShape(option);
793  }
794 ////--- if ( thisNode->TestBit(kSonsInvisible) ) return;
795 
796 //*-*- Paint all sons
797  TSeqCollection *nodes = GetCollection();
798  Int_t nsons = nodes?nodes->GetSize():0;
799 
800  if(!nsons) return;
801 
802  gGeometry->PushLevel();
803  TVolumeView *node;
804  TIter next(nodes);
805  while ((node = (TVolumeView *)next())) {
806  if (view3D) view3D->PushMatrix();
807 
808  node->Paint(option);
809 
810  if (view3D) view3D->PopMatrix();
811  }
812  gGeometry->PopLevel();
813 }
814 
815 ////////////////////////////////////////////////////////////////////////////////
816 /// Paint shape of the node
817 /// To be called from the TObject::Paint method only
818 
820 {
821  Bool_t rangeView = option && option[0]=='r';
822 
823  TIter nextShape(fListOfShapes);
824  TShape *shape = 0;
825  while( (shape = (TShape *)nextShape()) ) {
826  if (!shape->GetVisibility()) continue;
827  if (!rangeView) {
828  TTablePadView3D *view3D = (TTablePadView3D*)gPad->GetView3D();
829  if (view3D)
830  view3D->SetLineAttr(shape->GetLineColor(),shape->GetLineWidth(),option);
831  }
832 #if ROOT_VERSION_CODE >= ROOT_VERSION(4,03,05)
833  // It MUST be the TShape::PAint method:
834  Bool_t viewerWantsSons = kTRUE;
835  TVirtualViewer3D * viewer3D = gPad->GetViewer3D();
836  if (viewer3D) {
837  // We only provide master frame positions in these shapes
838  // so don't ask viewer preference
839 
840  // Ask all shapes for kCore/kBoundingBox/kShapeSpecific
841  // Not all will support the last two - which is fine
842  const TBuffer3D & buffer =
844 
845  // TShape sets buffer id based on TNode * gNode
846  // As we not using TNode we need to override this
847  const_cast<TBuffer3D &>(buffer).fID = this;
848 
849  Int_t reqSections = viewer3D->AddObject(buffer, &viewerWantsSons);
850  if (reqSections != TBuffer3D::kNone) {
851  shape->GetBuffer3D(reqSections);
852  viewer3D->AddObject(buffer);
853  }
854  }
855 #else
856  shape->Paint(option);
857 #endif
858  }
859 }
860 
861 ////////////////////////////////////////////////////////////////////////////////
862 /// return the full path of this data set
863 
865 {
866  TString str;
867  TVolumeView *parent = (TVolumeView *)GetParent();
868  if (parent) {
869  str = parent->PathP();
870  str += "/";
871  }
872  str += GetName();
874  if (p) {
875  char buffer[10];
876  snprintf(buffer,10,";%d",p->GetId());
877  str += buffer;
878  }
879  return str;
880 }
881 
882 ////////////////////////////////////////////////////////////////////////////////
883 ///to be documented
884 
885 void TVolumeView::SavePrimitive(std::ostream &out, Option_t * /*= ""*/)
886 {
887  const Char_t *sceleton[] = {
888  "TVolumeView *CreateNodeView(TVolume *topNode) {"
889  ," TString thisNodePath = "
890  ," UInt_t thisPositionId = "
891  ," Double_t thisTranslate[3] = "
892  ," "
893  ," TString matrixName = "
894  ," Int_t matrixType = "
895  ," Double_t thisMatrix[] = { "
896  ," "
897  ," "
898  ," };"
899  ," return = new TVolumeView(thisTranslate, thisMatrix, thisPositionId, topNode,"
900  ," thisNodePath.Data(),matrixName.Data(), matrixType);"
901  ,"}"
902  };
903 //------------------- end of sceleton ---------------------
904  Int_t sceletonSize = sizeof(sceleton)/sizeof(const Char_t*);
905  TVolumePosition *thisPosition = GetPosition();
906  TVolume *thisFullNode = GetNode();
907  TString thisNodePath = thisFullNode ? thisFullNode->Path() : TString("");
908  // Define position
909  UInt_t thisPositionId = thisPosition ? thisPosition->GetId():0;
910  Double_t thisX = thisPosition ? thisPosition->GetX():0;
911  Double_t thisY = thisPosition ? thisPosition->GetY():0;
912  Double_t thisZ = thisPosition ? thisPosition->GetZ():0;
913 
914  const TRotMatrix *matrix = thisPosition ? thisPosition->GetMatrix():0;
915  Int_t matrixType = 2;
916  TString matrixName = " ";
917  Double_t thisMatrix[] = { 0,0,0, 0,0,0, 0,0,0 };
918  if (matrix) {
919  matrixName = matrix->GetName();
920  memcpy(thisMatrix,((TRotMatrix *)matrix)->GetMatrix(),9*sizeof(Double_t));
921  matrixType = matrix->GetType();
922  }
923  Int_t im = 0;
924  for (Int_t lineNumber =0; lineNumber < sceletonSize; lineNumber++) {
925  out << sceleton[lineNumber]; // std::cout << lineNumber << ". " << sceleton[lineNumber];
926  switch (lineNumber) {
927  case 1: out << "\"" << thisNodePath.Data() << "\";" ; // std::cout << "\"" << thisNodePath.Data() << "\";" ;
928  break;
929  case 2: out << thisPositionId << ";" ; // std::cout << "\"" << thisNodePath.Data() << "\";" ;
930  break;
931  case 3: out << "{" << thisX << ", " << thisY << ", "<< thisZ << "};"; // std::cout << thisX << ";" ;
932  break;
933  case 5: out << "\"" << matrixName << "\";" ; // std::cout << "\"" << matrixName << "\";" ;
934  break;
935  case 6: out << matrixType << ";" ; // std::cout << matrixType << ";" ;
936  break;
937  case 7: out << thisMatrix[im++] << ", "; out << thisMatrix[im++] << ", "; out << thisMatrix[im++] << ", ";
938  break;
939  case 8: out << thisMatrix[im++] << ", "; out << thisMatrix[im++] << ", "; out << thisMatrix[im++] << ", ";
940  break;
941  case 9: out << thisMatrix[im++] << ", "; out << thisMatrix[im++] << ", "; out << thisMatrix[im++];
942  break;
943  default:
944  break;
945  };
946 // std::cout << " " << std::endl;
947  out << " " << std::endl;
948  }
949 }
950 
951 ////////////////////////////////////////////////////////////////////////////////
952 ///to be documented
953 
955 {
956  TVolume *thisNode = GetNode();
957  if (thisNode) thisNode->SetLineAttributes();
958 }
959 
960 ////////////////////////////////////////////////////////////////////////////////
961 ///to be documented
962 
964 {
965  TVolume *node = GetNode();
966  if (node) node->SetVisibility(TVolume::ENodeSEEN(vis));
967 }
968 
969 ////////////////////////////////////////////////////////////////////////////////
970 ///*-*-*-*-*-*-*Return total size of this 3-D Node with its attributes*-*-*
971 ///*-* ==========================================================
972 
974 {
975  if (GetListOfShapes()) {
976  TIter nextShape(GetListOfShapes());
977  TShape *shape = 0;
978  while( (shape = (TShape *)nextShape()) ) {
979  if (shape->GetVisibility()) shape->Sizeof3D();
980  }
981  }
982 
983  TVolume *thisNode = GetNode();
984  if (thisNode && !(thisNode->GetVisibility()&TVolume::kThisUnvisible) ) {
985  TIter nextShape(thisNode->GetListOfShapes());
986  TShape *shape = 0;
987  while( (shape = (TShape *)nextShape()) ) {
988  if (shape->GetVisibility()) shape->Sizeof3D();
989  }
990  }
991 
992 // if ( TestBit(kSonsInvisible) ) return;
993 
994  TVolumeView *node;
995  TDataSetIter next((TVolumeView *)this);
996  while ((node = (TVolumeView *)next())) node->Sizeof3D();
997 }
virtual Double_t GetY() const
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
virtual UInt_t GetId() const
std::string GetName(const std::string &scope_name)
Definition: Cppyy.cxx:145
virtual Double_t * GetMatrix()
Definition: TRotMatrix.h:54
virtual Int_t GetDepth() const
Definition: TDataSetIter.h:70
double dist(Rotation3D const &r1, Rotation3D const &r2)
Definition: 3DDistances.cxx:48
virtual ENodeSEEN GetVisibility() const
Definition: TVolume.h:82
virtual void SetLineAttributes()
Invoke the DialogCanvas Line attributes.
Definition: TAttLine.cxx:280
TRotMatrix * GetRotMatrix(const char *name) const
Return pointer to RotMatrix with name.
Definition: TGeometry.cxx:356
virtual void Sizeof3D() const
-*-*-*-*-*-*Return total size of this 3-D Node with its attributes-*-* *-* ==========================...
virtual void WCtoNDC(const Float_t *pw, Float_t *pn)=0
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Computes distance from point (px,py) to the object.
Definition: TObject.cxx:193
float Float_t
Definition: RtypesCore.h:53
const char Option_t
Definition: RtypesCore.h:62
ENodeSEEN
Definition: TVolume.h:38
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:131
virtual void SetAutoRange(Bool_t autorange=kTRUE)=0
virtual Bool_t DoOwner(Bool_t done=kTRUE)
Set / Reset the ownerships and returns the previous status of the ownerships.
Definition: TObjectSet.cxx:85
virtual void AddFirst(TObject *obj)
Add object at the beginning of the list.
Definition: TList.cxx:97
virtual TVolume * GetNode() const
to be documented
See TView3D.
Definition: TView.h:25
Use this attribute class when an object should have 3D capabilities.
Definition: TAtt3D.h:19
TList * fListOfShapes
Definition: TVolumeView.h:28
#define gROOT
Definition: TROOT.h:375
Basic string class.
Definition: TString.h:129
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1099
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual Double_t GetZ() const
TList * GetListOfShapes() const
Definition: TVolume.h:80
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 TVolumePosition * GetPosition() const
Definition: TVolumeView.h:52
virtual TVirtualPad * cd(Int_t subpadnumber=0)=0
virtual Width_t GetLineWidth() const
Return the line width.
Definition: TAttLine.h:35
virtual void PaintShape(Option_t *option="")
Paint shape of the volume To be called from the TObject::Paint method only.
Definition: TVolume.cxx:632
virtual const TBuffer3D & GetBuffer3D(Int_t reqSections) const
Stub to avoid forcing implementation at this stage.
Definition: TShape.cxx:253
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition: TObject.cxx:112
const TRotMatrix * GetMatrix() const
#define SafeDelete(p)
Definition: RConfig.h:499
Sequenceable collection abstract base class.
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:135
Double_t x[n]
Definition: legend1.C:17
virtual void Add(TDataSet *dataset)
Definition: TVolume.h:97
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
-*-*-*-*-*-*-*-*Compute distance from point px,py to a TVolumeView-*-*-*-*-* *-* ====================...
void Class()
Definition: Class.C:29
Int_t GeomLevel() const
Definition: TGeometry.h:74
virtual void SetVisibility(ENodeSEEN vis=TVolume::kBothVisible)
Set visibility for this volume and its sons.
Definition: TVolume.cxx:744
virtual TShape * GetShape() const
Definition: TVolumeView.h:83
virtual TList * GetListOfPositions()
Definition: TVolume.h:83
virtual Int_t GetType() const
Definition: TRotMatrix.h:56
virtual TVolumePosition * Local2Master(const TVolumeView *localNode, const TVolumeView *masterNode=0)
to be documented
virtual Int_t PushLevel()
Definition: TGeometry.h:99
EDataSetPass
Definition: TDataSet.h:40
Abstract 3D shapes viewer.
virtual void Paint(Option_t *option="")
-*-*-*-*-*-*-*-*-*-*-*Paint Referenced node with current parameters-*-*-* *-* =======================...
static TRotMatrix * GetIdentity()
Return a pointer the "identity" matrix.
Definition: TVolume.cxx:498
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition: TVirtualPad.h:49
void Error(const char *location, const char *msgfmt,...)
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
to be documented
Definition: TVolume.cxx:336
A doubly linked list.
Definition: TList.h:43
TGeometry description.
Definition: TGeometry.h:39
virtual void GetLocalRange(Float_t *min, Float_t *max)
GetRange.
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:37
virtual Bool_t IsMarked() const
Definition: TVolume.h:98
virtual Double_t GetX(Int_t indx=0) const
virtual void SetObject(TObject *obj)
The depricated method (left here for the sake of the backward compatibility)
Definition: TObjectSet.h:59
This is the base class for all geometry shapes.
Definition: TShape.h:35
Manages a detector rotation matrix.
Definition: TRotMatrix.h:28
virtual TVolume * AddNode(TVolume *node)
Add the TVolume in the Tnode data-structure refered by this TVolumeView object Return TVolume * the i...
virtual Double_t * Local2Master(const Double_t *local, Double_t *master, Int_t nPoints=1) const
-*-*-*-*Convert one point from local system to master reference system-*-* *-* ======================...
virtual char * GetObjectInfo(Int_t px, Int_t py) const
to be documented
virtual void Add(TDataSet *dataset)
Definition: TVolumeView.h:79
static int * ucopy(const int *a, int *b, int n)
Definition: TCernLib.h:325
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:436
virtual void SetLineAttributes()
to be documented
virtual void UpdatePosition(Option_t *option="")
to be documented
virtual Int_t AddObject(const TBuffer3D &buffer, Bool_t *addChildren=0)=0
unsigned int UInt_t
Definition: RtypesCore.h:42
The most important graphics class in the ROOT system.
Definition: TPad.h:29
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:873
virtual TDataSet * Find(const char *path) const
Full description see: TDataSetIter::Find.
Definition: TDataSet.cxx:362
Generic 3D primitive description class.
Definition: TBuffer3D.h:17
virtual TString Path() const
return the full path of this data set
Definition: TDataSet.cxx:626
const Bool_t kFALSE
Definition: RtypesCore.h:92
virtual void SetId(UInt_t id)
virtual Color_t GetLineColor() const
Return the line color.
Definition: TAttLine.h:33
virtual TList * GetListOfShapes() const
Definition: TVolumeView.h:82
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:31
virtual void Browse(TBrowser *b)
to be documented
virtual void PaintShape(Option_t *option)
Paint shape of the node To be called from the TObject::Paint method only.
void Add(THist< DIMENSIONS, PRECISION_TO, STAT_TO... > &to, const THist< DIMENSIONS, PRECISION_FROM, STAT_FROM... > &from)
Add two histograms.
Definition: THist.hxx:336
#define ClassImp(name)
Definition: Rtypes.h:336
double Double_t
Definition: RtypesCore.h:55
virtual void Browse(TBrowser *b)
Browse this dataset (called by TBrowser).
Definition: TObjectSet.cxx:65
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:572
virtual void SetLineAttr(Color_t color, Int_t width, Option_t *opt="")
static float * vadd(const float *b, const float *c, float *a, int n)
Definition: TCernLib.h:380
virtual void SetGeomLevel(Int_t level=0)
Definition: TGeometry.h:104
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:39
virtual TVolume * GetNode() const
Mother of all ROOT objects.
Definition: TObject.h:37
virtual ~TVolumeView()
default dtor (empty for this class)
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
char Char_t
Definition: RtypesCore.h:29
virtual const TVolumePosition * GetPosition(Int_t level=0) const
to be documented
virtual void Draw(Option_t *depth="3")
-*-*-*-*-*-*-*-*-*-*-*Draw Referenced node with current parameters-*-*-* *-* ========================...
virtual Bool_t IsMarked() const
Definition: TVolumeView.h:81
TShape * GetShape() const
Definition: TVolume.h:79
virtual void Add(TObject *obj)
Definition: TList.h:77
virtual void GetRange(Float_t *min, Float_t *max)=0
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
#define snprintf
Definition: civetweb.c:822
virtual Bool_t IsOwner() const
Definition: TObjectSet.h:57
#define gPad
Definition: TVirtualPad.h:284
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
to be documented
virtual Int_t GetGlobalRange(const TVolumeView *rootNode, Float_t *min, Float_t *max)
Calculate the position of the vertrex of the outlined cube in repect of the given TVolumeView object...
virtual void Sizeof3D() const
Set total size of this 3D object (used by X3D interface).
Definition: TAtt3D.cxx:27
void Mark()
Definition: TDataSet.h:156
virtual void PopMatrix()
virtual Int_t GetSize() const
Definition: TCollection.h:89
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:155
R__EXTERN TGeometry * gGeometry
Definition: TGeometry.h:158
const Bool_t kTRUE
Definition: RtypesCore.h:91
virtual Int_t PopLevel()
Definition: TGeometry.h:100
Int_t GetVisibility() const
Definition: TShape.h:58
virtual TSeqCollection * GetCollection() const
Definition: TDataSet.h:105
virtual void PushMatrix()
virtual void SetVisibility(Int_t vis=1)
to be documented
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
virtual TDataSet * GetParent() const
Definition: TDataSet.h:111
const char * Data() const
Definition: TString.h:347
virtual TString PathP() const
return the full path of this data set