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