Data.h

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

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