Gradient.h

Go to the documentation of this file.
00001 #ifndef GRADIENT_H_
00002 #define GRADIENT_H_
00003 
00004 #include <string>
00005 #include "Vector.h"
00006 #include "Data.h"
00007 
00013 class Gradient {
00014 public:
00015         Gradient(Data* input, Vector<> boundaryValues = Vector<>(0,0,0));
00016         ~Gradient();
00017 
00018         // Sizes in x/y/z dimension
00019         unsigned short xdim() const { return mX; }
00020         unsigned short ydim() const { return mY; }
00021         unsigned short zdim() const { return mZ; }
00022 
00023         Vector<> getData(unsigned int aX, unsigned int aY, unsigned int aZ) const{
00024                 assert(aX < mX);
00025                 assert(aY < mY);
00026                 assert(aZ < mZ);
00027 
00028                 const unsigned int Ystride = mX;
00029                 const unsigned int Zstride = Ystride * mY;
00030 
00031                 return mData[aZ * Zstride + aY * Ystride + aX];
00032         }
00033         
00034         Vector<> getData_RangeCheck(int aX, int aY, int aZ){
00035                 
00036         //      printf("%ix%ix%i\n",aX,aY,aZ);
00037                 if ((aX<0) || (aX>=mX)) return Vector<>(0,0,0);
00038                 if ((aY<0) || (aY>=mY)) return Vector<>(0,0,0);
00039                 if ((aZ<0) || (aZ>=mZ)) return Vector<>(0,0,0);
00040 
00041 //              return getData((unsigned int) aX, (unsigned int) aY, (unsigned int) aZ);
00042                 const unsigned int Ystride = (unsigned int) mX;
00043                 const unsigned int Zstride = (unsigned int) Ystride * mY;
00044 
00045                 return mData[aZ * Zstride + aY * Ystride + aX];         
00046         }
00047         
00048         Vector<> getDataTrilinearInterpolated(float aX, float aY, float aZ){
00049 /*
00050 Trilinear interpolation. cube-corners:
00051   E-----F
00052  /|    /| 
00053 A-----B |                               Y  Z
00054 | H---|-G                               | /
00055 |/        |/                            |/
00056 D-----C                                 ---X
00057 
00058 1.Step: 4 * interpolate Z-Pos.
00059 2.Step: 2 * interpolate Y-Pos.
00060 3.Step: 1 *     interpolate X-Pos.
00061 
00062 */
00063                         
00064         //      printf("Input: %f %f %f\n",aX,aY,aZ);
00065                 int lowerX = (int) floor(aX);
00066                 int lowerY = (int) floor(aY);
00067                 int lowerZ = (int) floor(aZ);
00068                 int upperX = lowerX+1;
00069                 int upperY = lowerY+1;
00070                 int upperZ = lowerZ+1;
00071         //      printf("Output: %i %i %i\n", lowerX,lowerY,lowerZ);
00072         //define cube corners:
00073                 Vector<> A = getData_RangeCheck(lowerX, upperY, lowerZ);
00074                 Vector<> B = getData_RangeCheck(upperX, upperY, lowerZ);                
00075                 Vector<> C = getData_RangeCheck(upperX, lowerY, lowerZ);
00076                 Vector<> D = getData_RangeCheck(lowerX, lowerY, lowerZ);
00077 
00078                 Vector<> E = getData_RangeCheck(lowerX, upperY, upperZ);
00079                 Vector<> F = getData_RangeCheck(upperX, upperY, upperZ);
00080                 Vector<> G = getData_RangeCheck(upperX, lowerY, upperZ);
00081                 Vector<> H = getData_RangeCheck(lowerX, lowerY, upperZ);
00082         
00083                 float floatX = aX - lowerX;
00084                 float floatY = aY - lowerY;
00085                 float floatZ = aZ - lowerZ;
00086         //      printf("Floats: %f %f %f\n\n",floatX,floatY,floatZ);            
00087 
00088 //      1.Step:
00089         //      Vector<> AE = Vector<> (E.x() * floatZ + A.x() * (1-floatZ) , E.y() * floatZ + A.y() * (1-floatZ) , E.z() * floatZ + A.z() * (1-floatZ) );
00090         //      Vector<> BF = Vector<> (F.x() * floatZ + B.x() * (1-floatZ) , F.y() * floatZ + B.y() * (1-floatZ) , F.z() * floatZ + B.z() * (1-floatZ) );
00091         //      Vector<> CG = Vector<> (G.x() * floatZ + C.x() * (1-floatZ) , G.y() * floatZ + C.y() * (1-floatZ) , G.z() * floatZ + C.z() * (1-floatZ) );
00092 
00093                 Vector<> AE = E * floatZ + A * (1-floatZ);
00094                 Vector<> BF = F * floatZ + B * (1-floatZ);
00095                 Vector<> CG = G * floatZ + C * (1-floatZ);
00096 
00097                 Vector<> DH = H * floatZ + D * (1-floatZ);
00098 //      2.Step:
00099                 Vector<> AEDH = AE * floatY + DH * (1-floatY);
00100                 Vector<> BFCG = BF * floatY + CG * (1-floatY);
00101 //      3.Step:
00102                 return (BFCG * floatX + AEDH * (1-floatX)).normalized();
00103         }
00104 
00105         
00106         
00107 
00108 private:
00109         Vector<>* mData;
00110         
00111         Vector<> mBoundaryValues;
00112 
00113         unsigned short mX, mY, mZ;
00114         
00115 };
00116 
00117 #endif

Generated on Mon Dec 19 00:13:20 2005 for Visualization by  doxygen 1.4.5