00001
00002 #ifndef Impala_Visualization_AnnotationTableGui_h
00003 #define Impala_Visualization_AnnotationTableGui_h
00004
00005 #include "Persistency/AnnotationTableRepository.h"
00006 #include "Core/ImageSet/IxsDocument.h"
00007 #include "Core/VideoSet/SegmentationDocument.h"
00008
00009 #include "OglGui/StringSelector.h"
00010 #include "OglGui/StringListener.h"
00011 #include "Visualization/ImageSet.h"
00012 #include "Visualization/ImageSetIdxGridScroller.h"
00013 #include "Visualization/AppControlDoc.h"
00014
00015 namespace Impala {
00016 namespace Visualization {
00017
00018 class AnnotationTableGui :
00019 public Window,
00020 public AppControlDoc,
00021 public Core::Database::DataDocumentListener,
00022 public ImageSetIdxGridListener,
00023 public ImagesListener,
00024 public OglGui::StringListener
00025 {
00026 public:
00027 typedef Core::Table::AnnotationTable AnnotationTable;
00028 typedef Core::Database::DataDocument DataDocument;
00029 typedef Core::VideoSet::SegmentationDocument SegmentationDocument;
00030 typedef Core::ImageSet::IxsDocument IxsDocument;
00031
00032 AnnotationTableGui(OglGui::Window* parent, int wndWidth, int wndHeight,
00033 int nrImOnRow, int thumbWidth, int thumbHeight,
00034 double viewScale, SegmentationDocument* segDoc,
00035 String annoSet, int controlId) :
00036 Window(parent, wndWidth, wndHeight, true),
00037 AppControlDoc(controlId, segDoc)
00038 {
00039 mIxsDoc = 0;
00040 mSegDoc = segDoc;
00041 mDataDoc = segDoc;
00042 Init(wndWidth, wndHeight, nrImOnRow, thumbWidth, thumbHeight,
00043 viewScale, annoSet);
00044 }
00045
00046 AnnotationTableGui(OglGui::Window* parent, int wndWidth, int wndHeight,
00047 int nrImOnRow, int thumbWidth, int thumbHeight,
00048 double viewScale, IxsDocument* ixsDoc,
00049 String annoSet, int controlId) :
00050 Window(parent, wndWidth, wndHeight, true),
00051 AppControlDoc(controlId, ixsDoc)
00052 {
00053 mSegDoc = 0;
00054 mIxsDoc = ixsDoc;
00055 mDataDoc = ixsDoc;
00056 Init(wndWidth, wndHeight, nrImOnRow, thumbWidth, thumbHeight,
00057 viewScale, annoSet);
00058 }
00059
00060 void Init(int wndWidth, int wndHeight, int nrImOnRow, int thumbWidth,
00061 int thumbHeight, double viewScale, String annoSet)
00062 {
00063 mAnnoSet = annoSet;
00064 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00065 String fName;
00066 if (mSegDoc)
00067 fName = mSegDoc->GetVideoSet()->GetFilePathAnnotation(annoSet,
00068 false, false);
00069 if (mIxsDoc)
00070 fName = mIxsDoc->GetImageSet()->GetFilePathAnnotation(annoSet,
00071 false, false);
00072 mDataDoc->LoadConcepts(fName);
00073 #else // REPOSITORY_USED
00074 if (mSegDoc)
00075 mSegDoc->LoadConcepts(annoSet);
00076 if (mIxsDoc)
00077 mIxsDoc->LoadConcepts(annoSet);
00078 #endif // REPOSITORY_USED
00079 mCurConcept = -1;
00080 mAnno = 0;
00081 mImagesSet = 0;
00082 mImSetIdxGrid = 0;
00083
00084 AddDocListener(this);
00085
00086 mStringSelector = new OglGui::StringSelector(this, wndWidth, 120);
00087 mStringSelector->SetStringListener(this, 0);
00088 for (int i=0 ; i<mDataDoc->NrConcepts() ; i++)
00089 mStringSelector->AddString(mDataDoc->GetConcept(i));
00090 int heightUsed = 120;
00091
00092 CmdOptions& options = CmdOptions::GetInstance();
00093 if (!options.GetBool("annoTableIdxGrid",true))
00094 {
00095 int nrRow = (wndHeight - heightUsed) / (thumbHeight + 6);
00096 mImagesSet = new ImageSet(this, thumbWidth, thumbHeight, viewScale,
00097 nrImOnRow, nrRow);
00098 mImagesSet->ActivateInfoBox(false);
00099 mImagesSet->SetImagesListener(this, 0);
00100 }
00101 else
00102 {
00103 mImSetIdxGridScroller =
00104 new ImageSetIdxGridScroller(this,2,2,wndWidth-4,
00105 wndHeight-heightUsed-12,nrImOnRow);
00106 mImSetIdxGrid = mImSetIdxGridScroller->ImSetIdxGrid();
00107 mImSetIdxGrid->SetImageSetIdxGridListener(this);
00108
00109 mImSetIdxGrid->ShowDims(false);
00110 }
00111
00112 mDataDoc->SetConcept(0);
00113 }
00114
00115 virtual void
00116 HandleNewFile()
00117 {
00118 int concept = mDataDoc->GetConceptIdx();
00119 if (concept != mStringSelector->GetCurrentStringIdx())
00120 mStringSelector->SetCurrentString(concept, true);
00121 if (concept == mCurConcept)
00122 return;
00123
00124 mCurConcept = concept;
00125 if (mImagesSet)
00126 {
00127 mImagesSet->RemoveImages();
00128 mImagesSet->SetFirstVisY(0, true);
00129 }
00130 if (mImSetIdxGrid)
00131 mImSetIdxGrid->Clear();
00132 mVisibleKeys.clear();
00133 Core::VideoSet::Keyframes* keys = mSegDoc ? mSegDoc->GetKeyframes() : 0;
00134 if (mSegDoc && !keys)
00135 return;
00136
00137 Core::ImageSet::ImageSet* imSet =
00138 mSegDoc ? mSegDoc->GetImSetKeyframes(true) : mIxsDoc->GetImageSet();
00139 if (!imSet)
00140 return;
00141
00142 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00143 Util::Database* db;
00144 String conceptTab = mDataDoc->GetConcept()+".tab";
00145 String fName;
00146 if (mSegDoc)
00147 {
00148 Core::VideoSet::VideoSet* vidSet = mSegDoc->GetVideoSet();
00149 fName = vidSet->GetFilePathAnnotation(QUID_CLASS_FRAME, mAnnoSet,
00150 conceptTab, false, false);
00151 db = vidSet->GetDatabase();
00152 }
00153 if (mIxsDoc)
00154 {
00155 Core::ImageSet::ImageSet* ixsSet = mIxsDoc->GetImageSet();
00156 fName = ixsSet->GetFilePathAnnotation(QUID_CLASS_IMAGE, mAnnoSet,
00157 conceptTab, false, false);
00158 db = ixsSet->GetDatabase();
00159 }
00160 if (fName.empty())
00161 return;
00162
00163 if (mAnno)
00164 delete mAnno;
00165 mAnno = Core::Table::AnnotationTable::MakeFromFile
00166 (mDataDoc->GetConcept(),fName, db);
00167 #else // REPOSITORY_USED
00168 typedef Persistency::AnnotationTableLocator AnnoLoc;
00169 AnnoLoc loc;
00170 if (mSegDoc)
00171 {
00172 Core::VideoSet::VideoSet* vidSet = mSegDoc->GetVideoSet();
00173 loc = AnnoLoc(vidSet->GetLocator(), QUID_CLASS_FRAME, mAnnoSet,
00174 mDataDoc->GetConcept());
00175 }
00176 if (mIxsDoc)
00177 {
00178 Core::ImageSet::ImageSet* ixsSet = mIxsDoc->GetImageSet();
00179 loc = AnnoLoc(ixsSet->GetLocator(), QUID_CLASS_IMAGE, mAnnoSet,
00180 mDataDoc->GetConcept());
00181 }
00182 if (! Persistency::AnnotationTableRepository().Exists(loc))
00183 return;
00184
00185 if (mAnno)
00186 delete mAnno;
00187 mAnno = Persistency::AnnotationTableRepository().Get(loc);
00188 #endif // REPOSITORY_USED
00189 int sz = mAnno->Size();
00190 int maxNr = mImagesSet ? Min(sz, 1000) : sz;
00191
00192 int nrFound = 0;
00193 int s = 0;
00194 while ((s < mAnno->Size()) && (nrFound < maxNr))
00195 {
00196 if (mAnno->IsPositive(s))
00197 {
00198 Quid q = mAnno->Get1(s);
00199 int keyfr = keys ? keys->GetFrameId(q) : mAnno->GetIndex(q);
00200 if (keyfr != -1)
00201 {
00202 if (mImagesSet)
00203 mImagesSet->AddImage(keyfr, imSet);
00204 if (mImSetIdxGrid)
00205 mImSetIdxGrid->AddImageSetIdx(imSet,keyfr);
00206 mVisibleKeys.push_back(keyfr);
00207 nrFound++;
00208 }
00209 }
00210 s++;
00211 }
00212 if (mImSetIdxGrid)
00213 mImSetIdxGrid->UpdateLayout(true);
00214 ILOG_INFO("Found " << nrFound << " of " << mAnno->GetNrPositive()
00215 << " positive annotations");
00216 }
00217
00218 virtual void
00219 StringSelectionEvent(OglGui::StringSelector* src, int strIndex,
00220 void* listenerData)
00221 {
00222 mDataDoc->SetConcept(strIndex);
00223 HandleNewFile();
00224 }
00225
00226 void HandleImageSelectionEvent(int imIndex)
00227 {
00228 int keyfr = mVisibleKeys[imIndex];
00229 if (mSegDoc)
00230 mSegDoc->GotoKeyfr(keyfr);
00231 if (mIxsDoc)
00232 mIxsDoc->CursorToFile(keyfr);
00233 AllHandleNewCursor(Core::Database::LEVEL_SHOT, false);
00234 }
00235
00236 virtual void
00237 ImageSelectionEvent(ImagesWindow* src, int imIndex, void* listenerData)
00238 {
00239 HandleImageSelectionEvent(imIndex);
00240 }
00241
00242 virtual void
00243 ImageSelectionEvent(ImageSetIdxGrid* src, int imIndex, void* listenerData)
00244 {
00245 HandleImageSelectionEvent(imIndex);
00246 }
00247
00248 private:
00249
00250 DataDocument* mDataDoc;
00251 SegmentationDocument* mSegDoc;
00252 IxsDocument* mIxsDoc;
00253
00254 String mAnnoSet;
00255 int mCurConcept;
00256 AnnotationTable* mAnno;
00257 std::vector<int> mVisibleKeys;
00258 OglGui::StringSelector* mStringSelector;
00259 ImageSet* mImagesSet;
00260 ImageSetIdxGridScroller* mImSetIdxGridScroller;
00261 ImageSetIdxGrid* mImSetIdxGrid;
00262
00263 ILOG_VAR_DEC;
00264 };
00265
00266 ILOG_VAR_INIT(AnnotationTableGui, Visualization);
00267
00268 }
00269 }
00270
00271 #endif