Tetra2TriangleTopologicalMapping.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_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 } // namespace topology
00161 
00162 } // namespace component
00163 
00164 } // namespace sofa
00165 
00166 #endif // SOFA_COMPONENT_TOPOLOGY_TETRA2TRIANGLETOPOLOGICALMAPPING_H

Generated on Sun Nov 23 03:45:50 2008 for Sofa by  doxygen 1.5.7.1