41 TGeoManager* init_geo_mangeur()
47 TGeoManager *old = gGeoManager;
48 TGeoIdentity *old_id = gGeoIdentity;
50 TGeoManager* mgr =
new TGeoManager();
51 mgr->SetNameTitle(
"TEveGeoShape::fgGeoMangeur",
52 "Static geo manager used for wrapped TGeoShapes.");
53 gGeoIdentity =
new TGeoIdentity(
"Identity");
55 gGeoIdentity = old_id;
59 TGeoHMatrix localGeoHMatrixIdentity;
78 ClassImp(TEveGeoShape);
80 TGeoManager* TEveGeoShape::fgGeoMangeur = init_geo_mangeur();
88 TGeoManager* TEveGeoShape::GetGeoMangeur()
99 TGeoHMatrix* TEveGeoShape::GetGeoHMatrixIdentity()
101 return &localGeoHMatrixIdentity;
107 TEveGeoShape::TEveGeoShape(
const char* name,
const char* title) :
108 TEveShape (name, title),
119 TEveGeoShape::~TEveGeoShape()
127 TGeoShape* TEveGeoShape::MakePolyShape()
129 return TEveGeoPolyShape::Construct(fCompositeShape, fNSegments);
135 void TEveGeoShape::SetNSegments(Int_t s)
137 if (s != fNSegments && fCompositeShape != 0)
140 fShape = MakePolyShape();
155 void TEveGeoShape::SetShape(TGeoShape* s)
157 TEveGeoManagerHolder gmgr(fgGeoMangeur);
162 fShape = fCompositeShape;
166 fShape->SetUniqueID(fShape->GetUniqueID() - 1);
167 if (fShape->GetUniqueID() == 0)
175 fShape->SetUniqueID(fShape->GetUniqueID() + 1);
176 fCompositeShape =
dynamic_cast<TGeoCompositeShape*
>(fShape);
179 fShape = MakePolyShape();
187 void TEveGeoShape::ComputeBBox()
189 TGeoBBox *bb =
dynamic_cast<TGeoBBox*
>(fShape);
193 const Double_t *o = bb->GetOrigin();
194 BBoxCheckPoint(o[0] - bb->GetDX(), o[0] - bb->GetDY(), o[0] - bb->GetDZ());
195 BBoxCheckPoint(o[0] + bb->GetDX(), o[0] + bb->GetDY(), o[0] + bb->GetDZ());
206 void TEveGeoShape::Paint(Option_t* )
208 static const TEveException eh(
"TEveGeoShape::Paint ");
213 TEveGeoManagerHolder gmgr(fgGeoMangeur, fNSegments);
217 Double_t halfLengths[3] = { fCompositeShape->GetDX(), fCompositeShape->GetDY(), fCompositeShape->GetDZ() };
219 TBuffer3D buff(TBuffer3DTypes::kComposite);
221 buff.fColor = GetMainColor();
222 buff.fTransparency = GetMainTransparency();
223 RefMainTrans().SetBuffer3D(buff);
224 buff.fLocalFrame = kTRUE;
225 buff.SetAABoundingBox(fCompositeShape->GetOrigin(), halfLengths);
226 buff.SetSectionsValid(TBuffer3D::kCore|TBuffer3D::kBoundingBox);
228 Bool_t paintComponents = kTRUE;
231 if (TBuffer3D::GetCSLevel() == 0)
232 paintComponents = gPad->GetViewer3D()->OpenComposite(buff);
234 TBuffer3D::IncCSLevel();
237 TGeoMatrix *gst = TGeoShape::GetTransform();
238 TGeoShape::SetTransform(TEveGeoShape::GetGeoHMatrixIdentity());
239 if (paintComponents) fCompositeShape->GetBoolNode()->Paint(
"");
240 TGeoShape::SetTransform(gst);
242 if (TBuffer3D::DecCSLevel() == 0)
243 gPad->GetViewer3D()->CloseComposite();
247 TBuffer3D& buff = (TBuffer3D&) fShape->GetBuffer3D
248 (TBuffer3D::kCore, kFALSE);
251 buff.fColor = GetMainColor();
252 buff.fTransparency = GetMainTransparency();
253 RefMainTrans().SetBuffer3D(buff);
254 buff.fLocalFrame = kTRUE;
256 Int_t sections = TBuffer3D::kBoundingBox | TBuffer3D::kShapeSpecific;
258 sections |= TBuffer3D::kRawSizes | TBuffer3D::kRaw;
259 fShape->GetBuffer3D(sections, kTRUE);
261 Int_t reqSec = gPad->GetViewer3D()->AddObject(buff);
263 if (reqSec != TBuffer3D::kNone) {
265 if (reqSec & TBuffer3D::kCore)
266 Warning(eh,
"Core section required again for shape='%s'. This shouldn't happen.", GetName());
267 fShape->GetBuffer3D(reqSec, kTRUE);
268 reqSec = gPad->GetViewer3D()->AddObject(buff);
271 if (reqSec != TBuffer3D::kNone)
272 Warning(eh,
"Extra section required: reqSec=%d, shape=%s.", reqSec, GetName());
281 void TEveGeoShape::Save(
const char* file,
const char* name)
283 Warning(
"Save()",
"This function is deprecated, use SaveExtract() instead.");
284 SaveExtract(file, name);
291 void TEveGeoShape::SaveExtract(
const char* file,
const char* name)
293 TEveGeoShapeExtract* gse = DumpShapeTree(
this, 0);
295 TFile f(file,
"RECREATE");
303 void TEveGeoShape::WriteExtract(
const char* name)
305 TEveGeoShapeExtract* gse = DumpShapeTree(
this, 0);
312 TEveGeoShapeExtract* TEveGeoShape::DumpShapeTree(TEveGeoShape* gsre,
313 TEveGeoShapeExtract* parent)
315 TEveGeoShapeExtract* she =
new TEveGeoShapeExtract(gsre->GetName(), gsre->GetTitle());
316 she->SetTrans(gsre->RefMainTrans().Array());
318 Int_t ci = gsre->GetFillColor();
319 TColor *c = gROOT->GetColor(ci);
320 Float_t rgba[4] = { 1, 0, 0, Float_t(1 - gsre->GetMainTransparency()/100.) };
323 rgba[0] = c->GetRed();
324 rgba[1] = c->GetGreen();
325 rgba[2] = c->GetBlue();
330 Int_t ci = gsre->GetLineColor();
331 TColor *c = gROOT->GetColor(ci);
332 Float_t rgba[4] = { 1, 0, 0, 1 };
335 rgba[0] = c->GetRed();
336 rgba[1] = c->GetGreen();
337 rgba[2] = c->GetBlue();
339 she->SetRGBALine(rgba);
341 she->SetRnrSelf(gsre->GetRnrSelf());
342 she->SetRnrElements(gsre->GetRnrChildren());
343 she->SetRnrFrame(gsre->GetDrawFrame());
344 she->SetMiniFrame(gsre->GetMiniFrame());
345 she->SetShape(gsre->GetShape());
346 if (gsre->HasChildren())
348 TList* ele =
new TList();
349 she->SetElements(ele);
350 she->GetElements()->SetOwner(
true);
351 TEveElement::List_i i = gsre->BeginChildren();
352 while (i != gsre->EndChildren()) {
353 TEveGeoShape* l =
dynamic_cast<TEveGeoShape*
>(*i);
354 DumpShapeTree(l, she);
359 parent->GetElements()->Add(she);
367 TEveGeoShape* TEveGeoShape::ImportShapeExtract(TEveGeoShapeExtract* gse,
370 TEveGeoManagerHolder gmgr(fgGeoMangeur);
371 TEveManager::TRedrawDisabler redrawOff(gEve);
372 TEveGeoShape* gsre = SubImportShapeExtract(gse, parent);
373 gsre->ElementChanged();
380 TEveGeoShape* TEveGeoShape::SubImportShapeExtract(TEveGeoShapeExtract* gse,
383 TEveGeoShape* gsre =
new TEveGeoShape(gse->GetName(), gse->GetTitle());
384 gsre->RefMainTrans().SetFromArray(gse->GetTrans());
385 const Float_t* rgba = gse->GetRGBA();
386 gsre->SetMainColorRGB(rgba[0], rgba[1], rgba[2]);
387 gsre->SetMainAlpha(rgba[3]);
388 rgba = gse->GetRGBALine();
389 gsre->SetLineColor(TColor::GetColor(rgba[0], rgba[1], rgba[2]));
390 gsre->SetRnrSelf(gse->GetRnrSelf());
391 gsre->SetRnrChildren(gse->GetRnrElements());
392 gsre->SetDrawFrame(gse->GetRnrFrame());
393 gsre->SetMiniFrame(gse->GetMiniFrame());
394 gsre->SetShape(gse->GetShape());
397 parent->AddElement(gsre);
399 if (gse->HasElements())
401 TIter next(gse->GetElements());
402 TEveGeoShapeExtract* chld;
403 while ((chld = (TEveGeoShapeExtract*) next()) != 0)
404 SubImportShapeExtract(chld, gsre);
416 TClass* TEveGeoShape::ProjectedClass(
const TEveProjection* p)
const
419 return TEvePolygonSetProjected::Class();
421 return TEveGeoShapeProjected::Class();
428 TBuffer3D* TEveGeoShape::MakeBuffer3D()
430 if (fShape == 0)
return 0;
432 if (dynamic_cast<TGeoShapeAssembly*>(fShape)) {
437 TEveGeoManagerHolder gmgr(fgGeoMangeur, fNSegments);
439 TBuffer3D* buff = fShape->MakeBuffer3D();
440 TEveTrans& mx = RefMainTrans();
441 if (mx.GetUseTrans())
443 Int_t n = buff->NbPnts();
444 Double_t* pnts = buff->fPnts;
445 for(Int_t k = 0; k < n; ++k)
447 mx.MultiplyIP(&pnts[3*k]);
459 ClassImp(TEveGeoShapeProjected);
464 TEveGeoShapeProjected::TEveGeoShapeProjected() :
465 TEveShape(
"TEveGeoShapeProjected"),
473 TEveGeoShapeProjected::~TEveGeoShapeProjected()
484 void TEveGeoShapeProjected::SetDepthLocal(Float_t )
486 Warning(
"SetDepthLocal",
"This function only exists to fulfill an abstract interface.");
492 void TEveGeoShapeProjected::SetProjection(TEveProjectionManager* mng,
493 TEveProjectable* model)
495 TEveProjected::SetProjection(mng, model);
497 TEveGeoShape* gre =
dynamic_cast<TEveGeoShape*
>(fProjectable);
504 void TEveGeoShapeProjected::UpdateProjection()
506 TEveGeoShape *gre =
dynamic_cast<TEveGeoShape*
>(fProjectable);
507 TEveProjection *prj = fManager->GetProjection();
510 fBuff = gre->MakeBuffer3D();
514 fBuff->SetSectionsValid(TBuffer3D::kCore | TBuffer3D::kRawSizes | TBuffer3D::kRaw);
516 Double_t *p = fBuff->fPnts;
517 for (UInt_t i = 0; i < fBuff->NbPnts(); ++i, p+=3)
519 prj->ProjectPointdv(p, 0);
529 void TEveGeoShapeProjected::ComputeBBox()
531 if (fBuff && fBuff->NbPnts() > 0)
535 Double_t *p = fBuff->fPnts;
536 for (UInt_t i = 0; i < fBuff->NbPnts(); ++i, p+=3)
538 BBoxCheckPoint(p[0], p[1], p[2]);