Main Page   Class Hierarchy   Compound List   Compound Members  

qglviewer::KeyFrameInterpolator Class Reference

A key frame interpolator. More...

List of all members.

Public Slots

virtual void update ()

Public Methods

 KeyFrameInterpolator (qglviewer::Frame *fr=NULL)
virtual ~KeyFrameInterpolator ()
virtual QDomElement domElement (const QString &name, QDomDocument &doc) const
virtual void initFromDOMElement (const QDomElement &de)
virtual void drawPath (const int mask=1, int nbFrames=6, const float scale=1.0)
Key Frames
void setFrame (qglviewer::Frame *fr)
qglviewer::Frameframe () const
void addKeyFrame (const qglviewer::Frame &fr)
void addKeyFrame (const qglviewer::Frame &fr, const float time)
void addKeyFrame (const qglviewer::Frame *fr)
void addKeyFrame (const qglviewer::Frame *fr, const float time)
void deletePath ()
int numberOfKeyFrames () const
qglviewer::Vec keyFramePosition (const int i) const
qglviewer::Quaternion keyFrameOrientation (const int i) const
float keyFrameTime (const int i) const
Interpolation parameters
float interpolationTime () const
void setInterpolationTime (const float time)
float interpolationSpeed () const
void setInterpolationSpeed (const float speed)
int interpolationPeriod () const
void setInterpolationPeriod (const int msecs)
bool loopInterpolation () const
void setLoopInterpolation (const bool loop=true)
bool closedPath () const
void setClosedPath (const bool closed=true)
Interpolation
virtual void interpolateAtTime (const float time)
void startInterpolation (const int msecs=-1)
void stopInterpolation ()
void resetInterpolation ()
bool interpolationIsStarted () const
void toggleInterpolation ()


Detailed Description

A key frame interpolator.

KeyFrameInterpolator implements a classical interpolation of key Frames, using a smooth Catmull-Rom based interpolation.

Use addKeyFrame() to define the keyframes and then call startInterpolation(). The Frame associated with the interpolator (using the constructor or with setFrame()) will then be updated over time.

The interpolation can loop (setLoopInterpolation()) and the keyFrame path can be closed (setClosedPath()). The current interpolation time (interpolationTime()) and speed (interpolationSpeed()) can also be tuned.

The keyFrames are defined by a Frame and a time, expressed in seconds. The time has to be monotonously increasing over keyFrames.

See the keyFrames example for an illustration of the class.


Constructor & Destructor Documentation

KeyFrameInterpolator qglviewer::Frame   fr = NULL
 

Creates a KeyFrameInterpolator, which will drive the fr frame.

Use addKeyFrame() to define the key frames. Default interpolationTime() is 0.0, and interpolationSpeed() is 1.0.

virtual ~KeyFrameInterpolator   [inline, virtual]
 

Virtual destructor. Empty.


Member Function Documentation

void addKeyFrame const qglviewer::Frame   fr,
const float    time
 

Same as the reference version of addKeyFrame(), but with a pointer to a frame. NULL pointers are silently ignored.

void addKeyFrame const qglviewer::Frame   fr
 

Same as the reference version of addKeyFrame(), but with a pointer to a frame. NULL pointers are silently ignored.

void addKeyFrame const qglviewer::Frame   fr,
const float    time
 

Defines a new keyFrame, and the associated time (in seconds) that will be used to rythm the interpolation. The keyFrameTime() have to be monotonously increasing over keyFrames.

void addKeyFrame const qglviewer::Frame   fr
 

Defines a new keyFrame. Same as addKeyFrame() with a keyFrameTime() specification, except that the time is automatically set as previous keyFrameTime() + 1 second.

bool closedPath   const [inline]
 

Whether or not (default) the path defined by the keyFrames is a closed loop. When true, the last and the first KeyFrame are linked by a new spline segment.

Use setLoopInterpolation() to create a continuous animation over the entire path.

void deletePath  
 

Remove all keyFrames from the path. The numberOfKeyFrames() is set to 0.

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

Creates an XML QDomElement that represents the KeyFrameInterpolator. 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 KeyFrameInterpolator state from the resulting domElement.

See also Camera::domElement(), Frame::domElement()...

If you want to save the KeyFrameInterpolator in a file, use

QDomDocument doc("myKFI");
 doc.appendChild(domElement("KFI", doc)); ofstream file("myKFI.xml"); file << doc.toString();
Note that the Camera::keyFrameInterpolator() are automatically saved by QGLViewer::saveToFile() when a viewer is deleted.

Use the following code to retrieve the KeyFrameInterpolator from the saved file:

 // Load DOM from file
 QDomDocument doc;
 QFile f("myKFI.xml");
 f.open(IO_ReadOnly);
 doc.setContent(&f);
 f.close();
 // Parse the DOM tree
 QDomElement main=doc.documentElement();
 myKFI.initFromDOMElement(main);

Attention:
For KeyFrames defined by pointers, only the values of the pointed Frame are saved. See Frame::domElement().
Only the KeyFrames are saved, you still need to define the attached frame() with setFrame().

void drawPath const int    mask = 1,
int    nbFrames = 6,
const float    scale = 1.0
[virtual]
 

Draws the path that will be used to interpolate the frame().

mask controls what is drawn on the path : if (mask & 1) (default), the position path is drawed. If (mask & 2), a camera representation is regularly drawn and if (mask & 4), an oriented axis is regularly drawn.

/code drawPath(); // Simply draws the interpolation path drawPath(3); // Draws path and cameras drawPath(7); // Draws path, cameras and axis drawPath(5); // Draws path and axis /endcode

