00001 #ifndef Impala_Core_VideoSet_VxsDocument_h
00002 #define Impala_Core_VideoSet_VxsDocument_h
00003
00004 #include "Core/Database/DataDocument.h"
00005 #include "Core/Table/TableVxs.h"
00006 #include "Core/Table/RemoveRow.h"
00007 #include "Core/VideoSet/VideoSet.h"
00008 #include "Core/Column/Copy.h"
00009
00010 namespace Impala
00011 {
00012 namespace Core
00013 {
00014 namespace VideoSet
00015 {
00016
00017
00018 class VxsDocument : public Database::DataDocument
00019 {
00020 public:
00021 typedef Core::Table::TableVxs TableVxs;
00022 typedef TableVxs BookmarkedType;
00023
00024 VxsDocument(VideoSet* vidSet) : Database::DataDocument(vidSet)
00025 {
00026 mVidSet = vidSet;
00027 mCurSrc = 0;
00028 mCurSrcId = -1;
00029 mMarkedFrameBegin = -1;
00030 mMarkedFrameEnd = -1;
00031 mStepSize = 1;
00032 mCurrentFrame = -1;
00033 mBookmarked = new TableVxs();
00034 mBookmarkedIds = new TableIds(0);
00035 }
00036
00037 VideoSet*
00038 GetVideoSet()
00039 {
00040 return mVidSet;
00041 }
00042
00043
00044
00045 virtual bool
00046 HasCursor()
00047 {
00048 return mCurrentFrame != -1;
00049 }
00050
00051 Stream::RgbDataSrc*
00052 CurVideo()
00053 {
00054 return mCurSrc;
00055 }
00056
00057 bool
00058 GotoPrevVideo()
00059 {
00060 return TryVideoMoveCursor(-1);
00061 }
00062
00063 bool
00064 GotoNextVideo()
00065 {
00066 return TryVideoMoveCursor(1);
00067 }
00068
00069 bool
00070 GotoPrevFrame(int steps = 1)
00071 {
00072 return TryFrameMove(-steps);
00073 }
00074
00075 bool
00076 GotoNextFrame(int steps = 1)
00077 {
00078 return TryFrameMove(steps);
00079 }
00080
00081 int
00082 GetMarkedFrameBegin()
00083 {
00084 return mMarkedFrameBegin;
00085 }
00086
00087 void
00088 SetMarkedFrameBegin(int frameNr)
00089 {
00090 mMarkedFrameBegin = frameNr;
00091 }
00092
00093 int
00094 GetMarkedFrameEnd()
00095 {
00096 return mMarkedFrameEnd;
00097 }
00098
00099 void
00100 SetMarkedFrameEnd(int frameNr)
00101 {
00102 mMarkedFrameEnd = frameNr;
00103 }
00104
00105 int
00106 GetStepSize()
00107 {
00108 return mStepSize;
00109 }
00110
00111 void
00112 SetStepSize(int stepSize)
00113 {
00114 mStepSize = stepSize;
00115 }
00116
00117 virtual Database::DocLevel
00118 CursorToDir(int dirId)
00119 {
00120 return CursorToFile(dirId);
00121 }
00122
00123 virtual Database::DocLevel
00124 CursorPageUp()
00125 {
00126 if (GotoPrevVideo())
00127 return Database::LEVEL_FILE;
00128 return Database::LEVEL_NONE;
00129 }
00130
00131 virtual Database::DocLevel
00132 CursorPageDown()
00133 {
00134 if (GotoNextVideo())
00135 return Database::LEVEL_FILE;
00136 return Database::LEVEL_NONE;
00137 }
00138
00139 virtual Database::DocLevel
00140 CursorToFile(int fileId)
00141 {
00142 if (TryVideoMove(fileId))
00143 return Database::LEVEL_FILE;
00144 return Database::LEVEL_NONE;
00145 }
00146
00147 virtual Database::DocLevel
00148 CursorLeft()
00149 {
00150 if (GotoPrevFrame(mStepSize))
00151 return Database::LEVEL_FRAME;
00152 return Database::LEVEL_NONE;
00153 }
00154
00155 virtual Database::DocLevel
00156 CursorRight()
00157 {
00158 if (GotoNextFrame(mStepSize))
00159 return Database::LEVEL_FRAME;
00160 return Database::LEVEL_NONE;
00161 }
00162
00163 Database::DocLevel
00164 CursorToBookmark(int idx)
00165 {
00166 if (mBookmarked->SetCursor(idx))
00167 return CursorToCurBookmark();
00168 return Database::LEVEL_NONE;
00169 }
00170
00171 Database::DocLevel
00172 CursorNextBookmark()
00173 {
00174 if (mBookmarked->MoveCursor(1))
00175 return CursorToCurBookmark();
00176 return Database::LEVEL_NONE;
00177 }
00178
00179 Database::DocLevel
00180 CursorPrevBookmark()
00181 {
00182 if (mBookmarked->MoveCursor(-1))
00183 return CursorToCurBookmark();
00184 return Database::LEVEL_NONE;
00185 }
00186
00187 virtual Database::DocLevel
00188 CursorToCurBookmark()
00189 {
00190 if (!mBookmarked->HasCursor())
00191 return Database::LEVEL_NONE;
00192
00193 int startF = mBookmarked->Get1AtCursor();
00194 int endF = mBookmarked->Get2AtCursor();
00195 GotoFrame(mBookmarked->Get9AtCursor(), startF);
00196
00197 SetMarkedFrameBegin(startF);
00198 SetMarkedFrameEnd(endF);
00199 SetRect(mBookmarked->Get4AtCursor());
00200 SetConcept(mBookmarked->Get3AtCursor());
00201 return Database::LEVEL_FILE;
00202 }
00203
00204
00205
00206 virtual Array::Array2dVec3UInt8*
00207 VisualAtCursor(bool thumbnail)
00208 {
00209 if (!HasCursor())
00210 return 0;
00211 if (!mCurSrc)
00212 return 0;
00213 Array::Array2dVec3UInt8* srcWrap = Array::ArrayCreate<Array::Array2dVec3UInt8>
00214 (mCurSrc->FrameWidth(), mCurSrc->FrameHeight(), 0, 0,
00215 mCurSrc->DataPtr(), true);
00216
00217 return srcWrap;
00218 }
00219
00220 void
00221 SetFrameNavBetweenMarked(bool flag)
00222 {
00223 mFrameNavBetweenMarked = flag;
00224 }
00225
00226 bool
00227 HasCurFrame()
00228 {
00229 return mCurrentFrame != -1;
00230 }
00231
00232 int
00233 CurFrame()
00234 {
00235 return mCurrentFrame;
00236 }
00237
00238 void
00239 GotoFrame(int vid, int frame)
00240 {
00241 if (vid == mCurSrcId)
00242 {
00243 GotoFrame(frame);
00244 return;
00245 }
00246 if (mCurSrc)
00247 delete mCurSrc;
00248 mCurSrc = 0;
00249 mCurSrcId = vid;
00250 GotoFile(mCurSrcId);
00251 mCurSrc = mVidSet->GetVideo(mCurSrcId);
00252 mMarkedFrameBegin = -1;
00253 mMarkedFrameEnd = -1;
00254 GotoFrame(frame);
00255 }
00256
00257 void
00258 GotoFrame(int frame)
00259 {
00260 if (frame == -1)
00261 {
00262 mCurrentFrame = -1;
00263 return;
00264 }
00265 if (mCurSrc)
00266 {
00267 mCurSrc->GotoFrame(frame);
00268 int nStartRetry = 3;
00269 while ((nStartRetry > 0) && (mCurSrc->DataPtr() == 0))
00270 {
00271 std::cout << "Skipping empty frame" << std::endl;
00272 nStartRetry--;
00273 mCurSrc->NextFrame();
00274 }
00275 mCurrentFrame = mCurSrc->FrameNr();
00276 }
00277 }
00278
00279
00280
00281 BookmarkedType*
00282 GetBookmarked()
00283 {
00284 return mBookmarked;
00285 }
00286
00287 TableIds*
00288 GetBookmarkedIds()
00289 {
00290 mBookmarkedIds->ReserveMin(mBookmarked->Size(), false);
00291 Column::Copy(mBookmarkedIds->GetColumn1(), mBookmarked->GetColumn9(),
00292 mBookmarked->Size(), 0, 0);
00293 mBookmarkedIds->SetSize(mBookmarked->Size());
00294 return mBookmarkedIds;
00295 }
00296
00297 virtual bool
00298 HasBookmarks()
00299 {
00300 return mBookmarked->Size() > 0;
00301 }
00302
00303 bool
00304 HasCurBookmark()
00305 {
00306 return mBookmarked->HasCursor();
00307 }
00308
00309 int
00310 CurBookmark()
00311 {
00312 return mBookmarked->GetCursor();
00313 }
00314
00315 std::string
00316 CurBookmarkAnno()
00317 {
00318 if (!HasCurBookmark())
00319 return std::string("");
00320 return mBookmarked->Get3AtCursor();
00321 }
00322
00323 virtual std::string
00324 DescribeBookmark(int idx)
00325 {
00326 int fileId = mBookmarked->Get9(idx);
00327 return mDataSet->GetFile(fileId) + " " + mBookmarked->Get3(idx) + " ("
00328 + mDataSet->GetSectionOfFile(fileId)
00329 + "/" + mDataSet->GetDirOfFile(fileId) + ")";
00330 }
00331
00332 int
00333 TotalNrFramesInBookmarked()
00334 {
00335 int nr = 0;
00336 for (int i=0 ; i<mBookmarked->Size() ; i++)
00337 {
00338 nr += mBookmarked->Get2(i) - mBookmarked->Get1(i) + 1;
00339 }
00340 return nr;
00341 }
00342
00343 virtual bool
00344 AddCursorToBookmarked()
00345 {
00346 if (! HasCursor())
00347 return false;
00348 if ((mMarkedFrameBegin == -1) || (mMarkedFrameEnd == -1))
00349 return AddSegmentToBookmarked(CurFileId(), mCurrentFrame,
00350 mCurrentFrame);
00351 return AddSegmentToBookmarked(CurFileId(), mMarkedFrameBegin,
00352 mMarkedFrameEnd);
00353 }
00354
00355 virtual bool
00356 RemoveCursorFromBookmarked()
00357 {
00358 if (! HasCurBookmark())
00359 return false;
00360 int cursor = mBookmarked->GetCursor();
00361 Table::RemoveRow(mBookmarked, mBookmarked->GetCursor());
00362 CursorToBookmark(cursor);
00363 return true;
00364 }
00365
00366 virtual void
00367 ClearBookmarked()
00368 {
00369 mBookmarked->SetEmpty();
00370 }
00371
00372 virtual void
00373 LoadBookmarked(std::string fileName)
00374 {
00375 mBookmarkedFileName = fileName;
00376 mBookmarked->ReadVxsFile(fileName);
00377 Database::RawDataSet* dataSet = GetDataSet();
00378 for (int i=0 ; i<mBookmarked->Size() ; i++)
00379 {
00380 int fileId = dataSet->GetFileId(mBookmarked->Get6(i),
00381 mBookmarked->Get7(i),
00382 mBookmarked->Get5(i));
00383 mBookmarked->GetColumn9()->Set(i, fileId);
00384 }
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409 }
00410
00411
00412 virtual void
00413 SaveBookmarked(std::string fileName, std::string conceptName)
00414 {
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428 }
00429
00430 std::string
00431 GetBookmarkedFileName()
00432 {
00433 return mBookmarkedFileName;
00434 }
00435
00436 void
00437 LoadConceptsFromBookmarks()
00438 {
00439 for (int i=0 ; i<mBookmarked->Size() ; i++)
00440 AddConcept(mBookmarked->Get3(i));
00441 }
00442
00443 bool
00444 AddSegmentToBookmarked(int vid, int startFrame, int endFrame)
00445 {
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458 return false;
00459 }
00460
00461
00462
00463 virtual void
00464 Clear()
00465 {
00466 Database::DataDocument::Clear();
00467 mBookmarked->SetEmpty();
00468 GotoFrame(-1, -1);
00469 }
00470
00471 private:
00472
00473 bool
00474 TryVideoMoveCursor(int inc)
00475 {
00476 if (!HasCursor())
00477 return false;
00478 return TryVideoMove(CurFileId() + inc);
00479 }
00480
00481 bool
00482 TryVideoMove(int vid)
00483 {
00484 if ((vid < 0) || (vid >= mVidSet->NrFiles()))
00485 return false;
00486 GotoFrame(vid, 0);
00487 return true;
00488 }
00489
00490 bool
00491 TryFrameMove(int inc)
00492 {
00493 if (mCurSrc)
00494 {
00495 int newFrame = mCurSrc->FrameNr() + inc;
00496 if ((newFrame < 0) || (newFrame > mCurSrc->LastFrame()))
00497 return false;
00498 if (mFrameNavBetweenMarked && (mMarkedFrameBegin != -1)
00499 && (newFrame < mMarkedFrameBegin))
00500 return false;
00501 if (mFrameNavBetweenMarked && (mMarkedFrameEnd != -1)
00502 && (newFrame > mMarkedFrameEnd))
00503 return false;
00504 mCurSrc->NextFrame(inc);
00505 mCurrentFrame = mCurSrc->FrameNr();
00506 return true;
00507 }
00508 return false;
00509 }
00510
00511 VideoSet* mVidSet;
00512 Stream::RgbDataSrc* mCurSrc;
00513 int mCurSrcId;
00514 int mCurrentFrame;
00515 int mMarkedFrameBegin;
00516 int mMarkedFrameEnd;
00517 int mStepSize;
00518 bool mFrameNavBetweenMarked;
00519
00520 TableVxs* mBookmarked;
00521 TableIds* mBookmarkedIds;
00522 std::string mBookmarkedFileName;
00523
00524 };
00525
00526 }
00527 }
00528 }
00529
00530 #endif