b311480e |
1 | // Created on: 1996-08-30 |
2 | // Created by: Xavier BENVENISTE |
3 | // Copyright (c) 1996-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
17 | #include <GeomLib_Interpolate.ixx> |
18 | |
19 | #include <Standard_ConstructionError.hxx> |
20 | #include <PLib.hxx> |
21 | #include <BSplCLib.hxx> |
22 | #include <gp_Vec.hxx> |
23 | #include <TColgp_Array1OfPnt.hxx> |
24 | #include <TColgp_Array1OfVec.hxx> |
25 | #include <TColStd_HArray1OfReal.hxx> |
26 | #include <TColStd_Array1OfBoolean.hxx> |
27 | #include <TColStd_Array1OfInteger.hxx> |
cb389a77 |
28 | #include <TColStd_HArray1OfBoolean.hxx> |
7fd59977 |
29 | |
30 | //======================================================================= |
31 | //function : GeomLib_Interpolate |
32 | //purpose : |
33 | //======================================================================= |
34 | |
35 | GeomLib_Interpolate::GeomLib_Interpolate |
36 | (const Standard_Integer Degree, |
37 | const Standard_Integer NumPoints, |
38 | const TColgp_Array1OfPnt& PointsArray, |
39 | const TColStd_Array1OfReal& ParametersArray) |
40 | |
41 | { |
42 | Standard_Integer ii, |
43 | num_knots, |
44 | inversion_problem, |
45 | num_controls, |
46 | jj ; |
47 | |
48 | |
49 | if (NumPoints < Degree || |
50 | PointsArray.Lower() != 1 || |
51 | PointsArray.Upper() < NumPoints || |
52 | ParametersArray.Lower() != 1 || |
53 | ParametersArray.Upper() < NumPoints) { |
54 | myError = GeomLib_NotEnoughtPoints ; |
55 | } |
56 | else if (Degree < 3) { |
57 | myError = GeomLib_DegreeSmallerThan3 ; |
58 | } |
59 | else { |
60 | gp_Pnt null_point(0.0e0, 0.0e0, 0.0e0) ; |
61 | Standard_Integer order = Degree + 1, |
62 | half_order ; |
63 | if (order % 2) { |
64 | order -= 1 ; |
65 | } |
66 | half_order = order / 2 ; |
67 | num_knots = NumPoints + 2 * order - 2 ; |
68 | num_controls = num_knots - order ; |
69 | TColStd_Array1OfReal flat_knots(1,num_knots) ; |
70 | TColStd_Array1OfInteger contacts (1,num_controls) ; |
71 | TColStd_Array1OfInteger multiplicities(1, NumPoints) ; |
72 | TColStd_Array1OfReal parameters(1,num_controls) ; |
73 | TColgp_Array1OfPnt poles(1,num_controls) ; |
74 | |
75 | for (ii = 1 ; ii <= NumPoints ; ii++) { |
76 | multiplicities(ii) = 1 ; |
77 | } |
78 | multiplicities(1) = order ; |
79 | multiplicities(NumPoints) = order ; |
80 | for (ii = 1, |
81 | jj = num_controls + 1 ; ii <= order ; ii++, jj++) { |
82 | |
83 | flat_knots(ii) = ParametersArray(1) ; |
84 | flat_knots(jj) = ParametersArray(NumPoints) ; |
85 | } |
86 | jj = order + 1 ; |
87 | for (ii = 2 ; ii < NumPoints ; ii++) { |
88 | flat_knots(jj) = ParametersArray(ii) ; |
89 | jj+= 1 ; |
90 | } |
91 | for (ii = 1 ; ii <= num_controls ; ii++) { |
92 | contacts(ii) = 0 ; |
93 | } |
94 | jj = num_controls ; |
95 | for (ii = 1 ; ii <= half_order ; ii++) { |
96 | contacts(ii) = half_order + ii - 1 ; |
97 | parameters(ii) = ParametersArray(1) ; |
98 | poles(ii) = null_point ; |
99 | contacts(jj) = half_order + ii - 1 ; |
100 | parameters(jj) = ParametersArray(NumPoints) ; |
101 | poles(jj) = null_point ; |
102 | jj -= 1 ; |
103 | } |
104 | jj = half_order + 1 ; |
105 | for (ii = 2 ; ii < NumPoints ; ii++) { |
106 | parameters(jj) = ParametersArray(ii) ; |
107 | poles(jj) = PointsArray(ii) ; |
108 | jj += 1 ; |
109 | } |
110 | contacts(1) = 0 ; |
111 | contacts(num_controls) = 0 ; |
112 | poles(1) = PointsArray(1) ; |
113 | poles(num_controls) = PointsArray(NumPoints) ; |
114 | BSplCLib::Interpolate(order-1, |
115 | flat_knots, |
116 | parameters, |
117 | contacts, |
118 | poles, |
119 | inversion_problem) ; |
120 | |
121 | if (!inversion_problem) { |
122 | myCurve = |
123 | new Geom_BSplineCurve(poles, |
124 | ParametersArray, |
125 | multiplicities, |
126 | order-1) ; |
127 | myIsDone = Standard_True ; |
128 | } |
129 | else { |
130 | myError = GeomLib_InversionProblem ; |
131 | } |
132 | } |
133 | } |
134 | |
135 | |
136 | |
137 | //======================================================================= |
138 | //function : Curve |
139 | //purpose : |
140 | //======================================================================= |
141 | |
142 | Handle(Geom_BSplineCurve) GeomLib_Interpolate::Curve() const |
143 | { |
144 | return myCurve ; |
145 | } |
146 | |