Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-04 09:13:48

0001 // Created on: 2014-10-20
0002 // Created by: Denis BOGOLEPOV
0003 // Copyright (c) 2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef _BRepExtrema_TriangleSet_HeaderFile
0017 #define _BRepExtrema_TriangleSet_HeaderFile
0018 
0019 #include <BVH_PrimitiveSet3d.hxx>
0020 #include <gp_Pnt.hxx>
0021 #include <NCollection_Array1.hxx>
0022 #include <Standard_Integer.hxx>
0023 #include <NCollection_DataMap.hxx>
0024 #include <TopoDS_Edge.hxx>
0025 #include <TopoDS_Face.hxx>
0026 
0027 //! List of shapes and their IDs for collision detection.
0028 
0029 //! Triangle set corresponding to specific face.
0030 class BRepExtrema_TriangleSet : public BVH_PrimitiveSet3d
0031 {
0032 public:
0033   //! Creates empty triangle set.
0034   Standard_EXPORT BRepExtrema_TriangleSet();
0035 
0036   //! Creates triangle set from the given face.
0037   Standard_EXPORT BRepExtrema_TriangleSet(const NCollection_DynamicArray<TopoDS_Shape>& theFaces);
0038 
0039   //! Releases resources of triangle set.
0040   Standard_EXPORT ~BRepExtrema_TriangleSet() override;
0041 
0042 public: //! @name methods implementing BVH set interface
0043   //! Returns total number of triangles.
0044   Standard_EXPORT int Size() const override;
0045 
0046   //! Returns AABB of the given triangle.
0047   Standard_EXPORT BVH_Box<double, 3> Box(const int theIndex) const override;
0048 
0049   //! Make inherited method Box() visible to avoid CLang warning
0050   using BVH_PrimitiveSet3d::Box;
0051 
0052   //! Returns centroid position along specified axis.
0053   Standard_EXPORT double Center(const int theIndex, const int theAxis) const override;
0054 
0055   //! Swaps indices of two specified triangles.
0056   Standard_EXPORT void Swap(const int theIndex1, const int theIndex2) override;
0057 
0058 public:
0059   //! Clears triangle set data.
0060   Standard_EXPORT void Clear();
0061 
0062   //! Initializes triangle set.
0063   Standard_EXPORT bool Init(const NCollection_DynamicArray<TopoDS_Shape>& theShapes);
0064 
0065   //! Returns all vertices.
0066   Standard_EXPORT const BVH_Array3d& GetVertices() const { return myVertexArray; }
0067 
0068   //! Returns vertices of the given triangle.
0069   Standard_EXPORT void GetVertices(const int  theIndex,
0070                                    BVH_Vec3d& theVertex1,
0071                                    BVH_Vec3d& theVertex2,
0072                                    BVH_Vec3d& theVertex3) const;
0073 
0074   //! Returns vertex indices of the given triangle.
0075   Standard_EXPORT void GetVtxIndices(const int                theIndex,
0076                                      NCollection_Array1<int>& theVtxIndices) const;
0077 
0078   //! Returns face ID of the given triangle.
0079   Standard_EXPORT int GetFaceID(const int theIndex) const;
0080 
0081   //! Returns shape ID of the given vertex index.
0082   Standard_EXPORT int GetShapeIDOfVtx(const int theIndex) const;
0083 
0084   //! Returns vertex index in tringulation of the shape, which vertex belongs,
0085   //! with the given vtx ID in whole set.
0086   Standard_EXPORT int GetVtxIdxInShape(const int theIndex) const;
0087 
0088   //! Returns triangle index (before swapping) in tringulation of the shape, which triangle belongs,
0089   //! with the given trg ID in whole set (after swapping).
0090   Standard_EXPORT int GetTrgIdxInShape(const int theIndex) const;
0091 
0092 private:
0093   //! Initializes triangle set from the face
0094   bool initFace(const TopoDS_Face& theFace, const int theIndex);
0095 
0096   //! Initializes polygon from the edge
0097   bool initEdge(const TopoDS_Edge& theEdge, const int theIndex);
0098 
0099   //! Initializes nodes
0100   void initNodes(const NCollection_Array1<gp_Pnt>& theNodes,
0101                  const gp_Trsf&                    theTrsf,
0102                  const int                         theIndex);
0103 
0104 protected:
0105   //! Array of vertex indices.
0106   BVH_Array4i myTriangles;
0107 
0108   //! Array of vertex coordinates.
0109   BVH_Array3d myVertexArray;
0110 
0111   //! Vector of shapes' indices where index of item corresponds to index of vertex,
0112   //! belonging to this shape.
0113   NCollection_DynamicArray<int> myShapeIdxOfVtxVec;
0114 
0115   //! Vector of vertexes' number belonging to shape which index corresponds item's index.
0116   NCollection_DynamicArray<int> myNumVtxInShapeVec;
0117 
0118   //! Vector of triangles' number belonging to shape which index corresponds item's index.
0119   NCollection_DynamicArray<int> myNumTrgInShapeVec;
0120 
0121   //! Map of triangles' indices after (key) and before (value) swapping.
0122   NCollection_DataMap<int, int> myTrgIdxMap;
0123 
0124 public:
0125   DEFINE_STANDARD_RTTIEXT(BRepExtrema_TriangleSet, BVH_PrimitiveSet3d)
0126 };
0127 
0128 #endif // _BRepExtrema_TriangleSet_HeaderFile