Main Page   Class Hierarchy   Compound List   All functions   Search  

QGLViewer Class Reference

An OpenGL viewer based on QGLWidget. More...

List of all members.

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 setForegroundColor (float r, float g, float b)

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 aspectRatio () const
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

bool isFullScreen () const
bool displaysInStereo () const
void setFullScreen (bool f=true)
void toggleFullScreen ()
void setStereoDisplay (bool f=true)
void toggleStereoDisplay ()

Display functions

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

Mouse grabber

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

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 (int msecs=-1)
virtual void stopAnimation ()
void toggleAnimationMode ()
virtual void animate ()

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 (const int mask)
virtual void drawVisualHints ()
virtual void resetVisualHints ()

Static methods for all the viewers

All the created QGLViewers are stored in a QGLViewerPool(). These methods allow you to use this pool.

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 ()

Key customization

enum  ShortcutAction {
  DRAW_AXIS, DRAW_GRID, DISPLAY_FPS, DISPLAY_Z_BUFFER, ENABLE_TEXT, EXIT,
  SAVE_SCREENSHOT, CAMERA_MODE, FULL_SCREEN, STEREO, ANIMATION, HELP,
  EDIT_CAMERA_PATHS
}
enum  MouseBehavior { CAMERA, FRAME }
virtual void setShortcutKey (ShortcutAction action, int key, int stateKey=-1)
virtual void setShortcutStateKey (ShortcutAction action, ushort skey)
Qt::Key shortcutKey (const ShortcutAction action) const
Qt::ButtonState shortcutStateKey (ShortcutAction action) const
virtual void setKeyFrameKey (int nb, int key)
virtual void setAddKeyFrameStateKey (ushort skey)
virtual void setPlayKeyFramePathStateKey (ushort skey)
Qt::Key keyFrameKey (int nb)
Qt::ButtonState addKeyFrameStateKey ()
Qt::ButtonState playKeyFramePathStateKey ()
virtual void setMouseStateKey (MouseBehavior behavior, ushort skey)
Qt::ButtonState mouseStateKey (MouseBehavior behavior) const

Mouse and keyboard 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 keyPressEvent (QKeyEvent *)

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 fullScreenChanged (bool on)
void stereoChanged (bool on)

Public Methods

 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 ()
virtual QString helpString () const
virtual void help ()

Protected Types


Protected Methods

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 ()
QWidget * rootWidget () const


Detailed Description

An OpenGL viewer based on QGLWidget.

A QGLViewer is a 3D OpenGL based on the Qt's QGLWidget. It includes many classical viewer functionalities, such as a camera trackball, 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 order 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.

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 MouseBehavior [protected]
 

Defines the different mouse behavior modes : Camera or Frame motion. Use mouseStateKey() and setMouseStateKey() to select which key must be pressed to enable each one. See the mouse page for details.

Enumeration values:
CAMERA 
FRAME 

enum ShortcutAction [protected]
 

Defines the different actions that can directly be associated with a keyboard shortcut. Used by setShortcutKey(), setShortcutStateKey(), shortcutKey() and shortcutStateKey().

See the QGLViewer shortcuts page for details.

Enumeration values:
DRAW_AXIS 
DRAW_GRID 
DISPLAY_FPS 
DISPLAY_Z_BUFFER 
ENABLE_TEXT 
EXIT 
SAVE_SCREENSHOT 
CAMERA_MODE 
FULL_SCREEN 
STEREO 
ANIMATION 
HELP 
EDIT_CAMERA_PATHS 


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   [protected]
 

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 QGLViewer shortcuts page for details.

virtual void animate   [inline, protected, virtual]
 

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

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.

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 shortcut key 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.

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 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 25 frames, and hence will only change every 25 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().

virtual void displayFPS   const [inline, protected, virtual]
 

