4 #include <Reve/ReveManager.h>
5 #include <Reve/NLTPolygonSet.h>
7 #include "TGeoShapeExtract.h"
10 #include <TBuffer3D.h>
11 #include <TVirtualViewer3D.h>
15 #include <TGeoShape.h>
16 #include <TGeoVolume.h>
18 #include <TGeoShapeAssembly.h>
19 #include <TGeoManager.h>
20 #include <TVirtualGeoPainter.h>
25 //______________________________________________________________________
29 ClassImp(GeoNodeRnrEl)
31 GeoNodeRnrEl::GeoNodeRnrEl(TGeoNode* node) :
36 // Hack!! Should use cint to retrieve TAttLine::fLineColor offset.
37 char* l = (char*) dynamic_cast<TAttLine*>(node->GetVolume());
38 SetMainColorPtr((Color_t*)(l + sizeof(void*)));
40 fRnrSelf = fNode->TGeoAtt::IsVisible();
43 const Text_t* GeoNodeRnrEl::GetName() const { return fNode->GetName(); }
44 const Text_t* GeoNodeRnrEl::GetTitle() const { return fNode->GetTitle(); }
46 /**************************************************************************/
48 Int_t GeoNodeRnrEl::ExpandIntoListTree(TGListTree* ltree,
49 TGListTreeItem* parent)
51 // Checks if child-nodes have been imported ... imports them if not.
52 // Then calls RenderElement::ExpandIntoListTree.
54 if(fChildren.empty() && fNode->GetVolume()->GetNdaughters() > 0) {
55 TIter next(fNode->GetVolume()->GetNodes());
57 while((dnode = (TGeoNode*) next()) != 0) {
58 GeoNodeRnrEl* node_re = new GeoNodeRnrEl(dnode);
62 return RenderElement::ExpandIntoListTree(ltree, parent);
65 /**************************************************************************/
67 void GeoNodeRnrEl::SetRnrSelf(Bool_t rnr)
69 RenderElement::SetRnrSelf(rnr);
70 fNode->SetVisibility(rnr);
73 void GeoNodeRnrEl::SetRnrChildren(Bool_t rnr)
75 RenderElement::SetRnrChildren(rnr);
76 fNode->VisibleDaughters(rnr);
79 void GeoNodeRnrEl::SetRnrState(Bool_t rnr)
81 RenderElement::SetRnrState(rnr);
82 fNode->SetVisibility(rnr);
83 fNode->VisibleDaughters(rnr);
86 /**************************************************************************/
88 void GeoNodeRnrEl::SetMainColor(Color_t color)
90 fNode->GetVolume()->SetLineColor(color);
94 void GeoNodeRnrEl::SetMainColor(Pixel_t pixel)
96 // This one needed for proper calling via CINT (signals).
98 SetMainColor(Color_t(TColor::GetColor(pixel)));
101 /**************************************************************************/
103 void GeoNodeRnrEl::UpdateNode(TGeoNode* node)
105 // Updates all reve-browsers having the node in their contents.
106 // All 3D-pads updated if any change found.
108 // Should (could?) be optimized with some assumptions about
109 // volume/node structure (search for parent, know the same node can not
110 // reoccur on lower level once found).
112 static const Exc_t eH("GeoNodeRnrEl::UpdateNode ");
114 // printf("%s node %s %p\n", eH.Data(), node->GetName(), node);
119 for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
120 ((GeoNodeRnrEl*)(*i))->UpdateNode(node);
125 void GeoNodeRnrEl::UpdateVolume(TGeoVolume* volume)
127 // Updates all reve-browsers having the volume in their contents.
128 // All 3D-pads updated if any change found.
130 // Should (could?) be optimized with some assumptions about
131 // volume/node structure (search for parent, know the same node can not
132 // reoccur on lower level once found).
134 static const Exc_t eH("GeoNodeRnrEl::UpdateVolume ");
136 // printf("%s volume %s %p\n", eH.Data(), volume->GetName(), volume);
138 if(fNode->GetVolume() == volume)
141 for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
142 ((GeoNodeRnrEl*)(*i))->UpdateVolume(volume);
146 /**************************************************************************/
148 void GeoNodeRnrEl::Draw(Option_t* option)
152 fNode->GetVolume()->Draw(opt);
155 /**************************************************************************/
157 void GeoNodeRnrEl::Save(const char* file, const char* name)
159 TGeoShapeExtract* gse = DumpShapeTree(this, 0, 0);
161 TFile f(file, "RECREATE");
166 /**************************************************************************/
168 TGeoShapeExtract* GeoNodeRnrEl::DumpShapeTree(GeoNodeRnrEl* geon, TGeoShapeExtract* parent, Int_t level)
170 printf("dump_shape_tree %s \n", geon->GetName());
172 TGeoVolume* tvolume = 0;
173 TGeoShape* tshape = 0;
175 tnode = geon->GetNode();
177 printf("Null node for %s; assuming it's a holder and descending.\n", geon->GetName());
181 tvolume = tnode->GetVolume();
183 printf("Null volume for %s; skipping.\n", geon->GetName());
187 tshape = tvolume->GetShape();
192 if (parent) if (parent) trans.SetFromArray(parent->GetTrans());
193 TGeoMatrix* gm = tnode->GetMatrix();
194 const Double_t* rm = gm->GetRotationMatrix();
195 const Double_t* tv = gm->GetTranslation();
197 t(1,1) = rm[0]; t(1,2) = rm[1]; t(1,3) = rm[2];
198 t(2,1) = rm[3]; t(2,2) = rm[4]; t(2,3) = rm[5];
199 t(3,1) = rm[6]; t(3,2) = rm[7]; t(3,3) = rm[8];
200 t(1,4) = tv[0]; t(2,4) = tv[1]; t(3,4) = tv[2];
203 TGeoShapeExtract* gse = new TGeoShapeExtract(geon->GetName(), geon->GetTitle());
204 gse->SetTrans(trans.Array());
206 if(tvolume) ci = tvolume->GetLineColor();
207 TColor* c = gROOT->GetColor(ci);
208 Float_t rgba[4] = {1, 0, 0, 1};
210 rgba[0] = c->GetRed();
211 rgba[1] = c->GetGreen();
212 rgba[2] = c->GetBlue();
215 Bool_t rnr = geon->GetRnrSelf();
216 if(level > gGeoManager->GetVisLevel())
218 gse->SetRnrSelf(rnr);
219 gse->SetRnrElements(geon->GetRnrChildren());
221 if(dynamic_cast<TGeoShapeAssembly*>(tshape)){
222 // printf("<TGeoShapeAssembly \n");
225 gse->SetShape(tshape);
227 if ( geon->GetNChildren())
229 TList* ele = new TList();
230 gse->SetElements(ele);
231 gse->GetElements()->SetOwner(true);
233 RenderElement::List_i i = geon->BeginChildren();
234 while (i != geon->EndChildren()) {
235 GeoNodeRnrEl* l = dynamic_cast<GeoNodeRnrEl*>(*i);
236 DumpShapeTree(l, gse, level+1);
242 parent->GetElements()->Add(gse);
246 /**************************************************************************/
247 //______________________________________________________________________
250 // A wrapper over a TGeoNode, possibly displaced with a global
251 // trasformation fGlobalTrans (the matrix is owned by this class).
252 /**************************************************************************/
254 ClassImp(GeoTopNodeRnrEl)
256 GeoTopNodeRnrEl::GeoTopNodeRnrEl(TGeoManager* manager, TGeoNode* node,
257 Int_t visopt, Int_t vislvl) :
267 GeoTopNodeRnrEl::~GeoTopNodeRnrEl()
270 /**************************************************************************/
272 void GeoTopNodeRnrEl::SetGlobalTrans(const TGeoHMatrix* m)
274 fGlobalTrans.SetFrom(*m);
277 void GeoTopNodeRnrEl::UseNodeTrans()
279 fGlobalTrans.SetFrom(*fNode->GetMatrix());
282 /**************************************************************************/
284 void GeoTopNodeRnrEl::SetVisOption(Int_t visopt)
290 void GeoTopNodeRnrEl::SetVisLevel(Int_t vislvl)
296 /**************************************************************************/
298 void GeoTopNodeRnrEl::SetRnrSelf(Bool_t rnr)
300 // Revert from GeoNode to back to standard behaviour.
301 RenderElement::SetRnrSelf(rnr);
304 /**************************************************************************/
306 void GeoTopNodeRnrEl::Draw(Option_t* option)
311 void GeoTopNodeRnrEl::Paint(Option_t* option)
314 gGeoManager = fManager;
315 TVirtualPad* pad = gPad;
317 TGeoVolume* top_volume = fManager->GetTopVolume();
318 fManager->SetVisOption(fVisOption);
319 fManager->SetVisLevel(fVisLevel);
320 fManager->SetTopVolume(fNode->GetVolume());
322 TVirtualGeoPainter* vgp = fManager->GetGeomPainter();
325 fGlobalTrans.SetGeoHMatrix(geomat);
326 vgp->PaintNode(fNode, option, &geomat);
328 fManager->SetTopVolume(top_volume);
332 /**************************************************************************/
334 void GeoTopNodeRnrEl::VolumeVisChanged(TGeoVolume* volume)
336 static const Exc_t eH("GeoTopNodeRnrEl::VolumeVisChanged ");
337 printf("%s volume %s %p\n", eH.Data(), volume->GetName(), (void*)volume);
338 UpdateVolume(volume);
341 void GeoTopNodeRnrEl::VolumeColChanged(TGeoVolume* volume)
343 static const Exc_t eH("GeoTopNodeRnrEl::VolumeColChanged ");
344 printf("%s volume %s %p\n", eH.Data(), volume->GetName(), (void*)volume);
345 UpdateVolume(volume);
348 void GeoTopNodeRnrEl::NodeVisChanged(TGeoNode* node)
350 static const Exc_t eH("GeoTopNodeRnrEl::NodeVisChanged ");
351 printf("%s node %s %p\n", eH.Data(), node->GetName(), (void*)node);
356 /**************************************************************************/
357 //______________________________________________________________________
360 // Minimal shape-wrapper allowing import of stuff from gled and retaining
361 // user-set visibility, colors and transparency.
362 /**************************************************************************/
364 ClassImp(GeoShapeRnrEl)
366 GeoShapeRnrEl::GeoShapeRnrEl(const Text_t* name, const Text_t* title) :
368 TNamed (name, title),
374 fMainColorPtr = &fColor;
377 GeoShapeRnrEl::~GeoShapeRnrEl()
380 fShape->SetUniqueID(fShape->GetUniqueID() - 1);
381 if (fShape->GetUniqueID() == 0)
386 /**************************************************************************/
388 void GeoShapeRnrEl::Paint(Option_t* /*option*/)
393 TBuffer3D& buff = (TBuffer3D&) fShape->GetBuffer3D
394 (TBuffer3D::kCore, false);
397 buff.fColor = fColor;
398 buff.fTransparency = fTransparency;
399 fHMTrans.SetBuffer3D(buff);
400 buff.fLocalFrame = kTRUE; // Always enforce local frame (no geo manager).
402 fShape->GetBuffer3D(TBuffer3D::kBoundingBox | TBuffer3D::kShapeSpecific, true);
404 Int_t reqSec = gPad->GetViewer3D()->AddObject(buff);
406 if (reqSec != TBuffer3D::kNone) {
407 fShape->GetBuffer3D(reqSec, true);
408 reqSec = gPad->GetViewer3D()->AddObject(buff);
411 if (reqSec != TBuffer3D::kNone)
412 printf("spooky reqSec=%d for %s\n", reqSec, GetName());
415 /**************************************************************************/
417 void GeoShapeRnrEl::Save(const char* file, const char* name)
419 TGeoShapeExtract* gse = DumpShapeTree(this, 0);
421 TFile f(file, "RECREATE");
426 /**************************************************************************/
428 TGeoShapeExtract* GeoShapeRnrEl::DumpShapeTree(GeoShapeRnrEl* gsre, TGeoShapeExtract* parent)
430 // printf("dump_shape_tree %s \n", gsre->GetName());
431 TGeoShapeExtract* she = new TGeoShapeExtract(gsre->GetName(), gsre->GetTitle());
432 she->SetTrans(gsre->RefHMTrans().Array());
433 Int_t ci = gsre->GetColor();
434 TColor* c = gROOT->GetColor(ci);
435 Float_t rgba[4] = {1, 0, 0, 1 - gsre->GetMainTransparency()/100.};
438 rgba[0] = c->GetRed();
439 rgba[1] = c->GetGreen();
440 rgba[2] = c->GetBlue();
443 she->SetRnrSelf(gsre->GetRnrSelf());
444 she->SetRnrElements(gsre->GetRnrChildren());
445 she->SetShape(gsre->GetShape());
446 if ( gsre->GetNChildren())
448 TList* ele = new TList();
449 she->SetElements(ele);
450 she->GetElements()->SetOwner(true);
451 RenderElement::List_i i = gsre->BeginChildren();
452 while (i != gsre->EndChildren()) {
453 GeoShapeRnrEl* l = dynamic_cast<GeoShapeRnrEl*>(*i);
454 DumpShapeTree(l, she);
459 parent->GetElements()->Add(she);
464 GeoShapeRnrEl* GeoShapeRnrEl::ImportShapeExtract(TGeoShapeExtract * gse,
465 RenderElement * parent)
467 gReve->DisableRedraw();
468 GeoShapeRnrEl* gsre = SubImportShapeExtract(gse, parent);
469 gsre->ElementChanged();
470 gReve->EnableRedraw();
475 GeoShapeRnrEl* GeoShapeRnrEl::SubImportShapeExtract(TGeoShapeExtract * gse,
476 RenderElement * parent)
478 GeoShapeRnrEl* gsre = new GeoShapeRnrEl(gse->GetName(), gse->GetTitle());
479 gsre->fHMTrans.SetFromArray(gse->GetTrans());
480 const Float_t* rgba = gse->GetRGBA();
481 gsre->fColor = TColor::GetColor(rgba[0], rgba[1], rgba[2]);
482 gsre->fTransparency = (UChar_t) (100.0f*(1.0f - rgba[3]));
483 gsre->SetRnrSelf(gse->GetRnrSelf());
484 gsre->SetRnrChildren(gse->GetRnrElements());
485 gsre->fShape = gse->GetShape();
487 gsre->fShape->SetUniqueID(gsre->fShape->GetUniqueID() + 1);
489 gReve->AddGlobalRenderElement(gsre, parent);
491 if (gse->HasElements())
493 TIter next(gse->GetElements());
494 TGeoShapeExtract* chld;
495 while ((chld = (TGeoShapeExtract*) next()) != 0)
496 SubImportShapeExtract(chld, gsre);
502 /**************************************************************************/
504 TClass* GeoShapeRnrEl::ProjectedClass() const
506 return NLTPolygonSet::Class();
509 /**************************************************************************/
511 TBuffer3D* GeoShapeRnrEl::MakeBuffer3D()
513 if(fShape == 0) return 0;
515 if(dynamic_cast<TGeoShapeAssembly*>(fShape)){
516 // !!!! TGeoShapeAssembly makes a bad TBuffer3D
520 TBuffer3D* buff = fShape->MakeBuffer3D();
521 if (fHMTrans.GetUseTrans())
523 Reve::ZTrans& mx = RefHMTrans();
524 Int_t N = buff->NbPnts();
525 Double_t* pnts = buff->fPnts;
526 for(Int_t k=0; k<N; k++)
528 mx.MultiplyIP(&pnts[3*k]);