Hexa2QuadTopologicalMapping.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_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 } // namespace topology
00160 
00161 } // namespace component
00162 
00163 } // namespace sofa
00164 
00165 #endif // SOFA_COMPONENT_TOPOLOGY_HEXA2QUADTOPOLOGICALMAPPING_H

Generated on Sun Nov 23 03:43:31 2008 for Sofa by  doxygen 1.5.7.1