Ignition Common

API Reference

3.9.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 
278  public: common::PoseAnimation *Waypoints() const;
279 
283  public: void SetWaypoints(
285  _waypoints);
286 
288  private: TrajectoryInfoPrivate *dataPtr{nullptr};
289  };
290  }
291 }
292 #endif
double length
animation duration
Definition: Animation.hh:113
bool build
determines if the interpolation splines need building
Definition: Animation.hh:119
Information about a trajectory for an animation (e.g., Actor) This contains the keyframe information...
Definition: Animation.hh:198
Manages an animation, which is a collection of keyframes and the ability to interpolate between the k...
Definition: Animation.hh:42
A numeric animation.
Definition: Animation.hh:173
STL class.
std::string name
animation name
Definition: Animation.hh:110
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:122
STL class.
A pose animation.
Definition: Animation.hh:135
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:128
std::vector< common::KeyFrame * > KeyFrame_V
array of keyframe type alias
Definition: Animation.hh:125
Forward declarations for the common classes.
double timePos
current time position
Definition: Animation.hh:116
A keyframe for a PoseAnimation.
Definition: KeyFrame.hh:48