Logo ROOT   master
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
std::vector< TGeoFacet > fFacets
Box class.
Definition: TGeoBBox.h:17
void SetVertices(VertexVec_t *vertices, int nvert=0, int i0=-1, int i1=-1, int i2=-1, int i3=-1)
virtual void AfterStreamer()
Function to be called after reading tessellated volumes from the geometry file.
virtual void SavePrimitive(std::ostream &, Option_t *)
Save a primitive as a C++ statement(s) on output stream "out".
const char Option_t
Definition: RtypesCore.h:62
int fIvert[4]
bool CheckClosure(bool fixFlipped=true, bool verbose=true)
Check closure of the solid and check/fix flipped normals.
Tessellated solid class.
static TGeoTessellated * ImportFromObjFormat(const char *objfile, bool check=false, bool verbose=false)
Reader from .obj format.
virtual void SetSegsAndPols(TBuffer3D &buff) const
Fills TBuffer3D structure for segments and polygons.
bool Bool_t
Definition: RtypesCore.h:59
int GetNfacets() const
int GetVertexIndex(int ivert) const
bool Check() const
TGeoFacet(VertexVec_t *vertices, int nvert, int i0=-1, int i1=-1, int i2=-1, int i3=-1)
bool IsNeighbour(const TGeoFacet &other, bool &flip) const
Check if a connected neighbour facet has compatible normal.
#define ClassDef(name, id)
Definition: Rtypes.h:326
bool IsDefined() const
bool IsClosedBody() const
VertexVec_t * fVertices
virtual void Print(Option_t *option="") const
Prints basic info.
void ResizeCenter(double maxsize)
Resize and center the shape in a box of size maxsize.
virtual const TBuffer3D & GetBuffer3D(int reqSections, Bool_t localFrame) const
Fills a static 3D buffer and returns a reference.
Vertex_t & GetVertex(int ivert)
virtual void GetMeshNumbers(int &nvert, int &nsegs, int &npols) const
Returns numbers of vertices, segments and polygons composing the shape mesh.
point * points
Definition: X3DBuffer.c:22
const Vertex_t & GetVertex(int ivert) const
virtual void InspectShape() const
Prints shape parameters.
virtual ~TGeoTessellated()
std::vector< Vertex_t > VertexVec_t
Definition: TGeoTypedefs.h:18
virtual int GetNmeshVertices() const
virtual int DistancetoPrimitive(int, int)
Compute closest distance from point px,py to each corner.
virtual void SetPoints(double *points) const
Fill tessellated points to an array.
int GetNsegments() const
std::vector< Vertex_t > fVertices
ROOT::Geom::Vertex_t Vertex_t
Definition: TGeoTypedefs.h:17
virtual void Sizeof3D() const
Generic 3D primitive description class.
Definition: TBuffer3D.h:17
virtual TBuffer3D * MakeBuffer3D() const
Creates a TBuffer3D describing this shape.
void ComputeBBox()
Compute bounding box.
bool fClosedBody
Shape fully defined.
const TGeoFacet & operator=(const TGeoFacet &other)
int fNvert
array of vertices
Tessellated::VertexVec_t VertexVec_t
void FlipFacets()
Flip all facets.
Vertex_t ComputeNormal(bool &degenerated) const
static int CompactFacet(Vertex_t *vert, int nvertices)
const Vertex_t & GetVertex(int i)
int GetNvertices() const
void CloseShape(bool check=true, bool fixFlipped=true, bool verbose=true)
Close the shape: calculate bounding box and compact vertices.
const TGeoFacet & GetFacet(int i)
bool AddFacet(const Vertex_t &pt0, const Vertex_t &pt1, const Vertex_t &pt2)
Adding a triangular facet from vertex positions in absolute coordinates.
TGeoFacet(const Vertex_t &pt0, const Vertex_t &pt1, const Vertex_t &pt2)
void flip(struct mesh *m, struct behavior *b, struct otri *flipedge)
Definition: triangle.c:7889
int GetNvert() const
TGeoFacet(const Vertex_t &pt0, const Vertex_t &pt1, const Vertex_t &pt2, const Vertex_t &pt3)
char name[80]
Definition: TGX11.cxx:109
std::ostream & operator<<(std::ostream &os, TGeoFacet const &facet)