Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

SearchTopic.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_Trec_SearchTopic_h
00002 #define Impala_Core_Trec_SearchTopic_h
00003 
00004 #include <vector>
00005 #include "Basis/File.h"
00006 #include "Basis/Timer.h"
00007 #include "Basis/FileName.h"
00008 #include "Core/ImageSet/ImageSet.h"
00009 #include "Core/VideoSet/VideoSet.h"
00010 #include "Core/VideoSet/Keyframes.h"
00011 
00012 namespace Impala
00013 {
00014 namespace Core
00015 {
00016 namespace Trec
00017 {
00018 
00019 
00020 class SearchTopic
00021 {
00022 public:
00023 
00024     SearchTopic() : mTimer(1)
00025     {
00026         mTopics = 0;
00027         mImages = 0;
00028         mThumbnails = 0;
00029         mVideos = 0;
00030         mKeyframes = 0;
00031         mCurTopic = 0;
00032     }
00033 
00034     SearchTopic(Core::ImageSet::ImageSet* images,
00035                 Core::ImageSet::ImageSet* thumbnails,
00036                 Core::VideoSet::VideoSet* videos) : mTimer(1)
00037     {
00038         mImages = images;
00039         mThumbnails = thumbnails;
00040         mVideos = videos;
00041         mKeyframes = 0;
00042 
00043         if (mImages)
00044             mTopics = mImages;
00045         else if (mVideos)
00046             mTopics = mVideos;
00047         else if (mThumbnails)
00048             mTopics = mThumbnails;
00049         mCurTopic = 0;
00050     }
00051 
00052     // inquiry
00053 
00054     int
00055     NrTopic()
00056     {
00057         if (mTopics)
00058             return mTopics->NrDirs();
00059         return mNum.size();
00060     }
00061 
00062     String
00063     GetTopicNum(int id)
00064     {
00065         if ((id >= 0) && (id < mNum.size()))
00066             return mNum[id];
00067         return MakeString(id);
00068     }
00069 
00070     String
00071     GetTopicText(int id)
00072     {
00073         if ((id >= 0) && (id < mText.size()))
00074             return mText[id];
00075         if (mTopics)
00076             return mImages->GetDir(id);
00077         return String("");
00078     }
00079 
00080     bool
00081     HasVideos()
00082     {
00083         return mVideos != 0;
00084     }
00085 
00086     int
00087     GetNrExamples(int id)
00088     {
00089         if (mTopics)
00090             return mTopics->GetNrFiles(id);
00091         return 0;
00092     }
00093 
00094     String
00095     GetExampleName(int topic, int example)
00096     {
00097         int fileId = mTopics->GetFirstFileId(topic) + example;
00098         return FileNameBase(mTopics->GetFile(fileId));
00099     }
00100 
00101     String
00102     GetVideoExampleName(int topic, int example, bool toWrite)
00103     {
00104         int fileId = mVideos->GetFirstFileId(topic) + example;
00105 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00106         return mVideos->GetFilePathVideoData(fileId, toWrite, false);
00107 #else // REPOSITORY_USED
00108         ILOG_ERROR("Not implemented yet");
00109         return "";
00110 #endif // REPOSITORY_USED
00111     }
00112 
00113     Quid
00114     GetVideoExampleQuid(int topic, int example)
00115     {
00116         if (!mKeyframes)
00117         {
00118             mKeyframes = new Core::VideoSet::Keyframes(mVideos, "");
00119         }
00120 
00121         int fileId = mTopics->GetFirstFileId(topic) + example;
00122         
00123         int keyframeId = mKeyframes->GetFrameId(mTopics->GetFile(fileId));
00124         Quid q = mKeyframes->GetQuidFrame(keyframeId);
00125         return q;
00126     }
00127 
00128     Core::Array::Array2dVec3UInt8*
00129     GetTopicImageExample(int topic, int example, bool thumbnail)
00130     {
00131         int fileId = mTopics->GetFirstFileId(topic) + example;
00132         if (thumbnail && mThumbnails)
00133             return mThumbnails->GetImage(fileId);
00134         return mImages->GetImage(fileId);
00135     }
00136 
00137     String
00138     GetImageExampleName(int topic, int example, bool thumbnail,
00139                         bool toWrite = false)
00140     {
00141 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00142         if (thumbnail)
00143         {
00144             int fileId = mThumbnails->GetFirstFileId(topic) + example;
00145             return mThumbnails->GetFilePathImageData(fileId, toWrite, false);
00146         }
00147         int fileId = mImages->GetFirstFileId(topic) + example;
00148         return mImages->GetFilePathImageData(fileId, toWrite, false);
00149 #else // REPOSITORY_USED
00150         ILOG_ERROR("Not implemented yet");
00151         return "";
00152 #endif // REPOSITORY_USED
00153     }
00154 
00155     // current topic part
00156 
00157     virtual void
00158     TopicSelect(int topic)
00159     {
00160         mCurTopic = topic;
00161         mTimer.Start();
00162     }
00163 
00164     int
00165     CurTopic()
00166     {
00167         return mCurTopic;
00168     }
00169 
00170     String
00171     GetCurTopicNum()
00172     {
00173         return GetTopicNum(mCurTopic);
00174     }
00175 
00176     String
00177     GetCurTopicText()
00178     {
00179         return GetTopicText(mCurTopic);
00180     }
00181 
00182     // number of video examples is equal to number of image examples
00183     int
00184     GetCurTopicNrExamples()
00185     {
00186         return GetNrExamples(mCurTopic);
00187     }
00188 
00189     String
00190     GetCurTopicExampleName(int nr)
00191     {
00192         return GetExampleName(mCurTopic, nr);
00193     }
00194 
00195     Quid
00196     GetCurTopicExampleQuid(int example)
00197     {
00198         return GetVideoExampleQuid(mCurTopic, example);
00199     }
00200 
00201     String
00202     GetCurTopicVideoExampleName(int nr)
00203     {
00204         return GetVideoExampleName(mCurTopic, nr, false);
00205     }
00206 
00207     Core::Array::Array2dVec3UInt8*
00208     GetCurTopicImageExample(int nr, bool thumbnail)
00209     {
00210         int fileId = mTopics->GetFirstFileId(mCurTopic) + nr;
00211         if (thumbnail && mThumbnails)
00212             return mThumbnails->GetImage(fileId);
00213         return mImages->GetImage(fileId);
00214     }
00215 
00216     // time in minutes since last topicSelect
00217     double
00218     GetElapsedTime()
00219     {
00220         return mTimer.SplitTime() / 60;
00221     }
00222 
00223 protected:
00224 
00225     std::vector<String> mNum;
00226     std::vector<String> mText;
00227 
00228     Core::Database::RawDataSet* mTopics; // "master" definition topics, is mImages or mVideos
00229     Core::ImageSet::ImageSet*   mImages;
00230     Core::ImageSet::ImageSet*   mThumbnails;
00231     Core::VideoSet::VideoSet*   mVideos;
00232     Core::VideoSet::Keyframes*  mKeyframes;
00233 
00234     int    mCurTopic;
00235     Timer  mTimer;
00236 
00237     ILOG_VAR_DEC;
00238 };
00239 
00240 ILOG_VAR_INIT(SearchTopic, Impala.Core.Trec);
00241 
00242 } // namespace Trec
00243 } // namespace Core
00244 } // namespace Impala
00245 
00246 #endif

Generated on Fri Mar 19 09:31:26 2010 for ImpalaSrc by  doxygen 1.5.1