4 #include <Reve/ReveManager.h>
5 #include <Reve/NLTPolygonSet.h>
7 #include "TGeoShapeExtract.h"
8 #include "TGeoMatrix.h"
11 #include <TBuffer3D.h>
12 #include <TVirtualViewer3D.h>
16 #include <TGeoShape.h>
17 #include <TGeoVolume.h>
19 #include <TGeoShapeAssembly.h>
20 #include <TGeoManager.h>
21 #include <TVirtualGeoPainter.h>
26 //______________________________________________________________________
30 ClassImp(GeoNodeRnrEl)
32 GeoNodeRnrEl::GeoNodeRnrEl(TGeoNode* node) :
37 // Hack!! Should use cint to retrieve TAttLine::fLineColor offset.
38 char* l = (char*) dynamic_cast<TAttLine*>(node->GetVolume());
39 SetMainColorPtr((Color_t*)(l + sizeof(void*)));
41 fRnrSelf = fNode->TGeoAtt::IsVisible();
44 const Text_t* GeoNodeRnrEl::GetName() const { return fNode->GetName(); }
45 const Text_t* GeoNodeRnrEl::GetTitle() const { return fNode->GetTitle(); }
47 /**************************************************************************/
49 Int_t GeoNodeRnrEl::ExpandIntoListTree(TGListTree* ltree,
50 TGListTreeItem* parent)
52 // Checks if child-nodes have been imported ... imports them if not.
53 // Then calls RenderElement::ExpandIntoListTree.
55 if(fChildren.empty() && fNode->GetVolume()->GetNdaughters() > 0) {
56 TIter next(fNode->GetVolume()->GetNodes());
58 while((dnode = (TGeoNode*) next()) != 0) {
59 GeoNodeRnrEl* node_re = new GeoNodeRnrEl(dnode);
63 return RenderElement::ExpandIntoListTree(ltree, parent);
66 /**************************************************************************/
68 void GeoNodeRnrEl::SetRnrSelf(Bool_t rnr)
70 RenderElement::SetRnrSelf(rnr);
71 fNode->SetVisibility(rnr);
74 void GeoNodeRnrEl::SetRnrChildren(Bool_t rnr)
76 RenderElement::SetRnrChildren(rnr);
77 fNode->VisibleDaughters(rnr);
80 void GeoNodeRnrEl::SetRnrState(Bool_t rnr)
82 RenderElement::SetRnrState(rnr);
83 fNode->SetVisibility(rnr);
84 fNode->VisibleDaughters(rnr);
87 /**************************************************************************/
89 void GeoNodeRnrEl::SetMainColor(Color_t color)
91 fNode->GetVolume()->SetLineColor(color);
95 void GeoNodeRnrEl::SetMainColor(Pixel_t pixel)
97 // This one needed for proper calling via CINT (signals).
99 SetMainColor(Color_t(TColor::GetColor(pixel)));
102 /**************************************************************************/
104 void GeoNodeRnrEl::UpdateNode(TGeoNode* node)
106 // Updates all reve-browsers having the node in their contents.
107 // All 3D-pads updated if any change found.
109 // Should (could?) be optimized with some assumptions about
110 // volume/node structure (search for parent, know the same node can not
111 // reoccur on lower level once found).
113 static const Exc_t eH("GeoNodeRnrEl::UpdateNode ");
115 // printf("%s node %s %p\n", eH.Data(), node->GetName(), node);
120 for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
121 ((GeoNodeRnrEl*)(*i))->UpdateNode(node);
126 void GeoNodeRnrEl::UpdateVolume(TGeoVolume* volume)
128 // Updates all reve-browsers having the volume in their contents.
129 // All 3D-pads updated if any change found.
131 // Should (could?) be optimized with some assumptions about
132 // volume/node structure (search for parent, know the same node can not
133 // reoccur on lower level once found).
135 static const Exc_t eH("GeoNodeRnrEl::UpdateVolume ");
137 // printf("%s volume %s %p\n", eH.Data(), volume->GetName(), volume);
139 if(fNode->GetVolume() == volume)
142 for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
143 ((GeoNodeRnrEl*)(*i))->UpdateVolume(volume);
147 /**************************************************************************/
149 void GeoNodeRnrEl::Draw(Option_t* option)
153 fNode->GetVolume()->Draw(opt);
156 /**************************************************************************/
158 void GeoNodeRnrEl::Save(const char* file, const char* name)
160 TGeoShapeExtract* gse = DumpShapeTree(this, 0, 0);
162 TFile f(file, "RECREATE");
167 /**************************************************************************/
169 TGeoShapeExtract* GeoNodeRnrEl::DumpShapeTree(GeoNodeRnrEl* geon, TGeoShapeExtract* parent, Int_t level)
171 printf("dump_shape_tree %s \n", geon->GetName());
173 TGeoVolume* tvolume = 0;
174 TGeoShape* tshape = 0;
176 tnode = geon->GetNode();
178 printf("Null node for %s; assuming it's a holder and descending.\n", geon->GetName());
182 tvolume = tnode->GetVolume();
184 printf("Null volume for %s; skipping.\n", geon->GetName());
188 tshape = tvolume->GetShape();
193 if (parent) if (parent) trans.SetFromArray(parent->GetTrans());
194 TGeoMatrix* gm = tnode->GetMatrix();
195 const Double_t* rm = gm->GetRotationMatrix();
196 const Double_t* tv = gm->GetTranslation();
198 t(1,1) = rm[0]; t(1,2) = rm[1]; t(1,3) = rm[2];
199 t(2,1) = rm[3]; t(2,2) = rm[4]; t(2,3) = rm[5];
200 t(3,1) = rm[6]; t(3,2) = rm[7]; t(3,3) = rm[8];
201 t(1,4) = tv[0]; t(2,4) = tv[1]; t(3,4) = tv[2];
204 TGeoShapeExtract* gse = new TGeoShapeExtract(geon->GetName(), geon->GetTitle());
205 gse->SetTrans(trans.Array());
207 if(tvolume) ci = tvolume->GetLineColor();
208 TColor* c = gROOT->GetColor(ci);
209 Float_t rgba[4] = {1, 0, 0, 1};
211 rgba[0] = c->GetRed();
212 rgba[1] = c->GetGreen();
213 rgba[2] = c->GetBlue();
216 Bool_t rnr = geon->GetRnrSelf();
217 if(level > gGeoManager->GetVisLevel())
219 gse->SetRnrSelf(rnr);
220 gse->SetRnrElements(geon->GetRnrChildren());
222 if(dynamic_cast<TGeoShapeAssembly*>(tshape)){
223 // printf("<TGeoShapeAssembly \n");
226 gse->SetShape(tshape);
228 if ( geon->GetNChildren())
230 TList* ele = new TList();
231 gse->SetElements(ele);
232 gse->GetElements()->SetOwner(true);
234 RenderElement::List_i i = geon->BeginChildren();
235 while (i != geon->EndChildren()) {
236 GeoNodeRnrEl* l = dynamic_cast<GeoNodeRnrEl*>(*i);
237 DumpShapeTree(l, gse, level+1);
243 parent->GetElements()->Add(gse);
247 /**************************************************************************/
248 //______________________________________________________________________
251 // A wrapper over a TGeoNode, possibly displaced with a global
252 // trasformation fGlobalTrans (the matrix is owned by this class).
253 /**************************************************************************/
255 ClassImp(GeoTopNodeRnrEl)
257 GeoTopNodeRnrEl::GeoTopNodeRnrEl(TGeoManager* manager, TGeoNode* node,
258 Int_t visopt, Int_t vislvl) :
268 GeoTopNodeRnrEl::~GeoTopNodeRnrEl()
271 /**************************************************************************/
273 void GeoTopNodeRnrEl::SetGlobalTrans(const TGeoHMatrix* m)
275 fGlobalTrans.SetFrom(*m);
278 void GeoTopNodeRnrEl::UseNodeTrans()
280 fGlobalTrans.SetFrom(*fNode->GetMatrix());
283 /**************************************************************************/
285 void GeoTopNodeRnrEl::SetVisOption(Int_t visopt)
291 void GeoTopNodeRnrEl::SetVisLevel(Int_t vislvl)
297 /**************************************************************************/
299 void GeoTopNodeRnrEl::SetRnrSelf(Bool_t rnr)
301 // Revert from GeoNode to back to standard behaviour.
302 RenderElement::SetRnrSelf(rnr);
305 /**************************************************************************/
307 void GeoTopNodeRnrEl::Draw(Option_t* option)
312 void GeoTopNodeRnrEl::Paint(Option_t* option)
315 gGeoManager = fManager;
316 TVirtualPad* pad = gPad;
318 TGeoVolume* top_volume = fManager->GetTopVolume();
319 fManager->SetVisOption(fVisOption);
320 fManager->SetVisLevel(fVisLevel);
321 fManager->SetTopVolume(fNode->GetVolume());
323 TVirtualGeoPainter* vgp = fManager->GetGeomPainter();
326 fGlobalTrans.SetGeoHMatrix(geomat);
327 vgp->PaintNode(fNode, option, &geomat);
329 fManager->SetTopVolume(top_volume);
333 /**************************************************************************/
335 void GeoTopNodeRnrEl::VolumeVisChanged(TGeoVolume* volume)
337 static const Exc_t eH("GeoTopNodeRnrEl::VolumeVisChanged ");
338 printf("%s volume %s %p\n", eH.Data(), volume->GetName(), (void*)volume);
339 UpdateVolume(volume);
342 void GeoTopNodeRnrEl::VolumeColChanged(TGeoVolume* volume)
344 static const Exc_t eH("GeoTopNodeRnrEl::VolumeColChanged ");
345 printf("%s volume %s %p\n", eH.Data(), volume->GetName(), (void*)volume);
346 UpdateVolume(volume);
349 void GeoTopNodeRnrEl::NodeVisChanged(TGeoNode* node)
351 static const Exc_t eH("GeoTopNodeRnrEl::NodeVisChanged ");
352 printf("%s node %s %p\n", eH.Data(), node->GetName(), (void*)node);
357 /**************************************************************************/
358 //______________________________________________________________________
361 // Minimal shape-wrapper allowing import of stuff from gled and retaining
362 // user-set visibility, colors and transparency.
363 /**************************************************************************/
365 ClassImp(GeoShapeRnrEl)
367 GeoShapeRnrEl::GeoShapeRnrEl(const Text_t* name, const Text_t* title) :
369 TNamed (name, title),
375 fMainColorPtr = &fColor;
378 GeoShapeRnrEl::~GeoShapeRnrEl()
381 fShape->SetUniqueID(fShape->GetUniqueID() - 1);
382 if (fShape->GetUniqueID() == 0)
387 /**************************************************************************/
389 void GeoShapeRnrEl::Paint(Option_t* /*option*/)
394 TBuffer3D& buff = (TBuffer3D&) fShape->GetBuffer3D
395 (TBuffer3D::kCore, false);
398 buff.fColor = fColor;
399 buff.fTransparency = fTransparency;
400 fHMTrans.SetBuffer3D(buff);
401 buff.fLocalFrame = kTRUE; // Always enforce local frame (no geo manager).
403 fShape->GetBuffer3D(TBuffer3D::kBoundingBox | TBuffer3D::kShapeSpecific, true);
405 Int_t reqSec = gPad->GetViewer3D()->AddObject(buff);
407 if (reqSec != TBuffer3D::kNone) {
408 fShape->GetBuffer3D(reqSec, true);
409 reqSec = gPad->GetViewer3D()->AddObject(buff);
412 if (reqSec != TBuffer3D::kNone)
413 printf("spooky reqSec=%d for %s\n", reqSec, GetName());
416 /**************************************************************************/
418 void GeoShapeRnrEl::Save(const char* file, const char* name)
420 TGeoShapeExtract* gse = DumpShapeTree(this, 0);
422 TFile f(file, "RECREATE");
427 /**************************************************************************/
429 TGeoShapeExtract* GeoShapeRnrEl::DumpShapeTree(GeoShapeRnrEl* gsre, TGeoShapeExtract* parent)
431 // printf("dump_shape_tree %s \n", gsre->GetName());
432 TGeoShapeExtract* she = new TGeoShapeExtract(gsre->GetName(), gsre->GetTitle());
433 she->SetTrans(gsre->RefHMTrans().Array());
434 Int_t ci = gsre->GetColor();
435 TColor* c = gROOT->GetColor(ci);
436 Float_t rgba[4] = {1, 0, 0, 1 - gsre->GetMainTransparency()/100.};
439 rgba[0] = c->GetRed();
440 rgba[1] = c->GetGreen();
441 rgba[2] = c->GetBlue();
444 she->SetRnrSelf(gsre->GetRnrSelf());
445 she->SetRnrElements(gsre->GetRnrChildren());
446 she->SetShape(gsre->GetShape());
447 if ( gsre->GetNChildren())
449 TList* ele = new TList();
450 she->SetElements(ele);
451 she->GetElements()->SetOwner(true);
452 RenderElement::List_i i = gsre->BeginChildren();
453 while (i != gsre->EndChildren()) {
454 GeoShapeRnrEl* l = dynamic_cast<GeoShapeRnrEl*>(*i);
455 DumpShapeTree(l, she);
460 parent->GetElements()->Add(she);
465 GeoShapeRnrEl* GeoShapeRnrEl::ImportShapeExtract(TGeoShapeExtract * gse,
466 RenderElement * parent)
468 gReve->DisableRedraw();
469 GeoShapeRnrEl* gsre = SubImportShapeExtract(gse, parent);
470 gsre->ElementChanged();
471 gReve->EnableRedraw();
476 GeoShapeRnrEl* GeoShapeRnrEl::SubImportShapeExtract(TGeoShapeExtract * gse,
477 RenderElement * parent)
479 GeoShapeRnrEl* gsre = new GeoShapeRnrEl(gse->GetName(), gse->GetTitle());
480 gsre->fHMTrans.SetFromArray(gse->GetTrans());
481 const Float_t* rgba = gse->GetRGBA();
482 gsre->fColor = TColor::GetColor(rgba[0], rgba[1], rgba[2]);
483 gsre->fTransparency = (UChar_t) (100.0f*(1.0f - rgba[3]));
484 gsre->SetRnrSelf(gse->GetRnrSelf());
485 gsre->SetRnrChildren(gse->GetRnrElements());
486 gsre->fShape = gse->GetShape();
488 gsre->fShape->SetUniqueID(gsre->fShape->GetUniqueID() + 1);
490 gReve->AddGlobalRenderElement(gsre, parent);
492 if (gse->HasElements())
494 TIter next(gse->GetElements());
495 TGeoShapeExtract* chld;
496 while ((chld = (TGeoShapeExtract*) next()) != 0)
497 SubImportShapeExtract(chld, gsre);
503 /**************************************************************************/
505 TClass* GeoShapeRnrEl::ProjectedClass() const
507 return NLTPolygonSet::Class();
510 /**************************************************************************/
512 TBuffer3D* GeoShapeRnrEl::MakeBuffer3D()
514 if(fShape == 0) return 0;
516 if(dynamic_cast<TGeoShapeAssembly*>(fShape)){
517 // !!!! TGeoShapeAssembly makes a bad TBuffer3D
521 TBuffer3D* buff = fShape->MakeBuffer3D();
522 if (fHMTrans.GetUseTrans())
524 Reve::ZTrans& mx = RefHMTrans();
525 Int_t N = buff->NbPnts();
526 Double_t* pnts = buff->fPnts;
527 for(Int_t k=0; k<N; k++)
529 mx.MultiplyIP(&pnts[3*k]);