Developer Documentation
Loading...
Searching...
No Matches
MultiInterpolationAnimationT_impl.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#define MULTIINTERPOLATIONANIMATIONT_C
45
46#include "AnimationT.hh"
47#include <algorithm>
48
49//-----------------------------------------------------------------------------------------------------
50
55template<class PointT>
57 InterpolationAnimationT<PointT>(NULL, NULL),
58 interpolationAnimations_(_other.interpolationAnimations_)
59{
60}
61
62//-----------------------------------------------------------------------------------------------------
63
64template<class PointT>
67}
68
69//-----------------------------------------------------------------------------------------------------
70
71template<class PointT>
73 if (interpolationAnimations_.size() == 0)
74 return false;
75 else
76 interpolationAnimations_[0]->getMinInput(_result);
77
78 for (uint i=0;i<interpolationAnimations_.size();++i) {
79 Scalar currentInput;
80 interpolationAnimations_[i]->getMinInput(currentInput);
81
82 if (currentInput < _result)
83 _result = currentInput;
84 }
85
86 return true;
87}
88
89//-----------------------------------------------------------------------------------------------------
90
91template<class PointT>
93 if (interpolationAnimations_.size() == 0)
94 return false;
95 else
96 interpolationAnimations_[0]->getMaxInput(_result);
97
98 for (uint i=0;i<interpolationAnimations_.size();++i) {
99 Scalar currentInput;
100 interpolationAnimations_[i]->getMaxInput(currentInput);
101
102 if (currentInput > _result)
103 _result = currentInput;;
104 }
105
106 return true;
107}
108
109//-----------------------------------------------------------------------------------------------------
110
115template<class PointT>
117{
118 Scalar minInput=0, maxInput=0;
119 if (getMinInput(minInput) && getMaxInput(maxInput)) {
120 return ((maxInput - minInput) * FPS);
121 }
122
123 return 0;
124}
125
126//-----------------------------------------------------------------------------------------------------
127
128template<class PointT>
130 //Use the reference pose of the first (in terms of the input value, i.e. the time in most cases)
131
132 if (interpolationAnimations_.size() == 0)
133 return NULL;
134
135 Scalar minValue=0; uint minInterpolationAnimationIndex = 0;
136 for (uint i=0; i<interpolationAnimations_.size(); ++i) {
137 Scalar currentValue;
138 interpolationAnimations_[i]->getMinInput(currentValue);
139 Scalar minValueTmp = std::min(minValue, currentValue);
140 minInterpolationAnimationIndex = (minValueTmp < minValue) ? i : minInterpolationAnimationIndex;
141 }
142
143 return pose(_iFrame, interpolationAnimations_[minValue]->getReference());
144}
145
146//-----------------------------------------------------------------------------------------------------
147
148template<class PointT>
150 if (_iFrame == 0)
151 return _reference;
152
153 Pose* newPose = NULL;
154 Pose* referenceCopy = new Pose(*_reference);
155
156 for (uint i=0; i<interpolationAnimations_.size(); ++i) {
157 Scalar minInput, maxInput;
158 interpolationAnimations_[i]->getMinInput(minInput); interpolationAnimations_[i]->getMaxInput(maxInput);
159
160 unsigned int minFrame = (minInput * FPS);
161 unsigned int maxFrame = (maxInput * FPS);
162
163 //Check, if the current animation is responsible for displaying this frame
164 if (_iFrame < minFrame || _iFrame > maxFrame)
165 continue;
166
167 if (interpolationAnimations_[i]) {
168 if (newPose == NULL)
169 newPose = interpolationAnimations_[i]->pose(_iFrame - minFrame, referenceCopy);
170 else
171 newPose = interpolationAnimations_[i]->pose(_iFrame - minFrame, newPose);
172 }
173 }
174
175 delete referenceCopy;
176
177 if (newPose == NULL)
178 newPose = _reference;
179
180 return newPose;
181}
182
183//-----------------------------------------------------------------------------------------------------
184
185template<class PointT>
187 if ( _index < interpolationAnimations_.size() )
188 return interpolationAnimations_[ _index ];
189 else
190 return 0;
191}
192
193//-----------------------------------------------------------------------------------------------------
194
Stores a single animation.
Definition AnimationT.hh:59
virtual Pose * pose(unsigned int _iFrame)
get a pose
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:59