Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 <map>
16#include "TGeoVector3.h"
17#include "TGeoTypedefs.h"
18#include "TGeoBBox.h"
19
20class TGeoFacet {
21public:
24
25private:
26 int fIvert[4] = {0, 0, 0, 0}; // Vertex indices in the array
27 int fNvert = 0; // number of vertices (can be 3 or 4)
28
29private:
30 void SetVertices(int nvert = 0, int i0 = -1, int i1 = -1, int i2 = -1, int i3 = -1)
31 {
32 fNvert = nvert;
33 fIvert[0] = i0;
34 fIvert[1] = i1;
35 fIvert[2] = i2;
36 fIvert[3] = i3;
37 }
38
39public:
41 TGeoFacet(int i0, int i1, int i2) { SetVertices(3, i0, i1, i2); }
42 TGeoFacet(int i0, int i1, int i2, int i3) { SetVertices(4, i0, i1, i2, i3); }
43
44 int operator[](int ivert) const { return fIvert[ivert]; }
45 static int CompactFacet(Vertex_t *vert, int nvertices);
46 int GetNvert() const { return fNvert; }
47
48 void Flip()
49 {
50 int iv = fIvert[0];
51 fIvert[0] = fIvert[2];
52 fIvert[2] = iv;
53 }
54 bool IsNeighbour(const TGeoFacet &other, bool &flip) const;
55};
56
57class TGeoTessellated : public TGeoBBox {
58
59public:
61
62private:
63 int fNfacets = 0; // Number of facets
64 int fNvert = 0; // Number of vertices
65 int fNseg = 0; // Number of segments
66 bool fDefined = false; ///<! Shape fully defined
67 bool fClosedBody = false; // The faces are making a closed body
68 std::vector<Vertex_t> fVertices; // List of vertices
69 std::vector<TGeoFacet> fFacets; // List of facets
70 std::multimap<long, int> fVerticesMap; ///<! Temporary map used to deduplicate vertices
71 std::vector<Vertex_t> fOutwardNormals; // Vector of outward-facing normals (to be streamed !)
72
73 bool fIsClosed = false; //! to know if shape still needs closure/initialization
74 void *fBVH = nullptr; //! BVH acceleration structure for safety and navigation
75
78
79 // bvh helper functions
80 void BuildBVH();
81 void CalculateNormals();
82
83public:
84 // constructors
86 TGeoTessellated(const char *name, int nfacets = 0);
87 TGeoTessellated(const char *name, const std::vector<Vertex_t> &vertices);
88 // destructor
89 ~TGeoTessellated() override {}
90
91 void ComputeBBox() override;
92 void CloseShape(bool check = true, bool fixFlipped = true, bool verbose = true);
93
94 bool AddFacet(const Vertex_t &pt0, const Vertex_t &pt1, const Vertex_t &pt2);
95 bool AddFacet(const Vertex_t &pt0, const Vertex_t &pt1, const Vertex_t &pt2, const Vertex_t &pt3);
96 bool AddFacet(int i1, int i2, int i3);
97 bool AddFacet(int i1, int i2, int i3, int i4);
98 int AddVertex(const Vertex_t &vert);
99
100 bool FacetCheck(int ifacet) const;
102
103 int GetNfacets() const { return fFacets.size(); }
104 int GetNsegments() const { return fNseg; }
105 int GetNvertices() const { return fNvert; }
106 bool IsClosedBody() const { return fClosedBody; }
108 bool IsDefined() const { return fDefined; }
109
110 const TGeoFacet &GetFacet(int i) const { return fFacets[i]; }
111 const Vertex_t &GetVertex(int i) const { return fVertices[i]; }
112
113 int DistancetoPrimitive(int, int) override { return 99999; }
114 const TBuffer3D &GetBuffer3D(int reqSections, Bool_t localFrame) const override;
115 void GetMeshNumbers(int &nvert, int &nsegs, int &npols) const override;
116 int GetNmeshVertices() const override { return fNvert; }
117 void InspectShape() const override {}
118 TBuffer3D *MakeBuffer3D() const override;
119 void Print(Option_t *option = "") const override;
120 void SavePrimitive(std::ostream &, Option_t *) override {}
121 void SetPoints(double *points) const override;
122 void SetPoints(Float_t *points) const override;
123 void SetSegsAndPols(TBuffer3D &buff) const override;
124 void Sizeof3D() const override {}
125
126 /// Resize and center the shape in a box of size maxsize
127 void ResizeCenter(double maxsize);
128
129 /// Flip all facets
131 {
132 for (auto facet : fFacets)
133 facet.Flip();
134 }
135
136 bool CheckClosure(bool fixFlipped = true, bool verbose = true);
137
138 /// Reader from .obj format
139 static TGeoTessellated *ImportFromObjFormat(const char *objfile, bool check = false, bool verbose = false);
140
141 // navigation functions used by TGeoNavigator (attention: only the iact == 3 cases implemented for now)
142 Double_t DistFromOutside(const Double_t *point, const Double_t *dir, Int_t iact = 1,
143 Double_t step = TGeoShape::Big(), Double_t *safe = nullptr) const override;
144 Double_t DistFromInside(const Double_t *point, const Double_t *dir, Int_t iact = 1, Double_t step = TGeoShape::Big(),
145 Double_t *safe = nullptr) const override;
146 bool Contains(const Double_t *point) const override;
147 Double_t Safety(const Double_t *point, Bool_t in = kTRUE) const override;
148 void ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm) const override;
149
150 Double_t Capacity() const override;
151
152private:
153 // a safety kernel used in multiple implementations
154 template <bool closest_facet = false>
155 Double_t SafetyKernel(const Double_t *point, bool in, int *closest_facet_id = nullptr) const;
156
157 ClassDefOverride(TGeoTessellated, 2) // tessellated shape class
158};
159
160#endif
bool Bool_t
Boolean (0=false, 1=true) (bool)
Definition RtypesCore.h:77
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
#define ClassDefOverride(name, id)
Definition Rtypes.h:348
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t points
char name[80]
Definition TGX11.cxx:110
Generic 3D primitive description class.
Definition TBuffer3D.h:18
Box class.
Definition TGeoBBox.h:18
void SetVertices(int nvert=0, int i0=-1, int i1=-1, int i2=-1, int i3=-1)
Tessellated::VertexVec_t VertexVec_t
bool IsNeighbour(const TGeoFacet &other, bool &flip) const
Check if a connected neighbour facet has compatible normal.
static int CompactFacet(Vertex_t *vert, int nvertices)
Compact consecutive equal vertices.
int operator[](int ivert) const
TGeoFacet(int i0, int i1, int i2, int i3)
TGeoFacet(int i0, int i1, int i2)
int GetNvert() const
static Double_t Big()
Definition TGeoShape.h:95
Tessellated solid class.
Double_t Safety(const Double_t *point, Bool_t in=kTRUE) const override
Safety.
void ResizeCenter(double maxsize)
Resize and center the shape in a box of size maxsize.
const TGeoFacet & GetFacet(int i) const
int DistancetoPrimitive(int, int) override
Compute closest distance from point px,py to each corner.
int AddVertex(const Vertex_t &vert)
Add a vertex checking for duplicates, returning the vertex index.
bool Contains(const Double_t *point) const override
Contains.
void ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm) const override
ComputeNormal interface.
void Sizeof3D() const override
int GetNsegments() const
bool FacetCheck(int ifacet) const
Check validity of facet.
const Vertex_t & GetVertex(int i) const
Double_t SafetyKernel(const Double_t *point, bool in, int *closest_facet_id=nullptr) const
a reusable safety kernel, which optionally returns the closest face
void InspectShape() const override
Prints shape parameters.
void Print(Option_t *option="") const override
Prints basic info.
bool IsDefined() const
Double_t Capacity() const override
Capacity.
Double_t DistFromInside(const Double_t *point, const Double_t *dir, Int_t iact=1, Double_t step=TGeoShape::Big(), Double_t *safe=nullptr) const override
DistFromOutside.
void * fBVH
to know if shape still needs closure/initialization
Double_t DistFromOutside(const Double_t *point, const Double_t *dir, Int_t iact=1, Double_t step=TGeoShape::Big(), Double_t *safe=nullptr) const override
DistFromOutside.
void SetSegsAndPols(TBuffer3D &buff) const override
Fills TBuffer3D structure for segments and polygons.
void BuildBVH()
BuildBVH.
const TBuffer3D & GetBuffer3D(int reqSections, Bool_t localFrame) const override
Fills a static 3D buffer and returns a reference.
Bool_t IsConvex() const final
TGeoTessellated(const TGeoTessellated &)=delete
BVH acceleration structure for safety and navigation.
void SetPoints(double *points) const override
Fill tessellated points to an array.
TGeoTessellated & operator=(const TGeoTessellated &)=delete
bool IsClosedBody() const
bool CheckClosure(bool fixFlipped=true, bool verbose=true)
Check closure of the solid and check/fix flipped normals.
int GetNvertices() const
void SavePrimitive(std::ostream &, Option_t *) override
Save a primitive as a C++ statement(s) on output stream "out".
int GetNmeshVertices() const override
bool fDefined
! Shape fully defined
Vertex_t FacetComputeNormal(int ifacet, bool &degenerated) const
Compute normal for a given facet.
void CloseShape(bool check=true, bool fixFlipped=true, bool verbose=true)
Close the shape: calculate bounding box and compact vertices.
void GetMeshNumbers(int &nvert, int &nsegs, int &npols) const override
Returns numbers of vertices, segments and polygons composing the shape mesh.
std::vector< TGeoFacet > fFacets
static TGeoTessellated * ImportFromObjFormat(const char *objfile, bool check=false, bool verbose=false)
Reader from .obj format.
TBuffer3D * MakeBuffer3D() const override
Creates a TBuffer3D describing this shape.
void ComputeBBox() override
Compute bounding box.
std::multimap< long, int > fVerticesMap
! Temporary map used to deduplicate vertices
~TGeoTessellated() override
std::vector< Vertex_t > fOutwardNormals
bool AddFacet(const Vertex_t &pt0, const Vertex_t &pt1, const Vertex_t &pt2)
Adding a triangular facet from vertex positions in absolute coordinates.
void CalculateNormals()
Calculate the normals.
void FlipFacets()
Flip all facets.
std::vector< Vertex_t > fVertices
int GetNfacets() const
std::vector< Vertex_t > VertexVec_t
ROOT::Geom::Vertex_t Vertex_t