4 #include <Reve/ReveManager.h>
5 #include <Reve/NLTPolygonSet.h>
7 #include "TGeoShapeExtract.h"
10 #include <TBuffer3D.h>
11 #include <TVirtualViewer3D.h>
14 #include <TGeoShape.h>
15 #include <TGeoVolume.h>
17 #include <TGeoShapeAssembly.h>
18 #include <TGeoManager.h>
19 #include <TVirtualGeoPainter.h>
22 //______________________________________________________________________
28 TClass* GeoRnrEl::ProjectedClass() const
30 return NLTPolygonSet::Class();
33 //______________________________________________________________________
37 ClassImp(GeoNodeRnrEl)
39 GeoNodeRnrEl::GeoNodeRnrEl(TGeoNode* node) :
44 // Hack!! Should use cint to retrieve TAttLine::fLineColor offset.
45 char* l = (char*) dynamic_cast<TAttLine*>(node->GetVolume());
46 SetMainColorPtr((Color_t*)(l + sizeof(void*)));
48 fRnrSelf = fNode->TGeoAtt::IsVisible();
51 const Text_t* GeoNodeRnrEl::GetName() const { return fNode->GetName(); }
52 const Text_t* GeoNodeRnrEl::GetTitle() const { return fNode->GetTitle(); }
54 /**************************************************************************/
56 Int_t GeoNodeRnrEl::ExpandIntoListTree(TGListTree* ltree,
57 TGListTreeItem* parent)
59 // Checks if child-nodes have been imported ... imports them if not.
60 // Then calls RenderElement::ExpandIntoListTree.
62 if(fChildren.empty() && fNode->GetVolume()->GetNdaughters() > 0) {
63 TIter next(fNode->GetVolume()->GetNodes());
65 while((dnode = (TGeoNode*) next()) != 0) {
66 GeoNodeRnrEl* node_re = new GeoNodeRnrEl(dnode);
70 return RenderElement::ExpandIntoListTree(ltree, parent);
73 /**************************************************************************/
75 void GeoNodeRnrEl::SetRnrSelf(Bool_t rnr)
77 RenderElement::SetRnrSelf(rnr);
78 fNode->SetVisibility(rnr);
81 void GeoNodeRnrEl::SetRnrChildren(Bool_t rnr)
83 RenderElement::SetRnrChildren(rnr);
84 fNode->VisibleDaughters(rnr);
87 void GeoNodeRnrEl::SetRnrState(Bool_t rnr)
89 RenderElement::SetRnrState(rnr);
90 fNode->SetVisibility(rnr);
91 fNode->VisibleDaughters(rnr);
94 /**************************************************************************/
96 void GeoNodeRnrEl::SetMainColor(Color_t color)
98 fNode->GetVolume()->SetLineColor(color);
102 void GeoNodeRnrEl::SetMainColor(Pixel_t pixel)
104 // This one needed for proper calling via CINT (signals).
106 SetMainColor(Color_t(TColor::GetColor(pixel)));
109 /**************************************************************************/
111 void GeoNodeRnrEl::UpdateNode(TGeoNode* node)
113 // Updates all reve-browsers having the node in their contents.
114 // All 3D-pads updated if any change found.
116 // Should (could?) be optimized with some assumptions about
117 // volume/node structure (search for parent, know the same node can not
118 // reoccur on lower level once found).
120 static const Exc_t eH("GeoNodeRnrEl::UpdateNode ");
122 // printf("%s node %s %p\n", eH.Data(), node->GetName(), node);
127 for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
128 ((GeoNodeRnrEl*)(*i))->UpdateNode(node);
133 void GeoNodeRnrEl::UpdateVolume(TGeoVolume* volume)
135 // Updates all reve-browsers having the volume in their contents.
136 // All 3D-pads updated if any change found.
138 // Should (could?) be optimized with some assumptions about
139 // volume/node structure (search for parent, know the same node can not
140 // reoccur on lower level once found).
142 static const Exc_t eH("GeoNodeRnrEl::UpdateVolume ");
144 // printf("%s volume %s %p\n", eH.Data(), volume->GetName(), volume);
146 if(fNode->GetVolume() == volume)
149 for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
150 ((GeoNodeRnrEl*)(*i))->UpdateVolume(volume);
154 /**************************************************************************/
156 void GeoNodeRnrEl::Draw(Option_t* option)
160 fNode->GetVolume()->Draw(opt);
163 /**************************************************************************/
165 TBuffer3D* GeoNodeRnrEl::MakeBuffer3D()
167 TGeoShape* shape = fNode->GetVolume()->GetShape();
168 if(shape == 0) return 0;
170 if(dynamic_cast<TGeoShapeAssembly*>(shape)){
171 // !!!! TGeoShapeAssembly makes a bad TBuffer3D
175 printf("eoNodeRnrEl::MakeBuffer3D() \n");
176 TBuffer3D* buff = shape->MakeBuffer3D();
177 TGeoMatrix* mx = fNode->GetMatrix();
178 Int_t N = buff->NbPnts();
179 Double_t* pnts = buff->fPnts;
181 for(Int_t i = 0; i<N; i++)
183 mx->LocalToMaster(&pnts[3*i], master);
184 pnts[3*i] = master[0];
185 pnts[3*i+1] = master[1];
186 pnts[3*i+2] = master[2];
190 /**************************************************************************/
191 //______________________________________________________________________
194 // A wrapper over a TGeoNode, possibly displaced with a global
195 // trasformation fGlobalTrans (the matrix is owned by this class).
196 /**************************************************************************/
198 ClassImp(GeoTopNodeRnrEl)
200 GeoTopNodeRnrEl::GeoTopNodeRnrEl(TGeoManager* manager, TGeoNode* node,
201 Int_t visopt, Int_t vislvl) :
211 GeoTopNodeRnrEl::~GeoTopNodeRnrEl()
214 /**************************************************************************/
216 void GeoTopNodeRnrEl::SetGlobalTrans(const TGeoHMatrix* m)
218 fGlobalTrans.SetFrom(*m);
221 void GeoTopNodeRnrEl::UseNodeTrans()
223 fGlobalTrans.SetFrom(*fNode->GetMatrix());
226 /**************************************************************************/
228 void GeoTopNodeRnrEl::SetVisOption(Int_t visopt)
234 void GeoTopNodeRnrEl::SetVisLevel(Int_t vislvl)
240 /**************************************************************************/
242 void GeoTopNodeRnrEl::SetRnrSelf(Bool_t rnr)
244 // Revert from GeoNode to back to standard behaviour.
245 RenderElement::SetRnrSelf(rnr);
248 /**************************************************************************/
250 void GeoTopNodeRnrEl::Draw(Option_t* option)
255 void GeoTopNodeRnrEl::Paint(Option_t* option)
258 gGeoManager = fManager;
259 TVirtualPad* pad = gPad;
261 TGeoVolume* top_volume = fManager->GetTopVolume();
262 fManager->SetVisOption(fVisOption);
263 fManager->SetVisLevel(fVisLevel);
264 fManager->SetTopVolume(fNode->GetVolume());
266 TVirtualGeoPainter* vgp = fManager->GetGeomPainter();
269 fGlobalTrans.SetGeoHMatrix(geomat);
270 vgp->PaintNode(fNode, option, &geomat);
272 fManager->SetTopVolume(top_volume);
276 /**************************************************************************/
278 void GeoTopNodeRnrEl::VolumeVisChanged(TGeoVolume* volume)
280 static const Exc_t eH("GeoTopNodeRnrEl::VolumeVisChanged ");
281 printf("%s volume %s %p\n", eH.Data(), volume->GetName(), (void*)volume);
282 UpdateVolume(volume);
285 void GeoTopNodeRnrEl::VolumeColChanged(TGeoVolume* volume)
287 static const Exc_t eH("GeoTopNodeRnrEl::VolumeColChanged ");
288 printf("%s volume %s %p\n", eH.Data(), volume->GetName(), (void*)volume);
289 UpdateVolume(volume);
292 void GeoTopNodeRnrEl::NodeVisChanged(TGeoNode* node)
294 static const Exc_t eH("GeoTopNodeRnrEl::NodeVisChanged ");
295 printf("%s node %s %p\n", eH.Data(), node->GetName(), (void*)node);
300 /**************************************************************************/
301 //______________________________________________________________________
304 // Minimal shape-wrapper allowing import of stuff from gled and retaining
305 // user-set visibility, colors and transparency.
306 /**************************************************************************/
308 ClassImp(GeoShapeRnrEl)
310 GeoShapeRnrEl::GeoShapeRnrEl(const Text_t* name, const Text_t* title) :
312 TNamed (name, title),
318 fMainColorPtr = &fColor;
321 GeoShapeRnrEl::~GeoShapeRnrEl()
324 fShape->SetUniqueID(fShape->GetUniqueID() - 1);
325 if (fShape->GetUniqueID() == 0)
330 /**************************************************************************/
332 void GeoShapeRnrEl::Paint(Option_t* /*option*/)
337 TBuffer3D& buff = (TBuffer3D&) fShape->GetBuffer3D
338 (TBuffer3D::kCore, false);
341 buff.fColor = fColor;
342 buff.fTransparency = fTransparency;
343 fHMTrans.SetBuffer3D(buff);
344 buff.fLocalFrame = kTRUE; // Always enforce local frame (no geo manager).
346 fShape->GetBuffer3D(TBuffer3D::kBoundingBox | TBuffer3D::kShapeSpecific, true);
348 Int_t reqSec = gPad->GetViewer3D()->AddObject(buff);
350 if (reqSec != TBuffer3D::kNone) {
351 fShape->GetBuffer3D(reqSec, true);
352 reqSec = gPad->GetViewer3D()->AddObject(buff);
355 if (reqSec != TBuffer3D::kNone)
356 printf("spooky reqSec=%d for %s\n", reqSec, GetName());
359 /**************************************************************************/
361 GeoShapeRnrEl* GeoShapeRnrEl::ImportShapeExtract(TGeoShapeExtract * gse,
362 RenderElement * parent)
364 gReve->DisableRedraw();
365 GeoShapeRnrEl* gsre = SubImportShapeExtract(gse, parent);
366 gsre->ElementChanged();
367 gReve->EnableRedraw();
372 GeoShapeRnrEl* GeoShapeRnrEl::SubImportShapeExtract(TGeoShapeExtract * gse,
373 RenderElement * parent)
375 GeoShapeRnrEl* gsre = new GeoShapeRnrEl(gse->GetName(), gse->GetTitle());
376 gsre->fHMTrans.SetFromArray(gse->GetTrans());
377 const Float_t* rgba = gse->GetRGBA();
378 gsre->fColor = TColor::GetColor(rgba[0], rgba[1], rgba[2]);
379 gsre->fTransparency = (UChar_t) (100.0f*(1.0f - rgba[3]));
380 gsre->SetRnrSelf(gse->GetRnrSelf());
381 gsre->SetRnrChildren(gse->GetRnrElements());
382 gsre->fShape = gse->GetShape();
384 gsre->fShape->SetUniqueID(gsre->fShape->GetUniqueID() + 1);
386 gReve->AddGlobalRenderElement(gsre, parent);
388 if (gse->HasElements())
390 TIter next(gse->GetElements());
391 TGeoShapeExtract* chld;
392 while ((chld = (TGeoShapeExtract*) next()) != 0)
393 SubImportShapeExtract(chld, gsre);
399 /**************************************************************************/
401 TBuffer3D* GeoShapeRnrEl::MakeBuffer3D()
403 if(fShape == 0) return 0;
405 if(dynamic_cast<TGeoShapeAssembly*>(fShape)){
406 // !!!! TGeoShapeAssembly makes a bad TBuffer3D
410 TBuffer3D* buff = fShape->MakeBuffer3D();
411 if (fHMTrans.GetUseTrans())
413 Reve::ZTrans& mx = RefHMTrans();
414 Int_t N = buff->NbPnts();
415 Double_t* pnts = buff->fPnts;
416 for(Int_t k=0; k<N; k++)
418 mx.MultiplyIP(&pnts[3*k]);