OscillatorConstraint.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
00092 void projectResponse(VecDeriv& dx);
00093 virtual void projectVelocity(VecDeriv& );
00094 virtual void projectPosition(VecCoord& );
00095
00096 void draw(){}
00097
00099 bool isHolonomic() {return true;}
00100 };
00101
00102 }
00103
00104 }
00105
00106 }
00107
00108 #endif