Quad2TriangleTopologicalMapping.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_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 } // namespace topology
00164 
00165 } // namespace component
00166 
00167 } // namespace sofa
00168 
00169 #endif // SOFA_COMPONENT_TOPOLOGY_QUAD2TRIANGLETOPOLOGICALMAPPING_H

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