Developer Documentation
PoseT.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 #pragma once
43 
44 #include "ACG/Math/Matrix4x4T.hh"
45 
46 #include "ACG/Math/QuaternionT.hh"
47 #include "ACG/Math/DualQuaternionT.hh"
48 
49 
50 template<typename PointT>
51 class SkeletonT;
52 
57 template<typename PointT>
58 class PoseT
59 {
60  template<typename>
61  friend class SkeletonT;
62  template<typename>
63  friend class AnimationT;
64  template<typename>
65  friend class FrameAnimationT;
66 
67 protected:
68  typedef PointT Point;
69  typedef typename Point::value_type Scalar;
70  typedef typename ACG::VectorT<Scalar, 3> Vector;
71  typedef typename ACG::Matrix4x4T<Scalar> Matrix;
72  typedef typename ACG::QuaternionT<Scalar> Quaternion;
74 
75 public:
77  explicit PoseT(SkeletonT<Point>* _skeleton);
78 
80  explicit PoseT(const PoseT<PointT>& _other);
81 
83  virtual ~PoseT();
84 
85  // =======================================================================================
90  // =======================================================================================
91 
94  inline const Matrix& localMatrix(unsigned int _joint) const;
95  void setLocalMatrix(unsigned int _joint, const Matrix &_local, bool _keepLocalChildPositions=true);
96  inline Vector localTranslation(unsigned int _joint);
97  void setLocalTranslation(unsigned int _joint, const Vector &_position, bool _keepLocalChildPositions=true);
98 
99  inline Matrix localMatrixInv(unsigned int _joint) const;
100 
103  inline const Matrix& globalMatrix(unsigned int _joint) const;
104  void setGlobalMatrix(unsigned int _joint, const Matrix &_global, bool _keepGlobalChildPositions=true);
105  inline Vector globalTranslation(unsigned int _joint);
106  void setGlobalTranslation(unsigned int _joint, const Vector &_position, bool _keepGlobalChildPositions=true);
107 
108  virtual Matrix globalMatrixInv(unsigned int _joint) const;
109 
112  // =======================================================================================
117  // =======================================================================================
118 
130  virtual void insertJointAt(size_t _index);
131 
143  virtual void removeJointAt(size_t _index);
144 
147 protected:
148  // =======================================================================================
154  // =======================================================================================
155 
156  void updateFromLocal(size_t _joint, bool _keepChildPositions=true);
157  void updateFromGlobal(size_t _joint, bool _keepChildPositions=true);
158 
161 public:
162 
163  // =======================================================================================
168  // =======================================================================================
169 
170  inline const Matrix& unifiedMatrix(size_t _joint);
171  inline const Quaternion& unifiedRotation(size_t _joint);
172  inline const DualQuaternion& unifiedDualQuaternion(size_t _joint);
173 
176 protected:
177 
181  std::vector<Matrix> local_;
183  std::vector<Matrix> global_;
184 
186  std::vector<Matrix> unified_;
187 
190  std::vector<DualQuaternion> unifiedDualQuaternion_;
191 };
192 
193 //=============================================================================
194 //=============================================================================
195 #if defined(INCLUDE_TEMPLATES) && !defined(POSET_C)
196 #define POSET_TEMPLATES
197 #include "PoseT_impl.hh"
198 #endif
199 
200 
virtual Matrix globalMatrixInv(unsigned int _joint) const
Simply returns the inverse of the global matrix.
Definition: PoseT_impl.hh:267
virtual ~PoseT()
Destructor.
Definition: PoseT_impl.hh:91
Matrix localMatrixInv(unsigned int _joint) const
Simply returns the inverse of the local matrix.
Definition: PoseT_impl.hh:176
void setGlobalMatrix(unsigned int _joint, const Matrix &_global, bool _keepGlobalChildPositions=true)
Sets the global coordinate system.
Definition: PoseT_impl.hh:211
const Matrix & unifiedMatrix(size_t _joint)
Returns the unified matrix.
Definition: PoseT_impl.hh:397
void setGlobalTranslation(unsigned int _joint, const Vector &_position, bool _keepGlobalChildPositions=true)
Sets the global translation vector.
Definition: PoseT_impl.hh:249
const Quaternion & unifiedRotation(size_t _joint)
Returns a quaternion holding the rotational part of the unified matrix.
Definition: PoseT_impl.hh:415
void updateFromLocal(size_t _joint, bool _keepChildPositions=true)
This method propagates the change in the local coordinate system to the global system and all childre...
Definition: PoseT_impl.hh:315
std::vector< DualQuaternion > unifiedDualQuaternion_
Definition: PoseT.hh:190
DualQuaternion class for representing rigid motions in 3d.
Stores a single animation.
Definition: AnimationT.hh:58
A general pose, used to store the frames of the animation.
Definition: PoseT.hh:58
void setLocalTranslation(unsigned int _joint, const Vector &_position, bool _keepLocalChildPositions=true)
Sets the local translation vector.
Definition: PoseT_impl.hh:161
ACG::Vec3d Vector
Standard Type for 3d Vector used for scripting.
Definition: DataTypes.hh:174
PoseT(SkeletonT< Point > *_skeleton)
Constructor.
Definition: PoseT_impl.hh:59
const Matrix & localMatrix(unsigned int _joint) const
Returns the local matrix for the given joint.
Definition: PoseT_impl.hh:104
std::vector< Matrix > unified_
the global pose matrix left-multiplied to the inverse global reference matrix:
Definition: PoseT.hh:186
virtual void insertJointAt(size_t _index)
Called by the skeleton/animation as a new joint is inserted.
Definition: PoseT_impl.hh:281
std::vector< Matrix > local_
the pose in local coordinates
Definition: PoseT.hh:181
SkeletonT< PointT > * skeleton_
a pointer to the skeleton
Definition: PoseT.hh:179
const DualQuaternion & unifiedDualQuaternion(size_t _joint)
Returns a dual quaternion holding the unified matrix represented as dual quaternion.
Definition: PoseT_impl.hh:431
void updateFromGlobal(size_t _joint, bool _keepChildPositions=true)
This method propagates the change in the global coordinate system to the local system and all childre...
Definition: PoseT_impl.hh:353
Vector localTranslation(unsigned int _joint)
Returns the local translation vector.
Definition: PoseT_impl.hh:139
virtual void removeJointAt(size_t _index)
Called by the skeleton/animation as a joint is removed.
Definition: PoseT_impl.hh:298
const Matrix & globalMatrix(unsigned int _joint) const
Returns the global matrix for the given joint.
Definition: PoseT_impl.hh:193
void setLocalMatrix(unsigned int _joint, const Matrix &_local, bool _keepLocalChildPositions=true)
Sets the local coordinate system.
Definition: PoseT_impl.hh:120
std::vector< Matrix > global_
the pose in global coordinates
Definition: PoseT.hh:183
Vector globalTranslation(unsigned int _joint)
Returns the global translation vector.
Definition: PoseT_impl.hh:227