Display the frame rate in the lower left corner. The frame rate is computed as an average and updateGL() must be called in a loop in order to have a meaningful value (this is the case when animationIsStarted()). The FPS display can be toggled with toggleDisplayFPS() or with setDisplayFPS(). See also 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().

void draw   [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, the default behavior of this function is to emit the drawNeeded() signal, which can be connected to your draw function. See the callback example for details.

Attention:
The GL_PROJECTION matrix must not be changed 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 can be changed 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 &    string,
GLfloat    height = 0.1f
const [protected]
 

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

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.

height is the text height, expressed in openGL scene units (measured when the text is in the screen plane).

See the draw3DText example for an illustration.

void drawAxis float    size = 1.0f
 

Displays an XYZ axis, with a given size (default is 1.0). The axis position and orientation only depends on the current modelview matrix state. This code will display a translated and rotated axis (with respect to the world coordinates system, that can be displayed using the DRAW_AXIS shortcut key. Default key is 'A').

  glPushMatrix();
  glTranslatef(x,y,z);
  glRotatef(90.,0.,1.,0.);
  drawAxis(0.2);
  glPopMatrix();
  
Use the following code to display the current position and orientation of a qglviewer::Frame :
  glPushMatrix();
  glMultMatrixd(frame.matrix());
  drawAxis(0.2);
  glPopMatrix();
  

Note:
The current matrix mode should be GL_MODELVIEW.

void drawGrid   [inline]
 

Displays a XY grid. 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 GLfloat    x,
GLfloat    y,
const char *    text,
GLfloat    height = 15.0f
const [protected]
 

Draws a text at position x, y (in pixels), with a given scale (in pixels). Can be called in draw() to easily display some information on the screen.

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

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(screenPos[0], screenPos[1], "My Object");
  
See the screenCoordSystem example for an illustration.

Text is displayed using the GLUT glutStrokeCharacter() function. The GL_MODELVIEW and GL_PROJECTION matrices are not modified by this function.

The (0,0) coordinates is the lower left corner of the window. See startScreenCoordinatesSystem() for details.

See also the draw3DText() function.

Note:
Each call to drawText() changes the camera projection matrix and restores it back (using startScreenCoordinatesSystem() and stopScreenCoordinatesSystem()). 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).

void drawVisualHints   [virtual]
 

Draws viewer related visual hints.

Displays the new qglviewer::Camera::revolveAroundPoint() when it is changed with a double simple click. 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.

void editCameraPath bool    edit = true [inline, slot]
 

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

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 fullScreenChanged bool    on [signal]
 

This signal is emitted whenever isFullScreen() changes value. This can be done with setFullScreen() or toggleFullScreen().

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

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

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]
 

This function is called when the user presses the HELP_KEY (default is H). It should display a brief help or start a more complex help browser.

The default behavior displays helpString() in a Qt::QMessageBox(), where rich text (HTML-like) can be used.

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).

QString helpString   const [virtual]
 

helpString() is displayed by the help() function when the HELP_KEY (default is H) is pressed. Overload this function to define your own help string.

The default behavior is to display a short description of the current key and mouse bindings. You can add your own shortcuts description with this kind of code:

QString text = QGLViewer::helpString();
text += "<b>C</b> sets the foo to zero<br>";
text += "<b>O</b> changes default output<br>";
return text;

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 standard. Actually, the following flags are defined :
glEnable(GL_LIGHTING);

glEnable(GL_LIGHT0);

glEnable(GL_DEPTH_TEST);

glEnable(GL_COLOR_MATERIAL);

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, call QGLViewer::initializeGL() at the beginning of your new initializeGL() function.

bool isFullScreen   const [inline]
 

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

Qt::Key keyFrameKey int    nb [protected]
 

Returns the camera Key Frame path shortcut key 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 QGLViewer shortcuts page for details.

void keyPressEvent QKeyEvent *    e [protected, virtual]
 

Key pressed callback function. Some default key bindings are implemented and can easily be redefined using setShortcutKey() and setShortcutStateKey(). See the QGLViewer shortcuts page for details and default values.

