Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

Algebraic Class Reference

#include <Algebraic.h>

Inheritance diagram for Algebraic:

Inheritance graph
[legend]
Collaboration diagram for Algebraic:

Collaboration graph
[legend]
List of all members.

Detailed Description

An algebraic implicit surface class.

This class implements arbitrary polynomials of three variables.

Definition at line 15 of file Algebraic.h.

Public Member Functions

 Algebraic ()
 Constucts a constant Algebraic.

 Algebraic (int degree)
 ~Algebraic ()
virtual double proc (gmVector3 x)
virtual gmVector3 grad (gmVector3 v)
 grad returns the gradient of the function (proc()) for a point or region.

virtual gmMatrix3 hess (gmVector3 v)
 hess returns the Hessian of the function (proc()) for a point or region.

virtual Intervald proc (Box< double >)
 proc of an interval-vector (aka a Box) X.

virtual Box3d grad (Box< double >)
virtual IMatrix3d hess (Box< double >)
int degree ()
 Degree of polynomial.

void degree (int)
int getNumCoef ()
 Number of coefficients.

int getCoefIndex (int i, int j, int k)
 Return the ordinal of the x^i y^j z^k coefficient.

double getCoef (int i, int j, int k)
 Returns scalar factor of the x^i y^j z^k term.

void setCoef (int i, int j, int k, double a)
 Sets coefficient of x^i y^j z^k to a.

virtual void procq (gmVector3, double *)
 Computes dproc()/dq for an algebraic.

virtual void procq (Box< double >, Intervald *)
 Computes dproc()/dq in Interval form for an algebraic.

virtual void gradq (Box< double >, Intervald *, Intervald *, Intervald *)
 Computes dgrad()/dq = d^2proc/dxdq and stores it in three arrays.

virtual void getq (double *)
 Get copy of the implicit model parameters.

virtual void _setq (double *)
 Overridden by subclasses to set Qs.

virtual int qlen ()
 Number of implicit model parameters for this implicit object including its children.

virtual void getqname (char **qn)
 The name of each parameter.

 MAKE_NAME ()

Static Public Member Functions

int coefficients (int)
 Compute the number of terms for a degree d trivariate polynomial.


Protected Member Functions

void initPowerArrays ()
 Initialize the m_x,m_y and m_z arrays to their corresponding exponents in coefficient order.

void initXYZPowerArrays (gmVector3 v)
 Fills m_[xyz]Pow cache with powers of x, y and z.

void initDerivCoefs (void)
void calcNumCoef ()
 Set the number of coefficients in m_numCoef based on the current degree held in m_d.

double dx (gmVector3 v)
double dy (gmVector3 v)
double dz (gmVector3 v)
double dx2 (gmVector3 v)
double dy2 (gmVector3 v)
double dz2 (gmVector3 v)
double dxdy (gmVector3 v)
double dxdz (gmVector3 v)
double dydz (gmVector3 v)

Protected Attributes

int m_d
 Degree.

int m_numCoef
 Number of terms.

int * m_x
 Array storing the exponents of x in coefficient order.

int * m_y
 Array storing the exponents of y in coefficient order.

int * m_z
 Array storing the exponents of z in coefficient order.

double * m_xPow
 Cached array of powers of input value of x in coefficient order.

double * m_yPow
 Cached array of powers of input value of y in coefficient order.

double * m_zPow
 Cached array of powers of input value of z in coefficient order.


Private Member Functions

void init (int)
 Initialization routine called by constructors.

Intervald m_alrp (int, Intervald)
 Linear interpolate - 4D critical points.


Private Attributes

double * m_a
 Array of coefficients.


Constructor & Destructor Documentation

Algebraic::Algebraic  ) 
 

Constucts a constant Algebraic.

Definition at line 37 of file Algebraic.cpp.

References init().

Algebraic::Algebraic int  degree  ) 
 

Definition at line 42 of file Algebraic.cpp.

References init().

Algebraic::~Algebraic  ) 
 

Definition at line 104 of file Algebraic.cpp.

References m_a, m_x, m_xPow, m_y, m_yPow, m_z, and m_zPow.


Member Function Documentation

void Algebraic::_setq double *   )  [virtual]
 

Overridden by subclasses to set Qs.

_setq() is called directly only in subclasses of Implicit. Outside the Implicit class hierarchy, always call setq(). So, if you want to save the old set of Qs, a subclass should override _setq(). In fact, the default _setq() in Implicit does nothing, so you have to override it to do the work of setting the current Q array. However, on the off chance you have a subclass where you do not want to save the old Qs, then override setq() to do the work of settings the current Qs. Typically you will want to save the old Qs so subclasses will usually override (and call) _setq().

