Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

vuKeyFrameCanvas.cpp

Go to the documentation of this file.
00001 #include "vuKeyFrameCanvas.h"
00002 #include "vuColourRGBa.h"
00003 //#include "../vuTransferDialog/vuTransferDialog.h"
00004 #include <GL/gl.h>
00005 #include <GL/glu.h>
00006 #include <math.h>
00007 
00008 BEGIN_EVENT_TABLE(vuKeyFrameCanvas, vuGLCanvas)
00009     EVT_MOUSE_EVENTS(vuKeyFrameCanvas::OnMouse)
00010 END_EVENT_TABLE()
00011 
00012 //----------------------------------------------------------------------------
00013 //------------------------- The constructor ----------------------------------
00014 //----------------------------------------------------------------------------
00015 
00016 vuKeyFrameCanvas::vuKeyFrameCanvas(wxWindow *parent,wxWindowID id,bool edit)
00017   : vuGLCanvas(parent,id,wxDefaultPosition,wxDefaultSize,0,"vuKeyFrameCanvas",NULL)
00018     , m_Edit(edit),m_xMin(0),m_xMax(255),m_yMin(0),m_yMax(1)
00019 {
00020     m_Opacity = m_Colour = (dword) -1;
00021 
00022     m_xScreenMin = m_xMin;
00023     m_xScreenMax = m_xMax;
00024     m_yScreenMin = m_yMin;
00025     m_yScreenMax = m_yMax;
00026 
00027 }
00028 
00029 //----------------------------------------------------------------------------
00030 //------------------------- The destructor -----------------------------------
00031 //----------------------------------------------------------------------------
00032 
00033 vuKeyFrameCanvas::~vuKeyFrameCanvas()
00034 {
00035 }
00036 
00037 //----------------------------------------------------------------------------
00038 //------------------------- public: setOpacitiesmoothing() -------------------
00039 //----------------------------------------------------------------------------
00040 
00041 void vuKeyFrameCanvas::setSmoothing(float opacity, float colour)
00042 {
00043     redraw();
00044 }
00045 
00046 
00047 //----------------------------------------------------------------------------
00048 //------------------------- protected: glInit() ------------------------------
00049 //----------------------------------------------------------------------------
00050 
00051 bool vuKeyFrameCanvas::glInit(void)
00052 {
00053     glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
00054 
00055     //Set up the coordinate system.
00056     glMatrixMode(GL_MODELVIEW);
00057     glLoadIdentity();
00058     glMatrixMode(GL_PROJECTION);
00059     glLoadIdentity();
00060     gluOrtho2D(m_xScreenMin,m_xScreenMax,m_yScreenMin,m_yScreenMax);
00061 
00062     return true;
00063 };
00064 
00065 //----------------------------------------------------------------------------
00066 //------------------------- protected: resize() ------------------------------
00067 //----------------------------------------------------------------------------
00068 
00069 void vuKeyFrameCanvas::resize()
00070 {
00071     glViewport(0, 0, (GLint)getWidth(),(GLint)getHeight());
00072 
00073     //Recalculate the grid values
00074     m_dx = float(m_xMax-m_xMin) / getWidth();
00075     m_dy = float(m_yMax-m_yMin) / getHeight();
00076 
00077     if (m_Edit)
00078     {
00079         //Fix the coordinate system.
00080         m_xScreenMin = m_xMin-10*m_dx;
00081         m_xScreenMax = m_xMax+10*m_dx;
00082         m_yScreenMin = m_yMin-30*m_dy;
00083         m_yScreenMax = m_yMax+10*m_dy;
00084 
00085         glMatrixMode(GL_MODELVIEW);
00086         glLoadIdentity();
00087         glMatrixMode(GL_PROJECTION);
00088         glLoadIdentity();
00089         gluOrtho2D(m_xScreenMin,m_xScreenMax,m_yScreenMin,m_yScreenMax);
00090     }
00091 }
00092 
00093 //----------------------------------------------------------------------------
00094 //------------------------- protected: render() ------------------------------
00095 //----------------------------------------------------------------------------
00096 
00097 void vuKeyFrameCanvas::render()
00098 {
00099     glClear(GL_COLOR_BUFFER_BIT);
00100 
00101     //First fill in the graph.
00102     //Draw the colour regions
00103     glBegin(GL_QUADS);
00104     for (dword i = m_xMin; i <= m_xMax; i++)
00105     {
00106         vuColourRGBa rgba;
00107 
00108         glColor3fv(rgba.getData());
00109         glVertex2f(i-0.5,-20*m_dy);
00110         glVertex2f(i+0.5,-20*m_dy);
00111     }
00112     glEnd();
00113 
00114     //When editing, draw all the helper lines
00115     if (m_Edit)
00116     {
00117         //Draw the surrounding box
00118         glBegin(GL_LINE_LOOP);
00119         glColor3f(1,1,1);
00120         glVertex2f(m_xMin,m_yMin-20*m_dy);
00121         glVertex2f(m_xMax,m_yMin-20*m_dy);
00122         glVertex2f(m_xMax,m_yMax);
00123         glVertex2f(m_xMin,m_yMax);
00124         glEnd();
00125 
00126         //Draw the polyline opacity function.
00127         glBegin(GL_LINE_STRIP);
00128         glColor3f(1,1,1);
00129         glEnd();
00130 
00131         //Draw the opacity control nodes.
00132         {
00133                 glColor4f(1,0.5,0.5,0.01);
00134                 glColor4f(1,1,1,0.01);
00135 
00136 
00137             glBegin(GL_LINE_LOOP);
00138             glEnd();
00139         }
00140 
00141         //Draw the colour control nodes.
00142         {
00143                 glColor4f(1,1,1,0.01);
00144 
00145             glBegin(GL_LINE_LOOP);
00146             glEnd();
00147         }
00148     }
00149 };
00150 
00151 //----------------------------------------------------------------------------
00152 //------------------------- protected: OnMouse() -----------------------------
00153 //----------------------------------------------------------------------------
00154 
00155 void vuKeyFrameCanvas::OnMouse(wxMouseEvent &ev)
00156 {
00157         int i = 0;
00158     if (ev.ButtonDClick() && !m_Edit)
00159     {
00160         //Pop up dialog Canvas that lets you edit
00161 
00162         {
00163 
00164             postEvent(vuEVT_TRANSFER_CHANGE);
00165             redraw();
00166         }
00167     }
00168     else if (ev.LeftDown() && m_Edit) //Select the clicked control Node
00169     {
00170 
00171         postEvent(vuEVT_TRANSFER_NODE_SELECT);
00172         redraw();
00173     }
00174     else if (ev.LeftDClick() && m_Edit) //Create and/or open up control Node
00175     {
00176         unsigned int x = 0, y = 0;
00177         //If in the colour range, open the clicked colour node, or add a new one
00178         if ((m_Colour != (dword)-1))
00179         {
00180             postEvent(vuEVT_TRANSFER_NODE_OPEN);
00181         }
00182         else if (( x >= m_xMin && x <= m_xMax) && (fabs(-20*m_dy-y) < 4*m_dy))
00183         {
00184           if(m_DoSpectral) {
00185             // This has to be changed!
00186           } else {
00187           }
00188             m_Opacity = (dword)-1;
00189 
00190             postEvent(vuEVT_TRANSFER_CHANGE);
00191             postEvent(vuEVT_TRANSFER_NODE_OPEN);
00192             redraw();
00193         }
00194     }
00195     else if (ev.RightDClick() && m_Edit) //Remove control Node
00196     {
00197         //Translate click into graph coordinates
00198 //        float x = (float(ev.GetX()) / getWidth()) * float(m_xScreenMax - m_xScreenMin) + m_xScreenMin;
00199   //      float y = (float(getHeight() - ev.GetY()) / getHeight()) * float(m_yScreenMax - m_yScreenMin) + m_yScreenMin;
00200 
00201         //Find out if there is an associated Opacity Node and remove it
00202         {
00203             {
00204                 if (int (i) == int (m_Opacity)) m_Opacity = (dword)-1;
00205 
00206                 postEvent(vuEVT_TRANSFER_CHANGE);
00207                 redraw();
00208             }
00209         }
00210 
00211         //Find out if there is an associated colour Node and remove it
00212         {
00213             {
00214                 if (int (i) == int (m_Colour)) m_Colour = (dword)-1;
00215 
00216                 postEvent(vuEVT_TRANSFER_CHANGE);
00217                 redraw();
00218             }
00219         }
00220     }
00221     else if (ev.LeftIsDown() && ev.Dragging() && m_Edit) //Drag the selected control node
00222     {
00223         //Translate into graph coordinates
00224     //    float x = (float(ev.GetX()) / getWidth()) * float(m_xScreenMax - m_xScreenMin) + m_xScreenMin;
00225       //  float y = (float(getHeight() - ev.GetY()) / getHeight()) * float(m_yScreenMax - m_yScreenMin) + m_yScreenMin;
00226 
00227         //Update the dragged Opacity Node, if any.
00228         if ((m_Opacity != (dword)-1))
00229         {
00230             postEvent(vuEVT_TRANSFER_CHANGE);
00231             redraw();
00232         }
00233 
00234         //Update the dragged colour Node, if any.
00235         if ((m_Colour != (dword)-1))
00236         {
00237             postEvent(vuEVT_TRANSFER_CHANGE);
00238             redraw();
00239         }
00240     }
00241 }
00242 
00243 //----------------------------------------------------------------------------
00244 //------------------------- protected: postEvent() ---------------------------
00245 //----------------------------------------------------------------------------
00246 
00247 void vuKeyFrameCanvas::postEvent(wxEventType ev)
00248 {
00249      wxCommandEvent commandEvent(ev, GetId());
00250      commandEvent.SetEventObject( this );
00251      GetEventHandler()->ProcessEvent(commandEvent);
00252 }
00253 
00254 

Generated on Wed Dec 15 21:20:34 2004 for vuVolume by  doxygen 1.3.9.1