ae9a414a |
1 | // Created on: 2015-04-26 |
2 | // Created by: Denis BOGOLEPOV |
3 | // Copyright (c) 2015 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_OverlapTool_HeaderFile |
17 | #define _BRepExtrema_OverlapTool_HeaderFile |
18 | |
ae9a414a |
19 | #include <BRepExtrema_TriangleSet.hxx> |
20 | #include <BRepExtrema_ElementFilter.hxx> |
21 | #include <BRepExtrema_MapOfIntegerPackedMapOfInteger.hxx> |
7c1a8210 |
22 | #include <BVH_Traverse.hxx> |
ae9a414a |
23 | |
24 | //! Enables storing of individual overlapped triangles (useful for debug). |
25 | // #define OVERLAP_TOOL_OUTPUT_TRIANGLES |
26 | |
27 | //! Tool class for for detection of overlapping of two BVH primitive sets. |
28 | //! This tool is not intended to be used independently, and is integrated |
29 | //! in other classes, implementing algorithms based on shape tessellation |
30 | //! (BRepExtrema_ShapeProximity and BRepExtrema_SelfIntersection). |
31 | //! |
32 | //! Note that input element sets may correspond to different shapes or to |
33 | //! the same shape. In first case, tessellations of two given shapes will |
34 | //! be tested for intersection (or overlapping, if tolerance is not zero). |
35 | //! In second case, tessellation of single shape will be tested for self- |
36 | //! intersections. Please note that algorithm results are approximate and |
37 | //! depend greatly on the quality of input tessellation(s). |
7c1a8210 |
38 | class BRepExtrema_OverlapTool : public BVH_PairTraverse <Standard_Real, 3> |
ae9a414a |
39 | { |
40 | public: |
41 | |
42 | //! Creates new unitialized overlap tool. |
43 | BRepExtrema_OverlapTool(); |
44 | |
45 | //! Creates new overlap tool for the given element sets. |
46 | BRepExtrema_OverlapTool (const Handle(BRepExtrema_TriangleSet)& theSet1, |
47 | const Handle(BRepExtrema_TriangleSet)& theSet2); |
48 | |
49 | public: |
50 | |
51 | //! Loads the given element sets into the overlap tool. |
52 | void LoadTriangleSets (const Handle(BRepExtrema_TriangleSet)& theSet1, |
53 | const Handle(BRepExtrema_TriangleSet)& theSet2); |
54 | |
55 | //! Performs searching of overlapped mesh elements. |
56 | void Perform (const Standard_Real theTolerance = 0.0); |
57 | |
58 | //! Is overlap test completed? |
59 | Standard_Boolean IsDone() const { return myIsDone; } |
60 | |
61 | //! Marks test results as outdated. |
62 | void MarkDirty() { myIsDone = Standard_False; } |
63 | |
64 | //! Returns set of overlapped sub-shapes of 1st shape (currently only faces are detected). |
65 | const BRepExtrema_MapOfIntegerPackedMapOfInteger& OverlapSubShapes1() const { return myOverlapSubShapes1; } |
66 | |
67 | //! Returns set of overlapped sub-shapes of 2nd shape (currently only faces are detected). |
68 | const BRepExtrema_MapOfIntegerPackedMapOfInteger& OverlapSubShapes2() const { return myOverlapSubShapes2; } |
69 | |
70 | #ifdef OVERLAP_TOOL_OUTPUT_TRIANGLES |
71 | //! Returns set of overlapped triangles from the 1st shape (for debug). |
72 | const TColStd_PackedMapOfInteger& OverlapTriangles1() const { return myOverlapTriangles1; } |
73 | |
74 | //! Returns set of overlapped triangles from the 2nd shape (for debug). |
75 | const TColStd_PackedMapOfInteger& OverlapTriangles2() const { return myOverlapTriangles2; } |
76 | #endif |
77 | |
78 | //! Sets filtering tool for preliminary checking pairs of mesh elements. |
79 | void SetElementFilter (BRepExtrema_ElementFilter* theFilter) { myFilter = theFilter; } |
80 | |
7c1a8210 |
81 | |
82 | public: //! @name Reject/Accept implementations |
83 | |
84 | //! Defines the rules for node rejection by bounding box |
85 | Standard_EXPORT virtual Standard_Boolean RejectNode (const BVH_Vec3d& theCornerMin1, |
86 | const BVH_Vec3d& theCornerMax1, |
87 | const BVH_Vec3d& theCornerMin2, |
88 | const BVH_Vec3d& theCornerMax2, |
89 | Standard_Real&) const Standard_OVERRIDE; |
90 | //! Defines the rules for leaf acceptance |
91 | Standard_EXPORT virtual Standard_Boolean Accept (const Standard_Integer theLeaf1, |
92 | const Standard_Integer theLeaf2) Standard_OVERRIDE; |
93 | |
94 | |
ae9a414a |
95 | protected: |
96 | |
97 | //! Performs narrow-phase of overlap test (exact intersection). |
7c1a8210 |
98 | void intersectTrianglesExact (const Standard_Integer theTrgIdx1, |
99 | const Standard_Integer theTrgIdx2); |
ae9a414a |
100 | |
101 | //! Performs narrow-phase of overlap test (intersection with non-zero tolerance). |
7c1a8210 |
102 | void intersectTrianglesToler (const Standard_Integer theTrgIdx1, |
103 | const Standard_Integer theTrgIdx2, |
104 | const Standard_Real theToler); |
ae9a414a |
105 | |
106 | private: |
107 | |
108 | //! Set of all mesh elements (triangles) of the 1st shape. |
109 | Handle(BRepExtrema_TriangleSet) mySet1; |
110 | //! Set of all mesh elements (triangles) of the 2nd shape. |
111 | Handle(BRepExtrema_TriangleSet) mySet2; |
112 | |
113 | //! Filter for preliminary checking pairs of mesh elements. |
114 | BRepExtrema_ElementFilter* myFilter; |
115 | |
116 | //! Resulted set of overlapped sub-shapes of 1st shape (only faces). |
117 | BRepExtrema_MapOfIntegerPackedMapOfInteger myOverlapSubShapes1; |
118 | //! Resulted set of overlapped sub-shapes of 2nd shape (only faces). |
119 | BRepExtrema_MapOfIntegerPackedMapOfInteger myOverlapSubShapes2; |
120 | |
121 | #ifdef OVERLAP_TOOL_OUTPUT_TRIANGLES |
122 | //! Set of overlapped elements from the 1st shape (only triangles). |
123 | TColStd_PackedMapOfInteger myOverlapTriangles1; |
124 | //! Set of overlapped elements from the 2nd shape (only triangles). |
125 | TColStd_PackedMapOfInteger myOverlapTriangles2; |
126 | #endif |
127 | |
128 | //! Is overlap test test completed? |
129 | Standard_Boolean myIsDone; |
7c1a8210 |
130 | |
131 | Standard_Real myTolerance; |
ae9a414a |
132 | }; |
133 | |
134 | #endif // _BRepExtrema_OverlapTool_HeaderFile |