Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
FrameAnimationT.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 FRAMEANIMATIONT_C
51 
52 #include <vector>
53 #include <cassert>
54 
55 //-----------------------------------------------------------------------------
56 
67 template<class PointT>
69  skeleton_(_pose.skeleton_)
70 {
71  poses_.push_back(new Pose(_pose));
72 }
73 
74 //-----------------------------------------------------------------------------
75 
80 template<class PointT>
82  skeleton_(_skeleton)
83 {
84 }
85 
86 //-----------------------------------------------------------------------------
87 
97 template<class PointT>
98 FrameAnimationT<PointT>::FrameAnimationT(Skeleton* _skeleton, unsigned int _iNumFrames) :
99  skeleton_(_skeleton)
100 {
101  for(unsigned int i = 0; i < _iNumFrames; ++i)
102  poses_.push_back(new Pose(_skeleton));
103 }
104 
105 //-----------------------------------------------------------------------------
106 
115 template<class PointT>
117  AnimationT<PointT>(),
118  skeleton_(_other.skeleton_)
119 {
120  for(typename std::vector<Pose*>::const_iterator it = _other.poses_.begin(); it != _other.poses_.end(); ++it)
121  poses_.push_back(new Pose(**it));
122 }
123 
124 //-----------------------------------------------------------------------------
125 
129 template<class PointT>
131 {
132  for(typename std::vector<Pose*>::iterator it = poses_.begin(); it != poses_.end(); ++it)
133  delete *it;
134  poses_.clear();
135 }
136 
137 //-----------------------------------------------------------------------------
138 
142 template<class PointT>
144  return new FrameAnimationT<PointT>(*this);
145 }
146 
147 //-----------------------------------------------------------------------------
148 
149 
150 template<class PointT>
152 {
153  assert(_iFrame < poses_.size());
154 
155  return poses_[_iFrame];
156 }
157 
158 //-----------------------------------------------------------------------------
159 
160 template<class PointT>
162 {
163  return poses_.size();
164 }
165 
166 //-----------------------------------------------------------------------------
167 
168 template<class PointT>
169 void FrameAnimationT<PointT>::setFrameCount(unsigned int _frames)
170 {
171  //delete poses
172  while ( _frames < poses_.size() ){
173  Pose* pose = poses_.back();
174  poses_.pop_back();
175  delete pose;
176  }
177 
178  //add poses
179  while ( _frames > poses_.size() )
180  poses_.push_back(new Pose(skeleton_));
181 }
182 
183 //-----------------------------------------------------------------------------
184 
185 
186 template<class PointT>
187 void FrameAnimationT<PointT>::insertJointAt(unsigned int _index)
188 {
189  for(typename std::vector<Pose*>::iterator it = poses_.begin(); it != poses_.end(); ++it)
190  (*it)->insertJointAt(_index);
191 }
192 
193 //-----------------------------------------------------------------------------
194 
195 
196 template<class PointT>
197 void FrameAnimationT<PointT>::removeJointAt(unsigned int _index)
198 {
199  for(typename std::vector<Pose*>::iterator it = poses_.begin(); it != poses_.end(); ++it)
200  (*it)->removeJointAt(_index);
201 }
202 
203 //-----------------------------------------------------------------------------
204 
212 template<class PointT>
214 {
215  for(typename std::vector<Pose*>::iterator it = poses_.begin(); it != poses_.end(); ++it)
216  (*it)->updateFromGlobal(_index);
217 }
218 
219 //-----------------------------------------------------------------------------
virtual void updateFromGlobal(unsigned int _index)
Updates the local matrix using the global matrix.
void insertJointAt(unsigned int _index)
Called by the skeleton as a new joint is inserted.
virtual AnimationT< PointT > * copy()
Copy Function.
Pose * pose(const AnimationHandle &_hAni)
Returns a pointer to the pose with the given animation handle.
Definition: SkeletonT.cc:741
A general pose, used to store the frames of the animation.
Definition: PoseT.hh:68
FrameAnimationT(const PoseT< PointT > &_pose)
Constructor - Creates a new animation consisting of a single pose.
Pose * pose(unsigned int _iFrame)
Returns a pointer to the pose stored in the given frame.
std::vector< Pose * > poses_
Every entry in this vector is a frame of the animation.
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.
Stores a single animation.
Definition: AnimationT.hh:67
virtual ~FrameAnimationT()
Destructor.
unsigned int frameCount()
Returns the number of frames stored in this pose.