0030655: Modeling Data - Provide interfaces for selection of the elements from BVH...
[occt.git] / src / BRepExtrema / BRepExtrema_ShapeProximity.hxx
CommitLineData
558e68ea 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_ShapeProximity_HeaderFile
17#define _BRepExtrema_ShapeProximity_HeaderFile
18
558e68ea 19#include <NCollection_DataMap.hxx>
ae9a414a 20#include <TColStd_PackedMapOfInteger.hxx>
558e68ea 21
ae9a414a 22#include <BRepExtrema_TriangleSet.hxx>
23#include <BRepExtrema_OverlapTool.hxx>
558e68ea 24
25//! Tool class for shape proximity detection.
26//! For two given shapes and given tolerance (offset from the mesh) the algorithm allows
27//! to determine whether or not they are overlapped. The algorithm input consists of any
28//! shapes which can be decomposed into individual faces (used as basic shape elements).
29//! High performance is achieved through the use of existing triangulation of faces. So
30//! poly triangulation (with the desired deflection) should already be built. Note that
31//! solution is approximate (and corresponds to the deflection used for triangulation).
32//!
33//! The algorithm can be run in two modes. If tolerance is set to zero, the algorithm
34//! will detect only intersecting faces (containing triangles with common points). If
35//! tolerance is set to positive value, the algorithm will also detect faces located
36//! on distance less than the given tolerance from each other.
37class BRepExtrema_ShapeProximity
38{
ae9a414a 39public:
558e68ea 40
41 //! Creates empty proximity tool.
42 Standard_EXPORT BRepExtrema_ShapeProximity (const Standard_Real theTolerance = 0.0);
43
44 //! Creates proximity tool for the given two shapes.
45 Standard_EXPORT BRepExtrema_ShapeProximity (const TopoDS_Shape& theShape1,
46 const TopoDS_Shape& theShape2,
47 const Standard_Real theTolerance = 0.0);
48
49public:
50
51 //! Returns tolerance value for overlap test (distance between shapes).
52 Standard_Real Tolerance() const
53 {
54 return myTolerance;
55 }
56
57 //! Sets tolerance value for overlap test (distance between shapes).
58 void SetTolerance (const Standard_Real theTolerance)
59 {
60 myTolerance = theTolerance;
61 }
62
63 //! Loads 1st shape into proximity tool.
64 Standard_EXPORT Standard_Boolean LoadShape1 (const TopoDS_Shape& theShape1);
65
66 //! Loads 2nd shape into proximity tool.
67 Standard_EXPORT Standard_Boolean LoadShape2 (const TopoDS_Shape& theShape2);
68
ae9a414a 69 //! Performs search of overlapped faces.
558e68ea 70 Standard_EXPORT void Perform();
71
72 //! True if the search is completed.
73 Standard_Boolean IsDone() const
74 {
ae9a414a 75 return myOverlapTool.IsDone();
558e68ea 76 }
77
ae9a414a 78 //! Returns set of IDs of overlapped faces of 1st shape (started from 0).
79 const BRepExtrema_MapOfIntegerPackedMapOfInteger& OverlapSubShapes1() const
558e68ea 80 {
ae9a414a 81 return myOverlapTool.OverlapSubShapes1();
558e68ea 82 }
83
ae9a414a 84 //! Returns set of IDs of overlapped faces of 2nd shape (started from 0).
85 const BRepExtrema_MapOfIntegerPackedMapOfInteger& OverlapSubShapes2() const
558e68ea 86 {
ae9a414a 87 return myOverlapTool.OverlapSubShapes2();
558e68ea 88 }
89
ae9a414a 90 //! Returns sub-shape from 1st shape with the given index (started from 0).
558e68ea 91 const TopoDS_Face& GetSubShape1 (const Standard_Integer theID) const
92 {
93 return myFaceList1.Value (theID);
94 }
95
ae9a414a 96 //! Returns sub-shape from 1st shape with the given index (started from 0).
558e68ea 97 const TopoDS_Face& GetSubShape2 (const Standard_Integer theID) const
98 {
99 return myFaceList2.Value (theID);
100 }
101
ae9a414a 102 //! Returns set of all the face triangles of the 1st shape.
103 const Handle(BRepExtrema_TriangleSet)& ElementSet1() const
104 {
105 return myElementSet1;
106 }
558e68ea 107
ae9a414a 108 //! Returns set of all the face triangles of the 2nd shape.
109 const Handle(BRepExtrema_TriangleSet)& ElementSet2() const
110 {
111 return myElementSet2;
112 }
558e68ea 113
114private:
115
116 //! Maximum overlapping distance.
117 Standard_Real myTolerance;
118
119 //! Is the 1st shape initialized?
120 Standard_Boolean myIsInitS1;
121 //! Is the 2nd shape initialized?
122 Standard_Boolean myIsInitS2;
123
124 //! List of faces of the 1st shape.
125 BRepExtrema_ShapeList myFaceList1;
126 //! List of faces of the 2nd shape.
127 BRepExtrema_ShapeList myFaceList2;
128
129 //! Set of all the face triangles of the 1st shape.
ae9a414a 130 Handle(BRepExtrema_TriangleSet) myElementSet1;
558e68ea 131 //! Set of all the face triangles of the 2nd shape.
ae9a414a 132 Handle(BRepExtrema_TriangleSet) myElementSet2;
558e68ea 133
ae9a414a 134 //! Overlap tool used for intersection/overlap test.
135 BRepExtrema_OverlapTool myOverlapTool;
558e68ea 136
137};
138
139#endif // _BRepExtrema_ShapeProximity_HeaderFile