00001 #ifndef Impala_Core_Trec_ThreadSet_h
00002 #define Impala_Core_Trec_ThreadSet_h
00003
00004 #include "Core/Trec/ThreadVisualSimilarity.h"
00005 #include "Core/Trec/ThreadBookmarked.h"
00006 #include "Core/Trec/ThreadTime.h"
00007 #include "Core/Trec/ThreadRank.h"
00008 #include "Core/Trec/ThreadShots.h"
00009 #include "Core/Trec/ThreadHistory.h"
00010 #include "Core/Trec/ThreadVirtual.h"
00011 #include "Core/ImageSet/ImageSet.h"
00012 #include "Core/VideoSet/Segmentation.h"
00013 #include "Core/VideoSet/Keyframes.h"
00014
00015 namespace Impala {
00016 namespace Core {
00017 namespace Trec {
00018
00019 class ThreadSet
00020 {
00021 public:
00022
00023 ThreadSet(VideoSet::Segmentation* shots, VideoSet::Keyframes* keyframes,
00024 ImageSet::ImageSet* imSetThumb, ImageSet::ImageSet* imSetKey)
00025 {
00026 mShots = shots;
00027 mKeyframes = keyframes;
00028 mImSetThumb = imSetThumb;
00029 mImSetKey = imSetKey;
00030 }
00031
00032 int
00033 GetNrThreads()
00034 {
00035 return mThreads.size();
00036 }
00037
00038 Thread*
00039 GetThread(int idx)
00040 {
00041 if ((idx >= 0) && (idx < mThreads.size()))
00042 return mThreads[idx];
00043 return 0;
00044 }
00045
00046 std::list<Thread*>
00047 GetThreadsByType(int type)
00048 {
00049 std::list<Thread*> results;
00050 for (int i=0; i < mThreads.size(); i++) {
00051 if (mThreads[i]->GetType() == type)
00052 results.push_back(mThreads[i]);
00053 }
00054 return results;
00055 }
00056
00057 Thread*
00058 GetThreadByName(CString name)
00059 {
00060 for (int i=0; i < mThreads.size(); i++) {
00061 if (mThreads[i]->GetName() == name)
00062 return mThreads[i];
00063 }
00064 return NULL;
00065 }
00066
00067 void
00068 CopyToShotsThread(Thread *input, CString output)
00069 {
00070 std::list<ShotResult> list;
00071 if (input != 0 && GetThreadByName("shots_" + output) == 0)
00072 {
00073 ILOG_DEBUG("Copying thread " << input->GetName() << " to shots_" <<
00074 output<<" (" << input->GetLength() << " shots to copy)");
00075 for (int i=0; i<input->GetLength(); i++)
00076 {
00077 ShotResult r;
00078 r.shotid = input->GetShot(i);
00079 r.rank = i+1;
00080 r.score = 1.0;
00081 list.push_back(r);
00082 }
00083 AddThreadShots(output, list);
00084 }
00085 }
00086
00087 void
00088 AddThreadTime()
00089 {
00090 mThreads.push_back(new ThreadTime(mShots));
00091 }
00092
00093 void
00094 AddThreadRank(Table::SimilarityTableSet* simSet, int simId)
00095 {
00096 mThreads.push_back(new ThreadRank(mShots, mKeyframes, simSet, simId));
00097 }
00098
00099 void
00100 AddThreadVisualSimilarity(CString feature)
00101 {
00102 ThreadVisualSimilarity* thread =
00103 new ThreadVisualSimilarity(feature, mKeyframes);
00104 if (thread->GetValid())
00105 mThreads.push_back(thread);
00106 }
00107
00108 void
00109 AddThreadShots(CString name, std::list<ShotResult> shotlist)
00110 {
00111 mThreads.push_back(new ThreadShots(name, shotlist, mShots, mKeyframes));
00112 }
00113
00114 void
00115 AddThreadShots(CString name, std::list<KeyframeResult> keyframelist)
00116 {
00117 mThreads.push_back(new ThreadShots(name,keyframelist,mShots,mKeyframes));
00118 }
00119
00120 void
00121 AddThreadBookmarked(VideoSet::TableShots* bookmarked)
00122 {
00123 mThreads.push_back(new ThreadBookmarked(bookmarked));
00124 }
00125
00126 void
00127 AddThreadBookmarked(CString identifier)
00128 {
00129 mThreads.push_back(new ThreadBookmarked(0, "bookmarked_" + identifier));
00130 }
00131
00132 void
00133 AddThreadHistory()
00134 {
00135 mThreads.push_back(new ThreadHistory());
00136 }
00137
00138 void
00139 AddThreadVirtual(CString identifier)
00140 {
00141 mThreads.push_back(new ThreadVirtual(identifier));
00142 }
00143
00144 void
00145 RemoveThread(CString threadname)
00146 {
00147 std::vector<Thread*>::iterator i;
00148 bool somethingerased = true;
00149 while (somethingerased)
00150 {
00151 somethingerased = false;
00152 for (i = mThreads.begin(); i != mThreads.end(); i++)
00153 {
00154 if ((*i) && (*i)->GetName() == threadname)
00155 {
00156 Thread *d = (*i);
00157 mThreads.erase(i);
00158 delete d;
00159 ILOG_DEBUG("erased thread " << threadname);
00160 somethingerased = true;
00161 break;
00162 }
00163 }
00164 }
00165 }
00166
00167 void
00168 RemoveShotThreads()
00169 {
00170 std::vector<Thread*>::iterator i;
00171 bool somethingerased = true;
00172 while (somethingerased)
00173 {
00174 somethingerased = false;
00175 for (i = mThreads.begin(); i != mThreads.end(); i++)
00176 {
00177 if ((*i) && (*i)->GetName().find("shots_") != String::npos)
00178 {
00179 ILOG_DEBUG("erased thread " << (*i)->GetName());
00180 delete *i;
00181 mThreads.erase(i);
00182 somethingerased = true;
00183 break;
00184 }
00185 }
00186 }
00187 }
00188
00189 VideoSet::Segmentation*
00190 GetSegmentation()
00191 {
00192 return mShots;
00193 }
00194
00195 String
00196 GetShotName(int shot)
00197 {
00198 return mShots->GetName(shot);
00199 }
00200
00201 VideoSet::Keyframes*
00202 GetKeyframes()
00203 {
00204 return mKeyframes;
00205 }
00206
00207
00208 Core::Array::Array2dVec3UInt8*
00209 GetKeyframe(int shot)
00210 {
00211 ILOG_WARN("GetKeyframe: deprecated warning: " <<
00212 "use GetImageByShotID instead.");
00213 return GetImageByShotID(shot);
00214 }
00215
00216 Core::Array::Array2dVec3UInt8*
00217 GetImageByShotID(int shot, bool fromKeyframes=false)
00218 {
00219 if (!mKeyframes || !mImSetThumb)
00220 return 0;
00221 int key = mKeyframes->GetShotRKF(shot);
00222
00223
00224 if (fromKeyframes && mImSetKey)
00225 return mImSetKey->GetImage(key);
00226 return mImSetThumb->GetImage(key);
00227 }
00228
00229 Core::Array::Array2dVec3UInt8*
00230 GetImageByKeyframeID(int keyframe, bool fromKeyframes= false)
00231 {
00232 if (!mKeyframes || !mImSetThumb)
00233 return 0;
00234 if (fromKeyframes && mImSetKey)
00235 return mImSetKey->GetImage(keyframe);
00236 return mImSetThumb->GetImage(keyframe);
00237 }
00238
00239 int
00240 GetShotRKF(int shot)
00241 {
00242 if (!mKeyframes)
00243 return -1;
00244 return mKeyframes->GetShotRKF(shot);
00245
00246 }
00247
00248 ImageSet::ImageSet*
00249 GetImageSetThumbnails()
00250 {
00251 return mImSetThumb;
00252 }
00253
00254 ImageSet::ImageSet*
00255 GetImageSetKeyframes()
00256 {
00257 return mImSetKey;
00258 }
00259
00260 private:
00261
00262 std::vector<Thread*> mThreads;
00263 VideoSet::Segmentation* mShots;
00264 VideoSet::Keyframes* mKeyframes;
00265 ImageSet::ImageSet* mImSetKey;
00266 ImageSet::ImageSet* mImSetThumb;
00267
00268 ILOG_VAR_DEC;
00269
00270 };
00271
00272 ILOG_VAR_INIT(ThreadSet, Core.Trec);
00273
00274 }
00275 }
00276 }
00277
00278 #endif