0024166: Unable to create file with "Save" menu of voxeldemo Qt sample
[occt.git] / src / GeomLib / GeomLib_Interpolate.cxx
CommitLineData
b311480e 1// Created on: 1996-08-30
2// Created by: Xavier BENVENISTE
3// Copyright (c) 1996-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21
22
23#include <GeomLib_Interpolate.ixx>
24
25#include <Standard_ConstructionError.hxx>
26#include <PLib.hxx>
27#include <BSplCLib.hxx>
28#include <gp_Vec.hxx>
29#include <TColgp_Array1OfPnt.hxx>
30#include <TColgp_Array1OfVec.hxx>
31#include <TColStd_HArray1OfReal.hxx>
32#include <TColStd_Array1OfBoolean.hxx>
33#include <TColStd_Array1OfInteger.hxx>
34#include <Handle_TColStd_HArray1OfBoolean.hxx>
35
36//=======================================================================
37//function : GeomLib_Interpolate
38//purpose :
39//=======================================================================
40
41GeomLib_Interpolate::GeomLib_Interpolate
42(const Standard_Integer Degree,
43 const Standard_Integer NumPoints,
44 const TColgp_Array1OfPnt& PointsArray,
45 const TColStd_Array1OfReal& ParametersArray)
46
47{
48 Standard_Integer ii,
49 num_knots,
50 inversion_problem,
51 num_controls,
52 jj ;
53
54
55 if (NumPoints < Degree ||
56 PointsArray.Lower() != 1 ||
57 PointsArray.Upper() < NumPoints ||
58 ParametersArray.Lower() != 1 ||
59 ParametersArray.Upper() < NumPoints) {
60 myError = GeomLib_NotEnoughtPoints ;
61 }
62 else if (Degree < 3) {
63 myError = GeomLib_DegreeSmallerThan3 ;
64 }
65 else {
66 gp_Pnt null_point(0.0e0, 0.0e0, 0.0e0) ;
67 Standard_Integer order = Degree + 1,
68 half_order ;
69 if (order % 2) {
70 order -= 1 ;
71 }
72 half_order = order / 2 ;
73 num_knots = NumPoints + 2 * order - 2 ;
74 num_controls = num_knots - order ;
75 TColStd_Array1OfReal flat_knots(1,num_knots) ;
76 TColStd_Array1OfInteger contacts (1,num_controls) ;
77 TColStd_Array1OfInteger multiplicities(1, NumPoints) ;
78 TColStd_Array1OfReal parameters(1,num_controls) ;
79 TColgp_Array1OfPnt poles(1,num_controls) ;
80
81 for (ii = 1 ; ii <= NumPoints ; ii++) {
82 multiplicities(ii) = 1 ;
83 }
84 multiplicities(1) = order ;
85 multiplicities(NumPoints) = order ;
86 for (ii = 1,
87 jj = num_controls + 1 ; ii <= order ; ii++, jj++) {
88
89 flat_knots(ii) = ParametersArray(1) ;
90 flat_knots(jj) = ParametersArray(NumPoints) ;
91 }
92 jj = order + 1 ;
93 for (ii = 2 ; ii < NumPoints ; ii++) {
94 flat_knots(jj) = ParametersArray(ii) ;
95 jj+= 1 ;
96 }
97 for (ii = 1 ; ii <= num_controls ; ii++) {
98 contacts(ii) = 0 ;
99 }
100 jj = num_controls ;
101 for (ii = 1 ; ii <= half_order ; ii++) {
102 contacts(ii) = half_order + ii - 1 ;
103 parameters(ii) = ParametersArray(1) ;
104 poles(ii) = null_point ;
105 contacts(jj) = half_order + ii - 1 ;
106 parameters(jj) = ParametersArray(NumPoints) ;
107 poles(jj) = null_point ;
108 jj -= 1 ;
109 }
110 jj = half_order + 1 ;
111 for (ii = 2 ; ii < NumPoints ; ii++) {
112 parameters(jj) = ParametersArray(ii) ;
113 poles(jj) = PointsArray(ii) ;
114 jj += 1 ;
115 }
116 contacts(1) = 0 ;
117 contacts(num_controls) = 0 ;
118 poles(1) = PointsArray(1) ;
119 poles(num_controls) = PointsArray(NumPoints) ;
120 BSplCLib::Interpolate(order-1,
121 flat_knots,
122 parameters,
123 contacts,
124 poles,
125 inversion_problem) ;
126
127 if (!inversion_problem) {
128 myCurve =
129 new Geom_BSplineCurve(poles,
130 ParametersArray,
131 multiplicities,
132 order-1) ;
133 myIsDone = Standard_True ;
134 }
135 else {
136 myError = GeomLib_InversionProblem ;
137 }
138 }
139}
140
141
142
143//=======================================================================
144//function : Curve
145//purpose :
146//=======================================================================
147
148Handle(Geom_BSplineCurve) GeomLib_Interpolate::Curve() const
149{
150 return myCurve ;
151}
152