CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FWGeoTopNode.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : FWGeoTopNode
5 //
6 // Implementation:
7 // [Notes on implementation]
8 //
9 // Original Author: Matevz Tadel, Alja Mrak Tadel
10 // Created: Thu Jun 23 01:24:51 CEST 2011
11 // $Id: FWGeoTopNode.cc,v 1.17 2011/07/20 23:18:59 amraktad Exp $
12 //
13 
14 // system include files
15 
16 // user include files
17 
18 #include "TEveTrans.h"
19 #include "TEveManager.h"
20 #include "TEveUtil.h"
21 
22 
23 #include "TROOT.h"
24 #include "TBuffer3D.h"
25 #include "TBuffer3DTypes.h"
26 #include "TVirtualViewer3D.h"
27 #include "TColor.h"
28 
29 #include "TGeoShape.h"
30 #include "TGeoVolume.h"
31 #include "TGeoNode.h"
32 #include "TGeoShapeAssembly.h"
33 #include "TGeoCompositeShape.h"
34 #include "TGeoBoolNode.h"
35 #include "TGeoManager.h"
36 #include "TGeoMatrix.h"
37 #include "TVirtualGeoPainter.h"
38 
43 
45  m_browser(t),
46  m_maxLevel(0),
47  m_filterOff(0)
48 {
50 }
51 
53 {
54 }
55 
56 
57 //______________________________________________________________________________
58 void FWGeoTopNode::setupBuffMtx(TBuffer3D& buff, const TGeoHMatrix& mat)
59 {
60  const Double_t *r = mat.GetRotationMatrix();
61  const Double_t *t = mat.GetTranslation();
62  const Double_t *s = mat.GetScale();
63  Double_t *m = buff.fLocalMaster;
64  m[0] = r[0]*s[0]; m[1] = r[1]*s[1]; m[2] = r[2]*s[2]; m[3] = 0;
65  m[4] = r[3]*s[0]; m[5] = r[4]*s[1]; m[6] = r[5]*s[2]; m[7] = 0;
66  m[8] = r[6]*s[0]; m[9] = r[7]*s[1]; m[10] = r[8]*s[2]; m[11] = 0;
67  m[12] = t[0]; m[13] = t[1]; m[15] = t[2]; m[15] = 1;
68 
69  buff.fLocalFrame = kTRUE;
70 }
71 //______________________________________________________________________________
72 void FWGeoTopNode::Paint(Option_t*)
73 {
74 
75  // workaround for global usage of gGeoManager in TGeoShape
76  TEveGeoManagerHolder gmgr( FWGeometryTableViewManager::getGeoMangeur());
77 
78  int topIdx = m_browser->getTopNodeIdx();
80 
82  m_filterOff = m_browser->getFilter().empty();
83 
84  TGeoHMatrix mtx;
85  if (topIdx >= 0)
86  {
87  std::advance(sit, topIdx);
89 
90  // paint this node
91  if ( m_filterOff == false)
93 
95  paintShape(*sit, mtx);
96  }
97 
99  paintChildNodesRecurse( sit, mtx);
100 }
101 
102 // ______________________________________________________________________
103 
105 {
106  TGeoNode* parentNode = pIt->m_node;
107  int nD = parentNode->GetNdaughters();
108 
109  int dOff=0;
110  pIt++;
111 
113  for (int n = 0; n != nD; ++n)
114  {
115  it = pIt;
116  std::advance(it,n + dOff);
117 
118  TGeoHMatrix nm = parentMtx;
119  nm.Multiply(it->m_node->GetMatrix());
120 
121 
122  if (m_filterOff)
123  {
125  paintShape(*it, nm);
126 
127  if ( m_browser->getTableManager()->getVisibilityChld(*it) && it->m_level < m_maxLevel )
128  paintChildNodesRecurse(it, nm);
129 
130  }
131  else
132  {
135  paintShape(*it, nm);
136 
138  paintChildNodesRecurse(it, nm);
139  }
140 
141 
142  FWGeometryTableManager::getNNodesTotal(parentNode->GetDaughter(n), dOff);
143  }
144 }
145 
146 // ______________________________________________________________________
148 {
149  static const TEveException eh("FWGeoTopNode::paintShape ");
150 
151 
152  TGeoShape* shape = data.m_node->GetVolume()->GetShape();
153  TGeoCompositeShape* compositeShape = dynamic_cast<TGeoCompositeShape*>(shape);
154  if (compositeShape)
155  {
156  // printf("!!!!!!!!!!!!!!!!!!!! composite shape\n");
157  Double_t halfLengths[3] = { compositeShape->GetDX(), compositeShape->GetDY(), compositeShape->GetDZ() };
158 
159  TBuffer3D buff(TBuffer3DTypes::kComposite);
160  buff.fID = data.m_node->GetVolume();
161  // buff.fColor = data.m_color;
162  buff.fColor = m_browser->getVolumeMode() ? data.m_node->GetVolume()->GetLineColor(): data.m_color;
163  buff.fTransparency = data.m_node->GetVolume()->GetTransparency();
164 
165  nm.GetHomogenousMatrix(buff.fLocalMaster);
166  // RefMainTrans().SetBuffer3D(buff);
167  buff.fLocalFrame = kTRUE; // Always enforce local frame (no geo manager).
168  buff.SetAABoundingBox(compositeShape->GetOrigin(), halfLengths);
169  buff.SetSectionsValid(TBuffer3D::kCore|TBuffer3D::kBoundingBox);
170 
171  Bool_t paintComponents = kTRUE;
172 
173  // Start a composite shape, identified by this buffer
174  if (TBuffer3D::GetCSLevel() == 0)
175  paintComponents = gPad->GetViewer3D()->OpenComposite(buff);
176 
177  TBuffer3D::IncCSLevel();
178 
179  // Paint the boolean node - will add more buffers to viewer
180  TGeoHMatrix xxx;
181  TGeoMatrix *gst = TGeoShape::GetTransform();
182  TGeoShape::SetTransform(&xxx);
183  if (paintComponents) compositeShape->GetBoolNode()->Paint("");
184  TGeoShape::SetTransform(gst);
185  // Close the composite shape
186  if (TBuffer3D::DecCSLevel() == 0)
187  gPad->GetViewer3D()->CloseComposite();
188 
189  }
190  else
191  {
192  TBuffer3D& buff = (TBuffer3D&) shape->GetBuffer3D (TBuffer3D::kCore, kFALSE);
193  setupBuffMtx(buff, nm);
194  buff.fID = data.m_node->GetVolume();
195  buff.fColor = m_browser->getVolumeMode() ? data.m_node->GetVolume()->GetLineColor(): data.m_color;
196  buff.fTransparency = data.m_node->GetVolume()->GetTransparency();
197 
198  nm.GetHomogenousMatrix(buff.fLocalMaster);
199  buff.fLocalFrame = kTRUE; // Always enforce local frame (no geo manager).
200 
201  Int_t sections = TBuffer3D::kBoundingBox | TBuffer3D::kShapeSpecific;
202  shape->GetBuffer3D(sections, kTRUE);
203 
204 
205  Int_t reqSec = gPad->GetViewer3D()->AddObject(buff);
206 
207  if (reqSec != TBuffer3D::kNone) {
208  // This shouldn't happen, but I suspect it does sometimes.
209  if (reqSec & TBuffer3D::kCore)
210  Warning(eh, "Core section required again for shape='%s'. This shouldn't happen.", GetName());
211  shape->GetBuffer3D(reqSec, kTRUE);
212  reqSec = gPad->GetViewer3D()->AddObject(buff);
213  }
214 
215  if (reqSec != TBuffer3D::kNone)
216  Warning(eh, "Extra section required: reqSec=%d, shape=%s.", reqSec, GetName());
217  }
218 }
void paintChildNodesRecurse(FWGeometryTableManager::Entries_i pIt, const TGeoHMatrix &mtx)
bool getVisibilityChld(const NodeInfo &nodeInfo) const
virtual ~FWGeoTopNode()
Definition: FWGeoTopNode.cc:52
std::string getFilter() const
virtual void Paint(Option_t *option="")
Definition: FWGeoTopNode.cc:72
FWGeometryTableManager * getTableManager()
static const G4AffineTransform & GetTransform(const G4TouchableHistory *touchable, int depth)
void paintShape(FWGeometryTableManager::NodeInfo &nodeInfo, const TGeoHMatrix &nm)
bool getIgnoreVisLevelWhenFilter() const
FWGeoTopNode(FWGeometryTableView *)
Definition: FWGeoTopNode.cc:44
FWGeometryTableManager::Entries_v * m_entries
Definition: FWGeoTopNode.h:52
bool getVisibility(const NodeInfo &nodeInfo) const
static TGeoManager * getGeoMangeur()
void assertNodeFilterCache(NodeInfo &data)
FWGeometryTableView * m_browser
Definition: FWGeoTopNode.h:49
void getNodeMatrix(const NodeInfo &nodeInfo, TGeoHMatrix &mat) const
static void getNNodesTotal(TGeoNode *geoNode, int &off)
Entries_v::iterator Entries_i
bool getVolumeMode() const
bool m_filterOff
Definition: FWGeoTopNode.h:54
string s
Definition: asciidump.py:422
void setupBuffMtx(TBuffer3D &buff, const TGeoHMatrix &mat)
Definition: FWGeoTopNode.cc:58