Ignition Common

API Reference

3.14.0
Animation.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef IGNITION_COMMON_ANIMATION_HH_
18 #define IGNITION_COMMON_ANIMATION_HH_
19 
20 #include <map>
21 #include <string>
22 #include <vector>
23 
24 #include <ignition/math/Pose3.hh>
25 #include <ignition/math/Spline.hh>
27 
28 #include <ignition/common/graphics/Export.hh>
29 
30 namespace ignition
31 {
32  namespace common
33  {
34  class KeyFrame;
35  class PoseKeyFrame;
36  class NumericKeyFrame;
37  class TrajectoryInfoPrivate;
38 
42  class IGNITION_COMMON_GRAPHICS_VISIBLE Animation
43  {
48  public: Animation(const std::string &_name,
49  const double _length, const bool _loop);
50 
52  public: virtual ~Animation();
53 
56  public: double Length() const;
57 
60  public: void Length(const double _len);
61 
64  public: void Time(const double _time);
65 
68  public: void AddTime(const double _time);
69 
72  public: double Time() const;
73 
76  public: bool InterpolateX() const;
77 
80  public: void SetInterpolateX(const bool _interpolateX);
81 
84  public: unsigned int KeyFrameCount() const;
85 
89  public: common::KeyFrame *KeyFrame(const unsigned int _index) const;
90 
97  protected: double KeyFramesAtTime(
98  double _time, common::KeyFrame **_kf1,
99  common::KeyFrame **_kf2,
100  unsigned int &_firstKeyIndex) const;
101 
102 #ifdef _WIN32
103 // Disable warning C4251 which is triggered by
104 // std::unique_ptr
105 #pragma warning(push)
106 #pragma warning(disable: 4251)
107 #endif
108 
110  protected: std::string name;
111 
113  protected: double length;
114 
116  protected: double timePos;
117 
119  protected: mutable bool build;
120 
122  protected: bool loop;
123 
126 
128  protected: KeyFrame_V keyFrames;
129 #ifdef _WIN32
130 #pragma warning(pop)
131 #endif
132  };
133 
135  class IGNITION_COMMON_GRAPHICS_VISIBLE PoseAnimation : public Animation
136  {
141  public: PoseAnimation(const std::string &_name,
142  const double _length, const bool _loop);
143 
145  public: virtual ~PoseAnimation();
146 
150  public: PoseKeyFrame *CreateKeyFrame(const double _time);
151 
154  public: void InterpolatedKeyFrame(PoseKeyFrame &_kf) const;
155 
159  protected: void InterpolatedKeyFrame(const double _time,
160  PoseKeyFrame &_kf) const;
161 
163  protected: void BuildInterpolationSplines() const;
164 
166  private: mutable math::Spline *positionSpline;
167 
169  private: mutable math::RotationSpline *rotationSpline;
170  };
171 
173  class IGNITION_COMMON_GRAPHICS_VISIBLE NumericAnimation : public Animation
174  {
179  public: NumericAnimation(const std::string &_name,
180  const double _length, const bool _loop);
181 
183  public: virtual ~NumericAnimation();
184 
188  public: NumericKeyFrame *CreateKeyFrame(const double _time);
189 
193  public: void InterpolatedKeyFrame(NumericKeyFrame &_kf) const;
194  };
195 
198  class IGNITION_COMMON_GRAPHICS_VISIBLE TrajectoryInfo
199  {
201  public: TrajectoryInfo();
202 
205  public: TrajectoryInfo(const TrajectoryInfo &_trajInfo);
206 
209  public: TrajectoryInfo(TrajectoryInfo &&_trajInfo) noexcept;
210 
212  public: ~TrajectoryInfo();
213 
217  public: TrajectoryInfo &operator=(const TrajectoryInfo &_trajInfo);
218 
221  public: void CopyFrom(const TrajectoryInfo &_trajInfo);
222 
225  public: unsigned int Id() const;
226 
229  public: void SetId(unsigned int _id);
230 
233  public: unsigned int AnimIndex() const;
234 
238  public: void SetAnimIndex(unsigned int _index);
239 
242  public: std::chrono::steady_clock::duration Duration() const;
243 
247  public: double DistanceSoFar(
248  const std::chrono::steady_clock::duration &_time) const;
249 
252  public: std::chrono::steady_clock::time_point StartTime() const;
253 
256  public: void SetStartTime(
257  const std::chrono::steady_clock::time_point &_startTime);
258 
261  public: std::chrono::steady_clock::time_point EndTime() const;
262 
265  public: void SetEndTime(
266  const std::chrono::steady_clock::time_point &_endTime);
267 
270  public: bool Translated() const;
271 
274  public: void SetTranslated(bool _translated);
275 
279 
283  public: void SetWaypoints(
285  _waypoints);
286 
288  private: TrajectoryInfoPrivate *dataPtr{nullptr};
289  };
290  }
291 }
292 #endif
Manages an animation, which is a collection of keyframes and the ability to interpolate between the k...
Definition: Animation.hh:43
common::KeyFrame * KeyFrame(const unsigned int _index) const
Get a key frame using an index value.
KeyFrame_V keyFrames
array of key frames
Definition: Animation.hh:128
bool InterpolateX() const
Return the interpolateX value.
unsigned int KeyFrameCount() const
Return the number of key frames in the animation.
void AddTime(const double _time)
Add time to the animation.
bool loop
true if animation repeats
Definition: Animation.hh:122
double timePos
current time position
Definition: Animation.hh:116
double Time() const
Return the current time position.
virtual ~Animation()
Destructor.
double length
animation duration
Definition: Animation.hh:113
std::string name
animation name
Definition: Animation.hh:110
double Length() const
Return the duration of the animation.
void Length(const double _len)
Set the duration of the animation.
bool build
determines if the interpolation splines need building
Definition: Animation.hh:119
void SetInterpolateX(const bool _interpolateX)
Set the interpolateX value.
std::vector< common::KeyFrame * > KeyFrame_V
array of keyframe type alias
Definition: Animation.hh:125
double KeyFramesAtTime(double _time, common::KeyFrame **_kf1, common::KeyFrame **_kf2, unsigned int &_firstKeyIndex) const
Get the two key frames that bound a time value.
Animation(const std::string &_name, const double _length, const bool _loop)
Constructor.
void Time(const double _time)
Set the current time position of the animation.
A key frame in an animation.
Definition: KeyFrame.hh:31
A numeric animation.
Definition: Animation.hh:174
NumericAnimation(const std::string &_name, const double _length, const bool _loop)
Constructor.
void InterpolatedKeyFrame(NumericKeyFrame &_kf) const
Get a keyframe using the animation's current time.
NumericKeyFrame * CreateKeyFrame(const double _time)
Create a numeric keyframe at the given time.
virtual ~NumericAnimation()
Destructor.
A keyframe for a NumericAnimation.
Definition: KeyFrame.hh:91
A pose animation.
Definition: Animation.hh:136
void BuildInterpolationSplines() const
Update the pose splines.
PoseKeyFrame * CreateKeyFrame(const double _time)
Create a pose keyframe at the given time.
void InterpolatedKeyFrame(const double _time, PoseKeyFrame &_kf) const
Get a keyframe using a passed in time.
void InterpolatedKeyFrame(PoseKeyFrame &_kf) const
Get a keyframe using the animation's current time.
PoseAnimation(const std::string &_name, const double _length, const bool _loop)
Constructor.
virtual ~PoseAnimation()
Destructor.
A keyframe for a PoseAnimation.
Definition: KeyFrame.hh:49
Information about a trajectory for an animation (e.g., Actor) This contains the keyframe information.
Definition: Animation.hh:199
void CopyFrom(const TrajectoryInfo &_trajInfo)
Copy TrajectoryInfo from a TrajectoryInfo instance.
bool Translated() const
Return whether the trajectory is translated.
void SetTranslated(bool _translated)
Set whether the trajectory is translated.
TrajectoryInfo(const TrajectoryInfo &_trajInfo)
Copy constructor.
void SetWaypoints(std::map< std::chrono::steady_clock::time_point, math::Pose3d > _waypoints)
Load all waypoints in the trajectory.
TrajectoryInfo(TrajectoryInfo &&_trajInfo) noexcept
Move constructor.
common::PoseAnimation * Waypoints() const
Return the waypoints in the trajectory.
unsigned int AnimIndex() const
Return the animation index.
std::chrono::steady_clock::time_point EndTime() const
Return the end time of the trajectory.
void SetEndTime(const std::chrono::steady_clock::time_point &_endTime)
Set the end time of the trajectory.
TrajectoryInfo & operator=(const TrajectoryInfo &_trajInfo)
Assignment operator.
void SetId(unsigned int _id)
Set the id of the trajectory.
void SetStartTime(const std::chrono::steady_clock::time_point &_startTime)
Set the start time of the trajectory.
unsigned int Id() const
Return the id of the trajectory.
double DistanceSoFar(const std::chrono::steady_clock::duration &_time) const
Get the distance covered by the trajectory by a given time.
void SetAnimIndex(unsigned int _index)
Set the animation index.
std::chrono::steady_clock::duration Duration() const
Return the duration of the trajectory.
std::chrono::steady_clock::time_point StartTime() const
Return the start time of the trajectory.
Forward declarations for the common classes.