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

Blob.h

Go to the documentation of this file.
00001 /** 
00002  * @file Blob.h A blob abstract class
00003  * @author John C. Hart
00004  * @date Fall 2000
00005  */
00006 
00007 #ifndef __BLOB_H
00008 #define __BLOB_H
00009 
00010 #include "Implicit/Operator/UnaryOp.h"
00011 
00012 /**
00013  * A pure virtual Blob class collecting methods common to all blobby models.
00014  *
00015  * Blob is a unary operator that assumes a quadric operand that returns
00016  * radius squared. A separate real kernel function of one variable is
00017  * defined by its instances that accepts the squared radius and returns
00018  * a quasi-Gaussian bump.
00019  */
00020 
00021 class Blob : public UnaryOp
00022 {
00023   protected:
00024     double m_r;  ///< The radius of blob object
00025 
00026   public:
00027     /// The kernel function defined by instances.
00028     virtual double kernel(double r2) = 0;
00029 
00030     /** The derivatives (wrt r2, not r !!!) of the kernel
00031      * \todo These should default to central differences.
00032      */
00033     virtual double dkernel(double r2) = 0;
00034     virtual double d2kernel(double r2) = 0;
00035 
00036     virtual Intervald kernel(Intervald r2) = 0;
00037     virtual Intervald dkernel(Intervald r2) = 0;
00038     virtual Intervald d2kernel(Intervald r2) = 0;
00039 
00040 #ifndef INTERVAL_EVAL_ONLY
00041 /// proc just applies the kernel to the squared-radius
00042     virtual double proc(gmVector3 x)
00043     {
00044       double retval = 0.0;
00045       if (m_f != NULL)
00046         retval = kernel(m_f->proc(x));
00047       return retval;
00048     }
00049 
00050     /** Blob gradient.
00051      * Uses chain rule for gradient
00052      * d/dx blob(x) = d/dx kernel(m_f(x)) = dkernel(m_f(x))dm_f(x)/dx
00053      */
00054     virtual gmVector3 grad(gmVector3 x)
00055     {
00056       gmVector3 retval;
00057       if (m_f != NULL)
00058         retval = dkernel(m_f->proc(x)) * m_f->grad(x);
00059       return retval;
00060     }
00061 
00062     /** Blob Hessian
00063      * Uses chain rule.
00064      * d2/dx2 blob(x) = d/dx dkernel(m_f(x))dm_f(x)/dx
00065      * = d2kernel(m_f(x))/dx2 (dm_f(x)/dx)^2 + dkernel(m_f(x))/dx d2m_f(x)/dx2
00066      */
00067     virtual gmMatrix3 hess(gmVector3 x)
00068     {
00069       gmMatrix3 retval;
00070       if (m_f != NULL)
00071         retval = d2kernel(m_f->proc(x)) * outer(m_f->grad(x),m_f->grad(x)) +
00072                  dkernel(m_f->proc(x)) * m_f->hess(x);
00073       return retval;
00074     }
00075 #endif
00076 
00077     /// Interval version of proc()
00078     virtual Intervald proc(Box<double> x)
00079     {
00080       Intervald result = Intervald(0.0);
00081       if (m_f != NULL)
00082         result = kernel(m_f->proc(x));
00083       return result;
00084     }
00085 
00086     /// Interval version of grad()
00087     virtual Box3d grad(Box<double> x)
00088     {
00089       Box3d result = Box3d(0.0);
00090       if (m_f != NULL)
00091         {
00092           Intervald dkern = dkernel(m_f->proc(x));
00093           result = m_f->grad(x);
00094           for (int i = 0; i < 3; i++)
00095             result[i] *= dkern;
00096         }
00097       return result;
00098     }
00099 
00100     /// Interval version of hess()
00101     virtual IMatrix3d hess(Box<double> x)
00102     {
00103       IMatrix3d result = IMatrix3d(0.0);
00104       if (m_f != NULL)
00105         {
00106           Intervald dkern = dkernel(m_f->proc(x));
00107           Intervald d2kern = d2kernel(m_f->proc(x));
00108           IMatrix3d hessres = m_f->hess(x);
00109           IMatrix3d outerres = outer(m_f->grad(x),m_f->grad(x));
00110           for (int i = 0; i < 2; i++)
00111             for (int j = 0; j < 2; j++)
00112               result[i][j] = (dkern * hessres[i][j]) + 
00113                              (d2kern * outerres[i][j]);
00114         }
00115       return result;
00116     }
00117 
00118     virtual const char ** getPixmapXPM(const int& size) const
00119     {
00120       if (size <= 16)
00121         return (const char **)blob_pixmap16;
00122       else if (size <= 32)
00123         return (const char **)blob_pixmap32;
00124       else
00125         return (const char **)blob_pixmap48;
00126     }
00127 };
00128 
00129 #endif
00130 

Generated on Mon Jun 28 14:58:13 2004 for Advanced Surface Library by doxygen 1.3.4