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