Commit | Line | Data |
---|---|---|
7fd59977 | 1 | // File: BRepExtrema_Poly.cxx |
2 | // Created: Fri Sep 8 11:03:14 1995 | |
3 | // Author: Christophe MARION | |
7fd59977 | 4 | |
92d1589b A |
5 | #include <BRepExtrema_Poly.hxx> |
6 | ||
7fd59977 | 7 | #include <BRep_Tool.hxx> |
8 | #include <TopoDS_Face.hxx> | |
9 | #include <TopoDS.hxx> | |
10 | #include <TopExp_Explorer.hxx> | |
11 | #include <Precision.hxx> | |
12 | #include <Poly_Triangulation.hxx> | |
13 | #include <TColgp_Array1OfPnt.hxx> | |
14 | ||
15 | //======================================================================= | |
16 | //function : Distance | |
17 | //purpose : | |
18 | //======================================================================= | |
19 | ||
92d1589b A |
20 | Standard_Boolean BRepExtrema_Poly::Distance (const TopoDS_Shape& S1, const TopoDS_Shape& S2, |
21 | gp_Pnt& P1, gp_Pnt& P2, Standard_Real& dist) | |
7fd59977 | 22 | { |
7fd59977 | 23 | dist = Precision::Infinite(); |
92d1589b | 24 | |
7fd59977 | 25 | TopLoc_Location L; |
92d1589b A |
26 | Handle(Poly_Triangulation) Tr; |
27 | TopExp_Explorer exFace; | |
7fd59977 | 28 | |
92d1589b | 29 | Standard_Integer nbn1 = 0; |
7fd59977 | 30 | for (exFace.Init(S1, TopAbs_FACE); |
31 | exFace.More(); | |
92d1589b A |
32 | exFace.Next()) |
33 | { | |
7fd59977 | 34 | const TopoDS_Face& F = TopoDS::Face(exFace.Current()); |
35 | Tr = BRep_Tool::Triangulation(F,L); | |
36 | if (!Tr.IsNull()) | |
37 | nbn1 += Tr->NbNodes(); | |
38 | } | |
92d1589b A |
39 | if (nbn1 == 0) return Standard_False; |
40 | ||
7fd59977 | 41 | Standard_Integer nbn2 = 0; |
7fd59977 | 42 | for (exFace.Init(S2, TopAbs_FACE); |
43 | exFace.More(); | |
92d1589b A |
44 | exFace.Next()) |
45 | { | |
7fd59977 | 46 | const TopoDS_Face& F = TopoDS::Face(exFace.Current()); |
47 | Tr = BRep_Tool::Triangulation(F,L); | |
48 | if (!Tr.IsNull()) | |
49 | nbn2 += Tr->NbNodes(); | |
50 | } | |
92d1589b | 51 | if (nbn2 == 0) return Standard_False; |
7fd59977 | 52 | |
92d1589b | 53 | Standard_Integer i,n; |
7fd59977 | 54 | |
55 | TColgp_Array1OfPnt TP1(1,nbn1); | |
56 | nbn1 = 0; | |
57 | ||
58 | for (exFace.Init(S1, TopAbs_FACE); | |
59 | exFace.More(); | |
92d1589b A |
60 | exFace.Next()) |
61 | { | |
7fd59977 | 62 | const TopoDS_Face& F = TopoDS::Face(exFace.Current()); |
63 | Tr = BRep_Tool::Triangulation(F,L); | |
92d1589b A |
64 | if (!Tr.IsNull()) |
65 | { | |
7fd59977 | 66 | const TColgp_Array1OfPnt& Nod = Tr->Nodes(); |
67 | n = Tr->NbNodes(); | |
92d1589b A |
68 | for (i = 1; i <= n; i++) |
69 | { | |
70 | nbn1++; | |
71 | TP1.SetValue(nbn1,Nod(i).Transformed(L)); | |
7fd59977 | 72 | } |
73 | } | |
74 | } | |
75 | ||
76 | TColgp_Array1OfPnt TP2(1,nbn2); | |
77 | nbn2 = 0; | |
78 | ||
79 | for (exFace.Init(S2, TopAbs_FACE); | |
80 | exFace.More(); | |
92d1589b A |
81 | exFace.Next()) |
82 | { | |
7fd59977 | 83 | const TopoDS_Face& F = TopoDS::Face(exFace.Current()); |
84 | Tr = BRep_Tool::Triangulation(F,L); | |
92d1589b A |
85 | if (!Tr.IsNull()) |
86 | { | |
7fd59977 | 87 | const TColgp_Array1OfPnt& Nod = Tr->Nodes(); |
88 | n = Tr->NbNodes(); | |
92d1589b A |
89 | for (i = 1; i <= n; i++) |
90 | { | |
91 | nbn2++; | |
92 | TP2.SetValue(nbn2,Nod(i).Transformed(L)); | |
7fd59977 | 93 | } |
94 | } | |
95 | } | |
92d1589b A |
96 | |
97 | Standard_Integer i1,i2; | |
98 | for (i1 = 1; i1 <= nbn1; i1++) | |
99 | { | |
100 | const gp_Pnt& PP1 = TP1(i1); | |
101 | for (i2 = 1; i2 <= nbn2; i2++) | |
102 | { | |
103 | const gp_Pnt& PP2 = TP2(i2); | |
104 | const Standard_Real dCur = PP1.Distance(PP2); | |
105 | if (dist > dCur) | |
106 | { | |
107 | P1 = PP1; | |
108 | P2 = PP2; | |
109 | dist = dCur; | |
7fd59977 | 110 | } |
111 | } | |
112 | } | |
113 | return Standard_True; | |
114 | } |