00001 #ifndef Impala_Core_VideoSet_Stills_h
00002 #define Impala_Core_VideoSet_Stills_h
00003
00004 #include "Core/Table/MakeGroupIndex.h"
00005 #include "Core/VideoSet/VideoSet.h"
00006
00007 #include "Core/Table/TableTem.h"
00008 #include "Core/Table/Read.h"
00009 #include "Core/Table/Write.h"
00010 #include "Core/Table/RemoveRow.h"
00011 #include "Core/Column/Find.h"
00012
00013 namespace Impala
00014 {
00015 namespace Core
00016 {
00017 namespace VideoSet
00018 {
00019
00020
00021 typedef Table::TableTem<Column::ColumnTem<Int32>,
00022 Column::ColumnTem<Int32>,
00023 Column::ColumnTem<Int32>,
00024 Column::ColumnTem<String> > StillsBaseType;
00025
00026
00027 class Stills : public StillsBaseType
00028 {
00029 typedef Impala::Core::Table::GroupIndex GroupIndex;
00030
00031 public:
00032
00033 Stills(VideoSet* vidSet, String name) : StillsBaseType(0)
00034 {
00035 mVidSet = vidSet;
00036 mName = name;
00037 mVideoGroups = 0;
00038 mShotGroups = 0;
00039 SetColName(1, "videoId");
00040 SetColName(2, "shotId");
00041 SetColName(3, "frameNr");
00042 SetColName(4, "name");
00043 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00044 if (!mName.empty())
00045 Load();
00046 #else // REPOSITORY_USED
00047 if (!mName.empty())
00048 ILOG_ERROR("Load stills via repository");
00049 #endif // REPOSITORY_USED
00050 }
00051
00052
00053
00054 int
00055 GetNrStills()
00056 {
00057 return Size();
00058 }
00059
00060 int
00061 GetVideoId(int stillId)
00062 {
00063 return Get1(stillId);
00064 }
00065
00066 int
00067 GetShotId(int stillId)
00068 {
00069 return Get2(stillId);
00070 }
00071
00072 String
00073 GetName(int stillId)
00074 {
00075 return Get4(stillId);
00076 }
00077
00078 int
00079 GetFrameNr(int stillId)
00080 {
00081 return Get3(stillId);
00082 }
00083
00084 int
00085 GetFrameId(String name)
00086 {
00087 int rank = Find(GetColumn4(), name, 0, Size());
00088 if (rank == Size())
00089 return -1;
00090 return rank;
00091 }
00092
00093
00094 int
00095 GetFrameId(int frameNr, int idxStart, int idxEnd)
00096 {
00097 int rank = Find(GetColumn3(), frameNr, idxStart, idxEnd);
00098 if (rank == idxEnd)
00099 return -1;
00100 return rank;
00101 }
00102
00103 VideoSet*
00104 GetVideoSet()
00105 {
00106 return mVidSet;
00107 }
00108
00109
00110
00111 void
00112 UpdateGroups()
00113 {
00114 if (mVideoGroups == 0)
00115 {
00116 mVideoGroups = new GroupIndex(0);
00117 mVideoGroups->SetColName(1, "firstStillId");
00118 mVideoGroups->SetColName(2, "nrStills");
00119 }
00120 MakeGroupIndex(mVideoGroups, GetColumn1(), 0, Size());
00121 if (mShotGroups == 0)
00122 {
00123 mShotGroups = new GroupIndex(0);
00124 mShotGroups->SetColName(1, "firstStillId");
00125 mShotGroups->SetColName(2, "nrStills");
00126 }
00127
00128 MakeGroupIndex(mShotGroups, GetColumn2(), 0, Size());
00129 }
00130
00131 int
00132 GetNrVideos()
00133 {
00134 return mVideoGroups->Size();
00135 }
00136
00137 int
00138 GetFirstStillVideo(int videoId)
00139 {
00140 return mVideoGroups->Get1(videoId);
00141 }
00142
00143 int
00144 GetNrStillsVideo(int videoId)
00145 {
00146 return mVideoGroups->Get2(videoId);
00147 }
00148
00149 int
00150 GetFrameIdVideo(int videoId, int frameNr)
00151 {
00152 int start = GetFirstStillVideo(videoId);
00153 int nr = GetNrStillsVideo(videoId);
00154 return GetFrameId(frameNr, start, start+nr);
00155 }
00156
00157 int
00158 GetNrShots()
00159 {
00160 return mShotGroups->Size();
00161 }
00162
00163 int
00164 GetFirstStillShot(int shotId)
00165 {
00166 return mShotGroups->Get1(shotId);
00167 }
00168
00169 int
00170 GetNrStillsShot(int shotId)
00171 {
00172 return mShotGroups->Get2(shotId);
00173 }
00174
00175
00176
00177 int
00178 Diff(Stills* arg)
00179 {
00180 if (GetNrStills() != arg->GetNrStills())
00181 {
00182 ILOG_ERROR("Diff: nrStills differs: " << GetNrStills() << " vs " <<
00183 arg->GetNrStills());
00184 return 1;
00185 }
00186 int nDiff = 0;
00187 for (int i=0 ; i<GetNrStills() ; i++)
00188 {
00189 if (GetVideoId(i) != arg->GetVideoId(i))
00190 {
00191 ILOG_DEBUG("Id " << i << " differs " << GetVideoId(i) <<
00192 " vs " << arg->GetVideoId(i));
00193 nDiff++;
00194 }
00195 else if (GetShotId(i) != arg->GetShotId(i))
00196 {
00197 ILOG_DEBUG("Shot " << i << " differs " << GetShotId(i) <<
00198 " vs " << arg->GetShotId(i));
00199 nDiff++;
00200 }
00201 else if (GetFrameNr(i) != arg->GetFrameNr(i))
00202 {
00203 ILOG_DEBUG("Frame " << i << " differs " << GetFrameNr(i) <<
00204 " vs " << arg->GetFrameNr(i));
00205 nDiff++;
00206 }
00207 else if (GetName(i) != arg->GetName(i))
00208 {
00209 ILOG_DEBUG("Name " << i << " differs " << GetName(i) <<
00210 " vs " << arg->GetName(i));
00211 nDiff++;
00212 }
00213 }
00214 if (nDiff > 0)
00215 ILOG_ERROR("Found " << nDiff << " differences");
00216 return nDiff;
00217 }
00218
00219 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00220
00221
00222 void
00223 Load()
00224 {
00225 String fName = mVidSet->GetFilePathVideoIndex("", mName + ".tab",
00226 false, false);
00227 Read(this, fName, mVidSet->GetDatabase());
00228 UpdateGroups();
00229 }
00230
00231 void
00232 Save(String name, bool binary)
00233 {
00234 if (!name.empty())
00235 mName = name;
00236 String fName = mVidSet->GetFilePathVideoIndex("", mName + ".tab",
00237 true, false);
00238 Write(this, fName, mVidSet->GetDatabase(), binary);
00239 }
00240 #endif // REPOSITORY_USED
00241
00242 void
00243 DumpGroups()
00244 {
00245 mVideoGroups->Dump();
00246 mShotGroups->Dump();
00247 }
00248
00249 private:
00250
00251 VideoSet* mVidSet;
00252 String mName;
00253 GroupIndex* mVideoGroups;
00254 GroupIndex* mShotGroups;
00255
00256 ILOG_VAR_DEC;
00257 };
00258
00259 ILOG_VAR_INIT(Stills, Impala.Core.VideoSet);
00260
00261 }
00262 }
00263 }
00264
00265 #endif