00001 #ifndef Impala_Core_Trec_ThreadRank_h
00002 #define Impala_Core_Trec_ThreadRank_h
00003
00004 #include "Core/Trec/Thread.h"
00005 #include "Core/Table/SimilarityTableSet.h"
00006 #include "Core/Column/Find.h"
00007 #include "Core/VideoSet/Segmentation.h"
00008
00009 namespace Impala
00010 {
00011 namespace Core
00012 {
00013 namespace Trec
00014 {
00015
00016
00017 class ThreadRank : public Thread
00018 {
00019 public:
00020
00021 ThreadRank(VideoSet::Segmentation* segmentation, VideoSet::Keyframes* keyframes, Table::SimilarityTableSet* simSet,
00022 int simId) :
00023 Thread(std::string("rank_") + simSet->GetName(simId))
00024 {
00025 mSimSet = simSet;
00026 mSimId = simId;
00027 mKeyframes = keyframes;
00028 mSegmentation = segmentation;
00029 mRank = mSimSet->GetRankTable(mSimId);
00030 mKeyEqualShot = false;
00031 mUseShotQuids = false;
00032 Quid t = mRank->Get1(0);
00033 if (QuidClass(t) == QUID_CLASS_SHOT)
00034 {
00035 mUseShotQuids = true;
00036 }
00037 }
00038
00039 virtual int
00040 GetShot(int position)
00041 {
00042 if ((position < 0) || (position >= mRank->Size())) {
00043
00044
00045 return -1;
00046 }
00047 Quid quid = mRank->Get1(position);
00048 if (QuidClass(quid) == QUID_CLASS_SHOT)
00049 {
00050 return mSegmentation->GetShotId(quid);
00051 } else {
00052 return Key2Shot(mKeyframes->GetFrameId(quid));
00053 }
00054 }
00055
00056
00057 Real64
00058 GetShotScore(int position)
00059 {
00060 Quid q = mRank->Get1(position);
00061 int pos = mSimSet->FindQuid(q);
00062 return mSimSet->GetSimTable(mSimId)->Get1(pos);
00063 }
00064
00065 virtual int
00066 GetLength()
00067 {
00068
00069 return mRank->Size();
00070 }
00071
00072 virtual int
00073 GetShotAt(int shot, int offset)
00074 {
00075 Quid quidf;
00076 if (mUseShotQuids)
00077 {
00078 quidf = mSegmentation->GetQuidShot(shot);
00079 } else {
00080 quidf = mKeyframes->GetQuidFrame(Shot2Key(shot));
00081 }
00082 int r = Column::Find(mRank->GetColumn1(), quidf, 0, mRank->Size());
00083 int dst = r + offset;
00084 if ((dst < 0) || (dst >= mRank->Size())) {
00085
00086
00087
00088 return -1;
00089 }
00090 Quid quid = mRank->Get1(dst);
00091 if (QuidClass(quid) == QUID_CLASS_SHOT)
00092 {
00093 return mSegmentation->GetShotId(quid);
00094 } else {
00095 return Key2Shot(mKeyframes->GetFrameId(quid));
00096 }
00097 }
00098
00099 virtual int
00100 GetShotPosition(int shot)
00101 {
00102 Quid quidf;
00103 if (mUseShotQuids)
00104 {
00105 quidf = mSegmentation->GetQuidShot(shot);
00106 } else {
00107 quidf = mKeyframes->GetQuidFrame(Shot2Key(shot));
00108 }
00109 int r = Column::Find(mRank->GetColumn1(), quidf, 0, mRank->Size());
00110 if (r == mRank->Size()) {
00111
00112
00113 return -1;
00114 }
00115
00116
00117 return r;
00118 }
00119
00120 virtual int
00121 GetType()
00122 {
00123 return RANK;
00124 }
00125
00126 private:
00127
00128 int
00129 Shot2Key(int shot)
00130 {
00131 return (mKeyEqualShot) ? shot : mKeyframes->GetShotRKF(shot);
00132 }
00133
00134 int
00135 Key2Shot(int key)
00136 {
00137 return (mKeyEqualShot) ? key : mKeyframes->GetShotId(key);
00138 }
00139
00140 Table::SimilarityTableSet* mSimSet;
00141 int mSimId;
00142 Table::SimilarityTableSet::RankTableType* mRank;
00143 VideoSet::Keyframes* mKeyframes;
00144 VideoSet::Segmentation* mSegmentation;
00145 bool mKeyEqualShot;
00146 bool mUseShotQuids;
00147
00148 ILOG_VAR_DEC;
00149 };
00150 ILOG_VAR_INIT(ThreadRank, Core.Trec);
00151
00152
00153 }
00154 }
00155 }
00156
00157 #endif