Point3dWidget Class Reference

Class for drawing 3D points. More...

#include <point3dwidget.h>

List of all members.

Public Slots

void setXRotation (int angle)
 set x rotation factor
void setYRotation (int angle)
 set y rotation factor
void setZRotation (int angle)
 set z rotation factor
void setMousePoint (int mp)
 set moving point index

Signals

void xRotationChanged (int angle)
 angle for x axis rotation
void yRotationChanged (int angle)
 angle for y axis rotation
void zRotationChanged (int angle)
 angle for z axis rotation
void cubeWidthChanged (int cw)
 set cubewidth

Public Member Functions

 Point3dWidget (QWidget *parent=0)
 The constructor.
 ~Point3dWidget ()
 The deconstructor.
int xRotation () const
 return xRotation
int yRotation () const
 return yRotation
int zRotation () const
 return zRotation
void updateFile (FileReader *fd)
 update File Reader
void setDrawAble (bool status)
 enable drawing 3d points
void initCamera ()
 move camera to initial position

Public Attributes

QColor bColor
 background color
QColor pointColor
 point color
bool cameraEnable
 enable camera drawing
bool bounding
 enable bounding
bool movingClear
 clear model while moving or not
bool pointDrawn
 draw using point or not
int cubeWidth
 cube width
bool cubeDrawn
 draw using cube or not
bool initColor
 initial color for 3d point or not

Protected Member Functions

void initializeGL ()
 init GL
void paintGL ()
 paintGL
void resizeGL (int width, int height)
 resize GL
void mousePressEvent (QMouseEvent *event)
 mouse Press event
void mouseReleaseEvent (QMouseEvent *event)
 mouse Release event
void mouseMoveEvent (QMouseEvent *event)
 mouse Move event
void wheelEvent (QWheelEvent *we)
 mouse wheel Roll event
void mouseDoubleClickEvent (QMouseEvent *event)
 mouse double click event
void keyPressEvent (QKeyEvent *event)
 keyboard press event
void dragEnterEvent (QDragEnterEvent *event)
void dropEvent (QDropEvent *event)


Detailed Description

Class for drawing 3D points.

Definition at line 60 of file point3dwidget.h.


Constructor & Destructor Documentation

Point3dWidget::Point3dWidget QWidget *  parent = 0  ) 
 

The constructor.

Definition at line 45 of file point3dwidget.cpp.

References BB, bColor, BG, bounding, BR, cameraEnable, cubeDrawn, cubeWidth, INIT_X, INIT_Y, INIT_Z, initColor, movingClear, pointColor, and pointDrawn.

00046     : QGLWidget(parent)
00047 {
00048     // initiate flags and vars
00049     xRot = INIT_X;
00050     yRot = INIT_Y;
00051     zRot = INIT_Z;
00052     drawAble = false;
00053     mousePoint = -1;
00054     depth = -1.0f;
00055 
00056     // initiate average values
00057     avgX = 0.0f;
00058     avgY = 0.0f;
00059     avgZ = 0.0f;
00060 
00061     // initiate colors
00062     bColor = QColor(BR*255, BG*255, BB*255);
00063     pointColor = QColor(0, 0, 255);
00064     initColor = true;
00065 
00066     // initiate flags
00067     movingMouse = false;
00068     bounding = true;
00069     cameraEnable = true;
00070     movingClear = false;
00071     pointDrawn = true;
00072     cubeDrawn = false;
00073     cubeWidth = 3;
00074 
00075     // set main window parent
00076     mainWindow = qobject_cast<QMainWindow *>(parentWidget());
00077 
00078     // set strong focus for mouse and keyboard
00079     setFocusPolicy(Qt::StrongFocus);
00080 }

Point3dWidget::~Point3dWidget  ) 
 

The deconstructor.

Definition at line 85 of file point3dwidget.cpp.

00086 {
00087     makeCurrent();
00088 }


Member Function Documentation

void Point3dWidget::cubeWidthChanged int  cw  )  [signal]
 

