MeshLoader.cpp

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 #include <sofa/component/MeshLoader.h>
00026 #include <sofa/core/ObjectFactory.h>
00027 #include <sofa/core/componentmodel/topology/Topology.h>
00028 #include <iostream>
00029 
00030 namespace sofa
00031 {
00032 
00033 namespace component
00034 {
00035 
00036 using namespace sofa::defaulttype;
00037 
00038 SOFA_DECL_CLASS(MeshLoader)
00039 
00040 int MeshLoaderClass = core::RegisterObject("Generic Mesh Loader")
00041 .add< MeshLoader >()
00042 ;
00043 
00044 MeshLoader::MeshLoader()
00045 : seqPoints(initData(&seqPoints,"points","List of points"))
00046 , seqEdges(initData(&seqEdges,"lines","List of line indices"))
00047 , seqTriangles(initData(&seqTriangles,"triangles","List of triangle indices"))
00048 , seqQuads(initData(&seqQuads,"quads","List of quad indices"))
00049 , seqTetras(initData(&seqTetras,"tetras","List of tetra indices"))
00050 , seqHexas(initData(&seqHexas,"hexas","List of hexa indices"))
00051 , filename(initData(&filename,"filename","Filename of the object"))
00052 {
00053     this->getContext()->addObject(this);
00054 }
00055 
00056 void MeshLoader::parse(core::objectmodel::BaseObjectDescription* arg)
00057 {
00058     this->BaseObject::parse(arg); 
00059     
00060     if (filename.getValue() != "") 
00061         load(filename.getValue().c_str());
00062 }
00063 
00064 void MeshLoader::clear()
00065 {
00066     seqPoints.beginEdit()->clear();
00067     seqPoints.endEdit();
00068 
00069     seqEdges.beginEdit()->clear(); 
00070     seqEdges.endEdit();
00071 
00072     seqTriangles.beginEdit()->clear(); 
00073     seqTriangles.endEdit();
00074 
00075     seqQuads.beginEdit()->clear();
00076     seqQuads.endEdit();
00077 
00078     seqTetras.beginEdit()->clear();
00079     seqTetras.endEdit();
00080 
00081     seqHexas.beginEdit()->clear();
00082     seqHexas.endEdit();
00083 }
00084 
00085 bool MeshLoader::load(const char* filename)
00086 {
00087     clear();
00088     if (!MeshTopologyLoader::load(filename))
00089     {         
00090         logWarning(std::string("Unable to load Mesh \"") + filename );                      
00091         return false;
00092     }
00093 
00094     this->filename.setValue(filename);
00095     return true;
00096 }
00097 
00098 void MeshLoader::addPoint(double px, double py, double pz)
00099 {   
00100     seqPoints.beginEdit()->push_back(helper::make_array((SReal)px, (SReal)py, (SReal)pz));
00101     seqPoints.endEdit();
00102 }
00103 
00104 void MeshLoader::addLine( int a, int b )
00105 {
00106     seqEdges.beginEdit()->push_back(Edge(a,b));
00107     seqEdges.endEdit();
00108 }
00109 
00110 void MeshLoader::addTriangle( int a, int b, int c )
00111 {
00112     seqTriangles.beginEdit()->push_back( Triangle(a,b,c) );
00113     seqTriangles.endEdit();
00114 }
00115 
00116 void MeshLoader::addTetra( int a, int b, int c, int d )
00117 {
00118     seqTetras.beginEdit()->push_back( Tetra(a,b,c,d) );
00119     seqTetras.endEdit();
00120 }
00121 
00122 void MeshLoader::addQuad(int p1, int p2, int p3, int p4)
00123 {
00124     seqQuads.beginEdit()->push_back(Quad(p1,p2,p3,p4));
00125     seqQuads.endEdit();
00126 }
00127 
00128 void MeshLoader::addCube(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8)
00129 {
00130 #ifdef SOFA_NEW_HEXA
00131     seqHexas.beginEdit()->push_back(Hexa(p1,p2,p3,p4,p5,p6,p7,p8));
00132 #else
00133     seqHexas.beginEdit()->push_back(Hexa(p1,p2,p4,p3,p5,p6,p8,p7));
00134 #endif
00135     seqHexas.endEdit();
00136 }
00137 
00138 const MeshLoader::SeqPoints& MeshLoader::getPoints() const
00139 {
00140     return seqPoints.getValue();
00141 }
00142 
00143 const MeshLoader::SeqEdges& MeshLoader::getEdges()  const
00144 {
00145     return seqEdges.getValue();
00146 }
00147 
00148 const MeshLoader::SeqTriangles& MeshLoader::getTriangles() const
00149 {
00150     return seqTriangles.getValue();
00151 }
00152 
00153 const MeshLoader::SeqQuads& MeshLoader::getQuads() const
00154 {
00155     return seqQuads.getValue();
00156 }
00157 
00158 const MeshLoader::SeqTetras& MeshLoader::getTetras() const
00159 {
00160     return seqTetras.getValue();
00161 }
00162 
00163 const MeshLoader::SeqHexas& MeshLoader::getHexas() const
00164 {  
00165     return seqHexas.getValue();
00166 }
00167 
00168 int MeshLoader::getNbPoints() const
00169 {
00170     return seqPoints.getValue().size();
00171 }
00172 
00173 } // namespace component
00174 
00175 } // namespace sofa
00176 

Generated on Sun Nov 23 03:41:42 2008 for Sofa by  doxygen 1.5.7.1