QGLViewer Class Reference

An OpenGL viewer based on QGLWidget. More...

#include <qglviewer.h>

List of all members.

Mouse behavior customization

enum  MouseAction {
  NO_MOUSE_ACTION, ROTATE, ZOOM, TRANSLATE, MOVE_FORWARD, LOOK_AROUND,
  MOVE_BACKWARD, SCREEN_ROTATE, ROLL, SCREEN_TRANSLATE, ZOOM_ON_REGION
}
void setMouseStateKey (MouseHandler mh, int buttonState)
void setMouseBinding (int buttonState, MouseHandler handler, MouseAction action, bool withConstraint=true)
MouseAction mouseAction (int buttonState) const
int mouseHandler (int buttonState) const
Qt::ButtonState mouseButtonState (MouseHandler mh, MouseAction ma, bool withConstraint=true) const
void setMouseBinding (int buttonState, ClickAction action, bool doubleClick=false, int buttonBefore=Qt::NoButton)
ClickAction clickAction (int buttonState, bool doubleClick, int buttonBefore) const
void getClickButtonState (ClickAction ca, Qt::ButtonState &buttonState, bool &doubleClick, Qt::ButtonState &buttonBefore) const
void setMouseBindingDescription (int buttonState, bool doubleClick, QString description)
void setWheelBinding (int stateKey, MouseHandler handler, MouseAction action, bool withConstraint=true)
MouseAction wheelAction (int buttonState) const
int wheelHandler (int buttonState) const
int wheelButtonState (MouseHandler mh, MouseAction ma, bool withConstraint=true) const
enum  MouseHandler { CAMERA, FRAME }
enum  ClickAction {
  NO_CLICK_ACTION, ZOOM_ON_PIXEL, ZOOM_TO_FIT, SELECT, RAP_FROM_PIXEL, RAP_IS_CENTER,
  CENTER_FRAME, CENTER_SCENE, SHOW_ENTIRE_SCENE, ALIGN_FRAME, ALIGN_CAMERA
}

Viewer colors

qglviewer::Vec backgroundColor () const
void getBackgroundColor (float &r, float &g, float &b) const
qglviewer::Vec foregroundColor () const
void getForegroundColor (float &r, float &g, float &b) const
void setBackgroundColor (const qglviewer::Vec &color)
void setBackgroundColor (float r, float g, float b)
void setForegroundColor (const qglviewer::Vec &color)
void setBackgroundColor (const QColor &c)
void setForegroundColor (float r, float g, float b)
void setForegroundColor (const QColor &c)

Display of visual hints

bool axisIsDrawn () const
bool gridIsDrawn () const
bool fpsIsDisplayed () const
bool zBufferIsDisplayed () const
bool textIsEnabled () const
bool cameraPathIsEdited () const
void setDrawAxis (bool f=true)
void toggleDrawAxis ()
void setDrawGrid (bool f=true)
void toggleDrawGrid ()
void setDisplayFPS (bool f=true)
void toggleDisplayFPS ()
void setDisplayZBuffer (bool f=true)
void toggleDisplayZBuffer ()
void setEnableText (bool f=true)
void toggleEnableText ()
void editCameraPath (bool edit=true)
void toggleCameraPathEditor ()

Scene related values

float sceneRadius () const
qglviewer::Vec sceneCenter () const
void getSceneCenter (float &x, float &y, float &z) const
void setSceneBoundingBox (const float m[3], const float M[3])
float currentFPS ()
void setSceneRadius (float r)
void setSceneCenter (const qglviewer::Vec &sc)
void setSceneCenter (float x, float y, float z)
void setSceneBoundingBox (const qglviewer::Vec &m, const qglviewer::Vec &M)
void showEntireScene ()

Associated objects

qglviewer::Cameracamera () const
qglviewer::ManipulatedFramemanipulatedFrame () const
void setCamera (qglviewer::Camera *const c)
void setManipulatedFrame (qglviewer::ManipulatedFrame *fr)

State of the viewer

float aspectRatio () const
bool isFullScreen () const
bool displaysInStereo () const
void setFullScreen (bool fs=true)
void toggleFullScreen ()
void setStereoDisplay (bool s=true)
void toggleStereoDisplay ()
virtual void toggleCameraMode ()

Display functions

void drawAxis (float scale=1.0f)
void drawGrid ()
virtual void startScreenCoordinatesSystem (bool upward=false) const
virtual void stopScreenCoordinatesSystem () const
void drawText (int x, int y, const QString &text, const QFont &fnt=QFont())
void draw3DText (const qglviewer::Vec &pos, const qglviewer::Vec &normal, const QString &string, GLfloat height=0.1f)
virtual void drawLight (GLenum light, float scale=1.0f) const
virtual void displayFPS ()
virtual void displayZBuffer () const

Mouse grabber

qglviewer::MouseGrabbermouseGrabber () const
void setMouseGrabber (qglviewer::MouseGrabber *mg)

Snapshots

const QString & snapshotFilename () const
const QString & snapshotFormat () const
int snapshotCounter () const
void saveSnapshot (bool automatic=false, bool overwrite=false)
void setSnapshotFilename (const QString &n)
void setSnapshotFormat (const QString &f)
void setSnapshotCounter (const int c)

Animation

bool animationIsStarted () const
int animationPeriod () const
void setAnimationPeriod (int msecs)
virtual void startAnimation ()
virtual void stopAnimation ()
void toggleAnimationMode ()
virtual void animate ()

Help window

virtual QString helpString () const
virtual QString mouseString () const
virtual QString keyboardString () const
virtual QString mouseBindingsString () const
virtual QString shortcutBindingsString () const
virtual void help ()

Object selection

virtual void select (const QMouseEvent *e)
virtual void select (int x, int y)
virtual void beginSelection (int x, int y)
virtual void drawWithNames ()
virtual void endSelection (int x, int y)
virtual void postSelection (int, int)
int selectedName ()
void setSelectedName (int id)
int selectBufferSize ()
void setSelectBufferSize (int size)
int selectRegionSize ()
void setSelectRegionSize (int size)
GLuint * selectBuffer ()

Keyboard accelerators customization

void setKeyboardAccelerator (KeyboardAction action, QKeySequence key)
QKeySequence keyboardAccelerator (KeyboardAction action)
void setKeyDescription (QKeySequence key, QString description)
void setShortcutKey (KeyboardAction action, int key, int state=-1)
void setShortcutStateKey (KeyboardAction, int)
Qt::Key shortcutKey (KeyboardAction action) const
Qt::ButtonState shortcutStateKey (KeyboardAction action) const
virtual void setKeyFrameKey (int nb, int key)
Qt::Key keyFrameKey (int nb) const
virtual void setAddKeyFrameStateKey (int buttonState)
Qt::ButtonState addKeyFrameStateKey () const
virtual void setPlayKeyFramePathStateKey (int buttonState)
Qt::ButtonState playKeyFramePathStateKey () const
enum  KeyboardAction {
  DRAW_AXIS, DRAW_GRID, DISPLAY_FPS, DISPLAY_Z_BUFFER, ENABLE_TEXT, EXIT,
  SAVE_SCREENSHOT, CAMERA_MODE, FULL_SCREEN, STEREO, ANIMATION, HELP,
  EDIT_CAMERA_PATHS, MOVE_CAMERA_LEFT, MOVE_CAMERA_RIGHT, MOVE_CAMERA_UP, MOVE_CAMERA_DOWN, INCREASE_FLYSPEED,
  DECREASE_FLYSPEED
}

Save and restore viewer state

virtual void saveToFile (const QString &fileName="")
virtual void restoreFromFile (const QString &fileName="")
virtual QDomElement domElement (const QString &name, QDomDocument &doc) const
virtual void initFromDOMElement (const QDomElement &de)

Visual hints

virtual void setVisualHintsMask (int mask, int delay=2000)
virtual void drawVisualHints ()
virtual void resetVisualHints ()

QGLViewerPool associated methods

const QPtrList< QGLViewer > & QGLViewerPool ()
int QGLViewerIndex (const QGLViewer *const v)
void connectSignalToAllViewers (const QObject *sender, const char *signal, const char *member=SLOT(updateGL()))
void disconnectSignalToAllViewers (const QObject *sender, const char *signal, const char *member=SLOT(updateGL()))
void updateGLForAllViewers ()
void saveToFileForAllViewers ()

Mouse, keyboard and event handlers

virtual void mousePressEvent (QMouseEvent *)
virtual void mouseDoubleClickEvent (QMouseEvent *)
virtual void mouseReleaseEvent (QMouseEvent *)
virtual void mouseMoveEvent (QMouseEvent *)
virtual void wheelEvent (QWheelEvent *)
virtual void timerEvent (QTimerEvent *)
virtual void closeEvent (QCloseEvent *)
virtual void keyPressEvent (QKeyEvent *)

Public Types


Signals

void viewerInitialized ()
void drawNeeded ()
void animateNeeded ()
void helpRequired ()
void axisDrawn (bool on)
void gridDrawn (bool on)
void fpsDisplayed (bool on)
void zBufferDisplayed (bool on)
void textEnabled (bool on)
void cameraPathEdited (bool on)
void stereoChanged (bool on)
void pointSelected (const QMouseEvent *e)

Public Member Functions

 QGLViewer (QWidget *parent=NULL, const char *name=0, const QGLWidget *shareWidget=0, WFlags flags=0)
 QGLViewer (const QGLFormat &format, QWidget *parent=0, const char *name=0, const QGLWidget *shareWidget=0, WFlags flags=0)
virtual ~QGLViewer ()

Protected Types


Protected Member Functions

virtual void resizeGL (int w, int h)
virtual void initializeGL ()
virtual void init ()
virtual void paintGL ()
virtual void preDraw ()
virtual void preDrawStereo (bool leftBuffer=true)
virtual void draw ()
virtual void fastDraw ()
virtual void postDraw ()


Detailed Description

An OpenGL viewer based on QGLWidget.

A QGLViewer is a 3D OpenGL viewer based on the Qt's QGLWidget. It includes many classical viewer functionalities, such as a camera trackball, manipulated objects, snapshot saving and much more. Its main goal is to enable the very fast development of new 3D applications.

In order to display a scene, you simply have to derive the draw() function (or use the drawNeeded() signal, see below) and to provide the openGL orders that define your scene. New users should read the introduction page to get familiar with important notions such as sceneRadius() and sceneCenter().

Try the numerous simple examples to discover the possibilities and understand how it works. See also the Qt's QGLWidget documentation for details about inherited methods such as QGLWidget::setAutoBufferSwap() or QGLWidget::swapBuffers().

Instantiation

To use it, you can derive a class from it and overload the draw() virtual method. See the simpleViewer example for an introduction.

 // The Viewer class inherits from QGLViewer and overloads the draw function.
 class Viewer : public QGLViewer
 {
   protected:
   virtual void draw();
   {
     // Your OpenGL drawing code goes here...
   }
 };
A complete commented example is also available.

