1 // Created on: 1995-09-08
2 // Created by: Christophe MARION
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and / or modify it
9 // under the terms of the GNU Lesser General Public version 2.1 as published
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <BRepExtrema_Poly.hxx>
19 #include <BRep_Tool.hxx>
20 #include <TopoDS_Face.hxx>
22 #include <TopExp_Explorer.hxx>
23 #include <Precision.hxx>
24 #include <Poly_Triangulation.hxx>
25 #include <TColgp_Array1OfPnt.hxx>
27 //=======================================================================
30 //=======================================================================
32 Standard_Boolean BRepExtrema_Poly::Distance (const TopoDS_Shape& S1, const TopoDS_Shape& S2,
33 gp_Pnt& P1, gp_Pnt& P2, Standard_Real& dist)
35 dist = Precision::Infinite();
38 Handle(Poly_Triangulation) Tr;
39 TopExp_Explorer exFace;
41 Standard_Integer nbn1 = 0;
42 for (exFace.Init(S1, TopAbs_FACE);
46 const TopoDS_Face& F = TopoDS::Face(exFace.Current());
47 Tr = BRep_Tool::Triangulation(F,L);
49 nbn1 += Tr->NbNodes();
51 if (nbn1 == 0) return Standard_False;
53 Standard_Integer nbn2 = 0;
54 for (exFace.Init(S2, TopAbs_FACE);
58 const TopoDS_Face& F = TopoDS::Face(exFace.Current());
59 Tr = BRep_Tool::Triangulation(F,L);
61 nbn2 += Tr->NbNodes();
63 if (nbn2 == 0) return Standard_False;
67 TColgp_Array1OfPnt TP1(1,nbn1);
70 for (exFace.Init(S1, TopAbs_FACE);
74 const TopoDS_Face& F = TopoDS::Face(exFace.Current());
75 Tr = BRep_Tool::Triangulation(F,L);
78 const TColgp_Array1OfPnt& Nod = Tr->Nodes();
80 for (i = 1; i <= n; i++)
83 TP1.SetValue(nbn1,Nod(i).Transformed(L));
88 TColgp_Array1OfPnt TP2(1,nbn2);
91 for (exFace.Init(S2, TopAbs_FACE);
95 const TopoDS_Face& F = TopoDS::Face(exFace.Current());
96 Tr = BRep_Tool::Triangulation(F,L);
99 const TColgp_Array1OfPnt& Nod = Tr->Nodes();
101 for (i = 1; i <= n; i++)
104 TP2.SetValue(nbn2,Nod(i).Transformed(L));
109 Standard_Integer i1,i2;
110 for (i1 = 1; i1 <= nbn1; i1++)
112 const gp_Pnt& PP1 = TP1(i1);
113 for (i2 = 1; i2 <= nbn2; i2++)
115 const gp_Pnt& PP2 = TP2(i2);
116 const Standard_Real dCur = PP1.Distance(PP2);
125 return Standard_True;