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 
61 template<class PointT>
63  skeleton_(_pose.skeleton_)
64 {
65  poses_.push_back(new Pose(_pose));
66 }
67 
68 //-----------------------------------------------------------------------------
69 
74 template<class PointT>
76  skeleton_(_skeleton)
77 {
78 }
79 
80 //-----------------------------------------------------------------------------
81 
91 template<class PointT>
92 FrameAnimationT<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 
109 template<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 
123 template<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 
136 template<class PointT>
138  return new FrameAnimationT<PointT>(*this);
139 }
140 
141 //-----------------------------------------------------------------------------
142 
143 
144 template<class PointT>
146 {
147  assert(_iFrame < poses_.size());
148 
149  return poses_[_iFrame];
150 }
151 
152 //-----------------------------------------------------------------------------
153 
154 template<class PointT>
156 {
157  return poses_.size();
158 }
159 
160 //-----------------------------------------------------------------------------
161 
162 template<class PointT>
163 void FrameAnimationT<PointT>::setFrameCount(unsigned int _frames)
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 
180 template<class PointT>
181 void FrameAnimationT<PointT>::insertJointAt(unsigned int _index)
182 {
183  for(typename std::vector<Pose*>::iterator it = poses_.begin(); it != poses_.end(); ++it)
184  (*it)->insertJointAt(_index);
185 }
186 
187 //-----------------------------------------------------------------------------
188 
189 
190 template<class PointT>
191 void FrameAnimationT<PointT>::removeJointAt(unsigned int _index)
192 {
193  for(typename std::vector<Pose*>::iterator it = poses_.begin(); it != poses_.end(); ++it)
194  (*it)->removeJointAt(_index);
195 }
196 
197 //-----------------------------------------------------------------------------
198 
206 template<class PointT>
208 {
209  for(typename std::vector<Pose*>::iterator it = poses_.begin(); it != poses_.end(); ++it)
210  (*it)->updateFromGlobal(_index);
211 }
212 
213 //-----------------------------------------------------------------------------
void removeJointAt(unsigned int _index)
Called by the skeleton as a joint is deleted.
unsigned int frameCount()
Returns the number of frames stored in this pose.
virtual void updateFromGlobal(unsigned int _index)
Updates the local matrix using the global matrix.
Skeleton * skeleton_
Pointer to associated skeleton.
Stores a single animation.
Definition: AnimationT.hh:58
A general pose, used to store the frames of the animation.
Definition: PoseT.hh:58
Pose * pose(unsigned int _iFrame)
Returns a pointer to the pose stored in the given frame.
FrameAnimationT(const PoseT< PointT > &_pose)
Constructor - Creates a new animation consisting of a single pose.
std::vector< Pose * > poses_
Every entry in this vector is a frame of the animation.
virtual ~FrameAnimationT()
Destructor.
void setFrameCount(unsigned int _frames)
Set number of frames stored in this pose.
void insertJointAt(unsigned int _index)
Called by the skeleton as a new joint is inserted.
virtual AnimationT< PointT > * copy()
Copy Function.