Reimplemented from Implicit.

Definition at line 592 of file Algebraic.cpp.

References m_a, and m_numCoef.

void Algebraic::calcNumCoef  )  [protected]
 

Set the number of coefficients in m_numCoef based on the current degree held in m_d.

Definition at line 303 of file Algebraic.cpp.

References coefficients(), m_d, and m_numCoef.

Referenced by degree(), and init().

int Algebraic::coefficients int  d  )  [static]
 

Compute the number of terms for a degree d trivariate polynomial.

Degree d algebraic has (d^3 + 6d^2 + 11d + 6)/6 coefficients.

0: 1 1: 3 + 1 = 4 2: 6 + 4 = 10 3: 10 + 10 = 20

# of terms of degree d = d+1 + # of terms of degree d-1. Why? Multiply x times terms of degree d-1, then all that is left are terms containing only y and z. There are d+1 of these. E.g. yyy yyz yzz zzz

Hence terms(d) = d+1 + terms(d-1) and terms(0) = 1. This yields terms(d) = sum[i = 1..d+1] i = (d+2)*(d+1)/2 (Recall sum[i = 1..n] i = (n+1)*n/2) = 1/2 d^2 + 3/2 d + 1.

The # of terms of degree d or less is thus sum[i = 0..d] terms(i) = sum[i = 0..d] 1/2 d^2 + 3/2 d + 1 = 1/2 * d*(d+1)*(2d+1)/6 + 3/2 * d*(d+1)/2 + d+1 (Recall sum[i = 1..n] i^2 = n(n+1)(2n+1)/6) = 1/12 * (2d^3 + 3d^2 + d) + 3/4 * (d^2 + d) + d + 1 = d^3/6 + d^2 + 1 10/12 d + 1.

Definition at line 295 of file Algebraic.cpp.

Referenced by calcNumCoef(), getCoefIndex(), and ImpFileManager::readImplicit().

void Algebraic::degree int   ) 
 

Definition at line 47 of file Algebraic.cpp.

References calcNumCoef(), initPowerArrays(), m_a, m_d, m_numCoef, m_x, m_xPow, m_y, m_yPow, m_z, and m_zPow.

int Algebraic::degree  ) 
 

Degree of polynomial.

Definition at line 264 of file Algebraic.cpp.

References m_d.

double Algebraic::dx gmVector3  v  )  [protected]
 

Definition at line 404 of file Algebraic.cpp.

References initXYZPowerArrays(), m_a, m_numCoef, m_x, m_xPow, m_y, m_yPow, m_z, and m_zPow.

Referenced by grad().

double Algebraic::dx2 gmVector3  v  )  [protected]
 

Definition at line 446 of file Algebraic.cpp.

References initXYZPowerArrays(), m_a, m_numCoef, m_x, m_xPow, m_y, m_yPow, m_z, and m_zPow.

Referenced by hess().

double Algebraic::dxdy gmVector3  v  )  [protected]
 

Definition at line 488 of file Algebraic.cpp.

References initXYZPowerArrays(), m_a, m_numCoef, m_x, m_xPow, m_y, m_yPow, m_z, and m_zPow.

Referenced by hess().

double Algebraic::dxdz gmVector3  v  )  [protected]
 

Definition at line 502 of file Algebraic.cpp.

References initXYZPowerArrays(), m_a, m_numCoef, m_x, m_xPow, m_y, m_yPow, m_z, and m_zPow.

Referenced by hess().

double Algebraic::dy gmVector3  v  )  [protected]
 

Definition at line 418 of file Algebraic.cpp.

References initXYZPowerArrays(), m_a, m_numCoef, m_x, m_xPow, m_y, m_yPow, m_z, and m_zPow.

Referenced by grad().

double Algebraic::dy2 gmVector3  v  )  [protected]
 

Definition at line 460 of file Algebraic.cpp.

References initXYZPowerArrays(), m_a, m_numCoef, m_x, m_xPow, m_y, m_yPow, m_z, and m_zPow.

Referenced by hess().

double Algebraic::dydz gmVector3  v  )  [protected]
 

Definition at line 516 of file Algebraic.cpp.

References initXYZPowerArrays(), m_a, m_numCoef, m_x, m_xPow, m_y, m_yPow, m_z, and m_zPow.

Referenced by hess().

double Algebraic::dz gmVector3  v  )  [protected]
 

Definition at line 432 of file Algebraic.cpp.

References initXYZPowerArrays(), m_a, m_numCoef, m_x, m_xPow, m_y, m_yPow, m_z, and m_zPow.

