FrameAnimationT.cc 8.68 KB
Newer Older
1
2
3
/*===========================================================================*\
*                                                                            *
*                              OpenFlipper                                   *
Jan Möbius's avatar
Jan Möbius committed
4
*      Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen       *
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
*                           www.openflipper.org                              *
*                                                                            *
*--------------------------------------------------------------------------- *
*  This file is part of OpenFlipper.                                         *
*                                                                            *
*  OpenFlipper is free software: you can redistribute it and/or modify       *
*  it under the terms of the GNU Lesser General Public License as            *
*  published by the Free Software Foundation, either version 3 of            *
*  the License, or (at your option) any later version with the               *
*  following exceptions:                                                     *
*                                                                            *
*  If other files instantiate templates or use macros                        *
*  or inline functions from this file, or you compile this file and          *
*  link it with other files to produce an executable, this file does         *
*  not by itself cause the resulting executable to be covered by the         *
*  GNU Lesser General Public License. This exception does not however        *
*  invalidate any other reasons why the executable file might be             *
*  covered by the GNU Lesser General Public License.                         *
*                                                                            *
*  OpenFlipper is distributed in the hope that it will be useful,            *
*  but WITHOUT ANY WARRANTY; without even the implied warranty of            *
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
*  GNU Lesser General Public License for more details.                       *
*                                                                            *
*  You should have received a copy of the GNU LesserGeneral Public           *
*  License along with OpenFlipper. If not,                                   *
*  see <http://www.gnu.org/licenses/>.                                       *
*                                                                            *
\*===========================================================================*/

/*===========================================================================*\
*                                                                            *
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
*                                                                            *
\*===========================================================================*/

Dirk Wilden's avatar
Dirk Wilden committed
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#define FRAMEANIMATIONT_C

#include <vector>
#include <assert.h>

using namespace std;

//-----------------------------------------------------------------------------

/**
 * @brief Constructor - Creates a new animation consisting of a single pose
 *
 * The animation will hold a single frame, made up by a copy of the given pose. After this call returns the
 * pose given by \e _pose is no longer needed and independent from this instance.
 *
 * You can use this operation to clone the reference pose as new instance, then modify the pose.
 *
 * @param _pose This pose will make up the only frame in this new animation
 */
62
template<class PointT>
Dirk Wilden's avatar
Dirk Wilden committed
63
64
65
66
67
68
69
70
71
72
73
74
75
76
FrameAnimationT<PointT>::FrameAnimationT(const PoseT<PointT> &_pose) :
  skeleton_(_pose.skeleton_)
{
  poses_.push_back(new Pose(_pose));
}

//-----------------------------------------------------------------------------

/**
 * @brief Constructor - Creates a new empty animation
 *
 * @param _hierarchy The skeleton that will hold this animation
 * @param _reference The skeletons reference pose
 */
77
template<class PointT>
Dirk Wilden's avatar
Dirk Wilden committed
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
FrameAnimationT<PointT>::FrameAnimationT(Skeleton* _skeleton) :
  skeleton_(_skeleton)
{
}

//-----------------------------------------------------------------------------

/**
 * @brief Constructor - Creates a new animation with the given number of frames
 *
 * The poses in the given number of frames will all hold identity matrices for all joints. Make sure you write
 * data to the poses before you use it.
 *
 * @param _hierarchy The skeleton that will hold this animation
 * @param _reference The skeletons reference pose
 * @param _iNumFrames The number of frames for this animation
 */
95
template<class PointT>
Dirk Wilden's avatar
Dirk Wilden committed
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
FrameAnimationT<PointT>::FrameAnimationT(Skeleton* _skeleton, unsigned int _iNumFrames) :
  skeleton_(_skeleton)
{
  for(unsigned int i = 0; i < _iNumFrames; ++i)
    poses_.push_back(new Pose(_skeleton));
}

//-----------------------------------------------------------------------------

/**
 * @brief Copy constructor
 *
 * This animation will copy all frames from the given animation. After the call returns they are completely
 * independent.
 *
 * @param _other The animation to copy from
 */
