Frame.h

Go to the documentation of this file.
00001 /******************************************************************************
00002 *       SOFA, Simulation Open-Framework Architecture, version 1.0 beta 3      *
00003 *                (c) 2006-2008 MGH, INRIA, USTL, UJF, CNRS                    *
00004 *                                                                             *
00005 * This library is free software; you can redistribute it and/or modify it     *
00006 * under the terms of the GNU Lesser General Public License as published by    *
00007 * the Free Software Foundation; either version 2.1 of the License, or (at     *
00008 * your option) any later version.                                             *
00009 *                                                                             *
00010 * This library is distributed in the hope that it will be useful, but WITHOUT *
00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
00013 * for more details.                                                           *
00014 *                                                                             *
00015 * You should have received a copy of the GNU Lesser General Public License    *
00016 * along with this library; if not, write to the Free Software Foundation,     *
00017 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.          *
00018 *******************************************************************************
00019 *                              SOFA :: Framework                              *
00020 *                                                                             *
00021 * Authors: M. Adam, J. Allard, B. Andre, P-J. Bensoussan, S. Cotin, C. Duriez,*
00022 * H. Delingette, F. Falipou, F. Faure, S. Fonteneau, L. Heigeas, C. Mendoza,  *
00023 * M. Nesme, P. Neumann, J-P. de la Plata Alcade, F. Poyer and F. Roy          *
00024 *                                                                             *
00025 * Contact information: contact@sofa-framework.org                             *
00026 ******************************************************************************/
00027 #ifndef SOFA_DEFAULTTYPE_FRAME_H
00028 #define SOFA_DEFAULTTYPE_FRAME_H
00029 
00030 #include <sofa/defaulttype/Vec.h>
00031 #include <sofa/defaulttype/Mat.h>
00032 #include <sofa/helper/Quater.h>
00033 
00034 namespace sofa
00035 {
00036 
00037 namespace defaulttype
00038 {
00039 
00048 class Frame
00049 {
00050 public: 
00051         typedef Vec<3,SReal> Vec3;
00052         typedef helper::Quater<SReal> Quat;
00053         typedef Mat<3,3,SReal> Mat33;
00054 private:
00055         Vec3 origin_;
00056         Mat33 basis_;
00057 public:
00059         Frame (const Vec3 &origin, const Mat33& m );
00060 
00062         Frame (const Vec3 &origin, const Quat &orientation, const Vec3& scale=Vec3(1,1,1) );
00063 
00065         Frame (const Vec3 &origin );
00066 
00068         Frame ();
00069 
00071         void setTransform( const Vec3& origin, const Quat& orientation, const Vec3& scale );
00072 
00074         void clear();
00075 
00077         Vec3& getOrigin ();
00078 
00080         const Vec3& getOrigin () const;
00081 
00083         void setOrigin( const Vec3& origin );
00084 
00086         Mat33& getBasis ();
00087 
00089         const Mat33& getBasis () const;
00090 
00092         void setBasis( const Mat33& m );
00093 
00095         static Frame identity(); 
00096 
00098         void multRight( const Frame& c );
00099 
00101         Frame mult( const Frame& c ) const;
00102 
00104         void writeOpenGlMatrix( float* m ) const;
00105 
00107         void writeOpenGlMatrix( double* m ) const;
00108 
00110         template<class V>
00111         V projectVector( const V& v ) const
00112         {
00113                 return V(
00114                                basis_[0][0]*v[0]+basis_[0][1]*v[1]+basis_[0][2]*v[2],
00115                                basis_[1][0]*v[0]+basis_[1][1]*v[1]+basis_[1][2]*v[2],
00116                                basis_[2][0]*v[0]+basis_[2][1]*v[1]+basis_[2][2]*v[2]
00117                        );
00118         }
00119 
00121         template<class V>
00122         V projectPoint( const V& v ) const
00123         {
00124                 return projectVector(v)+origin_;
00125         }
00126 
00128         Frame inversed() const;
00129 
00130         friend std::ostream& operator << (std::ostream& out, const Frame& c );
00131 };
00132 } // namespace defaulttype
00133 
00134 } // namespace sofa
00135 #endif

Generated on Sun Nov 23 02:29:27 2008 for Sofa by  doxygen 1.5.7.1