1 // Created on: 1996-02-15
2 // Created by: Jacques GOUSSARD
3 // Copyright (c) 1996-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 under
9 // the terms of the GNU Lesser General Public License 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.
18 #include <BRep_Tool.hxx>
20 #include <Geom_BezierCurve.hxx>
21 #include <Geom_BSplineCurve.hxx>
22 #include <Geom_Circle.hxx>
23 #include <Geom_Curve.hxx>
24 #include <Geom_Ellipse.hxx>
25 #include <Geom_Line.hxx>
26 #include <Geom_TrimmedCurve.hxx>
27 #include <LocOpe_FindEdges.hxx>
28 #include <Precision.hxx>
29 #include <TColgp_Array1OfPnt.hxx>
30 #include <TColStd_Array1OfInteger.hxx>
31 #include <TColStd_Array1OfReal.hxx>
32 #include <TopExp_Explorer.hxx>
33 #include <TopoDS_Edge.hxx>
34 #include <TopoDS_Shape.hxx>
36 //=======================================================================
39 //=======================================================================
40 void LocOpe_FindEdges::Set(const TopoDS_Shape& FFrom,
41 const TopoDS_Shape& FTo)
49 TopExp_Explorer expf,expt;
50 Handle(Geom_Curve) Cf,Ct;
52 Standard_Real ff,lf,ft,lt;
53 Handle(Standard_Type) Tf,Tt;
55 for (expf.Init(myFFrom,TopAbs_EDGE); expf.More(); expf.Next()) {
56 const TopoDS_Edge& edgf = TopoDS::Edge(expf.Current());
57 Cf = BRep_Tool::Curve(edgf,Loc,ff,lf);
58 if (!Loc.IsIdentity()) {
59 Handle(Geom_Geometry) GGf = Cf->Transformed(Loc.Transformation());
60 Cf = Handle(Geom_Curve)::DownCast (GGf);
62 Tf = Cf->DynamicType();
63 if (Tf == STANDARD_TYPE(Geom_TrimmedCurve)) {
64 Cf = Handle(Geom_TrimmedCurve)::DownCast (Cf)->BasisCurve();
65 Tf = Cf->DynamicType();
67 if (Tf != STANDARD_TYPE(Geom_Line) && Tf != STANDARD_TYPE(Geom_Circle) &&
68 Tf != STANDARD_TYPE(Geom_Ellipse) && Tf != STANDARD_TYPE(Geom_BSplineCurve)
69 && Tf != STANDARD_TYPE(Geom_BezierCurve)) {
72 for (expt.Init(myFTo,TopAbs_EDGE); expt.More(); expt.Next()) {
73 const TopoDS_Edge& edgt = TopoDS::Edge(expt.Current());
74 Ct = BRep_Tool::Curve(edgt,Loc,ft,lt);
75 if (!Loc.IsIdentity()) {
76 Handle(Geom_Geometry) GGt = Ct->Transformed(Loc.Transformation());
77 Ct = Handle(Geom_Curve)::DownCast (GGt);
79 Tt = Ct->DynamicType();
80 if (Tt == STANDARD_TYPE(Geom_TrimmedCurve)) {
81 Ct = Handle(Geom_TrimmedCurve)::DownCast (Ct)->BasisCurve();
82 Tt = Ct->DynamicType();
87 // On a presomption de confusion
88 Standard_Real Tol = Precision::Confusion();
89 if (Tt == STANDARD_TYPE(Geom_Line)) {
90 gp_Lin lif = Handle(Geom_Line)::DownCast (Cf)->Lin();
91 gp_Lin lit = Handle(Geom_Line)::DownCast (Ct)->Lin();
92 gp_Pnt p1 = ElCLib::Value(ff,lif);
93 gp_Pnt p2 = ElCLib::Value(lf,lif);
94 Standard_Real prm1 = ElCLib::Parameter(lit,p1);
95 Standard_Real prm2 = ElCLib::Parameter(lit,p2);
96 if (prm1 >= ft-Tol && prm1 <= lt+Tol &&
97 prm2 >= ft-Tol && prm2 <= lt+Tol) {
99 gp_Pnt pt = ElCLib::Value(prm1,lit);
100 if (pt.SquareDistance(p1) <= Tol) {
101 pt = ElCLib::Value(prm2,lit);
102 if (pt.SquareDistance(p2) <= Tol) {
103 myLFrom.Append(edgf);
110 else if (Tt == STANDARD_TYPE(Geom_Circle)) {
111 gp_Circ cif = Handle(Geom_Circle)::DownCast (Cf)->Circ();
112 gp_Circ cit = Handle(Geom_Circle)::DownCast (Ct)->Circ();
113 if (Abs(cif.Radius()-cit.Radius()) <= Tol &&
114 cif.Location().SquareDistance(cit.Location()) <= Tol*Tol) {
115 // Point debut, calage dans periode, et detection meme sens
119 ElCLib::D1(ff,cif,p1,tgf);
120 p2 = ElCLib::Value(lf,cif);
122 Standard_Real prm1 = ElCLib::Parameter(cit,p1);
123 Standard_Real Tol2d = Precision::PConfusion();
124 if (Abs(prm1-ft) <= Tol2d) prm1 = ft;
125 prm1 = ElCLib::InPeriod(prm1,ft,ft+2.*M_PI);
126 ElCLib::D1(prm1,cit,p1,tgt);
128 Standard_Real prm2 = ElCLib::Parameter(cit,p2);
129 if (tgt.Dot(tgf) > 0.) { // meme sens
130 while (prm2 <= prm1) {
135 if (Abs(prm1-ft) <= Precision::Angular()) {
138 while (prm2 >= prm1) {
143 if (prm1 >= ft-Tol && prm1 <= lt+Tol &&
144 prm2 >= ft-Tol && prm2 <= lt+Tol) {
145 myLFrom.Append(edgf);
150 // Cas non traite : on est a cheval
152 std::cout <<" cas a cheval."<< std::endl;
155 // myLFrom.Append(edgf);
156 // myLTo.Append(edgt);
161 else if (Tt == STANDARD_TYPE(Geom_Ellipse)) {
162 gp_Elips cif = Handle(Geom_Ellipse)::DownCast (Cf)->Elips();
163 gp_Elips cit = Handle(Geom_Ellipse)::DownCast (Ct)->Elips();
166 if (Abs(cif.MajorRadius()-cit.MajorRadius()) <= Tol &&
167 Abs(cif.MinorRadius()-cit.MinorRadius()) <= Tol &&
168 cif.Location().SquareDistance(cit.Location()) <= Tol*Tol) {
169 // Point debut, calage dans periode, et detection meme sens
173 ElCLib::D1(ff,cif,p1,tgf);
174 p2 = ElCLib::Value(lf,cif);
176 Standard_Real prm1 = ElCLib::Parameter(cit,p1);
177 prm1 = ElCLib::InPeriod(prm1,ft,ft+2.*M_PI);
178 ElCLib::D1(prm1,cit,p1,tgt);
180 Standard_Real prm2 = ElCLib::Parameter(cit,p2);
181 if (tgt.Dot(tgf) > 0.) { // meme sens
182 while (prm2 <= prm1) {
187 if (Abs(prm1-ft) <= Precision::Angular()) {
190 while (prm2 >= prm1) {
195 if (prm1 >= ft-Tol && prm1 <= lt+Tol &&
196 prm2 >= ft-Tol && prm2 <= lt+Tol) {
197 myLFrom.Append(edgf);
202 // Cas non traite : on est a cheval
204 std::cout <<" cas a cheval."<< std::endl;
206 // myLFrom.Append(edgf);
207 // myLTo.Append(edgt);
211 else if (Tt == STANDARD_TYPE(Geom_BSplineCurve)) {
212 Handle(Geom_BSplineCurve) Bf = Handle(Geom_BSplineCurve)::DownCast (Cf);
213 Handle(Geom_BSplineCurve) Bt = Handle(Geom_BSplineCurve)::DownCast (Ct);
215 Standard_Boolean IsSame = Standard_True;
217 Standard_Integer nbpoles = Bf->NbPoles();
218 if (nbpoles != Bt->NbPoles()) {
219 IsSame = Standard_False;
223 Standard_Integer nbknots = Bf->NbKnots();
224 if (nbknots != Bt->NbKnots()) {
225 IsSame = Standard_False;
229 TColgp_Array1OfPnt Pf(1, nbpoles), Pt(1, nbpoles);
233 Standard_Real tol3d = BRep_Tool::Tolerance(edgt);
234 for (Standard_Integer p = 1; p <= nbpoles; p++) {
235 if ( (Pf(p)).Distance(Pt(p)) > tol3d) {
236 IsSame = Standard_False;
242 TColStd_Array1OfReal Kf(1, nbknots), Kt(1, nbknots);
246 TColStd_Array1OfInteger Mf(1, nbknots), Mt(1, nbknots);
247 Bf->Multiplicities(Mf);
248 Bt->Multiplicities(Mt);
250 for (Standard_Integer k = 1; k <= nbknots; k++) {
251 if ((Kf(k)-Kt(k)) > Tol) {
252 IsSame = Standard_False;
255 if (Abs(Mf(k)-Mt(k)) > Tol) {
256 IsSame = Standard_False;
261 if (!Bf->IsRational()) {
262 if (Bt->IsRational()) {
263 IsSame = Standard_False;
267 if (!Bt->IsRational()) {
268 IsSame = Standard_False;
272 if (IsSame && Bf->IsRational()) {
273 TColStd_Array1OfReal Wf(1, nbpoles), Wt(1, nbpoles);
277 for (Standard_Integer w = 1; w <= nbpoles; w++) {
278 if (Abs(Wf(w)-Wt(w)) > Tol) {
279 IsSame = Standard_False;
287 std::cout <<"memes bsplines."<< std::endl;
289 myLFrom.Append(edgf);
297 else if (Tt == STANDARD_TYPE(Geom_BezierCurve)) {
298 Handle(Geom_BezierCurve) Bf = Handle(Geom_BezierCurve)::DownCast (Cf);
299 Handle(Geom_BezierCurve) Bt = Handle(Geom_BezierCurve)::DownCast (Ct);
301 Standard_Boolean IsSame = Standard_True;
303 Standard_Integer nbpoles = Bf->NbPoles();
304 if (nbpoles != Bt->NbPoles()) {
305 IsSame = Standard_False;
309 TColgp_Array1OfPnt Pf(1, nbpoles), Pt(1, nbpoles);
313 for (Standard_Integer p = 1; p <= nbpoles; p++) {
314 if ( (Pf(p)).Distance(Pt(p)) > Tol) {
315 IsSame = Standard_False;
321 if (!Bf->IsRational()) {
322 if (Bt->IsRational()) {
323 IsSame = Standard_False;
327 if (!Bt->IsRational()) {
328 IsSame = Standard_False;
332 if (IsSame && Bf->IsRational()) {
333 TColStd_Array1OfReal Wf(1, nbpoles), Wt(1, nbpoles);
337 for (Standard_Integer w = 1; w <= nbpoles; w++) {
338 if (Abs(Wf(w)-Wt(w)) > Tol) {
339 IsSame = Standard_False;
347 std::cout <<"memes beziers."<< std::endl;
349 myLFrom.Append(edgf);