set cubewidth

Referenced by keyPressEvent().

void Point3dWidget::initCamera  ) 
 

move camera to initial position

Parameters:
void 
Returns:
void

Definition at line 460 of file point3dwidget.cpp.

References INIT_X, INIT_Y, INIT_Z, setXRotation(), setYRotation(), and setZRotation().

Referenced by mouseDoubleClickEvent().

00460                               {
00461     setXRotation(INIT_X);
00462     setYRotation(INIT_Y);
00463     setZRotation(INIT_Z);
00464 }

void Point3dWidget::initializeGL  )  [protected]
 

init GL

Parameters:
void 
Returns:
void

Definition at line 204 of file point3dwidget.cpp.

References bColor.

00205 {
00206     glEnable(GL_DEPTH_TEST);
00207     glEnable(GL_NORMALIZE);
00208     glEnable(GL_BLEND);
00209     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00210     glClearColor(bColor.red()/255, bColor.green()/255, bColor.blue()/255, 0.0);
00211 }

void Point3dWidget::keyPressEvent QKeyEvent *  e  )  [protected]
 

keyboard press event

Parameters:
QKeyEvent *event
Returns:
void

Definition at line 522 of file point3dwidget.cpp.

References cubeWidth, and cubeWidthChanged().

00522                                              {
00523     switch( e->key() ){
00524         case Qt::Key_Right:
00525             cubeWidth ++;
00526             emit cubeWidthChanged(cubeWidth);
00527             break;
00528         case Qt::Key_Left:
00529             cubeWidth --;
00530             emit cubeWidthChanged(cubeWidth);
00531             break;
00532         case Qt::Key_Up:
00533             depth += 0.2f;
00534             mainWindow->statusBar()->showMessage(QString("Z coordinate %1").arg(depth));
00535             updateGL();
00536             break;
00537         case Qt::Key_Down:
00538             depth -= 0.2f;
00539             mainWindow->statusBar()->showMessage(QString("Z coordinate %1").arg(depth));
00540             updateGL();
00541             break;
00542         default:
00543             break;
00544     }
00545 }

void Point3dWidget::mouseDoubleClickEvent QMouseEvent *  event  )  [protected]
 

mouse double click event

Parameters:
QMouseEvent *event
Returns:
void

Definition at line 451 of file point3dwidget.cpp.

References initCamera().

00451                                                            {
00452     initCamera();
00453 }

void Point3dWidget::mouseMoveEvent QMouseEvent *  event  )  [protected]
 

mouse Move event

Parameters:
QMouseEvent *event
Returns:
void

Definition at line 489 of file point3dwidget.cpp.

References setXRotation(), setYRotation(), and setZRotation().

00490 {
00491     int dx = event->x() - lastPos.x();
00492     int dy = event->y() - lastPos.y();
00493 
00494     if (event->buttons() & Qt::LeftButton) {
00495         setXRotation((int) (xRot + 2.0 * dy));
00496         setYRotation((int) (yRot + 2.0 * dx));
00497     } else if (event->buttons() & Qt::RightButton) {
00498         setXRotation((int) (xRot + 2.0 * dy));
00499         setZRotation((int) (zRot + 2.0 * dx));
00500     }
00501     lastPos = event->pos();
00502 }

void Point3dWidget::mousePressEvent QMouseEvent *  event  )  [protected]
 

mouse Press event

Parameters:
QMouseEvent *event
Returns:
void

Definition at line 429 of file point3dwidget.cpp.

00430 {
00431     movingMouse = true;
00432     lastPos = event->pos();
00433     updateGL();
00434 }

void Point3dWidget::mouseReleaseEvent QMouseEvent *  event  )  [protected]
 

mouse Release event

Parameters:
QMouseEvent *event
Returns:
void

Definition at line 441 of file point3dwidget.cpp.

00441                                                        {
00442     movingMouse = false;
00443     updateGL();
00444 }

void Point3dWidget::paintGL  )  [protected]
 

