Geom::Bezier Class Reference

#include <bezier.h>

List of all members.


Classes

struct  Order

Public Types

typedef Coord output_type

Public Member Functions

unsigned int order () const
unsigned int size () const
 Bezier ()
 Bezier (const Bezier &b)
Bezieroperator= (Bezier const &other)
 Bezier (Order ord)
 Bezier (Coord c0)
 Bezier (Coord c0, Coord c1)
 Bezier (Coord c0, Coord c1, Coord c2)
 Bezier (Coord c0, Coord c1, Coord c2, Coord c3)
void resize (unsigned int n, Coord v=0)
void clear ()
unsigned degree () const
bool isZero () const
bool isConstant () const
bool isFinite () const
Coord at0 () const
Coord at1 () const
Coord valueAt (double t) const
Coord operator() (double t) const
SBasis toSBasis () const
Coordoperator[] (unsigned ix)
Coord const & operator[] (unsigned ix) const
void setPoint (unsigned ix, double val)
std::vector< CoordvalueAndDerivatives (Coord t, unsigned n_derivs) const
std::pair< Bezier, Beziersubdivide (Coord t) const
std::vector< doubleroots () const

Protected Member Functions

 Bezier (Coord const c[], unsigned ord)

Private Attributes

std::valarray< Coordc_

Friends

Bezier portion (const Bezier &a, Coord from, Coord to)
OptInterval bounds_fast (Bezier const &b)
Bezier derivative (const Bezier &a)

Detailed Description

Definition at line 101 of file bezier.h.


Member Typedef Documentation

Definition at line 174 of file bezier.h.


Constructor & Destructor Documentation

Geom::Bezier::Bezier ( Coord const   c[],
unsigned  ord 
) [inline, protected]

Definition at line 112 of file bezier.h.

00112                                           : c_(c, ord+1){
00113         //std::copy(c, c+order()+1, &c_[0]);
00114     }

Geom::Bezier::Bezier (  )  [inline]

Definition at line 120 of file bezier.h.

00120 {}

Geom::Bezier::Bezier ( const Bezier b  )  [inline]

Definition at line 121 of file bezier.h.

00121 :c_(b.c_) {}

Geom::Bezier::Bezier ( Order  ord  )  [inline]

Definition at line 138 of file bezier.h.

References order(), and Geom::Bezier::Order::order.

00138                       : c_(0., ord.order+1) {
00139         assert(ord.order ==  order());
00140     }

Geom::Bezier::Bezier ( Coord  c0  )  [inline, explicit]

Definition at line 142 of file bezier.h.

References c_.

00142                               : c_(0., 1) {
00143         c_[0] = c0;
00144     }

Geom::Bezier::Bezier ( Coord  c0,
Coord  c1 
) [inline]

Definition at line 147 of file bezier.h.

References c_.

00147                                : c_(0., 2) {
00148         c_[0] = c0; c_[1] = c1;
00149     }

Geom::Bezier::Bezier ( Coord  c0,
Coord  c1,
Coord  c2 
) [inline]

Definition at line 152 of file bezier.h.

References c_.

00152                                          : c_(0., 3) {
00153         c_[0] = c0; c_[1] = c1; c_[2] = c2;
00154     }

Geom::Bezier::Bezier ( Coord  c0,
Coord  c1,
Coord  c2,
Coord  c3 
) [inline]

Definition at line 157 of file bezier.h.

References c_.

00157                                                    : c_(0., 4) {
00158         c_[0] = c0; c_[1] = c1; c_[2] = c2; c_[3] = c3;
00159     }


Member Function Documentation

Coord Geom::Bezier::at0 (  )  const [inline]

Definition at line 193 of file bezier.h.

References c_.

00193 { return c_[0]; }

Coord Geom::Bezier::at1 (  )  const [inline]

Definition at line 194 of file bezier.h.

References c_, and order().

00194 { return c_[order()]; }

void Geom::Bezier::clear (  )  [inline]

Definition at line 166 of file bezier.h.

References c_.

Referenced by Geom::sbasis_to_bezier().

