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 
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                 A-------B
00075                 |       |       |
00076                 |---*   |
00077                 |               |
00078                 D-------C
00079                 */      
00080                                 
00081                 //printf("pos(%f, %f, 0)\n",aX,aY);
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                 //printf("A(%f, %f, %f)\n",A.x(),A.y(), A.z());
00090                 //printf("B(%f, %f, %f)\n",B.x(),B.y(), B.z());
00091                 //printf("C(%f, %f, %f)\n",C.x(),C.y(), C.z());
00092                 //printf("D(%f, %f, %f)\n",D.x(),D.y(), D.z());
00093 
00094                 const Vector<float>& upperLeft = getPosition(mCurrentX,mCurrentY);
00095 //              const Vector<float>& lowerRight = getPosition(mCurrentX+1, mCurrentY +1);
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 //              float xCellDiff = lowerRight.x() - upperLeft.x();
00105 //              float yCellDiff = lowerRight.y() - upperLeft.y(); 
00106 
00107                 
00108                 //printf("xDiff: %f\n",xDiff);
00109                 //printf("yDiff: %f\n",yDiff);
00110                 //printf("xCellDiff: %f\n",xCellDiff);
00111                 //printf("yCellDiff: %f\n",yCellDiff);
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 //              const Vector<float>& result = AD * xDiff / xCellDiff + BC * (xCellDiff - xDiff)/ xCellDiff;
00117                 //printf("result(%f, %f, %f)\n",result.x(),result.y(), result.z());
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 //              printf("maxPos %i %i\n",mX,mY);
00144                 return getDataPoint(mX-1,mY-1).getPosition();
00145         }
00146 
00152         std::pair<float, float> getDataRange(unsigned int aDataIndex) const {
00153 //              printf("aDataIndex: %i; countDataPieces(): %i\n",aDataIndex, countDataPieces());
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                 //printf("\nnewDataIndex\n");
00205                 
00206                 //printf("pos(%f, %f, 0)",aX ,aY);
00207                 //printf("upperLeft(%f, %f, %f)\n",upperLeft.x(),upperLeft.y(), upperLeft.z());
00208                 //printf("lowerRight(%f, %f, %f)\n",lowerRight.x(),lowerRight.y(), lowerRight.z());             
00209                 
00210                 //printf("Index: %i %i\n",mCurrentX, mCurrentY);
00211                 
00212                 if ((upperLeft.x()> aX)||(upperLeft.y()> aY)||(lowerRight.x()< aX)||(lowerRight.y()< aY)){//we are in another cell
00213                         //printf("newCell!!\n");
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                 //upperLeft = getPosition(mCurrentX,mCurrentY);
00230                 //lowerRight = getPosition(mCurrentX+1, mCurrentY+1);
00231 
00232                 //printf(" Index: %i %i\n",mCurrentX, mCurrentY);       
00233                 //printf("upperLeft(%f, %f, %f)\n",upperLeft.x(),upperLeft.y(), upperLeft.z());
00234                 //printf("lowerRight(%f, %f, %f)\n",lowerRight.x(),lowerRight.y(), lowerRight.z());
00235                 //printf("\n");
00236         }
00237 
00238         DataPoint* mData;
00239         float* mXCellDiff;
00240         float* mYCellDiff;
00241         
00242         mutable unsigned int mCurrentX;//needed to optimize requests in world coords.
00243         mutable unsigned int mCurrentY;//needed to optimize requests in world coords.
00244 
00245         
00246         typedef std::vector< std::pair<float, float> > RangeType;
00247         RangeType mDataRanges;
00248 
00249         unsigned int mX, mY;
00250         unsigned int mDataCount; //< Number of additional data pieces
00251 
00252         // Not to be implemented
00253         Data(const Data& other);
00254         Data& operator=(Data& other);
00255 };
00256 
00257 #endif

Generated on Mon Jan 23 19:44:27 2006 for Visualization by  doxygen 1.4.6