Hexa2QuadTopologicalMapping.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_HEXA2QUADTOPOLOGICALMAPPING_H
00026 #define SOFA_COMPONENT_TOPOLOGY_HEXA2QUADTOPOLOGICALMAPPING_H
00027
00028 #include <sofa/core/componentmodel/topology/TopologicalMapping.h>
00029
00030 #include <sofa/defaulttype/Vec.h>
00031 #include <map>
00032
00033 #include <sofa/core/BaseMapping.h>
00034
00035 namespace sofa
00036 {
00037
00038 namespace component
00039 {
00040
00041 namespace topology
00042 {
00043 using namespace sofa::defaulttype;
00044
00045 using namespace sofa::component::topology;
00046 using namespace sofa::core::componentmodel::topology;
00047
00048 using namespace sofa::core;
00049
00060 class Hexa2QuadTopologicalMapping : public TopologicalMapping
00061 {
00062 public:
00063
00069 Hexa2QuadTopologicalMapping(In* from=NULL, Out* to=NULL);
00070
00075 virtual ~Hexa2QuadTopologicalMapping();
00076
00079 virtual void init();
00080
00081
00088 virtual void updateTopologicalMapping();
00089
00090 virtual unsigned int getFromIndex(unsigned int ind);
00091
00097 template<class T>
00098 static bool canCreate(T*& obj, core::objectmodel::BaseContext* context, core::objectmodel::BaseObjectDescription* arg)
00099 {
00100 if (arg->findObject(arg->getAttribute("object1","../..")) == NULL)
00101 std::cerr << "Cannot create "<<className(obj)<<" as object1 is missing.\n";
00102 if (arg->findObject(arg->getAttribute("object2","..")) == NULL)
00103 std::cerr << "Cannot create "<<className(obj)<<" as object2 is missing.\n";
00104
00105 if (arg->findObject(arg->getAttribute("object1","../..")) == NULL || arg->findObject(arg->getAttribute("object2","..")) == NULL)
00106 return false;
00107
00108 BaseMeshTopology* topoIn;
00109 BaseMeshTopology* topoOut;
00110 (dynamic_cast<sofa::core::objectmodel::BaseObject*>(arg->findObject(arg->getAttribute("object1","../.."))))->getContext()->get(topoIn);
00111 (dynamic_cast<sofa::core::objectmodel::BaseObject*>(arg->findObject(arg->getAttribute("object2",".."))))->getContext()->get(topoOut);
00112
00113 if (dynamic_cast<In*>(topoIn) == NULL)
00114 return false;
00115 if (dynamic_cast<Out*>(topoOut) == NULL)
00116 return false;
00117 return BaseMapping::canCreate(obj, context, arg);
00118 }
00119
00124 template<class T>
00125 static void create(T*& obj, core::objectmodel::BaseContext* context, core::objectmodel::BaseObjectDescription* arg)
00126 {
00127 BaseMeshTopology* topoIn=NULL;
00128 BaseMeshTopology* topoOut=NULL;
00129 if (arg)
00130 {
00131 if (arg->findObject(arg->getAttribute("object1","../..")) != NULL)
00132 (dynamic_cast<sofa::core::objectmodel::BaseObject*>(arg->findObject(arg->getAttribute("object1","../.."))))->getContext()->get(topoIn);
00133 if (arg->findObject(arg->getAttribute("object2","..")) != NULL)
00134 (dynamic_cast<sofa::core::objectmodel::BaseObject*>(arg->findObject(arg->getAttribute("object2",".."))))->getContext()->get(topoOut);
00135 }
00136 obj = new T(
00137 (arg?dynamic_cast<In*>(topoIn):NULL),
00138 (arg?dynamic_cast<Out*>(topoOut):NULL));
00139 if (context) context->addObject(obj);
00140 if ((arg) && (arg->getAttribute("object1")))
00141 {
00142 obj->object1.setValue( arg->getAttribute("object1") );
00143 arg->removeAttribute("object1");
00144 }
00145 if ((arg) && (arg->getAttribute("object2")))
00146 {
00147 obj->object2.setValue( arg->getAttribute("object2") );
00148 arg->removeAttribute("object2");
00149 }
00150 if (arg) obj->parse(arg);
00151 }
00152
00153 protected:
00154 Data< std::string > object1;
00155 Data< std::string > object2;
00156
00157 };
00158
00159 }
00160
00161 }
00162
00163 }
00164
00165 #endif // SOFA_COMPONENT_TOPOLOGY_HEXA2QUADTOPOLOGICALMAPPING_H