Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-07 08:44:47

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 <TColgp_Array1OfPnt.hxx>
0021 #include <TColStd_DataMapOfIntegerInteger.hxx>
0022 #include <TopoDS_Edge.hxx>
0023 #include <TopoDS_Face.hxx>
0024 
0025 //! List of shapes and their IDs for collision detection.
0026 typedef NCollection_Vector<TopoDS_Shape> BRepExtrema_ShapeList;
0027 
0028 //! Triangle set corresponding to specific face.
0029 class BRepExtrema_TriangleSet : public BVH_PrimitiveSet3d
0030 {
0031 public:
0032   //! Creates empty triangle set.
0033   Standard_EXPORT BRepExtrema_TriangleSet();
0034 
0035   //! Creates triangle set from the given face.
0036   Standard_EXPORT BRepExtrema_TriangleSet(const BRepExtrema_ShapeList& theFaces);
0037 
0038   //! Releases resources of triangle set.
0039   Standard_EXPORT ~BRepExtrema_TriangleSet();
0040 
0041 public: //! @name methods implementing BVH set interface
0042   //! Returns total number of triangles.
0043   Standard_EXPORT Standard_Integer Size() const Standard_OVERRIDE;
0044 
0045   //! Returns AABB of the given triangle.
0046   Standard_EXPORT BVH_Box<Standard_Real, 3> Box(const Standard_Integer theIndex) const
0047     Standard_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 Standard_Real Center(const Standard_Integer theIndex,
0054                                        const Standard_Integer theAxis) const Standard_OVERRIDE;
0055 
0056   //! Swaps indices of two specified triangles.
0057   Standard_EXPORT void Swap(const Standard_Integer theIndex1,
0058                             const Standard_Integer theIndex2) Standard_OVERRIDE;
0059 
0060 public:
0061   //! Clears triangle set data.
0062   Standard_EXPORT void Clear();
0063 
0064   //! Initializes triangle set.
0065   Standard_EXPORT Standard_Boolean Init(const BRepExtrema_ShapeList& theShapes);
0066 
0067   //! Returns all vertices.
0068   Standard_EXPORT const BVH_Array3d& GetVertices() const { return myVertexArray; }
0069 
0070   //! Returns vertices of the given triangle.
0071   Standard_EXPORT void GetVertices(const Standard_Integer theIndex,
0072                                    BVH_Vec3d&             theVertex1,
0073                                    BVH_Vec3d&             theVertex2,
0074                                    BVH_Vec3d&             theVertex3) const;
0075 
0076   //! Returns vertex indices of the given triangle.
0077   Standard_EXPORT void GetVtxIndices(const Standard_Integer                theIndex,
0078                                      NCollection_Array1<Standard_Integer>& theVtxIndices) const;
0079 
0080   //! Returns face ID of the given triangle.
0081   Standard_EXPORT Standard_Integer GetFaceID(const Standard_Integer theIndex) const;
0082 
0083   //! Returns shape ID of the given vertex index.
0084   Standard_EXPORT Standard_Integer GetShapeIDOfVtx(const Standard_Integer theIndex) const;
0085 
0086   //! Returns vertex index in tringulation of the shape, which vertex belongs,
0087   //! with the given vtx ID in whole set.
0088   Standard_EXPORT Standard_Integer GetVtxIdxInShape(const Standard_Integer theIndex) const;
0089 
0090   //! Returns triangle index (before swapping) in tringulation of the shape, which triangle belongs,
0091   //! with the given trg ID in whole set (after swapping).
0092   Standard_EXPORT Standard_Integer GetTrgIdxInShape(const Standard_Integer theIndex) const;
0093 
0094 private:
0095   //! Initializes triangle set from the face
0096   Standard_Boolean initFace(const TopoDS_Face& theFace, const Standard_Integer theIndex);
0097 
0098   //! Initializes polygon from the edge
0099   Standard_Boolean initEdge(const TopoDS_Edge& theEdge, const Standard_Integer theIndex);
0100 
0101   //! Initializes nodes
0102   void initNodes(const TColgp_Array1OfPnt& theNodes,
0103                  const gp_Trsf&            theTrsf,
0104                  const Standard_Integer    theIndex);
0105 
0106 protected:
0107   //! Array of vertex indices.
0108   BVH_Array4i myTriangles;
0109 
0110   //! Array of vertex coordinates.
0111   BVH_Array3d myVertexArray;
0112 
0113   //! Vector of shapes' indices where index of item corresponds to index of vertex,
0114   //! belonging to this shape.
0115   NCollection_Vector<Standard_Integer> myShapeIdxOfVtxVec;
0116 
0117   //! Vector of vertexes' number belonging to shape which index corresponds item's index.
0118   NCollection_Vector<Standard_Integer> myNumVtxInShapeVec;
0119 
0120   //! Vector of triangles' number belonging to shape which index corresponds item's index.
0121   NCollection_Vector<Standard_Integer> myNumTrgInShapeVec;
0122 
0123   //! Map of triangles' indices after (key) and before (value) swapping.
0124   TColStd_DataMapOfIntegerInteger myTrgIdxMap;
0125 
0126 public:
0127   DEFINE_STANDARD_RTTIEXT(BRepExtrema_TriangleSet, BVH_PrimitiveSet3d)
0128 };
0129 
0130 DEFINE_STANDARD_HANDLE(BRepExtrema_TriangleSet, BVH_PrimitiveSet3d)
0131 
0132 #endif // _BRepExtrema_TriangleSet_HeaderFile