0022627: Change OCCT memory management defaults
[occt.git] / src / GeomLib / GeomLib_Interpolate.cxx
CommitLineData
7fd59977 1// File: GeomLib_Interpolate.cxx
2// Created: Fri Aug 30 18:03:15 1996
3// Author: Xavier BENVENISTE
4// <xab@zozox.paris1.matra-dtv.fr>
5
6
7#include <GeomLib_Interpolate.ixx>
8
9#include <Standard_ConstructionError.hxx>
10#include <PLib.hxx>
11#include <BSplCLib.hxx>
12#include <gp_Vec.hxx>
13#include <TColgp_Array1OfPnt.hxx>
14#include <TColgp_Array1OfVec.hxx>
15#include <TColStd_HArray1OfReal.hxx>
16#include <TColStd_Array1OfBoolean.hxx>
17#include <TColStd_Array1OfInteger.hxx>
18#include <Handle_TColStd_HArray1OfBoolean.hxx>
19
20//=======================================================================
21//function : GeomLib_Interpolate
22//purpose :
23//=======================================================================
24
25GeomLib_Interpolate::GeomLib_Interpolate
26(const Standard_Integer Degree,
27 const Standard_Integer NumPoints,
28 const TColgp_Array1OfPnt& PointsArray,
29 const TColStd_Array1OfReal& ParametersArray)
30
31{
32 Standard_Integer ii,
33 num_knots,
34 inversion_problem,
35 num_controls,
36 jj ;
37
38
39 if (NumPoints < Degree ||
40 PointsArray.Lower() != 1 ||
41 PointsArray.Upper() < NumPoints ||
42 ParametersArray.Lower() != 1 ||
43 ParametersArray.Upper() < NumPoints) {
44 myError = GeomLib_NotEnoughtPoints ;
45 }
46 else if (Degree < 3) {
47 myError = GeomLib_DegreeSmallerThan3 ;
48 }
49 else {
50 gp_Pnt null_point(0.0e0, 0.0e0, 0.0e0) ;
51 Standard_Integer order = Degree + 1,
52 half_order ;
53 if (order % 2) {
54 order -= 1 ;
55 }
56 half_order = order / 2 ;
57 num_knots = NumPoints + 2 * order - 2 ;
58 num_controls = num_knots - order ;
59 TColStd_Array1OfReal flat_knots(1,num_knots) ;
60 TColStd_Array1OfInteger contacts (1,num_controls) ;
61 TColStd_Array1OfInteger multiplicities(1, NumPoints) ;
62 TColStd_Array1OfReal parameters(1,num_controls) ;
63 TColgp_Array1OfPnt poles(1,num_controls) ;
64
65 for (ii = 1 ; ii <= NumPoints ; ii++) {
66 multiplicities(ii) = 1 ;
67 }
68 multiplicities(1) = order ;
69 multiplicities(NumPoints) = order ;
70 for (ii = 1,
71 jj = num_controls + 1 ; ii <= order ; ii++, jj++) {
72
73 flat_knots(ii) = ParametersArray(1) ;
74 flat_knots(jj) = ParametersArray(NumPoints) ;
75 }
76 jj = order + 1 ;
77 for (ii = 2 ; ii < NumPoints ; ii++) {
78 flat_knots(jj) = ParametersArray(ii) ;
79 jj+= 1 ;
80 }
81 for (ii = 1 ; ii <= num_controls ; ii++) {
82 contacts(ii) = 0 ;
83 }
84 jj = num_controls ;
85 for (ii = 1 ; ii <= half_order ; ii++) {
86 contacts(ii) = half_order + ii - 1 ;
87 parameters(ii) = ParametersArray(1) ;
88 poles(ii) = null_point ;
89 contacts(jj) = half_order + ii - 1 ;
90 parameters(jj) = ParametersArray(NumPoints) ;
91 poles(jj) = null_point ;
92 jj -= 1 ;
93 }
94 jj = half_order + 1 ;
95 for (ii = 2 ; ii < NumPoints ; ii++) {
96 parameters(jj) = ParametersArray(ii) ;
97 poles(jj) = PointsArray(ii) ;
98 jj += 1 ;
99 }
100 contacts(1) = 0 ;
101 contacts(num_controls) = 0 ;
102 poles(1) = PointsArray(1) ;
103 poles(num_controls) = PointsArray(NumPoints) ;
104 BSplCLib::Interpolate(order-1,
105 flat_knots,
106 parameters,
107 contacts,
108 poles,
109 inversion_problem) ;
110
111 if (!inversion_problem) {
112 myCurve =
113 new Geom_BSplineCurve(poles,
114 ParametersArray,
115 multiplicities,
116 order-1) ;
117 myIsDone = Standard_True ;
118 }
119 else {
120 myError = GeomLib_InversionProblem ;
121 }
122 }
123}
124
125
126
127//=======================================================================
128//function : Curve
129//purpose :
130//=======================================================================
131
132Handle(Geom_BSplineCurve) GeomLib_Interpolate::Curve() const
133{
134 return myCurve ;
135}
136