Main Page | Namespace List | Class Hierarchy | Compound List | File List | Compound Members | File Members | Related Pages

qglviewer.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 
00003  This file is part of the QGLViewer library
00004  Copyright (C) 2002-2004  Gilles Debunne (Gilles.Debunne@imag.fr)
00005  Version 1.3.5 Release 8. Packaged on Monday December 22, 2003.
00006 
00007  http://www-imagis.imag.fr/Membres/Gilles.Debunne/CODE/QGLViewer
00008 
00009  libQGLViewer is free software; you can redistribute it and/or modify
00010  it under the terms of the GNU General Public License as published by
00011  the Free Software Foundation; either version 2 of the License, or
00012  (at your option) any later version.
00013 
00014  libQGLViewer is distributed in the hope that it will be useful,
00015  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  GNU General Public License for more details.
00018 
00019  You should have received a copy of the GNU General Public License
00020  along with libQGLViewer; if not, write to the Free Software
00021  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 
00023 *****************************************************************************/
00024 
00025 #ifndef QGLVIEWER_QGLVIEWER_H
00026 #define QGLVIEWER_QGLVIEWER_H
00027 
00028 #include <qgl.h>
00029 #include "camera.h"
00030 
00086 class QGLVIEWER_EXPORT QGLViewer : public QGLWidget
00087 {
00088   Q_OBJECT        // must include this if you use Qt signals/slots
00089   
00090 // #ifndef DOXYGEN
00091   // Q_PROPERTY(QString snapshotFilename READ snapshotFilename WRITE setSnapshotFilename)
00092 // #endif
00093     
00094 public:
00095   QGLViewer(QWidget* parent=NULL, const char* name=0,
00096         const QGLWidget* shareWidget=0, WFlags flags=0);
00097   
00098   QGLViewer(const QGLFormat& format, QWidget* parent=0,const char* name=0,
00099         const QGLWidget* shareWidget=0, WFlags flags=0);
00100 
00101   virtual ~QGLViewer();
00102 
00105 public:
00122   qglviewer::Vec backgroundColor() const { return backgroundColor_; };
00124   void getBackgroundColor(float& r, float& g, float& b) const;
00134   qglviewer::Vec foregroundColor() const { return foregroundColor_; };
00136   void getForegroundColor(float& r, float& g, float& b) const;
00137 public slots:
00141   void setBackgroundColor(const qglviewer::Vec& color) { backgroundColor_ = color; glClearColor(color.x, color.y, color.z, 1.0); };
00143   void setBackgroundColor(float r, float g, float b) { setBackgroundColor(qglviewer::Vec(r, g ,b)); };
00148   void setBackgroundColor(const QColor &c) { setBackgroundColor(c.red(), c.green(), c.blue()); };
00149   void setForegroundColor(const qglviewer::Vec& color) { foregroundColor_ = color; };
00151   void setForegroundColor(float r, float g, float b) { setForegroundColor(qglviewer::Vec(r, g ,b)); };;
00153   void setForegroundColor(const QColor &c) { setForegroundColor(c.red(), c.green(), c.blue()); };
00155   
00158 public:
00160   bool axisIsDrawn() const { return drawAxis_; };
00161 public slots:
00163   void setDrawAxis(bool f=true) { drawAxis_ = f; emit axisDrawn(f); if (initializationStage_==3) updateGL(); };
00166   void toggleDrawAxis() { setDrawAxis(!drawAxis_); };
00167 
00168 public:
00170   bool gridIsDrawn() const { return drawGrid_; };
00171 public slots:
00173   void setDrawGrid(bool f=true) { drawGrid_ = f; emit gridDrawn(f); if (initializationStage_==3) updateGL(); };
00176   void toggleDrawGrid() { setDrawGrid(!drawGrid_); };
00177 
00178 public:
00181   bool fpsIsDisplayed() const { return displayFPS_; };
00182 public slots:
00185   void setDisplayFPS(bool f=true) { displayFPS_ = f; emit fpsDisplayed(f); if (initializationStage_==3) updateGL(); };
00188   void toggleDisplayFPS() { setDisplayFPS(!displayFPS_); };
00189 
00190 public:
00193   bool zBufferIsDisplayed() const { return displayZBuffer_; };
00194 public slots:
00196   void setDisplayZBuffer(bool f=true) { displayZBuffer_ = f; emit zBufferDisplayed(f); if (initializationStage_==3) updateGL(); };
00199   void toggleDisplayZBuffer() { setDisplayZBuffer(!displayZBuffer_); };
00200   
00201 public:
00204   bool textIsEnabled() const { return enableText_; };
00205 public slots:
00208   void setEnableText(bool f=true) { enableText_ = f; emit textEnabled(f); if (initializationStage_==3) updateGL(); };
00211   void toggleEnableText() { setEnableText(!enableText_); };
00212 
00213 public:
00220   bool cameraPathIsEdited() const { return camera()->cameraPathIsEdited(); };
00221 public slots:
00224   void editCameraPath(bool edit=true) { camera()->editCameraPath(edit); emit cameraPathEdited(edit); if (initializationStage_==3) updateGL(); };
00227   void toggleCameraPathEditor() { editCameraPath(!camera()->cameraPathIsEdited()); };
00229 
00230 
00233 public:
00236   float aspectRatio() const { return static_cast<float>(width())/static_cast<float>(height()); };
00237 public slots:
00238 
00239 public:
00245   float sceneRadius() const { return camera()->sceneRadius(); };
00246 public slots:
00264   void setSceneRadius(float r) { camera()->setSceneRadius(r); };
00265 
00266 public:
00269   qglviewer::Vec sceneCenter() const { return camera()->sceneCenter(); };
00270   void getSceneCenter(float& x, float& y, float& z) const;
00271 public slots:
00290   void setSceneCenter(const qglviewer::Vec& sc) { camera()->setSceneCenter(sc); };
00292   void setSceneCenter(float x, float y, float z) { setSceneCenter(qglviewer::Vec(x,y,z)); };
00299   void setSceneBoundingBox(const qglviewer::Vec& m, const qglviewer::Vec& M) { camera()->setSceneBoundingBox(m,M); };
00300 
00308   void showEntireScene() { camera()->showEntireScene(); if (initializationStage_==3) updateGL(); };
00309 public:
00311   void setSceneBoundingBox(const float m[3], const float M[3]) { setSceneBoundingBox(qglviewer::Vec(m),qglviewer::Vec(M)); };
00322   float currentFPS() { return f_p_s_; };
00324 
00327 public:
00330   qglviewer::Camera* camera() const { return camera_; };
00331 
00339   qglviewer::ManipulatedFrame* manipulatedFrame() const { return manipulatedFrame_; };
00340   
00341 public slots:
00342   void setCamera(qglviewer::Camera* const c);
00343   void setManipulatedFrame(qglviewer::ManipulatedFrame* fr);
00345 
00346   
00349 public:
00351   bool isFullScreen() const { return fullScreen_; };
00353   bool displaysInStereo() const { return stereo_; }  
00354 public slots:
00355   void setFullScreen(bool fs=true);
00356   void toggleFullScreen();
00357   void setStereoDisplay(bool s=true);
00361   void toggleStereoDisplay()        { setStereoDisplay(!stereo_); };
00362   virtual void toggleCameraMode();
00364 
00365   
00368 public:
00369   void drawAxis(float scale=1.0f);
00375   void drawGrid() { glCallList(GridDL_); };
00376 
00377   virtual void startScreenCoordinatesSystem(bool upward = false) const;
00378   virtual void stopScreenCoordinatesSystem() const;
00379 
00380 protected:
00381   virtual void drawLight(GLenum light, float scale = 1.0f) const;
00382   virtual void displayFPS();
00383   virtual void displayZBuffer() const;
00384   
00385   void drawText(int x, int y, const QString& text, const QFont& fnt=QFont());
00386   void draw3DText(const qglviewer::Vec& pos, const qglviewer::Vec& normal, const QString& string, GLfloat height=0.1f);
00387 
00388 private:
00390   virtual void drawVectorial() { makeCurrent(); paintGL(); };
00391   
00392 #ifndef DOXYGEN // Hidden
00393   friend void drawVectorial(void* param);
00394 #endif
00395 
00396 
00397   
00400 public:
00417   qglviewer::MouseGrabber* mouseGrabber() const { return mouseGrabber_; };
00418 
00419 public slots:
00420   void setMouseGrabber(qglviewer::MouseGrabber* mg);
00422 
00423 
00426 public:  
00428   const QString& snapshotFilename() const { return snapshotFilename_; };
00431   const QString& snapshotFormat() const { return snapshotFormat_; };
00435   int snapshotCounter() const { return snapshotCounter_; };
00436   
00437 public slots:
00438   // Qt 2.3 does not support double default value parameters
00439   // Uncomment the following line (and comment the next one) with Qt 2.3
00440   // void saveSnapshot(bool automatic, bool overwrite);
00441   void saveSnapshot(bool automatic=false, bool overwrite=false);
00442   
00443   void setSnapshotFilename(const QString& n);
00460   void setSnapshotFormat(const QString& f) { snapshotFormat_ = f; };
00462   void setSnapshotCounter(const int c) { snapshotCounter_ = c; };
00464 
00467 public:
00471   bool animationIsStarted() const { return animationStarted_; };
00473   int animationPeriod() const { return animationPeriod_; };
00474 
00475 public slots:
00479   void setAnimationPeriod(int msecs) { animationPeriod_ = msecs; };
00480   virtual void startAnimation(int msecs = -1);
00481   virtual void stopAnimation();
00483   void toggleAnimationMode() { if (animationIsStarted()) stopAnimation(); else startAnimation(); };
00484 protected:
00488   virtual void animate() { emit animateNeeded(); };
00490 
00491 public:
00492 signals:
00498   void viewerInitialized();
00499 
00519   void drawNeeded();
00520 
00526   void animateNeeded();
00527 
00533   void helpRequired();
00534 
00536   void axisDrawn(bool on);
00538   void gridDrawn(bool on);
00540   void fpsDisplayed(bool on);
00542   void zBufferDisplayed(bool on);
00544   void textEnabled(bool on);
00546   void cameraPathEdited(bool on);
00548   void stereoChanged(bool on);
00552   void pointSelected(const QMouseEvent* e);
00553                                                       
00556 public:
00574   virtual QString helpString() const { return QString::null; };
00575 public slots:
00576   virtual void help();
00577   
00578 public:
00579   virtual QString mouseBindingsString() const;
00580   virtual QString shortcutBindingsString() const;
00582 
00583 protected:
00584   virtual void resizeGL( int w, int h );
00585 
00586   virtual void initializeGL();
00587 
00610   virtual void init() { emit viewerInitialized(); };
00611 
00612   virtual void paintGL();
00613 
00614   virtual void preDraw();  
00615   virtual void preDrawStereo(bool leftBuffer=true);
00616   
00631   virtual void draw() {};
00632   virtual void fastDraw();
00633   virtual void postDraw();
00634   virtual void select(const QMouseEvent* e);
00635   
00637   QWidget* rootWidget() const;
00638     
00641 protected:
00642   virtual void mousePressEvent(QMouseEvent *);
00643   virtual void mouseDoubleClickEvent(QMouseEvent *);
00644   virtual void mouseReleaseEvent(QMouseEvent *);
00645   virtual void mouseMoveEvent(QMouseEvent *);
00646   virtual void wheelEvent(QWheelEvent *);
00647   virtual void timerEvent(QTimerEvent *);
00648   virtual void closeEvent(QCloseEvent *);
00649 
00650   // keyboard handler
00651   virtual void keyPressEvent(QKeyEvent *);
00653 
00654   
00657 protected:
00662   enum ShortcutAction { DRAW_AXIS, DRAW_GRID, DISPLAY_FPS, DISPLAY_Z_BUFFER, ENABLE_TEXT, EXIT, SAVE_SCREENSHOT,
00663             CAMERA_MODE, FULL_SCREEN, STEREO, ANIMATION, HELP, EDIT_CAMERA_PATHS };
00664   //#CONNECTION# shortcutBindingsString
00665 
00666   virtual void setShortcutKey(ShortcutAction action, int key, int stateKey = -1);
00667   Qt::Key shortcutKey(ShortcutAction action) const;
00668 
00669   virtual void setShortcutStateKey(ShortcutAction action, int buttonState);
00670   Qt::ButtonState shortcutStateKey(ShortcutAction action) const;
00671 
00672   // Key Frames shortcut keys
00673   virtual void setKeyFrameKey(int nb, int key);
00674   Qt::Key keyFrameKey(int nb) const;
00675 
00676   virtual void setAddKeyFrameStateKey(int buttonState);
00677   Qt::ButtonState addKeyFrameStateKey() const;
00678 
00679   virtual void setPlayKeyFramePathStateKey(int buttonState);
00680   Qt::ButtonState playKeyFramePathStateKey() const;
00682 
00683   
00686 public:
00690   enum MouseHandler { CAMERA, FRAME };
00691 
00692   enum ClickAction { NO_ACTION, ZOOM_ON_PIXEL, ZOOM_TO_FIT, SELECT, RAP_FROM_PIXEL, RAP_IS_CENTER,
00693              CENTER_FRAME, CENTER_SCENE, SHOW_ENTIRE_SCENE, ALIGN_FRAME, ALIGN_CAMERA };
00694 
00695 protected:
00696   virtual void setMouseStateKey(MouseHandler mh, int buttonState);
00697   Qt::ButtonState mouseStateKey(int) const;
00698 
00699   void setMouseBinding(int buttonState, MouseHandler handler, qglviewer::ManipulatedFrame::MouseMotion action, bool withConstraint=true);
00700   qglviewer::ManipulatedFrame::MouseMotion mouseAction(int buttonState);
00701   int mouseHandler(int buttonState);
00702   Qt::ButtonState mouseButtonState(MouseHandler mh, qglviewer::ManipulatedFrame::MouseMotion ma, bool withConstraint=true);
00703 
00704   void setMouseBinding(int buttonState, ClickAction action, bool doubleClick=false, int buttonBefore=Qt::NoButton);
00705   ClickAction clickAction(int buttonState, bool doubleClick, int buttonBefore);
00706   void clickButtonState(ClickAction ca, Qt::ButtonState& buttonState, bool& doubleClick, Qt::ButtonState& buttonBefore);
00707 
00708   void setWheelBinding(int stateKey, MouseHandler handler, qglviewer::ManipulatedFrame::MouseMotion action, bool withConstraint=true);
00709   qglviewer::ManipulatedFrame::MouseMotion wheelAction(int buttonState);
00710   int wheelHandler(int buttonState);
00711   int wheelButtonState(MouseHandler mh, qglviewer::ManipulatedFrame::MouseMotion ma, bool withConstraint=true);
00712 
00713 
00714   /* XXX Modified by Aidan Lane (Feb 13, 2004), for compatibility reasons. XXX */
00715   GLuint AxisDL_, GridDL_, CameraDL_;
00716   void createDisplayLists();
00718 
00719   
00722 public:
00723   virtual void saveToFile(const QString& fileName="");
00724   virtual void restoreFromFile(const QString& fileName="");
00725   
00726   virtual QDomElement domElement(const QString& name, QDomDocument& doc) const;
00727   virtual void initFromDOMElement(const QDomElement& de);
00729 
00730 
00735   public:
00745   static const QPtrList<QGLViewer>& QGLViewerPool() { return QGLViewerPool_; };
00751   static int  QGLViewerIndex(const QGLViewer* const v) { return QGLViewerPool_.find(v); };
00752   static void connectSignalToAllViewers(const QObject* sender, const char* signal, const char* member=SLOT(updateGL()));
00753   static void disconnectSignalToAllViewers(const QObject* sender, const char* signal, const char* member=SLOT(updateGL()));
00754   static void updateGLForAllViewers();
00755   static void saveToFileForAllViewers();
00757 
00758 
00761   public:
00762   virtual void setVisualHintsMask(int mask, int delay = 2000);
00763   virtual void drawVisualHints();
00764     
00765   public slots:
00766   virtual void resetVisualHints();
00768     
00769 private slots:
00770   void delayedFullScreen() { move(prevPos_); setFullScreen(); };
00771   
00772 private:
00773   // Copy constructor and opertor= are declared private and undefined
00774   // Prevents everyone from trying to use them
00775   QGLViewer(const QGLViewer& v);
00776   QGLViewer& operator=(const QGLViewer& v);
00777 
00778   // Set parameters to their default values. Called by the constructors.
00779   void defaultConstructor();
00780 
00781   // C a m e r a
00782   qglviewer::Camera* camera_;
00783   
00784   // C o l o r s
00785   qglviewer::Vec backgroundColor_, foregroundColor_;
00786   
00787   // D i s p l a y    f l a g s
00788   bool drawAxis_;   // world axis 
00789   bool drawGrid_;   // world XY grid
00790   bool displayFPS_; // Frame Per Seconds
00791   bool displayZBuffer_; // Grey level z-buffer
00792   bool enableText_; // drawText() actually draws text or not
00793   bool stereo_;     // stereo display
00794   bool fullScreen_; // full screen mode
00795   QPoint prevPos_;  // Previous window position, used for full screen mode
00796 
00797   // A n i m a t i o n    p a r a m e t e r s
00798   bool animationStarted_; // animation mode started
00799   int animationPeriod_;   // period in msecs
00800   int animationTimerId_;
00801   
00802   // F P S    d i s p l a y 
00803   QTime fpsTime_;
00804   unsigned int fpsCounter_;
00805   float f_p_s_;
00806   
00807   // M a n i p u l a t e d    f r a m e 
00808   qglviewer::ManipulatedFrame* manipulatedFrame_;
00809   bool manipulatedFrameIsACamera_;
00810   qglviewer::MouseGrabber* mouseGrabber_;
00811   bool mouseGrabberIsAManipulatedFrame_;
00812   bool mouseGrabberIsAManipulatedCameraFrame_;
00813   
00814   // D i s p l a y    l i s t s
00815   /* XXX Modified by Aidan Lane (Feb 13, 2004), for compatibility reasons. XXX */
00816   //GLuint AxisDL_, GridDL_, CameraDL_;
00817   //void createDisplayLists();
00818 
00819   // V i s u a l   h i n t s
00820   int visualHint_;
00821 
00822   // S h o r t c u t   k e y s 
00823   void setDefaultShortcutKeys();
00824   enum { nbShortcuts_ = 13 };
00825   Qt::Key         shortcutKey_[nbShortcuts_];
00826   Qt::ButtonState shortcutStateKey_[nbShortcuts_];
00827 
00828   // K e y   F r a m e s   s h o r t c u t s
00829   Qt::Key *keyFrameKey_;
00830   Qt::ButtonState addKFStateKey_, playKFStateKey_;
00831 
00832   // M o u s e   a c t i o n s
00833   struct MouseMotionPrivate {
00834     MouseHandler handler;
00835     qglviewer::ManipulatedFrame::MouseMotion action;
00836     bool withConstraint; 
00837   };
00838 
00839   class ClickActionPrivate {
00840   public:
00841     Qt::ButtonState buttonState;
00842     bool doubleClick;
00843     Qt::ButtonState buttonBefore;
00844 
00845     bool operator<(const ClickActionPrivate& cap) const
00846     {
00847       if (buttonState != cap.buttonState)
00848     return buttonState < cap.buttonState;
00849       else
00850     if (buttonBefore != cap.buttonBefore)
00851       return buttonBefore < cap.buttonBefore;
00852     else
00853       return doubleClick < cap.doubleClick;
00854     }
00855   };
00856 
00857   void setDefaultMouseBindings();
00858   void performClickAtion(ClickAction ca, const QMouseEvent* const e);
00859   QMap<Qt::ButtonState, MouseMotionPrivate> mouseBinding_;
00860   QMap<Qt::ButtonState, MouseMotionPrivate> wheelBinding_;
00861   QMap<ClickActionPrivate, ClickAction> clickBinding_;
00862   
00863   // S n a p s h o t s
00864   QString snapshotFilename_, snapshotFormat_;
00865   int snapshotCounter_;
00866   
00867   // Q G L V i e w e r   p o o l
00868   static QPtrList<QGLViewer> QGLViewerPool_;
00869   
00870   // I n t e r n a l   d e b u g
00871   int initializationStage_;
00872 };
00873 
00874 #endif // QGLVIEWER_QGLVIEWER_H

Generated on Fri Feb 27 12:01:39 2004 for Glitch by doxygen 1.3.2