0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[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
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
7fd59977 17
7fd59977 18#include <BSplCLib.hxx>
42cf5bc1 19#include <Geom_BSplineCurve.hxx>
20#include <GeomLib_Interpolate.hxx>
42cf5bc1 21#include <StdFail_NotDone.hxx>
7fd59977 22#include <TColgp_Array1OfPnt.hxx>
23#include <TColgp_Array1OfVec.hxx>
7fd59977 24#include <TColStd_Array1OfInteger.hxx>
7fd59977 25
26//=======================================================================
27//function : GeomLib_Interpolate
28//purpose :
29//=======================================================================
7fd59977 30GeomLib_Interpolate::GeomLib_Interpolate
31(const Standard_Integer Degree,
32 const Standard_Integer NumPoints,
33 const TColgp_Array1OfPnt& PointsArray,
34 const TColStd_Array1OfReal& ParametersArray)
d533dafb 35: myIsDone(Standard_False)
7fd59977 36{
37 Standard_Integer ii,
38 num_knots,
39 inversion_problem,
40 num_controls,
41 jj ;
42
43
44 if (NumPoints < Degree ||
45 PointsArray.Lower() != 1 ||
46 PointsArray.Upper() < NumPoints ||
47 ParametersArray.Lower() != 1 ||
48 ParametersArray.Upper() < NumPoints) {
49 myError = GeomLib_NotEnoughtPoints ;
50 }
51 else if (Degree < 3) {
52 myError = GeomLib_DegreeSmallerThan3 ;
53 }
54 else {
55 gp_Pnt null_point(0.0e0, 0.0e0, 0.0e0) ;
56 Standard_Integer order = Degree + 1,
57 half_order ;
58 if (order % 2) {
59 order -= 1 ;
60 }
61 half_order = order / 2 ;
62 num_knots = NumPoints + 2 * order - 2 ;
63 num_controls = num_knots - order ;
64 TColStd_Array1OfReal flat_knots(1,num_knots) ;
65 TColStd_Array1OfInteger contacts (1,num_controls) ;
66 TColStd_Array1OfInteger multiplicities(1, NumPoints) ;
67 TColStd_Array1OfReal parameters(1,num_controls) ;
68 TColgp_Array1OfPnt poles(1,num_controls) ;
69
70 for (ii = 1 ; ii <= NumPoints ; ii++) {
71 multiplicities(ii) = 1 ;
72 }
73 multiplicities(1) = order ;
74 multiplicities(NumPoints) = order ;
75 for (ii = 1,
76 jj = num_controls + 1 ; ii <= order ; ii++, jj++) {
77
78 flat_knots(ii) = ParametersArray(1) ;
79 flat_knots(jj) = ParametersArray(NumPoints) ;
80 }
81 jj = order + 1 ;
82 for (ii = 2 ; ii < NumPoints ; ii++) {
83 flat_knots(jj) = ParametersArray(ii) ;
84 jj+= 1 ;
85 }
86 for (ii = 1 ; ii <= num_controls ; ii++) {
87 contacts(ii) = 0 ;
88 }
89 jj = num_controls ;
90 for (ii = 1 ; ii <= half_order ; ii++) {
91 contacts(ii) = half_order + ii - 1 ;
92 parameters(ii) = ParametersArray(1) ;
93 poles(ii) = null_point ;
94 contacts(jj) = half_order + ii - 1 ;
95 parameters(jj) = ParametersArray(NumPoints) ;
96 poles(jj) = null_point ;
97 jj -= 1 ;
98 }
99 jj = half_order + 1 ;
100 for (ii = 2 ; ii < NumPoints ; ii++) {
101 parameters(jj) = ParametersArray(ii) ;
102 poles(jj) = PointsArray(ii) ;
103 jj += 1 ;
104 }
105 contacts(1) = 0 ;
106 contacts(num_controls) = 0 ;
107 poles(1) = PointsArray(1) ;
108 poles(num_controls) = PointsArray(NumPoints) ;
109 BSplCLib::Interpolate(order-1,
110 flat_knots,
111 parameters,
112 contacts,
113 poles,
114 inversion_problem) ;
115
116 if (!inversion_problem) {
117 myCurve =
118 new Geom_BSplineCurve(poles,
119 ParametersArray,
120 multiplicities,
121 order-1) ;
122 myIsDone = Standard_True ;
123 }
124 else {
125 myError = GeomLib_InversionProblem ;
126 }
127 }
128}
129
130
131
132//=======================================================================
133//function : Curve
134//purpose :
135//=======================================================================
136
137Handle(Geom_BSplineCurve) GeomLib_Interpolate::Curve() const
138{
139 return myCurve ;
140}
141