0024428: Implementation of LGPL license
[occt.git] / src / BRepExtrema / BRepExtrema_DistShapeShape.hxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and / or modify it
6 // under the terms of the GNU Lesser General Public 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.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 #ifndef _BRepExtrema_DistShapeShape_HeaderFile
15 #define _BRepExtrema_DistShapeShape_HeaderFile
16
17 #ifndef _Standard_HeaderFile
18 #include <Standard.hxx>
19 #endif
20 #ifndef _Standard_DefineAlloc_HeaderFile
21 #include <Standard_DefineAlloc.hxx>
22 #endif
23 #ifndef _Standard_Macro_HeaderFile
24 #include <Standard_Macro.hxx>
25 #endif
26
27 #ifndef _Standard_Integer_HeaderFile
28 #include <Standard_Integer.hxx>
29 #endif
30 #ifndef _Standard_Real_HeaderFile
31 #include <Standard_Real.hxx>
32 #endif
33 #ifndef _Standard_Boolean_HeaderFile
34 #include <Standard_Boolean.hxx>
35 #endif
36 #ifndef _BRepExtrema_SeqOfSolution_HeaderFile
37 #include <BRepExtrema_SeqOfSolution.hxx>
38 #endif
39 #ifndef _BRepExtrema_SolutionElem_HeaderFile
40 #include <BRepExtrema_SolutionElem.hxx>
41 #endif
42 #ifndef _TopoDS_Shape_HeaderFile
43 #include <TopoDS_Shape.hxx>
44 #endif
45 #ifndef _TopTools_IndexedMapOfShape_HeaderFile
46 #include <TopTools_IndexedMapOfShape.hxx>
47 #endif
48 #ifndef _Extrema_ExtFlag_HeaderFile
49 #include <Extrema_ExtFlag.hxx>
50 #endif
51 #ifndef _Extrema_ExtAlgo_HeaderFile
52 #include <Extrema_ExtAlgo.hxx>
53 #endif
54 #ifndef _BRepExtrema_SupportType_HeaderFile
55 #include <BRepExtrema_SupportType.hxx>
56 #endif
57 #ifndef _Standard_OStream_HeaderFile
58 #include <Standard_OStream.hxx>
59 #endif
60 #ifndef _gp_Pnt_HeaderFile
61 #include <gp_Pnt.hxx>
62 #endif
63 class TopoDS_Shape;
64 class TopTools_IndexedMapOfShape;
65 class Bnd_SeqOfBox;
66
67
68 //! This class  provides tools to compute minimum distance <br>
69 //! between two Shapes (Compound,CompSolid, Solid, Shell, Face, Wire, Edge, Vertex). <br>
70 class BRepExtrema_DistShapeShape
71 {
72  public:
73
74   DEFINE_STANDARD_ALLOC
75
76   //! create empty tool <br>
77   Standard_EXPORT BRepExtrema_DistShapeShape();
78   //! computation of the minimum distance (value and pair of points) using default deflection <br>
79   //! Default value is Precision::Confusion(). <br>
80   Standard_EXPORT BRepExtrema_DistShapeShape(const TopoDS_Shape& Shape1,const TopoDS_Shape& Shape2,const Extrema_ExtFlag F = Extrema_ExtFlag_MINMAX,const Extrema_ExtAlgo A = Extrema_ExtAlgo_Grad);
81   //! create tool and load both shapes into it <br>
82   Standard_EXPORT BRepExtrema_DistShapeShape(const TopoDS_Shape& Shape1,const TopoDS_Shape& Shape2,const Standard_Real theDeflection,const Extrema_ExtFlag F = Extrema_ExtFlag_MINMAX,const Extrema_ExtAlgo A = Extrema_ExtAlgo_Grad);
83   
84   Standard_EXPORT void SetDeflection(const Standard_Real theDeflection)
85   {
86     myEps = theDeflection;
87   }
88   //! load first shape into extrema <br>
89   Standard_EXPORT void LoadS1(const TopoDS_Shape& Shape1);
90   //! load second shape into extrema <br>
91   Standard_EXPORT void LoadS2(const TopoDS_Shape& Shape1);
92   //! computation of  the minimum  distance  (value  and <br>
93   //!          couple  of points). Parameter theDeflection is used <br>
94   //!          to specify a maximum deviation of extreme distances <br>
95   //!          from the minimum one. <br>
96   //!          Returns IsDone status. <br>
97   Standard_EXPORT Standard_Boolean Perform();
98   //! True if the minimum distance is found. <br>
99   Standard_EXPORT Standard_Boolean IsDone() const
100   { 
101     return myIsDone;
102   }
103   //! Returns the number of solutions satisfying the minimum distance. <br>
104   Standard_EXPORT Standard_Integer NbSolution() const
105   { 
106     return mySolutionsShape1.Length();
107   }
108   //! Returns the value of the minimum distance. <br>
109   Standard_EXPORT Standard_Real Value() const;
110   //! True if one of the shapes is a solid and the other shape <br>
111   //! is completely or partially inside the solid. <br>
112   Standard_EXPORT Standard_Boolean InnerSolution() const
113   { 
114     return myInnerSol;
115   }
116   //! Returns the Point corresponding to the <N>th solution on the first Shape <br>
117   Standard_EXPORT const gp_Pnt & PointOnShape1(const Standard_Integer N) const
118   { 
119     return mySolutionsShape1.Value(N).Point();
120   }
121   //! Returns the Point corresponding to the <N>th solution on the second Shape <br>
122   Standard_EXPORT const gp_Pnt & PointOnShape2(const Standard_Integer N) const
123   { 
124     return mySolutionsShape2.Value(N).Point();
125   }
126   //! gives the type of the support where the Nth solution on the first shape is situated: <br>
127   //!   IsVertex => the Nth solution on the first shape is a Vertex <br>
128   //!   IsOnEdge => the Nth soluion on the first shape is on a Edge <br>
129   //!   IsInFace => the Nth solution on the first shape is inside a face <br>
130   //! the corresponding support is obtained by the method SupportOnShape1 <br>
131   Standard_EXPORT BRepExtrema_SupportType SupportTypeShape1(const Standard_Integer N) const
132   { 
133     return mySolutionsShape1.Value(N).SupportKind();
134   }
135   //! gives the type of the support where the Nth solution on the second shape is situated: <br>
136   //!   IsVertex => the Nth solution on the second shape is a Vertex <br>
137   //!   IsOnEdge => the Nth soluion on the secondt shape is on a Edge <br>
138   //!   IsInFace => the Nth solution on the second shape is inside a face <br>
139   //! the corresponding support is obtained by the method SupportOnShape2 <br>
140   Standard_EXPORT BRepExtrema_SupportType SupportTypeShape2(const Standard_Integer N) const
141   { 
142     return mySolutionsShape2.Value(N).SupportKind();
143   }
144   //! gives the support where the Nth solution on the first shape is situated. <br>
145   //! This support can be a Vertex, an Edge or a Face. <br>
146   Standard_EXPORT TopoDS_Shape SupportOnShape1(const Standard_Integer N) const;
147   //! gives the support where the Nth solution on the second shape is situated. <br>
148   //! This support can be a Vertex, an Edge or a Face. <br>
149   Standard_EXPORT TopoDS_Shape SupportOnShape2(const Standard_Integer N) const;
150   //! gives the corresponding parameter t if the Nth solution <br>
151   //! is situated on an Egde of the first shape <br>
152   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 Egde of the first shape <br>
155   Standard_EXPORT void ParOnEdgeS2(const Standard_Integer N,Standard_Real& t) const;
156   //! gives the corresponding parameters (U,V) if the Nth solution <br>
157   //! is situated on an face of the first shape <br>
158   Standard_EXPORT void ParOnFaceS1(const Standard_Integer N,Standard_Real& u,Standard_Real& v) const;
159   //! gives the corresponding parameters (U,V) if the Nth solution <br>
160   //! is situated on an Face of the second shape <br>
161   Standard_EXPORT void ParOnFaceS2(const Standard_Integer N,Standard_Real& u,Standard_Real& v) const;
162   //! Prints on the stream o information on the current state of the object. <br>
163   Standard_EXPORT void Dump(Standard_OStream& o) const;
164
165   Standard_EXPORT void SetFlag(const Extrema_ExtFlag F)
166   {
167     myFlag = F;
168   }
169
170   Standard_EXPORT void SetAlgo(const Extrema_ExtAlgo A)
171   {
172     myAlgo = A;
173   }
174
175 private:
176
177   //! computes the minimum distance between two maps of shapes (Face,Edge,Vertex) <br>
178   Standard_EXPORT void DistanceMapMap(const TopTools_IndexedMapOfShape& Map1,const TopTools_IndexedMapOfShape& Map2,const Bnd_SeqOfBox& LBox1,const Bnd_SeqOfBox& LBox2);
179
180   Standard_Real myDistRef;
181   Standard_Boolean myIsDone;
182   BRepExtrema_SeqOfSolution mySolutionsShape1;
183   BRepExtrema_SeqOfSolution mySolutionsShape2;
184   Standard_Boolean myInnerSol;
185   Standard_Real myEps;
186   TopoDS_Shape myShape1;
187   TopoDS_Shape myShape2;
188   TopTools_IndexedMapOfShape myMapV1;
189   TopTools_IndexedMapOfShape myMapV2;
190   TopTools_IndexedMapOfShape myMapE1;
191   TopTools_IndexedMapOfShape myMapE2;
192   TopTools_IndexedMapOfShape myMapF1;
193   TopTools_IndexedMapOfShape myMapF2;
194   Extrema_ExtFlag myFlag;
195   Extrema_ExtAlgo myAlgo;
196 };
197
198 #endif