Overload this function to implement a specific shortcut key 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::MouseButtonMask);
  if (state==Qt::AltButton)
    switch (e->key())
    {
      ...
    }
  else
    ...
  

qglviewer::ManipulatedFrame* manipulatedFrame   const [inline]
 

Returns the current manipulated frame, which can be moved with the mouse. One needs to press the mouseStateKey(FRAME) (default is Control) in order to move the manipulatedFrame(). Returns NULL when no frame has been associated with the viewer (with setManipulatedFrame()). See the manipulatedFrame example for an illustration.

void mouseDoubleClickEvent QMouseEvent *    e [protected, virtual]
 

When the user double clicks on the mouse:

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.

void mouseMoveEvent QMouseEvent *    e [protected, virtual]
 

Maintaining a button pressed while moving the mouse updates the camera or the manipulated frame. See mousePressEvent() for a description of the different possible actions.

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

 void Viewer::mousePressEvent(QMouseEvent* e)
 {
   if ((e->state() & ~Qt::MouseButtonMask) == (Your personal 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.

Use setMouseStateKey() if you simply want to change the state key associated with the standard QGLViewer behavior. See also setShortcutKey() and setShortcutStateKey().

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().

See the mouseMoveEvent() documentation for an example of mouse behavior customization. Use the Qt::MouseButtonMask to separate the Control/Alt/Shift state key from the mouse (left/middle/right) buttons.

if ((e->state() & ~Qt::MouseButtonMask) == MY_COMBINATION_OF_Qt::ButtonState)  // (Qt::ShiftButton/Qt::ControlButton/Qt::AltButton)
  myBehaviorPressEvent(e);
else
  QGLViewer::mousePressEvent(e);

void mouseReleaseEvent QMouseEvent *    e [protected, virtual]
 

When the user releases the mouse button, the camera action is stopped. If the action was a rotation (REVOLVE qglviewer::Camera::mode() only), a continuous spinning is possible if the speed of the cursor is large enough when the button is released. Press the rotate button again to stop the spinning.

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

Qt::ButtonState mouseStateKey MouseBehavior    behavior const [protected]
 

Returns the value of the key that should be pressed when clicking the mouse to select between the two mouse behaviors. The different mouse behaviors are represented in the MouseBehavior enum. The default values are Qt::NoButton for the Camera motion and Qt::ControlButton for the Frame displacement.

The state key can be Qt::NoButton, Qt::ControlButton, Qt::ShiftButton, Qt::AltButton or a bitwise combination (using |) of these (such as Qt::ControlButton | Qt::ShiftButton). This value can be modified with setMouseStateKey() to tune the behavior of the viewer.

See the QGLViewer mouse page for details.

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   [protected]
 

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 QGLViewer shortcuts page for 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.

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();

void preDrawStereo bool    leftBuffer = true [protected, virtual]
 

Called before draw. Default behavior clear screen and pops camera model view matrix.

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.

Return -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(), updateGLForAllViewers() and saveToFileForAllViewers(). 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.

This function should be called at the end (so that your manipulatedFrame(), if defined, can also be initialized) in your init() function to restore the previous session parameters :

  void Viewer::init()
  {
    // Other init code goes here.
    restoreFromFile();
  }
  

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

QWidget * rootWidget   const [protected]
 

Recursively call QWidget::parentWidget() until the root widget is found.

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, fig). 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);
  }
  
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). See also saveToFileForAllViewers().

void saveToFileForAllViewers   [static]
 

Calls saveToFile() for all the created QGLViewers. Called when you press the EXIT shortcut key (default is Escape, use setShortcutKey() to define a new key).

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 setAddKeyFrameStateKey ushort    skey [protected, virtual]
 

Defines the shortcut 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 QGLViewer shortcuts page for details.

void setAnimationPeriod int    msecs [inline, slot]
 

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

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);

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 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    f = true [slot]
 

