0031642: Visualization - crash in Graphic3d_Structure::SetVisual() on redisplaying...
[occt.git] / src / BRepExtrema / BRepExtrema_TriangleSet.hxx
1 // Created on: 2014-10-20
2 // Created by: Denis BOGOLEPOV
3 // Copyright (c) 2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef _BRepExtrema_TriangleSet_HeaderFile
17 #define _BRepExtrema_TriangleSet_HeaderFile
18
19 #include <TopoDS_Face.hxx>
20 #include <BVH_PrimitiveSet3d.hxx>
21
22 //! List of shapes and their IDs for collision detection.
23 typedef NCollection_Vector<TopoDS_Face> BRepExtrema_ShapeList;
24
25 //! Triangle set corresponding to specific face.
26 class BRepExtrema_TriangleSet : public BVH_PrimitiveSet3d
27 {
28 public:
29
30   //! Creates empty triangle set.
31   Standard_EXPORT BRepExtrema_TriangleSet();
32
33   //! Creates triangle set from the given face.
34   Standard_EXPORT BRepExtrema_TriangleSet (const BRepExtrema_ShapeList& theFaces);
35
36   //! Releases resources of triangle set.
37   Standard_EXPORT ~BRepExtrema_TriangleSet();
38
39 public: //! @name methods implementing BVH set interface
40
41   //! Returns total number of triangles.
42   Standard_EXPORT Standard_Integer Size() const Standard_OVERRIDE;
43
44   //! Returns AABB of the given triangle.
45   Standard_EXPORT BVH_Box<Standard_Real, 3> Box (const Standard_Integer theIndex) const Standard_OVERRIDE;
46
47   //! Make inherited method Box() visible to avoid CLang warning
48   using BVH_PrimitiveSet3d::Box;
49
50   //! Returns centroid position along specified axis.
51   Standard_EXPORT Standard_Real Center (const Standard_Integer theIndex, const Standard_Integer theAxis) const Standard_OVERRIDE;
52
53   //! Swaps indices of two specified triangles.
54   Standard_EXPORT void Swap (const Standard_Integer theIndex1, const Standard_Integer theIndex2) Standard_OVERRIDE;
55
56 public:
57
58   //! Clears triangle set data.
59   Standard_EXPORT void Clear();
60
61   //! Initializes triangle set.
62   Standard_EXPORT Standard_Boolean Init (const BRepExtrema_ShapeList& theFaces);
63
64   //! Returns vertices of the given triangle.
65   Standard_EXPORT void GetVertices (const Standard_Integer theIndex,
66                                     BVH_Vec3d&             theVertex1,
67                                     BVH_Vec3d&             theVertex2,
68                                     BVH_Vec3d&             theVertex3) const;
69
70   //! Returns face ID of the given triangle.
71   Standard_EXPORT Standard_Integer GetFaceID (const Standard_Integer theIndex) const;
72
73 protected:
74
75   //! Array of vertex indices.
76   BVH_Array4i myTriangles;
77
78   //! Array of vertex coordinates.
79   BVH_Array3d myVertexArray;
80
81 public:
82
83   DEFINE_STANDARD_RTTIEXT(BRepExtrema_TriangleSet, BVH_PrimitiveSet3d)
84
85 };
86
87 DEFINE_STANDARD_HANDLE(BRepExtrema_TriangleSet, BVH_PrimitiveSet3d)
88
89 #endif // _BRepExtrema_TriangleSet_HeaderFile