When camera or axis is drawn, nbFrames controls the number of objects (axis or camera) drawn between two successive keyFrames. When nbFrames=1, only the path Key Frames are drawn. nbFrames=2 also draws the intermediate orientation, etc. The maximum value is 30. nbFrames should divide 30 so that an object is drawn for each Key Frame. Default value is 6.

scale (default=1.0) controls the scaling of the camera and axis drawing. A value of QGLViewer::sceneRadius() usually gives good results.

qglviewer::Frame* frame   const [inline]
 

The frame that is associated and modified by the KeyFrameInterpolator. Set using setFrame() or with the KeyFrameInterpolator() constructor.

void initFromDOMElement const QDomElement &    de [virtual]
 

Restore the KeyFrameInterpolator state from a QDomElement created by domElement(). See also Camera::initFromDOMElement(), Frame::initFromDOMElement().

Attention:
For KeyFrames defined by pointers, only the values of the pointed Frame are saved.
Only the KeyFrames are saved, you still need to define the attached frame() with setFrame().

void interpolateAtTime const float    time [virtual]
 

Interpolate frame() for time time. interpolationTime() is set to time and frame() is set accordingly.

If you simply want to change interpolationTime() but not the frame(), use setInterpolationTime() instead.

All the currently created QGLViewers have their display updated (see QGLViewer::updateGLForAllViewers()).

bool interpolationIsStarted   const [inline]
 

Returns true when the interpolation is being processed (after a call to startInterpolation()). Set to false by stopInterpolation(). See also toggleInterpolation().

int interpolationPeriod   const [inline]
 

Returns the current interpolation period, expressed in milliseconds. This period will be added to the interpolationTime() at each update(), when interpolationIsStarted() is true.

float interpolationSpeed   const [inline]
 

Returns the current interpolation speed. Default value is 1.0, which means that the times associated with the keyFrames (see keyFrameTime() and addKeyFrame()), expressed in seconds, will be respected during the interpolation (see startInterpolation()), provided that your display is fast enough.

A negative value will result in a reverse interpolation of the keyFrames.

float interpolationTime   const [inline]
 

Current interpolation time, updated when interpolationIsStarted() is true. Can be set directly with setInterpolationTime() or interpolateAtTime().

Quaternion keyFrameOrientation const int    i const
 

Returns the keyFrame orientation of keyFrame number i. No index verification is performed. See also keyFramePosition(), keyFrameTime() and numberOfKeyFrames().

Vec keyFramePosition const int    i const
 

Returns the keyFrame position of keyFrame number i. No index verification is performed. See also keyFrameOrientation(), keyFrameTime() and numberOfKeyFrames().

float keyFrameTime const int    i const [inline]
 

Returns the time associated with the keyframe number i. See also keyFramePosition(), keyFrameOrientation() and addKeyFrame().

bool loopInterpolation   const [inline]
 

Whether or not (default) the interpolation will be played in (infinite) loop when startInterpolation() is called (until stopInterpolation() is called). When false, the interpolation will stop when interpolationTime() reaches the last keyFrames associated time (see keyFrameTime()).

Use setClosedPath() to create a closed path with the keyFrames.

int numberOfKeyFrames   const [inline]
 

Number of keyFrames used in the interpolation. Use addKeyFrame() to add new keyFrames.

void resetInterpolation  
 

interpolationTime() is reset to the keyFrameTime() associated with the first keyFrame and interpolation is stopped() (not much than setInterpolationTime() and stopInterpolation()).

void setClosedPath const bool    closed = true [inline]
 

Set the closedPath() value.

void setFrame qglviewer::Frame   fr [inline]
 

Set the frame that will be associated with the KeyFrameInterpolator. Current frame is in frame().

void setInterpolationPeriod const int    msecs [inline]
 

Set the interpolationPeriod().

void setInterpolationSpeed const float    speed [inline]
 

Set the interpolation speed. Negative values are possible. See interpolationSpeed().

void setInterpolationTime const float    time [inline]
 

Set the current interpolation time. See also interpolationTime().

Attention:
The frame() is not affected by this method. Use this function to define the starting time of a future interpolation (see startInterpolation()). Use interpolateAtTime() to actually interpolate at a given time.

void setLoopInterpolation const bool    loop = true [inline]
 

Set the loopInterpolation() value.

void startInterpolation const int    msecs = -1
 

Starts the interpolation process. A timer will be started with a period defined by msecs. The timer calls update() to update the frame() position and orientation. Use stopInterpolation() to stop interpolation, and setInterpolationTime() to change the interpolationTime(). interpolationIsStarted() will be true until stopInterpolation() is called.

If interpolationTime() is greater than the last keyFrameTime(), it is reset to the first keyFrameTime() and interpolation starts from there (natural behavior).

If msecs is negative (default with no parameter), the current interpolationPeriod() will be used (default is 25Hz, see setInterpolationPeriod()), otherwise interpolationPeriod() will be set to msecs.

You may also be interested in QGLViewer::animate() and QGLViewer::startAnimation().

Attention:
The keyFrames must be defined before you startInterpolation(), or else the interpolation will naturally immediately stop.

void stopInterpolation  
 

Stops an interpolation started with startInterpolation().

void toggleInterpolation   [inline]
 

Calls startInterpolation() or stopInterpolation(), depending on interpolationIsStarted().

void update   [virtual, slot]
 

Interpolates frame() for the next interpolationTime() (defined by interpolationPeriod()). This internal function is called by a timer when startInterpolation() is called. It is publically provided for your debugging purpose only. stopInterpolation() is called when interpolationTime() reaches the first or last keyFrameTime(), unless loopInterpolation() is true.


Generated on Thu Jan 16 12:53:47 2003 for libQGLViewer by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002