Intp.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  $RCSfile: Intp.h,v $ --- $Date: 2006/07/19 13:21:43 $ --- $Revision: 1.3 $
00003  *****************************************************************************
00004  PREPROCESSOR DIRECTIVES
00005  *****************************************************************************/
00006 
00007  #ifndef CALC_INTP_H
00008  #define CALC_INTP_H
00009 
00010 /*****************************************************************************
00011  INCLUDE FILES
00012  *****************************************************************************/
00013 
00014  #include "Base.h"
00015 
00016 /*****************************************************************************
00017  NAMESPACE IDENTIFICATIONS
00018  *****************************************************************************/
00019 
00020  namespace calc {
00021 
00022 /*****************************************************************************
00023  IntpErr CLASS
00024  *****************************************************************************/
00034 
00035 
00046  class IntpErr:public Err {
00047 
00048  public:
00049 
00050  // Enumerations
00051 
00053     enum ERR_ENUM {
00054        INIT=0,    
00055        MEMORY,    
00056        EQUAL,     
00057        ERR_CNT,   
00058     };
00059 
00060  // Constructors
00061 
00068     IntpErr(enum IntpErr::ERR_ENUM indErr):
00069     Err() {
00070        const char* const CLASS_NAME="Intp";
00071        const char* const ERR_STR[ERR_CNT]={
00072           "object initialization error"                  ,   // text for index INIT
00073           "memory allocation error"                      ,   // text for index MEMORY
00074           "equivalent/decreasing independent data points",   // text for index EQUAL
00075        };
00076        setError(indErr,CLASS_NAME,ERR_STR[indErr]);
00077     }
00078  };
00079 
00080 /*****************************************************************************
00081  Intp CLASS TEMPLATE
00082  *****************************************************************************/
00084 
00100  template <typename xType, typename yType>
00101  class Intp:public Base {
00102 
00103  public:
00104 
00105  // Member Enumerations
00106 
00108     enum CTYPE {
00109        CUBIC=0   ,  
00110        NURBS     ,  
00111        POLYNOMIAL,  
00112        CTYPE_CNT ,  
00113     };
00115     enum VTYPE {
00116        INDEPENDENT=0,   
00117        KNOT         ,   
00118        DEPENDENT    ,   
00119        DERIVATIVE   ,   
00120        POLYGON      ,   
00121        ORDER        ,   
00122        VTYPE_CNT    ,   
00123     };
00124 
00125  // Member Functions
00126 
00127     bool update (const xType *arX, const yType *arY);
00128 
00129     virtual xType       *copyArrayX  (enum Intp<xType,yType>::VTYPE vType, xType *array) const;
00130     virtual yType       *copyArrayY  (enum Intp<xType,yType>::VTYPE vType, yType *array) const;
00131     virtual const xType *getArrayX   (enum Intp<xType,yType>::VTYPE vType) const;
00132     virtual const yType *getArrayY   (enum Intp<xType,yType>::VTYPE vType) const;
00133     virtual int          getCount    (enum Intp<xType,yType>::VTYPE vType) const;
00134 
00146     bool isBounded(xType x) const {return (((x-aX[0])*(x-aX[mData]))<=(xType)(0));}
00155     bool isIncreasing(void) const {return bInc;}
00170     enum Intp<xType,yType>::CTYPE getMethod(void) const {return cTyp;}
00182     virtual bool update(void) {return nogo;}
00197     virtual yType eval(xType x) throw (IntpErr)=0;
00198 
00199  // Data Members
00200 
00201     static const int DEF_POINTS;
00202 
00203  protected:
00204 
00205  // Constructors
00206 
00207     Intp(const xType *arX, const yType *arY, int nCount, int nPoints);
00208     Intp(const Intp<xType,yType> &in);
00209    ~Intp(void);
00210 
00211  // Data Members
00212 
00213     xType      *aX;              
00214     yType      *aY;              
00215     int         nData;           
00216     int         mData;           
00217     int         nPts;            
00218     bool        bInc;            
00219     enum Intp<xType,yType>::CTYPE cTyp;  
00221  private:
00222 
00223  // Member Functions
00224 
00225     virtual void varInit (void);
00226 
00236     bool varAlloc(int nCount)
00237        {return ((!(aX=new xType[nCount]))||(!(aY=new yType[nCount])));}
00238  };
00239 
00240 /*****************************************************************************/
00241 
00243  template <typename xType, typename yType>
00244  const int calc::Intp<xType,yType>::DEF_POINTS=4;
00245 
00246 /*****************************************************************************
00247  EndCube CLASS TEMPLATE
00248  *****************************************************************************/
00250 
00270  template <typename xType, typename yType>
00271  class EndCube:public Base {
00272 
00273  public:
00274 
00275  // Member Enumerations
00276 
00278     enum DTYPE {
00279      DDY=0,     
00280      DY,        
00281      DTYPE_CNT, 
00282     };
00283 
00284  // Constructors
00285 
00296     EndCube(void):
00297     Base() {varInit();}
00327     EndCube(yType yDLo, enum EndCube<xType,yType>::DTYPE eDLo,
00328             yType yDHi, enum EndCube<xType,yType>::DTYPE eDHi):
00329     Base() {yDrv[LO]=yDLo; eDrv[LO]=eDLo;
00330             yDrv[HI]=yDHi; eDrv[HI]=eDHi; nogo=false;}
00337     EndCube(const EndCube &dc):
00338     Base(dc) {yDrv[LO]=dc.yDrv[LO]; eDrv[LO]=dc.eDrv[LO];
00339               yDrv[HI]=dc.yDrv[HI]; eDrv[HI]=dc.eDrv[HI]; nogo=false;}
00343    ~EndCube(void) {}
00344 
00345  // Member Functions
00346 
00371     void setDerivative(yType yDeriv, enum EndCube<xType,yType>::DTYPE dType, enum Base::BOUND iBnd)
00372        {yDrv[iBnd]=yDeriv; eDrv[iBnd]=dType;}
00388     yType getDerivative(enum Base::BOUND iBnd) const {return yDrv[iBnd];}
00399     enum EndCube<xType,yType>::DTYPE getType(enum Base::BOUND iBnd) const
00400        {return eDrv[iBnd];}
00414     bool operator==(const EndCube& dc) const
00415        {return ((yDrv[LO]==dc.yDrv[LO])&&(eDrv[LO]==dc.eDrv[LO])&&
00416                 (yDrv[HI]==dc.yDrv[HI])&&(eDrv[HI]==dc.eDrv[HI])&&(!nogo)&&(!dc.nogo));}
00430     bool operator!=(const EndCube& dc) const 
00431        {return ((yDrv[LO]!=dc.yDrv[LO])||(eDrv[LO]!=dc.eDrv[LO])||
00432                 (yDrv[HI]!=dc.yDrv[HI])||(eDrv[HI]!=dc.eDrv[HI])||(nogo)||(dc.nogo));}
00433 
00434  // Related Print Functions
00435 
00452     friend std::ostream& operator<<(std::ostream& ostr, const EndCube& ec)
00453        {ostr<<ec.yDrv[LO]<<","<<ec.eDrv[LO]<<","
00454             <<ec.yDrv[HI]<<","<<ec.eDrv[HI]; return ostr;}
00455 
00456  private:
00457 
00458  // Member Functions
00459 
00463     virtual void varInit(void)
00464        {yDrv[LO]=yDrv[HI]=(xType)(0); eDrv[LO]=eDrv[HI]=DDY; nogo=false;}
00465 
00466  // Data Members
00467 
00468     yType      yDrv[Base::BOUND_CNT]; 
00469     enum EndCube<xType,yType>::DTYPE eDrv[Base::BOUND_CNT]; 
00470  };
00471 
00472 /*****************************************************************************
00473  Cube CLASS TEMPLATE
00474  *****************************************************************************/
00476 
00500  template <typename xType, typename yType>
00501  class Cube:public Intp<xType,yType> {
00502 
00503  // Inherited Member Functions & Data Members
00504 
00505     using Intp<xType,yType>::nogo;
00506     using Intp<xType,yType>::mData;
00507     using Intp<xType,yType>::nData;
00508     using Intp<xType,yType>::nPts;
00509     using Intp<xType,yType>::cTyp;
00510     using Intp<xType,yType>::aX;
00511     using Intp<xType,yType>::aY;
00512     using Intp<xType,yType>::LO;
00513     using Intp<xType,yType>::HI;
00514     using Intp<xType,yType>::DERIVATIVE;
00515     using Intp<xType,yType>::CUBIC;
00516     using Intp<xType,yType>::memCopy;
00517 
00518  public:
00519 
00520  // Constructors
00521 
00522     Cube(const Cube<xType,yType> &cu);
00523     Cube(const Intp<xType,yType> &in);
00524    ~Cube(void);
00525 
00547     Cube(const xType *arX, const yType *arY, int nCount):
00548     Intp<xType,yType>(arX,arY,nCount,DEF_POINTS) {specInit((EndCube<xType,yType>*)(0));}
00567     Cube(const xType *arX, const yType *arY, int nCount, const EndCube<xType,yType> &rDc):
00568     Intp<xType,yType>(arX,arY,nCount,DEF_POINTS) {specInit(&rDc);}
00569 
00570  // Member Functions
00571 
00572     virtual bool          update        (void);
00573     virtual yType         eval          (xType x) throw (IntpErr);
00574     virtual yType        *copyArrayY    (enum Intp<xType,yType>::VTYPE vType, yType *array) const;
00575     virtual const yType  *getArrayY     (enum Intp<xType,yType>::VTYPE vType) const;
00576     virtual int           getCount      (enum Intp<xType,yType>::VTYPE vType) const;
00577 
00578     bool setEndCube (EndCube<xType,yType> eCube);
00579 
00593     EndCube<xType,yType> getEndCube(void) const {return pDy;}
00594 
00595  // Data Members
00596 
00597     static const int   DEF_POINTS;
00598     static const xType DDY_SCALE;
00599 
00600  private:
00601 
00602  // Member Functions
00603 
00604     virtual void varInit (void);
00605 
00606     void specInit (const EndCube<xType,yType> *pDc);
00607 
00617     bool varAlloc(int nCount) {return (!(aDDy=new yType[nCount]));}
00618 
00619  // Data Members
00620 
00621     EndCube<xType,yType>   pDy;   
00622     yType                 *aDDy;  
00623  };
00624 
00625 /*****************************************************************************/
00626 
00628  template <typename xType, typename yType>
00629  const int calc::Cube<xType,yType>::DEF_POINTS=4;
00631  template <typename xType, typename yType>
00632  const xType calc::Cube<xType,yType>::DDY_SCALE=6;
00633 
00634 /*****************************************************************************
00635  Nurb CLASS TEMPLATE
00636  *****************************************************************************/
00638 
00661  template <typename xType, typename yType>
00662  class Nurb:public Intp<xType,yType> {
00663 
00664  // Inherited Member Functions & Data Members
00665 
00666     using Intp<xType,yType>::nogo;
00667     using Intp<xType,yType>::mData;
00668     using Intp<xType,yType>::nData;
00669     using Intp<xType,yType>::nPts;
00670     using Intp<xType,yType>::cTyp;
00671     using Intp<xType,yType>::aX;
00672     using Intp<xType,yType>::aY;
00673     using Intp<xType,yType>::LO;
00674     using Intp<xType,yType>::HI;
00675     using Intp<xType,yType>::BOUND_CNT;
00676     using Intp<xType,yType>::KNOT;
00677     using Intp<xType,yType>::POLYGON;
00678     using Intp<xType,yType>::NURBS;
00679     using Intp<xType,yType>::memSet;
00680     using Intp<xType,yType>::memCopy;
00681 
00682  public:
00683 
00684  // Constructors
00685 
00686     Nurb(const xType *arX, const yType *arY, int nCount, int nPoints=DEF_POINTS);
00687     Nurb(const xType *arX, const yType *arY, const xType *arK, int nCount, int nPoints=DEF_POINTS);
00688     Nurb(const Nurb<xType,yType> &po);
00689     Nurb(const Intp<xType,yType> &in);
00690    ~Nurb(void);
00691 
00692  // Member Functions
00693 
00694     virtual bool         update     (void);
00695     virtual yType        eval       (xType x) throw (IntpErr);
00696     virtual xType       *copyArrayX (enum Intp<xType,yType>::VTYPE vType, xType *array) const;
00697     virtual yType       *copyArrayY (enum Intp<xType,yType>::VTYPE vType, yType *array) const;
00698     virtual const xType *getArrayX  (enum Intp<xType,yType>::VTYPE vType) const;
00699     virtual const yType *getArrayY  (enum Intp<xType,yType>::VTYPE vType) const;
00700     virtual int          getCount   (enum Intp<xType,yType>::VTYPE vType) const;
00701 
00702     bool setCount (int nPoints);
00703 
00704  // Static Functions
00705 
00706     static bool evalKnots (xType *arK, const xType *arX, int nCount, int nPoints=DEF_POINTS);
00707 
00708  // Data Members
00709 
00710     static const xType  VAR_SMALL;
00711     static const int    DEF_POINTS;
00712 
00713  private:
00714 
00715  // Member Functions
00716 
00717     virtual void varInit (void);
00718 
00719     bool   varAlloc  (int nPoints);
00720     int    evalIndex (xType x) const;
00721     void   evalBasis (xType x, int iKnot, xType *aBase);
00722     bool   evalMatrix(xType *aBan, yType *aVec, int nRow, int nBan, int iDiag) const;
00723 
00724  // Data Members
00725 
00726     xType  xOffset;                    
00727     xType  xScale;                     
00728     xType *xKnot;                      
00729     xType *dKnot[Base::BOUND_CNT];     
00730     xType *yBase;                      
00731     yType *yPoly;                      
00732     int    mPts;                       
00733     int    nKnot;                      
00734     bool   bKnot;                      
00736  };
00737 
00738 /*****************************************************************************/
00739 
00741  template <typename xType, typename yType>
00742  const xType calc::Nurb<xType,yType>::VAR_SMALL=1.0E-20;
00744  template <typename xType, typename yType>
00745  const int calc::Nurb<xType,yType>::DEF_POINTS=4;
00746 
00747 /*****************************************************************************
00748  Poly CLASS TEMPLATE
00749  *****************************************************************************/
00751 
00774  template <typename xType, typename yType>
00775  class Poly:public Intp<xType,yType> {
00776 
00777  // Inherited Member Functions & Data Members
00778 
00779     using Intp<xType,yType>::nogo;
00780     using Intp<xType,yType>::mData;
00781     using Intp<xType,yType>::nData;
00782     using Intp<xType,yType>::nPts;
00783     using Intp<xType,yType>::cTyp;
00784     using Intp<xType,yType>::bInc;
00785     using Intp<xType,yType>::aX;
00786     using Intp<xType,yType>::aY;
00787     using Intp<xType,yType>::LO;
00788     using Intp<xType,yType>::HI;
00789     using Intp<xType,yType>::POLYNOMIAL;
00790     using Intp<xType,yType>::memCopy;
00791 
00792  public:
00793 
00794  // Constructors
00795 
00796     Poly(const xType *arX, const yType *arY, int nCount, int nPoints=DEF_POINTS);
00797     Poly(const Poly<xType,yType> &po);
00798     Poly(const Intp<xType,yType> &in);
00799    ~Poly(void);
00800 
00801  // Member Functions
00802 
00803     virtual yType eval (xType x) throw (IntpErr);
00804 
00805     bool   setCount (int nPoints);
00806 
00814     xType getError(void) const {return yErr;}
00815 
00816  // Data Members
00817 
00818     static const int DEF_POINTS;
00819 
00820  private:
00821 
00822  // Member Functions
00823 
00824     virtual void varInit  (void);
00825 
00826     bool   varAlloc (int nPoints);
00827     yType  evalPoly (const xType *arX, const yType *arY, xType x) throw (IntpErr);
00828 
00829  // Data Members
00830 
00831     yType  *yDel[Base::BOUND_CNT];  
00832     xType   yErr;                   
00833     int     nBnd[Base::BOUND_CNT];  
00834  };}
00835 
00836 /*****************************************************************************/
00837 
00839  template <typename xType, typename yType>
00840  const int calc::Poly<xType,yType>::DEF_POINTS=4;
00841 
00842 /*****************************************************************************
00843  PREPROCESSOR DIRECTIVES
00844  *****************************************************************************/
00845 
00846  #endif
00847 
00848 /*****************************************************************************
00849  CLASS TEMPLATE SOURCE
00850  *****************************************************************************/
00851 
00852  #include "Intp.cpp"
00853  #include "Cube.cpp"
00854  #include "Nurb.cpp"
00855  #include "Poly.cpp"
00856 
00857 /*****************************************************************************/

Generated on Wed Jul 19 09:23:35 2006 for CalcLib by  doxygen 1.4.7