00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef _GOSPLINECURVE_H
00034 #define _GOSPLINECURVE_H
00035
00036
00037 #include "DirectionCone.h"
00038 #include "ParamCurve.h"
00039 #include "BsplineBasis.h"
00040
00041
00042 namespace Go
00043 {
00046
00047
00048 class Interpolator;
00049
00052 class SplineCurve : public ParamCurve
00053 {
00054 public:
00055
00058 SplineCurve() : dim_(-1), rational_(false) { }
00059
00075 template <typename RandomIterator1, typename RandomIterator2>
00076 SplineCurve(int number,
00077 int order,
00078 RandomIterator1 knotstart,
00079 RandomIterator2 coefsstart,
00080 int dim,
00081 bool rational = false)
00082 : dim_(dim), rational_(rational),
00083 basis_(number, order, knotstart)
00084 {
00085 if (rational) {
00086 rcoefs_.resize((dim+1)*number);
00087 std::copy(coefsstart, coefsstart+(dim+1)*number,
00088 rcoefs_.begin());
00089 coefs_.resize(dim*number);
00090 updateCoefsFromRcoefs();
00091 } else {
00092 coefs_.resize(dim*number);
00093 std::copy(coefsstart, coefsstart + dim*number,
00094 coefs_.begin());
00095 }
00096 }
00097
00105 SplineCurve(const Point& pnt1, const Point& pnt2);
00106
00115 SplineCurve(const Point& pnt1, double startpar,
00116 const Point& pnt2, double endpar);
00117
00119 virtual ~SplineCurve();
00120
00121
00122 virtual void read (std::istream& is);
00123
00124
00125 virtual void write (std::ostream& os) const;
00126
00127
00128 virtual BoundingBox boundingBox() const;
00129
00130
00131 virtual int dimension() const;
00132
00133
00134 virtual ClassType instanceType() const;
00135
00136
00137 static ClassType classType()
00138 { return Class_SplineCurve; }
00139
00140
00141
00142
00143
00144 virtual SplineCurve* clone() const
00145 { return new SplineCurve(*this); }
00146
00147
00148
00149 virtual void point(Point& pt, double tpar) const;
00150
00151
00152 virtual void point(std::vector<Point>& pts,
00153 double tpar,
00154 int derivs,
00155 bool from_right = true) const;
00156
00157
00158 virtual double startparam() const;
00159
00160
00161 virtual double endparam() const;
00162
00163
00164 virtual void reverseParameterDirection(bool switchparam = false);
00165
00166
00167 virtual SplineCurve* geometryCurve();
00168
00169
00170 virtual DirectionCone directionCone() const;
00171
00172
00173 virtual CompositeBox compositeBox() const;
00174
00175
00176 virtual bool isDegenerate(double degenerate_epsilon);
00177
00184
00185 SplineCurve* derivCurve(int ider) const;
00186
00187
00188 #if ((_MSC_VER > 0) && (_MSC_VER < 1300))
00189 virtual ParamCurve* subCurve(double from_par, double to_par,
00190 double fuzzy
00191 = DEFAULT_PARAMETER_EPSILON) const;
00192 #else
00193 virtual SplineCurve* subCurve(double from_par, double to_par,
00194 double fuzzy
00195 = DEFAULT_PARAMETER_EPSILON) const;
00196 #endif
00197
00198
00199 virtual void closestPoint(const Point& pt,
00200 double tmin,
00201 double tmax,
00202 double& clo_t,
00203 Point& clo_pt,
00204 double& clo_dist,
00205 double const *seed = 0) const;
00206
00229 virtual void appendCurve(ParamCurve* other_curve,
00230 int continuity,
00231 double& dist,
00232 bool repar=true);
00233
00243 virtual void appendCurve(ParamCurve* cv, bool repar=true);
00244
00247 const BsplineBasis& basis() const
00248 { return basis_; }
00249
00252 BsplineBasis& basis()
00253 { return basis_; }
00254
00257 int numCoefs() const
00258 { return basis_.numCoefs(); }
00259
00262 int order() const
00263 { return basis_.order(); }
00264
00267 bool rational() const
00268 { return rational_; }
00269
00272 std::vector<double>::iterator knotsBegin()
00273 { return basis_.begin(); }
00276 std::vector<double>::iterator knotsEnd()
00277 { return basis_.end(); }
00280 std::vector<double>::const_iterator knotsBegin() const
00281 { return basis_.begin(); }
00284 std::vector<double>::const_iterator knotsEnd() const
00285 { return basis_.end(); }
00286
00287
00292 std::vector<double>::iterator coefs_begin()
00293 { return coefs_.begin(); }
00298 std::vector<double>::iterator coefs_end()
00299 { return coefs_.end(); }
00304 std::vector<double>::const_iterator coefs_begin() const
00305 { return coefs_.begin(); }
00310 std::vector<double>::const_iterator coefs_end() const
00311 { return coefs_.end(); }
00316 std::vector<double>::iterator rcoefs_begin()
00317 { return rcoefs_.begin(); }
00322 std::vector<double>::iterator rcoefs_end()
00323 { return rcoefs_.end(); }
00328 std::vector<double>::const_iterator rcoefs_begin() const
00329 { return rcoefs_.begin(); }
00334 std::vector<double>::const_iterator rcoefs_end() const
00335 { return rcoefs_.end(); }
00336
00349 void interpolate(Interpolator& interpolator,
00350 int num_points,
00351 int dim,
00352 const double* param_start,
00353 const double* data_start);
00354
00357 void insertKnot(double apar);
00358
00362 void insertKnot(const std::vector<double>& new_knots);
00363
00366 void makeBernsteinKnots();
00367
00372 void setParameterInterval(double t1, double t2);
00373
00376 void removeKnot(double tpar);
00377
00381 void raiseOrder(int i = 1);
00382
00385 void makeKnotStartRegular();
00386
00389 void makeKnotEndRegular();
00390
00393 void swap(SplineCurve& other);
00394
00403 virtual double nextSegmentVal(double par, bool forward,
00404 double tol) const;
00405
00406
00407 private:
00408
00409 int dim_;
00410 bool rational_;
00411 BsplineBasis basis_;
00412 std::vector<double> coefs_;
00413 std::vector<double> rcoefs_;
00414
00415
00416
00417 void updateCoefsFromRcoefs();
00428 void appendSelfPeriodic();
00429
00430 };
00431
00432
00434 }
00435
00436
00437
00438 #endif // _GOSPLINECURVE_H
00439
00440