An other method is to connect your drawing methods to the signals emitted by the QGLViewer (clean callback mechanism). See the callback example for a complete example.

 // A Scene class holds the scene data and provides a drawScene function.
 class Scene : public QObject
 {
   Q_OBJECT // Needed in order to use the Qt signals/slots mechanism
  
   public:
     Scene(const QGLViewer* const v);
  
   public slots:
     void drawScene();
 };

 Scene::Scene(const QGLViewer* const viewer)
 {
   // Connect the viewer signal to our draw function slot
   connect(viewer, SIGNAL(drawNeeded()), SLOT(drawScene()));
 }


Member Enumeration Documentation

enum ClickAction [protected]
 

Defines the possible actions that can be binded to a mouse click. ClickAction are binded using setMouseBinding(). See the mouse page for details.

enum KeyboardAction [protected]
 

Defines the different actions that can directly be associated with a keyboard accelerator. Use setKeyboardAccelerator() to modify a keyboard accelerator.

See the keyboard page for details.

enum MouseAction
 

Defines the possible actions that can be binded to a mouse motion (a click, followed by a mouse displacement). These actions may be applied to the camera() or to the manipulatedFrame() (see MouseHandler). Use setMouseBinding() to bind a mouse button to an action. See the mouse page for details.

enum MouseHandler [protected]
 

Defines the different mouse handlers : Camera or Frame motion. Used by setMouseBinding() to define which handler receives the mouse displacements. See the mouse page for details.


Constructor & Destructor Documentation

QGLViewer QWidget *  parent = NULL,
const char *  name = 0,
const QGLWidget *  shareWidget = 0,
WFlags  flags = 0
 

Set default display flags, initializes camera and other parameters. Calls the QGLWidget constructor with the same parameters. Calls qglviewer::Camera::setDistanceToScreen(4.0) and qglviewer::Camera::setPhysicalScreenWidth(10.0) when screen aspect ratio > 2 (Reality Center).

See the Qt::QGLWidget associated constructor documentation for details on the parameters.

QGLViewer const QGLFormat &  format,
QWidget *  parent = 0,
const char *  name = 0,
const QGLWidget *  shareWidget = 0,
WFlags  flags = 0
 

Same as QGLViewer(), but a Qt::QGLFormat can be provided (used for stereo display in the stereoViewer example.

~QGLViewer  )  [virtual]
 

Virtual destructor. Removes object from QGLViewerPool() and releases allocated memory.


Member Function Documentation

Qt::ButtonState addKeyFrameStateKey  )  const
 

Returns the state key (Qt::AltButton, Qt::ShiftButton, Qt::ControlButton) that must be pressed with the keyFrameKey() to add a KeyFrame to a camera KeyFrame path. Default value is Qt::AltButton. See setAddKeyFrameStateKey() for details.

See also keyFrameKey() and playKeyFramePathStateKey().

See the keyboard accelerator page for details.

virtual void animate  )  [inline, virtual, slot]
 

Scene animation function. Once startAnimation() has been called, an infinite loop calls animate() and draw().

This function should be used for dynamic simulation, games or other applications where the scene geometry evolves over time. Note that KeyFrameInterpolator and SpinningFrame, which regularily update a Frame do not use this method but rather rely on a QTimer signal-slot mechanism.

See the animation example for an illustration.

void animateNeeded  )  [signal]
 

Signal emitted by the default QGLViewer::animate() function. Connect this signal to your scene animation function.

Use this signal-slot mechanism ONLY IF you don't inherit your viewer from QGLViewer (in that case, simply overload the animate() function).

bool animationIsStarted  )  const [inline]
 

Return true when the animation loop is started, i.e. viewer calls animate() and draw(). See startAnimation() and animate(). You should override this method if your scene contains animated elements (KeyFrameInterpolator driven objects excepted).

int animationPeriod  )  const [inline]
 

The animation loop period, in milliseconds. See startAnimation() and animate().

float aspectRatio  )  const [inline]
 

Returns the aspect ratio of the GL widget. That is the ratio between its width and height (see the Qt QGLWidget documentation).

void axisDrawn bool  on  )  [signal]
 

This signal is emitted whenever axisIsDrawn() changes value. This can be done with setDrawAxis() or toggleDrawAxis().

bool axisIsDrawn  )  const [inline]
 

Returns true if the world axis is drawn by the viewer. Set by setDrawAxis() or toggleDrawAxis().

qglviewer::Vec backgroundColor  )  const [inline]
 

Returns the current background color of the viewer. The x, y and z of the result represent the red, green and blue color components. Use setBackgroundColor() to define the background color.

This function is provided for convenience as the background color is an OpenGL state variable set with glClearColor() (see setBackgroundColor()). However, this internal representation has the advantage that it is saved (resp. restored) with saveToFile() (resp. restoreFromFile()) as it is part of the domElement().

Default value is (0.2, 0.2, 0.2) (dark gray). Each color component ranges between 0.0 and 1.0 (see the glColor3f() documentation). You may have to change foregroundColor() accordingly (see setForegroundColor()). See also the QGLWidget::qglColor() and QGLWidget::qglClearColor() documentations.

Attention:
If you directly use glClearColor() instead of setBackgroundColor(), the result of this function will be erroneous. Consider using a glGet() to retrieve the actual current value in that case.

void beginSelection int  x,
int  y
[virtual]
 

This method should prepare the selection. It is called by select() before drawWithNames().

The default implementation uses the GL_SELECT mode to perform a selection. It uses selectBuffer() and selectBufferSize() to define a glSelectBuffer(). The GL_PROJECTION is then set using gluPickMatrix(), with a window selection size defined by selectRegionSize(). Finally, the GL_MODELVIEW matrix is set to the world coordinate sytem using qglviewer::Camera::loadModelViewMatrix().

You should have to redefine this function (if you use the GL_SELECT mode to perform your selection), since this code is fairly classical and can be tuned using setSelectBufferSize() and setSelectRegionSize(). You are more likely to overload endSelection() if you want to use a more complex select buffer structure.

qglviewer::Camera* camera  )  const [inline]
 

The camera that is used by the viewer. See the qglviewer::Camera documentation for a complete description of the available functions.

void cameraPathEdited bool  on  )  [signal]
 

This signal is emitted whenever cameraPathIsEdited() changes value. This can be done with editCameraPath() or toggleCameraPathEditor().

bool cameraPathIsEdited  )  const [inline]
 

Returns true if the camera paths are being edited in the viewer. Set by editCameraPath() or toggleCameraPathEditor() (default EDIT_CAMERA_PATHS keyboard accelerator is 'C'). Default value is false.

When cameraPathIsEdited(), the camera paths that are defined are displayed using qglviewer::Camera::drawAllPaths(). qglviewer::Camera::zNear() and qglviewer::Camera::zFar() are modified so that the paths are not clipped. zBuffer precision is highly affected.

QGLViewer::ClickAction clickAction int  buttonState,
bool  doubleClick,
int  buttonBefore
const
 

Same as mouseAction(), but for the click action set using setMouseBinding().

void closeEvent QCloseEvent *  e  )  [protected, virtual]
 

Save the viewer current state using saveToFile() and then call QGLWidget::closeEvent().

void connectSignalToAllViewers const QObject *  sender,
const char *  signal,
const char *  member = SLOT(updateGL())
[static]
 

Connect a signal to a signal or a slot of all the QGLViewers.

Typical usage would be:

connectSignalToAllViewers(myScene, SIGNAL(needsRedisplay()));

The default target signal is updateGL(), but any other signal/slot can be used. This function will silently ignore the connections that cannot be established.

See also QGLViewerPool(), disconnectSignalToAllViewers() and updateGLForAllViewers().

float currentFPS  )  [inline]
 

Returns the current viewer frame rate, as displayed by displayFPS() (see setDisplayFPS() and toggleDisplayFPS()).

This function is useful for true real-time applications that may adapt the computational load according to frame rate evolution in order to maintain a given frequency.

Note that for stability reasons this value is averaged over 20 frames, and hence will only change every 20 draw. As Qt redraws the window only when needed, this value is meaningful only when startAnimation() is called, when you use qglviewer::Camera::playKeyFramePath() or when the camera is manipulated with the mouse, so that draw() is called in a loop.

void disconnectSignalToAllViewers const QObject *  sender,
const char *  signal,
const char *  member = SLOT(updateGL())
[static]
 

Disconnect a signal to a signal or a slot of all the QGLViewers. Used in conjunction with connectSignalToAllViewers().

The default target signal is updateGL(), but any other signal/slot can be used. This function will silently ignore the connections that cannot be removed. See also updateGLForAllViewers().

void displayFPS  )  [protected, virtual]
 

Displays the current averaged frame rate in the upper left corner of the window. updateGL() should be called in a loop in order to have a meaningful value (this is the case when you continuously move the camera using the mouse or when animationIsStarted()). setAnimationPeriod(0) to make this loop as fast as possible in order to reach the maximum available frame rate.

The FPS display can be toggled with toggleDisplayFPS() (default keyboard accelerator is 'F') or with setDisplayFPS(). Use QApplication::setFont() to define the FPS font (see drawText()). Current application averaged frame rate is available from currentFPS().

bool displaysInStereo  )  const [inline]
 

Returns true if the viewer displays in stereo. Set by setStereoDisplay() or toggleStereoDisplay(). Default value is false.

void displayZBuffer  )  const [protected, virtual]
 

Displays the current z-buffer in grey levels for debugging purposes. Note that it hides the normal display. Frame rate is slowed down because of the z-buffer reading and writing.

QDomElement domElement const QString &  name,
QDomDocument &  doc
const [virtual]
 

Creates an XML QDomElement that represents the QGLViewer. name is the name of the QDomElement tag. You need to provide the QDomDocument doc that will hold the resulting element.

Use initFromDOMElement() to restore the QGLViewer state from the resulting domElement. Merges the qglviewer::ManipulatedFrame::domElement(), qglviewer::Camera::domElement(), ... elements.

Attention:
For the manipulatedFrame(), qglviewer::Frame::constraint() and qglviewer::Frame::referenceFrame() are not saved. See qglviewer::Frame::domElement().

virtual void draw  )  [inline, protected, virtual]
 

The core function of the viewer, called to draw the scene.

If you build a class that inherits from QGLViewer, this is the function you want to overload. See the simpleViewer example for an illustration.

If you choose to use a callback mechanism instead, connect the drawNeeded() signal to your own draw function (signal emitted by preDraw()). See the callback example for details.

Attention:
The GL_PROJECTION matrix must not be modified by this function, so that the viewer hints (axis, grid, FPS...) that are displayed in postDraw() are correctly displayed. Use push/pop or call camera()->loadProjectionMatrix() at the end of draw() if you need to change the projection matrix (unlikely). The GL_MODELVIEW matrix, on the other hand, can be modified and left in a different state as it will be reloaded in postDraw() anyhow.

void draw3DText const qglviewer::Vec pos,
const qglviewer::Vec normal,
const QString &  text,
GLfloat  height = 0.1f
 

