Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
TEveGeoPolyShape.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 "TEveGeoPolyShape.h"
13
14#include "Rtypes.h"
15#include "TEveGeoShape.h"
16#include "TEvePad.h"
17#include "TEveUtil.h"
18
19#include "TVirtualPad.h"
20#include "TBuffer3D.h"
21#include "TBuffer3DTypes.h"
22#include "TGLScenePad.h"
23#include "TGLFaceSet.h"
24
25#include "TList.h"
26#include "TGeoBoolNode.h"
27#include "TGeoCompositeShape.h"
28#include "TGeoMatrix.h"
29
30/** \class TEveGeoPolyShape
31\ingroup TEve
32Description of TEveGeoPolyShape
33*/
34
35
36////////////////////////////////////////////////////////////////////////////////
37/// Constructor.
38
44
45////////////////////////////////////////////////////////////////////////////////
46/// Static constructor from a composite shape.
47
49{
50 TEvePad pad;
51 TEvePadHolder gpad(kFALSE, &pad);
52 TGLScenePad scene_pad(&pad);
53 pad.Add(cshape);
54 pad.SetViewer3D(&scene_pad);
55
57
58 scene_pad.BeginScene();
59 {
60 Double_t halfLengths[3] = { cshape->GetDX(), cshape->GetDY(), cshape->GetDZ() };
61
63 buff.fID = cshape;
64 buff.fLocalFrame = kTRUE;
66 buff.SetAABoundingBox(cshape->GetOrigin(), halfLengths);
68
69 Bool_t paintComponents = kTRUE;
70
71 // Start a composite shape, identified by this buffer
72 if (TBuffer3D::GetCSLevel() == 0)
73 paintComponents = gPad->GetViewer3D()->OpenComposite(buff);
74
76
77 // Paint the boolean node - will add more buffers to viewer
80 if (paintComponents) cshape->GetBoolNode()->Paint("");
82 // Close the composite shape
83 if (TBuffer3D::DecCSLevel() == 0)
84 gPad->GetViewer3D()->CloseComposite();
85 }
86 scene_pad.EndScene();
87 pad.SetViewer3D(nullptr);
88
89 TGLFaceSet* fs = dynamic_cast<TGLFaceSet*>(scene_pad.FindLogical(cshape));
90 if (!fs) {
91 ::Warning("TEveGeoPolyShape::Construct", "Failed extracting CSG tesselation for shape '%s'.", cshape->GetName());
92 return nullptr;
93 }
94
96 egps->SetFromFaceSet(fs);
97 egps->fOrigin[0] = cshape->GetOrigin()[0];
98 egps->fOrigin[1] = cshape->GetOrigin()[1];
99 egps->fOrigin[2] = cshape->GetOrigin()[2];
100 egps->fDX = cshape->GetDX();
101 egps->fDY = cshape->GetDY();
102 egps->fDZ = cshape->GetDZ();
103
104 return egps;
105}
106
107////////////////////////////////////////////////////////////////////////////////
108/// Set data-members from a face-set.
109
116
117////////////////////////////////////////////////////////////////////////////////
118/// Fill the passed buffer 3D.
119
121{
122 if (reqSections & TBuffer3D::kCore)
123 {
124 // If writing core section all others will be invalid
125 b.ClearSectionsValid();
126
127 b.fID = const_cast<TEveGeoPolyShape*>(this);
128 b.fColor = 0;
129 b.fTransparency = 0;
130 b.fLocalFrame = kFALSE;
131 b.fReflection = kTRUE;
132
133 b.SetSectionsValid(TBuffer3D::kCore);
134 }
135
136 if (reqSections & TBuffer3D::kRawSizes || reqSections & TBuffer3D::kRaw)
137 {
138 UInt_t nvrt = fVertices.size() / 3;
139 UInt_t nseg = 0;
140
141 std::map<Edge_t, Int_t> edges;
142
143 const Int_t *pd = &fPolyDesc[0];
144 for (UInt_t i = 0; i < fNbPols; ++i)
145 {
146 UInt_t nv = pd[0]; ++pd;
147 for (UInt_t j = 0; j < nv; ++j)
148 {
149 Edge_t e(pd[j], (j != nv - 1) ? pd[j+1] : pd[0]);
150 if (edges.find(e) == edges.end())
151 {
152 edges.insert(std::make_pair(e, 0));
153 ++nseg;
154 }
155 }
156 pd += nv;
157 }
158
159 b.SetRawSizes(nvrt, 3*nvrt, nseg, 3*nseg, fNbPols, fNbPols+fPolyDesc.size());
160
161 memcpy(b.fPnts, &fVertices[0], sizeof(Double_t)*fVertices.size());
162
163 Int_t si = 0, scnt = 0;
164 for (std::map<Edge_t, Int_t>::iterator i = edges.begin(); i != edges.end(); ++i)
165 {
166 b.fSegs[si++] = 0;
167 b.fSegs[si++] = i->first.fI;
168 b.fSegs[si++] = i->first.fJ;
169 i->second = scnt++;
170 }
171
172 Int_t pi = 0;
173 pd = &fPolyDesc[0];
174 for (UInt_t i = 0; i < fNbPols; ++i)
175 {
176 UInt_t nv = pd[0]; ++pd;
177 b.fPols[pi++] = 0;
178 b.fPols[pi++] = nv;
179 for (UInt_t j = 0; j < nv; ++j)
180 {
181 b.fPols[pi++] = edges[Edge_t(pd[j], (j != nv - 1) ? pd[j+1] : pd[0])];
182 }
183 pd += nv;
184 }
185
186
187
188 b.SetSectionsValid(TBuffer3D::kRawSizes | TBuffer3D::kRaw);
189 }
190}
191
192////////////////////////////////////////////////////////////////////////////////
193/// Fill static buffer 3D.
194
195const TBuffer3D& TEveGeoPolyShape::GetBuffer3D(Int_t reqSections, Bool_t localFrame) const
196{
198
199 FillBuffer3D(buf, reqSections, localFrame);
200
201 return buf;
202}
203
204////////////////////////////////////////////////////////////////////////////////
205/// Create buffer 3D and fill it with point/segment/poly data.
206
#define b(i)
Definition RSha256.hxx:100
#define e(i)
Definition RSha256.hxx:103
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
Definition RtypesCore.h:60
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
#define gPad
Generic 3D primitive description class.
Definition TBuffer3D.h:18
void SetLocalMasterIdentity()
Set kRaw tessellation section of buffer with supplied sizes.
@ kBoundingBox
Definition TBuffer3D.h:60
static UInt_t DecCSLevel()
Decrement CS level.
static UInt_t GetCSLevel()
Return CS level.
void SetSectionsValid(UInt_t mask)
Definition TBuffer3D.h:74
Bool_t fLocalFrame
Definition TBuffer3D.h:99
static void IncCSLevel()
Increment CS level.
void SetAABoundingBox(const Double_t origin[3], const Double_t halfLengths[3])
Set fBBVertex in kBoundingBox section to a axis aligned (local) BB using supplied origin and box half...
TObject * fID
Definition TBuffer3D.h:96
Exception safe wrapper for setting gGeoManager.
Definition TEveUtil.h:142
void FillBuffer3D(TBuffer3D &buffer, Int_t reqSections, Bool_t localFrame) const override
Fill the passed buffer 3D.
const TBuffer3D & GetBuffer3D(Int_t reqSections, Bool_t localFrame) const override
Fill static buffer 3D.
static TEveGeoPolyShape * Construct(TGeoCompositeShape *cshp, Int_t n_seg)
Static constructor from a composite shape.
TBuffer3D * MakeBuffer3D() const override
Create buffer 3D and fill it with point/segment/poly data.
std::vector< Double_t > fVertices
TEveGeoPolyShape(const TEveGeoPolyShape &)
TEveGeoPolyShape()
Constructor.
void SetFromFaceSet(TGLFaceSet *fs)
Set data-members from a face-set.
std::vector< Int_t > fPolyDesc
static TGeoManager * GetGeoMangeur()
Return static geo-manager that is used internally to make shapes lead a happy life.
static TGeoHMatrix * GetGeoHMatrixIdentity()
Return static identity matrix in homogeneous representation.
Exception safe wrapper for setting gPad.
Definition TEveUtil.h:126
This was intended as a TPad wrapper to allow smart updates of groups of pads.
Definition TEvePad.h:18
Implements a native ROOT-GL representation of an arbitrary set of polygons.
Definition TGLFaceSet.h:23
std::vector< Int_t > & GetPolyDesc()
Definition TGLFaceSet.h:43
std::vector< Double_t > & GetVertices()
Definition TGLFaceSet.h:41
UInt_t GetNbPols()
Definition TGLFaceSet.h:44
Implements VirtualViewer3D interface and fills the base-class visualization structures from pad conte...
Definition TGLScenePad.h:26
void EndScene() override
End building of the scene.
void BeginScene() override
Start building of the scene.
TGLLogicalShape * FindLogical(TObject *logid) const override
Find and return logical shape identified by unique logid.
virtual const Double_t * GetOrigin() const
Definition TGeoBBox.h:81
Double_t fDX
Definition TGeoBBox.h:21
TGeoBBox(const TGeoBBox &)=delete
virtual Double_t GetDX() const
Definition TGeoBBox.h:78
virtual Double_t GetDZ() const
Definition TGeoBBox.h:80
virtual Double_t GetDY() const
Definition TGeoBBox.h:79
Double_t fOrigin[3]
Definition TGeoBBox.h:24
Double_t fDY
Definition TGeoBBox.h:22
Double_t fDZ
Definition TGeoBBox.h:23
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
Geometrical transformation package.
Definition TGeoMatrix.h:39
static void SetTransform(TGeoMatrix *matrix)
Set current transformation matrix that applies to shape.
const char * GetName() const override
Get the shape name.
static TGeoMatrix * GetTransform()
Returns current transformation matrix that applies to shape.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:1084
void SetViewer3D(TVirtualViewer3D *viewer3d) override
Definition TPad.h:370
void Add(TObject *obj, Option_t *opt="", Bool_t modified=kTRUE) override
Add an object to list of primitives with specified draw option When.
Definition TPad.cxx:419