Developer Documentation
FrameAnimationT_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 FRAMEANIMATIONT_C
45
46#include <vector>
47#include <cassert>
48
49//-----------------------------------------------------------------------------
50
61template<class PointT>
63 skeleton_(_pose.skeleton_)
64{
65 poses_.push_back(new Pose(_pose));
66}
67
68//-----------------------------------------------------------------------------
69
74template<class PointT>
76 skeleton_(_skeleton)
77{
78}
79
80//-----------------------------------------------------------------------------
81
91template<class PointT>
92FrameAnimationT<PointT>::FrameAnimationT(Skeleton* _skeleton, unsigned int _iNumFrames) :
93 skeleton_(_skeleton)
94{
95 for(unsigned int i = 0; i < _iNumFrames; ++i)
96 poses_.push_back(new Pose(_skeleton));
97}
98
99//-----------------------------------------------------------------------------
100
109template<class PointT>
111 AnimationT<PointT>(),
112 skeleton_(_other.skeleton_)
113{
114 for(typename std::vector<Pose*>::const_iterator it = _other.poses_.begin(); it != _other.poses_.end(); ++it)
115 poses_.push_back(new Pose(**it));
116}
117
118//-----------------------------------------------------------------------------
119
123template<class PointT>
125{
126 for(typename std::vector<Pose*>::iterator it = poses_.begin(); it != poses_.end(); ++it)
127 delete *it;
128 poses_.clear();
129}
130
131//-----------------------------------------------------------------------------
132
136template<class PointT>
138 return new FrameAnimationT<PointT>(*this);
139}
140
141//-----------------------------------------------------------------------------
142
143
144template<class PointT>
146{
147 assert(_iFrame < poses_.size());
148
149 return poses_[_iFrame];
150}
151
152//-----------------------------------------------------------------------------
153
154template<class PointT>
156{
157 return poses_.size();
158}
159
160//-----------------------------------------------------------------------------
161
162template<class PointT>
164{
165 //delete poses
166 while ( _frames < poses_.size() ){
167 Pose* pose = poses_.back();
168 poses_.pop_back();
169 delete pose;
170 }
171
172 //add poses
173 while ( _frames > poses_.size() )
174 poses_.push_back(new Pose(skeleton_));
175}
176
177//-----------------------------------------------------------------------------
178
179
180template<class PointT>
182{
183 for(typename std::vector<Pose*>::iterator it = poses_.begin(); it != poses_.end(); ++it)
184 (*it)->insertJointAt(_index);
185}
186
187//-----------------------------------------------------------------------------
188
189
190template<class PointT>
192{
193 for(typename std::vector<Pose*>::iterator it = poses_.begin(); it != poses_.end(); ++it)
194 (*it)->removeJointAt(_index);
195}
196
197//-----------------------------------------------------------------------------
198
206template<class PointT>
208{
209 for(typename std::vector<Pose*>::iterator it = poses_.begin(); it != poses_.end(); ++it)
210 (*it)->updateFromGlobal(_index);
211}
212
213//-----------------------------------------------------------------------------
Stores a single animation.
Definition: AnimationT.hh:59
virtual ~FrameAnimationT()
Destructor.
std::vector< Pose * > poses_
Every entry in this vector is a frame of the animation.
virtual void updateFromGlobal(unsigned int _index)
Updates the local matrix using the global matrix.
void removeJointAt(unsigned int _index)
Called by the skeleton as a joint is deleted.
void setFrameCount(unsigned int _frames)
Set number of frames stored in this pose.
unsigned int frameCount()
Returns the number of frames stored in this pose.
FrameAnimationT(const PoseT< PointT > &_pose)
Constructor - Creates a new animation consisting of a single pose.
void insertJointAt(unsigned int _index)
Called by the skeleton as a new joint is inserted.
virtual AnimationT< PointT > * copy()
Copy Function.
Pose * pose(unsigned int _iFrame)
Returns a pointer to the pose stored in the given frame.
A general pose, used to store the frames of the animation.
Definition: PoseT.hh:59