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