43 ClassImp(TEveGeoNode);
45 Int_t TEveGeoNode::fgCSGExportNSeg = 64;
46 std::list<TGeoShape*> TEveGeoNode::fgTemporaryStore;
51 Int_t TEveGeoNode::GetCSGExportNSeg()
53 return fgCSGExportNSeg;
59 void TEveGeoNode::SetCSGExportNSeg(Int_t nseg)
61 fgCSGExportNSeg = nseg;
67 TEveGeoNode::TEveGeoNode(TGeoNode* node) :
73 char* l = (
char*) dynamic_cast<TAttLine*>(node->GetVolume());
74 SetMainColorPtr((Color_t*)(l +
sizeof(
void*)));
75 SetMainTransparency(fNode->GetVolume()->GetTransparency());
77 SetRnrSelfChildren(fNode->IsVisible(), fNode->IsVisDaughters());
83 const char* TEveGeoNode::GetName()
const
85 return fNode->GetName();
91 const char* TEveGeoNode::GetTitle()
const
93 return fNode->GetTitle();
99 const char* TEveGeoNode::GetElementName()
const
101 return fNode->GetName();
107 const char* TEveGeoNode::GetElementTitle()
const
109 return fNode->GetTitle();
116 void TEveGeoNode::ExpandIntoListTree(TGListTree* ltree,
117 TGListTreeItem* parent)
119 if ( ! HasChildren() && fNode->GetVolume()->GetNdaughters() > 0)
121 TIter next(fNode->GetVolume()->GetNodes());
123 while ((dnode = (TGeoNode*) next()) != 0)
125 TEveGeoNode* node_re =
new TEveGeoNode(dnode);
129 TEveElement::ExpandIntoListTree(ltree, parent);
135 void TEveGeoNode::ExpandIntoListTrees()
137 for (sLTI_i i = fItems.begin(); i != fItems.end(); ++i)
139 ExpandIntoListTree(i->fTree, i->fItem);
147 void TEveGeoNode::ExpandIntoListTreesRecursively()
149 ExpandIntoListTrees();
150 for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i)
152 TEveGeoNode *egn =
dynamic_cast<TEveGeoNode*
>(*i);
154 egn->ExpandIntoListTreesRecursively();
162 void TEveGeoNode::AddStamp(UChar_t bits)
164 TEveElement::AddStamp(bits);
165 if (bits & kCBVisibility)
167 fNode->SetVisibility(fRnrSelf);
168 fNode->VisibleDaughters(fRnrChildren);
175 Bool_t TEveGeoNode::CanEditMainColor()
const
177 return ! fNode->GetVolume()->IsAssembly();
183 void TEveGeoNode::SetMainColor(Color_t color)
185 TEveElement::SetMainColor(color);
186 fNode->GetVolume()->SetLineColor(color);
192 Bool_t TEveGeoNode::CanEditMainTransparency()
const
194 return ! fNode->GetVolume()->IsAssembly();
200 Char_t TEveGeoNode::GetMainTransparency()
const
202 return fNode->GetVolume()->GetTransparency();
208 void TEveGeoNode::SetMainTransparency(Char_t t)
210 TEveElement::SetMainTransparency(t);
211 fNode->GetVolume()->SetTransparency(t);
222 void TEveGeoNode::UpdateNode(TGeoNode* node)
224 static const TEveException eH(
"TEveGeoNode::UpdateNode ");
229 StampColorSelection();
231 for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
232 ((TEveGeoNode*)(*i))->UpdateNode(node);
244 void TEveGeoNode::UpdateVolume(TGeoVolume* volume)
246 static const TEveException eH(
"TEveGeoNode::UpdateVolume ");
250 if(fNode->GetVolume() == volume)
251 StampColorSelection();
253 for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
254 ((TEveGeoNode*)(*i))->UpdateVolume(volume);
261 void TEveGeoNode::Draw(Option_t* option)
265 fNode->GetVolume()->Draw(opt);
272 void TEveGeoNode::Save(
const char* file,
const char* name, Bool_t leafs_only)
274 Warning(
"Save()",
"This function is deprecated, use SaveExtract() instead.");
275 SaveExtract(file, name, leafs_only);
282 void TEveGeoNode::SaveExtract(
const char* file,
const char* name, Bool_t leafs_only)
284 TEveGeoShapeExtract* gse = DumpShapeTree(
this, 0, leafs_only);
287 TFile f(file,
"RECREATE");
292 for (std::list<TGeoShape*>::iterator i = fgTemporaryStore.begin(); i != fgTemporaryStore.end(); ++i)
294 fgTemporaryStore.clear();
300 void TEveGeoNode::WriteExtract(
const char* name, Bool_t leafs_only)
302 TEveGeoShapeExtract* gse = DumpShapeTree(
this, 0, leafs_only);
312 TEveGeoShapeExtract* TEveGeoNode::DumpShapeTree(TEveGeoNode* geon,
313 TEveGeoShapeExtract* parent,
316 static const TEveException eh(
"TEveGeoNode::DumpShapeTree ");
319 TGeoVolume* tvolume = 0;
320 TGeoShape* tshape = 0;
322 tnode = geon->GetNode();
325 Info(eh,
"Null TGeoNode for TEveGeoNode '%s': assuming it's a holder and descending.", geon->GetName());
329 tvolume = tnode->GetVolume();
331 Warning(eh,
"Null TGeoVolume for TEveGeoNode '%s'; skipping its sub-tree.\n", geon->GetName());
334 tshape = tvolume->GetShape();
335 if (tshape->IsComposite())
338 TEvePadHolder gpad(kFALSE, &pad);
339 pad.GetListOfPrimitives()->Add(tshape);
340 TGLScenePad scene_pad(&pad);
341 pad.SetViewer3D(&scene_pad);
344 TEveGeoManagerHolder gmgr(tvolume->GetGeoManager(), fgCSGExportNSeg);
345 gGeoManager->SetPaintVolume(tvolume);
347 TGeoMatrix *gst = TGeoShape::GetTransform();
348 TGeoShape::SetTransform(TEveGeoShape::GetGeoHMatrixIdentity());
350 scene_pad.BeginScene();
351 dynamic_cast<TGeoCompositeShape*
>(tshape)->PaintComposite();
352 scene_pad.EndScene();
354 TGeoShape::SetTransform(gst);
359 TGLFaceSet* fs =
dynamic_cast<TGLFaceSet*
>(scene_pad.FindLogical(tvolume));
361 Warning(eh,
"Failed extracting CSG tesselation TEveGeoNode '%s'; skipping its sub-tree.\n", geon->GetName());
365 TEveGeoPolyShape* egps =
new TEveGeoPolyShape();
366 egps->SetFromFaceSet(fs);
368 fgTemporaryStore.push_back(egps);
375 trans.SetFromArray(parent->GetTrans());
378 TGeoMatrix *gm = tnode->GetMatrix();
379 const Double_t *rm = gm->GetRotationMatrix();
380 const Double_t *tv = gm->GetTranslation();
382 t(1,1) = rm[0]; t(1,2) = rm[1]; t(1,3) = rm[2];
383 t(2,1) = rm[3]; t(2,2) = rm[4]; t(2,3) = rm[5];
384 t(3,1) = rm[6]; t(3,2) = rm[7]; t(3,3) = rm[8];
385 t(1,4) = tv[0]; t(2,4) = tv[1]; t(3,4) = tv[2];
389 TEveGeoShapeExtract* gse =
new TEveGeoShapeExtract(geon->GetName(), geon->GetTitle());
390 gse->SetTrans(trans.Array());
394 ci = tvolume->GetLineColor();
395 transp = tvolume->GetTransparency();
397 TColor* c = gROOT->GetColor(ci);
398 Float_t rgba[4] = {1, 0, 0, 1.0f - transp/100.0f};
400 rgba[0] = c->GetRed();
401 rgba[1] = c->GetGreen();
402 rgba[2] = c->GetBlue();
406 c = gROOT->GetColor(TColor::GetColorDark(ci));
408 rgba[0] = c->GetRed();
409 rgba[1] = c->GetGreen();
410 rgba[2] = c->GetBlue();
412 gse->SetRGBALine(rgba);
415 Bool_t rnr = tnode ? tnode->IsVisible() : geon->GetRnrSelf();
416 Bool_t rnr_els = tnode ? tnode->IsVisDaughters() : geon->GetRnrChildren();
418 rnr = rnr && tvolume->IsVisible();
419 rnr_els = rnr_els && tvolume->IsVisDaughters();
421 gse->SetRnrSelf (rnr);
422 gse->SetRnrElements(rnr_els);
423 gse->SetRnrFrame (kTRUE);
424 gse->SetMiniFrame (kTRUE);
426 gse->SetShape((leafs_only && geon->HasChildren()) ? 0 : tshape);
428 if (geon->HasChildren())
430 TList* ele =
new TList();
431 gse->SetElements(ele);
432 gse->GetElements()->SetOwner(
true);
434 TEveElement::List_i i = geon->BeginChildren();
435 while (i != geon->EndChildren())
437 TEveGeoNode* l =
dynamic_cast<TEveGeoNode*
>(*i);
438 DumpShapeTree(l, gse, leafs_only);
444 parent->GetElements()->Add(gse);
461 ClassImp(TEveGeoTopNode);
466 TEveGeoTopNode::TEveGeoTopNode(TGeoManager* manager, TGeoNode* node,
467 Int_t visopt, Int_t vislvl, Int_t maxvisnds) :
472 fMaxVisNodes (maxvisnds)
482 void TEveGeoTopNode::UseNodeTrans()
484 RefMainTrans().SetFrom(*fNode->GetMatrix());
492 void TEveGeoTopNode::AddStamp(UChar_t bits)
494 TEveElement::AddStamp(bits);
500 void TEveGeoTopNode::Draw(Option_t* option)
510 void TEveGeoTopNode::Paint(Option_t* option)
514 TEveGeoManagerHolder geo_holder(fManager);
515 TVirtualPad *pad = gPad;
517 TGeoVolume* top_volume = fManager->GetTopVolume();
519 fManager->SetVisLevel(fVisLevel);
521 fManager->SetMaxVisNodes(fMaxVisNodes);
522 TVirtualGeoPainter* vgp = fManager->GetGeomPainter();
523 fManager->SetTopVolume(fNode->GetVolume());
527 fNode->GetVolume()->SetVisContainers(kTRUE);
528 fManager->SetTopVisible(kTRUE);
531 fNode->GetVolume()->SetVisLeaves(kTRUE);
532 fManager->SetTopVisible(kFALSE);
535 fNode->GetVolume()->SetVisOnly(kTRUE);
540 vgp->SetVisOption(fVisOption);
542 if (HasMainTrans()) RefMainTrans().SetGeoHMatrix(geomat);
543 vgp->PaintNode(fNode, option, &geomat);
545 fManager->SetTopVolume(top_volume);
552 void TEveGeoTopNode::VolumeVisChanged(TGeoVolume* volume)
554 static const TEveException eh(
"TEveGeoTopNode::VolumeVisChanged ");
555 printf(
"%s volume %s %p\n", eh.Data(), volume->GetName(), (
void*)volume);
556 UpdateVolume(volume);
562 void TEveGeoTopNode::VolumeColChanged(TGeoVolume* volume)
564 static const TEveException eh(
"TEveGeoTopNode::VolumeColChanged ");
565 printf(
"%s volume %s %p\n", eh.Data(), volume->GetName(), (
void*)volume);
566 UpdateVolume(volume);
572 void TEveGeoTopNode::NodeVisChanged(TGeoNode* node)
574 static const TEveException eh(
"TEveGeoTopNode::NodeVisChanged ");
575 printf(
"%s node %s %p\n", eh.Data(), node->GetName(), (
void*)node);