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

mitkWidgetModel3D.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 __mitkWidgetModel3D_h
00012 #define __mitkWidgetModel3D_h
00013 
00014 #include "mitkWidgetModel.h"
00015 
00024 class MITK_VISUALIZATION_API mitkWidgetModel3D : public mitkWidgetModel
00025 {
00026 public:
00027     MITK_TYPE(mitkWidgetModel3D, mitkWidgetModel)
00028 
00029     virtual void PrintSelf(ostream &os);
00030 
00035     virtual void SetScene(mitkScene *scene) { m_Scene = scene; }
00036     
00041     virtual void SetSourceModel(mitkDataModel *model);
00042     
00046     virtual void Update();
00047 
00048 protected:
00049     mitkWidgetModel3D();
00050     virtual ~mitkWidgetModel3D();
00051     
00052     void _widgetInit();
00053     void _widgetFree();
00054     void _defaultMaterial();
00055     void _undefaultMaterial();
00056 
00057     void _disableClippingPlanes();
00058 
00059     // Some components for widgets.
00060     void _drawLine(float startPos[3], float endPos[3], unsigned int name);
00061     void _drawCone(float pos[3], float direction[3], float radius, float length, unsigned int name);
00062     void _drawCylinder(float startPos[3], float endPos[3], float radius, bool close, unsigned int name);
00063     void _drawSphere(float pos[3], float radius, unsigned int name);
00064 //  void _drawCube(float pos[3], unsigned int name);
00065 
00066     mitkScene *m_Scene;
00067     
00068     GLUquadricObj *m_QObj;
00069     
00070     float m_LineWidth;
00071     float m_CubeSideLength;
00072     float m_BallRadius;
00073     float m_CylinderRadius;
00074     float m_ConeRadius; // cone uses m_CylinderSlice and m_CylinderStack to render
00075     float m_RotationMatrix[16]; // for locating of component
00076 
00077     float m_ScaleLength;
00078 
00079     int m_BallSlice;
00080     int m_CylinderSlice;
00081     int m_CylinderStack;
00082 
00083 private:
00084     mitkWidgetModel3D(const mitkWidgetModel3D&);
00085     void operator = (const mitkWidgetModel3D&);
00086 
00087 };
00088 
00089 inline void mitkWidgetModel3D::_defaultMaterial()
00090 {
00091     GLfloat ambient[]  = { 0.3f, 0.3f, 0.3f, 1.0f };
00092     GLfloat diffuse[]  = { 0.5f, 0.5f, 0.5f, 0.8f };
00093     GLfloat specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
00094     GLfloat shine[]    = { 50.0f };
00095     
00096     GLenum face = GL_FRONT;
00097     glEnable(GL_COLOR_MATERIAL);
00098     glMaterialfv(face, GL_AMBIENT,   ambient);
00099     glMaterialfv(face, GL_DIFFUSE,   diffuse);
00100     glMaterialfv(face, GL_SPECULAR,  specular);
00101     glMaterialfv(face, GL_SHININESS, shine);
00102 
00103     glColor4f(1.0f, 1.0f, 1.0f, 0.8f);  
00104 }
00105 
00106 inline void mitkWidgetModel3D::_undefaultMaterial()
00107 {
00108     glDisable(GL_COLOR_MATERIAL);
00109 }
00110 
00111 inline void mitkWidgetModel3D::_disableClippingPlanes()
00112 {
00113     if (m_SourceModel==NULL) return;
00114     mitkRenderer *renderer = m_SourceModel->GetBasicRenderer();
00115     if (renderer)
00116     {
00117         for (int i=0; i<renderer->GetClippingPlaneCount(); ++i)
00118             glDisable(GL_CLIP_PLANE0 + i);
00119     }
00120 }
00121 
00122 inline void mitkWidgetModel3D::_drawLine(float startPos[3], float endPos[3], unsigned int name)
00123 {
00124     glLoadName((GLuint)name);
00125     glLineWidth(m_LineWidth);
00126     glBegin(GL_LINES);
00127         glVertex3fv(startPos);
00128         glVertex3fv(endPos);
00129     glEnd();
00130 }
00131 
00132 inline void mitkWidgetModel3D::_drawSphere(float pos[3], float radius, unsigned int name)
00133 {
00134     glPushMatrix();
00135 
00136     glLoadName((GLuint)name);
00137     glTranslatef(pos[0], pos[1], pos[2]);
00138     gluSphere(m_QObj, radius, m_BallSlice, m_BallSlice);
00139 
00140     glPopMatrix();
00141 }
00142 
00143 /*
00144 inline void mitkWidgetModel3D::_drawCube(float pos[3], unsigned int name)
00145 {
00146     glPushMatrix();
00147 
00148     glLoadName((GLuint)name);
00149     glTranslatef(pos[0], pos[1], pos[2]);
00150     
00151     glPopMatrix();
00152 }
00153 */
00154 
00155 
00156 //#define DEFINED_mitkWidgetModel3D
00157 
00158 
00159 
00160 #endif
00161 

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