Developer Documentation
MultiInterpolationAnimationT.cc
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 #define MULTIINTERPOLATIONANIMATIONT_C
51 
52 #include "AnimationT.hh"
53 #include <algorithm>
54 
55 //-----------------------------------------------------------------------------------------------------
56 
61 template<class PointT>
63  InterpolationAnimationT<PointT>(NULL, NULL),
64  interpolationAnimations_(_other.interpolationAnimations_)
65 {
66 }
67 
68 //-----------------------------------------------------------------------------------------------------
69 
70 template<class PointT>
72  return new MultiInterpolationAnimationT<PointT>(*this);
73 }
74 
75 //-----------------------------------------------------------------------------------------------------
76 
77 template<class PointT>
79  if (interpolationAnimations_.size() == 0)
80  return false;
81  else
82  interpolationAnimations_[0]->getMinInput(_result);
83 
84  for (uint i=0;i<interpolationAnimations_.size();++i) {
85  Scalar currentInput;
86  interpolationAnimations_[i]->getMinInput(currentInput);
87 
88  if (currentInput < _result)
89  _result = currentInput;
90  }
91 
92  return true;
93 }
94 
95 //-----------------------------------------------------------------------------------------------------
96 
97 template<class PointT>
99  if (interpolationAnimations_.size() == 0)
100  return false;
101  else
102  interpolationAnimations_[0]->getMaxInput(_result);
103 
104  for (uint i=0;i<interpolationAnimations_.size();++i) {
105  Scalar currentInput;
106  interpolationAnimations_[i]->getMaxInput(currentInput);
107 
108  if (currentInput > _result)
109  _result = currentInput;;
110  }
111 
112  return true;
113 }
114 
115 //-----------------------------------------------------------------------------------------------------
116 
121 template<class PointT>
123 {
124  Scalar minInput=0, maxInput=0;
125  if (getMinInput(minInput) && getMaxInput(maxInput)) {
126  return ((maxInput - minInput) * FPS);
127  }
128 
129  return 0;
130 }
131 
132 //-----------------------------------------------------------------------------------------------------
133 
134 template<class PointT>
136  //Use the reference pose of the first (in terms of the input value, i.e. the time in most cases)
137 
138  if (interpolationAnimations_.size() == 0)
139  return NULL;
140 
141  Scalar minValue=0; uint minInterpolationAnimationIndex = 0;
142  for (uint i=0; i<interpolationAnimations_.size(); ++i) {
143  Scalar currentValue;
144  interpolationAnimations_[i]->getMinInput(currentValue);
145  Scalar minValueTmp = std::min(minValue, currentValue);
146  minInterpolationAnimationIndex = (minValueTmp < minValue) ? i : minInterpolationAnimationIndex;
147  }
148 
149  return pose(_iFrame, interpolationAnimations_[minValue]->getReference());
150 }
151 
152 //-----------------------------------------------------------------------------------------------------
153 
154 template<class PointT>
155 PoseT<PointT> * MultiInterpolationAnimationT<PointT>::pose(unsigned int _iFrame, Pose* _reference) {
156  if (_iFrame == 0)
157  return _reference;
158 
159  Pose* newPose = NULL;
160  Pose* referenceCopy = new Pose(*_reference);
161 
162  for (uint i=0; i<interpolationAnimations_.size(); ++i) {
163  Scalar minInput, maxInput;
164  interpolationAnimations_[i]->getMinInput(minInput); interpolationAnimations_[i]->getMaxInput(maxInput);
165 
166  unsigned int minFrame = (minInput * FPS);
167  unsigned int maxFrame = (maxInput * FPS);
168 
169  //Check, if the current animation is responsible for displaying this frame
170  if (_iFrame < minFrame || _iFrame > maxFrame)
171  continue;
172 
173  if (interpolationAnimations_[i]) {
174  if (newPose == NULL)
175  newPose = interpolationAnimations_[i]->pose(_iFrame - minFrame, referenceCopy);
176  else
177  newPose = interpolationAnimations_[i]->pose(_iFrame - minFrame, newPose);
178  }
179  }
180 
181  delete referenceCopy;
182 
183  if (newPose == NULL)
184  newPose = _reference;
185 
186  return newPose;
187 }
188 
189 //-----------------------------------------------------------------------------------------------------
190 
191 template<class PointT>
193  if ( _index < interpolationAnimations_.size() )
194  return interpolationAnimations_[ _index ];
195  else
196  return 0;
197 }
198 
199 //-----------------------------------------------------------------------------------------------------
200 
PoseT< PointT > Pose
Typedef for the pose template.
virtual unsigned int frameCount()
Returns the number of frames that this animation can playback.
A general pose, used to store the frames of the animation.
Definition: PoseT.hh:68
virtual Pose * pose(unsigned int _iFrame)
get a pose
Stores a single animation.
Definition: AnimationT.hh:67