File indexing completed on 2025-12-15 10:29:49
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef ROOT_TGeoTessellated
0013 #define ROOT_TGeoTessellated
0014
0015 #include <map>
0016 #include "TGeoVector3.h"
0017 #include "TGeoTypedefs.h"
0018 #include "TGeoBBox.h"
0019
0020 class TGeoFacet {
0021 using Vertex_t = Tessellated::Vertex_t;
0022 using VertexVec_t = Tessellated::VertexVec_t;
0023
0024 private:
0025 int fIvert[4] = {0, 0, 0, 0};
0026 int fNvert = 0;
0027
0028 private:
0029 void SetVertices(int nvert = 0, int i0 = -1, int i1 = -1, int i2 = -1, int i3 = -1)
0030 {
0031 fNvert = nvert;
0032 fIvert[0] = i0;
0033 fIvert[1] = i1;
0034 fIvert[2] = i2;
0035 fIvert[3] = i3;
0036 }
0037
0038 public:
0039 TGeoFacet() {}
0040 TGeoFacet(int i0, int i1, int i2) { SetVertices(3, i0, i1, i2); }
0041 TGeoFacet(int i0, int i1, int i2, int i3) { SetVertices(4, i0, i1, i2, i3); }
0042
0043 int operator[](int ivert) const { return fIvert[ivert]; }
0044 static int CompactFacet(Vertex_t *vert, int nvertices);
0045 int GetNvert() const { return fNvert; }
0046
0047 void Flip()
0048 {
0049 int iv = fIvert[0];
0050 fIvert[0] = fIvert[2];
0051 fIvert[2] = iv;
0052 }
0053 bool IsNeighbour(const TGeoFacet &other, bool &flip) const;
0054 };
0055
0056 class TGeoTessellated : public TGeoBBox {
0057
0058 public:
0059 using Vertex_t = Tessellated::Vertex_t;
0060
0061 private:
0062 int fNfacets = 0;
0063 int fNvert = 0;
0064 int fNseg = 0;
0065 bool fDefined = false;
0066 bool fClosedBody = false;
0067 std::vector<Vertex_t> fVertices;
0068 std::vector<TGeoFacet> fFacets;
0069 std::multimap<long, int> fVerticesMap;
0070
0071 TGeoTessellated(const TGeoTessellated &) = delete;
0072 TGeoTessellated &operator=(const TGeoTessellated &) = delete;
0073
0074 public:
0075
0076 TGeoTessellated() {}
0077 TGeoTessellated(const char *name, int nfacets = 0);
0078 TGeoTessellated(const char *name, const std::vector<Vertex_t> &vertices);
0079
0080 ~TGeoTessellated() override {}
0081
0082 void ComputeBBox() override;
0083 void CloseShape(bool check = true, bool fixFlipped = true, bool verbose = true);
0084
0085 bool AddFacet(const Vertex_t &pt0, const Vertex_t &pt1, const Vertex_t &pt2);
0086 bool AddFacet(const Vertex_t &pt0, const Vertex_t &pt1, const Vertex_t &pt2, const Vertex_t &pt3);
0087 bool AddFacet(int i1, int i2, int i3);
0088 bool AddFacet(int i1, int i2, int i3, int i4);
0089 int AddVertex(const Vertex_t &vert);
0090
0091 bool FacetCheck(int ifacet) const;
0092 Vertex_t FacetComputeNormal(int ifacet, bool °enerated) const;
0093
0094 int GetNfacets() const { return fFacets.size(); }
0095 int GetNsegments() const { return fNseg; }
0096 int GetNvertices() const { return fNvert; }
0097 bool IsClosedBody() const { return fClosedBody; }
0098 bool IsDefined() const { return fDefined; }
0099
0100 const TGeoFacet &GetFacet(int i) const { return fFacets[i]; }
0101 const Vertex_t &GetVertex(int i) const { return fVertices[i]; }
0102
0103 int DistancetoPrimitive(int, int) override { return 99999; }
0104 const TBuffer3D &GetBuffer3D(int reqSections, Bool_t localFrame) const override;
0105 void GetMeshNumbers(int &nvert, int &nsegs, int &npols) const override;
0106 int GetNmeshVertices() const override { return fNvert; }
0107 void InspectShape() const override {}
0108 TBuffer3D *MakeBuffer3D() const override;
0109 void Print(Option_t *option = "") const override;
0110 void SavePrimitive(std::ostream &, Option_t *) override {}
0111 void SetPoints(double *points) const override;
0112 void SetPoints(Float_t *points) const override;
0113 void SetSegsAndPols(TBuffer3D &buff) const override;
0114 void Sizeof3D() const override {}
0115
0116
0117 void ResizeCenter(double maxsize);
0118
0119
0120 void FlipFacets()
0121 {
0122 for (auto facet : fFacets)
0123 facet.Flip();
0124 }
0125
0126 bool CheckClosure(bool fixFlipped = true, bool verbose = true);
0127
0128
0129 static TGeoTessellated *ImportFromObjFormat(const char *objfile, bool check = false, bool verbose = false);
0130
0131 ClassDefOverride(TGeoTessellated, 1)
0132 };
0133
0134 #endif