00001 #ifndef VideoExcel_TableDataSourceImageDir_h
00002 #define VideoExcel_TableDataSourceImageDir_h
00003
00004 #include "TableDataSource.h"
00005 #include "Core/Array/ReadFile.h"
00006 #include "Core/Stream/RgbDataSrcRaw.h"
00007 #include "Util/DirImageFileNames.h"
00008
00009 namespace Impala {
00010 namespace Application {
00011 namespace VideoExcel {
00012
00013 class TableDataSourceImageDir : public TableDataSource
00014 {
00015 public:
00016 typedef Impala::Core::Stream::RgbDataSrcRaw RgbDataSrcRaw;
00017
00018 TableDataSourceImageDir(CString directory):
00019 TableDataSource()
00020 {
00021 Init();
00022 OpenDir(directory);
00023
00024 SetSortColumn("filename", TableDataSource::TYPE_TEXT);
00025 }
00026
00027 ~TableDataSourceImageDir()
00028 {
00029 ClearFiles();
00030 }
00031
00032 void OpenDir(CString dirName)
00033 {
00034 ClearFiles();
00035
00036 mDirName = dirName;
00037 String ext = FileNameExt(dirName,true);
00038
00039 if (ext == "raw")
00040 mRgbDataSrcRaw = new RgbDataSrcRaw(dirName);
00041 else
00042 Util::DirImageFileNames(dirName, mFileNames);
00043
00044 if (mRgbDataSrcRaw)
00045 mTotalRows = mRgbDataSrcRaw->LastFrame();
00046 else
00047 mTotalRows = mFileNames.size();
00048 mFilteredRows = mTotalRows;
00049 }
00050
00051 void ClearFiles()
00052 {
00053 if (mRgbDataSrcRaw)
00054 {
00055 delete mRgbDataSrcRaw;
00056 mRgbDataSrcRaw = 0;
00057 }
00058 for (unsigned int i=0 ; i<mFileNames.size() ; i++)
00059 delete mFileNames[i];
00060 mFileNames.clear();
00061 }
00062
00063
00064 virtual String
00065 GetTextDataByID(String column, int row)
00066 {
00067 if (column == "filename")
00068 {
00069 if (!mRgbDataSrcRaw)
00070 return *mFileNames[row];
00071 return String("raw:") + MakeString(row);
00072 }
00073 if (column == "id")
00074 return MakeString(row);
00075 return "N/A";
00076 }
00077
00078
00079
00080
00081
00082
00083
00084 virtual double
00085 GetNormalizedDataByID(String column, int row)
00086 {
00087 double v = row / (double)mTotalRows;
00088 if (column == "red")
00089 return v;
00090 if (column == "green")
00091 return 1.0 - v;
00092 if (column == "blue") {
00093 return (row % 10) / 10.0;
00094 }
00095 return 0.0;
00096 }
00097
00098 virtual Array2dVec3UInt8*
00099 GetImageDataByID(String colum, int row)
00100 {
00101 Array2dVec3UInt8* ar = 0;
00102 if (mRgbDataSrcRaw)
00103 {
00104 mRgbDataSrcRaw->GotoFrame(row);
00105 int imW = mRgbDataSrcRaw->FrameWidth();
00106 int imH = mRgbDataSrcRaw->FrameHeight();
00107 ar = new Array2dVec3UInt8(imW, imH, 0, 0, 0, false);
00108 memcpy((void *)ar->CPB(0, 0), mRgbDataSrcRaw->DataPtr(), imW*imH*3);
00109 }
00110 else
00111 {
00112 String fName = mDirName + "/" + *mFileNames[row];
00113 Core::Array::ReadFile(ar, fName, &Util::Database::GetInstance());
00114 if (ar == 0)
00115 ILOG_WARN("Could not read file: " << fName);
00116 }
00117 return ar;
00118 }
00119
00120 private:
00121
00122 void Init()
00123 {
00124 mRgbDataSrcRaw = 0;
00125
00126 AddStaticColumn("id", TYPE_TEXT, 50);
00127 AddStaticColumn("image", TYPE_IMAGE, 120);
00128 AddStaticColumn("filename", TYPE_TEXT, 300);
00129 AddColumn("red", TYPE_NORMALIZEDVALUE, 50, 1);
00130 AddColumn("green", TYPE_NORMALIZEDVALUE, 50, 2);
00131 AddColumn("blue", TYPE_NORMALIZEDVALUE, 50, 3);
00132 AddColumn("red", TYPE_NORMALIZEDVALUE, 50, 1);
00133 AddColumn("green", TYPE_NORMALIZEDVALUE, 50, 2);
00134 AddColumn("blue", TYPE_NORMALIZEDVALUE, 50, 3);
00135 }
00136
00137 String mDirName;
00138 RgbDataSrcRaw* mRgbDataSrcRaw;
00139 std::vector<String*> mFileNames;
00140
00141 ILOG_VAR_DEC;
00142 };
00143
00144 ILOG_VAR_INIT(TableDataSourceImageDir, Application.VideoExcel);
00145
00146 }
00147 }
00148 }
00149
00150 #endif // TableDataSourceImageDir_h