Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 #ifndef QGLVIEWER_KEY_FRAME_INTERPOLATOR_H
00024 #define QGLVIEWER_KEY_FRAME_INTERPOLATOR_H
00025 
00026 #if QT_VERSION > 0x040000
00027 # include <QObject>
00028 # include <QTimer>
00029 #else
00030 # include <qobject.h>
00031 # include <qtimer.h>
00032 #endif
00033 
00034 #include "quaternion.h"
00035 
00036 #include "frame.h"
00037 
00038 
00039 
00040 
00041 
00042 namespace qglviewer {
00043   class Camera;
00044   class Frame;
00131   class QGLVIEWER_EXPORT KeyFrameInterpolator : public QObject
00132   {
00133     
00134     Q_OBJECT
00135 
00136   public:
00137     KeyFrameInterpolator(Frame* fr=NULL);
00138     virtual ~KeyFrameInterpolator();
00139 
00140   Q_SIGNALS:
00155     void interpolated();
00156 
00162     void endReached();
00163 
00166   public Q_SLOTS:
00167     void addKeyFrame(const Frame& frame);
00168     void addKeyFrame(const Frame& frame, float time);
00169 
00170     void addKeyFrame(const Frame* const frame);
00171     void addKeyFrame(const Frame* const frame, float time);
00172 
00173     void deletePath();
00175 
00178   public:
00185     Frame* frame() const { return frame_; };
00186 
00187   public Q_SLOTS:
00188     void setFrame(Frame* const frame);
00190 
00193   public:
00194     Frame keyFrame(int index) const;
00195     float keyFrameTime(int index) const;
00197     int numberOfKeyFrames() const { return keyFrame_.count(); };
00198     float duration() const;
00199     float firstTime() const;
00200     float lastTime() const;
00202 
00205   public:
00210     float interpolationTime() const { return interpolationTime_; };
00218     float interpolationSpeed() const { return interpolationSpeed_; };
00227     int interpolationPeriod() const { return period_; };
00237     bool loopInterpolation() const { return loopInterpolation_; };
00238 #ifndef DOXYGEN
00239 
00244     bool closedPath() const { return closedPath_; };
00245 #endif
00246   public Q_SLOTS:
00252     void setInterpolationTime(float time) { interpolationTime_ = time; };
00254     void setInterpolationSpeed(float speed) { interpolationSpeed_ = speed; };
00256     void setInterpolationPeriod(int period) { period_ = period; };
00258     void setLoopInterpolation(bool loop=true) { loopInterpolation_ = loop; };
00259 #ifndef DOXYGEN
00260 
00261     void setClosedPath(bool closed=true) { closedPath_ = closed; };
00262 #endif
00263 
00264 
00265 
00268   public:
00271     bool interpolationIsStarted() const { return interpolationStarted_; };
00272   public Q_SLOTS:
00273     void startInterpolation(int period = -1);
00274     void stopInterpolation();
00275     void resetInterpolation();
00277     void toggleInterpolation() { if (interpolationIsStarted()) stopInterpolation(); else startInterpolation(); };
00278     virtual void interpolateAtTime(float time);
00280 
00283   public:
00284     virtual void drawPath(int mask=1, int nbFrames=6, float scale=1.0f);
00286 
00289   public:
00290     virtual QDomElement domElement(const QString& name, QDomDocument& document) const;
00291     virtual void initFromDOMElement(const QDomElement& element);
00293 
00294   private Q_SLOTS:
00295     virtual void update();
00296     virtual void invalidateValues() { valuesAreValid_ = false; pathIsValid_ = false; splineCacheIsValid_ = false; };
00297 
00298   private:
00299     
00300     
00301     
00302     
00303 
00304     void updateCurrentKeyFrameForTime(float time);
00305     void updateModifiedFrameValues();
00306     void updateSplineCache();
00307 
00308 #ifndef DOXYGEN
00309     
00310     class KeyFrame
00311     {
00312     public:
00313       KeyFrame(const Frame& fr, float t);
00314       KeyFrame(const Frame* fr, float t);
00315 
00316       Vec position() const { return p_; }
00317       Quaternion orientation() const { return q_; }
00318       Vec tgP() const { return tgP_; }
00319       Quaternion tgQ() const { return tgQ_; }
00320       float time() const { return time_; }
00321       const Frame* frame() const { return frame_; }
00322       void updateValuesFromPointer();
00323       void flipOrientationIfNeeded(const Quaternion& prev);
00324       void computeTangent(const KeyFrame* const prev, const KeyFrame* const next);
00325     private:
00326       Vec p_, tgP_;
00327       Quaternion q_, tgQ_;
00328       float time_;
00329       const Frame* const frame_;
00330     };
00331 #endif
00332 
00333     
00334 #if QT_VERSION >= 0x040000
00335     mutable QList<KeyFrame*> keyFrame_;
00336     QMutableListIterator<KeyFrame*>* currentFrame_[4];
00337     QList<Frame> path_;
00338 #else
00339     mutable QPtrList<KeyFrame> keyFrame_;
00340     
00341     QPtrListIterator<KeyFrame>* currentFrame_[4];
00342 # if QT_VERSION >= 0x030000
00343     
00344     QValueVector<Frame> path_;
00345 # else
00346     QVector<Frame> path_;
00347 # endif
00348 #endif
00349 
00350     
00351     Frame* frame_;
00352 
00353     
00354     QTimer timer_;
00355     int period_;
00356     float interpolationTime_;
00357     float interpolationSpeed_;
00358     bool interpolationStarted_;
00359 
00360     
00361     bool closedPath_;
00362     bool loopInterpolation_;
00363 
00364     
00365     bool pathIsValid_;
00366     bool valuesAreValid_;
00367     bool currentFrameValid_;
00368     bool splineCacheIsValid_;
00369     Vec v1, v2;
00370   };
00371 
00372 } 
00373 
00374 #endif // QGLVIEWER_KEY_FRAME_INTERPOLATOR_H