00001
00002
00003 #ifndef DATA_H_
00004 #define DATA_H_
00005
00006 #include <string>
00007 #include <stdio.h>
00008 #include <math.h>
00009
00010 #include "DataPoint.h"
00011
00015 class Data {
00016 public:
00021 Data(const std::string& aFilename);
00022 ~Data();
00023
00025 unsigned int xdim() const { return mX; }
00027 unsigned int ydim() const { return mY; }
00028
00033 Vector<float> getData( unsigned int aX,
00034 unsigned int aY) const {
00035 return getDataPoint(aX, aY).getFlow();
00036 }
00037
00038
00042 int getDataCount(){return mDataCount;}
00043
00047 float getDataPiece(float aX, float aY, unsigned int aDataIndex) const{
00048 newDataIndex(aX,aY);
00049
00050 float A = getDataPiece(mCurrentX, mCurrentY, aDataIndex);
00051 float B = getDataPiece(mCurrentX+1, mCurrentY, aDataIndex);
00052 float C = getDataPiece(mCurrentX+1, mCurrentY+1, aDataIndex);
00053 float D = getDataPiece(mCurrentX, mCurrentY+1, aDataIndex);
00054
00055 const Vector<float>& upperLeft = getPosition(mCurrentX,mCurrentY);
00056
00057 float xDiff = aX - upperLeft.x();
00058 float yDiff = aY - upperLeft.y();
00059
00060 float xCellDiff = mXCellDiff[mCurrentX];
00061 float yCellDiff = mYCellDiff[mCurrentY];
00062
00063 float AD = A * yDiff / yCellDiff + D * (yCellDiff - yDiff) / yCellDiff;
00064 float BC = B * yDiff / yCellDiff + C * (yCellDiff - yDiff) / yCellDiff;
00065
00066 return AD * xDiff / xCellDiff + BC * (xCellDiff - xDiff)/ xCellDiff;
00067 }
00068
00072 Vector<float> getFlow(float aX, float aY) const{
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 newDataIndex(aX,aY);
00083
00084 const Vector<float>& A = getFlow(mCurrentX, mCurrentY);
00085 const Vector<float>& B = getFlow(mCurrentX+1, mCurrentY);
00086 const Vector<float>& C = getFlow(mCurrentX+1, mCurrentY+1);
00087 const Vector<float>& D = getFlow(mCurrentX, mCurrentY+1);
00088
00089
00090
00091
00092
00093
00094 const Vector<float>& upperLeft = getPosition(mCurrentX,mCurrentY);
00095
00096
00097
00098 float xDiff = aX - upperLeft.x();
00099 float yDiff = aY - upperLeft.y();
00100
00101 float xCellDiff = mXCellDiff[mCurrentX];
00102 float yCellDiff = mYCellDiff[mCurrentY];
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 const Vector<float>& AD = A * yDiff / yCellDiff + D * (yCellDiff - yDiff) / yCellDiff;
00114 const Vector<float>& BC = B * yDiff / yCellDiff + C * (yCellDiff - yDiff) / yCellDiff;
00115
00116
00117
00118
00119 return AD * xDiff / xCellDiff + BC * (xCellDiff - xDiff)/ xCellDiff;
00120 }
00121
00126 unsigned int countDataPieces() const {
00127 return mDataCount;
00128 }
00129
00134 Vector<float> minPos() const {
00135 return getDataPoint(0,0).getPosition();
00136 }
00137
00142 Vector<float> maxPos() const {
00143
00144 return getDataPoint(mX-1,mY-1).getPosition();
00145 }
00146
00152 std::pair<float, float> getDataRange(unsigned int aDataIndex) const {
00153
00154 assert(aDataIndex < countDataPieces());
00155 return mDataRanges[aDataIndex];
00156 }
00157
00158 private:
00159 DataPoint& getDataPoint(unsigned int aX, unsigned int aY) const {
00160
00161 if (aX>= mX) printf("aX = %i mX = %i\n",aX,mX);
00162 if (aY>= mY) printf("aX = %i mX = %i\n",aX,mX);
00163
00164 assert(aX < mX);
00165 assert(aY < mY);
00166 return mData[aY * mX + aX];
00167 }
00168
00173 float getDataPiece(unsigned int aX,
00174 unsigned int aY,
00175 unsigned int aDataIndex) const {
00176 const DataPoint& p = getDataPoint(aX, aY);
00177 assert(p.countDataPieces() == mDataCount);
00178 return p.getDataPiece(aDataIndex);
00179 }
00180
00185 Vector<float> getPosition(unsigned int aX, unsigned int aY) const{
00186 return getDataPoint(aX,aY).getPosition();
00187 }
00188
00189 Vector<float> getFlow(unsigned int aX, unsigned int aY) const {
00190 return getDataPoint(aX,aY).getFlow();
00191 }
00192
00199 void newDataIndex(float aX, float aY) const{
00200
00201 Vector<float> upperLeft = getPosition(mCurrentX,mCurrentY);
00202 Vector<float> lowerRight = getPosition(mCurrentX+1, mCurrentY+1);
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212 if ((upperLeft.x()> aX)||(upperLeft.y()> aY)||(lowerRight.x()< aX)||(lowerRight.y()< aY)){
00213
00214
00215 while ((mCurrentX > 0) && (getPosition(mCurrentX,mCurrentY).x()> aX)){
00216 mCurrentX--;
00217 }
00218 while ((mCurrentX < mX-2) && (getPosition(mCurrentX + 1,mCurrentY + 1).x()< aX)){
00219 mCurrentX++;
00220 }
00221 while ((mCurrentY > 0) && (getPosition(mCurrentX,mCurrentY).y()> aY)){
00222 mCurrentY--;
00223 }
00224 while ((mCurrentY < mY-2) && (getPosition(mCurrentX + 1,mCurrentY + 1).y()< aY)){
00225 mCurrentY++;
00226 }
00227 }
00228
00229
00230
00231
00232
00233
00234
00235
00236 }
00237
00238 DataPoint* mData;
00239 float* mXCellDiff;
00240 float* mYCellDiff;
00241
00242 mutable unsigned int mCurrentX;
00243 mutable unsigned int mCurrentY;
00244
00245
00246 typedef std::vector< std::pair<float, float> > RangeType;
00247 RangeType mDataRanges;
00248
00249 unsigned int mX, mY;
00250 unsigned int mDataCount;
00251
00252
00253 Data(const Data& other);
00254 Data& operator=(Data& other);
00255 };
00256
00257 #endif