Viewer is set in full screen mode (true, default) or not (false). Get current value from isFullScreen(). See also toggleFullScreen() and the STEREO shortcut key (default is 'S').

void setKeyFrameKey int    nb,
int    key
[protected, virtual]
 

Defines the shortcut 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 setShortcutKey() to define other shortcut keys.

See the QGLViewer shortcuts 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 mouseStateKey() is pressed (default is Control, use setMouseStateKey() with (QGLViewer::FRAME, Qt::xxxButton) as arguments to define a new key).

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()
  {
    ManipulatedFrame* myFrame = new ManipulatedFrame();
    setManipulatedFrame(myFrame);
  }

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

Note that the camera can also be manipulated, just like a regular frame. Simply use:

  setManipulatedFrame( &(camera()->frame) );
  
However, the camera can always directly be moved by pressing a special state key (see mouseStateKey(CAMERA)) can be used to specifically move the camera (default value is Qt::NoButton).

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

void setMouseGrabber qglviewer::MouseGrabber   cr [inline, 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 MouseBehavior    behavior,
ushort    skey
[protected, virtual]
 

Defines which key should be pressed when clicking the mouse to select one of the two mouse behaviors. The different mouse behaviors are represented in the MouseBehavior enum. The default values are Qt::NoButton for the Camera motion and Qt::ControlButton for the manipulated Frame.

The state key can be set to Qt::NoButton, Qt::ControlButton, Qt::ShiftButton, Qt::AltButton or any bitwise ored (using "|") combination of these (such as Qt::ControlButton | Qt::ShiftButton). Use mouseStateKey() to get the current values. Set to 0 to forbid a given mouse behavior.

This example shows how to swap the camera and frame state keys:

  setMouseStateKey(QGLViewer::FRAME,  Qt::NoButton);
  setMouseStateKey(QGLViewer::CAMERA, Qt::ControlButton);
  

With the following code, you will have to press the Alt and the Control key in order to move the camera:

  setMouseStateKey(QGLViewer::CAMERA, Qt::AltButton|Qt::ControlButton);
  

If you want to move the camera with the Alt or the Control key, you need to overload the mousePressEvent() function:

  if (((e->state() & ~Qt::MouseButtonMask) == Qt::AltButton) ||
  ((e->state() & ~Qt::MouseButtonMask) == Qt::ControlButton))
  camera()->frame()->mousePressEvent(e);
  else
  QGLViewer::mousePressEvent(e);
  

See the QGLViewer mouse page for details.

void setPlayKeyFramePathStateKey ushort    skey [protected, virtual]
 

Defines the shortcut 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 QGLViewer shortcuts 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.

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().

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 setShortcutKey ShortcutAction    action,
int    key,
int    stateKey = -1
[protected, virtual]
 

Defines the shortcut key (and optionnally the state key) associated with a given action of the viewer. All the possible action are defined by the QGLViewer::ShortcutAction enum.

key is defined by the Qt::Key enum and is of the form Qt::Key_X (see the Qt documentation). Set the key to 0 to forbid the action shortcut. stateKey (optional) defines the state key (Alt, Control, ...) associated with this action, just like setShortcutStateKey().

Use setShortcutStateKey() to define a shortcut state key and shortcutKey() to get the current value. See also setKeyFrameKey() and setMouseStateKey().

For example, this code defines Alt-M as the new qglviewer::Camera::toggleMode() shortcut, and Q is the new EXIT shortcut key (state key unchanged):

  setShortcutKey (QGLViewer::CAMERA_MODE, Qt::Key_M, Qt::AltButton);
  setShortcutKey (QGLViewer::EXIT, Qt::Key_Q);
  setShortcutKey (QGLViewer::DISPLAY_Z_BUFFER, 0);
  

See the QGLViewer shortcuts page for details and default values.

void setShortcutStateKey ShortcutAction    action,
ushort    skey
[protected, virtual]
 

Defines the shortcut state key (Qt::AltButton, Qt::ShiftButton, Qt::ControlButton) that should be pressed while pressing a given action shortcutKey(). All the possible actions are defined by the ShortcutAction enum.

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()).

