Home || Visual Search || Applications || Architecture || Important Messages || OGL || Src

Grid.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_Feature_Grid_h
00002 #define Impala_Core_Feature_Grid_h
00003 
00004 #include "Basis/String.h"
00005 #include "Core/Database/RawDataSet.h"
00006 #include "Core/Feature/FeatureDefinition.h"
00007 #include "Core/VideoSet/VideoSet.h"
00008 #include "Core/Array/WritePng.h"
00009 
00010 // comment this line when commit to impala
00011 //#define __BITMAP_FUNC__
00012 
00013 #ifdef __BITMAP_FUNC__
00014 #include "Core/Feature/Bitmap.h"
00015 #endif
00016 
00017 #ifndef BYTE
00018 #define BYTE unsigned char
00019 #endif
00020 
00021 #ifndef BOOL
00022 #define BOOL bool
00023 #endif
00024 
00025 #ifndef UINT
00026 #define UINT unsigned int
00027 #endif
00028 
00029 
00030 namespace Impala
00031 {
00032 namespace Core
00033 {
00034 namespace Feature
00035 {
00036 
00037 
00038 class Grid
00039 {
00040 public:
00041 
00042     Grid()
00043     {
00044     }
00045 
00046     Grid(int nRow, int nCol)
00047     {
00048         mRow = nRow;
00049         mCol = nCol;
00050     }
00051     
00052     ~Grid()
00053     {
00054     }
00055 
00056     String
00057     GetName() const
00058     {
00059         return mName;
00060     }
00061 
00062     // have verified for 2x2, 4x4, 2x4, 4x2, 
00063     // not yet: 3x3
00064     void
00065     RetrievalGridBuffers(BYTE* im, BYTE** buf_list, int nWidth, int nHeight, Core::VideoSet::VideoSet* vs = NULL)
00066     {
00067         String fileName;
00068 
00069 #ifdef __BITMAP_FUNC__
00070         //Core::Feature::Bitmap bitmap;
00071         //bitmap.SaveRgb2BitmapFile("rgb_00.bmp", im, nWidth, nHeight);
00072 
00073         Array::Array2dVec3UInt8* buf = Array::ArrayCreate<Array::Array2dVec3UInt8>
00074                     (nWidth, nHeight, 0, 0, im, true);
00075         fileName = "rgb_00.png";
00076         Core::Array::WritePng(buf, fileName, vs->GetDatabase());
00077 #endif
00078 
00079         //--------------
00080         //   1   |   2
00081         //--------------
00082         //   3   |   4
00083         //--------------
00084         for (int x=0; x<mRow; x++)
00085         {
00086             for (int y=0; y<mCol; y++)
00087             {
00088                 int nFrameWidth = nWidth;
00089                 int nFrameHeight = nHeight;
00090 
00091                 int nGridWidth = nWidth/mCol;
00092                 int nGridHeight = nHeight/mRow;
00093 
00094                 int idx = y+x*mCol;
00095 
00096                 BYTE* cur_buf = buf_list[idx];
00097                 // process each row of the buffer
00098                 for (int j=0; j<nGridHeight; j++)
00099                 {
00100                     int nCurSize = nGridWidth*3*sizeof(BYTE);
00101 
00102                     //memcpy(cur_buf + j*nGridWidth*3, im + j*nFrameWidth*3, nCurSize);
00103                     BYTE* dst = cur_buf + j*nGridWidth*3;
00104                     //BYTE* src = im + j*nFrameWidth*3 + (nGridWidth*3*y+x*nGridWidth*nGridHeight*3*2);
00105                     int nFrameRowOffset1 = (nGridHeight * x) * nFrameWidth * 3; // three entry points
00106                     int nFrameRowOffset2 = j * nFrameWidth * 3;                 // within one grid row
00107                     int nFrameColOffset = nGridWidth * y * 3;                   // in column dimension   
00108                     
00109                     int nOffset = nFrameRowOffset1 + nFrameRowOffset2 + nFrameColOffset;
00110                     BYTE* src = im + nOffset;
00111                     memcpy(dst, src, nCurSize);
00112                 }
00113 
00114                 //verificatiion of the buffers
00115 #ifdef __BITMAP_FUNC__
00116                 String idxStr;
00117                 char index[128];
00118                 itoa(idx+1,index,10);
00119                 idxStr = index;
00120                 fileName = "rgb_grid_0" + idxStr + ".bmp";
00121 
00122                 //Core::Feature::Bitmap bitmap;
00123                 //bitmap.SaveRgb2BitmapFile(fileName.c_str(), cur_buf, nGridWidth, nGridHeight);
00124 
00125                 Array::Array2dVec3UInt8* sc = Array::ArrayCreate<Array::Array2dVec3UInt8>
00126                     (nGridWidth, nGridHeight, 0, 0, cur_buf, true);
00127                 fileName = "rgb_grid_0" + idxStr + ".png";
00128                 Core::Array::WritePng(sc, fileName, vs->GetDatabase());
00129 #endif
00130             }
00131         }
00132 
00133     }
00134 
00135 
00136 private:
00137 
00138     String                mName;
00139     int                   mRow;
00140     int                   mCol;
00141 
00142 };
00143 
00144 } // namespace Feature
00145 } // namespace Core
00146 } // namespace Impala
00147 
00148 #endif

Generated on Thu Jan 13 09:04:24 2011 for ImpalaSrc by  doxygen 1.5.1