Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 10:29:49

0001 // @(#)root/geom:$Id$
0002 // Author: Andrei Gheata   20/12/19
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
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};     // Vertex indices in the array
0026    int fNvert = 0;                   // number of vertices (can be 3 or 4)
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;                // Number of facets
0063    int fNvert = 0;                  // Number of vertices
0064    int fNseg = 0;                   // Number of segments
0065    bool fDefined = false;           //! Shape fully defined
0066    bool fClosedBody = false;        // The faces are making a closed body
0067    std::vector<Vertex_t> fVertices; // List of vertices
0068    std::vector<TGeoFacet> fFacets;  // List of facets
0069    std::multimap<long, int> fVerticesMap; //! Temporary map used to deduplicate vertices
0070 
0071    TGeoTessellated(const TGeoTessellated &) = delete;
0072    TGeoTessellated &operator=(const TGeoTessellated &) = delete;
0073 
0074 public:
0075    // constructors
0076    TGeoTessellated() {}
0077    TGeoTessellated(const char *name, int nfacets = 0);
0078    TGeoTessellated(const char *name, const std::vector<Vertex_t> &vertices);
0079    // destructor
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 &degenerated) 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    /// Resize and center the shape in a box of size maxsize
0117    void ResizeCenter(double maxsize);
0118 
0119    /// Flip all facets
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    /// Reader from .obj format
0129    static TGeoTessellated *ImportFromObjFormat(const char *objfile, bool check = false, bool verbose = false);
0130 
0131    ClassDefOverride(TGeoTessellated, 1) // tessellated shape class
0132 };
0133 
0134 #endif