Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members

mitkWidgetModel2D.h

00001 /*=========================================================================
00002 
00003   Program:   3DMed
00004   Date:      $Date: 2014-02-25 18:30:00 +0800 $
00005   Version:   $Version: 4.6.0 $
00006   Copyright: MIPG, Institute of Automation, Chinese Academy of Sciences
00007 
00008 =========================================================================*/
00009 
00010 
00011 #ifndef __mitkWidgetModel2D_h
00012 #define __mitkWidgetModel2D_h
00013 
00014 #include "mitkWidgetModel.h"
00015 
00016 class mitkImageScene;
00017 class mitkVolume;
00018 
00027 class MITK_VISUALIZATION_API mitkWidgetModel2D : public mitkWidgetModel
00028 {
00029 public:
00030     MITK_TYPE(mitkWidgetModel2D, mitkWidgetModel)
00031 
00032     virtual void PrintSelf(ostream &os);
00033 
00038     virtual void SetScene(mitkScene *scene);
00039 
00044     virtual void SetSourceModel(mitkDataModel *model);
00045     
00051     void SetUnits(float ux, float uy) { m_Units[0] = ux; m_Units[1] = uy; }
00052 
00058     void SetUnits(float units[2]) { this->SetUnits(units[0], units[1]); }
00059 
00068     void SetColor(float r, float g, float b, float a = 1.0);
00069 
00078     void SetColor(int r, int g, int b, int a = 255);
00079 
00083     virtual void Update();
00084 
00091     virtual mitkVolume* GetCurrentImage();
00092 
00099     virtual mitkVolume* GetRegionMask() { return NULL; }
00100 
00101 protected:
00102     mitkWidgetModel2D();
00103     virtual ~mitkWidgetModel2D();
00104 
00105     void _widgetInit();
00106     void _widgetFree();
00107 
00108     void _getOriginalCoordinates(int sx, int sy, float &ox, float &oy);
00109     void _getOriginalCoordinates(float objX, float objY, float &ox, float &oy);
00110 
00111     // Some components for widgets.
00112     void _drawLine(float startPos[2], float endPos[2], unsigned int name);
00113     void _drawLine(float x1, float y1, float x2, float y2, unsigned int name);
00114     void _drawArrow(float pos[2], float direction[2], float length, float width, unsigned int name);
00115     void _drawDisk(float center[2], float radius, unsigned int name);
00116     void _drawDisk(float cx, float cy, float radius, unsigned int name);
00117     void _drawSolidSquare(float center[2], float sideLength, unsigned int name);
00118     void _drawSolidSquare(float cx, float cy, float sideLength, unsigned int name);
00119 
00120     mitkImageScene *m_Scene;
00121     
00122     GLUquadricObj *m_QObj;
00123     float m_LineWidth;
00124     float m_ScaleLength;
00125     float m_RotationMatrix[16];
00126     float m_UsualColor[4];
00127     float m_Units[2];
00128     int   m_DiskSlice;
00129     
00130 
00131 private:
00132     mitkWidgetModel2D(const mitkWidgetModel2D&);
00133     void operator = (const mitkWidgetModel2D&);
00134 
00135 };
00136 
00137 inline void mitkWidgetModel2D::_drawLine(float startPos[2], float endPos[2], unsigned int name)
00138 {
00139     glLoadName((GLuint)name);
00140     glLineWidth(m_LineWidth);
00141     glBegin(GL_LINES);
00142         glVertex2fv(startPos);
00143         glVertex2fv(endPos);
00144     glEnd();
00145 }
00146 
00147 inline void mitkWidgetModel2D::_drawLine(float x1, float y1, float x2, float y2, unsigned int name)
00148 {
00149     glLoadName((GLuint)name);
00150     glLineWidth(m_LineWidth);
00151     glBegin(GL_LINES);
00152         glVertex2f(x1, y1);
00153         glVertex2f(x2, y2);
00154     glEnd();
00155 }
00156 
00157 inline void mitkWidgetModel2D::_drawArrow(float pos[2], float direction[2], 
00158                                           float length, float width,
00159                                           unsigned int name)
00160 {
00161     glPushMatrix();
00162     {
00163         glLoadName((GLuint)name);
00164 
00165         float len_inv = 1.0f / sqrtf(direction[0]*direction[0] + direction[1]*direction[1]);
00166         //float cosa = direction[1] * len_inv;
00167         //float sina = - direction[0] * len_inv;
00168 
00169         m_RotationMatrix[0]  = direction[1] * len_inv; //cosa
00170         m_RotationMatrix[1]  = - direction[0] * len_inv; //sina
00171 //      m_RotationMatrix[2]  = 0.0f;
00172 //      m_RotationMatrix[3]  = 0.0f;
00173 
00174         m_RotationMatrix[4]  = - m_RotationMatrix[1];
00175         m_RotationMatrix[5]  = m_RotationMatrix[0];
00176 //      m_RotationMatrix[6]  = 0.0f;
00177 //      m_RotationMatrix[7]  = 0.0f;
00178 
00179 //      m_RotationMatrix[8]  = 0.0f;
00180 //      m_RotationMatrix[9]  = 0.0f;
00181 //      m_RotationMatrix[10] = 1.0f;
00182 //      m_RotationMatrix[11] = 0.0f;
00183 
00184         m_RotationMatrix[12] = pos[0];
00185         m_RotationMatrix[13] = pos[1];
00186 //      m_RotationMatrix[14] = 0.0f;
00187 //      m_RotationMatrix[15] = 1.0f;
00188 
00189         glMultMatrixf(m_RotationMatrix);
00190 
00191 //      glBegin(GL_TRIANGLE_STRIP);
00192 //      {
00193 //          glVertex2f(- 0.5f * width, - 2.0f * length);
00194 //          glVertex2f(0.0f, 0.0f);
00195 //          glVertex2f(0.0f, - length);
00196 //          glVertex2f(0.5f * width, - 2.0f * length);
00197 //      }
00198 //      glEnd();
00199         
00200         glBegin(GL_TRIANGLES);
00201         {
00202             glVertex2f(0.0f, 0.0f);
00203             glVertex2f(- 0.5f * width, - length);
00204             glVertex2f(0.5f * width, -length);
00205         }
00206         glEnd();
00207     }
00208     glPopMatrix();
00209 }
00210 
00211 inline void mitkWidgetModel2D::_drawDisk(float cx, float cy, float radius, unsigned int name)
00212 {
00213 //  glMatrixMode(GL_MODELVIEW);
00214     glPushMatrix();
00215     {
00216         glLoadName((GLuint)name);
00217         glTranslatef(cx, cy, 0.0f);
00218         gluDisk(m_QObj, 0.0, radius, m_DiskSlice, 1);
00219     }
00220     glPopMatrix();
00221 }
00222 
00223 inline void mitkWidgetModel2D::_drawDisk(float center[2], float radius, unsigned int name)
00224 {
00225     this->_drawDisk(center[0], center[1], radius, name);
00226 }
00227 
00228 inline void mitkWidgetModel2D::_drawSolidSquare(float cx, float cy, float sideLength, unsigned int name)
00229 {
00230     glLoadName((GLuint)name);
00231 
00232     float halfLen = sideLength * 0.5f;
00233     glRectf(cx-halfLen, cy-halfLen, cx+halfLen, cy+halfLen);
00234 }
00235 
00236 inline void mitkWidgetModel2D::_drawSolidSquare(float center[2], float sideLength, unsigned int name)
00237 {
00238     this->_drawSolidSquare(center[0], center[1], sideLength, name);
00239 }
00240 
00241 
00242 //#define DEFINED_mitkWidgetModel2D
00243 
00244 
00245 
00246 #endif
00247 

Generated on Tue Feb 25 15:00:38 2014 for MITK (Medical Imaging ToolKit) by  doxygen 1.4.3