1 // Created on: 1995-06-13
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 <AdvApprox_ApproxAFunction.hxx>
19 #include <Geom2d_BSplineCurve.hxx>
20 #include <Geom_BSplineCurve.hxx>
21 #include <GeomLib_MakeCurvefromApprox.hxx>
22 #include <gp_Pnt2d.hxx>
23 #include <Standard_OutOfRange.hxx>
24 #include <StdFail_NotDone.hxx>
25 #include <TColgp_Array1OfPnt.hxx>
26 #include <TColgp_Array1OfPnt2d.hxx>
27 #include <TColStd_Array1OfInteger.hxx>
28 #include <TColStd_Array1OfReal.hxx>
29 #include <TColStd_HArray1OfInteger.hxx>
30 #include <TColStd_HArray1OfReal.hxx>
32 //=======================================================================
33 //function : GeomLib_MakeCurvefromApprox
35 //=======================================================================
36 GeomLib_MakeCurvefromApprox::GeomLib_MakeCurvefromApprox
37 (const AdvApprox_ApproxAFunction& Approx)
43 //=======================================================================
44 //function : Nb1DSpaces
46 //=======================================================================
48 Standard_Integer GeomLib_MakeCurvefromApprox::Nb1DSpaces() const
50 return myApprox.NumSubSpaces(1);
54 //=======================================================================
55 //function : Nb2DSpaces
57 //=======================================================================
59 Standard_Integer GeomLib_MakeCurvefromApprox::Nb2DSpaces() const
61 return myApprox.NumSubSpaces(2);
65 //=======================================================================
66 //function : Nb3DSpaces
68 //=======================================================================
70 Standard_Integer GeomLib_MakeCurvefromApprox::Nb3DSpaces() const
72 return myApprox.NumSubSpaces(3);
76 //=======================================================================
79 //=======================================================================
81 Handle(Geom2d_BSplineCurve) GeomLib_MakeCurvefromApprox::Curve2d
82 (const Standard_Integer Index2d) const
84 Standard_OutOfRange_Raise_if
85 ( Index2d < 0 || Index2d > Nb2DSpaces(),
86 " GeomLib_MakeCurvefromApprox : Curve2d");
87 StdFail_NotDone_Raise_if
89 " GeomLib_MakeCurvefromApprox : Curve2d");
91 TColgp_Array1OfPnt2d Poles( 1, myApprox.NbPoles());
92 TColStd_Array1OfReal Knots( 1, myApprox.NbKnots());
93 TColStd_Array1OfInteger Mults( 1, myApprox.NbKnots());
95 myApprox.Poles2d(Index2d, Poles);
96 Knots = myApprox.Knots()->Array1();
97 Mults = myApprox.Multiplicities()->Array1();
99 Handle(Geom2d_BSplineCurve) C =
100 new Geom2d_BSplineCurve( Poles, Knots, Mults, myApprox.Degree());
106 //=======================================================================
109 //=======================================================================
111 Handle(Geom2d_BSplineCurve) GeomLib_MakeCurvefromApprox::Curve2d
112 (const Standard_Integer Index1d,
113 const Standard_Integer Index2d) const
115 Standard_OutOfRange_Raise_if
116 ( Index1d < 0 || Index1d > Nb1DSpaces() ||
117 Index2d < 0 || Index2d > Nb2DSpaces(),
118 " GeomLib_MakeCurvefromApprox : Curve2d");
119 StdFail_NotDone_Raise_if
120 ( !IsDone() && ! myApprox.HasResult(),
121 " GeomLib_MakeCurvefromApprox : Curve2d");
123 TColgp_Array1OfPnt2d Poles ( 1, myApprox.NbPoles());
124 TColStd_Array1OfReal Weigths( 1, myApprox.NbPoles());
125 TColStd_Array1OfReal Knots ( 1, myApprox.NbKnots());
126 TColStd_Array1OfInteger Mults ( 1, myApprox.NbKnots());
128 myApprox.Poles2d(Index2d, Poles);
129 myApprox.Poles1d(Index1d, Weigths);
130 Knots = myApprox.Knots()->Array1();
131 Mults = myApprox.Multiplicities()->Array1();
134 for ( Standard_Integer i = 1; i <= myApprox.NbPoles(); i++) {
137 Poles(i).SetCoord(X/W, Y/W);
140 Handle(Geom2d_BSplineCurve) C =
141 new Geom2d_BSplineCurve( Poles, Knots, Mults, myApprox.Degree());
145 //=======================================================================
146 //function : Curve2dFromTwo1d
148 //=======================================================================
150 Handle(Geom2d_BSplineCurve) GeomLib_MakeCurvefromApprox::Curve2dFromTwo1d
151 (const Standard_Integer Index1d,
152 const Standard_Integer Index2d) const
154 Standard_OutOfRange_Raise_if
155 ( Index1d < 0 || Index1d > Nb1DSpaces() ||
156 Index2d < 0 || Index2d > Nb1DSpaces(),
157 " GeomLib_MakeCurvefromApprox : Curve2d");
158 StdFail_NotDone_Raise_if
159 ( !IsDone() && ! myApprox.HasResult(),
160 " GeomLib_MakeCurvefromApprox : Curve2d");
162 TColgp_Array1OfPnt2d Poles ( 1, myApprox.NbPoles());
163 TColStd_Array1OfReal Poles1d1( 1, myApprox.NbPoles());
164 TColStd_Array1OfReal Poles1d2( 1, myApprox.NbPoles());
165 TColStd_Array1OfReal Knots ( 1, myApprox.NbKnots());
166 TColStd_Array1OfInteger Mults ( 1, myApprox.NbKnots());
168 myApprox.Poles1d(Index2d, Poles1d2);
169 myApprox.Poles1d(Index1d, Poles1d1);
171 Knots = myApprox.Knots()->Array1();
172 Mults = myApprox.Multiplicities()->Array1();
174 // Standard_Real X,Y,W;
175 for ( Standard_Integer i = 1; i <= myApprox.NbPoles(); i++) {
176 Poles(i).SetCoord(Poles1d1.Value(i),Poles1d2.Value(i));
179 Handle(Geom2d_BSplineCurve) C =
180 new Geom2d_BSplineCurve( Poles, Knots, Mults, myApprox.Degree());
187 //=======================================================================
190 //=======================================================================
192 Handle(Geom_BSplineCurve) GeomLib_MakeCurvefromApprox::Curve
193 (const Standard_Integer Index3d) const
195 Standard_OutOfRange_Raise_if
196 ( Index3d < 0 || Index3d > Nb3DSpaces(),
197 " GeomLib_MakeCurvefromApprox : Curve");
198 StdFail_NotDone_Raise_if
199 ( !IsDone() && ! myApprox.HasResult(),
200 " GeomLib_MakeCurvefromApprox : Curve");
202 TColgp_Array1OfPnt Poles( 1, myApprox.NbPoles());
203 TColStd_Array1OfReal Knots( 1, myApprox.NbKnots());
204 TColStd_Array1OfInteger Mults( 1, myApprox.NbKnots());
206 myApprox.Poles(Index3d, Poles);
207 Knots = myApprox.Knots()->Array1();
208 Mults = myApprox.Multiplicities()->Array1();
210 Handle(Geom_BSplineCurve) C =
211 new Geom_BSplineCurve( Poles, Knots, Mults, myApprox.Degree());
217 //=======================================================================
220 //=======================================================================
222 Handle(Geom_BSplineCurve) GeomLib_MakeCurvefromApprox::Curve
223 (const Standard_Integer Index1d,
224 const Standard_Integer Index3d) const
226 Standard_OutOfRange_Raise_if
227 ( Index1d < 0 || Index1d > Nb1DSpaces() ||
228 Index3d < 0 || Index3d > Nb3DSpaces(),
229 " GeomLib_MakeCurvefromApprox : Curve3d");
230 StdFail_NotDone_Raise_if
232 " GeomLib_MakeCurvefromApprox : Curve3d");
234 TColgp_Array1OfPnt Poles ( 1, myApprox.NbPoles());
235 TColStd_Array1OfReal Weigths( 1, myApprox.NbPoles());
236 TColStd_Array1OfReal Knots ( 1, myApprox.NbKnots());
237 TColStd_Array1OfInteger Mults ( 1, myApprox.NbKnots());
239 myApprox.Poles (Index3d, Poles);
240 myApprox.Poles1d(Index1d, Weigths);
241 Knots = myApprox.Knots()->Array1();
242 Mults = myApprox.Multiplicities()->Array1();
244 Standard_Real X,Y,Z,W;
245 for ( Standard_Integer i = 1; i <= myApprox.NbPoles(); i++) {
247 Poles(i).Coord(X,Y,Z);
248 Poles(i).SetCoord(X/W, Y/W, Z/W);
251 Handle(Geom_BSplineCurve) C =
252 new Geom_BSplineCurve( Poles, Knots, Mults, myApprox.Degree());