Referenced by grad().

double Algebraic::dz2 gmVector3  v  )  [protected]
 

Definition at line 474 of file Algebraic.cpp.

References initXYZPowerArrays(), m_a, m_numCoef, m_x, m_xPow, m_y, m_yPow, m_z, and m_zPow.

Referenced by hess().

double Algebraic::getCoef int  i,
int  j,
int  k
 

Returns scalar factor of the x^i y^j z^k term.

Parameters:
i exponent for x.
j exponent for y.
k exponent for z.
Returns:
scalar factor of the x^i y^j z^k term.

Definition at line 243 of file Algebraic.cpp.

References getCoefIndex(), and m_a.

Referenced by Quadric::Q().

int Algebraic::getCoefIndex int  i,
int  j,
int  k
 

Return the ordinal of the x^i y^j z^k coefficient.

Resulting index used for m_a, m_x, m_y, m_z, m_xPow, m_yPow and m_zPow.

Coefficient order is constant first, then x, then y, then z. For a quadric, coefficient order is: 1, x, y, x^2, xy, y^2, z, xz, yz, z^2.

Todo:
: Coefficient order should be by degree, so for a quadric it should be: 1 x y z x^2 xy y^2 xz yz z^2. This way changing the degree means reducing or extending the parameter list without necessarily reordering the lower degree elements.
1 \

x y \ z

xx xy yy \ xz yz \ zz

xxx xxy xyy yyy \ xxz xyz yyz \ xzz yzz \ zzz

Coordinates: level: d = i+j+k (degree) horizontal: j vertical: k

Answer is: coefficients(d) - sum[kk=1..d+1-k](kk) + j = coefficients(d) - sum[kk=1..i+j+1](kk) + j (since d = i+j+k) = coefficients(d) - (i+j+1)(i+j+2)/2 + j = coefficients(d) - (i*i + 2*i*j + j*j + 3*i + 3*j + 2)/2 + j

Parameters:
i exponent of x
j exponent of y
k exponent of z
Returns:
coefficient-order index for x^i y^j z^k.

Definition at line 349 of file Algebraic.cpp.

References coefficients().

Referenced by getCoef(), initPowerArrays(), and setCoef().

int Algebraic::getNumCoef  ) 
 

Number of coefficients.

Definition at line 259 of file Algebraic.cpp.

References m_numCoef.

void Algebraic::getq double *  q  )  [virtual]
 

Get copy of the implicit model parameters.

Parameters:
A pointer to the array to be returned.

Reimplemented from Implicit.

Definition at line 584 of file Algebraic.cpp.

References m_a, and m_numCoef.

void Algebraic::getqname char **  qn  )  [virtual]
 

The name of each parameter.

The names of the parameters of the function (if any) are put into an array which gets returned.

Parameters:
qn An array of size qlen of strings listing names of parameters

Reimplemented from Implicit.

Definition at line 603 of file Algebraic.cpp.

References m_numCoef, m_x, m_y, and m_z.

Box3d Algebraic::grad Box< double >   )  [virtual]
 

Reimplemented from Implicit.

Definition at line 180 of file Algebraic.cpp.

References dx(), Intervald, m_a, m_alrp(), m_numCoef, m_x, m_y, and m_z.

gmVector3 Algebraic::grad gmVector3  v  )  [virtual]
 

grad returns the gradient of the function (proc()) for a point or region.

Basically, the gradient returns a vector of partial derivatives, or more formally grad(proc()) = (dproc/dx,dproc/dy,dproc/dz).

Note:
Unless grad is overwritten, it defaults to the numerical approximation of the gradient = (proc(x+eps) - proc(x))/eps ...
Parameters:
x Where to evaluate the gradient of the function.
Returns:
The gradient result.
See also:
setEpsilon(double)

Reimplemented from Implicit.

Definition at line 143 of file Algebraic.cpp.

References dx(), dy(), and dz().

void Algebraic::gradq Box< double >  x,
Intervald dfdxdq,
Intervald dfdydq,
Intervald dfdzdq
[virtual]
 

Computes dgrad()/dq = d^2proc/dxdq and stores it in three arrays.

Parameters:
dfdxdq returns Intervald x components of dgrad()/dq
dfdydq returns Intervald y components of dgrad()/dq
dfdzdq returns Intervald z components of dgrad()/dq
Arrays should be preallocated to length qlen().

Assume f(x,y,z) = a x^i y^j z^k. Then df/dx = a i x^(i-1) y^j z^k. Then d^2f/dxda = i x^(i-1) y^j z^k.

Reimplemented from Implicit.

