Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TEveGeoShape.cxx
Go to the documentation of this file.
1// @(#)root/eve:$Id$
2// Author: Matevz Tadel 2007
3
4/*************************************************************************
5 * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include "TEveGeoShape.h"
13#include "TEveTrans.h"
14#include "TEveManager.h"
16#include "TEveProjections.h"
18
19#include "TEveGeoShapeExtract.h"
20#include "TEveGeoPolyShape.h"
21
22#include "TROOT.h"
23#include "TBuffer3D.h"
24#include "TBuffer3DTypes.h"
25#include "TVirtualViewer3D.h"
26#include "TColor.h"
27#include "TFile.h"
28
29#include "TGeoShape.h"
30#include "TGeoVolume.h"
31#include "TGeoNode.h"
32#include "TGeoShapeAssembly.h"
33#include "TGeoCompositeShape.h"
34#include "TGeoBoolNode.h"
35#include "TGeoManager.h"
36#include "TGeoMatrix.h"
37#include "TVirtualGeoPainter.h"
38
39namespace
40{
42 {
43 // Create a phony geo manager that can be used for storing free
44 // shapes. Otherwise shapes register themselves to current
45 // geo-manager (or even create one).
46
49 gGeoManager = nullptr;
51 mgr->SetNameTitle("TEveGeoShape::fgGeoMangeur",
52 "Static geo manager used for wrapped TGeoShapes.");
53 gGeoIdentity = new TGeoIdentity("Identity");
54 gGeoManager = old;
56 return mgr;
57 }
58
60}
61
62/** \class TEveGeoShape
63\ingroup TEve
64Wrapper for TGeoShape with absolute positioning and color
65attributes allowing display of extracted TGeoShape's (without an
66active TGeoManager) and simplified geometries (needed for non-linear
67projections).
68
69TGeoCompositeShapes and TGeoAssemblies are supported.
70
71If fNSegments data-member is < 2 (0 by default), the default number of
72segments is used for tesselation and special GL objects are
73instantiated for selected shapes (spheres, tubes). If fNSegments is > 2,
74it gets forwarded to geo-manager and this tesselation detail is
75used when creating the buffer passed to GL.
76*/
77
78
80
81////////////////////////////////////////////////////////////////////////////////
82/// Return static geo-manager that is used internally to make shapes
83/// lead a happy life.
84/// Set gGeoManager to this object when creating TGeoShapes to be
85/// passed into TEveGeoShapes.
86
91
92////////////////////////////////////////////////////////////////////////////////
93/// Return static identity matrix in homogeneous representation.
94/// This is needed because TGeoCompositeShape::PaintComposite()
95/// assumes TGeoShape::fgTransform is a TGeoHMatrix and we need to pass in
96/// an identity matrix when painting a composite shape.
97
102
103////////////////////////////////////////////////////////////////////////////////
104/// Constructor.
105
106TEveGeoShape::TEveGeoShape(const char* name, const char* title) :
107 TEveShape (name, title),
108 fNSegments (0),
109 fShape (nullptr),
110 fCompositeShape (nullptr)
111{
113}
114
115////////////////////////////////////////////////////////////////////////////////
116/// Destructor.
117
119{
120 SetShape(nullptr);
121}
122
123////////////////////////////////////////////////////////////////////////////////
124/// Create derived TEveGeoShape form a TGeoCompositeShape.
125
130
131////////////////////////////////////////////////////////////////////////////////
132/// Set number of segments.
133
135{
136 if (s != fNSegments && fCompositeShape != nullptr)
137 {
138 delete fShape;
140 }
141 fNSegments = s;
142}
143
144////////////////////////////////////////////////////////////////////////////////
145/// Set TGeoShape shown by this object.
146///
147/// The shape is owned by TEveGeoShape but TGeoShape::fUniqueID is
148/// used for reference counting so you can pass the same shape to
149/// several TEveGeoShapes.
150///
151/// If it if is taken from an existing TGeoManager, manually
152/// increase the fUniqueID before passing it to TEveGeoShape.
153
155{
157
158 if (fCompositeShape)
159 {
160 delete fShape;
162 }
163 if (fShape)
164 {
166 if (fShape->GetUniqueID() == 0)
167 {
168 delete fShape;
169 }
170 }
171 fShape = s;
172 if (fShape)
173 {
175 fCompositeShape = dynamic_cast<TGeoCompositeShape*>(fShape);
176 if (fCompositeShape)
177 {
179 }
180 }
181}
182
183////////////////////////////////////////////////////////////////////////////////
184/// Compute bounding-box.
185
187{
188 TGeoBBox *bb = dynamic_cast<TGeoBBox*>(fShape);
189 if (bb)
190 {
191 BBoxInit();
192 const Double_t *o = bb->GetOrigin();
193 BBoxCheckPoint(o[0] - bb->GetDX(), o[0] - bb->GetDY(), o[0] - bb->GetDZ());
194 BBoxCheckPoint(o[0] + bb->GetDX(), o[0] + bb->GetDY(), o[0] + bb->GetDZ());
195 }
196 else
197 {
198 BBoxZero();
199 }
200}
201
202////////////////////////////////////////////////////////////////////////////////
203/// Paint object.
204
206{
207 static const TEveException eh("TEveGeoShape::Paint ");
208
209 if (fShape == nullptr)
210 return;
211
213
214 if (fCompositeShape)
215 {
217
219 buff.fID = this;
220 buff.fColor = GetMainColor();
221 buff.fTransparency = GetMainTransparency();
222 RefMainTrans().SetBuffer3D(buff);
223 buff.fLocalFrame = kTRUE; // Always enforce local frame (no geo manager).
224 buff.SetAABoundingBox(fCompositeShape->GetOrigin(), halfLengths);
226
228
229 // Start a composite shape, identified by this buffer
230 if (TBuffer3D::GetCSLevel() == 0)
231 paintComponents = gPad->GetViewer3D()->OpenComposite(buff);
232
234
235 // Paint the boolean node - will add more buffers to viewer
240 // Close the composite shape
241 if (TBuffer3D::DecCSLevel() == 0)
242 gPad->GetViewer3D()->CloseComposite();
243 }
244 else
245 {
248
249 buff.fID = this;
250 buff.fColor = GetMainColor();
251 buff.fTransparency = GetMainTransparency();
252 RefMainTrans().SetBuffer3D(buff);
253 buff.fLocalFrame = kTRUE; // Always enforce local frame (no geo manager).
254
256 if (fNSegments > 2)
258 fShape->GetBuffer3D(sections, kTRUE);
259
260 Int_t reqSec = gPad->GetViewer3D()->AddObject(buff);
261
262 if (reqSec != TBuffer3D::kNone) {
263 // This shouldn't happen, but I suspect it does sometimes.
265 Warning(eh, "Core section required again for shape='%s'. This shouldn't happen.", GetName());
267 reqSec = gPad->GetViewer3D()->AddObject(buff);
268 }
269
271 Warning(eh, "Extra section required: reqSec=%d, shape=%s.", reqSec, GetName());
272 }
273}
274
275////////////////////////////////////////////////////////////////////////////////
276/// Save the shape tree as TEveGeoShapeExtract.
277/// File is always recreated.
278/// This function is obsolete, use SaveExtractInstead().
279
280void TEveGeoShape::Save(const char* file, const char* name)
281{
282 Warning("Save()", "This function is deprecated, use SaveExtract() instead.");
283 SaveExtract(file, name);
284}
285
286////////////////////////////////////////////////////////////////////////////////
287/// Save the shape tree as TEveGeoShapeExtract.
288/// File is always recreated.
289
290void TEveGeoShape::SaveExtract(const char* file, const char* name)
291{
292 TEveGeoShapeExtract* gse = DumpShapeTree(this, nullptr);
293
294 TFile f(file, "RECREATE");
295 gse->Write(name);
296 f.Close();
297}
298
299////////////////////////////////////////////////////////////////////////////////
300/// Write the shape tree as TEveGeoShapeExtract to current directory.
301
303{
304 TEveGeoShapeExtract* gse = DumpShapeTree(this, nullptr);
305 gse->Write(name);
306}
307
308////////////////////////////////////////////////////////////////////////////////
309/// Export this shape and its descendants into a geoshape-extract.
310
312 TEveGeoShapeExtract* parent)
313{
314 TEveGeoShapeExtract* she = new TEveGeoShapeExtract(gsre->GetName(), gsre->GetTitle());
315 she->SetTrans(gsre->RefMainTrans().Array());
316 {
317 Int_t ci = gsre->GetFillColor();
318 TColor *c = gROOT->GetColor(ci);
319 Float_t rgba[4] = { 1, 0, 0, Float_t(1 - gsre->GetMainTransparency()/100.) };
320 if (c)
321 {
322 rgba[0] = c->GetRed();
323 rgba[1] = c->GetGreen();
324 rgba[2] = c->GetBlue();
325 }
326 she->SetRGBA(rgba);
327 }
328 {
329 Int_t ci = gsre->GetLineColor();
330 TColor *c = gROOT->GetColor(ci);
331 Float_t rgba[4] = { 1, 0, 0, 1 };
332 if (c)
333 {
334 rgba[0] = c->GetRed();
335 rgba[1] = c->GetGreen();
336 rgba[2] = c->GetBlue();
337 }
338 she->SetRGBALine(rgba);
339 }
340 she->SetRnrSelf(gsre->GetRnrSelf());
341 she->SetRnrElements(gsre->GetRnrChildren());
342 she->SetRnrFrame(gsre->GetDrawFrame());
343 she->SetMiniFrame(gsre->GetMiniFrame());
344 she->SetShape(gsre->GetShape());
345 if (gsre->HasChildren())
346 {
347 TList* ele = new TList();
348 she->SetElements(ele);
349 she->GetElements()->SetOwner(true);
350 TEveElement::List_i i = gsre->BeginChildren();
351 while (i != gsre->EndChildren()) {
352 TEveGeoShape* l = dynamic_cast<TEveGeoShape*>(*i);
354 i++;
355 }
356 }
357 if (parent)
358 parent->GetElements()->Add(she);
359
360 return she;
361}
362
363////////////////////////////////////////////////////////////////////////////////
364/// Import a shape extract 'gse' under element 'parent'.
365
375
376////////////////////////////////////////////////////////////////////////////////
377/// Recursive version for importing a shape extract tree.
378
380 TEveElement* parent)
381{
382 TEveGeoShape* gsre = new TEveGeoShape(gse->GetName(), gse->GetTitle());
383 gsre->RefMainTrans().SetFromArray(gse->GetTrans());
384 const Float_t* rgba = gse->GetRGBA();
385 gsre->SetMainColorRGB(rgba[0], rgba[1], rgba[2]);
386 gsre->SetMainAlpha(rgba[3]);
387 rgba = gse->GetRGBALine();
388 gsre->SetLineColor(TColor::GetColor(rgba[0], rgba[1], rgba[2]));
389 gsre->SetRnrSelf(gse->GetRnrSelf());
390 gsre->SetRnrChildren(gse->GetRnrElements());
391 gsre->SetDrawFrame(gse->GetRnrFrame());
392 gsre->SetMiniFrame(gse->GetMiniFrame());
393 gsre->SetShape(gse->GetShape());
394
395 if (parent)
396 parent->AddElement(gsre);
397
398 if (gse->HasElements())
399 {
400 TIter next(gse->GetElements());
402 while ((chld = (TEveGeoShapeExtract*) next()) != nullptr)
404 }
405
406 return gsre;
407}
408
409////////////////////////////////////////////////////////////////////////////////
410/// Return class for projected objects:
411/// - 2D projections: TEvePolygonSetProjected,
412/// - 3D projections: TEveGeoShapeProjected.
413/// Virtual from TEveProjectable.
414
416{
417 if (p->Is2D())
419 else
421}
422
423////////////////////////////////////////////////////////////////////////////////
424/// Create a TBuffer3D suitable for presentation of the shape.
425/// Transformation matrix is also applied.
426
428{
429 if (fShape == nullptr) return nullptr;
430
431 if (dynamic_cast<TGeoShapeAssembly*>(fShape)) {
432 // TGeoShapeAssembly makes a bad TBuffer3D.
433 return nullptr;
434 }
435
437
440 if (mx.GetUseTrans())
441 {
442 Int_t n = buff->NbPnts();
443 Double_t* pnts = buff->fPnts;
444 for(Int_t k = 0; k < n; ++k)
445 {
446 mx.MultiplyIP(&pnts[3*k]);
447 }
448 }
449 return buff;
450}
451
452
453/** \class TEveGeoShapeProjected
454\ingroup TEve
455A 3D projected TEveGeoShape.
456*/
457
458
459////////////////////////////////////////////////////////////////////////////////
460/// Constructor.
461
463 TEveShape("TEveGeoShapeProjected"),
464 fBuff(nullptr)
465{
466}
467
468////////////////////////////////////////////////////////////////////////////////
469/// Destructor.
470
475
476////////////////////////////////////////////////////////////////////////////////
477/// This should never be called as this class is only used for 3D
478/// projections.
479/// The implementation is required as this metod is abstract.
480/// Just emits a warning if called.
481
483{
484 Warning("SetDepthLocal", "This function only exists to fulfill an abstract interface.");
485}
486
487////////////////////////////////////////////////////////////////////////////////
488/// This is virtual method from base-class TEveProjected.
489
498
499////////////////////////////////////////////////////////////////////////////////
500/// This is virtual method from base-class TEveProjected.
501
503{
504 TEveGeoShape *gre = dynamic_cast<TEveGeoShape*>(fProjectable);
506
507 delete fBuff;
508 fBuff = gre->MakeBuffer3D();
509
510 if (fBuff)
511 {
513
514 Double_t *p = fBuff->fPnts;
515 for (UInt_t i = 0; i < fBuff->NbPnts(); ++i, p+=3)
516 {
517 prj->ProjectPointdv(p, 0);
518 }
519 }
520
521 ResetBBox();
522}
523
524////////////////////////////////////////////////////////////////////////////////
525/// Override of virtual method from TAttBBox.
526
528{
529 if (fBuff && fBuff->NbPnts() > 0)
530 {
531 BBoxInit();
532
533 Double_t *p = fBuff->fPnts;
534 for (UInt_t i = 0; i < fBuff->NbPnts(); ++i, p+=3)
535 {
536 BBoxCheckPoint(p[0], p[1], p[2]);
537 }
538 }
539 else
540 {
541 BBoxZero();
542 }
543}
dims_t fShape
#define f(i)
Definition RSha256.hxx:104
#define c(i)
Definition RSha256.hxx:101
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
R__EXTERN TEveManager * gEve
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char mx
char name[80]
Definition TGX11.cxx:110
R__EXTERN TGeoManager * gGeoManager
R__EXTERN TGeoIdentity * gGeoIdentity
Definition TGeoMatrix.h:537
#define gROOT
Definition TROOT.h:411
#define gPad
void BBoxCheckPoint(Float_t x, Float_t y, Float_t z)
Definition TAttBBox.h:69
void ResetBBox()
Definition TAttBBox.h:57
void BBoxZero(Float_t epsilon=0, Float_t x=0, Float_t y=0, Float_t z=0)
Create cube of volume (2*epsilon)^3 at (x,y,z).
Definition TAttBBox.cxx:41
void BBoxInit(Float_t infinity=1e6)
Dynamic Float_t[6] X(min,max), Y(min,max), Z(min,max)
Definition TAttBBox.cxx:28
Generic 3D primitive description class.
Definition TBuffer3D.h:18
UInt_t NbPnts() const
Definition TBuffer3D.h:80
@ kBoundingBox
Definition TBuffer3D.h:51
@ kShapeSpecific
Definition TBuffer3D.h:52
static UInt_t DecCSLevel()
Decrement CS level.
static UInt_t GetCSLevel()
Return CS level.
void SetSectionsValid(UInt_t mask)
Definition TBuffer3D.h:65
static void IncCSLevel()
Increment CS level.
Double_t * fPnts
Definition TBuffer3D.h:113
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
The color creation and management class.
Definition TColor.h:22
static Int_t GetColor(const char *hexcolor)
Static method returning color number for color specified by hex color string of form: "#rrggbb",...
Definition TColor.cxx:1926
Base class for TEveUtil visualization elements, providing hierarchy management, rendering control and...
Definition TEveElement.h:36
virtual void InitMainTrans(Bool_t can_edit=kTRUE)
Initialize the main transformation to identity matrix.
virtual void AddElement(TEveElement *el)
Add el to the list of children.
virtual TEveTrans & RefMainTrans()
Return reference to main transformation.
virtual Color_t GetMainColor() const
virtual Char_t GetMainTransparency() const
List_t::iterator List_i
Definition TEveElement.h:72
Exception class thrown by TEve classes and macros.
Definition TEveUtil.h:102
Exception safe wrapper for setting gGeoManager.
Definition TEveUtil.h:142
static TEveGeoPolyShape * Construct(TGeoCompositeShape *cshp, Int_t n_seg)
Static constructor from a composite shape.
Globally positioned TGeoShape with rendering attributes and an optional list of daughter shape-extrac...
void UpdateProjection() override
This is virtual method from base-class TEveProjected.
TEveGeoShapeProjected()
Constructor.
void SetDepthLocal(Float_t d) override
This should never be called as this class is only used for 3D projections.
static TClass * Class()
void ComputeBBox() override
Override of virtual method from TAttBBox.
~TEveGeoShapeProjected() override
Destructor.
void SetProjection(TEveProjectionManager *proj, TEveProjectable *model) override
This is virtual method from base-class TEveProjected.
Wrapper for TGeoShape with absolute positioning and color attributes allowing display of extracted TG...
TEveGeoShape(const TEveGeoShape &)
virtual TBuffer3D * MakeBuffer3D()
Create a TBuffer3D suitable for presentation of the shape.
void SetShape(TGeoShape *s)
Set TGeoShape shown by this object.
void SetNSegments(Int_t s)
Set number of segments.
void Save(const char *file, const char *name="Extract")
Save the shape tree as TEveGeoShapeExtract.
static TGeoManager * GetGeoMangeur()
Return static geo-manager that is used internally to make shapes lead a happy life.
TGeoCompositeShape * fCompositeShape
void SaveExtract(const char *file, const char *name)
Save the shape tree as TEveGeoShapeExtract.
TClass * ProjectedClass(const TEveProjection *p) const override
Return class for projected objects:
static TGeoHMatrix * GetGeoHMatrixIdentity()
Return static identity matrix in homogeneous representation.
static TEveGeoShape * ImportShapeExtract(TEveGeoShapeExtract *gse, TEveElement *parent=nullptr)
Import a shape extract 'gse' under element 'parent'.
static TEveGeoShape * SubImportShapeExtract(TEveGeoShapeExtract *gse, TEveElement *parent)
Recursive version for importing a shape extract tree.
static TGeoManager * fgGeoMangeur
Temporary holder (if passed shape is composite shape).
TGeoShape * fShape
~TEveGeoShape() override
Destructor.
void ComputeBBox() override
Compute bounding-box.
void Paint(Option_t *option="") override
Paint object.
TGeoShape * MakePolyShape()
Create derived TEveGeoShape form a TGeoCompositeShape.
TEveGeoShapeExtract * DumpShapeTree(TEveGeoShape *geon, TEveGeoShapeExtract *parent=nullptr)
Export this shape and its descendants into a geoshape-extract.
void WriteExtract(const char *name)
Write the shape tree as TEveGeoShapeExtract to current directory.
static TClass * Class()
Abstract base-class for non-linear projectable objects.
TEveProjectable * fProjectable
TEveProjectionManager * fManager
virtual void SetProjection(TEveProjectionManager *mng, TEveProjectable *model)
Sets projection manager and reference in the projectable object.
Manager class for steering of projections and managing projected objects.
TEveProjection * GetProjection()
Base-class for non-linear projections.
Abstract base-class for 2D/3D shapes.
Definition TEveShape.h:26
void CopyVizParams(const TEveElement *el) override
Copy visualization parameters from element el.
Definition TEveShape.cxx:69
TEveTrans is a 4x4 transformation matrix for homogeneous coordinates stored internally in a column-ma...
Definition TEveTrans.h:27
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Definition TFile.h:131
Box class.
Definition TGeoBBox.h:17
virtual const Double_t * GetOrigin() const
Definition TGeoBBox.h:79
virtual Double_t GetDX() const
Definition TGeoBBox.h:76
virtual Double_t GetDZ() const
Definition TGeoBBox.h:78
virtual Double_t GetDY() const
Definition TGeoBBox.h:77
void Paint(Option_t *option) override
Special schema for feeding the 3D buffers to the painter client.
Composite shapes are Boolean combinations of two or more shape components.
TGeoBoolNode * GetBoolNode() const
Matrix class used for computing global transformations Should NOT be used for node definition.
Definition TGeoMatrix.h:458
An identity transformation.
Definition TGeoMatrix.h:406
The manager class for any TGeo geometry.
Definition TGeoManager.h:45
Geometrical transformation package.
Definition TGeoMatrix.h:38
The shape encapsulating an assembly (union) of volumes.
Base abstract class for all shapes.
Definition TGeoShape.h:25
virtual const TBuffer3D & GetBuffer3D(Int_t reqSections, Bool_t localFrame) const
Stub implementation to avoid forcing implementation at this stage.
static void SetTransform(TGeoMatrix *matrix)
Set current transformation matrix that applies to shape.
static TGeoMatrix * GetTransform()
Returns current transformation matrix that applies to shape.
virtual TBuffer3D * MakeBuffer3D() const
Definition TGeoShape.h:154
A doubly linked list.
Definition TList.h:38
void Add(TObject *obj) override
Definition TList.h:81
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
virtual UInt_t GetUniqueID() const
Return the unique object id.
Definition TObject.cxx:475
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:1057
virtual void SetUniqueID(UInt_t uid)
Set the unique object id.
Definition TObject.cxx:875
const Int_t n
Definition legend1.C:16
TLine l
Definition textangle.C:4