Eigene Dateien/Vis/src/QBackgroundCanvas.cpp

Go to the documentation of this file.
00001 #include "QBackgroundCanvas.h"
00002 
00003 
00004 
00005 
00006 QBackgroundCanvas::QBackgroundCanvas(QWidget* parent /*= 0*/) : QObject(parent), QGLWidget(parent)
00007 {
00008         m_CanvasColor.setX(0.0f);
00009         m_CanvasColor.setY(0.0f);
00010         m_CanvasColor.setZ(0.0f);
00011 
00012         glInit ();
00013 }
00014 
00015 
00016 QBackgroundCanvas::~QBackgroundCanvas()
00017 {
00018         
00019 }
00020 
00021 void QBackgroundCanvas::setObjectName(const QString &name)
00022 {
00023 }
00024 
00025 void QBackgroundCanvas::setVolBackColorPtr(VVector *v)
00026 {
00027         m_VolCanvasColor = v;
00028 
00029         /*m_VolCanvasColor->setX(0.0f);
00030         m_VolCanvasColor->setY(0.0f);
00031         m_VolCanvasColor->setZ(0.0f);*/
00032 }
00033 
00034 void QBackgroundCanvas::initializeGL()
00035 {
00036         this->makeCurrent();
00037     // Set up the rendering context, define display lists etc.:
00038     //...
00039         glClearColor( m_CanvasColor.getX(), m_CanvasColor.getY(), m_CanvasColor.getZ(), 1.0f );
00040         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00041     glEnable(GL_DEPTH_TEST);
00042     //...
00043 }
00044 
00045 void QBackgroundCanvas::resizeGL( int w, int h )
00046 {
00047         this->makeCurrent();
00048 
00049     glViewport(0, 0, w, h);
00050         gluOrtho2D(0, w, h, 0);
00051         
00052 }
00053 
00054 void QBackgroundCanvas::paintGL()
00055 {       
00056         /*this*/makeCurrent();
00057         glClearColor( m_CanvasColor.getX(), m_CanvasColor.getY(), m_CanvasColor.getZ(), 1.0f );
00058         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);     // Clear Screen And Depth Buffer
00059     glEnable(GL_DEPTH_TEST);
00060 
00061         //glEnable(GL_ALPHA_TEST);
00062         //glAlphaFunc(GL_GREATER, 0.5f);
00063     // draw the scene:
00064     glPushAttrib(GL_ALL_ATTRIB_BITS);
00065         
00066         glMatrixMode(GL_PROJECTION);
00067         glPushMatrix();
00068 
00069         glMatrixMode(GL_MODELVIEW);
00070         glPushMatrix();
00071         
00072         glLoadIdentity();                                                                       // Reset The Current Modelview Matrix
00073 
00074         
00075         glMatrixMode(GL_PROJECTION);
00076         glPopMatrix();
00077 
00078         glMatrixMode(GL_MODELVIEW);
00079         glPopMatrix();
00080 
00081         glPopAttrib();
00082 }
00083 
00084 void QBackgroundCanvas::redraw()
00085 {
00086         makeCurrent();
00087         repaint();
00088         swapBuffers();
00089 }
00090 void QBackgroundCanvas::paintEvent( QPaintEvent *e )
00091 {
00092         QGLWidget::paintEvent(e);
00093 };
00094 
00095 void QBackgroundCanvas::mousePressEvent ( QMouseEvent * e )
00096 {                       
00097         //const VMouseEvent me(getMouseEvent(e));
00098         QColor qcolor = QColorDialog::getColor();
00099         VVector color((float)qcolor.red()/255.0f, (float)qcolor.green()/255.0f, (float)qcolor.blue()/255.0f);
00100         m_CanvasColor.setX((float)qcolor.red()/255.0f);
00101         m_CanvasColor.setY((float)qcolor.green()/255.0f);
00102         m_CanvasColor.setZ((float)qcolor.blue()/255.0f);
00103 
00104         m_VolCanvasColor->setX(m_CanvasColor.getX());
00105         m_VolCanvasColor->setY(m_CanvasColor.getY());
00106         m_VolCanvasColor->setZ(m_CanvasColor.getZ());
00107 
00108         redraw();
00109         
00110 };
00111 
00112 void QBackgroundCanvas::mouseReleaseEvent ( QMouseEvent * e )
00113 {
00114         //const VMouseEvent me(getMouseEvent(e));
00115 
00116 };
00117         
00118 void QBackgroundCanvas::mouseMoveEvent ( QMouseEvent * e )
00119 {
00120         const VMouseEvent me(getMouseEvent(e));
00121 
00122         // v is the position of the mouse
00123         // cursor over canvas: v ranges in R, from -1 to 1 in both directions, left bottom corner is -1,-1
00124         // cursor n.o. canvas: if mouse was pressed before cursor left canvas, position is outside the range R 
00125         const VVector v  = me.getPosition();
00126 
00127         //std::cout << "VolRend: " << v << std::endl;
00128 
00129 };
00130 
00131 void QBackgroundCanvas::mouseDoubleClickEvent ( QMouseEvent * e )
00132 {
00133         
00134 };
00135 
00136 void QBackgroundCanvas::keyPressEvent ( QKeyEvent * e )
00137 {
00138         //const VKeyboardEvent ke(getKeyboardEvent(e));
00139 
00140 };
00141 
00142 void QBackgroundCanvas::keyReleaseEvent ( QKeyEvent * e )
00143 {
00144         //const VKeyboardEvent ke(getKeyboardEvent(e));
00145         
00146 };
00147 
00148 const VMouseEvent QBackgroundCanvas::getMouseEvent (QMouseEvent *e)
00149 {
00150         const VVector vecPosition( (2.0f * float(e->x()) - float(width()))  / float(width()),
00151                                       ( float(height()) - 2.0f * float(e->y())) / float(height()),
00152                                                            0.0f);
00153         const int iButton = 
00154                                 ((e->button() == Qt::LeftButton)        ? VMouseEvent::BUTTON_LEFT       : 
00155                                 ((e->button() == Qt::MidButton)         ? VMouseEvent::BUTTON_MIDDLE : 
00156                                 ((e->button() == Qt::RightButton)       ? VMouseEvent::BUTTON_RIGHT      : VMouseEvent::BUTTON_NONE)));
00157 
00158         const int iStateLeft    = (e->buttons () & Qt::LeftButton)      ? VMouseEvent::STATE_DOWN : VMouseEvent::STATE_UP;
00159         const int iStateMiddle  = (e->buttons () & Qt::MidButton)       ? VMouseEvent::STATE_DOWN : VMouseEvent::STATE_UP;
00160         const int iStateRight   = (e->buttons () & Qt::RightButton) ? VMouseEvent::STATE_DOWN : VMouseEvent::STATE_UP;
00161 
00162         const int iModifiers =   ((e->modifiers()   & Qt::ShiftModifier)   ? VKeyboardEvent::MODIFIER_SHIFT : 0) 
00163                                                    | ((e->modifiers()   & Qt::ControlModifier) ? VKeyboardEvent::MODIFIER_CTRL  : 0) 
00164                                                    | ((e->modifiers()   & Qt::AltModifier)     ? VKeyboardEvent::MODIFIER_ALT   : 0);
00165 
00166         return VMouseEvent(vecPosition,iButton,iStateLeft,iStateMiddle,iStateRight,iModifiers);
00167 
00168 };
00169 
00170 const VKeyboardEvent QBackgroundCanvas::getKeyboardEvent (QKeyEvent *e)
00171 {
00172         const int iKey = e->key();
00173 
00174         const int iModifiers =    ((e->modifiers() & Qt::ShiftModifier)         ? VKeyboardEvent::MODIFIER_SHIFT : 0) 
00175                                                         | ((e->modifiers() & Qt::ControlModifier)       ? VKeyboardEvent::MODIFIER_CTRL  : 0) 
00176                                                         | ((e->modifiers() & Qt::AltModifier)           ? VKeyboardEvent::MODIFIER_ALT   : 0);
00177 
00178         return VKeyboardEvent(iKey,iModifiers);
00179 
00180 };

Generated on Wed Dec 5 05:15:09 2007 for VolRendering by  doxygen 1.5.4