Definition at line 570 of file Algebraic.cpp.

References Intervald, m_numCoef, m_x, m_y, and m_z.

IMatrix3d Algebraic::hess Box< double >   )  [virtual]
 

Reimplemented from Implicit.

Definition at line 201 of file Algebraic.cpp.

References Intervald, m_a, m_numCoef, m_x, m_y, and m_z.

gmMatrix3 Algebraic::hess gmVector3  v  )  [virtual]
 

hess returns the Hessian of the function (proc()) for a point or region.

Basically, the Hessian is a matrix of second partial derivatives, or more formally hess(proc()) =

d^2proc/dx^2, d^2proc/dxdy d^2proc/dxdz \ d^2proc/dxdy, d^2proc/dy^2 d^2proc/dydz \ d^2proc/dxdz, d^2proc/dydz d^2proc/dz^2

Note:
Unless hess is overwritten, it defaults to the numerical approximation of the Hessian.
Parameters:
x Where to evaluate the Hessian of the function.
Returns:
The Hessian result.
See also:
setEpsilon(double)
Note:
The Hessian is symmetric for our uses.

Reimplemented from Implicit.

Definition at line 148 of file Algebraic.cpp.

References dx2(), dxdy(), dxdz(), dy2(), dydz(), and dz2().

void Algebraic::init int  deg  )  [private]
 

Initialization routine called by constructors.

This function allows all of the main object init code to be in one place.

Definition at line 17 of file Algebraic.cpp.

References calcNumCoef(), initPowerArrays(), m_a, m_d, m_numCoef, m_x, m_xPow, m_y, m_yPow, m_z, and m_zPow.

Referenced by Algebraic().

void Algebraic::initDerivCoefs void   )  [protected]
 

void Algebraic::initPowerArrays  )  [protected]
 

Initialize the m_x,m_y and m_z arrays to their corresponding exponents in coefficient order.

Definition at line 362 of file Algebraic.cpp.

References getCoefIndex(), Implicit::k(), m_d, m_x, m_y, and m_z.

Referenced by degree(), and init().

void Algebraic::initXYZPowerArrays gmVector3  v  )  [protected]
 

Fills m_[xyz]Pow cache with powers of x, y and z.

Efficiently computes powers by using results of lower powers.

Parameters:
v The input x,y,z.
Note:
Remembers last v to avoid recomputation.

Todo:
Could memoize (hash) v to possibly avoid more recomputation. Need to build a general datastructure to handle this. Perhaps this should be handled at a higher level (e.g. as in Bloomenthal's marching cubes implementation).

Definition at line 387 of file Algebraic.cpp.

References m_d, m_xPow, m_yPow, and m_zPow.

Referenced by dx(), dx2(), dxdy(), dxdz(), dy(), dy2(), dydz(), dz(), dz2(), proc(), and procq().

Intervald Algebraic::m_alrp int  i,
Intervald  t
[private]
 

Linear interpolate - 4D critical points.

We use the "current" and the "last" coefficients to calculate an interval of the coefficients over a given time interval. This is used for 4D critical point finding.

Definition at line 122 of file Algebraic.cpp.

References Implicit::getqold(), Intervald, m_a, and m_numCoef.

Referenced by grad(), and proc().

Algebraic::MAKE_NAME  ) 
 

Reimplemented in Cone, Cylinder, Ellipsoid, Quadric, and Torus.

Intervald Algebraic::proc Box< double >  x  )  [virtual]
 

proc of an interval-vector (aka a Box) X.

If X is a 4D box then we assume q is lerp between qold and q.

x[3] = [told,t] m_alrp (i,x[3]) returns [(a_i)old,a_i]

Reimplemented from Implicit.

Definition at line 169 of file Algebraic.cpp.

References Intervald, m_a, m_alrp(), m_numCoef, m_x, m_y, and m_z.

double Algebraic::proc gmVector3  x  )  [virtual]
 

Implements Implicit.

Definition at line 132 of file Algebraic.cpp.

References initXYZPowerArrays(), m_a, m_numCoef, m_x, m_xPow, m_y, m_yPow, m_z, and m_zPow.

void Algebraic::procq Box< double >  x,
Intervald dfdq
[virtual]
 

Computes dproc()/dq in Interval form for an algebraic.

Each term of the algebraic is of the form a x^i y^j z^k so its derivative with respect to a is just x^i y^j z^k.

Reimplemented from Implicit.

Definition at line 548 of file Algebraic.cpp.

References Intervald, m_numCoef, m_x, m_y, and m_z.

void Algebraic::procq gmVector3  x,
double *  dfdq
[virtual]
 