113
template<class PointT>
Dirk Wilden's avatar
Dirk Wilden committed
114
115
116
117
118
119
120
121
122
123
124
125
126
FrameAnimationT<PointT>::FrameAnimationT(const FrameAnimationT<PointT> &_other) :
  AnimationT<PointT>(),
  skeleton_(_other.skeleton_)
{
  for(typename vector<Pose*>::const_iterator it = _other.poses_.begin(); it != _other.poses_.end(); ++it)
    poses_.push_back(new Pose(**it));
}

//-----------------------------------------------------------------------------

/**
 * @brief Destructor
 */
127
template<class PointT>
Dirk Wilden's avatar
Dirk Wilden committed
128
129
130
131
132
133
134
135
136
137
138
139
FrameAnimationT<PointT>::~FrameAnimationT()
{
  for(typename vector<Pose*>::iterator it = poses_.begin(); it != poses_.end(); ++it)
    delete *it;
  poses_.clear();
}

//-----------------------------------------------------------------------------

/**
 * @brief Copy Function
 */
140
template<class PointT>
Dirk Wilden's avatar
Dirk Wilden committed
141
142
143
144
145
146
147
148
149
150
151
AnimationT<PointT>* FrameAnimationT<PointT>::copy() {
  return new FrameAnimationT<PointT>(*this);
}

//-----------------------------------------------------------------------------

/**
 * @brief Returns a pointer to the pose stored in the given frame
 *
 * @param _iFrame The poses frame number
 */
152
template<class PointT>
Dirk Wilden's avatar
Dirk Wilden committed
153
154
155
156
157
158
159
160
161
162
163
164
typename FrameAnimationT<PointT>::Pose *FrameAnimationT<PointT>::pose(unsigned int _iFrame)
{
  assert(_iFrame < poses_.size());

  return poses_[_iFrame];
}

//-----------------------------------------------------------------------------

/**
 * @brief Returns the number of frames stored in this pose
 */
165
template<class PointT>
Dirk Wilden's avatar
Dirk Wilden committed
166
167
168
169
170
171
172
unsigned int FrameAnimationT<PointT>::frameCount()
{
  return poses_.size();
}

//-----------------------------------------------------------------------------

173
template<class PointT>
Dirk Wilden's avatar
Dirk Wilden committed
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
void FrameAnimationT<PointT>::setFrameCount(unsigned int _frames)
{
  //delete poses
  while ( _frames < poses_.size() ){
    Pose* pose = poses_.back();
    poses_.pop_back();
    delete pose;
  }
  
  //add poses
  while ( _frames > poses_.size() )
    poses_.push_back(new Pose(skeleton_));
}

//-----------------------------------------------------------------------------

/**
 * @brief Called by the skeleton as a new joint is inserted
 *
 * The call is dispatched to all poses stored in this animation. See BasePoseT::insert_at for more information.
 *
 * @param _index The new joint is inserted at this position. Insert new joints at the end by passing
 *                               SkeletonT::joints_.size as parameter.
 */
198
template<class PointT>
Dirk Wilden's avatar
Dirk Wilden committed
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
void FrameAnimationT<PointT>::insertJointAt(unsigned int _index)
{
  for(typename vector<Pose*>::iterator it = poses_.begin(); it != poses_.end(); ++it)
    (*it)->insertJointAt(_index);
}

//-----------------------------------------------------------------------------

/**
 * @brief Called by the skeleton as a joint is deleted
 *
 * The call is dispatched to all poses stored in this animation. See BasePoseT::remove_at for more information.
 *
 * @param _index The index of the joint that is being deleted.
 */
214
template<class PointT>
Dirk Wilden's avatar
Dirk Wilden committed
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
void FrameAnimationT<PointT>::removeJointAt(unsigned int _index)
{
  for(typename vector<Pose*>::iterator it = poses_.begin(); it != poses_.end(); ++it)
    (*it)->removeJointAt(_index);
}

//-----------------------------------------------------------------------------

/**
 * @brief Updates the local matrix using the global matrix
 *
 * Called when a joints parent is changed.
 *
 * @param _index The joints index
 */
230
template<class PointT>
Dirk Wilden's avatar
Dirk Wilden committed
231
232
233
234
235
236
237
void FrameAnimationT<PointT>::updateFromGlobal(unsigned int _index)
{
  for(typename vector<Pose*>::iterator it = poses_.begin(); it != poses_.end(); ++it)
    (*it)->updateFromGlobal(_index);
}

//-----------------------------------------------------------------------------