Edge2QuadTopologicalMapping.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_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;
00177 Data<double> m_radius;
00178
00179 Data< std::string > object1;
00180 Data< std::string > object2;
00181 };
00182
00183 }
00184
00185 }
00186
00187 }
00188
00189 #endif // SOFA_COMPONENT_TOPOLOGY_EDGE2QUADTOPOLOGICALMAPPING_H