paintGL

Parameters:
void 
Returns:
void

Definition at line 218 of file point3dwidget.cpp.

References bColor, bounding, cameraEnable, cubeDrawn, cubeWidth, FileReader::getEncoding(), FileReader::getNp(), initColor, movingClear, POINT_SIZE, FileReader::pointArray, pointColor, and pointDrawn.

00219 {
00220     makeCurrent();
00221     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00222     glClearColor((float)bColor.red()/255, (float)bColor.green()/255, (float)bColor.blue()/255, 0.0);
00223     glLoadIdentity();
00224     glPushMatrix();
00225 
00226     // move to init depth position
00227     glTranslated(0.0, 0.0, depth);
00228 
00229     // rotate model at specified factor
00230     // and around the model centre (by translate to avg points)
00231     glTranslated(0.0, avgY, avgZ);
00232     glRotated(xRot / 16.0, 1.0, 0.0, 0.0);
00233     glTranslated(0.0, -avgY, -avgZ);
00234 
00235     glTranslated(avgX, 0.0, avgZ);
00236     glRotated(yRot / 16.0, 0.0, 1.0, 0.0);
00237     glTranslated(-avgX, 0.0, -avgZ);
00238 
00239     glTranslated(avgX, avgY, 0.0);
00240     glRotated(zRot / 16.0, 0.0, 0.0, 1.0);
00241     glTranslated(-avgX, -avgY, 0.0);
00242 
00243     // drawing color
00244     glColor3f(0.0f,0.0f,1.0f);  // Color Blue
00245 
00246     // draw points after file is read
00247     if( drawAble ){
00248 
00249         // draw bounds first
00250         if(bounding){
00251 
00252             glBegin(GL_LINES);                    // Draw The Cube Using quads
00253                 glVertex3f( maxX, maxY, minZ);    // Top Right Of The Quad (Top)
00254                 glVertex3f( minX, maxY, minZ);    // Top Left Of The Quad (Top)
00255 
00256                 glVertex3f( minX, maxY, maxZ);    // Bottom Left Of The Quad (Top)
00257                 glVertex3f( maxX, maxY, maxZ);    // Bottom Right Of The Quad (Top)
00258 
00259                 glVertex3f( maxX, minY, maxZ);    // Top Right Of The Quad (Bottom)
00260                 glVertex3f( minX, minY, maxZ);    // Top Left Of The Quad (Bottom)
00261 
00262                 glVertex3f( minX, minY, minZ);    // Bottom Left Of The Quad (Bottom)
00263                 glVertex3f( maxX, minY, minZ);    // Bottom Right Of The Quad (Bottom)
00264 
00265                 glVertex3f( maxX, maxY, maxZ);    // Top Right Of The Quad (Front)
00266                 glVertex3f( maxX, minY, maxZ);    // Top Left Of The Quad (Front)
00267 
00268                 glVertex3f( minX, minY, maxZ);    // Bottom Left Of The Quad (Front)
00269                 glVertex3f( minX, maxY, maxZ);    // Bottom Right Of The Quad (Front)
00270 
00271                 glVertex3f( maxX, minY, minZ);    // Top Right Of The Quad (Back)
00272                 glVertex3f( maxX, minY, maxZ);    // Top Left Of The Quad (Back)
00273 
00274                 glVertex3f( minX, maxY, minZ);    // Bottom Left Of The Quad (Back)
00275                 glVertex3f( minX, maxY, maxZ);    // Bottom Right Of The Quad (Back)
00276 
00277                 glVertex3f( minX, minY, minZ);    // Top Right Of The Quad (Left)
00278                 glVertex3f( minX, maxY, minZ);    // Top Left Of The Quad (Left)
00279 
00280                 glVertex3f( minX, minY, minZ);    // Bottom Left Of The Quad (Left)
00281                 glVertex3f( minX, minY, maxZ);    // Bottom Right Of The Quad (Left)
00282 
00283                 glVertex3f( maxX, maxY, minZ);    // Top Right Of The Quad (Right)
00284                 glVertex3f( maxX, maxY, maxZ);    // Top Left Of The Quad (Right)
00285 
00286                 glVertex3f( maxX, maxY, minZ);    // Bottom Left Of The Quad (Right)
00287                 glVertex3f( maxX, minY, minZ);    // Bottom Right Of The Quad (Right)
00288 
00289             glEnd();                              // End Drawing The Cube
00290 
00291         }
00292 
00293         // if moving flag is not on when object is being moved
00294         if( ! ( movingClear && movingMouse ) ){
00295             // check whether point or cube is required for drawing
00296             if( pointDrawn )
00297                 glPointSize( POINT_SIZE );
00298             else if( cubeDrawn )
00299                 glPointSize( float( cubeWidth ));
00300 
00301             // now draw all points
00302             glBegin(GL_POINTS);
00303             if( fileReader->getEncoding() == 0 ){ // 3d points with associated image coordination
00304                 for( int i = 0; i < fileReader->getNp(); i ++){
00305                     double r = getColor( (int)fileReader->pointArray[i][3], (int)fileReader->pointArray[i][4], 0);
00306                     double g = getColor( (int)fileReader->pointArray[i][3], (int)fileReader->pointArray[i][4], 1);
00307                     double b = getColor( (int)fileReader->pointArray[i][3], (int)fileReader->pointArray[i][4], 2);
00308 
00309                     if( initColor )
00310                         glColor3d(r, g, b);
00311                     else
00312                         glColor3d(((float)pointColor.red()/255), ((float)pointColor.green()/255), ((float)pointColor.blue()/255));
00313 
00314                     glVertex3f(fileReader->pointArray[i][0], -fileReader->pointArray[i][1], -fileReader->pointArray[i][2]);
00315                 }
00316             }else{ // 3d points with their own color
00317                 for( int i = 0; i < fileReader->getNp(); i ++){
00318 
00319                     if( initColor )
00320                         glColor3f(fileReader->pointArray[i][3], fileReader->pointArray[i][4], fileReader->pointArray[i][5]);
00321                     else
00322                         glColor3d(((float)pointColor.red()/255), ((float)pointColor.green()/255), ((float)pointColor.blue()/255));
00323 
00324                     glVertex3f(fileReader->pointArray[i][0], -fileReader->pointArray[i][1], -fileReader->pointArray[i][2]);
00325                 }
00326             }
00327             glEnd();
00328         }
00329 
00330         glPointSize( POINT_SIZE );
00331 
00332         // draw Camera
00333         if( cameraEnable ){
00334             float TW = -0.2f;
00335             float UNC = -0.005f;
00336             glColor4f(1.0, 0.0, 0.0, 0.4);
00337             glBegin(GL_TRIANGLES);
00338               // top triangle
00339               glVertex3f( TW-UNC, TW+UNC, TW*3+UNC);
00340               glVertex3f( -TW+UNC, TW+UNC, TW*3+UNC);
00341               glVertex3f( 0.0, 0.0+UNC, 0.0-UNC);
00342 
00343               // right triangle
00344               glVertex3f( TW+UNC, TW-UNC, TW*3+UNC);
00345               glVertex3f( TW+UNC, -TW+UNC, TW*3+UNC);
00346               glVertex3f( 0.0+UNC, 0.0, 0.0+UNC);
00347 
00348               // bottom triangle
00349               glVertex3f( -TW-UNC, -TW-UNC, TW*3+UNC);
00350               glVertex3f( TW-UNC, -TW-UNC, TW*3+UNC);
00351               glVertex3f( 0.0, 0.0-UNC, 0.0+UNC);
00352 
00353               // left triangle
00354               glVertex3f( -TW-UNC, TW-UNC, TW*3+UNC);
00355               glVertex3f( -TW-UNC, -TW+UNC, TW*3+UNC);
00356               glVertex3f( 0.0-UNC, 0.0, 0.0+UNC);
00357             glEnd();
00358 
00359             // a line from camera center to the back of the object
00360             glColor3f(1.0,0.0,0.0);
00361             glBegin(GL_LINES);
00362                 glVertex3f(0.0, 0.0, 0.0);
00363                 glVertex3f(0.0, 0.0, maxZ);
00364             glEnd();
00365         }
00366 
00367         // mouse Point associated with reference pixel being pointed
00368         if( mousePoint >= 0 )
00369         {
00370             int i = mousePoint;
00371             float rw = 0.02;
00372             glColor3f(0.0, 1.0, 0.0);
00373             glBegin(GL_POLYGON);
00374                 glVertex3f(( fileReader->pointArray[i][0] + rw), -( fileReader->pointArray[i][1] + rw), -fileReader->pointArray[i][2]);
00375                 glVertex3f(( fileReader->pointArray[i][0] - rw), -( fileReader->pointArray[i][1] + rw), -fileReader->pointArray[i][2]);
00376                 glVertex3f(( fileReader->pointArray[i][0] - rw), -( fileReader->pointArray[i][1] - rw), -fileReader->pointArray[i][2]);
00377                 glVertex3f(( fileReader->pointArray[i][0] + rw), -( fileReader->pointArray[i][1] - rw), -fileReader->pointArray[i][2]);
00378             glEnd();
00379         }
00380     }
00381 
00382     glPopMatrix();
00383 
00384 }