Similar to drawText(), but the text is handled as a classical 3D object of the scene.

Although useful, this function is deprecated with recent Qt versions. Indeed, Qt renders text as pixmaps that cannot be orientated. However, when GLUT is used instead of Qt (when your Qt version is lower than 3.1, see QT_VERSION_WITHOUT_GLUT in config .h) orientated characters are possible and this function will work.

pos and normal respectly represent the 3D coordinate of the text and the normal to the text plane. They are expressed with respect to the current GL_MODELVIEW matrix.

If you want your text to always face the camera (normal parallel to camera()->viewDirection), use QGLWidget::renderText(x,y,z).

See the draw3DText example for an illustration.

void drawAxis float  size = 1.0f  ) 
 

Draws an XYZ axis, with a given size (default is 1.0). The axis position and orientation only depends on the current modelview matrix state.

Note that pressing the DRAW_AXIS keyboard accelerator (default is 'A') toggles the display of an axis centered on the world coordinates system and scaled to the sceneRadius(). This is useful to materialize the world coordinates system.

Use the following code to display the current position and orientation of a qglviewer::Frame :

  glPushMatrix();
  glMultMatrixd(frame.matrix());
  drawAxis(sceneRadius() / 5.0); // Or any scale
  glPopMatrix();

Note:
The matrix mode should be GL_MODELVIEW when this function is called.

void drawGrid  )  [inline]
 

Displays a XY grid of size 1, centered on (0,0,0). The calling function should set the GL_MODELVIEW matrix and scale factor before calling this function.

Attention:
The GL state is modified by this function: GL_LIGHTING is disabled and line width is set to 1.

void drawLight GLenum  light,
float  scale = 1.0f
const [protected, virtual]
 

This debugging function draws a representation of light. The drawing depends on the type of light (spot, directional...). Typically used in your draw function:

  drawLight(GL_LIGHT0)

Optionnal parameter scale (default 1.0f) rescales the light representation. For instance, to get a size twice bigger:

  drawLight(GL_LIGHT0, 2.0f)
Note that this size is already proportional to the scene radius.

See the drawLight example for an illustration.

void drawNeeded  )  [signal]
 

Signal emitted by the default QGLViewer::draw() function. Connect this signal to your main drawing function. preDraw() is called before this signal is emitted and will call qglviewer::Camera::loadProjectionMatrix() and qglviewer::Camera::loadModelViewMatrix() to set the viewing matrices. postDraw() will be called after this signal is answered. pre (resp. post) draw can be tuned by adding code at the beginning (resp. end) of your draw slot. See the callback example for an illustration.

You can check whether the camera is manipulated to call a fast draw version :

  if (viewer.camera()->isManipulated())
    fastDrawMethod();
  else
    normalDrawMethod();

Use this signal-slot mechanism ONLY IF you don't inherit your viewer from QGLViewer (in that case, simply overload the draw() and fastDraw() function).

See the fastDraw example for an illustration.

void drawText int  x,
int  y,
const QString &  text,
const QFont &  fnt = QFont()
 

Draws a text at position x, y (expressed in screen coordinates pixels, origin in the upper left corner of the window). Can be called in draw() to easily display some information on the screen.

This procedure calls QGLWidget::renderText() if your Qt version is at least 3.1, otherwise it uses GLUT. The default QApplication::font() is used to render the text when no fnt is specified. Use QApplication::setFont() to define the default font. Only the font size (set with QFont::setPixelSize() or QFont::setPointSize()) is taken into with the GLUT version.

Attention:
GL_LIGHTING should be disabled by the calling function so that colors are properly rendered (with the renderText version).
This function can be used in conjunction with the qglviewer::Camera::projectedCoordinatesOf() function to display a text attached to an object. In your draw() function call:
  qglviewer::Vec screenPos = camera()->projectedCoordinatesOf(myFrame.position());
  drawText((int)screenPos[0], (int)screenPos[1], "My Object");
See the screenCoordSystem example for an illustration.

QGLWidget::renderText() (Qt >= 3.1) performs a similar action. It exists in a 2D (pixel coordinates) and a 3D (classical coordinates) version. Use this QGLWidget::renderText(x,y,z, str) function to draw a text that faces the camera, located at a specific 3D location (no need to convert to screen coordinates).

The GL_MODELVIEW and GL_PROJECTION matrices are not modified by this function.

Text is displayed only when textIsEnabled() is true (default). Use toggleEnableText() or setEnableText() to change this value (default ENABLE_TEXT keyboard accelerator is '?'). This mechanism allows the user to conveniently remove all the displayed text with a single keyboard accelerator. Set the keyboard accelerator to 0 if you want to forbid this behavior (see setKeyboardAccelerator()).

See also the draw3DText() and displayFPS() functions.

Note:
Each call to drawText() changes the camera projection matrix and restores it back (using startScreenCoordinatesSystem() and stopScreenCoordinatesSystem() with Qt < 3.1). If you call this function several times and it slows down your frame rate, consider factorizing the context changes. You may also want to try the Qt image overlay mechanism which may be more efficient when your text does not change over time).

The Qt minimum version that disables glut is set by QT_VERSION_WITHOUT_GLUT in config .h. Default value is Qt 3.1.

void drawVisualHints  )  [virtual]
 

Draws viewer related visual hints.

Displays the new qglviewer::Camera::revolveAroundPoint() when it is changed. See the mouse page for details. Also draws a line between qglviewer::Camera::revolveAroundPoint() and mouse cursor when the camera is rotated around the camera Z axis.

See also setVisualHintsMask() and resetVisualHints(). The hint color is foregroundColor().

Note:
These functions may become more interesting one day. The current design is too limited and should be improved when other visual hints must be drawn.

virtual void drawWithNames  )  [inline, virtual]
 

This function is called by select() and is originally empty. You should overload it to draw the different elements of your scene you want to be able to select. The default select() implementation relies on the GL_SELECT, and requires the drawing of each element within glPushName() glPopName() block. A typical usage would be (see the select example):

    void Viewer::drawWithNames()
    {
      for (int i=0; i<nbObjects; ++i)
      {
        glPushName(i);
        object(i)->draw();
        glPopName();
      }
    }

The resulting selected name is retrieved by endSelection(), which setSelectedName() (a value of -1 means no selection). Use selectedName() to update your selection, probably in the postSelection() method.

void editCameraPath bool  edit = true  )  [slot]
 

Start (default, edit=true) or stop (edit=false) the edition of the camera paths. See also toggleCameraPathEditor().

void endSelection int  x,
int  y
[virtual]
 

This method is called by select() after scene elements were drawned by drawWithNames(). It should analyse the selection result to determine which object is actually selected.

The default implementation relies on GL_SELECT mode (see beginSelection()). It assumes that names were pushed and popped in drawWithNames(), and analyses the selectBuffer() to find the name that corresponds to the closer (z min) object. It then setSelectedName() to this value, or to -1 if the selectBuffer() is empty (no object under the mouse cursor). Use selectedName() (probably in the postSelection() method) to retrieve this value and update your data structure accordingly.

This default implementation, although sufficient for many cases is however limited and you may have to overload this method. This will be the case if drawWithNames() uses several push levels in the name heap. A more precise depth selection, for instance priviledging points over edges and triangles to avoir z precision problems, will also require an overloading. A typical implementation will look like:

  glFlush();

  // Get the number of objects that were seen through the pick matrix frustum.
  // Resets GL_RENDER mode.
  GLint nbHits = glRenderMode(GL_RENDER);

  if (nbHits <= 0)
    setSelectedName(-1);
  else
    {
      // Interpret results : each object created values in the selectBuffer().
      // See the glSelectBuffer() man page for details on the buffer structure.
      // The following code depends on your selectBuffer() structure.
      for (int i=0; i<nbHits; ++i)
       if ((selectBuffer())[i*4+1] < zMin)
         setSelectedName((selectBuffer())[i*4+3])
    }

void fastDraw  )  [protected, virtual]
 

Fast draw of the scene. Called instead of draw() when the camera is manipulated. Useful for interactive displacements in a complex scene. Default behavior calls draw(). See the fastDraw example for an illustration.

qglviewer::Vec foregroundColor  )  const [inline]
 

The current viewer foreground color. This color is used to display the FPS text (see setDisplayFPS()), camera paths (see qglviewer::Camera::drawAllPaths() and editCameraPath()), XY grid (see drawGrid() and setDrawGrid()) and the visual hints (see drawVisualHints()).

Default value is (0.7, 0.7, 0.7). Each color component ranges between 0.0 and 1.0 (see the glColor3f() documentation). This value should be changed in conjunction with the backgroundColor() (see setBackgroundColor()).

See also the QGLWidget::qglColor() and QGLWidget::qglClearColor() documentations.

void fpsDisplayed bool  on  )  [signal]
 

This signal is emitted whenever fpsIsDisplayed() changes value. This can be done with setDisplayFPS() or toggleDisplayFPS().

bool fpsIsDisplayed  )  const [inline]
 

Returns true if a displayFPS() is called by the viewer. Set by setDisplayFPS() or toggleDisplayFPS(). See currentFPS().

void getBackgroundColor float &  r,
float &  g,
float &  b
const
 

Same as backgroundColor(), but result is returned as three floats.

void getClickButtonState ClickAction  ca,
Qt::ButtonState &  buttonState,
bool &  doubleClick,
Qt::ButtonState &  buttonBefore
const
 

Similar to mouseButtonState(), but for the click actions. Note that the results of the query are returned in the buttonState, doubleClick and buttonBefore parameters. If the ClickAction is not associated to any mouse button, Qt::NoButton is returned in buttonState. If several mouse buttons trigger in the ClickAction, one of them is returned.

void getForegroundColor float &  r,
float &  g,
float &  b
const
 

Same as foregroundColor(), but result is returned as three floats.

void getSceneCenter float &  x,
float &  y,
float &  z
const
 

float version of sceneCenter().

void gridDrawn bool  on  )  [signal]
 

This signal is emitted whenever gridIsDrawn() changes value. This can be done with setDrawGrid() or toggleDrawGrid().

bool gridIsDrawn  )  const [inline]
 

Returns true if a grid is drawn by the viewer. Set by setDrawGrid() or toggleDrawGrid().

void help  )  [virtual, slot]
 

This function is called when the user presses the HELP_KEY (default is 'H'). It opens a modal help window that includes three tabs, which are respectively filled with the results of helpString(), keyboardString() and mouseString(). If one of these is QString::null, the associated tab is not created. Overload these functions to define you own help text. Rich html-like text can be used (see the QStyleSheet documentation).

Set the HELP_KEY keyboard accelerator to 0 to disable the help window (see setKeyboardAccelerator()).

The helpRequired() signal is emitted.

void helpRequired  )  [signal]
 

Signal emitted by the default QGLViewer::help() function. Connect this signal to your own help function.

Use this signal-slot mechanism ONLY IF you don't inherit your viewer from QGLViewer (in that case, simply overload the help() function).

