Ignition Common

API Reference

3.5.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 AnimationPrivate;
38  class TrajectoryInfoPrivate;
39 
43  class IGNITION_COMMON_GRAPHICS_VISIBLE Animation
44  {
49  public: Animation(const std::string &_name,
50  const double _length, const bool _loop);
51 
53  public: virtual ~Animation();
54 
57  public: double Length() const;
58 
61  public: void Length(const double _len);
62 
65  public: void Time(const double _time);
66 
69  public: void AddTime(const double _time);
70 
73  public: double Time() const;
74 
77  public: bool InterpolateX() const;
78 
81  public: void SetInterpolateX(const bool _interpolateX);
82 
85  public: unsigned int KeyFrameCount() const;
86 
90  public: common::KeyFrame *KeyFrame(const unsigned int _index) const;
91 
98  protected: double KeyFramesAtTime(
99  double _time, common::KeyFrame **_kf1,
100  common::KeyFrame **_kf2,
101  unsigned int &_firstKeyIndex) const;
102 
103 #ifdef _WIN32
104 // Disable warning C4251 which is triggered by
105 // std::unique_ptr
106 #pragma warning(push)
107 #pragma warning(disable: 4251)
108 #endif
109 
111  protected: std::string name;
112 
114  protected: double length;
115 
117  protected: double timePos;
118 
120  protected: mutable bool build;
121 
123  protected: bool loop;
124 
127 
129  protected: KeyFrame_V keyFrames;
130 #ifdef _WIN32
131 #pragma warning(pop)
132 #endif
133  };
134 
136  class IGNITION_COMMON_GRAPHICS_VISIBLE PoseAnimation : public Animation
137  {
142  public: PoseAnimation(const std::string &_name,
143  const double _length, const bool _loop);
144 
146  public: virtual ~PoseAnimation();
147 
151  public: PoseKeyFrame *CreateKeyFrame(const double _time);
152 
155  public: void InterpolatedKeyFrame(PoseKeyFrame &_kf) const;
156 
160  protected: void InterpolatedKeyFrame(const double _time,
161  PoseKeyFrame &_kf) const;
162 
164  protected: void BuildInterpolationSplines() const;
165 
167  private: mutable math::Spline *positionSpline;
168 
170  private: mutable math::RotationSpline *rotationSpline;
171  };
172 
174  class IGNITION_COMMON_GRAPHICS_VISIBLE NumericAnimation : public Animation
175  {
180  public: NumericAnimation(const std::string &_name,
181  const double _length, const bool _loop);
182 
184  public: virtual ~NumericAnimation();
185 
189  public: NumericKeyFrame *CreateKeyFrame(const double _time);
190 
194  public: void InterpolatedKeyFrame(NumericKeyFrame &_kf) const;
195  };
196 
199  class IGNITION_COMMON_GRAPHICS_VISIBLE TrajectoryInfo
200  {
202  public: TrajectoryInfo();
203 
206  public: TrajectoryInfo(const TrajectoryInfo &_trajInfo);
207 
210  public: TrajectoryInfo(TrajectoryInfo &&_trajInfo) noexcept;
211 
213  public: ~TrajectoryInfo();
214 
218  public: TrajectoryInfo &operator=(const TrajectoryInfo &_trajInfo);
219 
222  public: void CopyFrom(const TrajectoryInfo &_trajInfo);
223 
226  public: unsigned int Id() const;
227 
230  public: void SetId(unsigned int _id);
231 
234  public: unsigned int AnimIndex() const;
235 
239  public: void SetAnimIndex(unsigned int _index);
240 
243  public: std::chrono::steady_clock::duration Duration() const;
244 
248  public: double DistanceSoFar(
249  const std::chrono::steady_clock::duration &_time) const;
250 
253  public: std::chrono::steady_clock::time_point StartTime() const;
254 
257  public: void SetStartTime(
258  const std::chrono::steady_clock::time_point &_startTime);
259 
262  public: std::chrono::steady_clock::time_point EndTime() const;
263 
266  public: void SetEndTime(
267  const std::chrono::steady_clock::time_point &_endTime);
268 
271  public: bool Translated() const;
272 
275  public: void SetTranslated(bool _translated);
276 
279  public: common::PoseAnimation *Waypoints() const;
280 
284  public: void SetWaypoints(
286  _waypoints);
287 
289  private: TrajectoryInfoPrivate *dataPtr{nullptr};
290  };
291  }
292 }
293 #endif
double length
animation duration
Definition: Animation.hh:114
bool build
determines if the interpolation splines need building
Definition: Animation.hh:120
Information about a trajectory for an animation (e.g., Actor) This contains the keyframe information...
Definition: Animation.hh:199
Manages an animation, which is a collection of keyframes and the ability to interpolate between the k...
Definition: Animation.hh:43
std::vector< common::KeyFrame * > KeyFrame_V
array of keyframe type alias
Definition: Animation.hh:126
A numeric animation.
Definition: Animation.hh:174
STL class.
std::string name
animation name
Definition: Animation.hh:111
A Time class, can be used to hold wall- or sim-time. stored as sec and nano-sec.
Definition: Time.hh:33
bool loop
true if animation repeats
Definition: Animation.hh:123
STL class.
A pose animation.
Definition: Animation.hh:136
A key frame in an animation.
Definition: KeyFrame.hh:30
A keyframe for a NumericAnimation.
Definition: KeyFrame.hh:90
KeyFrame_V keyFrames
array of key frames
Definition: Animation.hh:129
Forward declarations for the common classes.
double timePos
current time position
Definition: Animation.hh:117
A keyframe for a PoseAnimation.
Definition: KeyFrame.hh:48