Edge2QuadTopologicalMapping.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_TOPOLOGY_EDGE2QUADTOPOLOGICALMAPPING_H
00026 #define SOFA_COMPONENT_TOPOLOGY_EDGE2QUADTOPOLOGICALMAPPING_H
00027 
00028 #include <sofa/core/componentmodel/topology/TopologicalMapping.h>
00029 
00030 #include <sofa/defaulttype/Vec.h>
00031 #include <sofa/defaulttype/RigidTypes.h>
00032 #include <map>
00033 
00034 #include <sofa/core/BaseMapping.h>
00035 #include <sofa/core/componentmodel/behavior/MechanicalState.h>
00036 
00037 
00038 namespace sofa
00039 {
00040 
00041 namespace component
00042 {
00043 
00044 namespace topology
00045 {
00046 
00047 using namespace sofa::defaulttype;
00048 
00049 using namespace sofa::component::topology;
00050 using namespace sofa::core::componentmodel::topology;
00051 using namespace sofa::core;
00052 using namespace sofa::core::componentmodel::behavior;
00053 
00064     class Edge2QuadTopologicalMapping : public TopologicalMapping 
00065     {
00066         public:
00067             typedef State<Rigid3Types>::VecCoord VecCoord;
00068             typedef State<Rigid3Types>::Coord Coord;            
00069             typedef Coord::value_type Real;         
00070             enum { M=Coord::static_size };
00071             typedef defaulttype::Mat<M,M,Real> Mat;
00072             typedef defaulttype::Vec<M,Real> Vec;
00073 
00074 
00075         public:
00076             
00082             Edge2QuadTopologicalMapping(In* from, Out* to)
00083             :  TopologicalMapping(from, to),
00084             m_nbPointsOnEachCircle( initData(&m_nbPointsOnEachCircle, "nbPointsOnEachCircle", "Discretization of created circles")),
00085             m_radius( initData(&m_radius, "radius", "Radius of created circles")),
00086             object1(initData(&object1, std::string("../.."), "object1", "First object to map")),
00087             object2(initData(&object2, std::string(".."), "object2", "Second object to map"))
00088             {
00089             }
00090 
00095             virtual ~Edge2QuadTopologicalMapping()
00096             {}              
00097 
00100             virtual void init();
00101 
00102             
00109             virtual void updateTopologicalMapping();
00110 
00111             virtual unsigned int getFromIndex(unsigned int ind);
00112 
00118             template<class T>
00119             static bool canCreate(T*& obj, core::objectmodel::BaseContext* context, core::objectmodel::BaseObjectDescription* arg)
00120             {
00121                 if (arg->findObject(arg->getAttribute("object1","../..")) == NULL)
00122                     std::cerr << "Cannot create "<<className(obj)<<" as object1 is missing.\n";
00123                 if (arg->findObject(arg->getAttribute("object2","..")) == NULL)
00124                     std::cerr << "Cannot create "<<className(obj)<<" as object2 is missing.\n";
00125 
00126                 if (arg->findObject(arg->getAttribute("object1","../..")) == NULL || arg->findObject(arg->getAttribute("object2","..")) == NULL)
00127                   return false;
00128 
00129 
00130                 BaseMeshTopology* topoIn;
00131                 BaseMeshTopology* topoOut;
00132                 (dynamic_cast<sofa::core::objectmodel::BaseObject*>(arg->findObject(arg->getAttribute("object1","../.."))))->getContext()->get(topoIn);
00133                 (dynamic_cast<sofa::core::objectmodel::BaseObject*>(arg->findObject(arg->getAttribute("object2",".."))))->getContext()->get(topoOut);
00134 
00135                 if (dynamic_cast<In*>(topoIn) == NULL)
00136                     return false;
00137                 if (dynamic_cast<Out*>(topoOut) == NULL)
00138                     return false;
00139                 return BaseMapping::canCreate(obj, context, arg);
00140             }
00141 
00146             template<class T>
00147             static void create(T*& obj, core::objectmodel::BaseContext* context, core::objectmodel::BaseObjectDescription* arg)
00148             {
00149                 BaseMeshTopology* topoIn=NULL;
00150                 BaseMeshTopology* topoOut=NULL;
00151                 if (arg)
00152                   {
00153                     if (arg->findObject(arg->getAttribute("object1","../..")) != NULL)
00154                       (dynamic_cast<sofa::core::objectmodel::BaseObject*>(arg->findObject(arg->getAttribute("object1","../.."))))->getContext()->get(topoIn);
00155                     if (arg->findObject(arg->getAttribute("object2","../..")) != NULL)
00156                       (dynamic_cast<sofa::core::objectmodel::BaseObject*>(arg->findObject(arg->getAttribute("object2",".."))))->getContext()->get(topoOut);
00157                   }
00158                 obj = new T(
00159                     (arg?dynamic_cast<In*>(topoIn):NULL),
00160                     (arg?dynamic_cast<Out*>(topoOut):NULL));
00161                 if (context) context->addObject(obj);
00162                 if ((arg) && (arg->getAttribute("object1")))
00163                 {
00164                     obj->object1.setValue( arg->getAttribute("object1") );
00165                     arg->removeAttribute("object1");
00166                 }
00167                 if ((arg) && (arg->getAttribute("object2")))
00168                 {
00169                     obj->object2.setValue( arg->getAttribute("object2") );
00170                     arg->removeAttribute("object2");
00171                 }
00172                 if (arg) obj->parse(arg);
00173             }
00174 
00175         protected:
00176             Data<unsigned int> m_nbPointsOnEachCircle; // number of points to create along the circles around each point of the input topology (10 by default)
00177             Data<double> m_radius;  // radius of the circles around each point of the input topology (1 by default) 
00178 
00179             Data< std::string > object1;
00180             Data< std::string > object2;
00181         };
00182 
00183 } // namespace topology
00184 
00185 } // namespace component
00186 
00187 } // namespace sofa
00188 
00189 #endif // SOFA_COMPONENT_TOPOLOGY_EDGE2QUADTOPOLOGICALMAPPING_H

Generated on Sun Nov 23 03:43:01 2008 for Sofa by  doxygen 1.5.7.1