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
19class TGeoFacet {
22
23private:
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
29public:
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 {
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 {
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
103std::ostream &operator<<(std::ostream &os, TGeoFacet const &facet);
104
105class TGeoTessellated : public TGeoBBox {
106
107public:
109
110private:
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
121
122public:
123 // constructors
125 TGeoTessellated(const char *name, int nfacets = 0);
126 TGeoTessellated(const char *name, const std::vector<Vertex_t> &vertices);
127 // destructor
128 virtual ~TGeoTessellated() {}
129
130 void ComputeBBox();
131 void CloseShape(bool check = true, bool fixFlipped = true, bool verbose = true);
132
133 bool AddFacet(const Vertex_t &pt0, const Vertex_t &pt1, const Vertex_t &pt2);
134 bool AddFacet(const Vertex_t &pt0, const Vertex_t &pt1, const Vertex_t &pt2, const Vertex_t &pt3);
135 bool AddFacet(int i1, int i2, int i3);
136 bool AddFacet(int i1, int i2, int i3, int i4);
137
138 int GetNfacets() const { return fFacets.size(); }
139 int GetNsegments() const { return fNseg; }
140 int GetNvertices() const { return fNvert; }
141 bool IsClosedBody() const { return fClosedBody; }
142 bool IsDefined() const { return fDefined; }
143
144 const TGeoFacet &GetFacet(int i) { return fFacets[i]; }
145 const Vertex_t &GetVertex(int i) { return fVertices[i]; }
146
147 virtual void AfterStreamer();
148 virtual int DistancetoPrimitive(int, int) { return 99999; }
149 virtual const TBuffer3D &GetBuffer3D(int reqSections, Bool_t localFrame) const;
150 virtual void GetMeshNumbers(int &nvert, int &nsegs, int &npols) const;
151 virtual int GetNmeshVertices() const { return fNvert; }
152 virtual void InspectShape() const {}
153 virtual TBuffer3D *MakeBuffer3D() const;
154 virtual void Print(Option_t *option = "") const;
155 virtual void SavePrimitive(std::ostream &, Option_t *) {}
156 virtual void SetPoints(double *points) const;
157 virtual void SetPoints(Float_t *points) const;
158 virtual void SetSegsAndPols(TBuffer3D &buff) const;
159 virtual void Sizeof3D() const {}
160
161 /// Resize and center the shape in a box of size maxsize
162 void ResizeCenter(double maxsize);
163
164 /// Flip all facets
166 {
167 for (auto facet : fFacets)
168 facet.Flip();
169 }
170
171 bool CheckClosure(bool fixFlipped = true, bool verbose = true);
172
173 /// Reader from .obj format
174 static TGeoTessellated *ImportFromObjFormat(const char *objfile, bool check = false, bool verbose = false);
175
176 ClassDef(TGeoTessellated, 1) // tessellated shape class
177};
178
179#endif
bool Bool_t
Definition: RtypesCore.h:63
float Float_t
Definition: RtypesCore.h:57
const char Option_t
Definition: RtypesCore.h:66
#define ClassDef(name, id)
Definition: Rtypes.h:325
char name[80]
Definition: TGX11.cxx:110
std::ostream & operator<<(std::ostream &os, TGeoFacet const &facet)
point * points
Definition: X3DBuffer.c:22
Generic 3D primitive description class.
Definition: TBuffer3D.h:18
Box class.
Definition: TGeoBBox.h:18
TGeoFacet(const Vertex_t &pt0, const Vertex_t &pt1, const Vertex_t &pt2)
Tessellated::VertexVec_t VertexVec_t
bool Check() const
bool IsNeighbour(const TGeoFacet &other, bool &flip) const
Check if a connected neighbour facet has compatible normal.
TGeoFacet(VertexVec_t *vertices, int nvert, int i0=-1, int i1=-1, int i2=-1, int i3=-1)
static int CompactFacet(Vertex_t *vert, int nvertices)
int GetVertexIndex(int ivert) const
Vertex_t & GetVertex(int ivert)
TGeoFacet(const Vertex_t &pt0, const Vertex_t &pt1, const Vertex_t &pt2, const Vertex_t &pt3)
VertexVec_t * fVertices
void SetVertices(VertexVec_t *vertices, int nvert=0, int i0=-1, int i1=-1, int i2=-1, int i3=-1)
int fNvert
array of vertices
const Vertex_t & GetVertex(int ivert) const
int fIvert[4]
Vertex_t ComputeNormal(bool &degenerated) const
int GetNvert() const
const TGeoFacet & operator=(const TGeoFacet &other)
Tessellated solid class.
void ResizeCenter(double maxsize)
Resize and center the shape in a box of size maxsize.
virtual int DistancetoPrimitive(int, int)
Compute closest distance from point px,py to each corner.
int GetNsegments() const
virtual void Sizeof3D() const
bool IsDefined() const
virtual void Print(Option_t *option="") const
Prints basic info.
TGeoTessellated(const TGeoTessellated &)=delete
TGeoTessellated & operator=(const TGeoTessellated &)=delete
bool IsClosedBody() const
virtual const TBuffer3D & GetBuffer3D(int reqSections, Bool_t localFrame) const
Fills a static 3D buffer and returns a reference.
virtual void SetSegsAndPols(TBuffer3D &buff) const
Fills TBuffer3D structure for segments and polygons.
bool CheckClosure(bool fixFlipped=true, bool verbose=true)
Check closure of the solid and check/fix flipped normals.
int GetNvertices() const
const Vertex_t & GetVertex(int i)
virtual int GetNmeshVertices() const
virtual void SetPoints(double *points) const
Fill tessellated points to an array.
virtual ~TGeoTessellated()
virtual TBuffer3D * MakeBuffer3D() const
Creates a TBuffer3D describing this shape.
void CloseShape(bool check=true, bool fixFlipped=true, bool verbose=true)
Close the shape: calculate bounding box and compact vertices.
std::vector< TGeoFacet > fFacets
static TGeoTessellated * ImportFromObjFormat(const char *objfile, bool check=false, bool verbose=false)
Reader from .obj format.
void ComputeBBox()
Compute bounding box.
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".
bool AddFacet(const Vertex_t &pt0, const Vertex_t &pt1, const Vertex_t &pt2)
Adding a triangular facet from vertex positions in absolute coordinates.
virtual void GetMeshNumbers(int &nvert, int &nsegs, int &npols) const
Returns numbers of vertices, segments and polygons composing the shape mesh.
virtual void InspectShape() const
Prints shape parameters.
void FlipFacets()
Flip all facets.
std::vector< Vertex_t > fVertices
int GetNfacets() const
const TGeoFacet & GetFacet(int i)
bool fClosedBody
Shape fully defined.
ROOT::Geom::Vertex_t Vertex_t
Definition: TGeoTypedefs.h:20
std::vector< Vertex_t > VertexVec_t
Definition: TGeoTypedefs.h:21
void flip(struct mesh *m, struct behavior *b, struct otri *flipedge)
Definition: triangle.c:7890