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

mainPlay.cpp

Go to the documentation of this file.
00001 // RvB: This App works best with APP_CONTROLLER_ALT set
00002 #define APP_CONTROLLER_ALT
00003 
00004 #include "Visualization/VideoNav.h"
00005 #include "Visualization/AppControlSrc.h"
00006 #include "Core/Stream/RgbDataSrcFactory.h" // dies as first include with VC8??
00007 #include "Link/DiskImage/DiskImageFuncs.h"
00008 
00009 // since we are not using libraries:
00010 #include "Link/ImpalaLib.cpp"
00011 #include "OglGui/OglLib.cpp"
00012 
00013 namespace Impala {
00014 namespace Application {
00015 
00016 using namespace Visualization;
00017 using namespace Core::Array;
00018 using namespace Core::Stream;
00019 
00020 class WindowPlay : public Window, public AppControlSrc,
00021                    public VideoNavListener, public OglGui::ViewListener
00022 {
00023 public:
00024 
00025     WindowPlay(int x, int y, bool doZoom, bool mainIs2d, bool vpIs2d,
00026                RgbDataSrc* src) :
00027         Window(x, y, SuggestWndWidth(1, src->FrameWidth()) + (doZoom ? 270 : 0),
00028                SuggestWndHeight(1, src->FrameHeight()) + 25 + 25, mainIs2d),
00029         AppControlSrc(1)
00030     {
00031         CmdOptions& options = CmdOptions::GetInstance();
00032         SetSrc(src); // tell AppControlSrc about src
00033         AppController::Instance().AddControl((AppControlSrc*) this, true);
00034 
00035         mViewScale = options.GetDouble("viewScale");
00036         mVideoNav = new VideoNav(this, src);
00037         mVideoNav->SetVideoNavListener(this);
00038         mRoiWidth = 32;
00039         mRoiHeight = 32;
00040         mZoomFac = 5;
00041         int zWidth = mRoiWidth * mZoomFac;
00042         int zHeight = mRoiHeight * mZoomFac;
00043         mZoomedIm = 
00044             (doZoom) ? ArrayCreate<Array2dVec3UInt8>(zWidth, zHeight) : 0;
00045         mVp =
00046             (doZoom) ? MakeViewport(zWidth+40, zHeight+40, vpIs2d) : 0;
00047 
00048 #if defined(OGL_USING_GLUT) && !defined(APP_CONTROLLER_ALT)
00049         SetAlwaysDraw(); // UpdateScene() doesn't work.
00050 #endif
00051         MapKeysTo(mVideoNav);
00052         AppController::Instance().MainLoop();
00053     }
00054 
00055     void Zoom()
00056     {
00057         View* srcView = mVideoNav->GetView(0);
00058         if (!srcView)
00059             return;
00060         if ((mZoomedIm == 0) || (srcView->GetPointerX() < 0))
00061             return;
00062         Array2dVec3UInt8* dispIm = srcView->GetDispImage();
00063         if (!dispIm)
00064             return;
00065 
00066         unsigned char* dataPtr = dispIm->CPB(0, 0);
00067         int srcSX = srcView->GetPointerX() - mRoiWidth/2;
00068         if (srcSX < 0)
00069             srcSX = 0;
00070         if (srcSX > dispIm->CW()-1-mRoiWidth)
00071             srcSX = dispIm->CW()-1-mRoiWidth;
00072         int srcSY = srcView->GetPointerY() - mRoiHeight/2;
00073         if (srcSY < 0)
00074             srcSY = 0;
00075         if (srcSY > dispIm->CH()-1-mRoiHeight)
00076             srcSY = dispIm->CH()-1-mRoiHeight;
00077         for (int y=0 ; y<mRoiHeight ; y++)
00078         {
00079             unsigned char* src = dispIm->CPB(srcSX, srcSY + y);
00080             for (int x=0 ; x<mRoiWidth ; x++)
00081             {
00082                 for (int zY=0 ; zY<mZoomFac ; zY++)
00083                 {
00084                     unsigned char* dst = mZoomedIm->CPB(x*mZoomFac,
00085                                                         y*mZoomFac + zY);
00086                     for (int zX=0 ; zX<mZoomFac ; zX++)
00087                     {
00088                         for (int i=0 ; i<3 ; i++) {
00089                             *dst++ = src[i];
00090                         }
00091                     }
00092                 }
00093                 src += 3;
00094             }
00095         }
00096         mVp->UpdateView(0, mZoomedIm, "Direct", mViewScale, 0);
00097         mVideoNav->SetRect(Core::Geometry::Rectangle(srcSX, srcSY,
00098                                                  srcSX + mRoiWidth,
00099                                                  srcSY + mRoiHeight));
00100     }
00101 
00102     void HandleCycleSrc()
00103     {
00104 // RvB: Should not be necessary and causes alwaysdraw behaviour
00105 //        UpdateScene();
00106         SetStatusStr((char*) GetFpsString().c_str());
00107     }
00108 
00109     void HandleNewFrame()
00110     {
00111         mVideoNav->UpdateView(0, GetSrc()->DataPtr(), GetSrc()->FrameWidth(),
00112                               GetSrc()->FrameHeight(), mViewScale, this);
00113         Zoom();
00114     }
00115 
00116     // specialization of base classes
00117 
00118     void NavFrameEvent(VideoNav* src, int requestedFrame, void* listenerData)
00119     {
00120         Jump(requestedFrame);
00121     }
00122 
00123     virtual void OnViewMouse(OglGui::View* view, int msg, int btn, int state,
00124                              float x, float y)
00125     {
00126         Zoom();
00127     }
00128 
00129 #ifdef APP_CONTROLLER_ALT
00130     // RvB: Test PP-Def APP_CONTROLLER_ALT
00131     virtual void DisplayFunc()
00132     {
00133         SetAlwaysDraw(GetDoContinuous());
00134         AppControlSrc::ComputeCycle(0.04);
00135         if (AppControlSrc::Done())
00136             exit(0);
00137         Window::DisplayFunc();
00138     }
00139 #endif
00140 
00141 private:
00142 
00143     double        mViewScale;
00144     int           mRoiWidth; // size of roi, before zooming
00145     int           mRoiHeight;
00146     int           mZoomFac;
00147 
00148     Array2dVec3UInt8* mZoomedIm;
00149     Window*           mVp;
00150     VideoNav*         mVideoNav;
00151 
00152 }; // class
00153 
00154 int
00155 mainPlay(int argc, char* argv[])
00156 {
00157     OglInit(&argc, &argv[0]);
00158     CmdOptions& options = CmdOptions::GetInstance();
00159     options.Initialise(true, false, true);
00160     options.AddOption(0, "noZoom", "", "0");
00161     options.AddOption(0, "3d", "", "0");
00162 
00163     if (Link::DiskImage::DiskImageUsed())
00164         options.AddOption(0, "javacp", "classpath", "");
00165 
00166     if (! options.ParseArgs(argc, argv, "camera|filename", 1))
00167         return 1;
00168 
00169     ILOG_VAR(Application.mainPlay);
00170 
00171     String srcName = options.GetArg(0);
00172     bool doZoom = ! options.GetBool("noZoom");
00173     bool is2d = ! options.GetBool("3d");
00174 
00175     RgbDataSrcFactory& factory = RgbDataSrcFactory::Instance();
00176     Persistency::RgbDataSrcLocator loc("dot", srcName, options);
00177     RgbDataSrc* src = factory.Construct(loc, options.GetString("src"));
00178     if (! src->Valid())
00179     {
00180         ILOG_ERROR("RgbDataSrc failed");
00181         return 0;
00182     }
00183     ILOG_INFO(src->LastFrame()+1 << " frames of " << src->FrameWidth() 
00184               << " x " << src->FrameHeight());
00185     ILOG_INFO("length " << src->LastFrameAsTime());
00186 
00187     src->DumpInfo();
00188 
00189     WindowPlay* oglWnd = new WindowPlay(0, 0, doZoom, true, is2d, src);
00190     if (! oglWnd->Valid())
00191     {
00192         ILOG_ERROR("WindowPlay failed");
00193         return 0;
00194     }
00195     return 1;
00196 }
00197 
00198 } // namespace Application
00199 } // namespace Impala
00200 
00201 int
00202 main(int argc, char* argv[])
00203 {
00204     return Impala::Application::mainPlay(argc, argv);
00205 }

Generated on Fri Mar 19 09:30:29 2010 for ImpalaSrc by  doxygen 1.5.1