00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
00089
00090
00091
00092
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
00439
00440
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
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
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
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
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
00774
00775 QGLViewer(const QGLViewer& v);
00776 QGLViewer& operator=(const QGLViewer& v);
00777
00778
00779 void defaultConstructor();
00780
00781
00782 qglviewer::Camera* camera_;
00783
00784
00785 qglviewer::Vec backgroundColor_, foregroundColor_;
00786
00787
00788 bool drawAxis_;
00789 bool drawGrid_;
00790 bool displayFPS_;
00791 bool displayZBuffer_;
00792 bool enableText_;
00793 bool stereo_;
00794 bool fullScreen_;
00795 QPoint prevPos_;
00796
00797
00798 bool animationStarted_;
00799 int animationPeriod_;
00800 int animationTimerId_;
00801
00802
00803 QTime fpsTime_;
00804 unsigned int fpsCounter_;
00805 float f_p_s_;
00806
00807
00808 qglviewer::ManipulatedFrame* manipulatedFrame_;
00809 bool manipulatedFrameIsACamera_;
00810 qglviewer::MouseGrabber* mouseGrabber_;
00811 bool mouseGrabberIsAManipulatedFrame_;
00812 bool mouseGrabberIsAManipulatedCameraFrame_;
00813
00814
00815
00816
00817
00818
00819
00820 int visualHint_;
00821
00822
00823 void setDefaultShortcutKeys();
00824 enum { nbShortcuts_ = 13 };
00825 Qt::Key shortcutKey_[nbShortcuts_];
00826 Qt::ButtonState shortcutStateKey_[nbShortcuts_];
00827
00828
00829 Qt::Key *keyFrameKey_;
00830 Qt::ButtonState addKFStateKey_, playKFStateKey_;
00831
00832
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
00864 QString snapshotFilename_, snapshotFormat_;
00865 int snapshotCounter_;
00866
00867
00868 static QPtrList<QGLViewer> QGLViewerPool_;
00869
00870
00871 int initializationStage_;
00872 };
00873
00874 #endif // QGLVIEWER_QGLVIEWER_H