Geom::SBasis Class Reference

#include <sbasis.h>

List of all members.

Public Types

typedef double output_type

Public Member Functions

size_t size () const
Linear operator[] (unsigned i) const
Linearoperator[] (unsigned i)
Linear const * begin () const
Linear const * end () const
Linearbegin ()
Linearend ()
bool empty () const
Linearback ()
Linear const & back () const
void pop_back ()
void resize (unsigned n)
void resize (unsigned n, Linear const &l)
void reserve (unsigned n)
void clear ()
void insert (Linear *before, const Linear *src_begin, const Linear *src_end)
Linearat (unsigned i)
bool operator== (SBasis const &B) const
bool operator!= (SBasis const &B) const
 operator std::vector< Linear > ()
 SBasis ()
 SBasis (double a)
 SBasis (double a, double b)
 SBasis (SBasis const &a)
 SBasis (Linear const &bo)
 SBasis (Linear *bo)
 SBasis (size_t n, Linear const &l)
bool isZero () const
bool isConstant () const
bool isFinite () const
 test all coefficients are finite
double at0 () const
double at1 () const
int degreesOfFreedom () const
double valueAt (double t) const
double operator() (double t) const
std::vector< doublevalueAndDerivatives (double t, unsigned n) const
 Compute the value and the first n derivatives.
SBasis toSBasis () const
double tailError (unsigned tail) const
 bound the error from term truncation
SBasis operator() (SBasis const &g) const
void normalize ()
void truncate (unsigned k)

Private Member Functions

void push_back (Linear const &l)
void derive ()
 Compute the derivative of this inplace (Exact).

Private Attributes

std::vector< Lineard

Detailed Description

Definition at line 67 of file sbasis.h.


Member Typedef Documentation

Definition at line 118 of file sbasis.h.


Constructor & Destructor Documentation

Geom::SBasis::SBasis (  )  [inline]

Definition at line 99 of file sbasis.h.

00099 {}

Geom::SBasis::SBasis ( double  a  )  [inline, explicit]

Definition at line 100 of file sbasis.h.

00100                               {
00101         push_back(Linear(a,a));
00102     }

Geom::SBasis::SBasis ( double  a,
double  b 
) [inline, explicit]

Definition at line 103 of file sbasis.h.

00103                                         {
00104         push_back(Linear(a,b));
00105     }

Geom::SBasis::SBasis ( SBasis const &  a  )  [inline]

Definition at line 106 of file sbasis.h.

00107                              :
00108         d(a.d)
    {}

Geom::SBasis::SBasis ( Linear const &  bo  )  [inline]

Definition at line 109 of file sbasis.h.

00109                               {
00110         push_back(bo);
00111     }

Geom::SBasis::SBasis ( Linear bo  )  [inline]

Definition at line 112 of file sbasis.h.

00112                        {
00113         push_back(*bo);
00114     }

Geom::SBasis::SBasis ( size_t  n,
Linear const &  l 
) [inline, explicit]

Definition at line 115 of file sbasis.h.

00115 : d(n, l) {}


Member Function Documentation

Linear& Geom::SBasis::at ( unsigned  i  )  [inline]

Definition at line 92 of file sbasis.h.

References d.

Referenced by Geom::unitVector().

00092 { return d.at(i);}

double Geom::SBasis::at0 (  )  const [inline]

Definition at line 135 of file sbasis.h.

Referenced by Geom::arc_length_parametrization(), Geom::centroid(), and Geom::sqrt_internal().

00135                               { 
00136         if(empty()) return 0; else return (*this)[0][0];
00137     }

double Geom::SBasis::at1 (  )  const [inline]

Definition at line 138 of file sbasis.h.

Referenced by Geom::arc_length_parametrization(), Geom::centroid(), and Geom::sqrt_internal().

00138                              {
00139         if(empty()) return 0; else return (*this)[0][1];
00140     }

Linear const& Geom::SBasis::back (  )  const [inline]

Definition at line 84 of file sbasis.h.

References d.

00084 {return d.back();}

Linear& Geom::SBasis::back (  )  [inline]

Definition at line 83 of file sbasis.h.

References d.

00083 {return d.back();}

Linear* Geom::SBasis::begin (  )  [inline]

Definition at line 80 of file sbasis.h.

References d.

