Horus Doc || C++ Reference || Class Overview   Pixels   Images   Detector   Geometry   Registry || Doxygen's quick Index  

HxSampledBSplineCurve Class Reference

Class definition for sampled BSpline curves. More...

#include <HxSampledBSplineCurve.h>

List of all members.

Public Methods

 HxSampledBSplineCurve ()
 Construct default curve. More...

 HxSampledBSplineCurve (const HxBSplineCurve &curve, int nSamples, HxBSplineSamplingAlg algorithm=samplingResolution)
 Construct a curve with given number of samples. More...

 HxSampledBSplineCurve (const HxBSplineCurve &curve, double pathInterval, HxBSplineSamplingAlg algorithm)
 Construct a curve with given path interval between samples. More...

 ~HxSampledBSplineCurve ()
 Destructor. More...

int ident () const
 Get the identifier. More...

HxBSplineCurve continuousCurve () const
 Get the continuous curve of this object. More...

HxBSplineType curveType () const
 Get the type of this curve. More...

HxBSplineSamplingAlg samplingAlg () const
 Get the sampling algorithm. More...

int nSamples () const
 Get the number of samples. More...

double sampledT (int j) const
 Get value of t for sample j. More...

vector< double > allSampledT () const
 Get value of t for all samples. More...

int indexOfT (double t) const
 Get index of sample corresponding to given t. More...

double dT (int j) const
 sampling interval at sample j . More...

HxSampledBSplineInterval sampledInterval (int j1, int j2) const
 Get curve interval defined by two curve samples j1, j2. More...

vector< int > samplesAffectedBy (int i) const
 Get list of curve samples affected by control point i. More...

HxSampledBSplineInterval intervalAffectedBy (int i) const
 Get curve interval affected by control point i. More...

vector< int > PThatAffectSample (int i) const
 Get all control points with influence on the position of curve sample i. More...

double B (int i, int j) const
 Get value of basis i for sample j. More...

vector< double > BAll (int j) const
 Get value of all basis that affect sample j. More...

double dB (int order, int i, int j) const
 Get derivative of basis i for sample j. More...

vector< double > dBAll (int order, int j) const
 Get derivative of all basis that affect sample j (given order). More...

HxPointR2 C (int j) const
 Get curve point for sample j. More...

HxPointSetR2 AllC () const
 Get all sampled curve points. More...

HxPolyline2d CPoly () const
 Polyline with all sampled curve points. More...

HxVectorR2 dC (int order, int j) const
 Get curve derivative at sample j. More...

vector< HxVectorR2dCAll (int order) const
 Get curve derivative at all samples. More...

double kAtC (int j) const
 Get curvature at sample j. More...

vector< double > kAtCAll () const
 Get curve derivative at all samples. More...

double dTurnAngleAtC (int j) const
 Derivative of turning angle at sample j. More...

vector< double > dTurnAngleAtCAll () const
 Derivative of turning angle at all samples. More...

double length () const
 total curve length. More...

double length (int j1, int j2) const
 length of interval between given samples. More...

double length (const HxSampledBSplineInterval &interval) const
 length of given interval. More...

int closestSample (const HxPointR2 &p) const
 Get index of sample that is closest to the given point. More...

int numP () const
 Get number of control points. More...

HxPointSetR2 allP () const
 Get all control points. More...

HxPolyline2d controlP () const
 Get the control polygon. More...

HxSampledBSplineCurve changeAllP (const HxPointSetR2 &p) const
 Replace all control points by given points. More...

HxSampledBSplineCurve translateCurve (const HxVectorR2 &v, const HxSampledBSplineInterval &interval) const
 Add vector to control points that affect the curve in the given interval. More...

STD_OSTREAM & dump (STD_OSTREAM &) const
 Dump the curve on the given stream. More...


Static Public Methods

HxSampledBSplineCurve makeUniform (HxPolyline2d cp, int degree, double distance)
 Make a curve with uniform knots. More...

HxSampledBSplineCurve makeInterpolating (HxPolyline2d cp, double distance)
 Make an interpolating curve. More...


Detailed Description

Class definition for sampled BSpline curves.


Constructor & Destructor Documentation

HxSampledBSplineCurve::HxSampledBSplineCurve  
 

Construct default curve.

00019 {
00020     _ident = _nr++;
00021     makeDefault();
00022 }

HxSampledBSplineCurve::HxSampledBSplineCurve const HxBSplineCurve   curve,
int    n,
HxBSplineSamplingAlg    algorithm = samplingResolution
 

