1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #ifndef _BRepExtrema_DistShapeShape_HeaderFile
15 #define _BRepExtrema_DistShapeShape_HeaderFile
17 #include <Bnd_Array1OfBox.hxx>
18 #include <BRepExtrema_SeqOfSolution.hxx>
19 #include <BRepExtrema_SolutionElem.hxx>
20 #include <BRepExtrema_SupportType.hxx>
21 #include <Extrema_ExtAlgo.hxx>
22 #include <Extrema_ExtFlag.hxx>
23 #include <Message_ProgressRange.hxx>
24 #include <TopoDS_Shape.hxx>
25 #include <Standard_OStream.hxx>
26 #include <Standard_DefineAlloc.hxx>
27 #include <TopTools_IndexedMapOfShape.hxx>
29 //! This class provides tools to compute minimum distance
30 //! between two Shapes (Compound,CompSolid, Solid, Shell, Face, Wire, Edge, Vertex).
31 class BRepExtrema_DistShapeShape
38 Standard_EXPORT BRepExtrema_DistShapeShape();
40 //! create tool and computation of the minimum distance (value and pair of points)
41 //! using default deflection in single thread mode. <br>
42 //! Default deflection value is Precision::Confusion(). <br>
43 //! @param Shape1 - the first shape for distance computation
44 //! @param Shape2 - the second shape for distance computation
45 //! @param F and @param A are not used in computation and are obsolete.
46 //! @param theRange - the progress indicator of algorithm
47 Standard_EXPORT BRepExtrema_DistShapeShape(const TopoDS_Shape& Shape1,
48 const TopoDS_Shape& Shape2,
49 const Extrema_ExtFlag F = Extrema_ExtFlag_MINMAX,
50 const Extrema_ExtAlgo A = Extrema_ExtAlgo_Grad,
51 const Message_ProgressRange& theRange = Message_ProgressRange());
52 //! create tool and computation of the minimum distance
53 //! (value and pair of points) in single thread mode. <br>
54 //! Default deflection value is Precision::Confusion(). <br>
55 //! @param Shape1 - the first shape for distance computation
56 //! @param Shape2 - the second shape for distance computation
57 //! @param theDeflection - the presition of distance computation
58 //! @param F and @param A are not used in computation and are obsolete.
59 //! @param theRange - the progress indicator of algorithm
60 Standard_EXPORT BRepExtrema_DistShapeShape(const TopoDS_Shape& Shape1,
61 const TopoDS_Shape& Shape2,
62 const Standard_Real theDeflection,
63 const Extrema_ExtFlag F = Extrema_ExtFlag_MINMAX,
64 const Extrema_ExtAlgo A = Extrema_ExtAlgo_Grad,
65 const Message_ProgressRange& theRange = Message_ProgressRange());
67 //! Sets deflection to computation of the minimum distance <br>
68 void SetDeflection(const Standard_Real theDeflection)
70 myEps = theDeflection;
73 //! load first shape into extrema <br>
74 Standard_EXPORT void LoadS1(const TopoDS_Shape& Shape1);
76 //! load second shape into extrema <br>
77 Standard_EXPORT void LoadS2(const TopoDS_Shape& Shape1);
79 //! computation of the minimum distance (value and <br>
80 //! couple of points). Parameter theDeflection is used <br>
81 //! to specify a maximum deviation of extreme distances <br>
82 //! from the minimum one. <br>
83 //! Returns IsDone status. <br>
84 //! theRange - the progress indicator of algorithm
85 Standard_EXPORT Standard_Boolean Perform(const Message_ProgressRange& theRange = Message_ProgressRange());
87 //! True if the minimum distance is found. <br>
88 Standard_Boolean IsDone() const
93 //! Returns the number of solutions satisfying the minimum distance. <br>
94 Standard_Integer NbSolution() const
96 return mySolutionsShape1.Length();
99 //! Returns the value of the minimum distance. <br>
100 Standard_EXPORT Standard_Real Value() const;
102 //! True if one of the shapes is a solid and the other shape <br>
103 //! is completely or partially inside the solid. <br>
104 Standard_Boolean InnerSolution() const
109 //! Returns the Point corresponding to the <N>th solution on the first Shape <br>
110 const gp_Pnt & PointOnShape1(const Standard_Integer N) const
112 return mySolutionsShape1.Value(N).Point();
115 //! Returns the Point corresponding to the <N>th solution on the second Shape <br>
116 const gp_Pnt & PointOnShape2(const Standard_Integer N) const
118 return mySolutionsShape2.Value(N).Point();
121 //! gives the type of the support where the Nth solution on the first shape is situated: <br>
122 //! IsVertex => the Nth solution on the first shape is a Vertex <br>
123 //! IsOnEdge => the Nth soluion on the first shape is on a Edge <br>
124 //! IsInFace => the Nth solution on the first shape is inside a face <br>
125 //! the corresponding support is obtained by the method SupportOnShape1 <br>
126 BRepExtrema_SupportType SupportTypeShape1(const Standard_Integer N) const
128 return mySolutionsShape1.Value(N).SupportKind();
131 //! gives the type of the support where the Nth solution on the second shape is situated: <br>
132 //! IsVertex => the Nth solution on the second shape is a Vertex <br>
133 //! IsOnEdge => the Nth soluion on the secondt shape is on a Edge <br>
134 //! IsInFace => the Nth solution on the second shape is inside a face <br>
135 //! the corresponding support is obtained by the method SupportOnShape2 <br>
136 BRepExtrema_SupportType SupportTypeShape2(const Standard_Integer N) const
138 return mySolutionsShape2.Value(N).SupportKind();
141 //! gives the support where the Nth solution on the first shape is situated. <br>
142 //! This support can be a Vertex, an Edge or a Face. <br>
143 Standard_EXPORT TopoDS_Shape SupportOnShape1(const Standard_Integer N) const;
145 //! gives the support where the Nth solution on the second shape is situated. <br>
146 //! This support can be a Vertex, an Edge or a Face. <br>
147 Standard_EXPORT TopoDS_Shape SupportOnShape2(const Standard_Integer N) const;
149 //! gives the corresponding parameter t if the Nth solution <br>
150 //! is situated on an Edge of the first shape <br>
151 Standard_EXPORT void ParOnEdgeS1(const Standard_Integer N,Standard_Real& t) const;
153 //! gives the corresponding parameter t if the Nth solution <br>
154 //! is situated on an Edge of the first shape <br>
155 Standard_EXPORT void ParOnEdgeS2(const Standard_Integer N,Standard_Real& t) const;
157 //! gives the corresponding parameters (U,V) if the Nth solution <br>
158 //! is situated on an face of the first shape <br>
159 Standard_EXPORT void ParOnFaceS1(const Standard_Integer N,Standard_Real& u,Standard_Real& v) const;
161 //! gives the corresponding parameters (U,V) if the Nth solution <br>
162 //! is situated on an Face of the second shape <br>
163 Standard_EXPORT void ParOnFaceS2(const Standard_Integer N,Standard_Real& u,Standard_Real& v) const;
165 //! Prints on the stream o information on the current state of the object. <br>
166 Standard_EXPORT void Dump(Standard_OStream& o) const;
168 //! Sets unused parameter
170 void SetFlag(const Extrema_ExtFlag F)
175 //! Sets unused parameter
177 void SetAlgo(const Extrema_ExtAlgo A)
182 //! If isMultiThread == Standard_True then computation will be performed in parallel.
183 void SetMultiThread(Standard_Boolean theIsMultiThread)
185 myIsMultiThread = theIsMultiThread;
188 //! Returns Standard_True then computation will be performed in parallel
189 //! Default value is Standard_False
190 Standard_Boolean IsMultiThread() const
192 return myIsMultiThread;
197 //! computes the minimum distance between two maps of shapes (Face,Edge,Vertex) <br>
198 Standard_Boolean DistanceMapMap(const TopTools_IndexedMapOfShape& Map1,
199 const TopTools_IndexedMapOfShape& Map2,
200 const Bnd_Array1OfBox& LBox1,
201 const Bnd_Array1OfBox& LBox2,
202 const Message_ProgressRange& theRange);
204 //! computes the minimum distance between two maps of vertices <br>
205 Standard_Boolean DistanceVertVert(const TopTools_IndexedMapOfShape& theMap1,
206 const TopTools_IndexedMapOfShape& theMap2,
207 const Message_ProgressRange& theRange);
209 Standard_Boolean SolidTreatment(const TopoDS_Shape& theShape,
210 const TopTools_IndexedMapOfShape& theMap,
211 const Message_ProgressRange& theRange);
215 Standard_Real myDistRef;
216 Standard_Boolean myIsDone;
217 BRepExtrema_SeqOfSolution mySolutionsShape1;
218 BRepExtrema_SeqOfSolution mySolutionsShape2;
219 Standard_Boolean myInnerSol;
221 TopoDS_Shape myShape1;
222 TopoDS_Shape myShape2;
223 TopTools_IndexedMapOfShape myMapV1;
224 TopTools_IndexedMapOfShape myMapV2;
225 TopTools_IndexedMapOfShape myMapE1;
226 TopTools_IndexedMapOfShape myMapE2;
227 TopTools_IndexedMapOfShape myMapF1;
228 TopTools_IndexedMapOfShape myMapF2;
229 Standard_Boolean myIsInitS1;
230 Standard_Boolean myIsInitS2;
231 Extrema_ExtFlag myFlag;
232 Extrema_ExtAlgo myAlgo;
233 Bnd_Array1OfBox myBV1;
234 Bnd_Array1OfBox myBV2;
235 Bnd_Array1OfBox myBE1;
236 Bnd_Array1OfBox myBE2;
237 Bnd_Array1OfBox myBF1;
238 Bnd_Array1OfBox myBF2;
239 Standard_Boolean myIsMultiThread;