00167     {
00168         c_.resize(0);
00169     }

unsigned Geom::Bezier::degree (  )  const [inline]

Definition at line 171 of file bezier.h.

References order().

00171 { return order(); }

bool Geom::Bezier::isConstant (  )  const [inline]

Definition at line 181 of file bezier.h.

References c_, Barcode::Code39Ext::i, and order().

00181                                    {
00182         for(unsigned i = 1; i <= order(); i++) {
00183             if(c_[i] != c_[0]) return false;
00184         }
00185         return true;
00186     }

bool Geom::Bezier::isFinite (  )  const [inline]

Definition at line 187 of file bezier.h.

References c_, Barcode::Code39Ext::i, IS_FINITE, and order().

00187                                  {
00188         for(unsigned i = 0; i <= order(); i++) {
00189             if(!IS_FINITE(c_[i])) return false;
00190         }
00191         return true;
00192     }

bool Geom::Bezier::isZero (  )  const [inline]

Definition at line 175 of file bezier.h.

References c_, Barcode::Code39Ext::i, and order().

00175                                {
00176         for(unsigned i = 0; i <= order(); i++) {
00177             if(c_[i] != 0) return false;
00178         }
00179         return true;
00180     }

Coord Geom::Bezier::operator() ( double  t  )  const [inline]

Definition at line 212 of file bezier.h.

References valueAt().

00212 { return valueAt(t); }

Bezier& Geom::Bezier::operator= ( Bezier const &  other  )  [inline]

Definition at line 122 of file bezier.h.

References c_.

00122                                            {
00123         if ( c_.size() != other.c_.size() ) {
00124             c_.resize(other.c_.size());
00125         }
00126         c_ = other.c_;
00127         return *this;
00128     }

Coord const& Geom::Bezier::operator[] ( unsigned  ix  )  const [inline]

Definition at line 224 of file bezier.h.

References c_.

00224 { return const_cast<std::valarray<Coord>&>(c_)[ix]; }

Coord& Geom::Bezier::operator[] ( unsigned  ix  )  [inline]

Definition at line 223 of file bezier.h.

References c_.

00223 { return c_[ix]; }

unsigned int Geom::Bezier::order (  )  const [inline]

void Geom::Bezier::resize ( unsigned int  n,
Coord  v = 0 
) [inline]

Definition at line 161 of file bezier.h.

References c_.

Referenced by Geom::sbasis_to_bezier().

00162     {
00163         c_.resize (n, v);
00164     }

std::vector<double> Geom::Bezier::roots (  )  const [inline]

Definition at line 255 of file bezier.h.

References c_, Geom::find_bernstein_roots(), and order().

Referenced by Geom::roots().

00255                                     {
00256         std::vector<double> solutions;
00257         find_bernstein_roots(&const_cast<std::valarray<Coord>&>(c_)[0], order(), solutions, 0, 0.0, 1.0);
00258         return solutions;
00259     }

void Geom::Bezier::setPoint ( unsigned  ix,
double  val 
) [inline]

Definition at line 226 of file bezier.h.

References c_.

00226 { c_[ix] = val; }

unsigned int Geom::Bezier::size (  )  const [inline]

Definition at line 118 of file bezier.h.

References c_.

Referenced by Geom::bounds_fast(), Geom::NL::LFMBezier::instance(), Geom::operator<<(), Geom::sbasis_to_bezier(), and valueAndDerivatives().

00118 { return c_.size();}

std::pair<Bezier, Bezier > Geom::Bezier::subdivide ( Coord  t  )  const [inline]

Definition at line 249 of file bezier.h.

References org::w3c::dom::svg::a, b, c_, order(), and Geom::subdivideArr().

00249                                                       {
00250         Bezier a(Bezier::Order(*this)), b(Bezier::Order(*this));
00251         subdivideArr(t, &const_cast<std::valarray<Coord>&>(c_)[0], &a.c_[0], &b.c_[0], order());
00252         return std::pair<Bezier, Bezier >(a, b);
00253     }

SBasis Geom::Bezier::toSBasis (  )  const [inline]