Construct a curve with given number of samples.

00025                                            : _curve(curve)
00026 {
00027     _ident = _nr++;
00028     if ( algorithm != samplingResolution ) {
00029         message("(constructor) invalid parameters - using default");
00030         makeDefault();
00031     }
00032     else
00033         sampleWithResolution(n);
00034 }

HxSampledBSplineCurve::HxSampledBSplineCurve const HxBSplineCurve   curve,
double    delta,
HxBSplineSamplingAlg    algorithm
 

Construct a curve with given path interval between samples.

00037                                                   : _curve(curve)
00038 {
00039     _ident = _nr++;
00040     if ( algorithm != samplingInterval ||
00041         delta < 0 || delta > (_curve.maxT() -_curve.minT()) ) {
00042         message("(constructor) invalid sampling interval - using default");
00043         makeDefault();
00044     }
00045     else
00046         sampleWithInterval(delta);
00047 }

HxSampledBSplineCurve::~HxSampledBSplineCurve  
 

Destructor.

00073 {
00074 }


Member Function Documentation

HxSampledBSplineCurve HxSampledBSplineCurve::makeUniform HxPolyline2d    cp,
int    degree,
double    distance
[static]
 

Make a curve with uniform knots.

00052 {
00053     HxBSplineCurve cc = HxBSplineCurve::makeUniform(cp, degree);
00054     double l = cc.length();
00055     int n = int(l / distance);
00056     if (n < cc.numP())
00057         n = cc.numP();
00058     return HxSampledBSplineCurve(cc, n);
00059 }

HxSampledBSplineCurve HxSampledBSplineCurve::makeInterpolating HxPolyline2d    cp,
double    distance
[static]
 

Make an interpolating curve.

00063 {
00064     HxBSplineCurve cc = HxBSplineCurve::makeInterpolating(cp);
00065     double l = cc.length();
00066     int n = int(l / distance);
00067     if (n < cc.numP())
00068         n = cc.numP();
00069     return HxSampledBSplineCurve(cc, n);
00070 }

int HxSampledBSplineCurve::ident   const [inline]
 

Get the identifier.

00219 {
00220     return _ident; 
00221 }

HxBSplineCurve HxSampledBSplineCurve::continuousCurve   const [inline]
 

Get the continuous curve of this object.

00225 {
00226     return _curve;
00227 }

HxBSplineType HxSampledBSplineCurve::curveType   const [inline]
 

Get the type of this curve.

00231 {
00232     return _curve.curveType(); 
00233 }

HxBSplineSamplingAlg HxSampledBSplineCurve::samplingAlg   const [inline]
 

Get the sampling algorithm.

00255 {
00256     return _samplingAlg;
00257 }

int HxSampledBSplineCurve::nSamples   const [inline]
 

Get the number of samples.

00261 {
00262     return _t.size();
00263 }

double HxSampledBSplineCurve::sampledT int    j const
 

Get value of t for sample j.

00110 {
00111     if ( j < 0 || j >= nSamples() ) {
00112         message("(sampledT) invalid j - setting to 0");
00113         j = 0;
00114     }
00115     return _t[j];
00116 }

vector< double > HxSampledBSplineCurve::allSampledT   const [inline]
 

Get value of t for all samples.

00267 {
00268     return _t;
00269 }

int HxSampledBSplineCurve::indexOfT double    t const
 

Get index of sample corresponding to given t.

00083 {
00084     if ( t < _curve.minT() ) {
00085         message("(indexOfT) invalid t - setting to minT()");
00086         return 0;
00087     }
00088     if ( t >=  _curve.maxT() ) {
00089         message("(indexOfT) invalid t - setting near to maxT()");
00090         return nSamples()-1;
00091     }
00092     int last = _t.size()-1;
00093     int j;
00094     for ( j=0; j < last && t > _t[j]; j++ );
00095     if ( t == _t[j] )
00096         return j;
00097     else    {       // get closest
00098         double da = absolute(t - _t[j]);
00099         double db = absolute(t - _t[j-1]);
00100         return (da <= db) ? j : j-1;
00101     }
00102 }

double HxSampledBSplineCurve::dT int    j const [inline]
 

sampling interval at sample j .

fixed value -> only works for uniform sampling!

00297 {
00298     if ( j < 0 || j >= nSamples() ) {
00299         message("(dT) invalid j - setting to 0");
00300         j = 0;
00301     }
00302     return _dt; // only for uniform!
00303 }