void Point3dWidget::resizeGL int  width,
int  height
[protected]
 

resize GL

Parameters:
int width, int height
Returns:
void

Definition at line 412 of file point3dwidget.cpp.

References SIZE.

00413 {
00414     int side = qMin(width, height);
00415     glViewport((width - side) / 2, (height - side) / 2, side, side);
00416     glMatrixMode(GL_PROJECTION);
00417     glLoadIdentity();
00418     glFrustum(-SIZE, +SIZE, -SIZE, SIZE, 1.0, 80.0);
00419     glMatrixMode(GL_MODELVIEW);
00420     glLoadIdentity();
00421     glTranslated(0.0, 0.0, depth);
00422 }

void Point3dWidget::setDrawAble bool  status  ) 
 

enable drawing 3d points

Parameters:
bool status
Returns:
void

Definition at line 195 of file point3dwidget.cpp.

Referenced by updateFile().

00195                                           {
00196     drawAble = status;
00197 }

void Point3dWidget::setMousePoint int  mp  )  [slot]
 

set moving point index

Parameters:
int mp
Returns:
void

Definition at line 391 of file point3dwidget.cpp.

00391                                        {
00392     mousePoint = mp;
00393 }

void Point3dWidget::setXRotation int  angle  )  [slot]
 

set x rotation factor

