Logo ROOT  
Reference Guide
TGeoTessellated.h
Go to the documentation of this file.
1 // @(#)root/geom:$Id$
2 // Author: Andrei Gheata 20/12/19
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, 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 #ifndef ROOT_TGeoTessellated
13 #define ROOT_TGeoTessellated
14 
15 #include "TGeoVector3.h"
16 #include "TGeoTypedefs.h"
17 #include "TGeoBBox.h"
18 
19 class TGeoFacet {
22 
23 private:
24  int fIvert[4] = {0, 0, 0, 0}; // Vertex indices in the array
25  VertexVec_t *fVertices = nullptr; //! array of vertices
26  int fNvert = 0; // number of vertices (can be 3 or 4)
27  bool fShared = false; // Vector of vertices shared flag
28 
29 public:
30  TGeoFacet() {}
31  TGeoFacet(const TGeoFacet &other);
32 
34  {
35  if (!fShared)
36  delete fVertices;
37  }
38 
39  const TGeoFacet &operator=(const TGeoFacet &other);
40 
41  // Triangular facet
42  TGeoFacet(const Vertex_t &pt0, const Vertex_t &pt1, const Vertex_t &pt2) : fIvert{0, 1, 2}
43  {
44  fVertices = new VertexVec_t;
45  fVertices->push_back(pt0);
46  fVertices->push_back(pt1);
47  fVertices->push_back(pt2);
48  fNvert = 3;
49  }
50 
51  // Quadrilateral facet
52  TGeoFacet(const Vertex_t &pt0, const Vertex_t &pt1, const Vertex_t &pt2, const Vertex_t &pt3) : fIvert{0, 1, 2, 3}
53  {
54  fVertices = new VertexVec_t;
55  fVertices->push_back(pt0);
56  fVertices->push_back(pt1);
57  fVertices->push_back(pt2);
58  fVertices->push_back(pt3);
59  fNvert = 4;
60  }
61 
62  TGeoFacet(VertexVec_t *vertices, int nvert, int i0 = -1, int i1 = -1, int i2 = -1, int i3 = -1)
63  {
64  fShared = true;
65  SetVertices(vertices, nvert, i0, i1, i2, i3);
66  }
67 
68  static int CompactFacet(Vertex_t *vert, int nvertices);
69 
70  void SetVertices(VertexVec_t *vertices, int nvert = 0, int i0 = -1, int i1 = -1, int i2 = -1, int i3 = -1)
71  {
72  if (!fShared)
73  delete fVertices;
74  fVertices = vertices;
75  if (nvert > 0) {
76  fIvert[0] = i0;
77  fIvert[1] = i1;
78  fIvert[2] = i2;
79  fIvert[3] = i3;
80  }
81  fNvert = nvert;
82  fShared = true;
83  }
84 
85  Vertex_t ComputeNormal(bool &degenerated) const;
86  int GetNvert() const { return fNvert; }
87 
88  Vertex_t &GetVertex(int ivert) { return fVertices->operator[](fIvert[ivert]); }
89  const Vertex_t &GetVertex(int ivert) const { return fVertices->operator[](fIvert[ivert]); }
90 
91  int GetVertexIndex(int ivert) const { return fIvert[ivert]; }
92 
93  bool Check() const;
94  void Flip()
95  {
96  int iv = fIvert[0];
97  fIvert[0] = fIvert[2];
98  fIvert[2] = iv;
99  }
100  bool IsNeighbour(const TGeoFacet &other, bool &flip) const;
101 };
102 
103 std::ostream &operator<<(std::ostream &os, TGeoFacet const &facet);
104 
105 class TGeoTessellated : public TGeoBBox {
106 
107 public:
109 
110 private:
111  int fNfacets = 0; // Number of facets
112  int fNvert = 0; // Number of vertices
113  int fNseg = 0; // Number of segments
114  bool fDefined = false; //! Shape fully defined
115  bool fClosedBody = false; // The faces are making a closed body
116  std::vector<Vertex_t> fVertices; // List of vertices
117  std::vector<TGeoFacet> fFacets; // List of facets
118 
119 public:
120  // constructors
122  TGeoTessellated(const char *name, int nfacets = 0);
123  TGeoTessellated(const char *name, const std::vector<Vertex_t> &vertices);
124  // destructor
125  virtual ~TGeoTessellated() {}
126 
127  void ComputeBBox();
128  void CloseShape(bool check = true, bool fixFlipped = true, bool verbose = true);
129 
130  bool AddFacet(const Vertex_t &pt0, const Vertex_t &pt1, const Vertex_t &pt2);
131  bool AddFacet(const Vertex_t &pt0, const Vertex_t &pt1, const Vertex_t &pt2, const Vertex_t &pt3);
132  bool AddFacet(int i1, int i2, int i3);
133  bool AddFacet(int i1, int i2, int i3, int i4);
134 
135  int GetNfacets() const { return fFacets.size(); }
136  int GetNsegments() const { return fNseg; }
137  int GetNvertices() const { return fNvert; }
138  bool IsClosedBody() const { return fClosedBody; }
139  bool IsDefined() const { return fDefined; }
140 
141  const TGeoFacet &GetFacet(int i) { return fFacets[i]; }
142  const Vertex_t &GetVertex(int i) { return fVertices[i]; }
143 
144  virtual void AfterStreamer();
145  virtual int DistancetoPrimitive(int, int) { return 99999; }
146  virtual const TBuffer3D &GetBuffer3D(int reqSections, Bool_t localFrame) const;
147  virtual void GetMeshNumbers(int &nvert, int &nsegs, int &npols) const;
148  virtual int GetNmeshVertices() const { return fNvert; }
149  virtual void InspectShape() const {}
150  virtual TBuffer3D *MakeBuffer3D() const;
151  virtual void Print(Option_t *option = "") const;
152  virtual void SavePrimitive(std::ostream &, Option_t *) {}
153  virtual void SetPoints(double *points) const;
154  virtual void SetPoints(float *points) const;
155  virtual void SetSegsAndPols(TBuffer3D &buff) const;
156  virtual void Sizeof3D() const {}
157 
158  /// Resize and center the shape in a box of size maxsize
159  void ResizeCenter(double maxsize);
160 
161  /// Flip all facets
162  void FlipFacets()
163  {
164  for (auto facet : fFacets)
165  facet.Flip();
166  }
167 
168  bool CheckClosure(bool fixFlipped = true, bool verbose = true);
169 
170  /// Reader from .obj format
171  static TGeoTessellated *ImportFromObjFormat(const char *objfile, bool check = false, bool verbose = false);
172 
173  ClassDef(TGeoTessellated, 1) // tessellated shape class
174 };
175 
176 #endif
TGeoTessellated::GetFacet
const TGeoFacet & GetFacet(int i)
Definition: TGeoTessellated.h:141
TGeoTessellated
Definition: TGeoTessellated.h:105
TGeoFacet::Flip
void Flip()
Definition: TGeoTessellated.h:100
TGeoTessellated::DistancetoPrimitive
virtual int DistancetoPrimitive(int, int)
Compute closest distance from point px,py to each corner.
Definition: TGeoTessellated.h:145
TGeoTessellated::Sizeof3D
virtual void Sizeof3D() const
Definition: TGeoTessellated.h:156
TGeoTessellated::IsClosedBody
bool IsClosedBody() const
Definition: TGeoTessellated.h:138
operator<<
std::ostream & operator<<(std::ostream &os, TGeoFacet const &facet)
Definition: TGeoTessellated.cxx:40
TGeoTessellated::ComputeBBox
void ComputeBBox()
Compute bounding box.
Definition: TGeoTessellated.cxx:494
TGeoTessellated::GetVertex
const Vertex_t & GetVertex(int i)
Definition: TGeoTessellated.h:142
TGeoFacet::VertexVec_t
Tessellated::VertexVec_t VertexVec_t
Definition: TGeoTessellated.h:27
Tessellated::VertexVec_t
std::vector< Vertex_t > VertexVec_t
Definition: TGeoTypedefs.h:27
TGeoFacet::GetVertex
Vertex_t & GetVertex(int ivert)
Definition: TGeoTessellated.h:94
TGeoFacet::SetVertices
void SetVertices(VertexVec_t *vertices, int nvert=0, int i0=-1, int i1=-1, int i2=-1, int i3=-1)
Definition: TGeoTessellated.h:76
TGeoTessellated::~TGeoTessellated
virtual ~TGeoTessellated()
Definition: TGeoTessellated.h:125
TGeoTessellated::CheckClosure
bool CheckClosure(bool fixFlipped=true, bool verbose=true)
Check closure of the solid and check/fix flipped normals.
Definition: TGeoTessellated.cxx:428
flip
void flip(struct mesh *m, struct behavior *b, struct otri *flipedge)
Definition: triangle.c:7889
TGeoTessellated::fVertices
std::vector< Vertex_t > fVertices
Definition: TGeoTessellated.h:116
TGeoFacet::fVertices
VertexVec_t * fVertices
Definition: TGeoTessellated.h:31
TGeoBBox.h
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TGeoTessellated::GetNfacets
int GetNfacets() const
Definition: TGeoTessellated.h:135
TGeoTessellated::TGeoTessellated
TGeoTessellated()
Definition: TGeoTessellated.h:121
TGeoTessellated::GetMeshNumbers
virtual void GetMeshNumbers(int &nvert, int &nsegs, int &npols) const
Returns numbers of vertices, segments and polygons composing the shape mesh.
Definition: TGeoTessellated.cxx:517
TGeoTypedefs.h
TGeoTessellated::ResizeCenter
void ResizeCenter(double maxsize)
Resize and center the shape in a box of size maxsize.
Definition: TGeoTessellated.cxx:607
TGeoFacet::operator=
const TGeoFacet & operator=(const TGeoFacet &other)
Definition: TGeoTessellated.cxx:59
TGeoFacet::ComputeNormal
Vertex_t ComputeNormal(bool &degenerated) const
Definition: TGeoTessellated.cxx:75
ROOT::Geom::Vertex_t
Definition: TGeoVector3.h:33
TGeoFacet::fNvert
int fNvert
array of vertices
Definition: TGeoTessellated.h:32
TGeoTessellated::CloseShape
void CloseShape(bool check=true, bool fixFlipped=true, bool verbose=true)
Close the shape: calculate bounding box and compact vertices.
Definition: TGeoTessellated.cxx:317
TGeoTessellated::fNseg
int fNseg
Definition: TGeoTessellated.h:113
TBuffer3D
Definition: TBuffer3D.h:17
Option_t
const typedef char Option_t
Definition: RtypesCore.h:66
TGeoFacet::CompactFacet
static int CompactFacet(Vertex_t *vert, int nvertices)
Definition: TGeoTessellated.cxx:135
Tessellated::Vertex_t
ROOT::Geom::Vertex_t Vertex_t
Definition: TGeoTypedefs.h:26
TGeoVector3.h
TGeoTessellated::SavePrimitive
virtual void SavePrimitive(std::ostream &, Option_t *)
Save a primitive as a C++ statement(s) on output stream "out".
Definition: TGeoTessellated.h:152
TGeoFacet::fIvert
int fIvert[4]
Definition: TGeoTessellated.h:30
TGeoFacet::TGeoFacet
TGeoFacet()
Definition: TGeoTessellated.h:36
TGeoFacet::~TGeoFacet
~TGeoFacet()
Definition: TGeoTessellated.h:39
TGeoTessellated::SetPoints
virtual void SetPoints(double *points) const
Fill tessellated points to an array.
Definition: TGeoTessellated.cxx:582
TGeoTessellated::FlipFacets
void FlipFacets()
Flip all facets.
Definition: TGeoTessellated.h:162
TGeoBBox
Definition: TGeoBBox.h:17
TGeoTessellated::GetNsegments
int GetNsegments() const
Definition: TGeoTessellated.h:136
TGeoFacet
Definition: TGeoTessellated.h:19
TGeoTessellated::AfterStreamer
virtual void AfterStreamer()
Function to be called after reading tessellated volumes from the geometry file.
Definition: TGeoTessellated.cxx:208
TGeoFacet::GetNvert
int GetNvert() const
Definition: TGeoTessellated.h:92
TGeoTessellated::fNvert
int fNvert
Definition: TGeoTessellated.h:112
TGeoTessellated::fDefined
bool fDefined
Definition: TGeoTessellated.h:114
TGeoTessellated::GetNvertices
int GetNvertices() const
Definition: TGeoTessellated.h:137
points
point * points
Definition: X3DBuffer.c:22
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TGeoTessellated::fFacets
std::vector< TGeoFacet > fFacets
Definition: TGeoTessellated.h:117
TGeoTessellated::Print
virtual void Print(Option_t *option="") const
Prints basic info.
Definition: TGeoTessellated.cxx:544
TGeoTessellated::InspectShape
virtual void InspectShape() const
Prints shape parameters.
Definition: TGeoTessellated.h:149
name
char name[80]
Definition: TGX11.cxx:110
TGeoTessellated::SetSegsAndPols
virtual void SetSegsAndPols(TBuffer3D &buff) const
Fills TBuffer3D structure for segments and polygons.
Definition: TGeoTessellated.cxx:553
genreflex::verbose
bool verbose
Definition: rootcling_impl.cxx:133
TGeoTessellated::GetNmeshVertices
virtual int GetNmeshVertices() const
Definition: TGeoTessellated.h:148
TGeoTessellated::fNfacets
int fNfacets
Definition: TGeoTessellated.h:111
TGeoTessellated::ImportFromObjFormat
static TGeoTessellated * ImportFromObjFormat(const char *objfile, bool check=false, bool verbose=false)
Reader from .obj format.
Definition: TGeoTessellated.cxx:661
TGeoFacet::IsNeighbour
bool IsNeighbour(const TGeoFacet &other, bool &flip) const
Check if a connected neighbour facet has compatible normal.
Definition: TGeoTessellated.cxx:157
TGeoTessellated::fClosedBody
bool fClosedBody
Shape fully defined.
Definition: TGeoTessellated.h:115
TGeoTessellated::IsDefined
bool IsDefined() const
Definition: TGeoTessellated.h:139
TGeoTessellated::GetBuffer3D
virtual const TBuffer3D & GetBuffer3D(int reqSections, Bool_t localFrame) const
Fills a static 3D buffer and returns a reference.
Definition: TGeoTessellated.cxx:630
TGeoTessellated::MakeBuffer3D
virtual TBuffer3D * MakeBuffer3D() const
Creates a TBuffer3D describing this shape.
Definition: TGeoTessellated.cxx:528
TGeoTessellated::AddFacet
bool AddFacet(const Vertex_t &pt0, const Vertex_t &pt1, const Vertex_t &pt2)
Adding a triangular facet from vertex positions in absolute coordinates.
Definition: TGeoTessellated.cxx:219
TGeoFacet::Check
bool Check() const
Definition: TGeoTessellated.cxx:103
TGeoFacet::GetVertexIndex
int GetVertexIndex(int ivert) const
Definition: TGeoTessellated.h:97
TGeoFacet::fShared
bool fShared
Definition: TGeoTessellated.h:33