virtual QString helpString  )  const [inline, virtual]
 

helpString() is displayed in the help window main tab. This window is created by the help() function when the HELP_KEY (default is 'H') is pressed. Overload this function to define your own help string, which should shortly describe your application and explains how it works. Rich-text (HTML) tags can be used.

  QString myViewer::helpString() const
  {
    QString text("<h2>M y V i e w e r</h2>");
    text += "Displays a <b>Scene</b> using openGL. Move the camera using the mouse.";
    return text;
  }

Default value is QString::null, which means that the associated tab in the help window is removed.

See also mouseString() and keyboardString().

virtual void init  )  [inline, protected, virtual]
 

Initialization of the viewer. This function will be called before the first drawing and you can overload it to initialize some of the GL flags. The original function is empty and hence does not need to be called.

Can be used to set the camera (qglviewer::Camera::setPosition(), qglviewer::Camera::setFieldOfView(), ...) or to make the camera fit the scene (see qglviewer::Camera::showEntireScene()).

OpenGL flags should also be (re)defined here. Some default flags are set in initializeGL(): only the glEnable(GL_COLOR_MATERIAL) and glEnable(GL_LIGHTING) are not set to their OpenGL default value. Use this function to set your own openGL flags.

Attention:
You should not call updateGL() (or any function that calls it) in this function, as it will create an infinite loop (this comes from the Qt initializeGL() function). The different QGLViewer set function (setDrawGrid(), setDrawAxis()...) are protected against this problem and can safely be called.

This function should only be used for viewer dependent initializations (camera, openGL state). Other data initializations (program parameters parsing, scene dependent initializations...) should be made in a separate function, called by your main or any other initialization function. On the other hand, all the openGL specific initializations must be done in this function: the openGL context is not yet available in your viewer constructor.

void initFromDOMElement const QDomElement &  de  )  [virtual]
 

Restores the QGLViewer state from a QDomElement created by domElement(). See also qglviewer::Camera::initFromDOMElement(), qglviewer::ManipulatedFrame::initFromDOMElement().

Note:
isFullScreen() cannot be properly restored in constructor or in init(). It requires initializeGL() to be completed before.

void initializeGL  )  [protected, virtual]
 

Initialization of the GL context, creation of some viewer display lists. Calls init() at the end.

Attention:
The initial QGLViewer GL state does not follow the openGL standards. Actually, to make beginners' life easier and to simplify the examples, the following flags are defined :
  glEnable(GL_LIGHTING);
  glEnable(GL_LIGHT0);
  glEnable(GL_DEPTH_TEST);
  glEnable(GL_COLOR_MATERIAL);

If you port an existing application to QGLViewer and your display changes, you probably want to disable these flags (in init()) to get back to a standard openGL state.

init() is called at the end, and the openGL flags can be re-defined there. This function should not be overloaded. Use init() for viewer initialization. In case of overloading, you should call QGLViewer::initializeGL() at the beginning of your new initializeGL() function (display list creation).

bool isFullScreen  )  const [inline]
 

Returns true if the viewer is in fullScreen mode. Set by setFullScreen() or toggleFullScreen().

QKeySequence keyboardAccelerator KeyboardAction  action  ) 
 

Returns the keyboard accelerator currently associated to a given QGLViewer::KeyboardAction.

Returns QKeySequence(0) if this action accelerator is disabled (use QKeySequence::isEmpty() to test for this value). Keyboard accelerators are set using setKeyboardAccelerator().

QString keyboardString  )  const [virtual]
 

Returns a QString that describes the application keyboard accelerator bindings, and that will be displayed in the help() window Keyboard tab. Default value is a table that describes all the current keyboard accelerators. This table is made of the standard QGLViewer::KeyboardAction accelerators (defined using setKeyboardAccelerator()), merged with the accelerators defined using setKeyDescription(). See the keyboard accelerator page for details on key customization.

You should not need to overload this function, unless you want a specific help display. A QString::null return value will suppress the Keyboard tab in help().

Qt::Key keyFrameKey int  nb  )  const
 

Returns the camera Key Frame path keyboard accelerator for index nb. nb should not exceed qglviewer::Camera::nbPaths(). Default values are F1..F12 for indexes 0..11. See setKeyFrameKey() for details.

See also addKeyFrameStateKey() and playKeyFramePathStateKey().

See the keyboard accelerator page for details.

void keyPressEvent QKeyEvent *  e  )  [protected, virtual]
 

Key pressed callback function. Some default keyboard accelerators are defined and can easily be redefined using setKeyboardAccelerator(). See the keyboard accelerator page for details and default bindings.

Overload this function to implement a specific keyboard accelerator binding for one of your application function. You should call the original function in the default case of your switch to preserve the default viewer key bindings :

  void Viewer::keyPressEvent(QKeyEvent *e)
  {
  switch (e->key())
  {
    case Qt::Key_R : reset(); updateGL(); break;
    // and so on...
    default: QGLViewer::keyPressEvent(e);
  }
  }

Consider testing the modifier keys for more complex behaviors:

  const Qt::ButtonState state = (Qt::ButtonState)(e->state() & Qt::KeyButtonMask);
  if (state == Qt::AltButton)
    switch (e->key())
    {
      ...
    }
  else
    ...

When you define a new keyboard accelerator, you should give a short description of your accelerator using setKeyDescription(), which is displayed in the help() window Keyboard tab.

Note that if you want to overload a QGLViewer::KeyboardAction accelerator, you need to disable the original accelerator using setKeyboardAccelerator() with a 0 QKeySequence. When there is such a conflict, setKeyDescription() automatically disables the QGLViewer::KeyboardAction action.

An alternative to this function is to use the QAccel class. See the associated Qt documentation.

qglviewer::ManipulatedFrame* manipulatedFrame  )  const [inline]
 

Returns the current manipulated frame, which can be moved with the mouse. Default mouse bindings make the ManipulatedFrame move when the Control key is pressed. Use setMouseBinding() to define your own bindings.

Returns NULL when no frame has been associated with the viewer (with setManipulatedFrame()). See the manipulatedFrame example for an illustration.

QGLViewer::MouseAction mouseAction int  buttonState  )  const
 

Returns the MouseAction currently associated with the Qt::ButtonState buttonState. If no action is associated, returns NO_MOUSE_ACTION.

For instance, to know which motion corresponds to Alt-LeftButton, do:

  QGLViewer::MouseAction mm = mouseAction(Qt::AltButton | Qt::LeftButton);
  if (mm != NO_MOUSE_ACTION) ...

Use mouseHandler() to know who (CAMERA or FRAME) will perform this motion.

virtual QString mouseBindingsString  )  const [inline, virtual]
 

This function is deprecated, use mouseString() instead.

Qt::ButtonState mouseButtonState MouseHandler  mh,
MouseAction  ma,
bool  withConstraint = true
const
 

Returns the Qt::ButtonState (if any) that has to be used to activate action ma on handler mh (with constraint or not). If no Qt::ButtonState is associated, returns Qt::NoButton which is an impossible case since at least one mouse button has to be specified in setMouseBinding().

To know which keys and mouse buttons have to be pressed to translate the camera, use tests like:

  Qt::ButtonState bs = mouseButtonState(QGLViewer::CAMERA, QGLViewer::TRANSLATE);
  if (bs & Qt::RightButton) ... // Right button needed to translate the camera
  if (bs & Qt::AltButton)   ... // Alt key needed
  if (bs & Qt::KeyButtonMask == Qt::NoButton) ... // No state key needed
Note that current mouse bindings are displayed by one of the help window tabs (use the 'H' key).

void mouseDoubleClickEvent QMouseEvent *  e  )  [protected, virtual]
 

The behavior of the mouse double click depends on the current mouse binding. See setMouseBinding() and the QGLViewer mouse page.

qglviewer::MouseGrabber* mouseGrabber  )  const [inline]
 

Returns the current MouseGrabber, or NULL if no MouseGrabber is currently under the mouse cursor. When qglviewer::MouseGrabber::grabsMouse(), the different mouse events are sent to the mouseGrabber() (see mousePressEvent(), mouseMoveEvent(), and related functions.)

You may use setMouseGrabber() to define a qglviewer::MouseGrabber, but mouseMoveEvent() already does it, using qglviewer::MouseGrabber::checkIfGrabsMouse() to determine if a MouseGrabber is currently under the mouse cursor. See the mouseGrabber example for an illustration.

In order to use mouseGrabber, you need to enable mouse tracking so that mouseMoveEvent() is called even when no mouse button is pressed. Add this in init() or in your viewer constructor:

  setMouseTracking(true);
Note that the default behavior is to disable mouse tracking. Use QWidget::hasMouseTracking() to get current value.

int mouseHandler int  buttonState  )  const
 

Returns the MouseHandler currently associated with the Qt::ButtonState buttonState. If no action is associated, returns -1.

For instance, to know which handler receives the Alt-LeftButton, do:

  int mh = mouseHandler(Qt::AltButton | Qt::LeftButton);
  if (mh == QGLViewer::CAMERA) ...

Use mouseAction() to know which action (see the MouseAction enum) will be perform on this handler.

void mouseMoveEvent QMouseEvent *  e  )  [protected, virtual]
 

Maintaining a button pressed while moving the mouse updates the camera or the manipulated frame. The different possible actions (see MouseAction) are binded to mouse buttons using setMouseBinding().

If you want to define your own mouse behavior, do something like this :

  void Viewer::mousePressEvent(QMouseEvent* e)
  {
    // Qt::KeyButtonMask separates the Control/Alt/Shift state key from the
    // mouse (left/middle/right) buttons
    if ((e->state() & Qt::KeyButtonMask) ==
           (Your Qt::ShiftButton/Qt::ControlButton/Qt::AltButton combination))
      myMouseBehavior = true;
    else
      QGLViewer::mousePressEvent(e);
  }

  void Viewer::mouseMoveEvent(QMouseEvent *e)
  {
  if (myMouseBehavior)
    // Use e->x() and e->y() as you want...
  else
    QGLViewer::mouseMoveEvent(e);
  }

  void Viewer::mouseReleaseEvent(QMouseEvent* e)
  {
  if (myMouseBehavior)
    myMouseBehavior = false;
  else
    QGLViewer::mouseReleaseEvent(e);
  }

Many other event handlers can be customized : mouseDoubleClickEvent(), wheelEvent(), mouseReleaseEvent()... See the Qt::QWidget protected members documentation for a complete list.

void mousePressEvent QMouseEvent *  e  )  [protected, virtual]
 

When the user clicks on the mouse:

See the QGLViewer mouse page for a complete description of mouse bindings. If you need to implement a scene object selection with the mouse, see the select example and qglviewer::Camera::convertClickToLine().

Classical mouse binding customization can be achieved using setMouseBinding() and setWheelBinding().

See the mouseMoveEvent() documentation for an example of more complex mouse behavior customization.

Note:
When the mouseGrabber() is a manipulatedFrame(), the modifier keys are not taken into account. This allows for a direct manipulation of the manipulatedFrame() when the mouse hovers, which is probably what is expected.

