1 // Created on: 1996-02-15
2 // Created by: Jacques GOUSSARD
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
23 #include <LocOpe_FindEdges.ixx>
25 #include <BRep_Tool.hxx>
26 #include <TopExp_Explorer.hxx>
28 #include <Geom_Curve.hxx>
29 #include <Geom_TrimmedCurve.hxx>
30 #include <Geom_Line.hxx>
31 #include <Geom_Circle.hxx>
32 #include <Geom_Ellipse.hxx>
33 #include <Geom_BSplineCurve.hxx>
34 #include <Geom_BezierCurve.hxx>
35 #include <TColgp_Array1OfPnt.hxx>
36 #include <TColStd_Array1OfReal.hxx>
37 #include <TColStd_Array1OfInteger.hxx>
41 #include <Precision.hxx>
45 //=======================================================================
48 //=======================================================================
50 void LocOpe_FindEdges::Set(const TopoDS_Shape& FFrom,
51 const TopoDS_Shape& FTo)
59 TopExp_Explorer expf,expt;
60 Handle(Geom_Curve) Cf,Ct;
62 Standard_Real ff,lf,ft,lt;
63 Handle(Standard_Type) Tf,Tt;
65 for (expf.Init(myFFrom,TopAbs_EDGE); expf.More(); expf.Next()) {
66 const TopoDS_Edge& edgf = TopoDS::Edge(expf.Current());
67 Cf = BRep_Tool::Curve(edgf,Loc,ff,lf);
68 if (!Loc.IsIdentity()) {
69 Handle(Geom_Geometry) GGf = Cf->Transformed(Loc.Transformation());
70 Cf = *((Handle(Geom_Curve)*)&GGf);
72 Tf = Cf->DynamicType();
73 if (Tf == STANDARD_TYPE(Geom_TrimmedCurve)) {
74 Cf = (*((Handle(Geom_TrimmedCurve)*)&Cf))->BasisCurve();
75 Tf = Cf->DynamicType();
77 if (Tf != STANDARD_TYPE(Geom_Line) && Tf != STANDARD_TYPE(Geom_Circle) &&
78 Tf != STANDARD_TYPE(Geom_Ellipse) && Tf != STANDARD_TYPE(Geom_BSplineCurve)
79 && Tf != STANDARD_TYPE(Geom_BezierCurve)) {
82 for (expt.Init(myFTo,TopAbs_EDGE); expt.More(); expt.Next()) {
83 const TopoDS_Edge& edgt = TopoDS::Edge(expt.Current());
84 Ct = BRep_Tool::Curve(edgt,Loc,ft,lt);
85 if (!Loc.IsIdentity()) {
86 Handle(Geom_Geometry) GGt = Ct->Transformed(Loc.Transformation());
87 Ct = *((Handle(Geom_Curve)*)&GGt);
89 Tt = Ct->DynamicType();
90 if (Tt == STANDARD_TYPE(Geom_TrimmedCurve)) {
91 Ct = (*((Handle(Geom_TrimmedCurve)*)&Ct))->BasisCurve();
92 Tt = Ct->DynamicType();
97 // On a presomption de confusion
98 Standard_Real Tol = Precision::Confusion();
99 if (Tt == STANDARD_TYPE(Geom_Line)) {
100 gp_Lin lif = (*((Handle(Geom_Line)*)&Cf))->Lin();
101 gp_Lin lit = (*((Handle(Geom_Line)*)&Ct))->Lin();
102 gp_Pnt p1 = ElCLib::Value(ff,lif);
103 gp_Pnt p2 = ElCLib::Value(lf,lif);
104 Standard_Real prm1 = ElCLib::Parameter(lit,p1);
105 Standard_Real prm2 = ElCLib::Parameter(lit,p2);
106 if (prm1 >= ft-Tol && prm1 <= lt+Tol &&
107 prm2 >= ft-Tol && prm2 <= lt+Tol) {
109 gp_Pnt pt = ElCLib::Value(prm1,lit);
110 if (pt.SquareDistance(p1) <= Tol) {
111 pt = ElCLib::Value(prm2,lit);
112 if (pt.SquareDistance(p2) <= Tol) {
113 myLFrom.Append(edgf);
120 else if (Tt == STANDARD_TYPE(Geom_Circle)) {
121 gp_Circ cif = (*((Handle(Geom_Circle)*)&Cf))->Circ();
122 gp_Circ cit = (*((Handle(Geom_Circle)*)&Ct))->Circ();
123 if (Abs(cif.Radius()-cit.Radius()) <= Tol &&
124 cif.Location().SquareDistance(cit.Location()) <= Tol*Tol) {
125 // Point debut, calage dans periode, et detection meme sens
129 ElCLib::D1(ff,cif,p1,tgf);
130 p2 = ElCLib::Value(lf,cif);
132 Standard_Real prm1 = ElCLib::Parameter(cit,p1);
133 Standard_Real Tol2d = Precision::PConfusion();
134 if (Abs(prm1-ft) <= Tol2d) prm1 = ft;
135 prm1 = ElCLib::InPeriod(prm1,ft,ft+2.*M_PI);
136 ElCLib::D1(prm1,cit,p1,tgt);
138 Standard_Real prm2 = ElCLib::Parameter(cit,p2);
139 if (tgt.Dot(tgf) > 0.) { // meme sens
140 while (prm2 <= prm1) {
145 if (Abs(prm1-ft) <= Precision::Angular()) {
148 while (prm2 >= prm1) {
153 if (prm1 >= ft-Tol && prm1 <= lt+Tol &&
154 prm2 >= ft-Tol && prm2 <= lt+Tol) {
155 myLFrom.Append(edgf);
160 // Cas non traite : on est a cheval
162 cout <<" cas a cheval."<< endl;
165 // myLFrom.Append(edgf);
166 // myLTo.Append(edgt);
171 else if (Tt == STANDARD_TYPE(Geom_Ellipse)) {
172 gp_Elips cif = (*((Handle(Geom_Ellipse)*)&Cf))->Elips();
173 gp_Elips cit = (*((Handle(Geom_Ellipse)*)&Ct))->Elips();
176 if (Abs(cif.MajorRadius()-cit.MajorRadius()) <= Tol &&
177 Abs(cif.MinorRadius()-cit.MinorRadius()) <= Tol &&
178 cif.Location().SquareDistance(cit.Location()) <= Tol*Tol) {
179 // Point debut, calage dans periode, et detection meme sens
183 ElCLib::D1(ff,cif,p1,tgf);
184 p2 = ElCLib::Value(lf,cif);
186 Standard_Real prm1 = ElCLib::Parameter(cit,p1);
187 prm1 = ElCLib::InPeriod(prm1,ft,ft+2.*M_PI);
188 ElCLib::D1(prm1,cit,p1,tgt);
190 Standard_Real prm2 = ElCLib::Parameter(cit,p2);
191 if (tgt.Dot(tgf) > 0.) { // meme sens
192 while (prm2 <= prm1) {
197 if (Abs(prm1-ft) <= Precision::Angular()) {
200 while (prm2 >= prm1) {
205 if (prm1 >= ft-Tol && prm1 <= lt+Tol &&
206 prm2 >= ft-Tol && prm2 <= lt+Tol) {
207 myLFrom.Append(edgf);
212 // Cas non traite : on est a cheval
214 cout <<" cas a cheval."<< endl;
216 // myLFrom.Append(edgf);
217 // myLTo.Append(edgt);
221 else if (Tt == STANDARD_TYPE(Geom_BSplineCurve)) {
222 Handle(Geom_BSplineCurve) Bf = *((Handle(Geom_BSplineCurve)*)&Cf);
223 Handle(Geom_BSplineCurve) Bt = *((Handle(Geom_BSplineCurve)*)&Ct);
225 Standard_Boolean IsSame = Standard_True;
227 Standard_Integer nbpoles = Bf->NbPoles();
228 if (nbpoles != Bt->NbPoles()) {
229 IsSame = Standard_False;
233 Standard_Integer nbknots = Bf->NbKnots();
234 if (nbknots != Bt->NbKnots()) {
235 IsSame = Standard_False;
239 TColgp_Array1OfPnt Pf(1, nbpoles), Pt(1, nbpoles);
243 Standard_Real tol3d = BRep_Tool::Tolerance(edgt);
244 for (Standard_Integer p = 1; p <= nbpoles; p++) {
245 if ( (Pf(p)).Distance(Pt(p)) > tol3d) {
246 IsSame = Standard_False;
252 TColStd_Array1OfReal Kf(1, nbknots), Kt(1, nbknots);
256 TColStd_Array1OfInteger Mf(1, nbknots), Mt(1, nbknots);
257 Bf->Multiplicities(Mf);
258 Bt->Multiplicities(Mt);
260 for (Standard_Integer k = 1; k <= nbknots; k++) {
261 if ((Kf(k)-Kt(k)) > Tol) {
262 IsSame = Standard_False;
265 if (Abs(Mf(k)-Mt(k)) > Tol) {
266 IsSame = Standard_False;
271 if (!Bf->IsRational()) {
272 if (Bt->IsRational()) {
273 IsSame = Standard_False;
277 if (!Bt->IsRational()) {
278 IsSame = Standard_False;
282 if (IsSame && Bf->IsRational()) {
283 TColStd_Array1OfReal Wf(1, nbpoles), Wt(1, nbpoles);
287 for (Standard_Integer w = 1; w <= nbpoles; w++) {
288 if (Abs(Wf(w)-Wt(w)) > Tol) {
289 IsSame = Standard_False;
297 cout <<"memes bsplines."<< endl;
299 myLFrom.Append(edgf);
307 else if (Tt == STANDARD_TYPE(Geom_BezierCurve)) {
308 Handle(Geom_BezierCurve) Bf = *((Handle(Geom_BezierCurve)*)&Cf);
309 Handle(Geom_BezierCurve) Bt = *((Handle(Geom_BezierCurve)*)&Ct);
311 Standard_Boolean IsSame = Standard_True;
313 Standard_Integer nbpoles = Bf->NbPoles();
314 if (nbpoles != Bt->NbPoles()) {
315 IsSame = Standard_False;
319 TColgp_Array1OfPnt Pf(1, nbpoles), Pt(1, nbpoles);
323 for (Standard_Integer p = 1; p <= nbpoles; p++) {
324 if ( (Pf(p)).Distance(Pt(p)) > Tol) {
325 IsSame = Standard_False;
331 if (!Bf->IsRational()) {
332 if (Bt->IsRational()) {
333 IsSame = Standard_False;
337 if (!Bt->IsRational()) {
338 IsSame = Standard_False;
342 if (IsSame && Bf->IsRational()) {
343 TColStd_Array1OfReal Wf(1, nbpoles), Wt(1, nbpoles);
347 for (Standard_Integer w = 1; w <= nbpoles; w++) {
348 if (Abs(Wf(w)-Wt(w)) > Tol) {
349 IsSame = Standard_False;
357 cout <<"memes beziers."<< endl;
359 myLFrom.Append(edgf);