00001 //-------------------------------------------------------------------- 00002 // 00003 // File: Txq3dCanvas.h 00004 // 00005 // Purpose: 00006 // The Txq3dCanvas is a Qt OpenGL widget which creates 00007 // an OpenGL plot context to plot 3d data. 00008 // OPENGL must be defined at compilation for this code to be implemented. 00009 // 00010 // Version: $Id: Txq3dCanvas.h,v 1.12 2001/10/11 17:02:53 kgl Exp $ 00011 // 00012 // Copyright (c) 2000 by Tech-X Corporation. All rights reserved. 00013 // 00014 // Author: Kelly G. Luetkemeyer 00015 // 00016 //-------------------------------------------------------------------- 00017 00018 #ifndef TXQ3_DCANVAS_H 00019 #define TXQ3_DCANVAS_H 00020 00021 #ifdef OPENGL 00022 00023 // Qt includes 00024 #include <qgl.h> 00025 #include <qpoint.h> 00026 #include <qpixmap.h> 00027 00028 // STL includes 00029 #include <algorithm> 00030 #include <cassert> 00031 #include <vector> 00032 #include <cmath> 00033 #if defined(_MSC_VER) 00034 #include <cfloat> 00035 #else 00036 #include <float.h> 00037 #endif 00038 00039 00040 // Txq includes 00041 #include "Txq3dDrawable.h" 00042 #include "Txq3dDefines.h" 00043 #include "Txq3dPlotAttribs.h" 00044 #include "Txq3dAxis.h" 00045 00061 class Txq3dCanvas : public QGLWidget 00062 { 00063 Q_OBJECT 00064 00065 public: 00066 00072 Txq3dCanvas( QWidget* parent=0, const char* name=0 ); 00073 00077 virtual ~Txq3dCanvas(); 00078 00088 virtual void setRange(double xMin, double xMax, 00089 double yMin, double yMax, 00090 double zMin, double zMax); 00091 00096 double getXmin() { return dataXmin; } 00097 00102 double getXmax() { return dataXmax; } 00103 00108 double getYmin() { return dataYmin; } 00109 00114 double getYmax() { return dataYmax; } 00115 00120 double getZmin() { return dataZmin; } 00121 00126 double getZmax() { return dataZmax; } 00127 00131 void setOrthoProjection(); 00132 00136 void setPerspectProjection(); 00137 00141 void setOrthoScaleValues(); 00142 00146 void setPerspectScaleValues(); 00147 00152 bool isPerspectProjection(); 00153 00158 bool isDataScale(); 00159 00164 void setDataScale(); 00165 00169 void setDataScaleValues(); 00170 00174 void setAxesScaleValues(); 00175 00181 void setAxesScale(); 00182 00188 void enableWireFrame(bool on); 00189 00194 bool isWireFrameEnabled(); 00195 00200 void setWireFrameColor(QColor c); 00201 00206 void setPixmapColor(QColor c); 00207 00212 void add(Txq3dDrawable *drawAble); 00213 00218 void remove(Txq3dDrawable *drawAble); 00219 00224 void add(Txq3dAxis *axis); 00225 00232 void setDrawableScale(double xs, double ys, double zs); 00233 00237 int getXRotation(); 00238 00242 int getYRotation(); 00243 00247 int getZRotation(); 00248 00254 QPixmap getPixmap(); 00255 00262 QPixmap getPixmap(int w, int h); 00263 00268 void invertBW(bool white); 00269 00274 bool isBlack(); 00275 00280 void setSize(QSize s); 00281 00286 void setPlotAttribs(Txq3dPlotAttribs *p); 00287 00292 void updatePlotAttribs(Txq3dPlotAttribs *p); 00293 00294 00295 signals: 00304 void mouseClick(double , double ); 00305 00310 void mouseClick(); 00311 00319 void mouseClick(QMouseEvent *); 00320 00328 void mouseClick(QPoint); 00329 00334 void mouseRightClick(); 00335 00336 00343 void mouseMiddleClick(int x, int y); 00344 00350 void mouseMiddleClick(QPoint); 00351 00352 00353 public slots: 00354 00359 void setXRotation( int degrees ); 00360 00365 void setYRotation( int degrees ); 00366 00371 void setZRotation( int degrees ); 00372 00377 void setTranslation ( int units); 00378 00382 void updateProjection(); 00383 00388 void dump(QTextStream *ts); 00389 00390 protected: 00391 00396 QSize sizeHint() const; 00397 00398 00403 virtual void initializeGL(); 00404 00409 virtual void paintGL(); 00410 00417 virtual void resizeGL( int w, int h ); 00418 00422 virtual GLuint makeObject(); 00423 00427 virtual void drawWireFrame(); 00428 00436 void mousePressEvent(QMouseEvent *); 00437 00438 private: 00439 00443 GLuint object; 00444 00448 GLdouble xRot; 00452 GLdouble yRot; 00456 GLdouble zRot; 00457 00461 GLdouble scale; 00462 00466 GLdouble trans; 00467 00472 GLdouble xClip; 00477 GLdouble yClip; 00482 GLdouble zClip; 00483 00487 GLdouble xScale; 00491 GLdouble yScale; 00495 GLdouble zScale; 00496 00500 double xmin; 00504 double xmax; 00508 double ymin; 00512 double ymax; 00516 double zmin; 00520 double zmax; 00521 00525 double dxmin; 00529 double dxmax; 00533 double dymin; 00537 double dymax; 00541 double dzmin; 00545 double dzmax; 00546 00550 double dataXmin; 00551 00555 double dataXmax; 00556 00560 double dataYmin; 00561 00565 double dataYmax; 00566 00570 double dataZmin; 00571 00575 double dataZmax; 00576 00580 double b1; 00584 double b2; 00588 double b3; 00589 00593 bool frameIsEnabled; 00594 00598 QColor pixmapColor; 00599 00604 float red; 00605 00610 float green; 00611 00616 float blue; 00617 00621 QColor wireFrameColor; 00622 00626 std::vector<Txq3dDrawable*> drawAbles; 00627 00632 bool dataScale; 00633 00638 bool axesScale; 00639 00643 int projection; 00644 00648 int canvasWidth; 00649 00653 int canvasHeight; 00654 00658 bool black; 00659 00663 int myWidth; 00664 00668 int myHeight; 00669 00670 private: 00676 Txq3dAxis *xAxis; 00677 00683 Txq3dAxis *yAxis; 00684 00690 Txq3dAxis *zAxis; 00691 00695 bool isXaxis; 00696 00700 bool isYaxis; 00701 00705 bool isZaxis; 00706 00710 std::vector<Txq3dAxis*> axes; 00711 00712 }; 00713 00714 00715 #endif // OPENGL 00716 #endif // TXQ3D_CANVAS_H
Copyright Tech-X Corporation, all rights reserved.