FixedPlaneConstraint.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_FIXEDPLANECONSTRAINT_H
00026 #define SOFA_COMPONENT_CONSTRAINT_FIXEDPLANECONSTRAINT_H
00027 
00028 #include <sofa/core/componentmodel/behavior/Constraint.h>
00029 #include <sofa/core/componentmodel/behavior/MechanicalState.h>
00030 #include <sofa/core/componentmodel/topology/BaseMeshTopology.h>
00031 #include <set>
00032 #include <sofa/component/topology/PointSubset.h>
00033 
00034 
00035 namespace sofa
00036 {
00037 
00038 namespace component
00039 {
00040 
00041 namespace constraint
00042 {
00043 
00044 template <class DataTypes>
00045 class FixedPlaneConstraint : public core::componentmodel::behavior::Constraint<DataTypes>, public virtual core::objectmodel::BaseObject
00046 {
00047 public:
00048     typedef core::componentmodel::behavior::Constraint<DataTypes> Inherit;
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 topology::PointSubset SetIndex;
00054     typedef typename Coord::value_type   Real    ;
00055 
00056 protected:
00057     Data<SetIndex> indices; // the set of vertex indices
00059     Data<Coord> direction;
00061     bool selectVerticesFromPlanes;
00062 
00063     Data<Real> dmin; // coordinates min of the plane for the vertex selection
00064     Data<Real> dmax;// coordinates max of the plane for the vertex selection
00065 public:
00066     FixedPlaneConstraint();
00067     
00068     ~FixedPlaneConstraint();
00069     
00070     FixedPlaneConstraint<DataTypes>* addConstraint(int index);
00071     
00072     FixedPlaneConstraint<DataTypes>* removeConstraint(int index);
00073     // Handle topological changes
00074     virtual void handleTopologyChange();
00075     // -- Constraint interface
00076     void projectResponse(VecDeriv& dx);
00077     virtual void projectVelocity(VecDeriv& /*dx*/){} 
00078     virtual void projectPosition(VecCoord& /*x*/){} 
00079 
00080     virtual void init();
00081     
00082     void setDirection (Coord dir);
00083     void selectVerticesAlongPlane();
00084     void setDminAndDmax(const Real _dmin,const Real _dmax){dmin=_dmin;dmax=_dmax;selectVerticesFromPlanes=true;}
00085 
00086     void draw();
00087 protected:
00088     
00089     sofa::core::componentmodel::topology::BaseMeshTopology* topology;
00090 
00091     // Define TestNewPointFunction
00092     static bool FPCTestNewPointFunction(int, void*, const helper::vector< unsigned int > &, const helper::vector< double >& );
00093 
00094     // Define RemovalFunction
00095     static void FPCRemovalFunction ( int , void*);
00096 
00097     bool isPointInPlane(Coord p) {
00098         Real d=dot(p,direction.getValue());
00099         if ((d>dmin.getValue())&& (d<dmax.getValue())) 
00100             return true;
00101         else
00102             return false;
00103     }
00104 };
00105 
00106 } // namespace constraint
00107 
00108 } // namespace component
00109 
00110 } // namespace sofa
00111 
00112 #endif

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