0027105: Make code ISO-compliant [-Wpedantic fixes]
[occt.git] / src / GeomLib / GeomLib_MakeCurvefromApprox.cxx
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
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
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>
31
32 //=======================================================================
33 //function : GeomLib_MakeCurvefromApprox
34 //purpose  : 
35 //=======================================================================
36 GeomLib_MakeCurvefromApprox::GeomLib_MakeCurvefromApprox
37 (const AdvApprox_ApproxAFunction& Approx)
38 :myApprox(Approx)
39 {
40 }
41
42
43 //=======================================================================
44 //function : Nb1DSpaces
45 //purpose  : 
46 //=======================================================================
47
48 Standard_Integer GeomLib_MakeCurvefromApprox::Nb1DSpaces() const 
49 {
50   return myApprox.NumSubSpaces(1);
51 }
52
53
54 //=======================================================================
55 //function : Nb2DSpaces
56 //purpose  : 
57 //=======================================================================
58
59 Standard_Integer GeomLib_MakeCurvefromApprox::Nb2DSpaces() const 
60 {
61   return myApprox.NumSubSpaces(2);
62 }
63
64
65 //=======================================================================
66 //function : Nb3DSpaces
67 //purpose  : 
68 //=======================================================================
69
70 Standard_Integer GeomLib_MakeCurvefromApprox::Nb3DSpaces() const 
71 {
72   return myApprox.NumSubSpaces(3);
73 }
74
75
76 //=======================================================================
77 //function : Curve2d
78 //purpose  : 
79 //=======================================================================
80
81 Handle(Geom2d_BSplineCurve) GeomLib_MakeCurvefromApprox::Curve2d
82 (const Standard_Integer Index2d) const 
83 {
84   Standard_OutOfRange_Raise_if
85     ( Index2d < 0 || Index2d > Nb2DSpaces(),
86      " GeomLib_MakeCurvefromApprox : Curve2d");
87   StdFail_NotDone_Raise_if
88     ( !IsDone(),
89      " GeomLib_MakeCurvefromApprox : Curve2d");
90
91   TColgp_Array1OfPnt2d    Poles( 1, myApprox.NbPoles());
92   TColStd_Array1OfReal    Knots( 1, myApprox.NbKnots());
93   TColStd_Array1OfInteger Mults( 1, myApprox.NbKnots());
94   
95   myApprox.Poles2d(Index2d, Poles);
96   Knots = myApprox.Knots()->Array1();
97   Mults = myApprox.Multiplicities()->Array1();
98   
99   Handle(Geom2d_BSplineCurve) C = 
100     new Geom2d_BSplineCurve( Poles, Knots, Mults, myApprox.Degree());
101
102   return C;
103 }
104
105
106 //=======================================================================
107 //function : Curve2d
108 //purpose  : 
109 //=======================================================================
110
111 Handle(Geom2d_BSplineCurve) GeomLib_MakeCurvefromApprox::Curve2d
112 (const Standard_Integer Index1d,
113  const Standard_Integer Index2d) const 
114 {
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");
122
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());
127   
128   myApprox.Poles2d(Index2d, Poles);
129   myApprox.Poles1d(Index1d, Weigths);
130   Knots = myApprox.Knots()->Array1();
131   Mults = myApprox.Multiplicities()->Array1();
132   
133   Standard_Real X,Y,W;
134   for ( Standard_Integer i = 1; i <= myApprox.NbPoles(); i++) {
135     W = Weigths(i);
136     Poles(i).Coord(X,Y);
137     Poles(i).SetCoord(X/W, Y/W);
138   }
139
140   Handle(Geom2d_BSplineCurve) C = 
141     new Geom2d_BSplineCurve( Poles, Knots, Mults, myApprox.Degree());
142
143   return C;
144 }
145 //=======================================================================
146 //function : Curve2dFromTwo1d
147 //purpose  : 
148 //=======================================================================
149
150 Handle(Geom2d_BSplineCurve) GeomLib_MakeCurvefromApprox::Curve2dFromTwo1d
151 (const Standard_Integer Index1d,
152  const Standard_Integer Index2d) const 
153 {
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");
161
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());
167   
168   myApprox.Poles1d(Index2d, Poles1d2);
169   myApprox.Poles1d(Index1d, Poles1d1);
170  
171   Knots = myApprox.Knots()->Array1();
172   Mults = myApprox.Multiplicities()->Array1();
173   
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));
177   }
178
179   Handle(Geom2d_BSplineCurve) C = 
180     new Geom2d_BSplineCurve( Poles, Knots, Mults, myApprox.Degree());
181
182   return C;
183 }
184
185
186
187 //=======================================================================
188 //function : Curve
189 //purpose  : 
190 //=======================================================================
191
192 Handle(Geom_BSplineCurve) GeomLib_MakeCurvefromApprox::Curve
193 (const Standard_Integer Index3d) const 
194 {
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");
201
202   TColgp_Array1OfPnt      Poles( 1, myApprox.NbPoles());
203   TColStd_Array1OfReal    Knots( 1, myApprox.NbKnots());
204   TColStd_Array1OfInteger Mults( 1, myApprox.NbKnots());
205   
206   myApprox.Poles(Index3d, Poles);
207   Knots = myApprox.Knots()->Array1();
208   Mults = myApprox.Multiplicities()->Array1();
209   
210   Handle(Geom_BSplineCurve) C = 
211     new Geom_BSplineCurve( Poles, Knots, Mults, myApprox.Degree());
212
213   return C;
214 }
215
216
217 //=======================================================================
218 //function : Curve
219 //purpose  : 
220 //=======================================================================
221
222 Handle(Geom_BSplineCurve) GeomLib_MakeCurvefromApprox::Curve
223 (const Standard_Integer Index1d,
224  const Standard_Integer Index3d) const 
225 {
226   Standard_OutOfRange_Raise_if
227     ( Index1d < 0 || Index1d > Nb1DSpaces() ||
228       Index3d < 0 || Index3d > Nb3DSpaces(),
229      " GeomLib_MakeCurvefromApprox : Curve3d");
230   StdFail_NotDone_Raise_if
231     ( !IsDone(),
232      " GeomLib_MakeCurvefromApprox : Curve3d");
233
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());
238   
239   myApprox.Poles  (Index3d, Poles);
240   myApprox.Poles1d(Index1d, Weigths);
241   Knots = myApprox.Knots()->Array1();
242   Mults = myApprox.Multiplicities()->Array1();
243   
244   Standard_Real X,Y,Z,W;
245   for ( Standard_Integer i = 1; i <= myApprox.NbPoles(); i++) {
246     W = Weigths(i);
247     Poles(i).Coord(X,Y,Z);
248     Poles(i).SetCoord(X/W, Y/W, Z/W);
249   }
250
251   Handle(Geom_BSplineCurve) C = 
252     new Geom_BSplineCurve( Poles, Knots, Mults, myApprox.Degree());
253
254   return C;
255 }