00001 #include "Persistency/RepositoryInFileSystem.h"
00002 #include "Core/Array/Arrays.h"
00003 #include "Persistency/ImageArchiveRepository.h"
00004 #include "Persistency/ImageRepository.h"
00005 #include "Core/Array/ImageArchiveFile.h"
00006 #include "Core/Array/ImageArchiveFileFset.h"
00007 #include "Visualization/Window.h"
00008
00009 #include "Visualization/DirImViewerScroller.h"
00010
00011
00012 #include "OglGui/OglLib.cpp"
00013
00014
00015 namespace Impala
00016 {
00017 namespace Application
00018 {
00019
00020
00021 using namespace Impala::Util;
00022 using namespace Impala::Persistency;
00023 using namespace Impala::Core::Array;
00024
00025 template <class ArrayT>
00026 class WindowShow : public Visualization::Window
00027 {
00028 public:
00029
00030 WindowShow(String locString, String setName, String fileName,
00031 String dispMode) :
00032 Visualization::Window(0, 0, 400, 400 + 25, true)
00033 {
00034 CmdOptions& options = CmdOptions::GetInstance();
00035 bool fset = options.GetBool("fset");
00036 mArchive = 0;
00037 mDispMode = dispMode;
00038 if (fset || (FileNameExt(fileName) == "fset"))
00039 {
00040 ImageArchiveLocator loc(locString, setName, fileName);
00041 loc.SetIsFset(true);
00042 mArchive = ImageArchiveRepository().Get(loc);
00043 mFileIm = 0;
00044 UpdateFileImage(0);
00045 SetDimensions(0, 0, mFileIm->CW() + 2, mFileIm->CH() + 25);
00046 }
00047 else if (FileNameExt(fileName) != "raw")
00048 {
00049
00050
00051
00052
00053
00054
00055
00056 ImageLocator loc(locString, setName, "", fileName);
00057 Array2dVec3UInt8* im = ImageRepository().Get(loc);
00058 mImages.push_back((ArrayT*) im);
00059 SetDimensions(0, 0, im->CW() + 2, im->CH() + 25);
00060 }
00061 else if ((mDispMode == "jpg") || (mDispMode == "png"))
00062 {
00063 ImageArchiveLocator loc(locString, setName, fileName);
00064 mArchive = ImageArchiveRepository().Get(loc);
00065 mFileIm = 0;
00066 UpdateFileImage(0);
00067 SetDimensions(0, 0, mFileIm->CW() + 2, mFileIm->CH() + 25);
00068 }
00069 else
00070 {
00071 Locator loc(locString, setName);
00072 RepositoryInFileSystem& rep = RepositoryInFileSystem::GetInstance();
00073 Persistency::File f = rep.GetFile(loc, "", fileName, false, false);
00074 ReadRawList(mImages, f);
00075 SetDimensions(0, 0, mImages[0]->CW() + 2, mImages[0]->CH() + 25);
00076 }
00077 mCurNr = -1;
00078 RequestNext(1);
00079 Visualization::AppController::Instance().MainLoop();
00080 }
00081
00082 int
00083 NrImages()
00084 {
00085 if (mArchive)
00086 return mArchive->NrImages();
00087 return mImages.size();
00088 }
00089
00090 void
00091 RequestNext(int inc)
00092 {
00093 int newNr = mCurNr + inc;
00094 if (newNr < 0)
00095 newNr = 0;
00096 if (newNr >= NrImages())
00097 newNr = NrImages() - 1;
00098 if (newNr != mCurNr)
00099 {
00100 mCurNr = newNr;
00101 ShowCurImage("");
00102 }
00103 }
00104
00105 void
00106 UpdateStatusBuf()
00107 {
00108 std::ostrstream statusStream;
00109 statusStream << "At nr " << mCurNr+1 << " of " << NrImages()
00110 << ", display : " << mDispMode << std::ends;
00111 SetStatusStr(statusStream.str());
00112 statusStream.freeze(false);
00113 }
00114
00115 void
00116 ShowCurImage(String dispMode)
00117 {
00118 if (!dispMode.empty())
00119 mDispMode = dispMode;
00120 ArrayT* im = 0;
00121 if (mArchive)
00122 {
00123 UpdateFileImage(mCurNr);
00124 UpdateView(0, mFileIm, "Direct");
00125 im = mFileIm;
00126 }
00127 else
00128 {
00129 UpdateView(0, mImages[mCurNr], mDispMode);
00130 im = mImages[mCurNr];
00131 }
00132 ILOG_INFO("image size = " << im->CW() << " x " << im->CH());
00133 UpdateStatusBuf();
00134 }
00135
00136 protected:
00137
00138 virtual void
00139 MouseFunc(INT msg, INT but, INT state, INT x, INT y)
00140 {
00141 Visualization::Window::MouseFunc(msg, but, state, x, y);
00142
00143 if ((mDispMode == "jpg") || (mDispMode == "png"))
00144 {
00145 return;
00146 }
00147
00148 if ((msg == oglMouseDown) && (but == oglRightButton))
00149 {
00150 OGLMENU menu = oglSys.MenuCreate();
00151 oglSys.MenuAdd(menu, "Direct", 0, 11);
00152 oglSys.MenuAdd(menu, "Stretch", 0, 12);
00153 oglSys.MenuAdd(menu, "Sigma", 0, 13);
00154 oglSys.MenuAdd(menu, "StrMax", 0, 14);
00155 oglSys.MenuAdd(menu, "LogMagnitude", 0, 15);
00156 oglSys.MenuAdd(menu, "Binary", 0, 16);
00157 oglSys.MenuAdd(menu, "Label", 0, 17);
00158 oglSys.MenuAdd(menu, "Label60", 0, 18);
00159
00160 int choice = oglSys.MenuPopUp(mOglWnd, menu);
00161
00162 switch (choice)
00163 {
00164 case 11: ShowCurImage("Direct"); break;
00165 case 12: ShowCurImage("Stretch"); break;
00166 case 13: ShowCurImage("Sigma"); break;
00167 case 14: ShowCurImage("StrMax"); break;
00168 case 15: ShowCurImage("LogMagnitude"); break;
00169 case 16: ShowCurImage("Binary"); break;
00170 case 17: ShowCurImage("Label"); break;
00171 case 18: ShowCurImage("Label60"); break;
00172 }
00173
00174 oglSys.MenuDestroy(menu);
00175 oglSys.UpdateSceneFlag(mOglWnd, 1);
00176 }
00177 }
00178
00179 virtual void
00180 KeyboardFunc(INT c, int state)
00181 {
00182 if (c == oglRIGHT)
00183 RequestNext(1);
00184 if (c == oglLEFT)
00185 RequestNext(-1);
00186 if (c == 'Q')
00187 exit(0);
00188
00189 Visualization::Window::KeyboardFunc(c, state);
00190 }
00191
00192 private:
00193
00194 void
00195 UpdateFileImage(int nr)
00196 {
00197 if (mFileIm)
00198 delete mFileIm;
00199 if (mArchive)
00200 mFileIm = (ArrayT*) mArchive->ReadImage(nr);
00201 }
00202
00203 std::vector<ArrayT*> mImages;
00204 int mCurNr;
00205 String mDispMode;
00206
00207 ImageArchive* mArchive;
00208 ArrayT* mFileIm;
00209
00210 ILOG_VAR_DEC;
00211 };
00212
00213 ILOG_VAR_INIT_TEMPL_1(WindowShow, ArrayT, Application);
00214
00215
00216 int
00217 mainShow(int argc, char* argv[])
00218 {
00219 OglInit(&argc, &argv[0]);
00220 CmdOptions& options = CmdOptions::GetInstance();
00221 options.Initialise(false, false, true);
00222 options.AddOption(0, "grid", "", "0");
00223 options.AddOption(0, "png", "", "0");
00224 options.AddOption(0, "fset", "", "0");
00225 options.AddOption(0, "wndWidth", "width", "1260");
00226 options.AddOption(0, "wndHeight", "height", "950");
00227 String usageStr = "location dataset filename\n\n";
00228 usageStr += " location = file:|dataServer:host:port|mapi:host:port:[db]\n";
00229 usageStr += " dataset = dot|abs|dataset.txt\n";
00230 usageStr += " filename = file.{raw,jpg,png,fset}\n";
00231 if (! options.ParseArgs(argc, argv, usageStr, 3))
00232 return 1;
00233
00234 ILOG_VAR(Impala.Application.mainShow);
00235
00236 int verb = options.GetInt("verb");
00237 bool png = options.GetBool("png");
00238
00239 bool grid = options.GetBool("grid");
00240 int reqWndWidth = options.GetInt("wndWidth");
00241 int reqWndHeight = options.GetInt("wndHeight");
00242
00243 String loc = options.GetArg(0);
00244 String setName = options.GetArg(1);
00245 String fileName = options.GetArg(2);
00246
00247 if (FileNameExt(fileName) != "raw")
00248 {
00249 ILOG_DEBUG("new WindowShow<Array2dVec3UInt8>(direct)");
00250 new WindowShow<Array2dVec3UInt8>(loc, setName, fileName, "Direct");
00251 return 0;
00252 }
00253
00254 ArrayType arrayType = ARRAY2DSCALARUINT8;
00255 if (loc != "mapi:")
00256 {
00257 arrayType = ARRAY2DUNKNOWN;
00258 RepositoryInFileSystem& repFS = RepositoryInFileSystem::GetInstance();
00259 Locator locator(loc, setName);
00260 Persistency::File f = repFS.GetFile(locator, "", fileName, false, true);
00261 if (f.Valid())
00262 arrayType = ReadRawArrayType(f);
00263 else
00264 ILOG_ERROR("Unable to open " << fileName << " at " << locator);
00265 }
00266
00267 switch (arrayType)
00268 {
00269 case ARRAY2DSCALARUINT8:
00270 if (grid)
00271 {
00272 ILOG_INFO("new DirImViewerScroller");
00273 Visualization::DirImViewerScroller *gridViewer =
00274 new Visualization::DirImViewerScroller(4, 4, reqWndWidth,
00275 reqWndHeight);
00276 Persistency::RgbDataSrcLocator srcLoc(loc, setName, fileName);
00277 gridViewer->OpenSrc(srcLoc);
00278 gridViewer->SetBackground(oglGUI_BG);
00279 gridViewer->Start();
00280 OglEventLoop();
00281 return 1;
00282 }
00283 ILOG_DEBUG("new WindowShow<Array2dVec3UInt8>(jpg/png)");
00284 if (png)
00285 new WindowShow<Array2dVec3UInt8>(loc, setName, fileName, "png");
00286 else
00287 new WindowShow<Array2dVec3UInt8>(loc, setName, fileName, "jpg");
00288 return 0;
00289 case ARRAY2DSCALARINT32:
00290 ILOG_DEBUG("new WindowShow<Array2dScalarInt32>(stretch)");
00291 new WindowShow<Array2dScalarInt32>(loc, setName, fileName, "Stretch");
00292 return 0;
00293 case ARRAY2DSCALARREAL64:
00294 ILOG_DEBUG("new WindowShow<Array2dScalarReal64>(stretch)");
00295 new WindowShow<Array2dScalarReal64>(loc, setName, fileName, "Stretch");
00296 return 0;
00297 case ARRAY2DVEC3UINT8:
00298 ILOG_DEBUG("new WindowShow<Array2dVec3UInt8>(direct)");
00299 new WindowShow<Array2dVec3UInt8>(loc, setName, fileName, "Direct");
00300 return 0;
00301
00302
00303
00304
00305
00306
00307 case ARRAY2DVEC3REAL64:
00308 ILOG_DEBUG("new WindowShow<Array2dVec3Real64>(stretch)");
00309 new WindowShow<Array2dVec3Real64>(loc, setName, fileName, "Stretch");
00310 return 0;
00311 default:
00312 ILOG_ERROR("Unknown Array type");
00313 return 1;
00314 }
00315 return 1;
00316 }
00317
00318 }
00319 }
00320
00321 int
00322 main(int argc, char* argv[])
00323 {
00324 return Impala::Application::mainShow(argc, argv);
00325 }