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
74
75public:
76 // constructors
78 TGeoTessellated(const char *name, int nfacets = 0);
79 TGeoTessellated(const char *name, const std::vector<Vertex_t> &vertices);
80 // destructor
81 ~TGeoTessellated() override {}
82
83 void ComputeBBox() override;
84 void CloseShape(bool check = true, bool fixFlipped = true, bool verbose = true);
85
86 bool AddFacet(const Vertex_t &pt0, const Vertex_t &pt1, const Vertex_t &pt2);
87 bool AddFacet(const Vertex_t &pt0, const Vertex_t &pt1, const Vertex_t &pt2, const Vertex_t &pt3);
88 bool AddFacet(int i1, int i2, int i3);
89 bool AddFacet(int i1, int i2, int i3, int i4);
90 int AddVertex(const Vertex_t &vert);
91
92 bool FacetCheck(int ifacet) const;
94
95 int GetNfacets() const { return fFacets.size(); }
96 int GetNsegments() const { return fNseg; }
97 int GetNvertices() const { return fNvert; }
98 bool IsClosedBody() const { return fClosedBody; }
100 bool IsDefined() const { return fDefined; }
101
102 const TGeoFacet &GetFacet(int i) const { return fFacets[i]; }
103 const Vertex_t &GetVertex(int i) const { return fVertices[i]; }
104
105 int DistancetoPrimitive(int, int) override { return 99999; }
106 const TBuffer3D &GetBuffer3D(int reqSections, Bool_t localFrame) const override;
107 void GetMeshNumbers(int &nvert, int &nsegs, int &npols) const override;
108 int GetNmeshVertices() const override { return fNvert; }
109 void InspectShape() const override {}
110 TBuffer3D *MakeBuffer3D() const override;
111 void Print(Option_t *option = "") const override;
112 void SavePrimitive(std::ostream &, Option_t *) override {}
113 void SetPoints(double *points) const override;
114 void SetPoints(Float_t *points) const override;
115 void SetSegsAndPols(TBuffer3D &buff) const override;
116 void Sizeof3D() const override {}
117
118 /// Resize and center the shape in a box of size maxsize
119 void ResizeCenter(double maxsize);
120
121 /// Flip all facets
123 {
124 for (auto facet : fFacets)
125 facet.Flip();
126 }
127
128 bool CheckClosure(bool fixFlipped = true, bool verbose = true);
129
130 /// Reader from .obj format
131 static TGeoTessellated *ImportFromObjFormat(const char *objfile, bool check = false, bool verbose = false);
132
133 ClassDefOverride(TGeoTessellated, 1) // tessellated shape class
134};
135
136#endif
bool Bool_t
Boolean (0=false, 1=true) (bool)
Definition RtypesCore.h:77
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
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
Tessellated solid class.
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.
void Sizeof3D() const override
int GetNsegments() const
bool FacetCheck(int ifacet) const
Check validity of facet.
const Vertex_t & GetVertex(int i) const
void InspectShape() const override
Prints shape parameters.
void Print(Option_t *option="") const override
Prints basic info.
bool IsDefined() const
void SetSegsAndPols(TBuffer3D &buff) const override
Fills TBuffer3D structure for segments and polygons.
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
Temporary map used to deduplicate vertices.
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
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
~TGeoTessellated() override
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 FlipFacets()
Flip all facets.
std::vector< Vertex_t > fVertices
int GetNfacets() const
bool fClosedBody
Shape fully defined.
std::vector< Vertex_t > VertexVec_t
ROOT::Geom::Vertex_t Vertex_t