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