1 // Created on: 2014-10-20
2 // Created by: Denis BOGOLEPOV
3 // Copyright (c) 2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _BRepExtrema_ShapeProximity_HeaderFile
17 #define _BRepExtrema_ShapeProximity_HeaderFile
19 #include <BVH_Geometry.hxx>
20 #include <BRepExtrema_TriangleSet.hxx>
21 #include <TColStd_PackedMapOfInteger.hxx>
22 #include <NCollection_DataMap.hxx>
24 //! Set of overlapped sub-shapes.
25 typedef NCollection_DataMap<Standard_Integer, TColStd_PackedMapOfInteger > BRepExtrema_OverlappedSubShapes;
27 //! Tool class for shape proximity detection.
28 //! For two given shapes and given tolerance (offset from the mesh) the algorithm allows
29 //! to determine whether or not they are overlapped. The algorithm input consists of any
30 //! shapes which can be decomposed into individual faces (used as basic shape elements).
31 //! High performance is achieved through the use of existing triangulation of faces. So
32 //! poly triangulation (with the desired deflection) should already be built. Note that
33 //! solution is approximate (and corresponds to the deflection used for triangulation).
35 //! The algorithm can be run in two modes. If tolerance is set to zero, the algorithm
36 //! will detect only intersecting faces (containing triangles with common points). If
37 //! tolerance is set to positive value, the algorithm will also detect faces located
38 //! on distance less than the given tolerance from each other.
39 class BRepExtrema_ShapeProximity
43 //! Creates empty proximity tool.
44 Standard_EXPORT BRepExtrema_ShapeProximity (const Standard_Real theTolerance = 0.0);
46 //! Creates proximity tool for the given two shapes.
47 Standard_EXPORT BRepExtrema_ShapeProximity (const TopoDS_Shape& theShape1,
48 const TopoDS_Shape& theShape2,
49 const Standard_Real theTolerance = 0.0);
53 //! Returns tolerance value for overlap test (distance between shapes).
54 Standard_Real Tolerance() const
59 //! Sets tolerance value for overlap test (distance between shapes).
60 void SetTolerance (const Standard_Real theTolerance)
62 myTolerance = theTolerance;
65 //! Loads 1st shape into proximity tool.
66 Standard_EXPORT Standard_Boolean LoadShape1 (const TopoDS_Shape& theShape1);
68 //! Loads 2nd shape into proximity tool.
69 Standard_EXPORT Standard_Boolean LoadShape2 (const TopoDS_Shape& theShape2);
71 //! Performs search for overlapped faces.
72 Standard_EXPORT void Perform();
74 //! True if the search is completed.
75 Standard_Boolean IsDone() const
80 //! Returns set of all the face triangles of the 1st shape.
81 const NCollection_Handle<BRepExtrema_TriangleSet>& PrimitiveSet1() const
83 return myPrimitiveSet1;
86 //! Returns set of all the face triangles of the 2nd shape.
87 const NCollection_Handle<BRepExtrema_TriangleSet>& PrimitiveSet2() const
89 return myPrimitiveSet2;
92 //! Returns set of IDs of overlapped faces of 1st shape.
93 const BRepExtrema_OverlappedSubShapes& OverlapSubShapes1() const
95 return myOverlapSubShapes1;
98 //! Returns set of IDs of overlapped faces of 2nd shape.
99 const BRepExtrema_OverlappedSubShapes& OverlapSubShapes2() const
101 return myOverlapSubShapes2;
104 //! Returns sub-shape from 1st shape with the given index.
105 const TopoDS_Face& GetSubShape1 (const Standard_Integer theID) const
107 return myFaceList1.Value (theID);
110 //! Returns sub-shape from 1st shape with the given index.
111 const TopoDS_Face& GetSubShape2 (const Standard_Integer theID) const
113 return myFaceList2.Value (theID);
118 //! Performs narrow-phase of overlap test (exact intersection).
119 void IntersectLeavesExact (const BVH_Vec4i& theLeaf1, const BVH_Vec4i& theLeaf2);
121 //! Performs narrow-phase of overlap test (intersection with non-zero tolerance).
122 void IntersectLeavesToler (const BVH_Vec4i& theLeaf1, const BVH_Vec4i& theLeaf2);
126 //! Maximum overlapping distance.
127 Standard_Real myTolerance;
129 //! Is the 1st shape initialized?
130 Standard_Boolean myIsInitS1;
131 //! Is the 2nd shape initialized?
132 Standard_Boolean myIsInitS2;
134 //! List of faces of the 1st shape.
135 BRepExtrema_ShapeList myFaceList1;
136 //! List of faces of the 2nd shape.
137 BRepExtrema_ShapeList myFaceList2;
139 //! Set of all the face triangles of the 1st shape.
140 NCollection_Handle<BRepExtrema_TriangleSet> myPrimitiveSet1;
141 //! Set of all the face triangles of the 2nd shape.
142 NCollection_Handle<BRepExtrema_TriangleSet> myPrimitiveSet2;
144 //! Set of overlapped faces of 1st shape.
145 BRepExtrema_OverlappedSubShapes myOverlapSubShapes1;
146 //! Set of overlapped faces of 2nd shape.
147 BRepExtrema_OverlappedSubShapes myOverlapSubShapes2;
149 //! Is overlap test completed?
150 Standard_Boolean myIsDone;
154 #endif // _BRepExtrema_ShapeProximity_HeaderFile