//=========================================================================== // GoTools Core - SINTEF Geometry Tools Core library, version 2.0.1 // // Copyright (C) 2000-2007, 2010 SINTEF ICT, Applied Mathematics, Norway. // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation version 2 of the License. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., // 59 Temple Place - Suite 330, // Boston, MA 02111-1307, USA. // // Contact information: E-mail: tor.dokken@sintef.no // SINTEF ICT, Department of Applied Mathematics, // P.O. Box 124 Blindern, // 0314 Oslo, Norway. // // Other licenses are also available for this software, notably licenses // for: // - Building commercial software. // - Building software whose source code you wish to keep private. //=========================================================================== 00015 #ifndef _SPLINEINTERPOLATOR_H 00016 #define _SPLINEINTERPOLATOR_H 00017 00018 00019 #include "GoTools/geometry/Interpolator.h" 00020 #include "GoTools/geometry/BsplineBasis.h" 00021 #include "GoTools/utils/Point.h" 00022 #include <boost/smart_ptr.hpp> 00023 00024 00025 namespace Go 00026 { 00027 00031 class GO_API SplineInterpolator : public Interpolator 00032 { 00033 public: 00035 SplineInterpolator() 00036 : ctype_(None), basis_set_(false) 00037 { 00038 } 00039 00041 virtual ~SplineInterpolator(); 00042 00043 // inherited from Interpolator 00044 virtual const BsplineBasis& basis(); 00045 00068 void interpolate(const std::vector<double>& params, 00069 const std::vector<double>& points, 00070 const std::vector<int>& tangent_index, 00071 const std::vector<double>& tangent_points, 00072 int order, 00073 std::vector<double>& coefs); 00074 00082 void interpolate(const std::vector<double>& params, 00083 const std::vector<double>& points, 00084 const std::vector<int>& tangent_index, 00085 const std::vector<double>& tangent_points, 00086 std::vector<double>& coefs); 00087 00095 virtual void interpolate(int num_points, int dimension, 00096 const double* param_start, 00097 const double* data_start, 00098 std::vector<double>& coefs); 00099 00116 enum CondType { None, Hermite, Natural, Free, NaturalAtStart, NaturalAtEnd }; 00117 00123 void setHermiteConditions(const Point& start_tangent, 00124 const Point& end_tangent) { 00125 ctype_ = Hermite; 00126 start_tangent_ = boost::shared_ptr<Point>(new Point(start_tangent)); 00127 end_tangent_ = boost::shared_ptr<Point>(new Point(end_tangent)); 00128 } 00129 00133 void setNaturalConditions() { ctype_ = Natural; } 00134 00140 void setNaturalStartCondition() { ctype_ = NaturalAtStart;} 00141 00147 void setNaturalEndCondition() { ctype_ = NaturalAtEnd; } 00148 00152 void setFreeConditions() { ctype_ = Free; } 00153 00159 void setEndTangents(boost::shared_ptr<Point>& start_tangent, 00160 boost::shared_ptr<Point>& end_tangent) 00161 { 00162 start_tangent_ = start_tangent; 00163 end_tangent_ = end_tangent; 00164 if (start_tangent.get() != 0 && end_tangent.get() != 0) 00165 ctype_ = Hermite; 00166 else if (start_tangent.get() != 0) 00167 ctype_ = NaturalAtEnd; 00168 else if (end_tangent.get() != 0) 00169 ctype_ = NaturalAtStart; 00170 else 00171 ctype_ = Natural; 00172 } 00173 00176 CondType getCondType() {return ctype_; } 00177 00185 void makeBasis(const std::vector<double>& params, 00186 const std::vector<int>& tangent_index, 00187 int order); 00188 00191 00196 void setBasis(BsplineBasis& basis) { 00197 basis_ = basis; 00198 basis_set_ = true; 00199 } 00200 00201 private: 00202 CondType ctype_; 00203 boost::shared_ptr<Point> start_tangent_; 00204 boost::shared_ptr<Point> end_tangent_; 00205 BsplineBasis basis_; 00206 bool basis_set_; 00207 }; 00208 00209 00210 00211 } // namespace Go 00212 00213 00214 #endif // _SPLINEINTERPOLATOR_H 00215