void mouseReleaseEvent QMouseEvent *  e  )  [protected, virtual]
 

When the user releases the mouse button, the camera (or the manipulatedFrame) action is stopped.

See the mouseMoveEvent() documentation for an example of mouse behavior customization.

QString mouseString  )  const [virtual]
 

Returns a QString that describes the application mouse bindings, as it will be displayed in the help() window Mouse tab.

Returns a table that describes all the current standard mouse bindings (as defined using setMouseBinding() and setWheelBinding()) as well as custom application mouse binding descriptions defined using setMouseBindingDescription().

See the mouse page for details on mouse bindings.

You should not need to overload this function, unless you want a specific help display. A QString::null return value will suppress the Mouse tab in help().

void paintGL  )  [protected, virtual]
 

The paint method. Calls preDraw(), draw() (or fastDraw()) and postDraw() in that order. Should not be overloaded. Overload the internal functions instead.

If you choose to overload, the GL_Context must not be changed between two successive calls to draw(), so that the user can feel free to set his/her openGL flags once for all.

If viewer displaysInStereo(), calls preDrawStereo(flag), draw(), postDraw(), first with flag = true and then flag = false to draw successively in left and right buffers.

Qt::ButtonState playKeyFramePathStateKey  )  const
 

Returns the state key (Qt::AltButton, Qt::ShiftButton, Qt::ControlButton) that must be pressed with the keyFrameKey() to play a camera KeyFrame path. Default value is Qt::NoButton. See setPlayKeyFramePathStateKey() for details.

See also keyFrameKey() and addKeyFrameStateKey().

See the keyboard accelerator page for details.

void pointSelected const QMouseEvent *  e  )  [signal]
 

Signal emitted when select() is called. Connect this signal to your selection drawing function. Use this signal-slot mechanism ONLY IF you don't inherit your viewer from QGLViewer (in that case, simply overload the select() or the drawWithNames() functions). See select() for more details.

void postDraw  )  [protected, virtual]
 

Done after draw(). Default behavior displays axis, grid, FPS... when the respective flags are enabled. The GLContext (color, LIGHTING, BLEND...) should not be changed by this function, so that in draw(), you can rely on the OpenGL context. Respect this convention (by pushing/popping the different attributes) if you overload this function. Assumes the GL_PROJECTION matrix was not changed by draw(), reset the GL_MODELVIEW matrix.

virtual void postSelection int  ,
int 
[inline, virtual]
 

This method is called at the end of the select() procedure. It should finalyse the selection process and update the data structure/interface/computation/display... according to the newly selected entity.

The default implementation is empty. Overload this method if needed, and use selectedName() to retrieve the selected entity name (returns -1 if no object was selectable under the mouse cursor). See the select example for an illustration.

void preDraw  )  [protected, virtual]
 

Called before draw(). Default behavior clears screen and set the projection and model view matrices :

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);    

  // GL_PROJECTION matrix
  camera()->loadProjectionMatrix();
  // GL_MODELVIEW matrix
  camera()->loadModelViewMatrix();

Emits the drawNeeded() signal once this is done. Mainly useful if you choose not to use derivation to create your own viewer. See the callback example for details.

void preDrawStereo bool  leftBuffer = true  )  [protected, virtual]
 

Called before draw() (instead of preDraw()) when viewer displaysInStereo(). Same as preDraw() except that the glDrawBuffer() is set to GL_BACK_LEFT or GL_BACK_RIGHT depending on leftBuffer.

int QGLViewerIndex const QGLViewer *const   v  )  [inline, static]
 

Returns the index of the QGLViewer v in the QGLViewerPool(). This index in unique and can be used to identify the different created QGLViewers (see saveToFile() for an application example). When a QGLViewer is deleted, all the next QGLViewers' indexes are shifted down.

Returns -1 if the QGLViewer could not be found (which should not be possible).

const QPtrList<QGLViewer>& QGLViewerPool  )  [inline, static]
 

This QPtrList (see Qt documentation) holds all the created QGLViewer. If you need to apply a method to all the created viewers, use code like this:

  QPtrListIterator<QGLViewer> it(QGLViewer::QGLViewerPool());
  for (QGLViewer* viewer; (viewer = it.current()) != NULL; ++it)
    viewer->anyAction();
Classical functions are allready implemented : connectSignalToAllViewers(), disconnectSignalToAllViewers() and updateGLForAllViewers(). See also QGLViewerIndex().

void resetVisualHints  )  [virtual, slot]
 

Reset the mask used by drawVisualHints(). Called by setVisualHintsMask() after 2 seconds to reset the display.

void resizeGL int  w,
int  h
[protected, virtual]
 

Called when the window size is modified. If you override this function, be very careful to call first the inherited method.

  void Viewer::resizeGL( int w, int h )
  {
  QGLViewer::resizeGL(w,h);
  // ...
  }

void restoreFromFile const QString &  fileName = ""  )  [virtual]
 

Restores the QGLViewer from a state saved in fileName with saveToFile().

If fileName is empty (default), the filename is automatically generated. A directory may also be provided as filename. See the saveToFile() documentation.

You should define your manipulatedFrame() before you call this function, so that its previous state can be restored. Initialization code put after this function will override saved values.

 void Viewer::init()
 {
 // declaration of a manipulatedFrame, if any.
 restoreFromFile();
 // main init code goes here and overrides file savings
 }

If you viewer starts with a black screen, remember that the mouse double clicks automatically fits the orientation, zoom and placement of the camera(). If sceneCenter() and sceneRadius() are properly defined, you no longer should have an empty screen.

void saveSnapshot bool  automatic = false,
bool  overwrite = false
[slot]
 

Saves a snapshot of the current image displayed by the widget. If no snapshot filename is defined (see snapshotFilename()) or if automatic is false, a file dialog is opened to ask for the filename.

Saving formats are those available in the Qt installation, plus some vectorial formats (EPS, PS, XFIG). See setSnapshotFormat().

Some artifacts may appear when displaying the PS and EPS result. Simply remove the anti-alias option in ghostview to get the correct display. Printed output will be fine. The libEPSRender library was written by Cyril Soler (Cyril.Soler@imag.fr).

When automatic is true (default is false), the filename is set to NAME-NUMBER, where NAME is snapshotFilename() and NUMBER is snapshotCounter(). The snapshotCounter() is incremented. This is useful to create videos from your application:

  init() { resize(720, 576); } // PAL DV format (use 720x480 for NTSC DV)

  draw() {
    scene.draw();
    
    if (makeMovie)
      saveSnapshot(true, true); // Warning, overwrite mode
  }
Then call draw() in a loop (for instance using animate() and/or a camera() KeyFrameInterpolator replay) to create your image sequence.

If you want to create a Quicktime VR panoramic sequence, simply use code like this:

  void Viewer::createQuicktime()
  {
    const int nbImages = 36;
    for (int i=0; i<nbImages; ++i)
      {
        camera()->setOrientation(2.0*M_PI/nbImages, 0.0); // Theta-Phi orientation
        showEntireScene();
        updateGL();  // calls draw(), which saveSnapshot() as above
      }
  }

When overwrite is set to false (default), a pop-up window asks for confirmation (when automatic is false) or the snapshotCounter() is incremented until a non-existing file name is found (when automatic is true).

void saveToFile const QString &  fileName = ""  )  [virtual]
 

Saves in fileName an XML representation of the QGLViewer state, obtained from domElement(). Use restoreFromFile() to restore the viewer.

If no filename is provided (default), the generated filename will be ".qglviewer.xml". If several viewers were created in this application, the files will be numbered (".qglviewer0.xml", ".qglviewer1.xml",... See QGLViewer::QGLViewerIndex()). Each viewer will then read back its own information in restoreFromFile(), provided that the viewers are created in the same order, which is usually the case.

If filename is a directory, the file name is generated as above and saved in this directory.

This function is called when a viewer is closed (default key is Escape).

void saveToFileForAllViewers  )  [static]
 

saveToFile() is called on all the created QGLViewers using the QGLViewerPool().

See connectSignalToAllViewers() and disconnectSignalToAllViewers() for more complex connections.

qglviewer::Vec sceneCenter  )  const [inline]
 

Scene should be included in a sphere centered on this point. Simply calls qglviewer::Camera::sceneCenter(). Set using setSceneCenter().

float sceneRadius  )  const [inline]
 

Returns the scene radius (used by the camera() to set qglviewer::Camera::zNear() and qglviewer::Camera::zFar()). The entire scene must be included in a sphere of radius sceneRadius(), centered on sceneCenter().

This function is equivalent to camera()->sceneRadius().

void select int  x,
int  y
[virtual]
 

This function performs a selection in the scene from pixel coordinates. It is called when the user clicks on the SELECT ClickAction binded button(s) (default is Shift-LeftButton).

This function successively calls four other functions:

The default implementation of these functions is as follows (see the functions' documentation for more details) :

  • beginSelection() sets the GL_SELECT mode with the appropriate picking matrices.
  • drawWithNames() is empty and should be overloaded to draw your scene with glPushNames() calls.
  • postSelection() is empty and can be overloaded for possible signal/display/interface update.
The GL_SELECT mode works as follows : a square frustum (see selectRegionSize()) is created around the mouse cursor by beginSelection(). The scene objects are then drawned by drawWithNames() which pushes a name (an integer value) before each of them. The names of the objects that draw something in the selection region are recorded in the selectBuffer(). endSelection() then analyses this buffer and setSelectedName() to the name corresponding to the closest object. postSelection() can then be used to update the data structure according to this selection. See the glSelectBuffer() man page for details on this mechanism.

This default implementation is quite limited: only the closer object is selected, and only one level of names can be pushed. However, this reveals sufficient in many cases and you usually only have to overload drawWithNames() and maybe postSelection(). See the select example for an illustration.

If you need a more complex selection process (such as a point, edge or triangle selection, which is easier with a 2 or 3 levels heap, and which requires a finer depth sorting to priviledge point over edge and edges over triangles), overload the endSelection() method. Use setSelectRegionSize(), setSelectBufferSize() to tune the select buffer configuration.

x and y are the pixel coordinates (origin in the upper left corner) where the selection occurs. Use qglviewer::Camera::convertClickToLine() to transform these coordinates in a 3D ray if you want to perform an analytical intersection.

Use setMouseBinding() to customize mouse bindings. See also selectBuffer(), selectBufferSize(), selectRegionSize().

void select const QMouseEvent *  e  )  [virtual]
 

Simple wrapper function : calls select(e->x(), e->y()).

Emits pointSelected(e) which is useful only if you rely on the Qt signal-slot mechanism and you did not overload QGLViewer. If you choose to derive your own viewer class, simply overload select() (or probably simply drawWithNames(), see the select example) to implement your selection mechanism.

GLuint* selectBuffer  )  [inline]
 

Returns a pointer to an array of GLuint. This buffer is used by the GL_SELECT mode in select() to perform object selection. The buffer size can be modified using setSelectBufferSize(). If you overload endSelection(), you will analyse the content of this buffer. See the glSelectBuffer() man page for details.