HxSampledBSplineInterval HxSampledBSplineCurve::sampledInterval int    j1,
int    j2
const
 

Get curve interval defined by two curve samples j1, j2.

00124 {
00125     if ( j1 >= j2 && curveType() != closed ) {
00126         message("(sampledInterval) invalid interval - setting to complete curve]");
00127         j1 = 0;
00128         j2 = nSamples()-1;
00129     }
00130     return HxSampledBSplineInterval(j1,j2,
00131             nSamples()-1, curveType());
00132 }

vector< int > HxSampledBSplineCurve::samplesAffectedBy int    i const
 

Get list of curve samples affected by control point i.

00141 {
00142     HxBSplineInterval tmp = _curve.pathAffectedBy(i);
00143     vector<int> vec;
00144 
00145     for ( int j=0; j < nSamples(); j++ )
00146         if ( tmp.contains(_t[j]) )
00147             vec.push_back(j);
00148 
00149     return vec;
00150 }

HxSampledBSplineInterval HxSampledBSplineCurve::intervalAffectedBy int    j const
 

Get curve interval affected by control point i.

00158 {
00159     vector<int> tmp = samplesAffectedBy(j);
00160     int j1;
00161     int j2;
00162 
00163     if ( curveType() == closed ) {
00164                     // special treatment for wrapping
00165        for ( int i=0; i<tmp.size()-1; i++ )
00166         if ( (tmp[i+1] - tmp[i]) != 1 ) {
00167             j1 = tmp[i+1];
00168             j2 = tmp[i];
00169             return HxSampledBSplineInterval(j1,j2,
00170                 nSamples(), curveType());
00171         }
00172     }
00173     j1 = tmp[0];
00174     j2 = tmp[ tmp.size()-1 ];
00175     return HxSampledBSplineInterval(j1,j2,
00176         nSamples(), curveType());
00177 }

vector< int > HxSampledBSplineCurve::PThatAffectSample int    i const [inline]
 

Get all control points with influence on the position of curve sample i.

00273 {
00274     return _curve.PThatAffectCAt(_t[i]);
00275 }

double HxSampledBSplineCurve::B int    i,
int    j
const [inline]
 

Get value of basis i for sample j.

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 }

vector< double > HxSampledBSplineCurve::BAll int    i const
 

Get value of all basis that affect sample j.

00185 {
00186     vector<double> tmp(nSamples());
00187     for ( int j=0; j < nSamples(); j++)
00188         tmp[j] = _curve.B(i, _t[j]);
00189     return tmp;
00190 }

double HxSampledBSplineCurve::dB int    order,
int    i,
int    j
const [inline]
 

Get derivative of basis i for sample j.

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 }

vector< double > HxSampledBSplineCurve::dBAll int    order,
int    i
const
 

Get derivative of all basis that affect sample j (given order).

00199 {
00200     vector<double> tmp(nSamples());
00201     for ( int j=0; j < nSamples(); j++)
00202         tmp[j] = _curve.dB(order, i, _t[j]);
00203     return tmp;
00204 }

HxPointR2 HxSampledBSplineCurve::C int    j const [inline]
 

Get curve point for sample j.

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 }

HxPointSetR2 HxSampledBSplineCurve::AllC   const
 

Get all sampled curve points.

00212 {
00213     vector<HxPointR2> tmp(nSamples());
00214     for ( int j=0; j < nSamples(); j++)
00215         tmp[j] = _curve.C(_t[j]);
00216     return tmp;
00217 }

HxPolyline2d HxSampledBSplineCurve::CPoly   const [inline]
 

Polyline with all sampled curve points.

00327 {
00328     return HxPolyline2d(AllC(), (curveType() == closed));
00329 }

HxVectorR2 HxSampledBSplineCurve::dC int    order,
int    j
const [inline]
 

Get curve derivative at sample j.

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 }

vector< HxVectorR2 > HxSampledBSplineCurve::dCAll int    order const
 

Get curve derivative at all samples.

00225 {
00226     vector<HxVectorR2> tmp(nSamples());
00227     for ( int j=0; j < nSamples(); j++)
00228         tmp[j] = _curve.dC(order, _t[j]);
00229     return tmp;
00230 }

double HxSampledBSplineCurve::kAtC int    j const [inline]
 

Get curvature at sample j.

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 }

vector< double > HxSampledBSplineCurve::kAtCAll   const
 

