MorphoGraphX
CameraPath.hpp
1 //
2 // This file is part of MorphoGraphX - http://www.MorphoGraphX.org
3 // Copyright (C) 2012-2015 Richard S. Smith and collaborators.
4 //
5 // If you use MorphoGraphX in your work, please cite:
6 // http://dx.doi.org/10.7554/eLife.05864
7 //
8 // MorphoGraphX is free software, and is licensed under under the terms of the
9 // GNU General (GPL) Public License version 2.0, http://www.gnu.org/licenses.
10 //
11 #ifndef CAMERAPATH_HPP
12 #define CAMERAPATH_HPP
13 
14 #include <Config.hpp>
15 
16 #include <Misc.hpp>
17 
18 #include <QObject>
19 #include <QTimer>
20 #include <QPointer>
21 #include <QList>
22 
23 class MGXCamera;
24 
25 class CameraPath : public QObject {
26  Q_OBJECT
27 public:
29  ~CameraPath();
30  void addFrame(MGXCamera* camera, float time = 1.0);
31  void addRotation(const mgx::Point3f& axis, double angle, float time = 2.0);
32 
33  void animatePath(MGXCamera* camera, float dt);
34 
35 protected slots:
36  void nextFrame();
37 
38 signals:
39  void endPath();
40  void frameUpdated();
41 
42 protected:
43  struct Action : public QObject {
44  Action(float t, QObject* parent = 0)
45  : QObject(parent)
46  , time(t)
47  {
48  }
49 
50  // Returns true when the end is reached
51  virtual bool startInterpolation(MGXCamera* camera) = 0;
52  virtual bool interpolateFrame(MGXCamera* camera, float t) = 0;
53  float time;
54  };
55 
56  struct ToPosition : public Action {
57  ToPosition(const mgx::Point3f& c, const mgx::Point3f& p, const mgx::Point3f& d, float z, float t, QObject* parent = 0)
58  : Action(t, parent)
59  , center(c)
60  , position(p)
61  , direction(d)
62  , zoom(z)
63  {
64  }
65 
66  virtual bool startInterpolation(MGXCamera* camera);
67  virtual bool interpolateFrame(MGXCamera* camera, float t);
68  mgx::Point3f center;
69  mgx::Point3f position;
70  mgx::Point3f direction;
71  float zoom;
72 
73  // Quaternions for camera orientation
74  mgx::Quaternion oq1, oq2;
75  // Quaternions for camera position
76  mgx::Quaternion pq1, pq2;
77  };
78 
79  struct Rotation : public Action {
80  Rotation(const mgx::Point3f& c, const mgx::Point3f& ax, float an, float t, QObject* parent = 0)
81  : Action(t, parent)
82  , center(c)
83  , axis(ax)
84  , angle(an)
85  {
86  }
87  virtual bool startInterpolation(MGXCamera*) {
88  return true;
89  }
90  virtual bool interpolateFrame(MGXCamera*, float) {
91  return true;
92  }
93  mgx::Point3f center;
94  mgx::Point3f axis;
95  double angle;
96  };
97 
98  QList<QPointer<Action> > frames;
99  MGXCamera* camera;
100  float dt;
101  float current_time;
102  int current_index;
103  QTimer* timer;
104 };
105 
106 #endif // CAMERAPATH_HPP
Definition: CameraPath.hpp:56
Definition: MorphoViewer.hpp:61
Misc.
Definition: CameraPath.hpp:43
QObject(QObject *parent=0)
Definition: CameraPath.hpp:79
Definition: CameraPath.hpp:25