int selectBufferSize  )  [inline]
 

Returns the current selectBuffer() size. Use setSelectBufferSize() to change this value. Default value is 256. This size should be over estimated to prevent a buffer overflow when many objects are drawned under the mouse cursor. The default value should however fit most applications. See the select() documentation for details. See also selectRegionSize().

int selectedName  )  [inline]
 

Returns the name (an integer value) of the entity that was last selected by select(). This value is set by endSelection(). See the select() documentation for details.

As a convention, this function returns -1 if the selectBuffer() was empty, meaning that no object was selected. Note that this function returns the same value until setSelectedName() is called, which should only be done by endSelection(), and hence only when a selection is performed using select().

Before the first call to select(), the return value is -1.

int selectRegionSize  )  [inline]
 

This size (in pixels) is used to define the selection window size created in beginSelection(). A square frustum is then created with this side size around the mouse cursor, and the objects that will be drawned in this region by drawWithNames() will be recorded in the selectBuffer(). endSelection() then analyses this buffer and setSelectedName() to the closest object name.

The default value is 4, which is adapted to standard applications. A smaller value results in a more precise but the user has to be careful for small feature selection.

void setAddKeyFrameStateKey int  buttonState  )  [virtual]
 

Defines the accelerator state key (Qt::AltButton, Qt::ShiftButton, Qt::ControlButton) that must be pressed in conjunction with the keyFrameKey(i) to add a Key Frame to the camera Key Frame path of index i. Default state key is Qt::AltButton.

The state key can be set to Qt::NoButton, Qt::ControlButton, Qt::ShiftButton, Qt::AltButton, or a combination of these (use the bit '|' operator, see setMouseStateKey()).

Use setKeyFrameKey() to define the associated Key Frame key. See also setPlayKeyFramePathStateKey().

See the keyboard accelerator page for details.

void setAnimationPeriod int  msecs  )  [inline, slot]
 

Set the period (in milliseconds) between the calls to animate() and draw(). Default is 40 msecs (25 Hz). The frame rate (DISPLAY_FPS default binding is 'F') will be set accordingly, provided that your animate() and draw() functions are fast enough.

If you want to know the maximum possible frame rate of your machine on a given scene, set this value to 0, and startAnimation() (keyboard accelerator is Enter). The display will then be updated as often as possible, and the frame rate will be meaningful.

Note:
This value is taken into account only the next time you call startAnimation(). If animationIsStarted(), you should stopAnimation() first.

void setBackgroundColor const QColor &  c  )  [inline, slot]
 

Same as setBackgroundColor, but with a QColor attribute.

void setBackgroundColor float  r,
float  g,
float  b
[inline, slot]
 

Same as setBackgroundColor(), but with float parameters.

void setBackgroundColor const qglviewer::Vec color  )  [inline, slot]
 

Defines the background color of the viewer: backgroundColor() is modified and glClearColor(color.x, color.y, color.z, 1.0) is called. See also setForegroundColor() and the QGLWidget::qglColor() and QGLWidget::qglClearColor() documentations.

void setCamera qglviewer::Camera *const   c  )  [slot]
 

Associate a new qglviewer::Camera to the viewer.

You should only use this method when you derive a new class from Camera and want to use one of its instances instead of the original class.

It you simply want to save and restore Camera positions, use qglviewer::Camera::addKeyFrame() and qglviewer::Camera::playKeyFramePath() instead.

This method will silently ignore NULL c pointers. The calling method is responsible for deleting the previous camera pointer, if that is intended, in order to prevent memory leaks:

delete camera();
setCamera(myCamera);

All the c qglviewer::Camera::keyFrameInterpolator() qglviewer::KeyFrameInterpolator::interpolated() signals are connected to the viewer updateGL() slot. The connections with the previous viewer's camera are removed.

The sceneRadius() and sceneCenter() of the new c camera are set to the current QGLViewer values.

void setDisplayFPS bool  f = true  )  [inline, slot]
 

Set the state of fpsIsDisplayed(). displayFPS() is called or not. See also toggleDisplayFPS() and currentFPS().

void setDisplayZBuffer bool  f = true  )  [inline, slot]
 

Set the state of zBufferIsDisplayed(). displayZBuffer() is called or not. See also toggleDisplayZBuffer().

void setDrawAxis bool  f = true  )  [inline, slot]
 

Set the state of the axisIsDrawn(). World axis is drawn or not. See also toggleDrawAxis().

void setDrawGrid bool  f = true  )  [inline, slot]
 

Set the state of the gridIsDrawn(). A XY grid is drawn or not. See also toggleDrawGrid().

void setEnableText bool  f = true  )  [inline, slot]
 

Set the state of textIsEnabled() : drawText() and draw3DText() actually draw text or not (default is yes). See also toggleEnableText().

void setForegroundColor const QColor &  c  )  [inline, slot]
 

Same as setForegroundColor, but with a QColor attribute.

void setForegroundColor float  r,
float  g,
float  b
[inline, slot]
 

Same as setForegroundColor(), but with float parameters.

void setForegroundColor const qglviewer::Vec color  )  [inline, slot]
 

Defines the color that is used to draw viewer hints. See foregroundColor() for details. See also setBackgroundColor() and the QGLWidget::qglColor() and QGLWidget::qglClearColor() documentations.

void setFullScreen bool  fs = true  )  [slot]
 

Viewer is set in full screen mode (fs = true, default) or not (fs = false). Get current value with isFullScreen(). See also toggleFullScreen() and the STEREO keyboard accelerator (default is 'S', see the keyboard accelerator page).

void setKeyboardAccelerator KeyboardAction  action,
QKeySequence  key
 

Defines the keyboard accelerator sequence that triggers a given QGLViewer::KeyboardAction on the viewer.

If you want to define keyboard accelerators for custom actions (say, open a scene file), overload keyPressEvent() or define a new QAccel and then setKeyDescription().

Accelerators are provided as QKeySequence: a keyboard code and optional modifier keys (Control, Alt, Shift and Meta). QKeySequence can be expressed as QStrings (such as QString("Ctrl+X")) or as an int, using Qt predefined values (as in CTRL+Key_X). Up to four successive such accelerators can be appended to create a specific QKeySequence. See the QKeySequence documentation for details.

Set the QKeySequence to 0 to disable the accelerator. Only one accelerator can be assigned to a given QGLViewer::KeyboardAction. If two QGLViewer::KeyboardAction are binded to the same accelerator, none will work.

  // 'Q' exits the program. Default Escape accelerator is lost.
  setKeyboardAccelerator (EXIT, Key_Q);
  
  // Press Ctrl+Alt+F to toggle full screen display.
  setKeyboardAccelerator (FULL_SCREEN, CTRL+ALT+Key_F);
  
  // Press Ctrl+X and then Ctrl+S to save a screenshot.
  setKeyboardAccelerator (SAVE_SCREENSHOT, QString("Ctrl+X,CTRL+S"));
  
  // The toggleDisplayZBuffer() accelerator is disabled
  setKeyboardAccelerator (DISPLAY_Z_BUFFER, 0);

Note that unless it is used to differentiate two accelerators, the Shift modifier is not taken into account: if 'F' toggles frame rate display, so does Shift+F.

Use keyboardAccelerator() to retrieve the accelerator that is currently binded to a QGLViewer::KeyboardAction. See also setKeyFrameKey() and setMouseStateKey().

These accelerators are automatically included in the help() window Keyboard tab.

See the keyboard accelerator page for details and default values and the keyboardAndMouse example for a practical illustration.

void setKeyDescription QKeySequence  key,
QString  description
 

Sets a custom keyboard accelerator description, that will be displayed in the help() window Keyboard tab.

The key definition is given as a QKeySequence, which accepts int and strings as constructor parameters (see the QKeySequence documentation). Set an empty description to remove an accelerator description.

  // int accelerator using Qt constants
  setKeyDescription(Key_W, "Toggles wireframe display");
  setKeyDescription(CTRL+Key_L, "Loads a new scene");

  // accelerator expressed as QStrings
  setKeyDescription(QString("Ctrl+C"),        "Cut the selection parameters");
  setKeyDescription(QString("Ctrl+X,Ctrl+S"), "Save to file");

  // Remove a description
  setKeyDescription(CTRL+Key_C, "");

See the keyboardAndMouse example for illustration. See the keyboard page for more details.

The help() window Keyboard tab is generated by keyboardString(). It merges the descriptions given using this function with the standard keyboard accelerators. Standard accelerators are those binded to the QGLViewer::KeyboardAction actions (for instance, 'F' is associated with DISPLAY_FPS, which toggles frame rate display). These standard accelerators can be modified using setKeyboardAccelerator(), and keyboardString() will be modified accordingly. You cannot change their text description.

Attention:
If your keyboard accelerator is identical to one already binded to a QGLViewer::KeyboardAction, your accelerator will replace the previous one, which will be disabled using setKeyboardAccelerator(0). Consider modifying the conflicting QGLViewer::KeyboardAction using setKeyboardAccelerator() before calling this function in order to prevent such conflicts.

void setKeyFrameKey int  nb,
int  key
[virtual]
 

Defines the accelerator key associated with the camera Key Frame path of index nb. The number of available indexes is returned by qglviewer::Camera::nbPaths(). The default keys are F1..F12 for indexes 0..11.

Use setAddKeyFrameStateKey() and setPlayKeyFramePathStateKey() to define the state key that must be pressed with this key to add (or delete) or play the Key Frame.

To delete a Key Frame path, quickly press twice the keyFrameKey() while pressing the addKeyFrameStateKey(). Once a path has been delete, trying to re-play the path (using keyFrameKey() and playKeyFramePathStateKey()) will do nothing until new key frames are added (using keyFrameKey() and addKeyFrameStateKey()).

Use setKeyboardAccelerator() to define other keyboard accelerators.

See the keyboard accelerator page for details.

void setManipulatedFrame qglviewer::ManipulatedFrame fr  )  [slot]
 

The frame fr becomes the new manipulated frame. The manipulated frame will be moved with the mouse when the associated mouse bindings are used (default is when pressing the Control key with any mouse button). Use setMouseBinding() to define new bindings.

You can use a manipulated frame to move an object in the scene. Your code will look like this (see the manipulatedFrame example):

 void Viewer::init() { setManipulatedFrame(new ManipulatedFrame()); }

 void draw()
 {
  glPushMatrix(); // Save state
  glMultMatrixd(manipulatedFrame()->matrix());
  // Your object drawing code goes here
  glPopMatrix();  // Restore previous state
 }

Since a camera() position is defined with a ManipulatedCameraFrame, a Camera frame can be given as a manipulatedFrame(). This is useful for an application with several viewers, where the other viewers' cameras are displayed and can be manipulated (with a direct feedback in the other viewer). Use code like:

setManipulatedFrame( otherQGLViewer->camera()->frame() );
Defining the own viewer camera()->frame() as the manipulatedFrame() is possible and will result in a classical camera manipulation. See the Luxo example for an illustration.