Parameters:
int angle
Returns:
void

Definition at line 95 of file point3dwidget.cpp.

References xRotationChanged().

Referenced by initCamera(), and mouseMoveEvent().

00096 {
00097     normalizeAngle(&angle);
00098     if (angle != xRot) {
00099         xRot = angle;
00100         emit xRotationChanged(angle);
00101         updateGL();
00102     }
00103 }

void Point3dWidget::setYRotation int  angle  )  [slot]
 

set y rotation factor

Parameters:
int angle
Returns:
void

Definition at line 110 of file point3dwidget.cpp.

References yRotationChanged().

Referenced by initCamera(), and mouseMoveEvent().

00111 {
00112     normalizeAngle(&angle);
00113     if (angle != yRot) {
00114         yRot = angle;
00115         emit yRotationChanged(angle);
00116         updateGL();
00117     }
00118 }

void Point3dWidget::setZRotation int  angle  )  [slot]
 

set z rotation factor

Parameters:
int angle
Returns:
void

Definition at line 125 of file point3dwidget.cpp.

References zRotationChanged().

Referenced by initCamera(), and mouseMoveEvent().

00126 {
00127     normalizeAngle(&angle);
00128     if (angle != zRot) {
00129         zRot = angle;
00130         emit zRotationChanged(angle);
00131         updateGL();
00132     }
00133 }

