//=========================================================================== // 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 _SPLINECURVE_H 00016 #define _SPLINECURVE_H 00017 00018 00019 #include "GoTools/utils/DirectionCone.h" 00020 #include "GoTools/geometry/ParamCurve.h" 00021 #include "GoTools/geometry/BsplineBasis.h" 00022 #include "GoTools/utils/config.h" 00023 00024 namespace Go 00025 { 00026 00027 class Interpolator; 00028 00031 class GO_API SplineCurve : public ParamCurve 00032 { 00033 public: 00034 00037 SplineCurve() : dim_(-1), rational_(false) { } 00038 00054 template <typename RandomIterator1, typename RandomIterator2> 00055 SplineCurve(int number, 00056 int order, 00057 RandomIterator1 knotstart, 00058 RandomIterator2 coefsstart, 00059 int dim, 00060 bool rational = false) 00061 : dim_(dim), rational_(rational), 00062 basis_(number, order, knotstart) 00063 { 00064 if (rational) { 00065 rcoefs_.resize((dim+1)*number); 00066 std::copy(coefsstart, coefsstart+(dim+1)*number, 00067 rcoefs_.begin()); 00068 coefs_.resize(dim*number); 00069 updateCoefsFromRcoefs(); 00070 } else { 00071 coefs_.resize(dim*number); 00072 std::copy(coefsstart, coefsstart + dim*number, 00073 coefs_.begin()); 00074 } 00075 } 00076 00084 SplineCurve(const Point& pnt1, const Point& pnt2); 00085 00094 SplineCurve(const Point& pnt1, double startpar, 00095 const Point& pnt2, double endpar); 00096 00098 virtual ~SplineCurve(); 00099 00100 // Inherited from Streamable 00101 virtual void read (std::istream& is); 00102 00103 // Inherited from Streamable 00104 virtual void write (std::ostream& os) const; 00105 00106 // Inherited from GeomObject 00107 virtual BoundingBox boundingBox() const; 00108 00109 // Inherited from GeomObject 00110 virtual int dimension() const; 00111 00112 // Inherited from GeomObject 00113 virtual ClassType instanceType() const; 00114 00115 // Inherited from GeomObject 00116 static ClassType classType() 00117 { return Class_SplineCurve; } 00118 // Inherited from GeomObject 00119 // #if ((_MSC_VER > 0) && (_MSC_VER < 1300)) 00120 // virtual GeomObject* clone() const 00121 // { return new SplineCurve(*this); } 00122 // #else 00123 virtual SplineCurve* clone() const 00124 { return new SplineCurve(*this); } 00125 // #endif 00126 00127 // Inherited from ParamCurve 00128 virtual void point(Point& pt, double tpar) const; 00129 00130 // Inherited from ParamCurve 00131 virtual void point(std::vector<Point>& pts, 00132 double tpar, 00133 int derivs, 00134 bool from_right = true) const; 00135 00136 // Inherited from ParamCurve 00137 virtual double startparam() const; 00138 00139 // Inherited from ParamCurve 00140 virtual double endparam() const; 00141 00142 // Inherited from ParamCurve 00143 virtual void reverseParameterDirection(bool switchparam = false); 00144 00145 // Inherited from ParamCurve 00146 virtual SplineCurve* geometryCurve(); 00147 00148 // Inherited from ParamCurve 00149 virtual DirectionCone directionCone() const; 00150 00151 // Inherited from ParamCurve 00152 virtual CompositeBox compositeBox() const; 00153 00154 // Inherited from ParamCurve 00155 virtual bool isDegenerate(double degenerate_epsilon); 00156 00163 00164 SplineCurve* derivCurve(int ider) const; 00165 00166 // Inherited from ParamCurve 00167 #if ((_MSC_VER > 0) && (_MSC_VER < 1300)) 00168 virtual ParamCurve* subCurve(double from_par, double to_par, 00169 double fuzzy 00170 = DEFAULT_PARAMETER_EPSILON) const; 00171 #else 00172 virtual SplineCurve* subCurve(double from_par, double to_par, 00173 double fuzzy 00174 = DEFAULT_PARAMETER_EPSILON) const; 00175 #endif 00176 00177 // Split curve in specified parameter values 00178 std::vector<boost::shared_ptr<SplineCurve> > 00179 split(std::vector<double>& param, 00180 double fuzzy = DEFAULT_PARAMETER_EPSILON) const; 00181 00182 // Inherited from ParamCurve 00183 virtual void closestPoint(const Point& pt, 00184 double tmin, 00185 double tmax, 00186 double& clo_t, 00187 Point& clo_pt, 00188 double& clo_dist, 00189 double const *seed = 0) const; 00190 00193 virtual double length(double tol); 00194 00217 virtual void appendCurve(ParamCurve* other_curve, 00218 int continuity, 00219 double& dist, 00220 bool repar=true); 00221 00231 virtual void appendCurve(ParamCurve* cv, bool repar=true); 00232 00235 const BsplineBasis& basis() const 00236 { return basis_; } 00237 00240 BsplineBasis& basis() 00241 { return basis_; } 00242 00245 int numCoefs() const 00246 { return basis_.numCoefs(); } 00247 00250 int order() const 00251 { return basis_.order(); } 00252 00255 bool rational() const 00256 { return rational_; } 00257 00260 std::vector<double>::iterator knotsBegin() 00261 { return basis_.begin(); } 00264 std::vector<double>::iterator knotsEnd() 00265 { return basis_.end(); } 00268 std::vector<double>::const_iterator knotsBegin() const 00269 { return basis_.begin(); } 00272 std::vector<double>::const_iterator knotsEnd() const 00273 { return basis_.end(); } 00274 00275 00280 std::vector<double>::iterator coefs_begin() 00281 { return coefs_.begin(); } 00286 std::vector<double>::iterator coefs_end() 00287 { return coefs_.end(); } 00292 std::vector<double>::const_iterator coefs_begin() const 00293 { return coefs_.begin(); } 00298 std::vector<double>::const_iterator coefs_end() const 00299 { return coefs_.end(); } 00304 std::vector<double>::iterator rcoefs_begin() 00305 { return rcoefs_.begin(); } 00310 std::vector<double>::iterator rcoefs_end() 00311 { return rcoefs_.end(); } 00316 std::vector<double>::const_iterator rcoefs_begin() const 00317 { return rcoefs_.begin(); } 00322 std::vector<double>::const_iterator rcoefs_end() const 00323 { return rcoefs_.end(); } 00324 00337 void interpolate(Interpolator& interpolator, 00338 int num_points, 00339 int dim, 00340 const double* param_start, 00341 const double* data_start); 00342 00345 void insertKnot(double apar); 00346 00350 void insertKnot(const std::vector<double>& new_knots); 00351 00354 void makeBernsteinKnots(); 00355 00360 virtual void setParameterInterval(double t1, double t2); 00361 00364 void removeKnot(double tpar); 00365 00369 void raiseOrder(int i = 1); 00370 00373 void makeKnotStartRegular(); 00374 00377 void makeKnotEndRegular(); 00378 00381 void swap(SplineCurve& other); 00382 00385 void equalBdWeights(bool at_start); 00386 00388 void representAsRational(); 00389 00391 void setBdWeight(double wgt, bool at_start); 00392 00401 virtual double nextSegmentVal(double par, bool forward, 00402 double tol) const; 00403 00404 void replaceEndPoint(Point pnt, bool at_start); 00405 00406 private: 00407 // Canonical data 00408 int dim_; 00409 bool rational_; 00410 BsplineBasis basis_; 00411 std::vector<double> coefs_; 00412 std::vector<double> rcoefs_; 00413 00414 00415 // Helper functions 00416 void updateCoefsFromRcoefs(); 00427 void appendSelfPeriodic(); 00428 00429 }; 00430 00431 00432 } // namespace Go 00433 00434 00435 00436 #endif // _SPLINECURVE_H 00437