Definition at line 267 of file bezier.h.

References Geom::bezier_to_sbasis().

Referenced by Geom::bounds_exact().

00267                               {
00268     SBasis sb;
00269     bezier_to_sbasis(sb, (*this));
00270     return sb;
00271     //return bezier_to_sbasis(&c_[0], order());
00272 }

std::vector<Coord> Geom::Bezier::valueAndDerivatives ( Coord  t,
unsigned  n_derivs 
) const [inline]

Definition at line 231 of file bezier.h.

References c_, Barcode::Code39Ext::i, NULL, order(), size(), and Geom::subdivideArr().

00231                                                                            {
00232         std::vector<Coord> val_n_der;
00233         std::valarray<Coord> d_(order()+1);
00234         unsigned nn = n_derivs + 1;     // the size of the result vector equals n_derivs+1 ...
00235         if(nn > order())
00236             nn = order()+1;     // .. but with a maximum of order() + 1!
00237         for(unsigned i = 0; i < size(); i++)
00238             d_[i] = c_[i];
00239         for(unsigned di = 0; di < nn; di++) {
00240             val_n_der.push_back(subdivideArr(t, &d_[0], NULL, NULL, order() - di));
00241             for(unsigned i = 0; i < order() - di; i++) {
00242                 d_[i] = (order()-di)*(d_[i+1] - d_[i]);
00243             }
00244         }
00245         val_n_der.resize(n_derivs);
00246         return val_n_der;
00247     }

Coord Geom::Bezier::valueAt ( double  t  )  const [inline]

Definition at line 196 of file bezier.h.

References c_, Barcode::Code39Ext::i, n, and order().

Referenced by operator()().

00196                                          {
00197         int n = order();
00198         double u, bc, tn, tmp;
00199         int i;
00200         u = 1.0 - t;
00201         bc = 1;
00202         tn = 1;
00203         tmp = c_[0]*u;
00204         for(i=1; i<n; i++){
00205             tn = tn*t;
00206             bc = bc*(n-i+1)/i;
00207             tmp = (tmp + tn*bc*c_[i])*u;
00208         }
00209         return (tmp + tn*t*c_[n]);
00210         //return subdivideArr(t, &c_[0], NULL, NULL, order());
00211     }


Friends And Related Function Documentation

OptInterval bounds_fast ( Bezier const &  b  )  [friend]

Definition at line 357 of file bezier.h.

00357                                                  {
00358     return Interval::fromArray(&const_cast<Bezier&>(b).c_[0], b.size());
00359 }

Bezier derivative ( const Bezier a  )  [friend]

Definition at line 336 of file bezier.h.

00336                                            {
00337     //if(a.order() == 1) return Bezier(0.0);
00338     if(a.order() == 1) return Bezier(a.c_[1]-a.c_[0]);
00339     Bezier der(Bezier::Order(a.order()-1));
00340 
00341     for(unsigned i = 0; i < a.order(); i++) {
00342         der.c_[i] = a.order()*(a.c_[i+1] - a.c_[i]);
00343     }
00344     return der;
00345 }

Bezier portion ( const Bezier a,
Coord  from,
Coord  to 
) [friend]

Definition at line 310 of file bezier.h.

00310                                                                 {
00311     //TODO: implement better?
00312     std::valarray<Coord> res(a.order() + 1);
00313     if(from == 0) {
00314         if(to == 1) { return Bezier(a); }
00315         subdivideArr(to, &const_cast<Bezier&>(a).c_[0], &res[0], NULL, a.order());
00316         return Bezier(&res[0], a.order());
00317     }
00318     subdivideArr(from, &const_cast<Bezier&>(a).c_[0], NULL, &res[0], a.order());
00319     if(to == 1) return Bezier(&res[0], a.order());
00320     std::valarray<Coord> res2(a.order()+1);
00321     subdivideArr((to - from)/(1 - from), &res[0], &res2[0], NULL, a.order());
00322     return Bezier(&res2[0], a.order());
00323 }


Member Data Documentation


The documentation for this class was generated from the following file: