00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef HxSampledBSplineCurve_h
00012 #define HxSampledBSplineCurve_h
00013
00014 #include "HxBSplineCurve.h"
00015 #include "HxSampledBSplineInterval.h"
00016 #include "HxIoFwd.h"
00017
00018
00022 enum HxBSplineSamplingAlg
00023 {
00024 samplingResolution,
00025 samplingInterval
00026 };
00027
00028
00031 class HxSampledBSplineCurve {
00032 public:
00034 HxSampledBSplineCurve();
00035
00039 HxSampledBSplineCurve(
00040 const HxBSplineCurve& curve, int nSamples,
00041 HxBSplineSamplingAlg algorithm =samplingResolution);
00042
00046 HxSampledBSplineCurve(
00047 const HxBSplineCurve& curve,
00048 double pathInterval,
00049 HxBSplineSamplingAlg algorithm);
00050
00052 static HxSampledBSplineCurve makeUniform(HxPolyline2d cp, int degree,
00053 double distance);
00054
00056 static HxSampledBSplineCurve makeInterpolating(HxPolyline2d cp, double distance);
00057
00059 ~HxSampledBSplineCurve();
00060
00061
00063 int ident() const;
00064
00066 HxBSplineCurve continuousCurve() const;
00067
00069 HxBSplineType curveType() const;
00070
00072 HxBSplineSamplingAlg samplingAlg() const;
00073
00075 int nSamples() const;
00076
00078 double sampledT(int j) const;
00079
00081 vector<double> allSampledT() const;
00082
00086 int indexOfT(double t) const;
00087
00091 double dT(int j) const;
00092
00096 HxSampledBSplineInterval sampledInterval(int j1, int j2) const;
00097
00101 vector<int> samplesAffectedBy(int i) const;
00102
00106 HxSampledBSplineInterval intervalAffectedBy(int i) const;
00107
00111 vector<int> PThatAffectSample(int i) const;
00112
00114 double B(int i, int j) const;
00115
00117 vector<double> BAll(int j) const;
00118
00120 double dB(int order, int i, int j) const;
00121
00125 vector<double> dBAll(int order, int j) const;
00126
00128 HxPointR2 C(int j) const;
00129
00131 HxPointSetR2 AllC() const;
00132
00134 HxPolyline2d CPoly() const;
00135
00137 HxVectorR2 dC(int order, int j) const;
00138
00140 vector<HxVectorR2> dCAll(int order) const;
00141
00143 double kAtC(int j) const;
00144
00146 vector<double> kAtCAll() const;
00147
00149 double dTurnAngleAtC(int j) const;
00150
00152 vector<double> dTurnAngleAtCAll() const;
00153
00155 double length() const;
00156
00158 double length(int j1, int j2) const;
00159
00161 double length(const HxSampledBSplineInterval& interval) const;
00162
00166 int closestSample(const HxPointR2& p) const;
00167
00168
00169
00170
00171
00173 int numP() const;
00174
00176 HxPointSetR2 allP() const;
00177
00179 HxPolyline2d controlP() const;
00180
00182 HxSampledBSplineCurve changeAllP(const HxPointSetR2& p) const;
00183
00189 HxSampledBSplineCurve translateCurve(const HxVectorR2& v,
00190 const HxSampledBSplineInterval& interval) const;
00191
00193 STD_OSTREAM& dump(STD_OSTREAM&) const;
00194
00195 private:
00196 HxBSplineCurve _curve;
00197 HxBSplineSamplingAlg _samplingAlg;
00198 vector<double> _t;
00199 double _dt;
00200 int _ident;
00201
00202 static int _nr;
00203
00204 void makeDefault();
00205 void message( charPtr msg=0 ) const;
00206 void sampleWithResolution( int n );
00207 void sampleWithInterval( double interval );
00208 };
00209
00210
00211 inline STD_OSTREAM&
00212 operator<<(STD_OSTREAM& os, const HxSampledBSplineCurve& b)
00213 {
00214 return b.dump(os);
00215 }
00216
00217 inline int
00218 HxSampledBSplineCurve::ident() const
00219 {
00220 return _ident;
00221 }
00222
00223 inline HxBSplineCurve
00224 HxSampledBSplineCurve::continuousCurve() const
00225 {
00226 return _curve;
00227 }
00228
00229 inline HxBSplineType
00230 HxSampledBSplineCurve::curveType() const
00231 {
00232 return _curve.curveType();
00233 }
00234
00235 inline int
00236 HxSampledBSplineCurve::numP() const
00237 {
00238 return _curve.numP();
00239 }
00240
00241 inline HxPointSetR2
00242 HxSampledBSplineCurve::allP() const
00243 {
00244 return _curve.allP();
00245 }
00246
00247 inline HxPolyline2d
00248 HxSampledBSplineCurve::controlP() const
00249 {
00250 return HxPolyline2d(allP(), (curveType() == closed));
00251 }
00252
00253 inline HxBSplineSamplingAlg
00254 HxSampledBSplineCurve::samplingAlg() const
00255 {
00256 return _samplingAlg;
00257 }
00258
00259 inline int
00260 HxSampledBSplineCurve::nSamples() const
00261 {
00262 return _t.size();
00263 }
00264
00265 inline vector<double>
00266 HxSampledBSplineCurve::allSampledT() const
00267 {
00268 return _t;
00269 }
00270
00271 inline vector<int>
00272 HxSampledBSplineCurve::PThatAffectSample (int i) const
00273 {
00274 return _curve.PThatAffectCAt(_t[i]);
00275 }
00276
00277 inline HxSampledBSplineCurve
00278 HxSampledBSplineCurve::changeAllP(const HxPointSetR2& p) const
00279 {
00280 HxSampledBSplineCurve tmp = *this;
00281 tmp._curve = _curve.changeAllP(p);
00282 return tmp;
00283 }
00284
00285 inline double
00286 HxSampledBSplineCurve::B(int i, int j) const
00287 {
00288 if ( j < 0 || j >= nSamples() ) {
00289 message("(B) invalid j - setting to 0");
00290 j = 0;
00291 }
00292 return _curve.B( i, _t[j]);
00293 }
00294
00295 inline double
00296 HxSampledBSplineCurve::dT(int j) const
00297 {
00298 if ( j < 0 || j >= nSamples() ) {
00299 message("(dT) invalid j - setting to 0");
00300 j = 0;
00301 }
00302 return _dt;
00303 }
00304
00305 inline double
00306 HxSampledBSplineCurve::dB(int order, int i, int j) const
00307 {
00308 if ( j < 0 || j >= nSamples() ) {
00309 message("(B) invalid j - setting to 0");
00310 j = 0;
00311 }
00312 return _curve.dB( order, i, _t[j]);
00313 }
00314
00315 inline HxPointR2
00316 HxSampledBSplineCurve::C(int j) const
00317 {
00318 if ( j < 0 || j >= nSamples() ) {
00319 message("(C) invalid j - setting to 0");
00320 j = 0;
00321 }
00322 return _curve.C(_t[j]);
00323 }
00324
00325 inline HxPolyline2d
00326 HxSampledBSplineCurve::CPoly() const
00327 {
00328 return HxPolyline2d(AllC(), (curveType() == closed));
00329 }
00330
00331 inline HxVectorR2
00332 HxSampledBSplineCurve::dC(int order, int j) const
00333 {
00334 if ( j < 0 || j >= nSamples() ) {
00335 message("(C) invalid j - setting to 0");
00336 j = 0;
00337 }
00338 return _curve.dC(order, _t[j]);
00339 }
00340
00341 inline double
00342 HxSampledBSplineCurve::kAtC(int j) const
00343 {
00344 if ( j < 0 || j >= nSamples() ) {
00345 message("(kAtC) invalid j - setting to 0");
00346 j = 0;
00347 }
00348 return _curve.kAtC(_t[j]);
00349 }
00350
00351 inline double
00352 HxSampledBSplineCurve::dTurnAngleAtC(int j) const
00353 {
00354 if ( j < 0 || j >= nSamples() ) {
00355 message("(dTurnAngleAtC) invalid j - setting to 0");
00356 j = 0;
00357 }
00358 return _curve.dTurnAngleAtC(_t[j]);
00359 }
00360
00361 inline double
00362 HxSampledBSplineCurve::length() const
00363 {
00364 return _curve.length(nSamples());
00365 }
00366
00367 inline double
00368 HxSampledBSplineCurve::length(int j1, int j2) const
00369 {
00370 return length( HxSampledBSplineInterval(j1, j2,
00371 nSamples(), curveType()) );
00372 }
00373
00374 inline HxString
00375 makeString(const HxSampledBSplineCurve& i)
00376 {
00377 return HxString("HxSampledBSplineCurve") + makeString(i.ident());
00378 }
00379
00380 #endif