Developer Documentation
InterpolationAnimationT.hh
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41 
42 /*===========================================================================*\
43 * *
44 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 #ifndef INTERPOLATIONANIMATIONT_HH
51 #define INTERPOLATIONANIMATIONT_HH
52 
53 #include <vector>
54 #include <map>
55 
56 #include "../PoseT.hh"
57 #include "InterpolationT.hh"
58 #include "InterpolationMatrixManipulatorT.hh"
59 
60 template<class PointT>
61 class InterpolationAnimationT : public AnimationT<PointT>
62 {
63  template<typename>
64  friend class SkeletonT;
65 
66  public:
67  typedef PointT Point;
68  typedef typename Point::value_type Scalar;
69  typedef PoseT<PointT> Pose;
72  typedef std::vector<Scalar> TargetType;
73 
74  public:
76  InterpolationAnimationT(Skeleton* _skeleton, MatrixManipulator *_matrixManipulator);
77  virtual ~InterpolationAnimationT();
78 
79  virtual AnimationT<PointT>* copy();
80 
81  virtual void updateFromGlobal(unsigned int _index);
82 
83  virtual bool getMinInput(Scalar& _result);
84  virtual bool getMaxInput(Scalar& _result);
85 
86  protected:
87 
88  Skeleton* skeleton_;
89 
90  std::vector<int> influencedJoints_;
91  std::vector< Interpolator* > interpolators_;
92  //Hier muss es einen Mapper geben, der weiß, wie er auf die Matrix aus der Pose die Werte, die der Interpolator
93  //erzeugt, anwendet.
94  std::map < Interpolator*, std::vector < TargetType > > precalculations_;
95  MatrixManipulator* matrixManipulator_;
96  unsigned int frames_;
97 
98  std::map < unsigned int, Pose* > interpolatedPoses_;
99 
100  unsigned int calcAbsoluteMaxForInterpolator(uint _index);
101 
102  public:
103  static const int FPS = 60;
104 
105  public:
106 
107  //===========================================================================
112  //===========================================================================
113 
119  virtual Pose* pose(unsigned int _iFrame);
120 
128  virtual Pose* pose(unsigned int _iFrame, Pose* _reference);
129 
133  inline unsigned int frameCount();
134 
138  //===========================================================================
143  //===========================================================================
144 
151  virtual void insertJointAt(unsigned int _index);
152 
159  virtual void removeJointAt(unsigned int _index);
160 
164  //===========================================================================
169  //===========================================================================
170 
175  void addInterpolator(InterpolationT<double> *_interpolator);
176 
182  Interpolator* interpolator(unsigned int _index);
183 
188  unsigned int interpolatorCount();
191  //===========================================================================
195  //===========================================================================
196 
197  void addInfluencedJoint(int _joint)
198  {
199  influencedJoints_.push_back(_joint);
200  }
201 
202  bool isInfluenced(int _joint);
203 
204  std::vector<int>& influencedJoints();
205 
208  //===========================================================================
212  //===========================================================================
213 
218  MatrixManipulator* matrixManipulator() { return matrixManipulator_; }
219 
222  Pose* getReference() { return pose(0); }
223 
224  virtual void clearPoseCache()
225  {
226  if (interpolatedPoses_.size() == 1 && interpolatedPoses_.find(0) != interpolatedPoses_.end())
227  return;
228 
229  if (interpolatedPoses_.find(0) != interpolatedPoses_.end()) {
230  // Pose* frame0 = (interpolatedPoses_.find(0)->second);
231 
232  if (interpolatedPoses_.size() > 1) {
233  typename std::map<unsigned int, Pose*>::iterator ip_it = interpolatedPoses_.begin();
234  ++ip_it;
235  for (; ip_it != interpolatedPoses_.end(); ++ip_it) {
236  delete ip_it->second;
237  interpolatedPoses_.erase(ip_it);
238  }
239  }
240 
241  // interpolatedPoses_.insert(std::pair<unsigned int, Pose>(0, frame0));
242  } else {
243  interpolatedPoses_.clear();
244  }
245  }
246 
247 
248 };
249 
250 //=============================================================================
251 #if defined(INCLUDE_TEMPLATES) && !defined(INTERPOLATIONANIMATIONT_C)
252 #define INTERPOLATIONANIMATIONT_TEMPLATES
253 #include "InterpolationAnimationT.cc"
254 #endif
255 //=============================================================================
256 
257 #endif //INTERPOLATIONANIMATIONT_HH
Interpolator * interpolator(unsigned int _index)
Get the i-th interpolator.
MatrixManipulator * matrixManipulator()
Get the matrix manipulator.
unsigned int interpolatorCount()
Get the number of interpolators.
virtual void removeJointAt(unsigned int _index)
Called by the skeleton as a joint is deleted.
unsigned int frameCount()
Returns the number of frames stored in this pose.
A general pose, used to store the frames of the animation.
Definition: PoseT.hh:68
Knows how to apply the values generated by an interpolator to a matrix. When playing back an Interpol...
virtual void insertJointAt(unsigned int _index)
Called by the skeleton as a new joint is inserted.
virtual void updateFromGlobal(unsigned int _index)
Updates the local matrix using the global matrix.
void addInterpolator(InterpolationT< double > *_interpolator)
Add an interpolator.
unsigned int calcAbsoluteMaxForInterpolator(uint _index)
Calculates the last frame that interpolator _index is responsible for.
Stores a single animation.
Definition: AnimationT.hh:67
InterpolationAnimationT(const InterpolationAnimationT< PointT > &_other)
Copy constructor.
virtual Pose * pose(unsigned int _iFrame)
Returns a pointer to the pose calculated for the given frame.