OscillatorConstraint.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 :: Modules                               *
00020 *                                                                             *
00021 * Authors: The SOFA Team and external contributors (see Authors.txt)          *
00022 *                                                                             *
00023 * Contact information: contact@sofa-framework.org                             *
00024 ******************************************************************************/
00025 #ifndef SOFA_COMPONENT_CONSTRAINT_OSCILLATORCONSTRAINT_H
00026 #define SOFA_COMPONENT_CONSTRAINT_OSCILLATORCONSTRAINT_H
00027 
00028 #include <sofa/core/componentmodel/behavior/Constraint.h>
00029 #include <sofa/core/componentmodel/behavior/MechanicalState.h>
00030 #include <sofa/helper/vector.h>
00031 
00032 
00033 namespace sofa
00034 {
00035 
00036 namespace component
00037 {
00038 
00039 namespace constraint
00040 {
00041 
00045 template <class DataTypes>
00046 class OscillatorConstraint : public core::componentmodel::behavior::Constraint<DataTypes>, public virtual core::objectmodel::BaseObject
00047 {
00048 public:
00049     typedef typename DataTypes::VecCoord VecCoord;
00050     typedef typename DataTypes::VecDeriv VecDeriv;
00051     typedef typename DataTypes::Coord Coord;
00052     typedef typename DataTypes::Deriv Deriv;
00053     typedef typename DataTypes::Real Real;
00054 
00055 protected:
00056     struct Oscillator {
00057                 unsigned int index;
00058         Coord mean;
00059         Deriv amplitude;
00060         Real pulsation;
00061         Real phase;
00062                 
00063                 Oscillator(){}
00064               
00065         Oscillator( unsigned int i, const Coord& m, const Deriv& a, const Real& w, const Real& p )
00066             : index(i), mean(m), amplitude(a), pulsation(w), phase(p) {}
00067   
00068                 inline friend std::istream& operator >> ( std::istream& in, Oscillator& o ){
00069                   in>>o.index>>o.mean>>o.amplitude>>o.pulsation>>o.phase;
00070                   return in;
00071                 }
00072 
00073                 inline friend std::ostream& operator << ( std::ostream& out, const Oscillator& o ){
00074                   out << o.index<< " " <<o.mean<< " " <<o.amplitude<< " " <<o.pulsation<< " " <<o.phase<<"\n";
00075                   return out;
00076                 }              
00077     };
00078         
00079     Data< helper::vector< Oscillator > > constraints; 
00080 
00081 
00082 public:
00083     OscillatorConstraint();
00084     
00085     OscillatorConstraint(core::componentmodel::behavior::MechanicalState<DataTypes>* mstate);
00086     
00087     ~OscillatorConstraint();
00088     
00089     OscillatorConstraint<DataTypes>* addConstraint(unsigned index, const Coord& mean, const Deriv& amplitude, Real pulsation, Real phase);
00090     
00091     // -- Constraint interface
00092     void projectResponse(VecDeriv& dx);
00093     virtual void projectVelocity(VecDeriv& /*dx*/); 
00094     virtual void projectPosition(VecCoord& /*x*/); 
00095     
00096     void draw(){}
00097 
00099     bool isHolonomic() {return true;}
00100 };
00101 
00102 } // namespace constraint
00103 
00104 } // namespace component
00105 
00106 } // namespace sofa
00107 
00108 #endif

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