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
 The size of the returned vector equals n_derivs+1.
std::pair< Bezier, Beziersubdivide (Coord t) const
std::vector< doubleroots () const
std::vector< doubleroots (Interval const ivl) 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 112 of file bezier.h.


Member Typedef Documentation

Definition at line 185 of file bezier.h.


Constructor & Destructor Documentation

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

Definition at line 123 of file bezier.h.

00123                                           : c_(c, ord+1){
00124         //std::copy(c, c+order()+1, &c_[0]);
00125     }

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

Definition at line 131 of file bezier.h.

00131 {}

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

Definition at line 132 of file bezier.h.

00132 :c_(b.c_) {}

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

Definition at line 149 of file bezier.h.

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

00149                       : c_(0., ord.order+1) {
00150         assert(ord.order ==  order());
00151     }

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

Definition at line 153 of file bezier.h.

References c_.

00153                               : c_(0., 1) {
00154         c_[0] = c0;
00155     }

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

Definition at line 158 of file bezier.h.

References c_.

00158                                : c_(0., 2) {
00159         c_[0] = c0; c_[1] = c1;
00160     }

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

Definition at line 163 of file bezier.h.

References c_.

00163                                          : c_(0., 3) {
00164         c_[0] = c0; c_[1] = c1; c_[2] = c2;
00165     }

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

Definition at line 168 of file bezier.h.

References c_.

00168                                                    : c_(0., 4) {
00169         c_[0] = c0; c_[1] = c1; c_[2] = c2; c_[3] = c3;
00170     }


Member Function Documentation

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

Definition at line 204 of file bezier.h.

References c_.

00204 { return c_[0]; }

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

Definition at line 205 of file bezier.h.

References c_, and order().

00205 { return c_[order()]; }

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

Definition at line 177 of file bezier.h.

References c_.

00178     {
00179         c_.resize(0);
00180     }

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

Definition at line 182 of file bezier.h.

References order().

00182 { return order(); }

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

Definition at line 192 of file bezier.h.

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

00192                                    {
00193         for(unsigned i = 1; i <= order(); i++) {
00194             if(c_[i] != c_[0]) return false;
00195         }
00196         return true;
00197     }

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

Definition at line 198 of file bezier.h.

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

00198                                  {
00199         for(unsigned i = 0; i <= order(); i++) {
00200             if(!IS_FINITE(c_[i])) return false;
00201         }
00202         return true;
00203     }

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

Definition at line 186 of file bezier.h.

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

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

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

Definition at line 223 of file bezier.h.

References valueAt().

00223 { return valueAt(t); }

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

Definition at line 133 of file bezier.h.

References c_.

00133                                            {
00134         if ( c_.size() != other.c_.size() ) {
00135             c_.resize(other.c_.size());
00136         }
00137         c_ = other.c_;
00138         return *this;
00139     }

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

Definition at line 235 of file bezier.h.

References c_.

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

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

Definition at line 234 of file bezier.h.

References c_.

00234 { return c_[ix]; }

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

Definition at line 172 of file bezier.h.

References c_.

00173     {
00174         c_.resize (n, v);
00175     }

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

Definition at line 281 of file bezier.h.

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

00281                                                       {
00282         std::vector<double> solutions;
00283         find_bernstein_roots(&const_cast<std::valarray<Coord>&>(c_)[0], order(), solutions, 0, ivl[0], ivl[1]);
00284         return solutions;
00285     }

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

Definition at line 276 of file bezier.h.

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

00276                                     {
00277         std::vector<double> solutions;
00278         find_bernstein_roots(&const_cast<std::valarray<Coord>&>(c_)[0], order(), solutions, 0, 0.0, 1.0);
00279         return solutions;
00280     }

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

Definition at line 237 of file bezier.h.

References c_.

00237 { c_[ix] = val; }

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

Definition at line 129 of file bezier.h.

References c_.

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

00129 { return c_.size();}

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

Definition at line 270 of file bezier.h.

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