Computes dproc()/dq for an algebraic.

Each term of the algebraic is of the form a x^i y^j z^k so its derivative with respect to a is just x^i y^j z^k.

Reimplemented from Implicit.

Definition at line 534 of file Algebraic.cpp.

References initXYZPowerArrays(), m_numCoef, m_x, m_xPow, m_y, m_yPow, m_z, and m_zPow.

int Algebraic::qlen  )  [virtual]
 

Number of implicit model parameters for this implicit object including its children.

Reimplemented from Implicit.

Definition at line 598 of file Algebraic.cpp.

References m_numCoef.

void Algebraic::setCoef int  i,
int  j,
int  k,
double  a
 

Sets coefficient of x^i y^j z^k to a.

Parameters:
i exponent for x.
j exponent for y.
k exponent for z.
a Coefficient for x^i y^j z^k.

Definition at line 254 of file Algebraic.cpp.

References getCoefIndex(), and m_a.

Referenced by Quadric::Quadric(), Torus::Torus(), and Quadric::Transform().


Member Data Documentation

double* Algebraic::m_a [private]
 

Array of coefficients.

Should be accessed through getCoef and setCoef.

Definition at line 65 of file Algebraic.h.

Referenced by _setq(), degree(), dx(), dx2(), dxdy(), dxdz(), dy(), dy2(), dydz(), dz(), dz2(), getCoef(), getq(), grad(), hess(), init(), m_alrp(), proc(), setCoef(), and ~Algebraic().

int Algebraic::m_d [protected]
 

Degree.

Definition at line 72 of file Algebraic.h.

Referenced by calcNumCoef(), degree(), init(), initPowerArrays(), and initXYZPowerArrays().

int Algebraic::m_numCoef [protected]
 

Number of terms.

Initialized by calcNumCoef. Accessed via getNumCoef.

Definition at line 78 of file Algebraic.h.

Referenced by _setq(), calcNumCoef(), degree(), dx(), dx2(), dxdy(), dxdz(), dy(), dy2(), dydz(), dz(), dz2(), getNumCoef(), getq(), getqname(), grad(), gradq(), hess(), init(), m_alrp(), proc(), procq(), and qlen().

int* Algebraic::m_x [protected]
 

Array storing the exponents of x in coefficient order.

Definition at line 81 of file Algebraic.h.

Referenced by degree(), dx(), dx2(), dxdy(), dxdz(), dy(), dy2(), dydz(), dz(), dz2(), getqname(), grad(), gradq(), hess(), init(), initPowerArrays(), proc(), procq(), and ~Algebraic().

double* Algebraic::m_xPow [protected]
 

Cached array of powers of input value of x in coefficient order.

Definition at line 90 of file Algebraic.h.

Referenced by degree(), dx(), dx2(), dxdy(), dxdz(), dy(), dy2(), dydz(), dz(), dz2(), init(), initXYZPowerArrays(), proc(), procq(), and ~Algebraic().

int* Algebraic::m_y [protected]
 

Array storing the exponents of y in coefficient order.

Definition at line 84 of file Algebraic.h.

Referenced by degree(), dx(), dx2(), dxdy(), dxdz(), dy(), dy2(), dydz(), dz(), dz2(), getqname(), grad(), gradq(), hess(), init(), initPowerArrays(), proc(), procq(), and ~Algebraic().

double* Algebraic::m_yPow [protected]
 

Cached array of powers of input value of y in coefficient order.

Definition at line 93 of file Algebraic.h.

Referenced by degree(), dx(), dx2(), dxdy(), dxdz(), dy(), dy2(), dydz(), dz(), dz2(), init(), initXYZPowerArrays(), proc(), procq(), and ~Algebraic().

int* Algebraic::m_z [protected]
 

Array storing the exponents of z in coefficient order.

Definition at line 87 of file Algebraic.h.

Referenced by degree(), dx(), dx2(), dxdy(), dxdz(), dy(), dy2(), dydz(), dz(), dz2(), getqname(), grad(), gradq(), hess(), init(), initPowerArrays(), proc(), procq(), and ~Algebraic().

double* Algebraic::m_zPow [protected]
 

Cached array of powers of input value of z in coefficient order.

Definition at line 96 of file Algebraic.h.

Referenced by degree(), dx(), dx2(), dxdy(), dxdz(), dy(), dy2(), dydz(), dz(), dz2(), init(), initXYZPowerArrays(), proc(), procq(), and ~Algebraic().


The documentation for this class was generated from the following files:
Generated on Mon Jun 28 15:02:00 2004 for Advanced Surface Library by doxygen 1.3.4