SolidTypes.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 // C++ Interface: SolidTypes
00028 //
00029 // Description: Base types for coordinate systems and articulated bodies
00030 //
00031 //
00032 // Author: Francois Faure, INRIA-UJF, (C) 2006
00033 //
00034 // Copyright: See COPYING file that comes with this distribution
00035 //
00036 //
00037 #ifndef SOFA_DEFAULTTYPE_SOLIDTYPES_H
00038 #define SOFA_DEFAULTTYPE_SOLIDTYPES_H
00039 
00040 //#include <sofa/core/objectmodel/BaseContext.h>
00041 #include <sofa/defaulttype/Vec.h>
00042 #include <sofa/defaulttype/Quat.h>
00043 #include <sofa/defaulttype/Mat.h>
00044 #include <sofa/helper/fixed_array.h>
00045 #include <sofa/helper/vector.h>
00046 #include <iostream>
00047 
00048 namespace sofa
00049 {
00050 
00051 namespace defaulttype
00052 {
00053 
00059 template< class R=float >
00060 class SolidTypes
00061 {
00062 public:
00063     typedef R Real;
00064     typedef defaulttype::Vec<3,Real> Vec;
00065     typedef helper::Quater<Real> Rot;
00066     typedef defaulttype::Mat<3,3,Real> Mat;
00067     typedef defaulttype::Mat<6,6,Real> Mat66;
00068     typedef defaulttype::Vec<6,Real> DOF;
00069 
00070 
00071 
00075     class SpatialVector
00076     {
00077     public:
00078         Vec lineVec;
00079         Vec freeVec;
00080         void clear();
00081         SpatialVector();
00086         SpatialVector( const Vec& l, const Vec& f );
00087         SpatialVector& operator += (const SpatialVector& v);
00088 
00089         //template<class Real2>
00090         SpatialVector operator * ( Real a ) const
00091         {
00092             return SpatialVector( lineVec *a, freeVec * a);
00093         }
00094 
00095         //template<class Real2>
00096         SpatialVector& operator *= ( Real a )
00097         {
00098             lineVec *=a;
00099             freeVec *= a;
00100             return *this;
00101         }
00102 
00103         SpatialVector operator + ( const SpatialVector& v ) const;
00104         SpatialVector operator - ( const SpatialVector& v ) const;
00105         SpatialVector operator - ( ) const;
00107         Real operator * ( const SpatialVector& v ) const;
00109         SpatialVector cross( const SpatialVector& v ) const;
00111         SpatialVector operator * (const Mat66&) const;
00113         inline friend std::ostream& operator << (std::ostream& out, const SpatialVector& t )
00114         {
00115             out<<t.lineVec<<" "<<t.freeVec;
00116             return out;
00117         }
00120         Vec& getLinearVelocity()
00121         {
00122             return freeVec;
00123         }
00124         const Vec& getLinearVelocity() const
00125         {
00126             return freeVec;
00127         }
00128         void setLinearVelocity(const Vec& v)
00129         {
00130             freeVec = v;
00131         }
00134         Vec& getAngularVelocity()
00135         {
00136             return lineVec;
00137         }
00138         const Vec& getAngularVelocity() const
00139         {
00140             return lineVec;
00141         }
00142         void setAngularVelocity(const Vec& v)
00143         {
00144             lineVec = v;
00145         }
00146 
00149         Vec& getTorque()
00150         {
00151             return freeVec;
00152         }
00153         const Vec& getTorque() const
00154         {
00155             return freeVec;
00156         }
00157         void setTorque(const Vec& v)
00158         {
00159             freeVec = v;
00160         }
00163         Vec& getForce() 
00164         {
00165             return lineVec;
00166         }
00167         const Vec& getForce() const
00168         {
00169             return lineVec;
00170         }
00171         void setForce(const Vec& v)
00172         {
00173             lineVec = v;
00174         }
00175     };
00176 
00183     class Transform
00184     {
00185     public:
00187         Transform();
00189         Transform( const Vec& origin, const Rot& orientation );
00191         Transform( const Rot& q, const Vec& o );
00193         void set( const Vec& t, const Rot& q );
00195         void clear();
00197         static Transform identity();
00199         //static Transform inParent(const Vec& t, const Rot& r);
00201         Transform( const SpatialVector& v );
00203         Transform inversed() const;
00205         const Vec& getOriginOfParentInChild() const;
00207         Vec getOrigin() const;
00209         void setOrigin( const Vec& );
00211         const Rot& getOrientation() const;
00213         void setOrientation( const Rot& );
00215         Mat getRotationMatrix() const;
00217         Vec projectVector( const Vec& vectorInChild ) const;
00219         Vec projectPoint( const Vec& pointInChild ) const;
00221         Vec backProjectVector( const Vec& vectorInParent ) const;
00223         Vec backProjectPoint( const Vec& pointInParent ) const;
00225         Transform operator * (const Transform& f2) const;
00227         Transform& operator *= (const Transform& f2);
00229         SpatialVector operator * (const SpatialVector& sv ) const;
00231         SpatialVector operator / (const SpatialVector& sv ) const;
00233         void writeOpenGlMatrix( double *m ) const;
00235         void glDraw() const;
00237         inline friend std::ostream& operator << (std::ostream& out, const Transform& t )
00238         {
00239             out<<"("<<t.getOrigin()<<")";
00240             out<<"("<<t.getOrientation()<<")";
00241             return out;
00242         }
00244         void printInternal( std::ostream&) const;
00245 
00249 
00250 
00251         Transform& operator +=(const SpatialVector& a);
00252 
00253         Transform& operator +=(const Transform& a);
00254 
00255         template<class Real2>
00256         Transform& operator*=(Real2 a)
00257         {
00258             std::cout << "SolidTypes<R>::Transform::operator *="<<std::endl;
00259             origin_ *= a;
00260             //orientation *= a;
00261             return *this;
00262         }
00263 
00264         template<class Real2>
00265         Transform operator*(Real2 a) const
00266         {
00267             Transform r = *this;
00268             r*=a;
00269             return r;
00270         }
00272 
00273 
00274     protected:
00275         Rot orientation_; 
00276         Vec origin_;  
00277 
00278     };
00279 
00280 
00281     class RigidInertia
00282     {
00283     public:
00284         Real m;  
00285         Vec h;   
00286         Mat I;  
00287         RigidInertia();
00288         RigidInertia( Real m, const Vec& h, const Mat& I );
00289         SpatialVector operator * (const SpatialVector& v ) const;
00290         RigidInertia operator * ( const Transform& t ) const;
00291         inline friend std::ostream& operator << (std::ostream& out, const RigidInertia& r )
00292         {
00293             out<<"I= "<<r.I<<std::endl;
00294             out<<"h= "<<r.h<<std::endl;
00295             out<<"m= "<<r.m<<std::endl;
00296             return out;
00297         }
00298     };
00299 
00300     class ArticulatedInertia
00301     {
00302     public:
00303         Mat M;
00304         Mat H;
00305         Mat I;
00306         ArticulatedInertia();
00307         ArticulatedInertia( const Mat& M, const Mat& H, const Mat& I );
00308         SpatialVector operator * (const SpatialVector& v ) const;
00309         ArticulatedInertia operator * ( Real r ) const;
00310         ArticulatedInertia& operator = (const RigidInertia& Ri );
00311         ArticulatedInertia& operator += (const ArticulatedInertia& Ai );
00312         ArticulatedInertia operator + (const ArticulatedInertia& Ai ) const;
00313         ArticulatedInertia operator - (const ArticulatedInertia& Ai ) const;
00314         inline friend std::ostream& operator << (std::ostream& out, const ArticulatedInertia& r )
00315         {
00316             out<<"I= "<<r.I<<std::endl;
00317             out<<"H= "<<r.H<<std::endl;
00318             out<<"M= "<<r.M<<std::endl;
00319             return out;
00320         }
00322         void copyTo( Mat66& ) const;
00323     };
00324 
00325     typedef Transform Coord;
00326     typedef SpatialVector Deriv;
00327     typedef Coord VecCoord;
00328     typedef Deriv VecDeriv;
00329     typedef Real  VecReal;
00330     //         typedef std::vector<Coord> VecCoord;
00331     //         typedef std::vector<SpatialVector> VecDeriv;
00332 
00333 
00334     template <class T>
00335     class SparseData
00336     {
00337     public:
00338         SparseData(unsigned int _index, T& _data): index(_index), data(_data){};
00339         unsigned int index;
00340         T data;
00341     };
00342 
00343     typedef SparseData<Coord> SparseCoord;
00344     typedef SparseData<Deriv> SparseDeriv;
00345 
00346     typedef helper::vector<SparseCoord> SparseVecCoord;
00347     typedef helper::vector<SparseDeriv> SparseVecDeriv;
00348 
00350     typedef helper::vector<SparseVecDeriv> VecConst;
00351 
00352 
00353     static Mat dyad( const Vec& u, const Vec& v );
00354 
00355     static Vec mult( const Mat& m, const Vec& v );
00356 
00357     static Vec multTrans( const Mat& m, const Vec& v );
00358 
00360     static Mat crossM( const Vec& v );
00361 
00362     static ArticulatedInertia dyad ( const SpatialVector& u, const SpatialVector& v );
00363     
00364     static const char* Name()
00365     {
00366         return "Solid";
00367     }
00368 };
00369 
00370 }// defaulttype
00371 
00372 }// sofa
00373 
00374 
00375 
00376 #endif
00377 
00378 

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