0022627: Change OCCT memory management defaults
[occt.git] / src / GeomLib / GeomLib_MakeCurvefromApprox.cxx
CommitLineData
7fd59977 1// File: GeomLib_MakeCurvefromApprox.cxx
2// Created: Tue Jun 13 11:09:09 1995
3// Author: Bruno DUMORTIER
4// <dub@fuegox>
5
6#include <GeomLib_MakeCurvefromApprox.ixx>
7#include <gp_Pnt2d.hxx>
8#include <TColStd_Array1OfReal.hxx>
9#include <TColStd_HArray1OfReal.hxx>
10#include <TColStd_Array1OfInteger.hxx>
11#include <TColStd_HArray1OfInteger.hxx>
12#include <TColgp_Array1OfPnt.hxx>
13#include <TColgp_Array1OfPnt2d.hxx>
14
15
16//=======================================================================
17//function : GeomLib_MakeCurvefromApprox
18//purpose :
19//=======================================================================
20
21GeomLib_MakeCurvefromApprox::GeomLib_MakeCurvefromApprox
22(const AdvApprox_ApproxAFunction& Approx)
23:myApprox(Approx)
24{
25}
26
27
28//=======================================================================
29//function : Nb1DSpaces
30//purpose :
31//=======================================================================
32
33Standard_Integer GeomLib_MakeCurvefromApprox::Nb1DSpaces() const
34{
35 return myApprox.NumSubSpaces(1);
36}
37
38
39//=======================================================================
40//function : Nb2DSpaces
41//purpose :
42//=======================================================================
43
44Standard_Integer GeomLib_MakeCurvefromApprox::Nb2DSpaces() const
45{
46 return myApprox.NumSubSpaces(2);
47}
48
49
50//=======================================================================
51//function : Nb3DSpaces
52//purpose :
53//=======================================================================
54
55Standard_Integer GeomLib_MakeCurvefromApprox::Nb3DSpaces() const
56{
57 return myApprox.NumSubSpaces(3);
58}
59
60
61//=======================================================================
62//function : Curve2d
63//purpose :
64//=======================================================================
65
66Handle(Geom2d_BSplineCurve) GeomLib_MakeCurvefromApprox::Curve2d
67(const Standard_Integer Index2d) const
68{
69 Standard_OutOfRange_Raise_if
70 ( Index2d < 0 || Index2d > Nb2DSpaces(),
71 " GeomLib_MakeCurvefromApprox : Curve2d");
72 StdFail_NotDone_Raise_if
73 ( !IsDone(),
74 " GeomLib_MakeCurvefromApprox : Curve2d");
75
76 TColgp_Array1OfPnt2d Poles( 1, myApprox.NbPoles());
77 TColStd_Array1OfReal Knots( 1, myApprox.NbKnots());
78 TColStd_Array1OfInteger Mults( 1, myApprox.NbKnots());
79
80 myApprox.Poles2d(Index2d, Poles);
81 Knots = myApprox.Knots()->Array1();
82 Mults = myApprox.Multiplicities()->Array1();
83
84 Handle(Geom2d_BSplineCurve) C =
85 new Geom2d_BSplineCurve( Poles, Knots, Mults, myApprox.Degree());
86
87 return C;
88}
89
90
91//=======================================================================
92//function : Curve2d
93//purpose :
94//=======================================================================
95
96Handle(Geom2d_BSplineCurve) GeomLib_MakeCurvefromApprox::Curve2d
97(const Standard_Integer Index1d,
98 const Standard_Integer Index2d) const
99{
100 Standard_OutOfRange_Raise_if
101 ( Index1d < 0 || Index1d > Nb1DSpaces() ||
102 Index2d < 0 || Index2d > Nb2DSpaces(),
103 " GeomLib_MakeCurvefromApprox : Curve2d");
104 StdFail_NotDone_Raise_if
105 ( !IsDone() && ! myApprox.HasResult(),
106 " GeomLib_MakeCurvefromApprox : Curve2d");
107
108 TColgp_Array1OfPnt2d Poles ( 1, myApprox.NbPoles());
109 TColStd_Array1OfReal Weigths( 1, myApprox.NbPoles());
110 TColStd_Array1OfReal Knots ( 1, myApprox.NbKnots());
111 TColStd_Array1OfInteger Mults ( 1, myApprox.NbKnots());
112
113 myApprox.Poles2d(Index2d, Poles);
114 myApprox.Poles1d(Index1d, Weigths);
115 Knots = myApprox.Knots()->Array1();
116 Mults = myApprox.Multiplicities()->Array1();
117
118 Standard_Real X,Y,W;
119 for ( Standard_Integer i = 1; i <= myApprox.NbPoles(); i++) {
120 W = Weigths(i);
121 Poles(i).Coord(X,Y);
122 Poles(i).SetCoord(X/W, Y/W);
123 }
124
125 Handle(Geom2d_BSplineCurve) C =
126 new Geom2d_BSplineCurve( Poles, Knots, Mults, myApprox.Degree());
127
128 return C;
129}
130//=======================================================================
131//function : Curve2dFromTwo1d
132//purpose :
133//=======================================================================
134
135Handle(Geom2d_BSplineCurve) GeomLib_MakeCurvefromApprox::Curve2dFromTwo1d
136(const Standard_Integer Index1d,
137 const Standard_Integer Index2d) const
138{
139 Standard_OutOfRange_Raise_if
140 ( Index1d < 0 || Index1d > Nb1DSpaces() ||
141 Index2d < 0 || Index2d > Nb1DSpaces(),
142 " GeomLib_MakeCurvefromApprox : Curve2d");
143 StdFail_NotDone_Raise_if
144 ( !IsDone() && ! myApprox.HasResult(),
145 " GeomLib_MakeCurvefromApprox : Curve2d");
146
147 TColgp_Array1OfPnt2d Poles ( 1, myApprox.NbPoles());
148 TColStd_Array1OfReal Poles1d1( 1, myApprox.NbPoles());
149 TColStd_Array1OfReal Poles1d2( 1, myApprox.NbPoles());
150 TColStd_Array1OfReal Knots ( 1, myApprox.NbKnots());
151 TColStd_Array1OfInteger Mults ( 1, myApprox.NbKnots());
152
153 myApprox.Poles1d(Index2d, Poles1d2);
154 myApprox.Poles1d(Index1d, Poles1d1);
155
156 Knots = myApprox.Knots()->Array1();
157 Mults = myApprox.Multiplicities()->Array1();
158
159// Standard_Real X,Y,W;
160 for ( Standard_Integer i = 1; i <= myApprox.NbPoles(); i++) {
161 Poles(i).SetCoord(Poles1d1.Value(i),Poles1d2.Value(i));
162 }
163
164 Handle(Geom2d_BSplineCurve) C =
165 new Geom2d_BSplineCurve( Poles, Knots, Mults, myApprox.Degree());
166
167 return C;
168}
169
170
171
172//=======================================================================
173//function : Curve
174//purpose :
175//=======================================================================
176
177Handle(Geom_BSplineCurve) GeomLib_MakeCurvefromApprox::Curve
178(const Standard_Integer Index3d) const
179{
180 Standard_OutOfRange_Raise_if
181 ( Index3d < 0 || Index3d > Nb3DSpaces(),
182 " GeomLib_MakeCurvefromApprox : Curve");
183 StdFail_NotDone_Raise_if
184 ( !IsDone() && ! myApprox.HasResult(),
185 " GeomLib_MakeCurvefromApprox : Curve");
186
187 TColgp_Array1OfPnt Poles( 1, myApprox.NbPoles());
188 TColStd_Array1OfReal Knots( 1, myApprox.NbKnots());
189 TColStd_Array1OfInteger Mults( 1, myApprox.NbKnots());
190
191 myApprox.Poles(Index3d, Poles);
192 Knots = myApprox.Knots()->Array1();
193 Mults = myApprox.Multiplicities()->Array1();
194
195 Handle(Geom_BSplineCurve) C =
196 new Geom_BSplineCurve( Poles, Knots, Mults, myApprox.Degree());
197
198 return C;
199}
200
201
202//=======================================================================
203//function : Curve
204//purpose :
205//=======================================================================
206
207Handle(Geom_BSplineCurve) GeomLib_MakeCurvefromApprox::Curve
208(const Standard_Integer Index1d,
209 const Standard_Integer Index3d) const
210{
211 Standard_OutOfRange_Raise_if
212 ( Index1d < 0 || Index1d > Nb1DSpaces() ||
213 Index3d < 0 || Index3d > Nb3DSpaces(),
214 " GeomLib_MakeCurvefromApprox : Curve3d");
215 StdFail_NotDone_Raise_if
216 ( !IsDone(),
217 " GeomLib_MakeCurvefromApprox : Curve3d");
218
219 TColgp_Array1OfPnt Poles ( 1, myApprox.NbPoles());
220 TColStd_Array1OfReal Weigths( 1, myApprox.NbPoles());
221 TColStd_Array1OfReal Knots ( 1, myApprox.NbKnots());
222 TColStd_Array1OfInteger Mults ( 1, myApprox.NbKnots());
223
224 myApprox.Poles (Index3d, Poles);
225 myApprox.Poles1d(Index1d, Weigths);
226 Knots = myApprox.Knots()->Array1();
227 Mults = myApprox.Multiplicities()->Array1();
228
229 Standard_Real X,Y,Z,W;
230 for ( Standard_Integer i = 1; i <= myApprox.NbPoles(); i++) {
231 W = Weigths(i);
232 Poles(i).Coord(X,Y,Z);
233 Poles(i).SetCoord(X/W, Y/W, Z/W);
234 }
235
236 Handle(Geom_BSplineCurve) C =
237 new Geom_BSplineCurve( Poles, Knots, Mults, myApprox.Degree());
238
239 return C;
240}