00001 #ifndef Impala_Visualization_SegmentationDocumentGuiStills_h
00002 #define Impala_Visualization_SegmentationDocumentGuiStills_h
00003
00004 #include "Persistency/StillsRepository.h"
00005 #include "Core/Array/Scale.h"
00006 #include "Core/Array/Set.h"
00007
00008 #include "Core/VideoSet/SegmentationDocument.h"
00009 #include "Core/VideoSet/Stills.h"
00010 #include "Core/Database/DataDocumentListener.h"
00011 #include "Visualization/ImageSet.h"
00012 #include "Visualization/AppControlDoc.h"
00013 #include "OglGui/CheckBox.h"
00014 #include "OglGui/TextField.h"
00015 #include "OglGui/TextArea.h"
00016 #include "OglGui/Strut.h"
00017 #include "Basis/ILog.h"
00018
00019 namespace Impala {
00020 namespace Visualization {
00021
00022 class SegmentationDocumentGuiStills :
00023 public Window,
00024 public AppControlDoc,
00025 public Core::Database::DataDocumentListener,
00026 public OglGui::ButtonListener,
00027 public ImagesListener
00028 {
00029 public:
00030 typedef Core::Array::Array2dVec3UInt8 Array2dVec3UInt8;
00031 typedef Core::VideoSet::SegmentationDocument SegmentationDocument;
00032 typedef Core::VideoSet::Stills Stills;
00033
00034 SegmentationDocumentGuiStills(OglGui::Window* parent, int w, int h,
00035 int nrImOnRow, int thumbW, int thumbH,
00036 double viewScale, bool doFullSize,
00037 bool imageStills,
00038 SegmentationDocument* segDoc,
00039 int controlId) :
00040 Window(parent, w, h, true),
00041 AppControlDoc(controlId, segDoc)
00042 {
00043 mSegDoc = segDoc;
00044 AddDocListener(this);
00045 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00046 mStills = new Stills(segDoc->GetVideoSet(), "stills");
00047 #else // REPOSITORY_USED
00048 Persistency::StillsLocator loc(segDoc->GetVideoSet()->GetLocator(),
00049 "stills");
00050 mStills = Persistency::StillsRepository().Get(loc, segDoc->GetVideoSet());
00051 #endif // REPOSITORY_USED
00052 mViewScale = viewScale;
00053 mDoFullSize = doFullSize;
00054 mImageStills = imageStills;
00055 mForceUpdate = false;
00056
00057 int line = 20;
00058 mCheckBox = new OglGui::CheckBox(this, 150, line, "Update stills");
00059 mCheckBox->SetSelected(false);
00060 mFrameSkipField = 0;
00061 if (!mImageStills)
00062 {
00063 OglGui::TextArea* tArea = new OglGui::TextArea(this, 80, 1*line,
00064 "Frame skip");
00065 tArea->SetBorderType(0);
00066 mFrameSkipField = new OglGui::TextField(this, 60, 20, "15");
00067 }
00068 OglGui::Button* but = new OglGui::Button(this, 80, 22, "Update (u)");
00069 but->SetButtonListener(this, 0);
00070 OglGui::Strut* strut = new OglGui::Strut(this, 4000, 1);
00071 int imWidth = (mDoFullSize) ? thumbW/mSegDoc->GetThumbScale() : thumbW;
00072 int imHeight = (mDoFullSize) ? thumbH/mSegDoc->GetThumbScale(): thumbH;
00073 if (mDoFullSize)
00074 {
00075 nrImOnRow = 4;
00076 mViewScale = 0.85 * mViewScale;
00077 }
00078 int nrRow = (mDoFullSize) ? 4 : 7;
00079 mNrIm = nrImOnRow * nrRow;
00080 mImagesSet = new ImageSet(this, imWidth, imHeight, mViewScale,
00081 nrImOnRow, nrRow);
00082 mImagesSet->SetMakeViewWithRect(true);
00083 mImagesSet->ActivateInfoBox(false);
00084 mImagesSet->SetImagesListener(this, 0);
00085 SetAsBox(mImagesSet);
00086 }
00087
00088 virtual void HandleNewFile()
00089 {
00090
00091
00092 if ((mCheckBox->GetSelected() || mForceUpdate))
00093 mImagesSet->RemoveImages();
00094 if (mSegDoc->HasCurShot() && (mCheckBox->GetSelected() || mForceUpdate))
00095 {
00096 bool done = false;
00097 if (mImageStills)
00098 done = UpdateFromJpg();
00099 if (!done)
00100 UpdateFromMpg();
00101 Core::Geometry::Rectangle r = mSegDoc->GetRect();
00102 for (int i=0 ; i<mImagesSet->NrViewers() ; i++)
00103 mImagesSet->GetViewWithRect(i)->SetRect(r);
00104 }
00105 mForceUpdate = false;
00106 UpdateScene();
00107 }
00108
00109 virtual void HandleNewKey(int c, int state)
00110 {
00111
00112 if (c == 'u')
00113 {
00114 mForceUpdate = true;
00115 HandleNewFile();
00116 }
00117 }
00118
00119 virtual void ButtonSelectionEvent(OglGui::Button* src, void* listenerData)
00120 {
00121 mForceUpdate = true;
00122 HandleNewFile();
00123 }
00124
00125
00126 virtual void OnViewMouse(OglGui::View* view, int msg, int btn, int state,
00127 float x, float y)
00128 {
00129 ViewWithRect* viewR = (ViewWithRect*) view;
00130 Core::Geometry::Rectangle r = viewR->GetRect();
00131 if (mDoFullSize)
00132 mSegDoc->SetRect(r, mViewScale);
00133 else
00134 mSegDoc->SetRectThumb(r);
00135 }
00136
00137 private:
00138
00139 void UpdateFromMpg()
00140 {
00141 int shot = mSegDoc->CurShot();
00142 int vidId = mSegDoc->CurFileId();
00143 Core::VideoSet::Segmentation* shots = mSegDoc->GetSegmentation();
00144 int startF = shots->GetStart(shot) + 1;
00145 int endF = shots->GetEnd(shot);
00146 Core::Stream::RgbDataSrc* src = mSegDoc->GetVideoSet()->GetVideo(vidId);
00147 if (!src)
00148 return;
00149 int skipFr = 15;
00150 if (mFrameSkipField)
00151 skipFr = atol(mFrameSkipField->GetText());
00152 int interval = (endF - startF) / (mNrIm - 1);
00153 if (interval < skipFr)
00154 interval = skipFr;
00155 #ifdef unix
00156 #define NO_PLAYER
00157 #endif
00158 #ifdef NO_PLAYER
00159
00160
00161 #else
00162 src->SetInterval(interval);
00163 while (startF < endF)
00164 {
00165 src->GotoFrame(startF);
00166 Array2dVec3UInt8* im = Core::Array::ArrayCreate<Array2dVec3UInt8>
00167 (src->FrameWidth(), src->FrameHeight(), 0, 0,
00168 src->DataPtr(), true);
00169 Array2dVec3UInt8* sc = 0;
00170 if (mDoFullSize)
00171 Core::Array::Set(sc, im);
00172 else
00173 Core::Array::Scale(sc, im, mSegDoc->GetThumbScale(),
00174 mSegDoc->GetThumbScale(),
00175 Core::Geometry::NEAREST, true);
00176 std::string cap = std::string("frame ") + MakeString(startF);
00177 mImagesSet->AddImage(sc, std::string("Direct"), cap, true);
00178 delete im;
00179 startF += interval;
00180 }
00181 #endif
00182 }
00183
00184 bool UpdateFromJpg()
00185 {
00186 Core::ImageSet::ImageSet* imSetStills = mSegDoc->GetImSetStills();
00187 if (!imSetStills)
00188 return false;
00189 int shot = mSegDoc->CurShot();
00190 int start = mStills->GetFirstStillShot(shot);
00191 int end = start + mStills->GetNrStillsShot(shot);
00192 for (int i=start ; i<end ; i++)
00193 {
00194 Array2dVec3UInt8* im = imSetStills->GetImage(i);
00195 Array2dVec3UInt8* sc = 0;
00196 if (mDoFullSize)
00197 Core::Array::Set(sc, im);
00198 else
00199 Core::Array::Scale(sc, im, mSegDoc->GetThumbScale(),
00200 mSegDoc->GetThumbScale(),
00201 Core::Geometry::NEAREST, true);
00202 mImagesSet->AddImage(sc, std::string("Direct"), "", true);
00203 delete im;
00204 }
00205 return true;
00206 }
00207
00208 void SetAsBox(OglGui::Window *w)
00209 {
00210
00211 w->SetBorderType(4);
00212 w->SetBorderFillShaded(2);
00213 }
00214
00215 bool mDoFullSize;
00216 bool mImageStills;
00217 bool mForceUpdate;
00218
00219 double mViewScale;
00220
00221 int mNrIm;
00222
00223 SegmentationDocument* mSegDoc;
00224 Stills* mStills;
00225
00226 OglGui::CheckBox* mCheckBox;
00227 OglGui::TextField* mFrameSkipField;
00228 ImageSet* mImagesSet;
00229
00230 ILOG_VAR_DEC;
00231 };
00232
00233 ILOG_VAR_INIT(SegmentationDocumentGuiStills, Visualization);
00234
00235 }
00236 }
00237
00238 #endif