Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1996-04-22 |
2 | // Created by: Herve LOUESSARD | |
3 | // Copyright (c) 1996-1999 Matra Datavision | |
973c2be1 | 4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e | 5 | // |
973c2be1 | 6 | // This file is part of Open CASCADE Technology software library. |
b311480e | 7 | // |
d5f74e42 | 8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published | |
973c2be1 | 10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT | |
12 | // distribution for complete text of the license and disclaimer of any warranty. | |
b311480e | 13 | // |
973c2be1 | 14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. | |
b311480e | 16 | |
92d1589b | 17 | // Modified: Mps(10-04-97) portage WNT |
92d1589b A |
18 | |
19 | #include <BRepExtrema_DistShapeShape.hxx> | |
20 | ||
7fd59977 | 21 | #include <Standard_OStream.hxx> |
22 | #include <TopTools_IndexedMapOfShape.hxx> | |
23 | #include <BRepBndLib.hxx> | |
24 | #include <Bnd_Box.hxx> | |
25 | #include <TopExp.hxx> | |
7fd59977 | 26 | #include <BRepExtrema_DistanceSS.hxx> |
27 | #include <TopoDS.hxx> | |
28 | #include <TopAbs.hxx> | |
29 | #include <TopoDS_Vertex.hxx> | |
30 | #include <TopoDS_Edge.hxx> | |
31 | #include <TopoDS_Face.hxx> | |
32 | #include <TopAbs_ShapeEnum.hxx> | |
33 | #include <Precision.hxx> | |
7fd59977 | 34 | #include <Bnd_SeqOfBox.hxx> |
35 | #include <BRepExtrema_UnCompatibleShape.hxx> | |
36 | #include <BRep_Tool.hxx> | |
37 | #include <BRepClass3d_SolidClassifier.hxx> | |
762b6cec | 38 | #include <NCollection_Comparator.hxx> |
762b6cec | 39 | #include <NCollection_Vector.hxx> |
92d1589b | 40 | #include <StdFail_NotDone.hxx> |
7fd59977 | 41 | |
3c162495 | 42 | #include <algorithm> |
762b6cec | 43 | namespace |
7fd59977 | 44 | { |
7fd59977 | 45 | |
762b6cec | 46 | static void Decomposition(const TopoDS_Shape& S, |
47 | TopTools_IndexedMapOfShape& MapV, | |
48 | TopTools_IndexedMapOfShape& MapE, | |
49 | TopTools_IndexedMapOfShape& MapF) | |
50 | { | |
51 | MapV.Clear(); | |
52 | MapE.Clear(); | |
53 | MapF.Clear(); | |
54 | TopExp::MapShapes(S,TopAbs_VERTEX,MapV); | |
55 | TopExp::MapShapes(S,TopAbs_EDGE,MapE); | |
56 | TopExp::MapShapes(S,TopAbs_FACE,MapF); | |
57 | } | |
58 | ||
59 | static void BoxCalculation(const TopTools_IndexedMapOfShape& Map, | |
60 | Bnd_SeqOfBox& SBox) | |
61 | { | |
62 | for (Standard_Integer i = 1; i <= Map.Extent(); i++) | |
63 | { | |
64 | Bnd_Box box; | |
65 | BRepBndLib::Add(Map(i), box); | |
66 | SBox.Append(box); | |
67 | } | |
68 | } | |
69 | ||
70 | inline Standard_Real DistanceInitiale(const TopoDS_Vertex V1, | |
71 | const TopoDS_Vertex V2) | |
92d1589b | 72 | { |
762b6cec | 73 | return (BRep_Tool::Pnt(V1).Distance(BRep_Tool::Pnt(V2))); |
92d1589b | 74 | } |
762b6cec | 75 | |
76 | //! Pair of objects to check extrema. | |
77 | struct BRepExtrema_CheckPair | |
78 | { | |
79 | Standard_Integer Index1; //!< Index of the 1st sub-shape | |
80 | Standard_Integer Index2; //!< Index of the 2nd sub-shape | |
81 | Standard_Real Distance; //!< Distance between sub-shapes | |
82 | ||
83 | //! Uninitialized constructor for collection. | |
84 | BRepExtrema_CheckPair() {} | |
85 | ||
86 | //! Creates new pair of sub-shapes. | |
87 | BRepExtrema_CheckPair (Standard_Integer theIndex1, | |
88 | Standard_Integer theIndex2, | |
89 | Standard_Real theDistance) | |
90 | : Index1 (theIndex1), | |
91 | Index2 (theIndex2), | |
92 | Distance (theDistance) {} | |
93 | }; | |
762b6cec | 94 | |
3c162495 | 95 | // Used by std::sort function |
96 | static Standard_Boolean BRepExtrema_CheckPair_Comparator (const BRepExtrema_CheckPair& theLeft, | |
97 | const BRepExtrema_CheckPair& theRight) | |
762b6cec | 98 | { |
3c162495 | 99 | return (theLeft.Distance < theRight.Distance); |
762b6cec | 100 | } |
3c162495 | 101 | } |
7fd59977 | 102 | |
103 | //======================================================================= | |
104 | //function : DistanceMapMap | |
105 | //purpose : | |
106 | //======================================================================= | |
107 | ||
762b6cec | 108 | void BRepExtrema_DistShapeShape::DistanceMapMap (const TopTools_IndexedMapOfShape& theMap1, |
109 | const TopTools_IndexedMapOfShape& theMap2, | |
110 | const Bnd_SeqOfBox& theLBox1, | |
111 | const Bnd_SeqOfBox& theLBox2) | |
7fd59977 | 112 | { |
762b6cec | 113 | NCollection_Vector<BRepExtrema_CheckPair> aPairList; |
114 | const Standard_Integer aCount1 = theMap1.Extent(); | |
115 | const Standard_Integer aCount2 = theMap2.Extent(); | |
116 | for (Standard_Integer anIdx1 = 1; anIdx1 <= aCount1; ++anIdx1) | |
117 | { | |
118 | for (Standard_Integer anIdx2 = 1; anIdx2 <= aCount2; ++anIdx2) | |
119 | { | |
4d19a2c5 | 120 | const Bnd_Box& aBox1 = theLBox1.Value (anIdx1); |
121 | const Bnd_Box& aBox2 = theLBox2.Value (anIdx2); | |
122 | if (aBox1.IsVoid() | |
123 | || aBox2.IsVoid()) | |
124 | { | |
125 | continue; | |
126 | } | |
127 | ||
128 | const Standard_Real aDist = aBox1.Distance (aBox2); | |
762b6cec | 129 | if (aDist < myDistRef - myEps || fabs (aDist - myDistRef) < myEps) |
130 | { | |
131 | aPairList.Append (BRepExtrema_CheckPair (anIdx1, anIdx2, aDist)); | |
132 | } | |
133 | } | |
134 | } | |
92d1589b | 135 | |
3c162495 | 136 | std::stable_sort(aPairList.begin(), aPairList.end(), BRepExtrema_CheckPair_Comparator); |
137 | ||
762b6cec | 138 | for (NCollection_Vector<BRepExtrema_CheckPair>::Iterator aPairIter (aPairList); |
139 | aPairIter.More(); aPairIter.Next()) | |
92d1589b | 140 | { |
762b6cec | 141 | const BRepExtrema_CheckPair& aPair = aPairIter.Value(); |
142 | if (aPair.Distance > myDistRef + myEps) | |
92d1589b | 143 | { |
762b6cec | 144 | break; // early search termination |
145 | } | |
92d1589b | 146 | |
762b6cec | 147 | const Bnd_Box& aBox1 = theLBox1.Value (aPair.Index1); |
148 | const Bnd_Box& aBox2 = theLBox2.Value (aPair.Index2); | |
149 | ||
150 | const TopoDS_Shape& aShape1 = theMap1 (aPair.Index1); | |
151 | const TopoDS_Shape& aShape2 = theMap2 (aPair.Index2); | |
152 | ||
153 | BRepExtrema_DistanceSS aDistTool (aShape1, aShape2, aBox1, aBox2, myDistRef, myEps); | |
154 | if (aDistTool.IsDone()) | |
155 | { | |
156 | if (aDistTool.DistValue() < myDistRef - myEps) | |
157 | { | |
158 | mySolutionsShape1.Clear(); | |
159 | mySolutionsShape2.Clear(); | |
160 | ||
161 | BRepExtrema_SeqOfSolution aSeq1 = aDistTool.Seq1Value(); | |
162 | BRepExtrema_SeqOfSolution aSeq2 = aDistTool.Seq2Value(); | |
163 | ||
164 | mySolutionsShape1.Append (aSeq1); | |
165 | mySolutionsShape2.Append (aSeq2); | |
166 | ||
167 | myDistRef = aDistTool.DistValue(); | |
168 | } | |
169 | else if (fabs (aDistTool.DistValue() - myDistRef) < myEps) | |
170 | { | |
171 | BRepExtrema_SeqOfSolution aSeq1 = aDistTool.Seq1Value(); | |
172 | BRepExtrema_SeqOfSolution aSeq2 = aDistTool.Seq2Value(); | |
173 | ||
174 | mySolutionsShape1.Append (aSeq1); | |
175 | mySolutionsShape2.Append (aSeq2); | |
176 | ||
177 | if (myDistRef > aDistTool.DistValue()) | |
92d1589b | 178 | { |
762b6cec | 179 | myDistRef = aDistTool.DistValue(); |
7fd59977 | 180 | } |
eafb234b | 181 | } |
7fd59977 | 182 | } |
183 | } | |
184 | } | |
185 | ||
186 | //======================================================================= | |
187 | //function : BRepExtrema_DistShapeShape | |
188 | //purpose : | |
189 | //======================================================================= | |
190 | ||
191 | BRepExtrema_DistShapeShape::BRepExtrema_DistShapeShape() | |
762b6cec | 192 | : myDistRef (0.0), |
193 | myIsDone (Standard_False), | |
194 | myInnerSol (Standard_False), | |
195 | myEps (Precision::Confusion()), | |
196 | myIsInitS1 (Standard_False), | |
197 | myIsInitS2 (Standard_False), | |
198 | myFlag (Extrema_ExtFlag_MINMAX), | |
199 | myAlgo (Extrema_ExtAlgo_Grad) | |
7fd59977 | 200 | { |
762b6cec | 201 | // |
7fd59977 | 202 | } |
203 | ||
204 | //======================================================================= | |
205 | //function : BRepExtrema_DistShapeShape | |
206 | //purpose : | |
207 | //======================================================================= | |
208 | BRepExtrema_DistShapeShape::BRepExtrema_DistShapeShape(const TopoDS_Shape& Shape1, | |
92d1589b A |
209 | const TopoDS_Shape& Shape2, |
210 | const Extrema_ExtFlag F, | |
211 | const Extrema_ExtAlgo A) | |
762b6cec | 212 | : myDistRef (0.0), |
213 | myIsDone (Standard_False), | |
214 | myInnerSol (Standard_False), | |
215 | myEps (Precision::Confusion()), | |
216 | myIsInitS1 (Standard_False), | |
217 | myIsInitS2 (Standard_False), | |
218 | myFlag (F), | |
219 | myAlgo (A) | |
7fd59977 | 220 | { |
7fd59977 | 221 | LoadS1(Shape1); |
222 | LoadS2(Shape2); | |
223 | Perform(); | |
224 | } | |
225 | ||
226 | //======================================================================= | |
227 | //function : BRepExtrema_DistShapeShape | |
228 | //purpose : | |
229 | //======================================================================= | |
230 | ||
231 | BRepExtrema_DistShapeShape::BRepExtrema_DistShapeShape(const TopoDS_Shape& Shape1, | |
92d1589b A |
232 | const TopoDS_Shape& Shape2, |
233 | const Standard_Real theDeflection, | |
234 | const Extrema_ExtFlag F, | |
235 | const Extrema_ExtAlgo A) | |
762b6cec | 236 | : myDistRef (0.0), |
237 | myIsDone (Standard_False), | |
238 | myInnerSol (Standard_False), | |
239 | myEps (theDeflection), | |
240 | myIsInitS1 (Standard_False), | |
241 | myIsInitS2 (Standard_False), | |
242 | myFlag (F), | |
243 | myAlgo (A) | |
7fd59977 | 244 | { |
7fd59977 | 245 | LoadS1(Shape1); |
246 | LoadS2(Shape2); | |
247 | Perform(); | |
248 | } | |
249 | ||
7fd59977 | 250 | //======================================================================= |
251 | //function : LoadS1 | |
252 | //purpose : | |
253 | //======================================================================= | |
254 | ||
762b6cec | 255 | void BRepExtrema_DistShapeShape::LoadS1 (const TopoDS_Shape& Shape1) |
7fd59977 | 256 | { |
257 | myShape1 = Shape1; | |
762b6cec | 258 | myIsInitS1 = Standard_False; |
259 | Decomposition (Shape1, myMapV1, myMapE1, myMapF1); | |
7fd59977 | 260 | } |
261 | ||
262 | //======================================================================= | |
263 | //function : LoadS2 | |
264 | //purpose : | |
265 | //======================================================================= | |
266 | ||
762b6cec | 267 | void BRepExtrema_DistShapeShape::LoadS2 (const TopoDS_Shape& Shape2) |
7fd59977 | 268 | { |
269 | myShape2 = Shape2; | |
762b6cec | 270 | myIsInitS2 = Standard_False; |
271 | Decomposition (Shape2, myMapV2, myMapE2, myMapF2); | |
7fd59977 | 272 | } |
273 | ||
274 | //======================================================================= | |
275 | //function : Perform | |
276 | //purpose : | |
277 | //======================================================================= | |
278 | ||
279 | Standard_Boolean BRepExtrema_DistShapeShape::Perform() | |
280 | { | |
281 | myIsDone=Standard_False; | |
282 | myInnerSol=Standard_False; | |
92d1589b A |
283 | mySolutionsShape1.Clear(); |
284 | mySolutionsShape2.Clear(); | |
285 | ||
286 | if ( myShape1.IsNull() || myShape2.IsNull() ) | |
7fd59977 | 287 | return Standard_False; |
288 | ||
92d1589b | 289 | TopoDS_Vertex V; |
92d1589b A |
290 | const Standard_Real tol = 0.001; |
291 | ||
292 | // Treatment of solids | |
293 | const TopAbs_ShapeEnum Type1 = myShape1.ShapeType(); | |
294 | if ((Type1==TopAbs_SOLID) || (Type1 == TopAbs_COMPSOLID)) | |
295 | { | |
7fd59977 | 296 | BRepClass3d_SolidClassifier Classi(myShape1); |
92d1589b A |
297 | const Standard_Integer nbv2 = myMapV2.Extent(); |
298 | Standard_Integer nbv1 = 0; | |
bdde5715 | 299 | while ( (nbv1<nbv2) && (!myInnerSol) ) |
1aeb969a | 300 | { |
7fd59977 | 301 | nbv1++; |
92d1589b A |
302 | V = TopoDS::Vertex(myMapV2(nbv1)); |
303 | const gp_Pnt &P = BRep_Tool::Pnt(V); | |
7fd59977 | 304 | Classi.Perform(P,tol); |
92d1589b A |
305 | if (Classi.State()==TopAbs_IN) |
306 | { | |
7fd59977 | 307 | myInnerSol = Standard_True; |
92d1589b | 308 | myDistRef = 0.; |
7fd59977 | 309 | myIsDone = Standard_True; |
92d1589b A |
310 | BRepExtrema_SolutionElem Sol(0,P,BRepExtrema_IsVertex,V); |
311 | mySolutionsShape1.Append(Sol); | |
312 | mySolutionsShape2.Append(Sol); | |
7fd59977 | 313 | } |
1aeb969a | 314 | } |
7fd59977 | 315 | } |
316 | ||
92d1589b A |
317 | const TopAbs_ShapeEnum Type2 = myShape2.ShapeType(); |
318 | if (((Type2==TopAbs_SOLID) || (Type2==TopAbs_COMPSOLID)) && (!myInnerSol)) | |
319 | { | |
7fd59977 | 320 | BRepClass3d_SolidClassifier Classi(myShape2); |
92d1589b A |
321 | const Standard_Integer nbv1 = myMapV1.Extent(); |
322 | Standard_Integer nbv2 = 0; | |
bdde5715 | 323 | while ( (nbv2<nbv1) && (!myInnerSol) ) |
1aeb969a | 324 | { |
7fd59977 | 325 | nbv2++; |
92d1589b A |
326 | V = TopoDS::Vertex(myMapV1(nbv2)); |
327 | const gp_Pnt &P = BRep_Tool::Pnt(V); | |
7fd59977 | 328 | Classi.Perform(P,tol); |
329 | if (Classi.State()==TopAbs_IN) { | |
330 | myInnerSol = Standard_True; | |
7fd59977 | 331 | myDistRef = 0; |
332 | myIsDone = Standard_True; | |
92d1589b A |
333 | BRepExtrema_SolutionElem Sol (0,P,BRepExtrema_IsVertex,V); |
334 | mySolutionsShape1.Append(Sol); | |
335 | mySolutionsShape2.Append(Sol); | |
7fd59977 | 336 | } |
1aeb969a | 337 | } |
7fd59977 | 338 | } |
762b6cec | 339 | |
92d1589b A |
340 | if (!myInnerSol) |
341 | { | |
762b6cec | 342 | if (!myIsInitS1) // rebuild cached data for 1st shape |
343 | { | |
344 | myBV1.Clear(); | |
345 | myBE1.Clear(); | |
346 | myBF1.Clear(); | |
347 | ||
348 | BoxCalculation (myMapV1, myBV1); | |
349 | BoxCalculation (myMapE1, myBE1); | |
350 | BoxCalculation (myMapF1, myBF1); | |
351 | ||
352 | myIsInitS1 = Standard_True; | |
353 | } | |
354 | ||
355 | if (!myIsInitS2) // rebuild cached data for 2nd shape | |
356 | { | |
357 | myBV2.Clear(); | |
358 | myBE2.Clear(); | |
359 | myBF2.Clear(); | |
360 | ||
361 | BoxCalculation (myMapV2, myBV2); | |
362 | BoxCalculation (myMapE2, myBE2); | |
363 | BoxCalculation (myMapF2, myBF2); | |
364 | ||
365 | myIsInitS2 = Standard_True; | |
366 | } | |
367 | ||
92d1589b A |
368 | if (myMapV1.Extent() && myMapV2.Extent()) |
369 | { | |
7fd59977 | 370 | TopoDS_Vertex V1 = TopoDS::Vertex(myMapV1(1)); |
371 | TopoDS_Vertex V2 = TopoDS::Vertex(myMapV2(1)); | |
92d1589b | 372 | myDistRef = DistanceInitiale(V1, V2); |
7fd59977 | 373 | } |
374 | else | |
92d1589b A |
375 | myDistRef= 1.e30; //szv:!!! |
376 | ||
762b6cec | 377 | DistanceMapMap (myMapV1, myMapV2, myBV1, myBV2); |
378 | DistanceMapMap (myMapV1, myMapE2, myBV1, myBE2); | |
379 | DistanceMapMap (myMapE1, myMapV2, myBE1, myBV2); | |
380 | DistanceMapMap (myMapV1, myMapF2, myBV1, myBF2); | |
381 | DistanceMapMap (myMapF1, myMapV2, myBF1, myBV2); | |
382 | DistanceMapMap (myMapE1, myMapE2, myBE1, myBE2); | |
383 | DistanceMapMap (myMapE1, myMapF2, myBE1, myBF2); | |
384 | DistanceMapMap (myMapF1, myMapE2, myBF1, myBE2); | |
385 | ||
386 | if (fabs (myDistRef) > myEps) | |
387 | { | |
388 | DistanceMapMap (myMapF1, myMapF2, myBF1, myBF2); | |
389 | } | |
7fd59977 | 390 | |
391 | // Modified by Sergey KHROMOV - Tue Mar 6 11:55:03 2001 Begin | |
92d1589b A |
392 | Standard_Integer i = 1; |
393 | for (; i <= mySolutionsShape1.Length(); i++) | |
394 | if (mySolutionsShape1.Value(i).Dist() > myDistRef + myEps) | |
395 | { | |
396 | mySolutionsShape1.Remove(i); | |
397 | mySolutionsShape2.Remove(i); | |
7fd59977 | 398 | } |
399 | // Modified by Sergey KHROMOV - Tue Mar 6 11:55:04 2001 End | |
92d1589b | 400 | myIsDone = ( mySolutionsShape1.Length() > 0 ); |
7fd59977 | 401 | } |
402 | return myIsDone; | |
403 | } | |
404 | ||
7fd59977 | 405 | //======================================================================= |
406 | //function : Value | |
407 | //purpose : | |
408 | //======================================================================= | |
409 | ||
410 | Standard_Real BRepExtrema_DistShapeShape::Value() const | |
411 | { | |
92d1589b | 412 | if (!myIsDone) |
9775fa61 | 413 | throw StdFail_NotDone("BRepExtrema_DistShapeShape::Value: There's no solution "); |
7fd59977 | 414 | |
92d1589b | 415 | return myDistRef; |
7fd59977 | 416 | } |
417 | ||
418 | //======================================================================= | |
419 | //function : SupportOnShape1 | |
420 | //purpose : | |
421 | //======================================================================= | |
422 | ||
92d1589b | 423 | TopoDS_Shape BRepExtrema_DistShapeShape::SupportOnShape1(const Standard_Integer N) const |
7fd59977 | 424 | { |
92d1589b | 425 | if (!myIsDone) |
9775fa61 | 426 | throw StdFail_NotDone("BRepExtrema_DistShapeShape::SupportOnShape1: There's no solution "); |
92d1589b A |
427 | |
428 | const BRepExtrema_SolutionElem &sol = mySolutionsShape1.Value(N); | |
429 | switch (sol.SupportKind()) | |
430 | { | |
431 | case BRepExtrema_IsVertex : return sol.Vertex(); | |
432 | case BRepExtrema_IsOnEdge : return sol.Edge(); | |
433 | case BRepExtrema_IsInFace : return sol.Face(); | |
434 | } | |
435 | return TopoDS_Shape(); | |
7fd59977 | 436 | } |
437 | ||
438 | //======================================================================= | |
439 | //function : SupportOnShape2 | |
440 | //purpose : | |
441 | //======================================================================= | |
442 | ||
443 | TopoDS_Shape BRepExtrema_DistShapeShape::SupportOnShape2(const Standard_Integer N) const | |
444 | { | |
92d1589b | 445 | if (!myIsDone) |
9775fa61 | 446 | throw StdFail_NotDone("BRepExtrema_DistShapeShape::SupportOnShape2: There's no solution "); |
92d1589b A |
447 | |
448 | const BRepExtrema_SolutionElem &sol = mySolutionsShape2.Value(N); | |
449 | switch (sol.SupportKind()) | |
450 | { | |
451 | case BRepExtrema_IsVertex : return sol.Vertex(); | |
452 | case BRepExtrema_IsOnEdge : return sol.Edge(); | |
453 | case BRepExtrema_IsInFace : return sol.Face(); | |
454 | } | |
455 | return TopoDS_Shape(); | |
7fd59977 | 456 | } |
457 | ||
458 | //======================================================================= | |
459 | //function : ParOnEdgeS1 | |
460 | //purpose : | |
461 | //======================================================================= | |
462 | ||
463 | void BRepExtrema_DistShapeShape::ParOnEdgeS1(const Standard_Integer N, Standard_Real& t) const | |
464 | { | |
92d1589b | 465 | if (!myIsDone) |
9775fa61 | 466 | throw StdFail_NotDone("BRepExtrema_DistShapeShape::ParOnEdgeS1: There's no solution"); |
92d1589b A |
467 | |
468 | const BRepExtrema_SolutionElem &sol = mySolutionsShape1.Value(N); | |
469 | if (sol.SupportKind() != BRepExtrema_IsOnEdge) | |
9775fa61 | 470 | throw BRepExtrema_UnCompatibleShape("BRepExtrema_DistShapeShape::ParOnEdgeS1: ParOnEdgeS1 is impossible without EDGE"); |
92d1589b A |
471 | |
472 | sol.EdgeParameter(t); | |
7fd59977 | 473 | } |
474 | ||
475 | //======================================================================= | |
476 | //function : ParOnEdgeS2 | |
477 | //purpose : | |
478 | //======================================================================= | |
479 | ||
480 | void BRepExtrema_DistShapeShape::ParOnEdgeS2(const Standard_Integer N, Standard_Real& t) const | |
481 | { | |
92d1589b | 482 | if (!myIsDone) |
9775fa61 | 483 | throw StdFail_NotDone("BRepExtrema_DistShapeShape::ParOnEdgeS2: There's no solution"); |
92d1589b A |
484 | |
485 | const BRepExtrema_SolutionElem &sol = mySolutionsShape2.Value(N); | |
486 | if (sol.SupportKind() != BRepExtrema_IsOnEdge) | |
9775fa61 | 487 | throw BRepExtrema_UnCompatibleShape("BRepExtrema_DistShapeShape::ParOnEdgeS2: ParOnEdgeS2 is impossible without EDGE"); |
7fd59977 | 488 | |
92d1589b | 489 | sol.EdgeParameter(t); |
7fd59977 | 490 | } |
491 | ||
492 | //======================================================================= | |
493 | //function : ParOnFaceS1 | |
494 | //purpose : | |
495 | //======================================================================= | |
496 | ||
497 | void BRepExtrema_DistShapeShape::ParOnFaceS1(const Standard_Integer N, Standard_Real& u, Standard_Real& v) const | |
498 | { | |
92d1589b | 499 | if (!myIsDone) |
9775fa61 | 500 | throw StdFail_NotDone("BRepExtrema_DistShapeShape::ParOnFaceS1: There's no solution"); |
92d1589b A |
501 | |
502 | const BRepExtrema_SolutionElem &sol = mySolutionsShape1.Value(N); | |
503 | if (sol.SupportKind() != BRepExtrema_IsInFace) | |
9775fa61 | 504 | throw BRepExtrema_UnCompatibleShape("BRepExtrema_DistShapeShape::ParOnFaceS1: ParOnFaceS1 is impossible without FACE"); |
7fd59977 | 505 | |
92d1589b | 506 | sol.FaceParameter(u, v); |
7fd59977 | 507 | } |
508 | ||
92d1589b A |
509 | //======================================================================= |
510 | //function : ParOnFaceS2 | |
511 | //purpose : | |
512 | //======================================================================= | |
513 | ||
7fd59977 | 514 | void BRepExtrema_DistShapeShape::ParOnFaceS2(const Standard_Integer N, Standard_Real& u, Standard_Real& v) const |
515 | { | |
92d1589b | 516 | if (!myIsDone) |
9775fa61 | 517 | throw StdFail_NotDone("BRepExtrema_DistShapeShape::ParOnFaceS2: There's no solution"); |
7fd59977 | 518 | |
92d1589b A |
519 | const BRepExtrema_SolutionElem &sol = mySolutionsShape2.Value(N); |
520 | if (sol.SupportKind() != BRepExtrema_IsInFace) | |
9775fa61 | 521 | throw BRepExtrema_UnCompatibleShape("BRepExtrema_DistShapeShape::ParOnFaceS2:ParOnFaceS2 is impossible without FACE "); |
92d1589b A |
522 | |
523 | sol.FaceParameter(u, v); | |
7fd59977 | 524 | } |
525 | ||
526 | //======================================================================= | |
527 | //function : Dump | |
528 | //purpose : | |
529 | //======================================================================= | |
530 | ||
531 | void BRepExtrema_DistShapeShape::Dump(Standard_OStream& o) const | |
532 | { | |
533 | Standard_Integer i; | |
534 | Standard_Real r1,r2; | |
7fd59977 | 535 | |
536 | o<< "the distance value is : " << Value()<<endl; | |
537 | o<< "the number of solutions is :"<<NbSolution()<<endl; | |
538 | o<<endl; | |
92d1589b A |
539 | for (i=1;i<=NbSolution();i++) |
540 | { | |
541 | o<<"solution number "<<i<<": "<< endl; | |
7fd59977 | 542 | o<<"the type of the solution on the first shape is " <<Standard_Integer( SupportTypeShape1(i)) <<endl; |
543 | o<<"the type of the solution on the second shape is "<<Standard_Integer( SupportTypeShape2(i))<< endl; | |
544 | o<< "the coordinates of the point on the first shape are: "<<endl; | |
545 | o<<"X=" <<PointOnShape1(i).X()<<" Y=" <<PointOnShape1(i).Y()<<" Z="<<PointOnShape1(i).Z()<<endl; | |
546 | o<< "the coordinates of the point on the second shape are: "<<endl; | |
547 | o<<"X="<< PointOnShape2(i).X()<< " Y="<<PointOnShape2(i).Y()<<" Z="<< PointOnShape2(i).Z()<<endl; | |
548 | ||
92d1589b A |
549 | switch (SupportTypeShape1(i)) |
550 | { | |
566f8441 | 551 | case BRepExtrema_IsVertex: |
552 | break; | |
92d1589b A |
553 | case BRepExtrema_IsOnEdge: |
554 | ParOnEdgeS1(i,r1); | |
555 | o << "parameter on the first edge : t= " << r1 << endl; | |
556 | break; | |
557 | case BRepExtrema_IsInFace: | |
558 | ParOnFaceS1(i,r1,r2); | |
559 | o << "parameters on the first face : u= " << r1 << " v=" << r2 << endl; | |
560 | break; | |
561 | } | |
562 | switch (SupportTypeShape2(i)) | |
563 | { | |
566f8441 | 564 | case BRepExtrema_IsVertex: |
565 | break; | |
92d1589b A |
566 | case BRepExtrema_IsOnEdge: |
567 | ParOnEdgeS2(i,r1); | |
568 | o << "parameter on the second edge : t=" << r1 << endl; | |
569 | break; | |
570 | case BRepExtrema_IsInFace: | |
571 | ParOnFaceS2(i,r1,r2); | |
572 | o << "parameters on the second face : u= " << r1 << " v=" << r2 << endl; | |
573 | break; | |
574 | } | |
7fd59977 | 575 | o<<endl; |
576 | } | |
577 | } |