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 #pragma once
43 
44 #include <vector>
45 #include <map>
46 
47 #include "../PoseT.hh"
48 #include "InterpolationT.hh"
49 #include "InterpolationMatrixManipulatorT.hh"
50 
51 template<class PointT>
52 class InterpolationAnimationT : public AnimationT<PointT>
53 {
54  template<typename>
55  friend class SkeletonT;
56 
57  public:
58  typedef PointT Point;
59  typedef typename Point::value_type Scalar;
60  typedef PoseT<PointT> Pose;
63  typedef std::vector<Scalar> TargetType;
64 
65  public:
67  InterpolationAnimationT(Skeleton* _skeleton, MatrixManipulator *_matrixManipulator);
68  virtual ~InterpolationAnimationT();
69 
70  virtual AnimationT<PointT>* copy();
71 
72  virtual void updateFromGlobal(unsigned int _index);
73 
74  virtual bool getMinInput(Scalar& _result);
75  virtual bool getMaxInput(Scalar& _result);
76 
77  protected:
78 
79  Skeleton* skeleton_;
80 
81  std::vector<int> influencedJoints_;
82  std::vector< Interpolator* > interpolators_;
83  //Hier muss es einen Mapper geben, der weiß, wie er auf die Matrix aus der Pose die Werte, die der Interpolator
84  //erzeugt, anwendet.
85  std::map < Interpolator*, std::vector < TargetType > > precalculations_;
86  MatrixManipulator* matrixManipulator_;
87  unsigned int frames_;
88 
89  std::map < unsigned int, Pose* > interpolatedPoses_;
90 
91  unsigned int calcAbsoluteMaxForInterpolator(uint _index);
92 
93  public:
94  static const int FPS = 60;
95 
96  public:
97 
98  //===========================================================================
103  //===========================================================================
104 
110  virtual Pose* pose(unsigned int _iFrame);
111 
119  virtual Pose* pose(unsigned int _iFrame, Pose* _reference);
120 
124  inline unsigned int frameCount();
125 
129  //===========================================================================
134  //===========================================================================
135 
142  virtual void insertJointAt(unsigned int _index);
143 
150  virtual void removeJointAt(unsigned int _index);
151 
155  //===========================================================================
160  //===========================================================================
161 
166  void addInterpolator(InterpolationT<double> *_interpolator);
167 
173  Interpolator* interpolator(unsigned int _index);
174 
179  unsigned int interpolatorCount();
182  //===========================================================================
186  //===========================================================================
187 
188  void addInfluencedJoint(int _joint)
189  {
190  influencedJoints_.push_back(_joint);
191  }
192 
193  bool isInfluenced(int _joint);
194 
195  std::vector<int>& influencedJoints();
196 
199  //===========================================================================
203  //===========================================================================
204 
209  MatrixManipulator* matrixManipulator() { return matrixManipulator_; }
210 
213  Pose* getReference() { return pose(0); }
214 
215  virtual void clearPoseCache()
216  {
217  if (interpolatedPoses_.size() == 1 && interpolatedPoses_.find(0) != interpolatedPoses_.end())
218  return;
219 
220  if (interpolatedPoses_.find(0) != interpolatedPoses_.end()) {
221  // Pose* frame0 = (interpolatedPoses_.find(0)->second);
222 
223  if (interpolatedPoses_.size() > 1) {
224  typename std::map<unsigned int, Pose*>::iterator ip_it = interpolatedPoses_.begin();
225  ++ip_it;
226  for (; ip_it != interpolatedPoses_.end(); ++ip_it) {
227  delete ip_it->second;
228  interpolatedPoses_.erase(ip_it);
229  }
230  }
231 
232  // interpolatedPoses_.insert(std::pair<unsigned int, Pose>(0, frame0));
233  } else {
234  interpolatedPoses_.clear();
235  }
236  }
237 
238 
239 };
240 
241 //=============================================================================
242 #if defined(INCLUDE_TEMPLATES) && !defined(INTERPOLATIONANIMATIONT_C)
243 #define INTERPOLATIONANIMATIONT_TEMPLATES
244 #include "InterpolationAnimationT_impl.hh"
245 #endif
246 //=============================================================================
247 
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.
InterpolationAnimationT(const InterpolationAnimationT< PointT > &_other)
Copy constructor.
virtual void removeJointAt(unsigned int _index)
Called by the skeleton as a joint is deleted.
Stores a single animation.
Definition: AnimationT.hh:58
A general pose, used to store the frames of the animation.
Definition: PoseT.hh:58
unsigned int calcAbsoluteMaxForInterpolator(uint _index)
Calculates the last frame that interpolator _index is responsible for.
unsigned int frameCount()
Returns the number of frames stored in this pose.
MatrixManipulator * matrixManipulator()
Get the matrix manipulator.
Interpolator * interpolator(unsigned int _index)
Get the i-th interpolator.
unsigned int interpolatorCount()
Get the number of interpolators.
void addInterpolator(InterpolationT< double > *_interpolator)
Add an interpolator.
virtual Pose * pose(unsigned int _iFrame)
Returns a pointer to the pose calculated for the given frame.
virtual void updateFromGlobal(unsigned int _index)
Updates the local matrix using the global matrix.