Logo ROOT  
Reference Guide
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
32 Description of TEveGeoPolyShape
33 */
34 
36 
37 ////////////////////////////////////////////////////////////////////////////////
38 /// Constructor.
39 
41  TGeoBBox(),
42  fNbPols(0)
43 {
44 }
45 
46 ////////////////////////////////////////////////////////////////////////////////
47 /// Static constructor from a composite shape.
48 
50 {
51  TEvePad pad;
52  TEvePadHolder gpad(kFALSE, &pad);
53  TGLScenePad scene_pad(&pad);
54  pad.GetListOfPrimitives()->Add(cshape);
55  pad.SetViewer3D(&scene_pad);
56 
58 
59  scene_pad.BeginScene();
60  {
61  Double_t halfLengths[3] = { cshape->GetDX(), cshape->GetDY(), cshape->GetDZ() };
62 
64  buff.fID = cshape;
65  buff.fLocalFrame = kTRUE;
67  buff.SetAABoundingBox(cshape->GetOrigin(), halfLengths);
69 
70  Bool_t paintComponents = kTRUE;
71 
72  // Start a composite shape, identified by this buffer
73  if (TBuffer3D::GetCSLevel() == 0)
74  paintComponents = gPad->GetViewer3D()->OpenComposite(buff);
75 
77 
78  // Paint the boolean node - will add more buffers to viewer
81  if (paintComponents) cshape->GetBoolNode()->Paint("");
83  // Close the composite shape
84  if (TBuffer3D::DecCSLevel() == 0)
85  gPad->GetViewer3D()->CloseComposite();
86  }
87  scene_pad.EndScene();
88  pad.SetViewer3D(0);
89 
90  TGLFaceSet* fs = dynamic_cast<TGLFaceSet*>(scene_pad.FindLogical(cshape));
91  if (!fs) {
92  ::Warning("TEveGeoPolyShape::Construct", "Failed extracting CSG tesselation for shape '%s'.", cshape->GetName());
93  return 0;
94  }
95 
97  egps->SetFromFaceSet(fs);
98  egps->fOrigin[0] = cshape->GetOrigin()[0];
99  egps->fOrigin[1] = cshape->GetOrigin()[1];
100  egps->fOrigin[2] = cshape->GetOrigin()[2];
101  egps->fDX = cshape->GetDX();
102  egps->fDY = cshape->GetDY();
103  egps->fDZ = cshape->GetDZ();
104 
105  return egps;
106 }
107 
108 ////////////////////////////////////////////////////////////////////////////////
109 /// Set data-members from a face-set.
110 
112 {
113  fVertices = fs->GetVertices();
114  fPolyDesc = fs->GetPolyDesc();
115  fNbPols = fs->GetNbPols();
116 }
117 
118 ////////////////////////////////////////////////////////////////////////////////
119 /// Fill the passed buffer 3D.
120 
122 {
123  if (reqSections & TBuffer3D::kCore)
124  {
125  // If writing core section all others will be invalid
126  b.ClearSectionsValid();
127 
128  b.fID = const_cast<TEveGeoPolyShape*>(this);
129  b.fColor = 0;
130  b.fTransparency = 0;
131  b.fLocalFrame = kFALSE;
132  b.fReflection = kTRUE;
133 
134  b.SetSectionsValid(TBuffer3D::kCore);
135  }
136 
137  if (reqSections & TBuffer3D::kRawSizes || reqSections & TBuffer3D::kRaw)
138  {
139  UInt_t nvrt = fVertices.size() / 3;
140  UInt_t nseg = 0;
141 
142  std::map<Edge_t, Int_t> edges;
143 
144  const Int_t *pd = &fPolyDesc[0];
145  for (UInt_t i = 0; i < fNbPols; ++i)
146  {
147  UInt_t nv = pd[0]; ++pd;
148  for (UInt_t j = 0; j < nv; ++j)
149  {
150  Edge_t e(pd[j], (j != nv - 1) ? pd[j+1] : pd[0]);
151  if (edges.find(e) == edges.end())
152  {
153  edges.insert(std::make_pair(e, 0));
154  ++nseg;
155  }
156  }
157  pd += nv;
158  }
159 
160  b.SetRawSizes(nvrt, 3*nvrt, nseg, 3*nseg, fNbPols, fNbPols+fPolyDesc.size());
161 
162  memcpy(b.fPnts, &fVertices[0], sizeof(Double_t)*fVertices.size());
163 
164  Int_t si = 0, scnt = 0;
165  for (std::map<Edge_t, Int_t>::iterator i = edges.begin(); i != edges.end(); ++i)
166  {
167  b.fSegs[si++] = 0;
168  b.fSegs[si++] = i->first.fI;
169  b.fSegs[si++] = i->first.fJ;
170  i->second = scnt++;
171  }
172 
173  Int_t pi = 0;
174  pd = &fPolyDesc[0];
175  for (UInt_t i = 0; i < fNbPols; ++i)
176  {
177  UInt_t nv = pd[0]; ++pd;
178  b.fPols[pi++] = 0;
179  b.fPols[pi++] = nv;
180  for (UInt_t j = 0; j < nv; ++j)
181  {
182  b.fPols[pi++] = edges[Edge_t(pd[j], (j != nv - 1) ? pd[j+1] : pd[0])];
183  }
184  pd += nv;
185  }
186 
187 
188 
189  b.SetSectionsValid(TBuffer3D::kRawSizes | TBuffer3D::kRaw);
190  }
191 }
192 
193 ////////////////////////////////////////////////////////////////////////////////
194 /// Fill static buffer 3D.
195 
196 const TBuffer3D& TEveGeoPolyShape::GetBuffer3D(Int_t reqSections, Bool_t localFrame) const
197 {
199 
200  FillBuffer3D(buf, reqSections, localFrame);
201 
202  return buf;
203 }
204 
205 ////////////////////////////////////////////////////////////////////////////////
206 /// Create buffer 3D and fill it with point/segment/poly data.
207 
209 {
211 
213 
214  return buf;
215 }
TEveGeoManagerHolder
Exception safe wrapper for setting gGeoManager.
Definition: TEveUtil.h:142
TEveGeoShape.h
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
e
#define e(i)
Definition: RSha256.hxx:103
TPad::SetViewer3D
virtual void SetViewer3D(TVirtualViewer3D *viewer3d)
Definition: TPad.h:356
TEvePad.h
TBuffer3D::SetSectionsValid
void SetSectionsValid(UInt_t mask)
Definition: TBuffer3D.h:65
TEveGeoPolyShape::TEveGeoPolyShape
TEveGeoPolyShape()
Constructor.
Definition: TEveGeoPolyShape.cxx:40
TGLFaceSet::GetPolyDesc
std::vector< Int_t > & GetPolyDesc()
Definition: TGLFaceSet.h:43
TGeoCompositeShape::GetBoolNode
TGeoBoolNode * GetBoolNode() const
Definition: TGeoCompositeShape.h:65
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TBuffer3D::DecCSLevel
static UInt_t DecCSLevel()
Decrement CS level.
Definition: TBuffer3D.cxx:512
TBuffer3D::SetAABoundingBox
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...
Definition: TBuffer3D.cxx:320
TGeoBBox::fOrigin
Double_t fOrigin[3]
Definition: TGeoBBox.h:24
TGeoBBox::GetDZ
virtual Double_t GetDZ() const
Definition: TGeoBBox.h:72
TEveGeoPolyShape::MakeBuffer3D
virtual TBuffer3D * MakeBuffer3D() const
Create buffer 3D and fill it with point/segment/poly data.
Definition: TEveGeoPolyShape.cxx:208
TList.h
TGLScenePad
Implements VirtualViewer3D interface and fills the base-class visualization structures from pad conte...
Definition: TGLScenePad.h:26
TEveGeoShape::GetGeoHMatrixIdentity
static TGeoHMatrix * GetGeoHMatrixIdentity()
Return static identity matrix in homogeneous representation.
Definition: TEveGeoShape.cxx:99
TGLFaceSet::GetVertices
std::vector< Double_t > & GetVertices()
Definition: TGLFaceSet.h:41
TBuffer3D::SetLocalMasterIdentity
void SetLocalMasterIdentity()
Set kRaw tessellation section of buffer with supplied sizes.
Definition: TBuffer3D.cxx:296
TEveGeoPolyShape.h
TEveGeoPolyShape::Edge_t
Definition: TEveGeoPolyShape.h:39
TGeoShape::GetTransform
static TGeoMatrix * GetTransform()
Returns current transformation matrix that applies to shape.
Definition: TGeoShape.cxx:536
TEveGeoPolyShape::FillBuffer3D
virtual void FillBuffer3D(TBuffer3D &buffer, Int_t reqSections, Bool_t localFrame) const
Fill the passed buffer 3D.
Definition: TEveGeoPolyShape.cxx:121
b
#define b(i)
Definition: RSha256.hxx:100
bool
TGeoCompositeShape
Class handling Boolean composition of shapes.
Definition: TGeoCompositeShape.h:28
TEveGeoPolyShape::fPolyDesc
std::vector< Int_t > fPolyDesc
Definition: TEveGeoPolyShape.h:33
TEveGeoPolyShape::fVertices
std::vector< Double_t > fVertices
Definition: TEveGeoPolyShape.h:32
TBuffer3D::kBoundingBox
@ kBoundingBox
Definition: TBuffer3D.h:51
TGLScenePad.h
TEveUtil.h
TGeoBBox::GetDX
virtual Double_t GetDX() const
Definition: TGeoBBox.h:70
TBuffer3D
Generic 3D primitive description class.
Definition: TBuffer3D.h:18
TGLScene::FindLogical
virtual TGLLogicalShape * FindLogical(TObject *logid) const
Find and return logical shape identified by unique logid.
Definition: TGLScene.cxx:1107
TEveGeoPolyShape::fNbPols
UInt_t fNbPols
Definition: TEveGeoPolyShape.h:34
TEveGeoShape::GetGeoMangeur
static TGeoManager * GetGeoMangeur()
Return static geo-manager that is used internally to make shapes lead a happy life.
Definition: TEveGeoShape.cxx:88
TBuffer3DTypes::kGeneric
@ kGeneric
Definition: TBuffer3DTypes.h:24
TGeoBBox::fDY
Double_t fDY
Definition: TGeoBBox.h:22
TBuffer3D.h
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TGeoBoolNode::Paint
void Paint(Option_t *option) override
Special schema for feeding the 3D buffers to the painter client.
Definition: TGeoBoolNode.cxx:294
TEveGeoPolyShape
Description of TEveGeoPolyShape.
Definition: TEveGeoPolyShape.h:24
TBuffer3DTypes.h
TVirtualPad.h
TBuffer3D::kRaw
@ kRaw
Definition: TBuffer3D.h:54
TGeoShape::GetName
virtual const char * GetName() const
Get the shape name.
Definition: TGeoShape.cxx:248
TGeoBBox::GetOrigin
virtual const Double_t * GetOrigin() const
Definition: TGeoBBox.h:73
TGeoBBox
Box class.
Definition: TGeoBBox.h:18
TGeoCompositeShape.h
TPad::GetListOfPrimitives
TList * GetListOfPrimitives() const
Definition: TPad.h:239
TEvePadHolder
Exception safe wrapper for setting gPad.
Definition: TEveUtil.h:126
TObject::Warning
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:876
TGLFaceSet.h
unsigned int
TGeoMatrix.h
TEveGeoPolyShape::GetBuffer3D
virtual const TBuffer3D & GetBuffer3D(Int_t reqSections, Bool_t localFrame) const
Fill static buffer 3D.
Definition: TEveGeoPolyShape.cxx:196
TGLScenePad::BeginScene
virtual void BeginScene()
Start building of the scene.
Definition: TGLScenePad.cxx:259
TGeoBBox::fDZ
Double_t fDZ
Definition: TGeoBBox.h:23
TEvePad
This was intended as a TPad wrapper to allow smart updates of groups of pads.
Definition: TEvePad.h:18
Double_t
double Double_t
Definition: RtypesCore.h:59
TGeoMatrix
Geometrical transformation package.
Definition: TGeoMatrix.h:41
TBuffer3D::fLocalFrame
Bool_t fLocalFrame
Definition: TBuffer3D.h:90
TGLFaceSet
Implements a native ROOT-GL representation of an arbitrary set of polygons.
Definition: TGLFaceSet.h:23
TBuffer3D::fID
TObject * fID
Definition: TBuffer3D.h:87
TGeant4Unit::pi
static constexpr double pi
Definition: TGeant4SystemOfUnits.h:67
TGeoBBox::GetDY
virtual Double_t GetDY() const
Definition: TGeoBBox.h:71
TGLFaceSet::GetNbPols
UInt_t GetNbPols()
Definition: TGLFaceSet.h:44
TEveGeoPolyShape::SetFromFaceSet
void SetFromFaceSet(TGLFaceSet *fs)
Set data-members from a face-set.
Definition: TEveGeoPolyShape.cxx:111
TList::Add
virtual void Add(TObject *obj)
Definition: TList.h:87
TBuffer3DTypes::kComposite
@ kComposite
Definition: TBuffer3DTypes.h:25
TBuffer3D::kRawSizes
@ kRawSizes
Definition: TBuffer3D.h:53
TGeoBoolNode.h
gPad
#define gPad
Definition: TVirtualPad.h:287
TGLScenePad::EndScene
virtual void EndScene()
End building of the scene.
Definition: TGLScenePad.cxx:310
TBuffer3D::GetCSLevel
static UInt_t GetCSLevel()
Return CS level.
Definition: TBuffer3D.cxx:496
Rtypes.h
TEveGeoPolyShape::Construct
static TEveGeoPolyShape * Construct(TGeoCompositeShape *cshp, Int_t n_seg)
Static constructor from a composite shape.
Definition: TEveGeoPolyShape.cxx:49
TGeoBBox::fDX
Double_t fDX
Definition: TGeoBBox.h:21
TBuffer3D::IncCSLevel
static void IncCSLevel()
Increment CS level.
Definition: TBuffer3D.cxx:504
int
TBuffer3D::kCore
@ kCore
Definition: TBuffer3D.h:50
TGeoShape::SetTransform
static void SetTransform(TGeoMatrix *matrix)
Set current transformation matrix that applies to shape.
Definition: TGeoShape.cxx:544