Blender  V2.59
MT_ExpMap.h
Go to the documentation of this file.
00001 /*
00002  * $Id: MT_ExpMap.h 35154 2011-02-25 11:43:19Z jesterking $
00003  * ***** BEGIN GPL LICENSE BLOCK *****
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software Foundation,
00017  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018  *
00019  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00020  * All rights reserved.
00021  *
00022  * The Original Code is: all of this file.
00023  *
00024  * Original author: Laurence
00025  * Contributor(s): Brecht
00026  *
00027  * ***** END GPL LICENSE BLOCK *****
00028  */
00029 
00035 #ifndef MT_ExpMap_H
00036 #define MT_ExpMap_H
00037 
00038 #include <MT_assert.h>
00039 
00040 #include "MT_Vector3.h"
00041 #include "MT_Quaternion.h"
00042 #include "MT_Matrix4x4.h"
00043 
00044 const MT_Scalar MT_EXPMAP_MINANGLE (1e-7);
00045 
00081 class MT_ExpMap {
00082 public:
00083 
00090     MT_ExpMap() {}
00091     MT_ExpMap(const MT_Vector3& v) : m_v(v) { angleUpdated(); }
00092 
00093     MT_ExpMap(const float v[3]) : m_v(v) { angleUpdated(); }
00094     MT_ExpMap(const double v[3]) : m_v(v) { angleUpdated(); }
00095 
00096     MT_ExpMap(MT_Scalar x, MT_Scalar y, MT_Scalar z) :
00097         m_v(x, y, z) { angleUpdated(); }
00098 
00103         MT_ExpMap(
00104                 const MT_Quaternion &q
00105         ) {
00106                 setRotation(q);
00107         };
00108 
00117         const 
00118                 MT_Vector3 &
00119         vector(
00120         ) const {
00121                 return m_v;
00122         };
00123 
00128                 void
00129         setRotation(
00130                 const MT_Quaternion &q
00131         );
00132 
00138                 const MT_Quaternion&
00139         getRotation(
00140         ) const;
00141 
00146                 MT_Matrix3x3
00147         getMatrix(
00148         ) const; 
00149         
00155                 void
00156         update(
00157                 const MT_Vector3& dv
00158         );
00159 
00166                 void
00167         partialDerivatives(
00168                 MT_Matrix3x3& dRdx,
00169                 MT_Matrix3x3& dRdy,
00170                 MT_Matrix3x3& dRdz
00171         ) const ;
00172         
00173 private :
00174 
00175         // m_v contains the exponential map, the other variables are
00176         // cached for efficiency
00177         
00178         MT_Vector3 m_v;
00179         MT_Scalar m_theta, m_sinp;
00180         MT_Quaternion m_q;
00181 
00182         // private methods
00183 
00184         // Compute partial derivatives dR (3x3 rotation matrix) / dVi (EM vector)
00185         // given the partial derivative dQ (Quaternion) / dVi (ith element of EM vector)
00186 
00187                 void
00188         compute_dRdVi(
00189                 const MT_Quaternion &dQdV,
00190                 MT_Matrix3x3 & dRdVi
00191         ) const;
00192 
00193         // compute partial derivatives dQ/dVi
00194 
00195                 void
00196         compute_dQdVi(
00197                 MT_Quaternion *dQdX
00198         ) const ; 
00199 
00200         // reparametrize away from singularity
00201 
00202                 void
00203         reParametrize(
00204         );
00205 
00206         // (re-)compute cached variables
00207 
00208                 void
00209         angleUpdated(
00210         );
00211 };
00212 
00213 #endif
00214