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 mSegDoc->LoadConcepts(annoSet);
00075 #endif // REPOSITORY_USED
00076 mCurConcept = -1;
00077 mAnno = 0;
00078 mImagesSet = 0;
00079 mImSetIdxGrid = 0;
00080
00081 AddDocListener(this);
00082
00083 mStringSelector = new OglGui::StringSelector(this, wndWidth, 120);
00084 mStringSelector->SetStringListener(this, 0);
00085 for (int i=0 ; i<mDataDoc->NrConcepts() ; i++)
00086 mStringSelector->AddString(mDataDoc->GetConcept(i));
00087 int heightUsed = 120;
00088
00089 CmdOptions& options = CmdOptions::GetInstance();
00090 if (!options.GetBool("annoTableIdxGrid",true))
00091 {
00092 int nrRow = (wndHeight - heightUsed) / (thumbHeight + 6);
00093 mImagesSet = new ImageSet(this, thumbWidth, thumbHeight, viewScale,
00094 nrImOnRow, nrRow);
00095 mImagesSet->ActivateInfoBox(false);
00096 mImagesSet->SetImagesListener(this, 0);
00097 }
00098 else
00099 {
00100 mImSetIdxGridScroller =
00101 new ImageSetIdxGridScroller(this,2,2,wndWidth-4,
00102 wndHeight-heightUsed-12,nrImOnRow);
00103 mImSetIdxGrid = mImSetIdxGridScroller->ImSetIdxGrid();
00104 mImSetIdxGrid->SetImageSetIdxGridListener(this);
00105
00106 mImSetIdxGrid->ShowDims(false);
00107 }
00108
00109 mDataDoc->SetConcept(0);
00110 }
00111
00112 virtual void
00113 HandleNewFile()
00114 {
00115 int concept = mDataDoc->GetConceptIdx();
00116 if (concept != mStringSelector->GetCurrentStringIdx())
00117 mStringSelector->SetCurrentString(concept, true);
00118 if (concept == mCurConcept)
00119 return;
00120
00121 mCurConcept = concept;
00122 if (mImagesSet)
00123 {
00124 mImagesSet->RemoveImages();
00125 mImagesSet->SetFirstVisY(0, true);
00126 }
00127 if (mImSetIdxGrid)
00128 mImSetIdxGrid->Clear();
00129 mVisibleKeys.clear();
00130 Core::VideoSet::Keyframes* keys = mSegDoc ? mSegDoc->GetKeyframes() : 0;
00131 if (mSegDoc && !keys)
00132 return;
00133
00134 Core::ImageSet::ImageSet* imSet =
00135 mSegDoc ? mSegDoc->GetImSetKeyframes(true) : mIxsDoc->GetImageSet();
00136 if (!imSet)
00137 return;
00138
00139 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00140 Util::Database* db;
00141 String conceptTab = mDataDoc->GetConcept()+".tab";
00142 String fName;
00143 if (mSegDoc)
00144 {
00145 Core::VideoSet::VideoSet* vidSet = mSegDoc->GetVideoSet();
00146 fName = vidSet->GetFilePathAnnotation(QUID_CLASS_FRAME, mAnnoSet,
00147 conceptTab, false, false);
00148 db = vidSet->GetDatabase();
00149 }
00150 if (mIxsDoc)
00151 {
00152 Core::ImageSet::ImageSet* ixsSet = mIxsDoc->GetImageSet();
00153 fName = ixsSet->GetFilePathAnnotation(QUID_CLASS_IMAGE, mAnnoSet,
00154 conceptTab, false, false);
00155 db = ixsSet->GetDatabase();
00156 }
00157 if (fName.empty())
00158 return;
00159
00160 if (mAnno)
00161 delete mAnno;
00162 mAnno = Core::Table::AnnotationTable::MakeFromFile
00163 (mDataDoc->GetConcept(),fName, db);
00164 #else // REPOSITORY_USED
00165 typedef Persistency::AnnotationTableLocator AnnoLoc;
00166 AnnoLoc loc;
00167 if (mSegDoc)
00168 {
00169 Core::VideoSet::VideoSet* vidSet = mSegDoc->GetVideoSet();
00170 loc = AnnoLoc(vidSet->GetLocator(), QUID_CLASS_FRAME, mAnnoSet,
00171 mDataDoc->GetConcept());
00172 }
00173 if (mIxsDoc)
00174 {
00175 Core::ImageSet::ImageSet* ixsSet = mIxsDoc->GetImageSet();
00176 loc = AnnoLoc(ixsSet->GetLocator(), QUID_CLASS_IMAGE, mAnnoSet,
00177 mDataDoc->GetConcept());
00178 }
00179 if (! Persistency::AnnotationTableRepository().Exists(loc))
00180 return;
00181
00182 if (mAnno)
00183 delete mAnno;
00184 mAnno = Persistency::AnnotationTableRepository().Get(loc);
00185 #endif // REPOSITORY_USED
00186 int sz = mAnno->Size();
00187 int maxNr = mImagesSet ? Min(sz, 1000) : sz;
00188
00189 int nrFound = 0;
00190 int s = 0;
00191 while ((s < mAnno->Size()) && (nrFound < maxNr))
00192 {
00193 if (mAnno->IsPositive(s))
00194 {
00195 Quid q = mAnno->Get1(s);
00196 int keyfr = keys ? keys->GetFrameId(q) : mAnno->GetIndex(q);
00197 if (keyfr != -1)
00198 {
00199 if (mImagesSet)
00200 mImagesSet->AddImage(keyfr, imSet);
00201 if (mImSetIdxGrid)
00202 mImSetIdxGrid->AddImageSetIdx(imSet,keyfr);
00203 mVisibleKeys.push_back(keyfr);
00204 nrFound++;
00205 }
00206 }
00207 s++;
00208 }
00209 if (mImSetIdxGrid)
00210 mImSetIdxGrid->UpdateLayout(true);
00211 ILOG_INFO("Found " << nrFound << " of " << mAnno->GetNrPositive()
00212 << " positive annotations");
00213 }
00214
00215 virtual void
00216 StringSelectionEvent(OglGui::StringSelector* src, int strIndex,
00217 void* listenerData)
00218 {
00219 mDataDoc->SetConcept(strIndex);
00220 HandleNewFile();
00221 }
00222
00223 void HandleImageSelectionEvent(int imIndex)
00224 {
00225 int keyfr = mVisibleKeys[imIndex];
00226 if (mSegDoc)
00227 mSegDoc->GotoKeyfr(keyfr);
00228 if (mIxsDoc)
00229 mIxsDoc->CursorToFile(keyfr);
00230 AllHandleNewCursor(Core::Database::LEVEL_SHOT, false);
00231 }
00232
00233 virtual void
00234 ImageSelectionEvent(ImagesWindow* src, int imIndex, void* listenerData)
00235 {
00236 HandleImageSelectionEvent(imIndex);
00237 }
00238
00239 virtual void
00240 ImageSelectionEvent(ImageSetIdxGrid* src, int imIndex, void* listenerData)
00241 {
00242 HandleImageSelectionEvent(imIndex);
00243 }
00244
00245 private:
00246
00247 DataDocument* mDataDoc;
00248 SegmentationDocument* mSegDoc;
00249 IxsDocument* mIxsDoc;
00250
00251 String mAnnoSet;
00252 int mCurConcept;
00253 AnnotationTable* mAnno;
00254 std::vector<int> mVisibleKeys;
00255 OglGui::StringSelector* mStringSelector;
00256 ImageSet* mImagesSet;
00257 ImageSetIdxGridScroller* mImSetIdxGridScroller;
00258 ImageSetIdxGrid* mImSetIdxGrid;
00259
00260 ILOG_VAR_DEC;
00261 };
00262
00263 ILOG_VAR_INIT(AnnotationTableGui, Visualization);
00264
00265 }
00266 }
00267
00268 #endif