The value of the currently manipulated frame is retrieved with manipulatedFrame().

void setMouseBinding int  buttonState,
ClickAction  action,
bool  doubleClick = false,
int  buttonBefore = Qt::NoButton
 

This function lets you associate any ClickAction to any Qt::ButtonState mouse button and state key combination.

The list of all possible ClickAction, some binding examples and default bindings are provided in the mouse page. See the keyboardAndMouse example for an illustration.

The parameters should read : when the buttonState mouse button(s) is (are) pressed (possibly with Alt, Control, Shift or any combination of these; possibly with a doubleClick), perform action.

If buttonBefore is specified (valid only when doubleClick is true), then these mouse buttons have to pressed before the double click occurs in order to perform action. For instance, with the default binding, pressing the right button, then double clicking on the left button will call RAP_FROM_PIXEL, which defines the new qglviewer::Camera::revolveAroundPoint() as the point under the mouse cursor (if any).

If no mouse button is specified in buttonState, the binding will be ignored.

To discard a specific action mouse binding, use code like:

  setMouseBinding(myButtonStateKeyCombo, NO_CLICK_ACTION);

See also setMouseBinding() and setWheelBinding().

void setMouseBinding int  buttonState,
MouseHandler  handler,
MouseAction  action,
bool  withConstraint = true
 

This function lets you associate any MouseAction to any Qt::ButtonState mouse button and state key combination. The receiver of the mouse events is a MouseHandler (CAMERA or FRAME).

The list of all possible MouseAction, some binding examples and default bindings are provided in the mouse page.

See the keyboardAndMouse example for an illustration.

The parameters should read : when the buttonState mouse button and state key are pressed, activate action on handler. If withConstraint is true (default), the constraint associated with the frame will be enforced.

If no mouse button is specified in buttonState, the binding will be ignored. If an action was previously associated with this buttonState, it is silently overwritten (use mouseAction() to know if the buttonState is already binded).

To discard a specific mouse binding, use code like:

  setMouseBinding(myButtonStateKeyCombo, myHandler, NO_MOUSE_ACTION);

See also setMouseBinding() and setWheelBinding().

void setMouseBindingDescription int  buttonState,
bool  doubleClick,
QString  description
 

Sets a custom mouse binding description, that will be displayed in the help() window mouse tab.

buttonState is a combination of modifier keys (Qt::ControlButton, Qt::AltButton, Qt::ShiftButton) with mouse buttons (Qt::LeftButton, Qt::MidButton and Qt::RightButton). These are combined using the "|" bit operator. doubleClick indicates whether or not the user has to double click this button. Set an empty description to remove a mouse binding description.

  // Left and Right button together simulate a middle button 
  setMouseBindingDescription(Qt::LeftButton | Qt::RightButton, false, "Emulates a middle button");

  // A left button double click toggles full screen
  setMouseBindingDescription(Qt::LeftButton, true, "Toggles full screen mode");

  // Remove the description of Ctrl+Right button
  setMouseBindingDescription(Qt::ControlButton | Qt::RightButton, false, "");

See the keyboardAndMouse example for an illustration. See the mouseMoveEvent() documentation for an example of custom mouse binding implementation. See the mouse page for more details.

Use setMouseBinding() and setWheelBinding() to change the standard mouse action bindings.

The help() window Mouse tab is generated by mouseString(). It merges the descriptions given using this function with the mouse bindings. Standard mouse bindings are those binded to the QGLViewer::ClickAction and QGLViewer::MouseAction. These standard mouse bindings can be modified using setMouseBinding() and setWheelBinding(). You cannot change their text description. Your description will overwrite any previous one with identical bindings.

void setMouseGrabber qglviewer::MouseGrabber mg  )  [slot]
 

Directly defines the QGLViewer's mouseGrabber(). You should not call this function directly as mouseMoveEvent() already does it using qglviewer::MouseGrabber::checkIfGrabsMouse().

void setMouseStateKey MouseHandler  mh,
int  buttonState
 

Associate a given state key (Alt, Shift, Control or a combinaison of these) to a specific MouseHandler. All the mouse handler's associated bindings will then need the specified buttonState key to be activated.

With this code,

  setMouseStateKey(QGLViewer::CAMERA, Qt::AltButton);
  setMouseStateKey(QGLViewer::FRAME,  Qt::NoButton);
you will have to press the Alt key while pressing mouse buttons in order to move the camera, while no key will be needed to move the associated manipulatedFrame().

This function is provided for convenience but its implementation is basic. Indeed, every action binded to mh has its state keys replaced by buttonState. If the MouseHandler had some actions binded to different state keys, this setting will be lost. You should consider using setMouseBinding() for finer tuning.

The default binding configuration binds Qt::ControlButton to all the QGLViewer::FRAME actions and Qt::NoButton to QGLViewer::CAMERA actions. This function hence easily allows you to change the MouseHandler associated key.

Attention:
This function calls setMouseBinding(), which ensures that only one action is binded to a given buttonState. If you want to swap the CAMERA and FRAME state keys, you have to use a temporary dummy buttonState (as when you are swapping two variables) or else the first call will overwrite the previous settings :
  // Associate FRAME with Alt (temporary value)
  setMouseStateKey(QGLViewer::FRAME, Qt::Alt);
  // Control is associated with CAMERA
  setMouseStateKey(QGLViewer::CAMERA, Qt::ControlButton);
  // And finally, FRAME can be associated with NoButton
  setMouseStateKey(QGLViewer::FRAME, Qt::NoButton);
If you had started with :
  setMouseStateKey(QGLViewer::FRAME, Qt::NoButton);
the FRAME bindings would have replaced all the previous CAMERA bindings (as CAMERA uses NoButton by default). A call to :
  setMouseStateKey(QGLViewer::CAMERA, Qt::ControlButton);
would then have done nothing as no more actions are binded to the CAMERA.

See the QGLViewer mouse page for details.

void setPlayKeyFramePathStateKey int  buttonState  )  [virtual]
 

Defines the accelerator state key (Qt::AltButton, Qt::ShiftButton, Qt::ControlButton) that must be pressed in conjunction with the keyFrameKey(i) to start playing the camera Key Frame path of index i. Default state key is Qt::NoButton.

The state key can be set to Qt::NoButton, Qt::ControlButton, Qt::ShiftButton, Qt::AltButton, or a combination of these (use the bit '|' operator, see setMouseStateKey()).

Use setKeyFrameKey() to define the associated Key Frame key. See also setAddKeyFrameStateKey().

See the keyboard accelerator page for details.

void setSceneBoundingBox const float  m[3],
const float  M[3]
[inline]
 

Same as setSceneBoundingBox(), with float[3] parameters.

void setSceneBoundingBox const qglviewer::Vec m,
const qglviewer::Vec M
[inline, slot]
 

Convenient way to call setSceneCenter() and setSceneRadius() from a Bounding Box of the scene. Equivalent to :

    setSceneCenter((m+M)/2.0);
    setSceneRadius(0.5*(M-m).norm());

void setSceneCenter float  x,
float  y,
float  z
[inline, slot]
 

float version of setSceneCenter().

void setSceneCenter const qglviewer::Vec sc  )  [inline, slot]
 

Set the center of the scene, defined in world coordinates. The entire scene should be include in a sphere of radius sceneRadius(), centered on sceneCenter(). Default value is (0,0,0), the world coordinate system origin.

This method should typically be called in the init() function, when the drawn scene is not centered on the world origin (so that sceneRadius(), qglviewer::Camera::zNear() and qglviewer::Camera::zFar() can be tightly fitted to the scene). It should normally not be modified after. See also setSceneBoundingBox().

The qglviewer::Camera::revolveAroundPoint() has a different meaning, and is probably the value you want to change while the program is running (see qglviewer::Camera::setRevolveAroundPoint()).

Attention:
The qglviewer::Camera::revolveAroundPoint() is set to the sceneCenter() value by this method.

void setSceneRadius float  r  )  [inline, slot]
 

Scene radius is used by the camera to scale axis and grid display, and to optimally set qglviewer::Camera::zNear() and qglviewer::Camera::zFar(). The entire scene must be included in a sphere centered on sceneCenter(), with radius sceneRadius(). Current value can be retrieved from sceneRadius().

You will typically use this function in QGLViewer::init() :

The default sceneRadius() is 1.0. See also setSceneCenter() and setSceneBoundingBox(). The camera() qglviewer::Camera::flySpeed() is set to 1% of this value by this function.

Attention:
If you want to retrieve z-buffer depth from the frame buffer (using glReadPixel(GL_DEPTH_COMPONENT)), you should provide tight bounds on the sceneRadius(). See also qglviewer::Camera::setZNearCoef(), qglviewer::Camera::zNear(), qglviewer::Camera::zFar().

void setSelectBufferSize int  size  ) 
 

Changes the selectBufferSize(). The previous selectBuffer() is deleted and a new one created.

void setSelectedName int  id  )  [inline]
 

Set the selectedName() value. Called by endSelection() during a selection.

void setSelectRegionSize int  size  )  [inline]
 

Changes the selectRegionSize(). Default value is 4 pixels.

void setShortcutKey KeyboardAction  action,
int  key,
int  state = -1
 

Deprecated function. Use setKeyboardAccelerator() instead. Should still work.

void setShortcutStateKey KeyboardAction  ,
int 
 

Deprecated function. Use setKeyboardAccelerator() instead. Does nothing.

void setSnapshotCounter const int  c  )  [inline, slot]
 

Defines the new snapshotCounter() value.

void setSnapshotFilename const QString &  n  )  [slot]
 

Sets the filename to use when saving snapshot with saveSnapshot(). If the filename is relative, the current working directory at the moment of the function call is added. snapshotFilename() returns the current snapshot file name.

void setSnapshotFormat const QString &  f  )  [inline, slot]
 

Defines the snapshot file format. This format will be used by saveSnapshot() in automatic mode. In non-automatic mode, this will be the default format of the saveAs dialog box.

The available formats are those handled by Qt. Classical values are "JPEG" (default snapshotFormat()), "PNG", "PPM, "BMP". Use the following code to get the actual list:

   QStringList formatList = QImage::outputFormatList();
   for (QStringList::Iterator it = formatList.begin(); it != formatList.end(); ++it)
     cout << (*it) << endl;

If the library was compiled with the EPSRender option, three additional vectorial formats are available: "EPS", "PS" and "XFIG".

Attention:
No verification is performed on the provided format validity. The next call to saveSnapshot() may fail if the format string is not supported by the Qt QImage class.

void setStereoDisplay bool  s = true  )  [slot]
 

Activates stereo mode (resp. switch back to mono when flag is false). Checks if the display system is able to handle stereovision using QGLWidget::format(). Should be called in init() or toggled with the STEREO keyboard accelerator (default key is 'S', see toggleStereoDisplay() and setKeyboardAccelerator()). Get current value from displaysInStereo().

