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 //
12 
13 // system include files
14 
15 // user include files
16 
17 #include "TEveTrans.h"
18 #include "TEveViewer.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 #include "TGLScenePad.h"
29 #include "TGLPhysicalShape.h"
30 #include "TGLSelectRecord.h"
31 #include "TGLViewer.h"
32 #include "TGLWidget.h"
33 
34 #include "TGeoShape.h"
35 #include "TGeoVolume.h"
36 #include "TGeoNode.h"
37 #include "TGeoShapeAssembly.h"
38 #include "TGeoCompositeShape.h"
39 #include "TGeoBoolNode.h"
40 #include "TGeoManager.h"
41 #include "TGeoMatrix.h"
42 #include "TVirtualGeoPainter.h"
43 
49 
50 TGLViewer* FWGeoTopNode::s_pickedViewer = 0;
52 
53 UInt_t FWGeoTopNode::phyID(int tableIdx)
54 {
55 return UInt_t(tableIdx + 2);
56 
57 }
58 
59 int FWGeoTopNode::tableIdx(TGLPhysicalShape* ps)
60 {
61  return ps->ID() - 2;
62 }
63 //______________________________________________________________________________
64 void FWGeoTopNode::EraseFromSet(std::set<TGLPhysicalShape*>& sset, TGLPhysicalShape* id)
65 {
66  sset.erase(id);
67  SetStateOf(id);
68 }
69 
70 //______________________________________________________________________________
71 void FWGeoTopNode::ClearSet(std::set<TGLPhysicalShape*>& sset)
72 {
73  while (!sset.empty())
74  {
75  TGLPhysicalShape *id = *sset.begin();
76  sset.erase(id);
77  SetStateOf(id);
78  }
79 }
80 //______________________________________________________________________________
81 void FWGeoTopNode::SetStateOf(TGLPhysicalShape* id)
82 {
84 
85  if (fSted.find(id) != fSted.end())
86  {
87  id->Select(1);
89  }
90  else if (fHted.find(id) != fHted.end())
91  {
92  id->Select(3);
94  }
95  else
96  {
97  id->Select(0);
100  }
101 
102 }
103 
104 //______________________________________________________________________________
105 void FWGeoTopNode::ProcessSelection(TGLSelectRecord& rec, std::set<TGLPhysicalShape*>& sset, TGLPhysicalShape* id)
106 {
107  // printf("FWGeoTopNode::ProcessSelection ===============================\n");
108 
109  m_scene->BeginUpdate();
110 
111  if (sset.empty())
112  {
113  if (id)
114  {
115  sset.insert(id);
116  rec.SetSecSelResult(TGLSelectRecord::kEnteringSelection);
117  }
118  }
119  else
120  {
121  if (id)
122  {
123  if (rec.GetMultiple())
124  {
125  if (sset.find(id) == sset.end())
126  {
127  sset.insert(id);
128  rec.SetSecSelResult(TGLSelectRecord::kModifyingInternalSelection);
129  }
130  else
131  {
132  EraseFromSet(sset, id);
133  if (sset.empty())
134  rec.SetSecSelResult(TGLSelectRecord::kLeavingSelection);
135  else
136  rec.SetSecSelResult(TGLSelectRecord::kModifyingInternalSelection);
137  }
138  }
139  else
140  {
141  if (sset.size() != 1 || sset.find(id) == sset.end())
142  {
143  ClearSet(sset);
144  sset.insert(id);
145  rec.SetSecSelResult(TGLSelectRecord::kModifyingInternalSelection);
146  }
147  }
148  }
149  else
150  {
151  if (!rec.GetMultiple())
152  {
153  ClearSet(sset);
154  rec.SetSecSelResult(TGLSelectRecord::kLeavingSelection);
155  }
156  }
157  }
158 
159  if (id)
160  {
161  SetStateOf(id);
162  }
163 
164  if (rec.GetSecSelResult() != TGLSelectRecord::kNone)
165  {
166  m_scene->EndUpdate(kTRUE, kFALSE, kTRUE);
167  gEve->Redraw3D();
168 
170  }
171  else
172  {
173  m_scene->EndUpdate(kFALSE, kFALSE, kFALSE);
174  }
175 }
176 
177 //______________________________________________________________________________
179 {
180  // printf("FWGeoTopNode::selectPhysicalFromTable
181 
182  TGLPhysicalShape* ps = m_scene->FindPhysical(phyID(tableIndex));
183  if (ps) {
184  fSted.insert(ps);
185  ps->Select(1);
186  // printf("selectPhysicalFromTable found physical \n");
187  return true;
188  }
189  else if ( tableManager()->refEntries().at(tableIndex).testBit(FWGeometryTableManagerBase::kVisNodeSelf));
190  {
191  fwLog(fwlog::kInfo) << "Selected entry not drawn in GL viewer. \n" ;
192  return false;
193  }
194 }
195 
196 //______________________________________________________________________________
198 {
199  for (std::set<TGLPhysicalShape*>::iterator it = fSted.begin(); it != fSted.end(); ++it)
200  {
201  printf("FWGeoTopNode::printSelected %s \n", tableManager()->refEntries().at(tableIdx(*it)).name() );
202  }
203 }
204 
205 //______________________________________________________________________________
206 
208 {
209  // Note: if object would be rendered, this would return fSted.begin().
210 
211  if (fSted.size() <= 1)
212  {
213  int cnt = 0;
214  for (FWGeometryTableManagerBase::Entries_i i = tableManager()->refEntries().begin(); i != tableManager()->refEntries().end(); ++i, ++cnt)
215  {
216  if (i->testBit(FWGeometryTableManagerBase::kSelected)) return cnt;
217  }
218  }
219  return -1;
220 }
221 
222 //______________________________________________________________________________
224 {
225  // Fill bounding-box information. Virtual from TAttBBox.
226 
227  BBoxZero(1.0f);
228 }
229 
230 //______________________________________________________________________________
231 void FWGeoTopNode::setupBuffMtx(TBuffer3D& buff, const TGeoHMatrix& mat)
232 {
233  const Double_t *r = mat.GetRotationMatrix();
234  const Double_t *t = mat.GetTranslation();
235  const Double_t *s = mat.GetScale();
236  Double_t *m = buff.fLocalMaster;
237  m[0] = r[0]*s[0]; m[1] = r[1]*s[1]; m[2] = r[2]*s[2]; m[3] = 0;
238  m[4] = r[3]*s[0]; m[5] = r[4]*s[1]; m[6] = r[5]*s[2]; m[7] = 0;
239  m[8] = r[6]*s[0]; m[9] = r[7]*s[1]; m[10] = r[8]*s[2]; m[11] = 0;
240  m[12] = t[0]; m[13] = t[1]; m[15] = t[2]; m[15] = 1;
241 
242  buff.fLocalFrame = kTRUE;
243 }
244 
245 // ______________________________________________________________________
246 void FWGeoTopNode::paintShape( Int_t tableIndex, const TGeoHMatrix& nm, bool volumeColor, bool isParentNode)
247 {
248  static const TEveException eh("FWGeoTopNode::paintShape ");
249 
250  // printf("paint sahpe id %d\n", tableIndex );
251 
253  UChar_t transparency = wrapTransparency(data, isParentNode);
254  // printf("trans %d \n", transparency );
255  if (transparency >= 100) return;
256 
257  TGeoShape* shape = data.m_node->GetVolume()->GetShape();
258 
259  TGeoCompositeShape* compositeShape = dynamic_cast<TGeoCompositeShape*>(shape);
260  if (compositeShape)
261  {
262  // m_scene->fNextCompositeID = phyID(tableIndex);
263 
264  Double_t halfLengths[3] = { compositeShape->GetDX(), compositeShape->GetDY(), compositeShape->GetDZ() };
265 
266  TBuffer3D buff(TBuffer3DTypes::kComposite);
267  buff.fID = data.m_node->GetVolume();
268  buff.fColor = volumeColor ? data.m_node->GetVolume()->GetLineColor() : data.m_color ;
269  buff.fTransparency = transparency;// data.m_node->GetVolume()->GetTransparency();
270 
271  nm.GetHomogenousMatrix(buff.fLocalMaster);
272  buff.fLocalFrame = kTRUE; // Always enforce local frame (no geo manager).
273  buff.SetAABoundingBox(compositeShape->GetOrigin(), halfLengths);
274  buff.SetSectionsValid(TBuffer3D::kCore|TBuffer3D::kBoundingBox);
275 
276  Bool_t paintComponents = kTRUE;
277  // Start a composite shape, identified by this buffer
278  if (TBuffer3D::GetCSLevel() == 0) {
279  paintComponents = m_scene->OpenCompositeWithPhyID(phyID(tableIndex), buff);
280  }
281 
282  TBuffer3D::IncCSLevel();
283 
284  // Paint the boolean node - will add more buffers to viewer
285  TGeoHMatrix xxx;
286  TGeoMatrix *gst = TGeoShape::GetTransform();
287  TGeoShape::SetTransform(&xxx);
288 
289  if (paintComponents) compositeShape->GetBoolNode()->Paint("");
290  TGeoShape::SetTransform(gst);
291  // Close the composite shape
292  if (TBuffer3D::DecCSLevel() == 0)
293  gPad->GetViewer3D()->CloseComposite();
294 
295 
296  // m_scene->fNextCompositeID = 0;
297  }
298  else
299  {
300  TBuffer3D& buff = (TBuffer3D&) shape->GetBuffer3D (TBuffer3D::kCore, kFALSE);
301  setupBuffMtx(buff, nm);
302  buff.fID = data.m_node->GetVolume();
303  buff.fColor = volumeColor ? data.m_node->GetVolume()->GetLineColor() : data.m_color ;
304  buff.fTransparency = transparency;// data.m_node->GetVolume()->GetTransparency();
305 
306 
307  nm.GetHomogenousMatrix(buff.fLocalMaster);
308  buff.fLocalFrame = kTRUE; // Always enforce local frame (no geo manager).
309 
310  Int_t sections = TBuffer3D::kBoundingBox | TBuffer3D::kShapeSpecific;
311  shape->GetBuffer3D(sections, kTRUE);
312 
313  Int_t reqSec = gPad->GetViewer3D()->AddObject(phyID(tableIndex), buff);
314 
315  if (reqSec != TBuffer3D::kNone) {
316  // This shouldn't happen, but I suspect it does sometimes.
317  if (reqSec & TBuffer3D::kCore)
318  Warning(eh, "Core section required again for shape='%s'. This shouldn't happen.", GetName());
319  shape->GetBuffer3D(reqSec, kTRUE);
320  reqSec = gPad->GetViewer3D()->AddObject(phyID(tableIndex), buff);
321  }
322 
323  if (reqSec != TBuffer3D::kNone)
324  Warning(eh, "Extra section required: reqSec=%d, shape=%s.", reqSec, GetName());
325  }
326 }
327 
328 // ______________________________________________________________________
329 void FWGeoTopNode::Paint(Option_t* opt)
330 {
331  static const TEveException eh("FWGeoTopNode::Paint ");
332 
333  TBuffer3D buff(TBuffer3DTypes::kGeneric);
334 
335  // Section kCore
336  buff.fID = this;
337  buff.fColor = GetMainColor();
338  buff.fTransparency = GetMainTransparency();
339  if (HasMainTrans()) RefMainTrans().SetBuffer3D(buff);
340 
341  buff.SetSectionsValid(TBuffer3D::kCore);
342 
343  Int_t reqSections = gPad->GetViewer3D()->AddObject(1, buff);
344  if (reqSections != TBuffer3D::kNone)
345  {
346  Warning(eh, "IsA='%s'. Viewer3D requires more sections (%d). Only direct-rendering supported.",
347  ClassName(), reqSections);
348  }
349 }
350 
351 // ______________________________________________________________________
353 {
354  ClearSet(fSted);
355  for (FWGeometryTableManagerBase::Entries_i i = tableManager()->refEntries().begin(); i != tableManager()->refEntries().end(); ++i)
357 }
358 
359 // ______________________________________________________________________
361 {
362  ClearSet(fHted);
363  for (FWGeometryTableManagerBase::Entries_i i = tableManager()->refEntries().begin(); i != tableManager()->refEntries().end(); ++i)
365 }
366 
367 
368 // ______________________________________________________________________
369 FWPopupMenu* FWGeoTopNode::setPopupMenu(int iX, int iY, TGLViewer* v, bool overlap)
370 {
371  if (getFirstSelectedTableIndex() < 0)
372  {
373  if (fSted.empty()) fwLog(fwlog::kInfo) << "No menu -- no node/entry selected \n";
374  return 0;
375  }
376 
377  FWPopupMenu* nodePopup = new FWPopupMenu();
378 
379  nodePopup->AddEntry("Set As Top Node", kSetTopNode);
380  nodePopup->AddEntry("Set As Top Node And Reset Camera", kSetTopNodeCam);
381  nodePopup->AddSeparator();
382  if (v) {
383  nodePopup->AddEntry("Rnr Off", kVisSelfOff);
384  }
385  nodePopup->AddEntry("Rnr Off For All Children", kVisChldOff);
386  nodePopup->AddEntry("Rnr On For All Children", kVisChldOn);
387  nodePopup->AddSeparator();
388 
389  if (overlap)
390  nodePopup->AddEntry("Print Overlap", kPrintOverlap);
391  nodePopup->AddEntry("Print Path", kPrintPath);
392  nodePopup->AddEntry("Print Shape", kPrintShape);
393  nodePopup->AddEntry("Print Material", kPrintMaterial);
394 
395  nodePopup->AddSeparator();
396  if (v) {
397  Window_t wdummy;
398  Int_t x,y;
399  gVirtualX->TranslateCoordinates(gClient->GetDefaultRoot()->GetId(), v->GetGLWidget()->GetId(), iX, iY, x, y, wdummy);
400  TGLVector3 pnt(x, y, 0.5*v->GetSelRec().GetMinZ());
401  v->CurrentCamera().WindowToViewport(pnt);
402  s_pickedCamera3DCenter = v->CurrentCamera().ViewportToWorld(pnt);
403  // s_pickedCamera3DCenter.Dump();
404  s_pickedViewer = v;
405 
406  nodePopup->AddEntry("Set Camera Center", kCamera);
407  }
408 
409  nodePopup->PlaceMenu(iX, iY,true,true);
410  return nodePopup;
411 }
412 
413 
415 {
416  if (isParentNode)
417  {
418  return TMath::Max((Char_t)browser()->getMinParentTransparency(), data.m_transparency) * browser()->getParentTransparencyFactor();
419  }
420  else
421  {
422  return TMath::Max((Char_t)browser()->getMinLeafTransparency(), data.m_transparency) * browser()->getLeafTransparencyFactor();
423  }
424 }
std::set< TGLPhysicalShape * > fSted
Definition: FWGeoTopNode.h:72
int i
Definition: DBlmapReader.cc:9
virtual FWGeometryTableManagerBase * tableManager()
Definition: FWGeoTopNode.h:68
void ClearSet(std::set< TGLPhysicalShape * > &sset)
Definition: FWGeoTopNode.cc:71
bool OpenCompositeWithPhyID(UInt_t phyID, const TBuffer3D &buffer)
virtual void Paint(Option_t *option="")
void printSelected()
void dataChanged()
Classes which inherit from FWTableManagerBase must call this when their underlying data changes...
int getFirstSelectedTableIndex()
bool overlap(const reco::Muon &muon1, const reco::Muon &muon2, double pullX=1.0, double pullY=1.0, bool checkAdjacentChambers=false)
static const G4AffineTransform & GetTransform(const G4TouchableHistory *touchable, int depth)
FWGeoTopNodeGLScene * m_scene
Definition: FWGeoTopNode.h:66
UChar_t wrapTransparency(FWGeometryTableManagerBase::NodeInfo &data, bool leafNode)
double f[11][100]
virtual void ComputeBBox()
FWPopupMenu * setPopupMenu(int iX, int iY, TGLViewer *v, bool)
#define fwLog(_level_)
Definition: fwLog.h:50
virtual FWGeometryTableViewBase * browser()
Definition: FWGeoTopNode.h:69
bool selectPhysicalFromTable(int)
static TGLViewer * s_pickedViewer
Definition: FWGeoTopNode.h:85
std::set< TGLPhysicalShape * > fHted
Definition: FWGeoTopNode.h:71
void paintShape(Int_t idx, const TGeoHMatrix &nm, bool volumeColor, bool parentNode)
#define begin
Definition: vmac.h:30
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
virtual void UnHighlighted()
void EraseFromSet(std::set< TGLPhysicalShape * > &sset, TGLPhysicalShape *id)
Definition: FWGeoTopNode.cc:64
void ProcessSelection(TGLSelectRecord &rec, std::set< TGLPhysicalShape * > &sset, TGLPhysicalShape *id)
void SetStateOf(TGLPhysicalShape *id)
Definition: FWGeoTopNode.cc:81
Definition: DDAxes.h:10
static int tableIdx(TGLPhysicalShape *ps)
Definition: FWGeoTopNode.cc:59
virtual void UnSelected()
static TGLVector3 s_pickedCamera3DCenter
Definition: FWGeoTopNode.h:84
void setupBuffMtx(TBuffer3D &buff, const TGeoHMatrix &mat)
list at
Definition: asciidump.py:428
static UInt_t phyID(int tableIdx)
Definition: FWGeoTopNode.cc:53