keyFrameInterpolator.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 
00003  Copyright (C) 2002-2013 Gilles Debunne. All rights reserved.
00004 
00005  This file is part of the QGLViewer library version 2.4.0.
00006 
00007  http://www.libqglviewer.com - contact@libqglviewer.com
00008 
00009  This file may be used under the terms of the GNU General Public License 
00010  versions 2.0 or 3.0 as published by the Free Software Foundation and
00011  appearing in the LICENSE file included in the packaging of this file.
00012  In addition, as a special exception, Gilles Debunne gives you certain 
00013  additional rights, described in the file GPL_EXCEPTION in this package.
00014 
00015  libQGLViewer uses dual licensing. Commercial/proprietary software must
00016  purchase a libQGLViewer Commercial License.
00017 
00018  This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00019  WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
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 // Not actually needed, but some bad compilers (Microsoft VS6) complain.
00036 #include "frame.h"
00037 
00038 // If you compiler complains about incomplete type, uncomment the next line
00039 // #include "frame.h"
00040 // and comment "class Frame;" 3 lines below
00041 
00042 namespace qglviewer {
00043   class Camera;
00044   class Frame;
00131   class QGLVIEWER_EXPORT KeyFrameInterpolator : public QObject
00132   {
00133     // todo closedPath, insertKeyFrames, deleteKeyFrame, replaceKeyFrame
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     // Copy constructor and opertor= are declared private and undefined
00300     // Prevents everyone from trying to use them
00301     // KeyFrameInterpolator(const KeyFrameInterpolator& kfi);
00302     // KeyFrameInterpolator& operator=(const KeyFrameInterpolator& kfi);
00303 
00304     void updateCurrentKeyFrameForTime(float time);
00305     void updateModifiedFrameValues();
00306     void updateSplineCache();
00307 
00308 #ifndef DOXYGEN
00309     // Internal private KeyFrame representation
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     // K e y F r a m e s
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     // 4 succesive frames. interpolationTime_ is between index 1 and 2.
00341     QPtrListIterator<KeyFrame>* currentFrame_[4];
00342 # if QT_VERSION >= 0x030000
00343     // Cached path computed values (for drawPath()).
00344     QValueVector<Frame> path_;
00345 # else
00346     QVector<Frame> path_;
00347 # endif
00348 #endif
00349 
00350     // A s s o c i a t e d   f r a m e
00351     Frame* frame_;
00352 
00353     // R h y t h m
00354     QTimer timer_;
00355     int period_;
00356     float interpolationTime_;
00357     float interpolationSpeed_;
00358     bool interpolationStarted_;
00359 
00360     // M i s c
00361     bool closedPath_;
00362     bool loopInterpolation_;
00363 
00364     // C a c h e d   v a l u e s   a n d   f l a g s
00365     bool pathIsValid_;
00366     bool valuesAreValid_;
00367     bool currentFrameValid_;
00368     bool splineCacheIsValid_;
00369     Vec v1, v2;
00370   };
00371 
00372 } // namespace qglviewer
00373 
00374 #endif // QGLVIEWER_KEY_FRAME_INTERPOLATOR_H


octovis
Author(s): Kai M. Wurm , Armin Hornung
autogenerated on Thu Feb 11 2016 23:51:20