Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

/home/slang/XVision2/src/Tools/XVAffineWarp.h

00001 // *** BEGIN_XVISION2_COPYRIGHT_NOTICE ***
00002 // *** END_XVISION2_COPYRIGHT_NOTICE ***
00003 
00019 #ifndef _XVAFFINEWARP_H_
00020 #define _XVAFFINEWARP_H_
00021 
00022 #include <iostream>
00023 #include <math.h>
00024 #include <string>
00025 
00026 #include <XVMacros.h>
00027 #include <XVTools.h>
00028 #include <XVImageBase.h>
00029 #include <XVImageIterator.h>
00030 
00031 #define INVERSE 1
00032 #define FORWARD 0
00033 
00034 #include <XVMatrix.h>
00035 
00037 class XVAffineMatrix {
00038 
00039  public:
00040 
00041   float a;
00042   float b;
00043   float c;
00044   float d;
00045 
00046   XVAffineMatrix(float a0, float b0, float c0, float d0) : a(a0), b(b0), c(c0), d(d0) {}
00047   XVAffineMatrix() : a(0),b(0),c(0),d(0){}
00048   XVAffineMatrix(double angle) {
00049     a = cos(angle);
00050     b = -sin(angle);
00051     c = sin(angle);
00052     d = cos(angle);
00053   }
00054 
00055   XVAffineMatrix(double sx, double sy) {
00056     a = sx;  d = sy; b = c = 0;
00057   };
00058 
00059   XVAffineMatrix(double sh, double d1, double d2){
00060     a = d = 1;  c = 0; b = sh;
00061   };
00062 
00063   XVAffineMatrix(const XVMatrix & m){
00064     a = m[0][0];
00065     b = m[0][1];
00066     c = m[1][0];
00067     d = m[1][1];
00068   };
00069 
00070   operator XVMatrix () {
00071     XVMatrix m(2, 2);  
00072     m[0][0] = a;  
00073     m[0][1] = b;
00074     m[1][0] = c;
00075     m[1][1] = d;
00076   };
00077 
00078   float det(){ return (a * d - b * c); }
00079 
00080   XVAffineMatrix i(){ 
00081     float det = this->det(); 
00082     XVAffineMatrix mat; 
00083     mat.a = d / det;
00084     mat.b = - b / det;
00085     mat.c = - c / det;
00086     mat.d = a / det;
00087     return mat;
00088   }
00089 
00090   XVAffineMatrix t(){
00091     XVAffineMatrix m;  
00092     m.a = this->a;  
00093     m.b = this->c;
00094     m.c = this->b;
00095     m.d = this->d;
00096   }
00097 };
00098 
00099 XVAffineMatrix operator * (const XVAffineMatrix & m1, const XVAffineMatrix & m2);
00100 
00101 #include <XVGeometry.h>
00102 typedef XV2Vec<float> XVCoord2D;
00103 
00104 XVCoord2D operator * (XVAffineMatrix mat, XVCoord2D vec);
00105 
00106 //------------------------------------------------------------------------
00107 //  XVAffineWarp Class Declaration
00108 //------------------------------------------------------------------------
00109 
00110 template <class T>
00111 class XVAffineWarp {
00112 private:
00113 
00115   XVAffineMatrix amatrix;
00117   float ratio;
00118 
00119   void invertMatrix();
00120 
00121 public:
00123   XVAffineWarp (float);      
00125   XVAffineWarp (float, float);  
00127   XVAffineWarp (float, float, float);  
00129   XVAffineWarp (float, float, float, float); 
00131   XVSize sizeNeeded (const XVImageBase<T> &); 
00132   void findBounds(const XVCoord2D &, const XVSize &, 
00133             XVCoord2D &, XVCoord2D &, XVCoord2D &, XVCoord2D &);
00135   XVImageBase<T> & warp (const XVImageBase<T> &, XVImageBase<T> &, 
00136                 const XVCoord2D &, int DIREC = INVERSE);
00137 
00139   XVImageBase<T> & reverseWarp (const XVImageBase<T> &, XVImageBase<T> &, 
00140                     const XVCoord2D &);
00141 
00143   XVCoord2D transform (XVCoord2D);
00145   void print();       
00146 };
00147 
00148 #include <XVAffineWarp.icc>
00149 #endif

Generated at Thu Mar 29 22:37:28 2001 for XVision by doxygen1.2.0 written by Dimitri van Heesch, © 1997-2000