Get curve derivative at all samples.

00238 {
00239     vector<double> tmp(nSamples());
00240     for ( int j=0; j < nSamples(); j++)
00241         tmp[j] = _curve.kAtC(_t[j]);
00242     return tmp;
00243 }

double HxSampledBSplineCurve::dTurnAngleAtC int    j const [inline]
 

Derivative of turning angle at sample j.

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 }

vector< double > HxSampledBSplineCurve::dTurnAngleAtCAll   const
 

Derivative of turning angle at all samples.

00252 {
00253     vector<double> tmp(nSamples());
00254     for ( int j=0; j < nSamples(); j++)
00255         tmp[j] = _curve.dTurnAngleAtC(_t[j]);
00256     return tmp;
00257 }

double HxSampledBSplineCurve::length   const [inline]
 

total curve length.

00363 {
00364     return _curve.length(nSamples());
00365 }

double HxSampledBSplineCurve::length int    j1,
int    j2
const [inline]
 

length of interval between given samples.

00369 {
00370     return length( HxSampledBSplineInterval(j1, j2, 
00371             nSamples(), curveType()) );
00372 }

double HxSampledBSplineCurve::length const HxSampledBSplineInterval   interval const
 

length of given interval.

00266 {
00267     HxBSplineInterval tmp(_t[interval.begin()], _t[interval.end()]+EPS,
00268         _curve.minT(), _curve.maxT(), curveType());
00269     
00270     return _curve.length(tmp, interval.size());
00271 }

int HxSampledBSplineCurve::closestSample const HxPointR2   p const
 

Get index of sample that is closest to the given point.

00280 {
00281     vector<HxPointR2> s = AllC();
00282     int iMin = 0;
00283     double dMin = HxVectorR2(p,s[iMin]).magnitude();
00284     for ( int i=1; i < s.size(); i++ ){
00285         HxVectorR2 v(p,s[i]);
00286         double d = v.magnitude();
00287         if ( d < dMin ) {
00288             dMin = d;
00289             iMin = i;
00290         }
00291     }
00292 
00293     return iMin;
00294 }

int HxSampledBSplineCurve::numP   const [inline]
 

Get number of control points.

00237 { 
00238     return _curve.numP();
00239 }

HxPointSetR2 HxSampledBSplineCurve::allP   const [inline]
 

Get all control points.

00243 {
00244     return _curve.allP();
00245 }

HxPolyline2d HxSampledBSplineCurve::controlP   const [inline]
 

Get the control polygon.

00249 {
00250     return HxPolyline2d(allP(), (curveType() == closed));
00251 }

HxSampledBSplineCurve HxSampledBSplineCurve::changeAllP const HxPointSetR2 &    p const [inline]
 

Replace all control points by given points.

00279 {
00280     HxSampledBSplineCurve tmp = *this;
00281     tmp._curve = _curve.changeAllP(p);
00282     return tmp;
00283 }

HxSampledBSplineCurve HxSampledBSplineCurve::translateCurve const HxVectorR2   translVec,
const HxSampledBSplineInterval   interval
const
 

Add vector to control points that affect the curve in the given interval.

This will translate a part of the curve in the given direction.

00305 {
00306     HxVectorR2 v = translVec;
00307     HxPointSetR2 P = _curve.allP();
00308     HxBSplineInterval tmp(sampledT(interval.begin()), sampledT(interval.end()), 
00309         _curve.minT(), _curve.maxT(), curveType());
00310     vector<int> index = _curve.PThatAffectCAt(tmp);
00311     for ( int i =0; i < index.size(); i++) {
00312         int j = index[i];
00313         P[j] =  P[j].add(v);
00314     }
00315 
00316     return changeAllP(P);
00317 }

STD_OSTREAM & HxSampledBSplineCurve::dump STD_OSTREAM &    os const
 

Dump the curve on the given stream.

00325 {
00326     _curve.dump(os);
00327 
00328     os << "Sampling Algorithm: " << samplingAlg();
00329 
00330     if ( _t.empty() ) {
00331         os << "\nNo Samples";
00332     } else {
00333         os << "\nT Vector: " << _t.size() << " samples\n";
00334         for ( int i = 0; i < _t.size(); i++ ) {
00335             os << _t[i] << ",";
00336         }
00337     }
00338 
00339     os << STD_ENDL;
00340     return os;
00341 }


The documentation for this class was generated from the following files:
Generated on Mon Jan 27 15:49:09 2003 for C++Reference by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001