//=========================================================================== // 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. //=========================================================================== 00016 #ifndef _BSPLINEBASIS_H 00017 #define _BSPLINEBASIS_H 00018 00019 #include <vector> 00020 #include "GoTools/utils/Values.h" 00021 #include "GoTools/geometry/Streamable.h" 00022 #include "GoTools/utils/config.h" 00023 00024 #ifdef NDEBUG 00025 #define CHECK(object) 00026 #else 00027 #define CHECK(object) (object)->check() 00028 #endif 00029 00030 namespace Go 00031 { 00032 00038 class GO_API BsplineBasis : public Streamable 00039 { 00040 public: 00042 BsplineBasis() 00043 : num_coefs_(0), order_(0), last_knot_interval_(0) 00044 { 00045 } 00046 00053 template <typename RandomIterator> 00054 BsplineBasis(int number, 00055 int order, 00056 RandomIterator knotstart) 00057 : num_coefs_(number), order_(order), 00058 knots_(knotstart, knotstart + number + order), 00059 last_knot_interval_(order - 1) 00060 { 00061 check(); 00062 } 00063 00070 template <typename RandomIterator> 00071 BsplineBasis(int order, 00072 RandomIterator knotstart, 00073 RandomIterator knotend) 00074 : num_coefs_(knotend - knotstart - order), order_(order), 00075 knots_(knotstart, knotend), 00076 last_knot_interval_(order - 1) 00077 { 00078 check(); 00079 } 00080 00082 virtual ~BsplineBasis(); 00083 00084 00089 template <typename RandomIterator> 00090 void setData(int number, int order, RandomIterator knotstart) 00091 { 00092 num_coefs_ = number; 00093 order_ = order; 00094 knots_.clear(); 00095 knots_.insert(knots_.end(), knotstart, knotstart + number + order); 00096 last_knot_interval_ = order - 1; 00097 } 00098 00101 void swap(BsplineBasis& other); 00102 00105 virtual void read(std::istream& is); 00106 00109 virtual void write(std::ostream& os) const; 00110 00113 virtual void read_bin(std::istream& is); 00114 00117 virtual void write_bin(std::ostream& os) const; 00118 00121 int knotInterval(double t) const; 00122 00132 std::vector<double> computeBasisValues(double t, int derivs=0) const; 00133 00145 void computeBasisValues(double t, 00146 double* basisvals_start, 00147 int derivs = 0, 00148 double resolution=1.0e-12) const; 00149 00175 void computeBasisValues(const double* parvals_start, 00176 const double* parvals_end, 00177 double* basisvals_start, 00178 int* knotinter_start, 00179 int derivs = 0) const; 00180 00184 std::vector<double> computeBasisValuesLeft(double tval, int derivs ) const; 00185 00193 void computeBasisValuesLeft(double tval, 00194 double* basisvals_start, 00195 int derivs, 00196 double resolution=1.0e-12) const; 00197 00201 void computeBasisValuesLeft(const double* parvals_start, 00202 const double* parvals_end, 00203 double* basisvals_start, 00204 int* knotinter_start, 00205 int derivs) const; 00206 00209 void reverseParameterDirection(); 00210 00214 void rescale (double new_start, double new_end); 00215 00218 void insertKnot(double apar); 00219 00225 int knotIntervalFuzzy(double& t, double tol = DEFAULT_PARAMETER_EPSILON) const; 00226 00229 void insertKnot(const std::vector<double>& new_knots); 00230 00235 void removeKnot(double old_knot); 00236 00239 inline int lastKnotInterval() const; 00240 00245 inline double grevilleParameter(int index) const; 00246 00251 int knotMultiplicity(const double parval) const; 00252 00257 int endMultiplicity(bool atstart) const; 00258 00261 void knotsSimple(std::vector<double>& result) const; 00262 00268 void cNDiscontinuities(std::vector<double>& cNDisconts, int depth) const; 00269 00273 bool isKreg() const 00274 { 00275 return (endMultiplicity(true) == order_ && 00276 endMultiplicity(false) == order_); 00277 } 00278 00284 void coefsAffectingParam(double tpar, int& first_coef, int& last_coef) const; 00285 00288 int numCoefs() const 00289 { return num_coefs_; } 00290 00293 int order() const 00294 { return order_; } 00295 00298 double startparam() const 00299 { return knots_[order_-1]; } 00300 00303 double endparam() const 00304 { return knots_[num_coefs_]; } 00305 00308 std::vector<double>::const_iterator begin() const 00309 { return knots_.begin(); } 00310 00313 std::vector<double>::const_iterator end() const 00314 { return knots_.end(); } 00315 00318 std::vector<double>::iterator begin() 00319 { return knots_.begin(); } 00322 std::vector<double>::iterator end() 00323 { return knots_.end(); } 00324 00326 void check() const; 00327 00329 bool isOK() const; 00330 00332 bool indistinctKnots(double tol, std::vector<double>& first_knotval) const; 00333 00335 bool sameSplineSpace(const BsplineBasis& other, 00336 double tol = DEFAULT_PARAMETER_EPSILON) const; 00337 00339 std::vector<double> 00340 missingKnots(const BsplineBasis& other, 00341 double tol = DEFAULT_PARAMETER_EPSILON) const; 00342 00343 // Return the basis for the subspace. 00344 BsplineBasis subBasis(double tmin, double tmax, double knot_diff_tol = 1e-05) const; 00345 00346 private: 00347 // Data members 00348 int num_coefs_; 00349 int order_; 00350 std::vector<double> knots_; 00351 mutable int last_knot_interval_; 00352 00353 00354 }; 00355 00356 00357 inline int BsplineBasis::lastKnotInterval() const 00358 { 00359 return last_knot_interval_; 00360 } 00361 00362 00363 inline double BsplineBasis::grevilleParameter(int index) const 00364 { 00365 double greville = 0.0; 00366 for (int i = 1; i < order(); ++i) 00367 greville += knots_[index+i]; 00368 00369 return greville/(order() - 1.0); 00370 } 00371 00372 00373 } // namespace Go 00374 00375 00376 #endif // This is what is 'ended': #ifndef _BSPLINEBASIS_H