void Point3dWidget::updateFile FileReader fd  ) 
 

update File Reader

Parameters:
FileReader *fd
Returns:
void

Definition at line 140 of file point3dwidget.cpp.

References setDrawAble().

Referenced by MainWidget::openFile().

00140                                              {
00141     fileReader = fd;
00142     setDrawAble(true);
00143     minX = findMin(0);
00144     maxX = findMax(0);
00145     minY = -findMin(1);
00146     maxY = -findMax(1);
00147     minZ = -findMin(2);
00148     maxZ = -findMax(2);
00149 
00150     avgX = (minX + maxX)/2;
00151     avgY = (minY + maxY)/2;
00152     avgZ = (minZ + maxZ)/2;
00153 
00154     updateGL();
00155 }

void Point3dWidget::wheelEvent QWheelEvent *  we  )  [protected]
 

mouse wheel Roll event

Parameters:
QMouseEvent *event
Returns:
void

Definition at line 471 of file point3dwidget.cpp.

00471                                               {
00472     // check for mouse move direction
00473     int deltaMoved = we->delta();
00474     if( deltaMoved < 0 )
00475         depth -= 0.2f; // decrease depth
00476     else
00477         depth += 0.2f; // increase depth
00478 
00479     mainWindow->statusBar()->showMessage(QString("Z coordinate %1").arg(depth));
00480 
00481     updateGL();
00482 }

int Point3dWidget::xRotation  )  const [inline]
 

return xRotation

Definition at line 68 of file point3dwidget.h.

void Point3dWidget::xRotationChanged int  angle  )  [signal]
 

angle for x axis rotation

Referenced by setXRotation().

int Point3dWidget::yRotation  )  const [inline]
 

return yRotation

Definition at line 69 of file point3dwidget.h.

void Point3dWidget::yRotationChanged int  angle  )  [signal]
 

angle for y axis rotation

Referenced by setYRotation().

int Point3dWidget::zRotation  )  const [inline]
 

return zRotation

Definition at line 70 of file point3dwidget.h.

void Point3dWidget::zRotationChanged int  angle  )  [signal]
 

angle for z axis rotation

Referenced by setZRotation().


Member Data Documentation

QColor Point3dWidget::bColor
 

background color

Definition at line 74 of file point3dwidget.h.

Referenced by initializeGL(), paintGL(), and Point3dWidget().

bool Point3dWidget::bounding
 

enable bounding

Definition at line 79 of file point3dwidget.h.

Referenced by paintGL(), and Point3dWidget().

bool Point3dWidget::cameraEnable
 

enable camera drawing

Definition at line 78 of file point3dwidget.h.

Referenced by paintGL(), and Point3dWidget().

bool Point3dWidget::cubeDrawn
 

draw using cube or not

Definition at line 83 of file point3dwidget.h.

Referenced by paintGL(), and Point3dWidget().

int Point3dWidget::cubeWidth
 

cube width

Definition at line 82 of file point3dwidget.h.

Referenced by keyPressEvent(), paintGL(), and Point3dWidget().

bool Point3dWidget::initColor
 

initial color for 3d point or not

Definition at line 84 of file point3dwidget.h.

Referenced by paintGL(), and Point3dWidget().

bool Point3dWidget::movingClear
 

clear model while moving or not

Definition at line 80 of file point3dwidget.h.

Referenced by paintGL(), and Point3dWidget().

QColor Point3dWidget::pointColor
 

point color

Definition at line 75 of file point3dwidget.h.

Referenced by paintGL(), and Point3dWidget().

bool Point3dWidget::pointDrawn
 

draw using point or not

Definition at line 81 of file point3dwidget.h.

Referenced by paintGL(), and Point3dWidget().


The documentation for this class was generated from the following files:
Generated on Mon Aug 14 10:44:21 2006 for S3DViewer by  doxygen 1.4.4