MeshLoader.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_MESHLOADER_H
00026 #define SOFA_COMPONENT_TOPOLOGY_MESHLOADER_H
00027 
00028 #include <string>
00029 #include <sofa/helper/fixed_array.h>
00030 #include <sofa/helper/vector.h>
00031 
00032 #include <sofa/core/objectmodel/BaseObject.h>
00033 #include <sofa/helper/io/MeshTopologyLoader.h>
00034 
00035 namespace sofa
00036 {
00037 
00038 namespace component
00039 {
00040 
00041 class MeshLoader : public virtual core::objectmodel::BaseObject,
00042                     public helper::io::MeshTopologyLoader
00043 {
00044 public:
00045     typedef unsigned int index_type;
00046     typedef index_type PointID;
00047     typedef index_type EdgeID;
00048     typedef index_type TriangleID;
00049     typedef index_type QuadID;
00050     typedef index_type TetraID;
00051     typedef index_type HexaID;
00052     
00053     typedef helper::fixed_array<SReal,3> Point;
00054     typedef helper::fixed_array<PointID,2> Edge;
00055     typedef helper::fixed_array<PointID,3> Triangle;
00056     typedef helper::fixed_array<PointID,4> Quad;
00057     typedef helper::fixed_array<PointID,4> Tetra;
00058     typedef helper::fixed_array<PointID,8> Hexa;
00059         
00060     typedef helper::vector<Point> SeqPoints;
00061     typedef helper::vector<Edge> SeqEdges;
00062     typedef helper::vector<Triangle> SeqTriangles;
00063     typedef helper::vector<Quad> SeqQuads;
00064     typedef helper::vector<Tetra> SeqTetras;
00065     typedef helper::vector<Hexa> SeqHexas;
00066 
00067     MeshLoader();
00068 
00069     virtual ~MeshLoader() {}
00070     
00071     virtual void clear();
00072     
00073     virtual bool load(const char* filename);
00074     
00075     
00076     void setFilename(std::string f)
00077     {
00078         filename.setValue(f);
00079     }
00080 
00081     const std::string &getFilename() const
00082     {
00083         return filename.getValue();
00084     }
00085 
00086     double getPX(int i) const { return seqPoints.getValue()[i][0]; }
00087     double getPY(int i) const { return seqPoints.getValue()[i][1]; }
00088     double getPZ(int i) const { return seqPoints.getValue()[i][2]; }
00089     
00090     int getNbPoints() const;
00091     const SeqPoints& getPoints() const;
00092     const SeqEdges& getEdges() const;
00093     const SeqTriangles& getTriangles() const;
00094     const SeqQuads& getQuads() const;
00095     const SeqTetras& getTetras() const;
00096     const SeqHexas& getHexas() const;
00097     
00098     void parse(core::objectmodel::BaseObjectDescription* arg);
00099 
00100 protected:  
00101     // helper::io::MeshTopologyLoader API
00102     void addPoint(double px, double py, double pz);
00103     void addLine( int a, int b );
00104     void addTriangle( int a, int b, int c );
00105     void addTetra( int a, int b, int c, int d );
00106     void addQuad( int a, int b, int c, int d );
00107     void addCube( int a, int b, int c, int d, int e, int f, int g, int h );
00108 
00109 protected:
00110     Data<SeqPoints>     seqPoints;
00111     Data<SeqEdges>      seqEdges;
00112     Data<SeqTriangles>  seqTriangles;
00113     Data<SeqQuads>      seqQuads;
00114     Data<SeqTetras>     seqTetras;
00115     Data<SeqHexas>      seqHexas;
00116 
00117     Data< std::string > filename;
00118 };
00119 
00120 } // namespace component
00121 
00122 } // namespace sofa
00123 
00124 #endif

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