1 // Created on: 1995-09-22
2 // Created by: Bruno DUMORTIER
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 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 <AppDef_Compute.hxx>
19 #include <AppDef_MultiLine.hxx>
20 #include <AppDef_MultiPointConstraint.hxx>
21 #include <AppParCurves_MultiCurve.hxx>
22 #include <BRepFill_ApproxSeewing.hxx>
23 #include <BSplCLib.hxx>
24 #include <Geom2d_BSplineCurve.hxx>
25 #include <Geom2d_Curve.hxx>
26 #include <Geom_BSplineCurve.hxx>
27 #include <Geom_Curve.hxx>
29 #include <StdFail_NotDone.hxx>
30 #include <TColgp_Array1OfPnt.hxx>
31 #include <TColgp_Array1OfPnt2d.hxx>
32 #include <TColStd_Array1OfInteger.hxx>
33 #include <TColStd_Array1OfReal.hxx>
35 //=======================================================================
36 //function : BRepFill_ApproxSeewing
38 //=======================================================================
39 BRepFill_ApproxSeewing::BRepFill_ApproxSeewing()
40 :myIsDone(Standard_False)
45 //=======================================================================
46 //function : BRepFill_ApproxSeewing
48 //=======================================================================
50 BRepFill_ApproxSeewing::BRepFill_ApproxSeewing(const BRepFill_MultiLine& ML)
51 :myIsDone(Standard_False)
57 //=======================================================================
60 //=======================================================================
62 void BRepFill_ApproxSeewing::Perform(const BRepFill_MultiLine& ML)
66 // evaluate the approximative length of the 3dCurve
68 Standard_Real Length = 0.;
69 Standard_Real U1 = myML.FirstParameter();
70 Standard_Real U2 = myML.LastParameter();
71 Standard_Integer NbPoints = 50;
72 Standard_Real Dist, dU = (U2 - U1) / ( 2*NbPoints - 1);
74 TColgp_Array1OfPnt2d LP(1,2*NbPoints); // tableau Longueur <-> Param
78 for ( i = 0; i < 2*NbPoints ; i++) {
79 P2 = myML.Value(U1 + i*dU);
80 Dist = P1.Distance(P2);
82 LP(i+1) = gp_Pnt2d( Length, U1 + (i*dU));
86 // On cherche a mettre NbPoints dans la curve.
87 // on met les points environ a Length/NbPoints.
89 AppDef_MultiLine MLS ( NbPoints);
90 AppDef_MultiPointConstraint MP ( 1, 2);
94 ML.Value3dOnF1OnF2(U1,P3d,PF1,PF2);
96 MP.SetPoint2d(2, PF1);
97 MP.SetPoint2d(3, PF2);
100 Standard_Real DCorde = Length / ( NbPoints - 1);
101 Standard_Real Corde = DCorde;
102 Standard_Integer Index = 1;
103 Standard_Real U, Alpha;
104 for ( i = 2; i < NbPoints; i++) {
105 while ( LP(Index).X() < Corde) Index ++;
106 Alpha = (Corde - LP(Index-1).X()) / (LP(Index).X() - LP(Index-1).X());
107 U = LP(Index-1).Y() + Alpha * ( LP(Index).Y() - LP(Index-1).Y());
108 AppDef_MultiPointConstraint MPC( 1, 2);
109 ML.Value3dOnF1OnF2(U,P3d,PF1,PF2);
110 MPC.SetPoint (1, P3d);
111 MPC.SetPoint2d(2, PF1);
112 MPC.SetPoint2d(3, PF2);
113 MLS.SetValue (i, MPC);
116 AppDef_MultiPointConstraint MPE( 1, 2);
117 ML.Value3dOnF1OnF2(U2,P3d,PF1,PF2);
118 MPE.SetPoint (1, P3d);
119 MPE.SetPoint2d(2, PF1);
120 MPE.SetPoint2d(3, PF2);
121 MLS.SetValue (NbPoints, MPE);
123 AppDef_Compute Fit(MLS);
125 Standard_Integer NbCurves = Fit.NbMultiCurves();
126 // Standard_Integer MaxDeg = 0;
128 if ( NbCurves == 0) {
130 cout << " TrimSurfaceTool : Approx echoue, on met les polygones" << endl;
133 TColStd_Array1OfReal Knots(1,NbPoints);
134 TColStd_Array1OfInteger Mults(1,NbPoints);
136 Mults(1) = Mults(NbPoints) = 2;
137 TColgp_Array1OfPnt P (1,NbPoints);
138 TColgp_Array1OfPnt2d P1(1,NbPoints);
139 TColgp_Array1OfPnt2d P2(1,NbPoints);
141 Standard_Real Uf = ML.FirstParameter();
142 Standard_Real Ul = ML.LastParameter();
143 Standard_Real dU = (Ul-Uf)/(NbPoints-1);
144 AppDef_MultiPointConstraint MPC;
145 for ( i = 1; i<= NbPoints-1; i++) {
148 P (i) = MPC.Point(1);
149 P1(i) = MPC.Point2d(2);
150 P2(i) = MPC.Point2d(3);
153 // eval the last point on Ul
154 MPC = MLS.Value(NbPoints);
155 P (NbPoints) = MPC.Point(1);
156 P1(NbPoints) = MPC.Point2d(2);
157 P2(NbPoints) = MPC.Point2d(3);
158 Knots(NbPoints) = Ul;
160 myCurve = new Geom_BSplineCurve ( P , Knots, Mults, 1);
161 myPCurve1 = new Geom2d_BSplineCurve( P1, Knots, Mults, 1);
162 myPCurve2 = new Geom2d_BSplineCurve( P2, Knots, Mults, 1);
164 myIsDone = Standard_True;
169 // Les approx sont a priori OK.
171 const AppParCurves_MultiBSpCurve& MBSp =
173 Standard_Integer NbPoles = MBSp.NbPoles();
174 TColgp_Array1OfPnt Poles (1 , NbPoles);
175 TColgp_Array1OfPnt2d Poles2d1(1 , NbPoles);
176 TColgp_Array1OfPnt2d Poles2d2(1 , NbPoles);
178 MBSp.Curve(1, Poles);
179 MBSp.Curve(2, Poles2d1);
180 MBSp.Curve(3, Poles2d2);
182 const TColStd_Array1OfReal& Knots = MBSp.Knots();
183 const TColStd_Array1OfInteger& Mults = MBSp.Multiplicities();
184 Standard_Integer Degree = MBSp.Degree();
186 myCurve = new Geom_BSplineCurve (Poles, Knots,Mults,Degree);
187 myPCurve1 = new Geom2d_BSplineCurve(Poles2d1,Knots,Mults,Degree);
188 myPCurve2 = new Geom2d_BSplineCurve(Poles2d2,Knots,Mults,Degree);
190 myIsDone = Standard_True;
194 //=======================================================================
197 //=======================================================================
199 Standard_Boolean BRepFill_ApproxSeewing::IsDone() const
205 //=======================================================================
206 //function : Handle(Geom_Curve)&
208 //=======================================================================
210 const Handle(Geom_Curve)& BRepFill_ApproxSeewing::Curve() const
212 StdFail_NotDone_Raise_if( !myIsDone,
213 "BRepFill_ApproxSeewing::Curve");
218 //=======================================================================
219 //function : Handle(Geom2d_Curve)&
221 //=======================================================================
223 const Handle(Geom2d_Curve)& BRepFill_ApproxSeewing::CurveOnF1() const
225 StdFail_NotDone_Raise_if( !myIsDone,
226 "BRepFill_ApproxSeewing::CurveOnF1");
231 //=======================================================================
232 //function : Handle(Geom2d_Curve)&
234 //=======================================================================
236 const Handle(Geom2d_Curve)& BRepFill_ApproxSeewing::CurveOnF2() const
238 StdFail_NotDone_Raise_if( !myIsDone,
239 "BRepFill_ApproxSeewing::CurveOnF2");