Quad2TriangleTopologicalMapping.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_QUAD2TRIANGLETOPOLOGICALMAPPING_H
00026 #define SOFA_COMPONENT_TOPOLOGY_QUAD2TRIANGLETOPOLOGICALMAPPING_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
00044
00045 using namespace sofa::defaulttype;
00046
00047 using namespace sofa::component::topology;
00048 using namespace sofa::core::componentmodel::topology;
00049
00050 using namespace sofa::core;
00051
00062 class Quad2TriangleTopologicalMapping : public TopologicalMapping
00063 {
00064
00065 public:
00066
00072 Quad2TriangleTopologicalMapping(In* from=NULL, Out* to=NULL);
00073
00078 virtual ~Quad2TriangleTopologicalMapping();
00079
00082 virtual void init();
00083
00084
00091 virtual void updateTopologicalMapping();
00092
00093 virtual unsigned int getFromIndex(unsigned int ind);
00094
00100 template<class T>
00101 static bool canCreate(T*& obj, core::objectmodel::BaseContext* context, core::objectmodel::BaseObjectDescription* arg)
00102 {
00103 if (arg->findObject(arg->getAttribute("object1","../..")) == NULL)
00104 std::cerr << "Cannot create "<<className(obj)<<" as object1 is missing.\n";
00105 if (arg->findObject(arg->getAttribute("object2","..")) == NULL)
00106 std::cerr << "Cannot create "<<className(obj)<<" as object2 is missing.\n";
00107
00108
00109 if (arg->findObject(arg->getAttribute("object1","../..")) == NULL || arg->findObject(arg->getAttribute("object2","..")) == NULL)
00110 return false;
00111
00112 BaseMeshTopology* topoIn;
00113 BaseMeshTopology* topoOut;
00114 (dynamic_cast<sofa::core::objectmodel::BaseObject*>(arg->findObject(arg->getAttribute("object1","../.."))))->getContext()->get(topoIn);
00115 (dynamic_cast<sofa::core::objectmodel::BaseObject*>(arg->findObject(arg->getAttribute("object2",".."))))->getContext()->get(topoOut);
00116
00117 if (dynamic_cast<In*>(topoIn) == NULL)
00118 return false;
00119 if (dynamic_cast<Out*>(topoOut) == NULL)
00120 return false;
00121 return BaseMapping::canCreate(obj, context, arg);
00122 }
00123
00128 template<class T>
00129 static void create(T*& obj, core::objectmodel::BaseContext* context, core::objectmodel::BaseObjectDescription* arg)
00130 {
00131 BaseMeshTopology* topoIn=NULL;
00132 BaseMeshTopology* topoOut=NULL;
00133 if (arg)
00134 {
00135 if (arg->findObject(arg->getAttribute("object1","../..")) != NULL)
00136 (dynamic_cast<sofa::core::objectmodel::BaseObject*>(arg->findObject(arg->getAttribute("object1","../.."))))->getContext()->get(topoIn);
00137 if (arg->findObject(arg->getAttribute("object2","..")) != NULL)
00138 (dynamic_cast<sofa::core::objectmodel::BaseObject*>(arg->findObject(arg->getAttribute("object2",".."))))->getContext()->get(topoOut);
00139 }
00140
00141 obj = new T(
00142 (arg?dynamic_cast<In*>(topoIn):NULL),
00143 (arg?dynamic_cast<Out*>(topoOut):NULL));
00144 if (context) context->addObject(obj);
00145 if ((arg) && (arg->getAttribute("object1")))
00146 {
00147 obj->object1.setValue( arg->getAttribute("object1") );
00148 arg->removeAttribute("object1");
00149 }
00150 if ((arg) && (arg->getAttribute("object2")))
00151 {
00152 obj->object2.setValue( arg->getAttribute("object2") );
00153 arg->removeAttribute("object2");
00154 }
00155 if (arg) obj->parse(arg);
00156 }
00157 protected:
00158 Data< std::string > object1;
00159 Data< std::string > object2;
00160
00161 };
00162
00163 }
00164
00165 }
00166
00167 }
00168
00169 #endif // SOFA_COMPONENT_TOPOLOGY_QUAD2TRIANGLETOPOLOGICALMAPPING_H