00080 { return (Linear*)&*d.begin();}

Linear const* Geom::SBasis::begin (  )  const [inline]

Definition at line 78 of file sbasis.h.

References d.

Referenced by divide_by_sk().

00078 { return (Linear const*)&*d.begin();}

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

Definition at line 89 of file sbasis.h.

References d.

Referenced by Geom::bezier_to_sbasis(), and Geom::NL::LFMSBasis::instance().

00089 {d.clear();}

int Geom::SBasis::degreesOfFreedom (  )  const [inline]

Definition at line 142 of file sbasis.h.

00142 { return size()*2;}

void Geom::SBasis::derive (  )  [private]

Compute the derivative of this inplace (Exact).

Definition at line 345 of file sbasis.cpp.

References isZero(), pop_back(), and size().

Referenced by valueAndDerivatives().

00345                     { // in place version
00346     if(isZero()) return;
00347     for(unsigned k = 0; k < size()-1; k++) {
00348         double d = (2*k+1)*((*this)[k][1] - (*this)[k][0]);
00349         
00350         (*this)[k][0] = d + (k+1)*(*this)[k+1][0];
00351         (*this)[k][1] = d - (k+1)*(*this)[k+1][1];
00352     }
00353     int k = size()-1;
00354     double d = (2*k+1)*((*this)[k][1] - (*this)[k][0]);
00355     if(d == 0)
00356         pop_back();
00357     else {
00358         (*this)[k][0] = d;
00359         (*this)[k][1] = d;
00360     }
00361 }

bool Geom::SBasis::empty (  )  const [inline]

Definition at line 82 of file sbasis.h.

References d.

Referenced by Geom::force_continuity().

00082 {return d.empty();}

Linear* Geom::SBasis::end (  )  [inline]

Definition at line 81 of file sbasis.h.

References d.

00081 { return (Linear*)&*d.end();}

Linear const* Geom::SBasis::end (  )  const [inline]

Definition at line 79 of file sbasis.h.

References d.

Referenced by divide_by_sk().

00079 { return (Linear const*)&*d.end();}

void Geom::SBasis::insert ( Linear before,
const Linear src_begin,
const Linear src_end 
) [inline]

Definition at line 90 of file sbasis.h.

References d.

Referenced by divide_by_sk().

00090 { d.insert(std::vector<Linear>::iterator(before), src_begin, src_end);}

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

Definition at line 126 of file sbasis.h.

References Barcode::Code39Ext::i.

00126                                    {
00127         if (empty()) return true;
00128         for (unsigned i = 0; i < size(); i++) {
00129             if(!(*this)[i].isConstant()) return false;
00130         }
00131         return true;
00132     }

bool Geom::SBasis::isFinite (  )  const

test all coefficients are finite

Definition at line 52 of file sbasis.cpp.

References Barcode::Code39Ext::i, and size().

00052                             {
00053     for(unsigned i = 0; i < size(); i++) {
00054         if(!(*this)[i].isFinite())
00055             return false;
00056     }
00057     return true;
00058 }

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

Definition at line 119 of file sbasis.h.

References Barcode::Code39Ext::i.

Referenced by Geom::compose(), derive(), and Geom::sqrt_internal().

00119                                {
00120         if(empty()) return true;
00121         for(unsigned i = 0; i < size(); i++) {
00122             if(!(*this)[i].isZero()) return false;
00123         }
00124         return true;
00125     }

void Geom::SBasis::normalize (  )  [inline]

Definition at line 171 of file sbasis.h.

00171                      {
00172         while(!empty() && 0 == back()[0] && 0 == back()[1])
00173             pop_back();
00174     }

Geom::SBasis::operator std::vector< Linear > (  )  [inline]

Definition at line 96 of file sbasis.h.

References d.

00096 { return d;}

bool Geom::SBasis::operator!= ( SBasis const &  B  )  const [inline]

Definition at line 95 of file sbasis.h.

References d.

00095 { return d != B.d;}

SBasis Geom::SBasis::operator() ( SBasis const &  g  )  const [inline]

Definition at line 346 of file sbasis.h.

References Geom::compose().

00346                                          {
00347     return compose(*this, g);
00348 }

double Geom::SBasis::operator() ( double  t  )  const [inline]

Definition at line 156 of file sbasis.h.

