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 {
23
24private:
25 int fIvert[4] = {0, 0, 0, 0}; // Vertex indices in the array
26 int fNvert = 0; // number of vertices (can be 3 or 4)
27
28private:
29 void SetVertices(int nvert = 0, int i0 = -1, int i1 = -1, int i2 = -1, int i3 = -1)
30 {
31 fNvert = nvert;
32 fIvert[0] = i0;
33 fIvert[1] = i1;
34 fIvert[2] = i2;
35 fIvert[3] = i3;
36 }
37
38public:
40 TGeoFacet(int i0, int i1, int i2) { SetVertices(3, i0, i1, i2); }
41 TGeoFacet(int i0, int i1, int i2, int i3) { SetVertices(4, i0, i1, i2, i3); }
42
43 int operator[](int ivert) const { return fIvert[ivert]; }
44 static int CompactFacet(Vertex_t *vert, int nvertices);
45 int GetNvert() const { return fNvert; }
46
47 void Flip()
48 {
49 int iv = fIvert[0];
50 fIvert[0] = fIvert[2];
51 fIvert[2] = iv;
52 }
53 bool IsNeighbour(const TGeoFacet &other, bool &flip) const;
54};
55
56class TGeoTessellated : public TGeoBBox {
57
58public:
60
61private:
62 int fNfacets = 0; // Number of facets
63 int fNvert = 0; // Number of vertices
64 int fNseg = 0; // Number of segments
65 bool fDefined = false; //! Shape fully defined
66 bool fClosedBody = false; // The faces are making a closed body
67 std::vector<Vertex_t> fVertices; // List of vertices
68 std::vector<TGeoFacet> fFacets; // List of facets
69 std::multimap<long, int> fVerticesMap; //! Temporary map used to deduplicate vertices
70
73
74public:
75 // constructors
77 TGeoTessellated(const char *name, int nfacets = 0);
78 TGeoTessellated(const char *name, const std::vector<Vertex_t> &vertices);
79 // destructor
80 ~TGeoTessellated() override {}
81
82 void ComputeBBox() override;
83 void CloseShape(bool check = true, bool fixFlipped = true, bool verbose = true);
84
85 bool AddFacet(const Vertex_t &pt0, const Vertex_t &pt1, const Vertex_t &pt2);
86 bool AddFacet(const Vertex_t &pt0, const Vertex_t &pt1, const Vertex_t &pt2, const Vertex_t &pt3);
87 bool AddFacet(int i1, int i2, int i3);
88 bool AddFacet(int i1, int i2, int i3, int i4);
89 int AddVertex(const Vertex_t &vert);
90
91 bool FacetCheck(int ifacet) const;
92 Vertex_t FacetComputeNormal(int ifacet, bool &degenerated) const;
93
94 int GetNfacets() const { return fFacets.size(); }
95 int GetNsegments() const { return fNseg; }
96 int GetNvertices() const { return fNvert; }
97 bool IsClosedBody() const { return fClosedBody; }
98 bool IsDefined() const { return fDefined; }
99
100 const TGeoFacet &GetFacet(int i) const { return fFacets[i]; }
101 const Vertex_t &GetVertex(int i) const { return fVertices[i]; }
102
103 int DistancetoPrimitive(int, int) override { return 99999; }
104 const TBuffer3D &GetBuffer3D(int reqSections, Bool_t localFrame) const override;
105 void GetMeshNumbers(int &nvert, int &nsegs, int &npols) const override;
106 int GetNmeshVertices() const override { return fNvert; }
107 void InspectShape() const override {}
108 TBuffer3D *MakeBuffer3D() const override;
109 void Print(Option_t *option = "") const override;
110 void SavePrimitive(std::ostream &, Option_t *) override {}
111 void SetPoints(double *points) const override;
112 void SetPoints(Float_t *points) const override;
113 void SetSegsAndPols(TBuffer3D &buff) const override;
114 void Sizeof3D() const override {}
115
116 /// Resize and center the shape in a box of size maxsize
117 void ResizeCenter(double maxsize);
118
119 /// Flip all facets
121 {
122 for (auto facet : fFacets)
123 facet.Flip();
124 }
125
126 bool CheckClosure(bool fixFlipped = true, bool verbose = true);
127
128 /// Reader from .obj format
129 static TGeoTessellated *ImportFromObjFormat(const char *objfile, bool check = false, bool verbose = false);
130
131 ClassDefOverride(TGeoTessellated, 1) // tessellated shape class
132};
133
134#endif
bool Bool_t
Definition RtypesCore.h:63
float Float_t
Definition RtypesCore.h:57
const char Option_t
Definition RtypesCore.h:66
#define ClassDefOverride(name, id)
Definition Rtypes.h:346
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
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
Computes distance from point (px,py) to the object.
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
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.
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.
ROOT::Geom::Vertex_t Vertex_t
std::vector< Vertex_t > VertexVec_t