CMS 3D CMS Logo

FWGeometryTableManager.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : FWGeometryTableManager
5 //
6 // Implementation:
7 // [Notes on implementation]
8 //
9 // Original Author:
10 // Created: Wed Jan 4 20:31:25 CET 2012
11 //
12 
13 // system include files
14 
15 // user include files
20 
21 #include "TEveUtil.h"
22 #include "TEveVector.h"
23 #include "TGeoShape.h"
24 #include "TGeoMatrix.h"
25 #include "TGeoBBox.h"
26 
27 
30  m_browser(v),
31  m_filterOff(true)
32 {}
33 
35 {}
36 
38 {
39  if (m_browser->getVolumeMode())
40  return Form("%s [%d]", data.m_node->GetVolume()->GetName(), data.m_node->GetNdaughters());
41  else
42  return Form("%s [%d]", data.m_node->GetName(), data.m_node->GetNdaughters());
43 }
44 
45 //------------------------------------------------------------------------------
46 
47 FWTableCellRendererBase* FWGeometryTableManager::cellRenderer(int iSortedRowNumber, int iCol) const
48 {
50  if (m_row_to_index.empty()) return renderer;
51 
52  int unsortedRow = m_row_to_index[iSortedRowNumber];
53  if (unsortedRow < 0) printf("!!!!!!!!!!!!!!!! error %d %d \n",unsortedRow, iSortedRowNumber);
54 
55  // editor state
56  //
57  m_renderer.showEditor(unsortedRow == m_editTransparencyIdx && iCol == kTranspColumn);
58 
59  // selection state
60  //
61  const NodeInfo& data = m_entries[unsortedRow];
62  TGeoNode& gn = *data.m_node;
63  bool isSelected = data.testBit(kHighlighted) || data.testBit(kSelected);
64  // printf("cell render %s \n", data.name());
65  if (data.testBit(kSelected))
66  {
67  m_highlightContext->SetBackground(0xc86464);
68  }
69  else if (data.testBit(kHighlighted) )
70  {
71  m_highlightContext->SetBackground(0x6464c8);
72  }
73  else if (iCol == kMaterialColumn && data.testBit(kMatches) )
74  {
75  m_highlightContext->SetBackground(0xdddddd);
76  }
77 
78  // set column content
79  //
80  if (iCol == kNameColumn)
81  {
82  renderer->setData(cellName(data), isSelected);
83 
84  renderer->setIsParent(nodeIsParent(data));
85 
87 
88  int level = data.m_level - m_levelOffset;
89  if (nodeIsParent(data))
90  renderer->setIndentation(20*level);
91  else
92  renderer->setIndentation(20*level + FWTextTreeCellRenderer::iconWidth());
93 
94  return renderer;
95  }
96  else
97  {
98  // printf("title %s \n",data.m_node->GetTitle());
99  renderer->setIsParent(false);
100  renderer->setIndentation(0);
101  if (iCol == kColorColumn)
102  {
103  // m_colorBoxRenderer.setData(data.m_node->GetVolume()->GetLineColor(), isSelected);
104  m_colorBoxRenderer.setData(data.m_color, isSelected);
105  return &m_colorBoxRenderer;
106  }
107  else if (iCol == kTranspColumn)
108  {
109  renderer->setData(Form("%d", 100 -data.m_transparency), isSelected);
110  return renderer;
111  }
112  else if (iCol == kVisSelfColumn)
113  {
114  renderer->setData(getVisibility(data) ? "On" : "-", isSelected);
115  return renderer;
116  }
117  else if (iCol == kVisChildColumn)
118  {
119  renderer->setData( getVisibilityChld(data) ? "On" : "-", isSelected);
120  return renderer;
121  }
122  else if (iCol == kMaterialColumn)
123  {
124  renderer->setData( gn.GetVolume()->GetMaterial()->GetName(), isSelected);
125  return renderer;
126  }
127  else
128  { renderer->setData("ERROR", false);
129  return renderer;
130  }
131  }
132 }
133 
134 //------------------------------------------------------------------------------
135 
137 {
138  NodeInfo& parent = m_entries[parent_idx];
139  TGeoNode* parentGeoNode = parent.m_node;
140  int parentLevel = parent.m_level;
141 
142  int nV = parentGeoNode->GetNdaughters();
143  int dOff = 0;
144  for (int n = 0; n != nV; ++n)
145  {
146  NodeInfo& data = m_entries[parent_idx + n + 1 + dOff];
147  data.m_node = parentGeoNode->GetDaughter(n);
148  data.m_level = parentLevel + 1;
149  data.m_parent = parent_idx;
150  data.m_color = data.m_node->GetVolume()->GetLineColor();
151  data.m_transparency = data.m_node->GetVolume()->GetTransparency();
152  if (data.m_level <= m_browser->getAutoExpand()) data.setBit(kExpanded);
153 
154  importChildren(parent_idx + n + 1 + dOff);
155  getNNodesTotal(parentGeoNode->GetDaughter(n), dOff);
156  }
157 }
158 
159 //==============================================================================
160 
162 {
163  // Used for debug: in a NodeInfo entry look TGeoNode children from parent index and check
164  // if child is found.
165 
166  for (size_t i = 0, e = m_entries.size(); i != e; ++i)
167  {
168  if (m_entries[i].m_level > 0)
169  {
170  TGeoNode* pn = m_entries[m_entries[i].m_parent].m_node;
171  bool ok = false;
172  for (int d = 0; d < pn->GetNdaughters(); ++d)
173  {
174  if (m_entries[i].m_node == pn->GetDaughter(d))
175  {
176  ok = true;
177  break;
178  }
179  }
180  if (! ok) printf("!!!!!! node %s has false parent %s \n", m_entries[i].name(), pn->GetName());
181  }
182  }
183 }
184 
185 void FWGeometryTableManager::checkChildMatches(TGeoVolume* vol, std::vector<TGeoVolume*>& pstack)
186 {
187  if (m_volumes[vol].m_matches)
188  {
189  for (std::vector<TGeoVolume*>::iterator i = pstack.begin(); i != pstack.end(); ++i)
190  {
191  Match& pm = m_volumes[*i];
192  pm.m_childMatches = true;
193  }
194  }
195 
196  pstack.push_back(vol);
197 
198  int nD = vol->GetNdaughters(); //TMath::Min(m_browser->getMaxDaughters(), vol->GetNdaughters());
199  for (int i = 0; i < nD; ++i)
200  checkChildMatches(vol->GetNode(i)->GetVolume(), pstack);
201 
202  pstack.pop_back();
203 }
204 
205 
206 //------------------------------------------------------------------------------
207 // Callbacks
208 //------------------------------------------------------------------------------
209 
211 {
212  std::string filterExp = m_browser->getFilter();
213  m_filterOff = filterExp.empty();
214  printf("update filter %s OFF %d volumes size %d\n",filterExp.c_str(), m_filterOff , (int)m_volumes.size());
215 
216  if (m_filterOff || m_entries.empty()) return;
217 
218  // update volume-match entries
219  int numMatched = 0;
220  for (Volumes_i i = m_volumes.begin(); i != m_volumes.end(); ++i)
221  {
222  const char* res = nullptr;
223 
225  {
226  res = strcasestr( i->first->GetMaterial()->GetName() , filterExp.c_str());
227  }
229  {
230  res = strcasestr( i->first->GetMaterial()->GetTitle() , filterExp.c_str());
231  }
232  else if (iType == FWGeometryTableView::kFilterShapeName)
233  {
234  res = strcasestr( i->first->GetShape()->GetName() , filterExp.c_str());
235  }
237  {
238  res = strcasestr( i->first->GetShape()->ClassName() , filterExp.c_str());
239  }
240 
241  i->second.m_matches = (res != nullptr);
242  i->second.m_childMatches = false;
243  if (res != nullptr) numMatched++;
244  }
245 
246  printf("update filter [%d] volumes matched\n", numMatched);
247  std::vector<TGeoVolume*> pstack;
248  checkChildMatches(m_entries[0].m_node->GetVolume(), pstack);
249 
250  for (Entries_i ni = m_entries.begin(); ni != m_entries.end(); ++ni)
251  {
252  ni->resetBit(kFilterCached);
254  }
255 
256 }
257 
258 //==============================================================================
259 
260 void FWGeometryTableManager::loadGeometry(TGeoNode* iGeoTopNode, TObjArray* iVolumes)
261 {
262 #ifdef PERFTOOL_GEO_TABLE
263  ProfilerStart("loadGeo");
264 #endif
265 
266  // Prepare data for cell render.
267 
268  // clear entries
269  m_entries.clear();
270  m_row_to_index.clear();
271  m_volumes.clear();
272  m_levelOffset = 0;
273 
274  // set volume table for filters
275  boost::unordered_map<TGeoVolume*, Match> pipi(iVolumes->GetSize());
276  m_volumes.swap(pipi);
277  TIter next( iVolumes);
278  TGeoVolume* v;
279  while ((v = (TGeoVolume*) next()) != nullptr)
280  m_volumes.insert(std::make_pair(v, Match()));
281 
282  if (!m_filterOff)
284 
285  // add top node to init
286 
287  int nTotal = 0;
288  NodeInfo topNodeInfo;
289  topNodeInfo.m_node = iGeoTopNode;
290  topNodeInfo.m_level = 0;
291  topNodeInfo.m_parent = -1;
292  topNodeInfo.m_color = iGeoTopNode->GetVolume()->GetLineColor();
293  topNodeInfo.m_transparency = iGeoTopNode->GetVolume()->GetTransparency();
294  topNodeInfo.setBitVal(kExpanded, m_browser->getAutoExpand());
295  topNodeInfo.setBitVal(kVisNodeSelf, m_browser->drawTopNode());
296 
297  getNNodesTotal(topNodeInfo.m_node , nTotal);
298  m_entries.resize(nTotal+1);
299  m_entries[0] = topNodeInfo;
300 
301  importChildren(0);
302 
303  // checkHierarchy();
304 
305 #ifdef PERFTOOL_GEO_TABLE
306  ProfilerStop();
307 #endif
308 }
309 
310 //------------------------------------------------------------------------------
311 
313 {
314  std::cerr << "not implemented \n";
315 }
316 
317 //------------------------------------------------------------------------------
318 
320 {
321  m_row_to_index.clear();
322 
323  int i = TMath::Max(0, m_browser->getTopNodeIdx());
324  m_row_to_index.push_back(i);
325 
326  NodeInfo& data = m_entries[i];
327 
328  if (!m_filterOff)
329  assertNodeFilterCache(data);
330 
331  if ((m_filterOff && data.testBit(kExpanded) == false) ||
332  (m_filterOff == false && data.testBit(kChildMatches) == false))
333  return;
334 
335  if (m_browser->getVolumeMode())
337  else
339 
340  // printf (" child [%d] FWGeometryTableManagerBase::recalculateVisibility table size %d \n", (int)m_row_to_index.size());
341 }
342 
343 //------------------------------------------------------------------------------
344 
346 {
347  TGeoNode* parentNode = m_entries[pIdx].m_node;
348  int nD = parentNode->GetNdaughters();
349  int dOff=0;
350 
351  // printf("----------- parent %s\n", parentNode->GetName() );
352 
353  std::vector<int> vi;
354  vi.reserve(nD);
355 
356  for (int n = 0; n != nD; ++n)
357  {
358  int idx = pIdx + 1 + n + dOff;
360 
361  bool toAdd = true;
362  for (std::vector<int>::iterator u = vi.begin(); u != vi.end(); ++u )
363  {
364  TGeoVolume* neighbourVolume = parentNode->GetDaughter(*u)->GetVolume();
365  if (neighbourVolume == data.m_node->GetVolume())
366  {
367  toAdd = false;
368  // printf("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
369  break;
370  }
371  }
372 
373  if (toAdd)
374  {
375  vi.push_back(n);
376  if (m_filterOff)
377  {
378  // std::cout << data.nameIndent() << std::endl;
379  m_row_to_index.push_back(idx);
381  }
382  else
383  {
384  assertNodeFilterCache(data);
385  if (data.testBitAny(kMatches | kChildMatches)) m_row_to_index.push_back(idx);
387  }
388  }
389  FWGeometryTableManagerBase::getNNodesTotal(parentNode->GetDaughter(n), dOff);
390  }
391 }
392 
393 //------------------------------------------------------------------------------
394 
396 {
397  TGeoNode* parentNode = m_entries[pIdx].m_node;
398  int nD = parentNode->GetNdaughters();
399  int dOff = 0;
400  for (int n = 0; n != nD; ++n)
401  {
402  int idx = pIdx + 1 + n + dOff;
404 
405  if (m_filterOff)
406  {
407  m_row_to_index.push_back(idx);
409  }
410  else
411  {
412  assertNodeFilterCache(data);
413  if (data.testBitAny(kMatches | kChildMatches)) m_row_to_index.push_back(idx);
415  }
416 
417  FWGeometryTableManagerBase::getNNodesTotal(parentNode->GetDaughter(n), dOff);
418  }
419 }
420 
421 //------------------------------------------------------------------------------
422 
424 {
425  if (! data.testBit(kFilterCached))
426  {
427  bool matches = m_volumes[data.m_node->GetVolume()].m_matches;
428  // if (matches) printf("%s matches filter \n", data.name());
429  data.setBitVal(kMatches, matches);
430  setVisibility(data, matches);
431 
432  bool childMatches = m_volumes[data.m_node->GetVolume()].m_childMatches;
433  data.setBitVal(kChildMatches, childMatches);
434  data.setBitVal(kExpanded, childMatches);
435  setVisibilityChld(data, childMatches);
436 
437  data.setBit(kFilterCached);
438  // printf("%s matches [%d] childMatches [%d] ................ %d %d \n", data.name(), data.testBit(kMatches), data.testBit(kChildMatches), matches , childMatches);
439  }
440 }
441 
442 //------------------------------------------------------------------------------
443 
445 {
446  if (m_browser->getVolumeMode())
447  {
448  if (data.m_node->GetVolume()->IsVisible() != x)
449  {
451  data.m_node->GetVolume()->SetVisibility(x);
452  }
453  }
454  else
455  {
456  data.setBitVal(kVisNodeSelf, x);
457  }
458 }
459 
460 //------------------------------------------------------------------------------
461 
463 {
464  if (m_browser->getVolumeMode())
465  {
466  if (data.m_node->GetVolume()->IsVisibleDaughters() != x)
467  {
468  TEveGeoManagerHolder gmgr( FWGeometryTableViewManager::getGeoMangeur());
469  data.m_node->GetVolume()->VisibleDaughters(x);
470  }
471  }
472  else
473  {
474  data.setBitVal(kVisNodeChld, x);
475  }
476 }
477 //______________________________________________________________________________
478 
480 {
481  TGeoNode *parentNode = m_entries[selectedIdx].m_node;
482  int nD = parentNode->GetNdaughters();
483  int dOff = 0;
484  for (int n = 0; n != nD; ++n)
485  {
486  int idx = selectedIdx + 1 + n + dOff;
488 
489  setVisibility(data, v);
490  setVisibilityChld(data, v);
491 
492  FWGeometryTableManager::getNNodesTotal(parentNode->GetDaughter(n), dOff);
493  }
494 }
495 
496 //------------------------------------------------------------------------------
497 
499 {
500  if (m_browser->getVolumeMode())
501  return data.m_node->GetVolume()->IsVisible();
502 
503  return data.testBit(kVisNodeSelf);
504 }
505 
507 {
508  if (m_browser->getVolumeMode())
509  return data.m_node->GetVolume()->IsVisibleDaughters();
510 
511  return data.testBit(kVisNodeChld);
512 }
513 
514 //------------------------------------------------------------------------------
515 
517 {
518  return (data.m_node->GetNdaughters() != 0) && (m_filterOff || data.testBit(kChildMatches));
519 }
520 
521 //------------------------------------------------------------------------------
522 
524 {
525  double sqr_r = radius * radius;
526 
527  for (Entries_i ni = m_entries.begin(); ni != m_entries.end(); ++ni)
528  ni->resetBit(kVisNodeChld);
529 
530  int cnt = 0;
531  TEveGeoManagerHolder mangeur( FWGeometryTableViewManager::getGeoMangeur());
532  printf("FWGeometryTableManagerBase::checkRegionOfInterest BEGIN r=%d center= (%.1f, %.1f, %.1f)\n ", (int)radius, center[0], center[1], center[2]);
533  TGeoIterator git(m_entries[0].m_node->GetVolume());
534  Entries_i eit(m_entries.begin());
535  while (git())
536  {
537  const TGeoMatrix *gm = git.GetCurrentMatrix();
538  const TGeoBBox *bb = static_cast<TGeoBBox*>(eit->m_node->GetVolume()->GetShape());
539  const Double_t *bo = bb->GetOrigin();
540  const Double_t bd[] = { bb->GetDX(), bb->GetDY(), bb->GetDZ() };
541  const Double_t *cc = center;
542 
543  bool visible = false;
544 
545  switch (algo)
546  {
548  {
549  const Double_t *t = gm->GetTranslation();
550  TEveVectorD d(cc[0] - (t[0] + bo[0]), cc[1] - (t[1] + bo[1]), cc[2] - (t[2] + bo[2]));
551  Double_t sqr_d = d.Mag2();;
552  visible = (sqr_d <= sqr_r);
553  break;
554  }
556  {
557  assert (gm->IsScale() == false);
558 
559  const Double_t *t = gm->GetTranslation();
560  const Double_t *r = gm->GetRotationMatrix();
561  TEveVectorD d(cc[0] - (t[0] + bo[0]), cc[1] - (t[1] + bo[1]), cc[2] - (t[2] + bo[2]));
562  Double_t sqr_d = 0;
563  for (Int_t i = 0; i < 3; ++i)
564  {
565  Double_t dp = d[0]*r[i] + d[1]*r[i+3] + d[2]*r[i+6];
566  if (dp < -bd[i])
567  {
568  Double_t delta = dp + bd[i];
569  sqr_d += delta * delta;
570  }
571  else if (dp > bd[i])
572  {
573  Double_t delta = dp - bd[i];
574  sqr_d += delta * delta;
575  }
576  }
577  visible = (sqr_d <= sqr_r);
578  }
579  }
580 
581  if (visible)
582  {
583  eit->setBit(kVisNodeSelf);
584  int pidx = eit->m_parent;
585  while (pidx >= 0)
586  {
587  m_entries[pidx].setBit(kVisNodeChld);
588  pidx = m_entries[pidx].m_parent;
589  ++cnt;
590  }
591  }
592  else
593  {
594  eit->resetBit(kVisNodeSelf);
595  }
596  eit++;
597  }
598 
599  printf("FWGeometryTableManager::checkRegionOfInterest END [%d]\n ", cnt);
600 }
601 
603 {
604  for (Entries_i ni = m_entries.begin(); ni != m_entries.end(); ++ni)
605  {
606  ni->setBit(kVisNodeSelf);
607  ni->setBit(kVisNodeChld);
608  }
609  // ni->setMatchRegion(true);
610 }
dbl * delta
Definition: mlp_gen.cc:36
FWGeometryTableView * m_browser
bool getVisibility(const NodeInfo &nodeInfo) const override
FWGeometryTableManager(FWGeometryTableView *)
void checkRegionOfInterest(double *center, double radius, long algo)
std::string getFilter() const
const char * cellName(const NodeInfo &data) const override
void setDaughtersSelfVisibility(int i, bool v) override
FWTableCellRendererBase * cellRenderer(int iSortedRowNumber, int iCol) const override
Definition: Electron.h:6
bool getVisibilityChld(const NodeInfo &nodeInfo) const override
void assertNodeFilterCache(NodeInfo &data)
virtual void setIndentation(int indentation=0)
T Max(T a, T b)
Definition: MathUtil.h:44
static void getNNodesTotal(TGeoNode *geoNode, int &off)
void setData(const std::string &, bool isSelected)
auto dp
Definition: deltaR.h:22
void loadGeometry(TGeoNode *iGeoTopNode, TObjArray *iVolumes)
void checkChildMatches(TGeoVolume *v, std::vector< TGeoVolume * > &)
def Match(required, got)
bool getVolumeMode() const
void setVisibility(NodeInfo &nodeInfo, bool) override
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
Volumes_t::iterator Volumes_i
void importChildren(int parent_idx)
void setVisibilityChld(NodeInfo &nodeInfo, bool) override
bool nodeIsParent(const NodeInfo &) const override
virtual void showEditor(bool value)