00156                                       {
00157         return valueAt(t);
00158     }

bool Geom::SBasis::operator== ( SBasis const &  B  )  const [inline]

Definition at line 94 of file sbasis.h.

References d.

00094 { return d == B.d;}

Linear& Geom::SBasis::operator[] ( unsigned  i  )  [inline]

Definition at line 77 of file sbasis.h.

References d.

00077 { return d.at(i); }

Linear Geom::SBasis::operator[] ( unsigned  i  )  const [inline]

Definition at line 74 of file sbasis.h.

References d.

00074                                         {
00075         return d[i];
00076     }

void Geom::SBasis::pop_back (  )  [inline]

Definition at line 85 of file sbasis.h.

References d.

Referenced by derive().

00085 { d.pop_back();}

void Geom::SBasis::push_back ( Linear const &  l  )  [inline, private]

Definition at line 69 of file sbasis.h.

References d.

Referenced by Geom::cheb(), and Geom::subdiv_sbasis().

00069 { d.push_back(l); }

void Geom::SBasis::reserve ( unsigned  n  )  [inline]

Definition at line 88 of file sbasis.h.

References d.

00088 { d.reserve(n);}

void Geom::SBasis::resize ( unsigned  n,
Linear const &  l 
) [inline]

Definition at line 87 of file sbasis.h.

References d.

00087 { d.resize(n, l);}

void Geom::SBasis::resize ( unsigned  n  )  [inline]

Definition at line 86 of file sbasis.h.

References d.

Referenced by Geom::bezier_to_sbasis(), Geom::NL::LFMSBasis::instance(), and Geom::sqrt_internal().

00086 { d.resize(n);}

size_t Geom::SBasis::size (  )  const [inline]

Definition at line 73 of file sbasis.h.

References d.

Referenced by derive(), divide_by_sk(), isFinite(), Geom::multi_roots_internal(), Geom::sqrt_internal(), and Geom::unitVector().

00073 {return d.size();}

double Geom::SBasis::tailError ( unsigned  tail  )  const

bound the error from term truncation

Parameters:
tail first term to chop
Returns:
the largest possible error this truncation could give

Definition at line 45 of file sbasis.cpp.

References Geom::bounds_fast(), Geom::Interval::max(), Geom::max(), and Geom::Interval::min().

Referenced by Geom::sqrt_internal(), Geom::subdiv_sbasis(), and Geom::unitVector().

00045                                             {
00046   Interval bs = *bounds_fast(*this, tail);
00047   return std::max(fabs(bs.min()),fabs(bs.max()));
00048 }

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

Definition at line 162 of file sbasis.h.

00162 { return SBasis(*this); }

void Geom::SBasis::truncate ( unsigned  k  )  [inline]

Definition at line 176 of file sbasis.h.

Referenced by Geom::sqrt_internal().

00176 { if(k < size()) resize(k); }

std::vector< double > Geom::SBasis::valueAndDerivatives ( double  t,
unsigned  n 
) const

Compute the value and the first n derivatives.

Parameters:
t position to evaluate
n number of derivatives (not counting value)
Returns:
a vector with the value and the n derivative evaluations

There is an elegant way to compute the value and n derivatives for a polynomial using a variant of horner's rule. Someone will someday work out how for sbasis.

Definition at line 67 of file sbasis.cpp.

References derive(), Barcode::Code39Ext::i, and valueAt().

00067                                                                         {
00068     std::vector<double> ret(n+1);
00069     ret[0] = valueAt(t);
00070     SBasis tmp = *this;
00071     for(unsigned i = 1; i < n+1; i++) {
00072         tmp.derive();
00073         ret[i] = tmp.valueAt(t);
00074     }
00075     return ret;
00076 }

double Geom::SBasis::valueAt ( double  t  )  const [inline]

Definition at line 144 of file sbasis.h.

Referenced by valueAndDerivatives().

00144                                    {
00145         double s = t*(1-t);
00146         double p0 = 0, p1 = 0;
00147         for(unsigned k = size(); k > 0; k--) {
00148             const Linear &lin = (*this)[k-1];
00149             p0 = p0*s + lin[0];
00150             p1 = p1*s + lin[1];
00151         }
00152         return (1-t)*p0 + t*p1;
00153     }


Member Data Documentation


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