The QGLViewer instance must be created with a stereo format to handle stereovision:

  QGLFormat format;
  format.setStereoDisplay( TRUE );
  QGLViewer viewer(format);
See the stereoViewer example.

The stereo parameters are defined by the camera(). See qglviewer::Camera::setIODist(), qglviewer::Camera::setDistanceToScreen(), qglviewer::Camera::setDistanceToZeroParallaxPlane() and qglviewer::Camera::setPhysicalScreenWidth().

void setVisualHintsMask int  mask,
int  delay = 2000
[virtual]
 

Defines the mask that will be used to drawVisualHints(). The only available mask is currently 1, corresponding to the display of the qglviewer::Camera::revolveAroundPoint(). resetVisualHints() is automatically called after delay milliseconds (default is 2 seconds).

void setWheelBinding int  stateKey,
MouseHandler  handler,
MouseAction  action,
bool  withConstraint = true
 

Associates a MouseAction to a mouse wheel event. The wheel event is received by handler. This function is very similar to setMouseBinding(), but specific to the wheel.

In the current implementation only MouseAction::ZOOM can be associated with FRAME, while CAMERA can receive MouseAction::ZOOM and MouseAction::MOVE_FORWARD.

See the mouse page for a list of all possible MouseAction, some binding examples and default bindings. See the keyboardAndMouse example for an illustration.

The difference between ZOOM and MOVE_FORWARD is that ZOOM speed depends on the distance to the object, while MOVE_FORWARD depends on qglviewer::ManipulatedCameraFrame::flySpeed().

virtual QString shortcutBindingsString  )  const [inline, virtual]
 

This function is deprecated, use keyboardString() instead.

Qt::Key shortcutKey KeyboardAction  action  )  const
 

Deprecated function. Use keyboardAccelerator() instead. Still works with simple QKeySequence.

Qt::ButtonState shortcutStateKey KeyboardAction  action  )  const
 

Deprecated function. Use keyboardAccelerator() instead. Still works with simple QKeySequence.

void showEntireScene  )  [inline, slot]
 

Set camera so that the entire scene is visible. This method should be called in init(), usually after setSceneRadius(), setSceneCenter() or qglviewer::Camera::setType().

This function simply calls qglviewer::Camera::showEntireScene(). It is called in the QGLViewer constructor, but with default scene parameters (sceneRadius() = 1.0, sceneCenter()=0,0,0 and qglviewer::Camera::type=PERSPECTIVE) that may not correspond to your scene. That is the reason why you should call it in init(), or use restoreFromFile() instead.

int snapshotCounter  )  const [inline]
 

The current value of the counter used to name snapshots in saveSnapshot() when automatic is true. Set using setSnapshotCounter(). Default value is 0, and it is incremented after each automatic snapshot. See saveSnapshot() for details.

const QString& snapshotFilename  )  const [inline]
 

Returns the current snapshot filename. Set by setSnapshotFilename(). Used in saveSnapshot().

const QString& snapshotFormat  )  const [inline]
 

Returns the current snapshot file format. Defined from the File Dialog window or with setSnapshotFormat(). Default value is "JPEG".

void startAnimation  )  [virtual, slot]
 

Start the animation loop. animate() and draw() will be called in a loop. The loop frequency is defined by animationPeriod() (default is 40 msecs=25Hz). See also stopAnimation() and animate().

See the animation example for illustration.

You may also be interested in qglviewer::KeyFrameInterpolator::startInterpolation().

void startScreenCoordinatesSystem bool  upward = false  )  const [virtual]
 

Use this function when you want to start drawing directly with the 2D screen coordinates system in your draw() function. Once this function has been called, the x, y coordinates correspond to the screen coordinates. The projection matrix is orthographic and glMatrixMode is set to GL_MODELVIEW.

The coordinates origin (0,0) is in the upper left corner of the window by default. This follows the Qt standards and make it easier to directly use QMouseEvent pos(). However, setting upward to true places the origin in the lower left corner, thus following the GL and mathematical standards. It is always possible to switch between the two representations using newY = height() - y.

Attention:
The select() function is sensitive to the orientation of the coordinates system (convertion between screen and GL coordinates). The upward coordinate system will not be compatible with the "classical" select() implementation (see the select example), and you should convert the y coordinate using newY = height() - y before calling select().
Use qglviewer::Camera::projectedCoordinatesOf() to compute the 2D projection on screen of a 3D point (results have an origin in the upper left corner). See the screenCoordSystem example for an illustration.

You may want to change gl state when drawing in 2D, such as for instance :

  startScreenCoordinatesSystem();

  // Disable lighting to enforce colors
  glDisable(GL_LIGHTING);

  // Enable blending to prevent aliassed lines
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  glEnable(GL_BLEND);
  glEnable(GL_LINE_SMOOTH);

  // And so on ...
  glDisable(GL_DEPTH_TEST);
  glLineWidth(1.0);

  // Your drawing code goes here

  // Restore (or not) previous gl state here
    
  stopScreenCoordinatesSystem();

You need to call stopScreenCoordinatesSystem() at the end of the drawing block to restore the previous camera matrix.

void stereoChanged bool  on  )  [signal]
 

This signal is emitted whenever displaysInStereo() changes value. This can be done with setStereoDisplay() or toggleStereoDisplay().

void stopAnimation  )  [virtual, slot]
 

Stop an animation started with startAnimation() or toggleAnimationMode().

void stopScreenCoordinatesSystem  )  const [virtual]
 

This function closes the screen coordinates drawing block that was started by startScreenCoordinatesSystem(). The GL_MODELVIEW and GL_PROJECTION matrices modified in startScreenCoordinatesSystem() are restored. glMatrixMode is set to GL_MODELVIEW.

Attention:
Calling this function when no startScreenCoordinatesSystem() was called will probably result in a crash.

void textEnabled bool  on  )  [signal]
 

This signal is emitted whenever textIsEnabled() changes value. This can be done with setEnableText() or toggleEnableText().

bool textIsEnabled  )  const [inline]
 

Returns true if drawText() and draw3DText() actually display text. Set by setEnableText() or toggleEnableText(). Convenient to remove all the possibly displayed text with a single key.

void timerEvent QTimerEvent *   )  [protected, virtual]
 

Overloading of the timer function. If animationIsStarted(), calls animate() and then draw(), at a frequency set by setAnimationPeriod().

void toggleAnimationMode  )  [inline, slot]
 

Calls startAnimation() or stopAnimation(), depending on animationIsStarted().

void toggleCameraMode  )  [virtual, slot]
 

Swaps between two predefined camera mouse bindings. This function is provided for backward compatibility since version 1.3.4. It simply defines preset mouse bindings as could be done using setMouseBinding().

The first mode makes the camera observe the scene while revolving around the qglviewer::Camera::revolveAroundPoint(). The second mode is designed for walkthrough applications and simulates a flying camera.

Practically, the three mouse buttons are respectly binded to :

  • In revolve mode : ROTATE, ZOOM, TRANSLATE.
  • In fly mode : MOVE_FORWARD, LOOK_AROUND, MOVE_BACKWARD.
The current mode is determined by checking if a mouse button is binded to ROTATE for the CAMERA (using mouseButtonState()). The state key that was previously used to move the camera is preserved.

The CAMERA_MODE keyboardAccelerator() calls this function (default is 'Space').

void toggleCameraPathEditor  )  [inline, slot]
 

Start/stop the edition of the camera paths (default EDIT_CAMERA_PATHS keyboard accelerator is 'C'). See cameraPathIsEdited(). See also editCameraPath().

void toggleDisplayFPS  )  [inline, slot]
 

Toggle the state of fpsIsDisplayed(). displayFPS() is called or not (default DISPLAY_FPS keyboard accelerator is 'F'). See also setDisplayFPS() and currentFPS().

void toggleDisplayZBuffer  )  [inline, slot]
 

Toggle the state of zBufferIsDisplayed(). displayZBuffer() is called or not (default DISPLAY_Z_BUFFER keyboard accelerator is 'Z'). See also setDisplayZBuffer().

void toggleDrawAxis  )  [inline, slot]
 

Toggle the state of axisIsDrawn(). A world axis is drawn or not (default DRAW_AXIS keyboard accelerator is 'A'). See also setDrawAxis().

void toggleDrawGrid  )  [inline, slot]
 

Toggle the state of gridIsDrawn() flag. A XY grid is drawn or not (default DRAW_GRID keyboard accelerator is 'G'). See also setDrawGrid().

void toggleEnableText  )  [inline, slot]
 

Toggle the state of textIsEnabled() : drawText() and draw3DText() actually draw text or not (default is yes) (default ENABLE_TEXT keyboard accelerator is '?'). See also setEnableText().

void toggleFullScreen  )  [slot]
 

Viewer is toggled between normal and full screen mode (FULL_SCREEN keyboard accelerator, default is Alt-Enter, see the keyboard accelerator page). See setFullScreen() and isFullScreen().

void toggleStereoDisplay  )  [inline, slot]
 

Toggle the state of displaysInStereo() (default STEREO keyboard accelerator is 'S'). See setStereoDisplay() for details.

See the stereoViewer example for an illustration.

void updateGLForAllViewers  )  [static]
 

updateGL() is called on all the created QGLViewers. All the viewers will have their display updated.

See also QGLViewerPool(). Use connectSignalToAllViewers() and disconnectSignalToAllViewers() for more complex connections.

void viewerInitialized  )  [signal]
 

Signal emitted by the default QGLViewer::init() function. Connect this signal to the functions that need to be called before any drawing (if any), to initialize your viewer.

Use this signal-slot mechanism ONLY IF you don't inherit your viewer from QGLViewer (in that case, simply overload the init() function).

QGLViewer::MouseAction wheelAction int  buttonState  )  const
 

Same as mouseAction(), but for the wheel action.

int wheelButtonState MouseHandler  mh,
MouseAction  ma,
bool  withConstraint = true
const
 

Same as mouseButtonState(), but for the wheel.

Attention:
Returns -1 when no Qt::ButtonState was associated with this handler/action/withConstraint value. mouseButtonState() returns Qt::NoButton is that case as it is an impossible value.

void wheelEvent QWheelEvent *  e  )  [protected, virtual]
 

The wheel associated event is controled using setWheelBinding(). Default behavior simulates a ZOOM action. See the QGLViewer mouse page and setWheelBinding() for details.

Depending on your system configuration, you may have to actually press the wheel while wheeling.

int wheelHandler int  buttonState  )  const
 

Same as mouseHandler but for the wheel action.

void zBufferDisplayed bool  on  )  [signal]
 

This signal is emitted whenever zBufferIsDisplayed() changes value. This can be done with setDisplayZBuffer() or toggleDisplayZBuffer().

bool zBufferIsDisplayed  )  const [inline]
 

Returns true if displayZBuffer() is called by the viewer. Set by setDisplayZBuffer() or toggleDisplayZBuffer().


Generated on Mon Jun 14 10:10:15 2004 for libQGLViewer by doxygen 1.3.4