Gazebo Common

API Reference

4.8.1
gz/common/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 <gz/math/Pose3.hh>
25 #include <gz/math/Spline.hh>
26 #include <gz/math/RotationSpline.hh>
27 
28 #include <ignition/utils/ImplPtr.hh>
29 
30 #include <gz/common/config.hh>
31 #include <gz/common/graphics/Export.hh>
32 
33 namespace ignition
34 {
35  namespace common
36  {
37  class KeyFrame;
38  class PoseKeyFrame;
39  class NumericKeyFrame;
40 
44  class IGNITION_COMMON_GRAPHICS_VISIBLE Animation
45  {
50  public: Animation(const std::string &_name,
51  const double _length, const bool _loop);
52 
55  public: double Length() const;
56 
59  public: void Length(const double _len);
60 
63  public: void Time(const double _time);
64 
67  public: void AddTime(const double _time);
68 
71  public: double Time() const;
72 
75  public: bool InterpolateX() const;
76 
79  public: void SetInterpolateX(const bool _interpolateX);
80 
83  public: unsigned int KeyFrameCount() const;
84 
88  public: common::KeyFrame *KeyFrame(const unsigned int _index) const;
89 
93  protected: template<typename KeyFrameType>
94  KeyFrameType *CreateKeyFrame(const double _time);
95 
102  protected: double KeyFramesAtTime(
103  double _time, common::KeyFrame **_kf1,
104  common::KeyFrame **_kf2,
105  unsigned int &_firstKeyIndex) const;
106 
108  IGN_UTILS_IMPL_PTR(dataPtr)
109  };
110 
112  class IGNITION_COMMON_GRAPHICS_VISIBLE PoseAnimation : public Animation
113  {
118  public: PoseAnimation(const std::string &_name,
119  const double _length, const bool _loop);
120 
132  public: PoseAnimation(const std::string &_name,
133  const double _length, const bool _loop,
134  double _tension);
135 
139  public: PoseKeyFrame *CreateKeyFrame(const double _time);
140 
143  public: void InterpolatedKeyFrame(PoseKeyFrame &_kf);
144 
148  protected: void InterpolatedKeyFrame(const double _time,
149  PoseKeyFrame &_kf);
150 
152  protected: void BuildInterpolationSplines();
153 
155  IGN_UTILS_IMPL_PTR(dataPtr)
156  };
157 
159  class IGNITION_COMMON_GRAPHICS_VISIBLE NumericAnimation : public Animation
160  {
165  public: NumericAnimation(const std::string &_name,
166  const double _length, const bool _loop);
167 
171  public: NumericKeyFrame *CreateKeyFrame(const double _time);
172 
176  public: void InterpolatedKeyFrame(NumericKeyFrame &_kf) const;
177 
179  IGN_UTILS_IMPL_PTR(dataPtr)
180  };
181 
184  class IGNITION_COMMON_GRAPHICS_VISIBLE TrajectoryInfo
185  {
187  public: TrajectoryInfo();
188 
191  public: unsigned int Id() const;
192 
195  public: void SetId(unsigned int _id);
196 
199  public: unsigned int AnimIndex() const;
200 
204  public: void SetAnimIndex(unsigned int _index);
205 
208  public: std::chrono::steady_clock::duration Duration() const;
209 
213  public: double DistanceSoFar(
214  const std::chrono::steady_clock::duration &_time) const;
215 
218  public: std::chrono::steady_clock::time_point StartTime() const;
219 
222  public: void SetStartTime(
223  const std::chrono::steady_clock::time_point &_startTime);
224 
227  public: std::chrono::steady_clock::time_point EndTime() const;
228 
231  public: void SetEndTime(
232  const std::chrono::steady_clock::time_point &_endTime);
233 
236  public: bool Translated() const;
237 
240  public: void SetTranslated(bool _translated);
241 
245 
249  public: void SetWaypoints(
251  _waypoints);
252 
261  public: void SetWaypoints(
263  _waypoints, double _tension);
264 
266  IGN_UTILS_IMPL_PTR(dataPtr)
267  };
268  }
269 }
270 #endif
Manages an animation, which is a collection of keyframes and the ability to interpolate between the k...
Definition: gz/common/Animation.hh:45
common::KeyFrame * KeyFrame(const unsigned int _index) const
Get a key frame using an index value.
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.
double Time() const
Return the current time position.
double Length() const
Return the duration of the animation.
void Length(const double _len)
Set the duration of the animation.
void SetInterpolateX(const bool _interpolateX)
Set the interpolateX value.
KeyFrameType * CreateKeyFrame(const double _time)
Create a keyframe at the given time.
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: gz/common/KeyFrame.hh:36
A numeric animation.
Definition: gz/common/Animation.hh:160
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.
A keyframe for a NumericAnimation.
Definition: gz/common/KeyFrame.hh:84
A pose animation.
Definition: gz/common/Animation.hh:113
void BuildInterpolationSplines()
Update the pose splines.
PoseAnimation(const std::string &_name, const double _length, const bool _loop, double _tension)
Constructor.
PoseKeyFrame * CreateKeyFrame(const double _time)
Create a pose keyframe at the given time.
void InterpolatedKeyFrame(PoseKeyFrame &_kf)
Get a keyframe using the animation's current time.
void InterpolatedKeyFrame(const double _time, PoseKeyFrame &_kf)
Get a keyframe using a passed in time.
PoseAnimation(const std::string &_name, const double _length, const bool _loop)
Constructor.
A keyframe for a PoseAnimation.
Definition: gz/common/KeyFrame.hh:54
Information about a trajectory for an animation (e.g., Actor) This contains the keyframe information.
Definition: gz/common/Animation.hh:185
void SetWaypoints(std::map< std::chrono::steady_clock::time_point, math::Pose3d > _waypoints, double _tension)
Load all waypoints in the trajectory.
bool Translated() const
Return whether the trajectory is translated.
void SetTranslated(bool _translated)
Set whether the trajectory is translated.
void SetWaypoints(std::map< std::chrono::steady_clock::time_point, math::Pose3d > _waypoints)
Load all waypoints in the trajectory.
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.
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.