00270                                                       {
00271         Bezier a(Bezier::Order(*this)), b(Bezier::Order(*this));
00272         subdivideArr(t, &const_cast<std::valarray<Coord>&>(c_)[0], &a.c_[0], &b.c_[0], order());
00273         return std::pair<Bezier, Bezier >(a, b);
00274     }

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

Definition at line 293 of file bezier.h.

References Geom::bezier_to_sbasis().

Referenced by Geom::bounds_exact().

00293                               {
00294     SBasis sb;
00295     bezier_to_sbasis(sb, (*this));
00296     return sb;
00297     //return bezier_to_sbasis(&c_[0], order());
00298 }

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

The size of the returned vector equals n_derivs+1.

Definition at line 242 of file bezier.h.

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

00242                                                                            {
00243         /* This is inelegant, as it uses several extra stores.  I think there might be a way to
00244          * evaluate roughly in situ. */
00245 
00246          // initialize return vector with zeroes, such that we only need to replace the non-zero derivs
00247         std::vector<Coord> val_n_der(n_derivs + 1, Coord(0.0));
00248 
00249         // initialize temp storage variables
00250         std::valarray<Coord> d_(order()+1);
00251         for (unsigned i = 0; i < size(); i++) {
00252             d_[i] = c_[i];
00253         }
00254 
00255         unsigned nn = n_derivs + 1;
00256         if(n_derivs > order()) {
00257             nn = order()+1; // only calculate the non zero derivs
00258         }
00259         for (unsigned di = 0; di < nn; di++) {
00260             //val_n_der[di] = (subdivideArr(t, &d_[0], NULL, NULL, order() - di));
00261             val_n_der[di] = bernsteinValueAt(t, &d_[0], order() - di);
00262             for (unsigned i = 0; i < order() - di; i++) {
00263                 d_[i] = (order()-di)*(d_[i+1] - d_[i]);
00264             }
00265         }
00266 
00267         return val_n_der;
00268     }

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

Definition at line 207 of file bezier.h.

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

Referenced by operator()().

00207                                          {
00208         int n = order();
00209         double u, bc, tn, tmp;
00210         int i;
00211         u = 1.0 - t;
00212         bc = 1;
00213         tn = 1;
00214         tmp = c_[0]*u;
00215         for(i=1; i<n; i++){
00216             tn = tn*t;
00217             bc = bc*(n-i+1)/i;
00218             tmp = (tmp + tn*bc*c_[i])*u;
00219         }
00220         return (tmp + tn*t*c_[n]);
00221         //return subdivideArr(t, &c_[0], NULL, NULL, order());
00222     }


Friends And Related Function Documentation

OptInterval bounds_fast ( Bezier const &  b  )  [friend]

Definition at line 383 of file bezier.h.

00383                                                  {
00384     return Interval::fromArray(&const_cast<Bezier&>(b).c_[0], b.size());
00385 }

Bezier derivative ( const Bezier a  )  [friend]

Definition at line 362 of file bezier.h.

00362                                            {
00363     //if(a.order() == 1) return Bezier(0.0);
00364     if(a.order() == 1) return Bezier(a.c_[1]-a.c_[0]);
00365     Bezier der(Bezier::Order(a.order()-1));
00366 
00367     for(unsigned i = 0; i < a.order(); i++) {
00368         der.c_[i] = a.order()*(a.c_[i+1] - a.c_[i]);
00369     }
00370     return der;
00371 }

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

Definition at line 336 of file bezier.h.

00336                                                                 {
00337     //TODO: implement better?
00338     std::valarray<Coord> res(a.order() + 1);
00339     if(from == 0) {
00340         if(to == 1) { return Bezier(a); }
00341         subdivideArr(to, &const_cast<Bezier&>(a).c_[0], &res[0], NULL, a.order());
00342         return Bezier(&res[0], a.order());
00343     }
00344     subdivideArr(from, &const_cast<Bezier&>(a).c_[0], NULL, &res[0], a.order());
00345     if(to == 1) return Bezier(&res[0], a.order());
00346     std::valarray<Coord> res2(a.order()+1);
00347     subdivideArr((to - from)/(1 - from), &res[0], &res2[0], NULL, a.order());
00348     return Bezier(&res2[0], a.order());
00349 }


Member Data Documentation


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