Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:03:10

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 
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 BRepExtrema_ShapeList& theFaces);
0038 
0039   //! Releases resources of triangle set.
0040   Standard_EXPORT ~BRepExtrema_TriangleSet();
0041 
0042 public: //! @name methods implementing BVH set interface
0043 
0044   //! Returns total number of triangles.
0045   Standard_EXPORT Standard_Integer Size() const Standard_OVERRIDE;
0046 
0047   //! Returns AABB of the given triangle.
0048   Standard_EXPORT BVH_Box<Standard_Real, 3> Box (const Standard_Integer theIndex) const Standard_OVERRIDE;
0049 
0050   //! Make inherited method Box() visible to avoid CLang warning
0051   using BVH_PrimitiveSet3d::Box;
0052 
0053   //! Returns centroid position along specified axis.
0054   Standard_EXPORT Standard_Real Center (const Standard_Integer theIndex, const Standard_Integer theAxis) const Standard_OVERRIDE;
0055 
0056   //! Swaps indices of two specified triangles.
0057   Standard_EXPORT void Swap (const Standard_Integer theIndex1, const Standard_Integer theIndex2) Standard_OVERRIDE;
0058 
0059 public:
0060 
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 
0096   //! Initializes triangle set from the face
0097   Standard_Boolean initFace (const TopoDS_Face& theFace, const Standard_Integer theIndex);
0098 
0099   //! Initializes polygon from the edge
0100   Standard_Boolean initEdge (const TopoDS_Edge& theEdge, const Standard_Integer theIndex);
0101 
0102   //! Initializes nodes
0103   void initNodes (const TColgp_Array1OfPnt& theNodes,
0104                   const gp_Trsf& theTrsf,
0105                   const Standard_Integer theIndex);
0106 
0107 protected:
0108 
0109   //! Array of vertex indices.
0110   BVH_Array4i myTriangles;
0111 
0112   //! Array of vertex coordinates.
0113   BVH_Array3d myVertexArray;
0114 
0115   //! Vector of shapes' indices where index of item corresponds to index of vertex,
0116   //! belonging to this shape.
0117   NCollection_Vector<Standard_Integer> myShapeIdxOfVtxVec;
0118 
0119   //! Vector of vertexes' number belonging to shape which index corresponds item's index.
0120   NCollection_Vector<Standard_Integer> myNumVtxInShapeVec;
0121 
0122   //! Vector of triangles' number belonging to shape which index corresponds item's index.
0123   NCollection_Vector<Standard_Integer> myNumTrgInShapeVec;
0124 
0125   //! Map of triangles' indices after (key) and before (value) swapping.
0126   TColStd_DataMapOfIntegerInteger myTrgIdxMap;
0127 
0128 public:
0129 
0130   DEFINE_STANDARD_RTTIEXT(BRepExtrema_TriangleSet, BVH_PrimitiveSet3d)
0131 
0132 };
0133 
0134 DEFINE_STANDARD_HANDLE(BRepExtrema_TriangleSet, BVH_PrimitiveSet3d)
0135 
0136 #endif // _BRepExtrema_TriangleSet_HeaderFile