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 <NCollection_DataMap.hxx>
21 #include <TColStd_PackedMapOfInteger.hxx>
23 #include <BRepExtrema_TriangleSet.hxx>
24 #include <BRepExtrema_OverlapTool.hxx>
26 //! Tool class for shape proximity detection.
27 //! For two given shapes and given tolerance (offset from the mesh) the algorithm allows
28 //! to determine whether or not they are overlapped. The algorithm input consists of any
29 //! shapes which can be decomposed into individual faces (used as basic shape elements).
30 //! High performance is achieved through the use of existing triangulation of faces. So
31 //! poly triangulation (with the desired deflection) should already be built. Note that
32 //! solution is approximate (and corresponds to the deflection used for triangulation).
34 //! The algorithm can be run in two modes. If tolerance is set to zero, the algorithm
35 //! will detect only intersecting faces (containing triangles with common points). If
36 //! tolerance is set to positive value, the algorithm will also detect faces located
37 //! on distance less than the given tolerance from each other.
38 class BRepExtrema_ShapeProximity
42 //! Creates empty proximity tool.
43 Standard_EXPORT BRepExtrema_ShapeProximity (const Standard_Real theTolerance = 0.0);
45 //! Creates proximity tool for the given two shapes.
46 Standard_EXPORT BRepExtrema_ShapeProximity (const TopoDS_Shape& theShape1,
47 const TopoDS_Shape& theShape2,
48 const Standard_Real theTolerance = 0.0);
52 //! Returns tolerance value for overlap test (distance between shapes).
53 Standard_Real Tolerance() const
58 //! Sets tolerance value for overlap test (distance between shapes).
59 void SetTolerance (const Standard_Real theTolerance)
61 myTolerance = theTolerance;
64 //! Loads 1st shape into proximity tool.
65 Standard_EXPORT Standard_Boolean LoadShape1 (const TopoDS_Shape& theShape1);
67 //! Loads 2nd shape into proximity tool.
68 Standard_EXPORT Standard_Boolean LoadShape2 (const TopoDS_Shape& theShape2);
70 //! Performs search of overlapped faces.
71 Standard_EXPORT void Perform();
73 //! True if the search is completed.
74 Standard_Boolean IsDone() const
76 return myOverlapTool.IsDone();
79 //! Returns set of IDs of overlapped faces of 1st shape (started from 0).
80 const BRepExtrema_MapOfIntegerPackedMapOfInteger& OverlapSubShapes1() const
82 return myOverlapTool.OverlapSubShapes1();
85 //! Returns set of IDs of overlapped faces of 2nd shape (started from 0).
86 const BRepExtrema_MapOfIntegerPackedMapOfInteger& OverlapSubShapes2() const
88 return myOverlapTool.OverlapSubShapes2();
91 //! Returns sub-shape from 1st shape with the given index (started from 0).
92 const TopoDS_Face& GetSubShape1 (const Standard_Integer theID) const
94 return myFaceList1.Value (theID);
97 //! Returns sub-shape from 1st shape with the given index (started from 0).
98 const TopoDS_Face& GetSubShape2 (const Standard_Integer theID) const
100 return myFaceList2.Value (theID);
103 //! Returns set of all the face triangles of the 1st shape.
104 const Handle(BRepExtrema_TriangleSet)& ElementSet1() const
106 return myElementSet1;
109 //! Returns set of all the face triangles of the 2nd shape.
110 const Handle(BRepExtrema_TriangleSet)& ElementSet2() const
112 return myElementSet2;
117 //! Maximum overlapping distance.
118 Standard_Real myTolerance;
120 //! Is the 1st shape initialized?
121 Standard_Boolean myIsInitS1;
122 //! Is the 2nd shape initialized?
123 Standard_Boolean myIsInitS2;
125 //! List of faces of the 1st shape.
126 BRepExtrema_ShapeList myFaceList1;
127 //! List of faces of the 2nd shape.
128 BRepExtrema_ShapeList myFaceList2;
130 //! Set of all the face triangles of the 1st shape.
131 Handle(BRepExtrema_TriangleSet) myElementSet1;
132 //! Set of all the face triangles of the 2nd shape.
133 Handle(BRepExtrema_TriangleSet) myElementSet2;
135 //! Overlap tool used for intersection/overlap test.
136 BRepExtrema_OverlapTool myOverlapTool;
140 #endif // _BRepExtrema_ShapeProximity_HeaderFile