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

RotorDoDView.h

Go to the documentation of this file.
00001 //345678901234567890123456789012345678901234567890123456789012345678901234567890
00002 #ifndef Impala_Visualzation_RotorBrowser_RotorDoDView_h
00003 #define Impala_Visualzation_RotorBrowser_RotorDoDView_h
00004 
00005 #ifndef OglGui_View
00006 #include "OglGui/View.h"
00007 #endif
00008 
00009 #ifndef OglGui_Window
00010 #include "OglGui/Window.h"
00011 #endif
00012 
00013 namespace Impala {
00014 namespace Visualization {
00015 namespace RotorBrowser {
00016 
00017 using namespace OglGui;
00018 
00019 class RectangleListener
00020 {
00021 public:
00022     virtual void
00023     OnRectangleSelect(float x, float y, float w, float h) = 0;
00024 };
00025 
00026 class RotorDoDView : public OglGui::View
00027 {
00028 public:
00029     RotorDoDView(OGLWND* oglWnd, OGLIMAGE *oglIm, float x, float y, float z,
00030                  float w, float h, float d, ViewListener* li=0) :
00031         OglGui::View(oglWnd, oglIm, x, y, z, w, h, d, li)
00032     {
00033         // ILOG_DEBUG("RotorDoDView()");;
00034         // SetTags(FlexViewTags);
00035         mIsDragging         = false;
00036         mRotorView          = NULL;
00037         mObscure            = 0;
00038         mPositiveAlpha      = 0;
00039         mNegativeAlpha      = 0;
00040         mProbabilityAlpha   = 0;
00041     }
00042 
00043     void SetObscure(float a)         { mObscure = a; }
00044     void PositiveAlpha(float a)      { mPositiveAlpha = a; } 
00045     void NegativeAlpha(float a)      { mNegativeAlpha = a; } 
00046     void ProbabiltyAlpha(float a)    { mProbabilityAlpha = a; } 
00047 
00048     void LeftCornerTriangle(int r, int g, int b, int a)
00049     {
00050         if (a <= 0.f) return;
00051         INT bInfo[3];
00052         oglSys.StartBlend(bInfo);
00053         OGCSetPolyFillMode(theOGC,3);
00054         ULONG col = RGBA2COLOR(r,g,b,a);
00055         SetSolidFillColor(col);
00056         OGLVIEW3D* v3D = GetOGLVIEW3D();
00057         float x = -v3D->w/2;
00058         float y = -v3D->h/2;
00059         float coords[6];
00060         coords[0] = x;
00061         coords[1] = y;
00062         coords[2] = x + v3D->w/2;
00063         coords[3] = y;
00064         coords[4] = x;
00065         coords[5] = y + v3D->h/2;
00066         FillTriangles(coords,3);
00067         oglSys.EndBlend(bInfo);
00068     }
00069 
00070     void HandleObscure()
00071     {
00072         if (mObscure <= 0.f) return;
00073         INT bInfo[3];
00074         oglSys.StartBlend(bInfo);
00075         int alpha = mObscure * 255;
00076         ULONG col = RGBA2COLOR(64,64,64,alpha);
00077         SetSolidFillColor(col);
00078         OGLVIEW3D* v3D = GetOGLVIEW3D();
00079         float x = -v3D->w/2+0.01;
00080         float y = -v3D->h/2+0.01;
00081         FillRectangle3D(x,y,0.01,v3D->w-0.02,v3D->h-0.02);
00082         oglSys.EndBlend(bInfo);
00083     }
00084 
00085     void HandleProbability()
00086     {
00087         // TODO implement
00088     }
00089 
00090     void HandlePositiveNegative()
00091     {
00092         glPushMatrix();
00093         glTranslatef(0,0,0.02);
00094         LeftCornerTriangle(0,255,0,mPositiveAlpha*255);
00095         LeftCornerTriangle(255,0,0,mNegativeAlpha*255);
00096         glPopMatrix();
00097     }
00098 
00099     void HandleDragRect()
00100     {
00101         if (!mIsDragging) return;
00102 
00103         OGC prevOGC;
00104         OGCSave( &prevOGC );
00105         SetLineWidth(2);
00106         SetSolidLineColor(0xffdddd22);
00107         DrawRectangle3D(mDragLX,mDragLY,0.01,mDragHX-mDragLX,mDragHY-mDragLY);
00108         OGCRestore( &prevOGC );
00109     }
00110 
00111     // allow for rectangle-based selecting in 3D:
00112     virtual void OnMouse(int msg, int btn, int state, float x, float y)
00113     {
00114         OglGui::View::OnMouse(msg, btn, state, x, y);
00115         float h = mView3D->h;
00116         float w = mView3D->w;
00117 
00118         if (msg == oglMouseDown && btn == oglLeftButton)
00119         {
00120             if (mIsDragging)
00121             {
00122                 // execute if click within box, cancel if outside:
00123                 if (mDragLX<=x && x<=mDragHX && mDragLY<=y && y<=mDragHY)
00124                 {
00125                     float sx, sy, sw, sh;
00126                     sx = mDragLX/w;
00127                     sy = mDragLY/h;
00128                     sw = (mDragHX - mDragLX)/w;
00129                     sh = (mDragHY - mDragLY)/h;
00130                     if (mRotorView && sw > 1 && sh > 1)
00131                         mRotorView->OnRectangleSelect(sx,1.0-(sy+sh),sw,sh);
00132                 }
00133                 mIsDragging = false;
00134             }
00135             else
00136             {
00137                 mDragLX = mDragHX = x;
00138                 mDragLY = mDragHY = y;
00139                 mIsDragging = true;
00140             }
00141         }
00142         if (msg == oglMouseMove && mIsDragging)
00143         {
00144             if (x < mDragLX) mDragLX = x;
00145             if (x > mDragHX) mDragHX = x;
00146             if (y < mDragLY) mDragLY = y;
00147             if (y > mDragHY) mDragHY = y;
00148 
00149             if (mDragLX < -w/2) mDragLX = -w/2;
00150             if (mDragLY < -h/2) mDragLY = -h/2;
00151             if (mDragHX > w/2)  mDragHX = w/2;
00152             if (mDragHY > h/2)  mDragHY = h/2;
00153         }
00154     }
00155 
00156     virtual void OnDrawView()
00157     {
00158         OglGui::View::OnDrawView();
00159         HandleObscure();
00160         HandlePositiveNegative();
00161         HandleProbability();
00162         HandleDragRect();
00163     }
00164 
00165     virtual void OnSelection(bool selected)
00166     {
00167         OglGui::View::OnSelection(selected);
00168         ILOG_DEBUG("OnSelection(" << selected <<")");
00169     }
00170 
00171     void SetCurrentRotorView(RectangleListener *rv)
00172     {
00173         mRotorView = rv;
00174         mIsDragging = false; // reset rectangle when RotorView changes
00175     }
00176 
00177     /* checks if this View's image resolution is the same as
00178        a given resolution, used in MDViewCache */
00179     bool HasResolution(int w, int h)
00180     {
00181         if (!mView3D->im) return false;
00182         return h == mView3D->im->h && w == mView3D->im->w;
00183     }
00184 
00185     float                   mDragLX, mDragHX;
00186     float                   mDragLY, mDragHY;
00187     bool                    mIsDragging;
00188 
00189     float                   mObscure;
00190     float                   mPositiveAlpha;
00191     float                   mNegativeAlpha;
00192     float                   mProbabilityAlpha;
00193 
00194     RectangleListener*      mRotorView;
00195 
00196     ILOG_VAR_DEC;
00197 
00198 }; // class RotorDoDView
00199 
00200 ILOG_VAR_INIT(RotorDoDView, Visualization.RotorBrowser);
00201 
00202 }
00203 }
00204 }
00205 
00206 #endif

Generated on Fri Mar 19 09:31:52 2010 for ImpalaSrc by  doxygen 1.5.1