00001
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
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
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
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
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
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
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
00077
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
00092
00093
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
00099 float AEDH = AE * floatY + DH * (1-floatY);
00100 float BFCG = BF * floatY + CG * (1-floatY);
00101
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
00111 Data(const Data& other);
00112 };
00113
00114 #endif