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