keyFrameInterpolator.h
Go to the documentation of this file.
1 /****************************************************************************
2 
3  Copyright (C) 2002-2014 Gilles Debunne. All rights reserved.
4 
5  This file is part of the QGLViewer library version 2.6.3.
6 
7  http://www.libqglviewer.com - contact@libqglviewer.com
8 
9  This file may be used under the terms of the GNU General Public License
10  versions 2.0 or 3.0 as published by the Free Software Foundation and
11  appearing in the LICENSE file included in the packaging of this file.
12  In addition, as a special exception, Gilles Debunne gives you certain
13  additional rights, described in the file GPL_EXCEPTION in this package.
14 
15  libQGLViewer uses dual licensing. Commercial/proprietary software must
16  purchase a libQGLViewer Commercial License.
17 
18  This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
19  WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 
21 *****************************************************************************/
22 
23 #ifndef QGLVIEWER_KEY_FRAME_INTERPOLATOR_H
24 #define QGLVIEWER_KEY_FRAME_INTERPOLATOR_H
25 
26 #include <QObject>
27 #include <QTimer>
28 
29 #include "quaternion.h"
30 // Not actually needed, but some bad compilers (Microsoft VS6) complain.
31 #include "frame.h"
32 
33 // If you compiler complains about incomplete type, uncomment the next line
34 // #include "frame.h"
35 // and comment "class Frame;" 3 lines below
36 
37 namespace qglviewer {
38 class Camera;
39 class Frame;
127 {
128  // todo closedPath, insertKeyFrames, deleteKeyFrame, replaceKeyFrame
129  Q_OBJECT
130 
131 public:
132  KeyFrameInterpolator(Frame* fr=NULL);
133  virtual ~KeyFrameInterpolator();
134 
135 Q_SIGNALS:
150  void interpolated();
151 
157  void endReached();
158 
161 public Q_SLOTS:
162  void addKeyFrame(const Frame& frame);
163  void addKeyFrame(const Frame& frame, qreal time);
164 
165  void addKeyFrame(const Frame* const frame);
166  void addKeyFrame(const Frame* const frame, qreal time);
167 
168  void deletePath();
170 
173 public:
180  Frame* frame() const { return frame_; }
181 
182 public Q_SLOTS:
183  void setFrame(Frame* const frame);
185 
188 public:
189  Frame keyFrame(int index) const;
190  qreal keyFrameTime(int index) const;
192  int numberOfKeyFrames() const { return keyFrame_.count(); }
193  qreal duration() const;
194  qreal firstTime() const;
195  qreal lastTime() const;
197 
200 public:
205  qreal interpolationTime() const { return interpolationTime_; }
213  qreal interpolationSpeed() const { return interpolationSpeed_; }
222  int interpolationPeriod() const { return period_; }
232  bool loopInterpolation() const { return loopInterpolation_; }
233 #ifndef DOXYGEN
234 
239  bool closedPath() const { return closedPath_; }
240 #endif
241 public Q_SLOTS:
247  void setInterpolationTime(qreal time) { interpolationTime_ = time; }
249  void setInterpolationSpeed(qreal speed) { interpolationSpeed_ = speed; }
251  void setInterpolationPeriod(int period) { period_ = period; }
253  void setLoopInterpolation(bool loop=true) { loopInterpolation_ = loop; }
254 #ifndef DOXYGEN
255 
256  void setClosedPath(bool closed=true) { closedPath_ = closed; }
257 #endif
258 
259 
260 
263 public:
266  bool interpolationIsStarted() const { return interpolationStarted_; }
267 public Q_SLOTS:
268  void startInterpolation(int period = -1);
269  void stopInterpolation();
270  void resetInterpolation();
272  void toggleInterpolation() { if (interpolationIsStarted()) stopInterpolation(); else startInterpolation(); }
273  virtual void interpolateAtTime(qreal time);
275 
278 public:
279  virtual void drawPath(int mask=1, int nbFrames=6, qreal scale=1.0);
281 
284 public:
285  virtual QDomElement domElement(const QString& name, QDomDocument& document) const;
286  virtual void initFromDOMElement(const QDomElement& element);
288 
289 private Q_SLOTS:
290  virtual void update();
291  virtual void invalidateValues() { valuesAreValid_ = false; pathIsValid_ = false; splineCacheIsValid_ = false; }
292 
293 private:
294  // Copy constructor and opertor= are declared private and undefined
295  // Prevents everyone from trying to use them
296  // KeyFrameInterpolator(const KeyFrameInterpolator& kfi);
297  // KeyFrameInterpolator& operator=(const KeyFrameInterpolator& kfi);
298 
299  void updateCurrentKeyFrameForTime(qreal time);
300  void updateModifiedFrameValues();
301  void updateSplineCache();
302 
303 #ifndef DOXYGEN
304  // Internal private KeyFrame representation
305  class KeyFrame
306  {
307  public:
308  KeyFrame(const Frame& fr, qreal t);
309  KeyFrame(const Frame* fr, qreal t);
310 
311  Vec position() const { return p_; }
312  Quaternion orientation() const { return q_; }
313  Vec tgP() const { return tgP_; }
314  Quaternion tgQ() const { return tgQ_; }
315  qreal time() const { return time_; }
316  const Frame* frame() const { return frame_; }
317  void updateValuesFromPointer();
318  void flipOrientationIfNeeded(const Quaternion& prev);
319  void computeTangent(const KeyFrame* const prev, const KeyFrame* const next);
320  private:
321  Vec p_, tgP_;
323  qreal time_;
324  const Frame* const frame_;
325  };
326 #endif
327 
328  // K e y F r a m e s
329  mutable QList<KeyFrame*> keyFrame_;
330  QMutableListIterator<KeyFrame*>* currentFrame_[4];
331  QList<Frame> path_;
332 
333  // A s s o c i a t e d f r a m e
335 
336  // R h y t h m
337  QTimer timer_;
338  int period_;
342 
343  // M i s c
346 
347  // C a c h e d v a l u e s a n d f l a g s
352  Vec v1, v2;
353 };
354 
355 } // namespace qglviewer
356 
357 #endif // QGLVIEWER_KEY_FRAME_INTERPOLATOR_H
A keyFrame Catmull-Rom Frame interpolator.
void setClosedPath(bool closed=true)
#define QGLVIEWER_EXPORT
The Vec class represents 3D positions and 3D vectors.
Definition: vec.h:65
void setLoopInterpolation(bool loop=true)
The Quaternion class represents 3D rotations and orientations.
Definition: quaternion.h:66
The Frame class represents a coordinate system, defined by a position and an orientation.
Definition: frame.h:121


octovis
Author(s): Kai M. Wurm , Armin Hornung
autogenerated on Wed Jun 5 2019 19:26:39