For example, this code defines Alt-M as the new qglviewer::Camera::toggleMode() shortcut:

  setShortcutKey     (QGLViewer::CAMERA_MODE, Qt::Key_M);
  setShortcutStateKey(QGLViewer::CAMERA_MODE, Qt::AltButton);
  

Use setShortcutKey() to define the shortcut key and shortcutStateKey() to get the current value. See also setKeyFrameKey(), setAddKeyFrameStateKey(), setPlayKeyFramePathStateKey() and setMouseStateKey().

See the QGLViewer shortcuts page for details and default values.

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    f = 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 shortcut key (default key is 'S', see toggleStereoDisplay()). 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.

void setVisualHintsMask const int    mask [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 2 seconds.

Qt::Key shortcutKey const ShortcutAction    action const [protected]
 

Returns the current shortcut value as defined with setShortcutKey(). action is defined by the QGLViewer::ShortcutAction enum.

See the QGLViewer shortcuts page for details and default values.

Qt::ButtonState shortcutStateKey ShortcutAction    action const [protected]
 

Returns the current shortcut state value as defined with setShortcutKey(). action is defined by the QGLViewer::ShortcutAction enum.

See the QGLViewer shortcuts page for details and default values.

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 int    msecs = -1 [virtual, slot]
 

Start the animation loop. animate() and draw() will be called in a loop.

If msecs is negative (default with no parameter), the loop frequency is the one defined by setAnimationPeriod() (default is 25Hz). Otherwise animationPeriod() is set to msecs (in milliseconds). See stopAnimation() and animate().

See the animation example for illustration.

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

void startScreenCoordinatesSystem   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 lower left corner in (0,0) and the upper right corner at (QWidget::width(), QWidget::height()). The projection matrix is set to ORTHO, GL_LIGHTING is disabled and anti-aliasing is activated (GL_BLEND and GL_LINE_SMOOTH). glMatrixMode is set to GL_MODELVIEW.

Use qglviewer::Camera::projectedCoordinatesOf() to computed the 2D projection on screen of a 3D point. See the screenCoordSystem example for an illustration.

You need to call stopScreenCoordinatesSystem() at the end of the drawing block to restore the previous camera matrix. This function is called by drawText().

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 attributes that may have been changed 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. Calls animate() (if animationIsStarted()) and then draw(), at a frequency set by setAnimationPeriod().

void toggleAnimationMode   [inline, slot]
 

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

void toggleCameraPathEditor   [inline, slot]
 

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

void toggleDisplayFPS   [inline, slot]
 

Toggle the state of fpsIsDisplayed(). displayFPS() is called or not (default DISPLAY_FPS shortcut key 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 shortcut key is 'Z'). See also setDisplayZBuffer().

void toggleDrawAxis   [inline, slot]
 

Toggle the state of axisIsDrawn(). A world axis is drawn or not (default DRAW_AXIS shortcut key 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 shortcut key 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 shortcut key is '?'). See also setEnableText().

void toggleFullScreen   [slot]
 

Viewer is toggled between normal and full screen mode (FULL_SCREEN shortcut key, default is Alt-Enter). See setFullScreen() and isFullScreen().

void toggleStereoDisplay   [inline, slot]
 

Toggle the state of displaysInStereo() (default STEREO shortcut key is 'S'). See also setStereoDisplay().

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 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).

void wheelEvent QWheelEvent *    e [protected, virtual]
 

Using the wheel is equivalent to using the mouse middle button (a Zoom/Walk motion). See mousePressEvent() for details. Depending on your system configuration, you may have to actually press the wheel while wheeling.

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 Fri Jun 27 18:34:03 2003 for libQGLViewer by doxygen1.3-rc2