Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

ImporterT.hh

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                               OpenMesh                                    *
00004  *        Copyright (C) 2003 by Computer Graphics Group, RWTH Aachen         *
00005  *                           www.openmesh.org                                *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------* 
00008  *                                                                           *
00009  *                                License                                    *
00010  *                                                                           *
00011  *  This library is free software; you can redistribute it and/or modify it  *
00012  *  under the terms of the GNU Library General Public License as published   *
00013  *  by the Free Software Foundation, version 2.                              *
00014  *                                                                           *
00015  *  This library is distributed in the hope that it will be useful, but      *
00016  *  WITHOUT ANY WARRANTY; without even the implied warranty of               *
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        *
00018  *  Library General Public License for more details.                         *
00019  *                                                                           *
00020  *  You should have received a copy of the GNU Library General Public        *
00021  *  License along with this library; if not, write to the Free Software      *
00022  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                *
00023  *                                                                           *
00024 \*===========================================================================*/
00025 
00026 
00027 //=============================================================================
00028 //
00029 //  Implements an importer module for arbitrary OpenMesh meshes
00030 //
00031 //=============================================================================
00032 
00033 
00034 #ifndef __IMPORTERT_HH__
00035 #define __IMPORTERT_HH__
00036 
00037 
00038 //=== INCLUDES ================================================================
00039 
00040 
00041 #include <OpenMesh/Core/IO/importer/BaseImporter.hh>
00042 #include <OpenMesh/Core/Utils/vector_cast.hh>
00043 #include <OpenMesh/Core/Attributes/Attributes.hh>
00044 
00045 
00046 //== NAMESPACES ===============================================================
00047 
00048 
00049 namespace OpenMesh {
00050 namespace IO {
00051 
00052 
00053 //=== IMPLEMENTATION ==========================================================
00054 
00055 
00059 template <class Mesh>
00060 class ImporterT : public BaseImporter
00061 {
00062 public:
00063 
00064   typedef typename Mesh::Point     Point;
00065   typedef typename Mesh::Normal    Normal;
00066   typedef typename Mesh::Color     Color;
00067   typedef typename Mesh::TexCoord  TexCoord;
00068 
00069 
00070   ImporterT(Mesh& _mesh) : mesh_(_mesh) {}
00071 
00072 
00073   virtual VertexHandle add_vertex(const Vec3f& _point) 
00074   {
00075     return mesh_.add_vertex(vector_cast<Point>(_point));
00076   }
00077    
00078 
00079   virtual FaceHandle add_face(const std::vector<VertexHandle>& _indices) 
00080   {
00081     return mesh_.add_face(_indices);
00082   }
00083 
00084 
00085   // vertex attributes
00086 
00087   virtual void set_normal(VertexHandle _vh, const Vec3f& _normal)
00088   {
00089     if (mesh_.has_vertex_normals())
00090       mesh_.set_normal(_vh, vector_cast<Normal>(_normal));
00091   }
00092 
00093 
00094   virtual void set_color(VertexHandle _vh, const Vec3uc& _color)
00095   {
00096     if (mesh_.has_vertex_colors())
00097       mesh_.set_color(_vh, vector_cast<Color>(_color));
00098   }
00099 
00100 
00101   virtual void set_texcoord(VertexHandle _vh, const Vec2f& _texcoord)
00102   {
00103     if (mesh_.has_vertex_texcoords())
00104     mesh_.set_texcoord(_vh, vector_cast<TexCoord>(_texcoord));
00105   }
00106 
00107 
00108   // face attributes
00109 
00110   virtual void set_normal(FaceHandle _fh, const Vec3f& _normal)
00111   {
00112     if (mesh_.has_face_normals())
00113       mesh_.set_normal(_fh, vector_cast<Normal>(_normal));
00114   }
00115 
00116   virtual void set_color(FaceHandle _fh, const Vec3uc& _color)
00117   {
00118     if (mesh_.has_face_colors())
00119       mesh_.set_color(_fh, vector_cast<Color>(_color));
00120   }
00121 
00122 
00123   // low-level access to mesh
00124 
00125   virtual BaseKernel& kernel() { return mesh_; }
00126 
00127   bool is_triangle_mesh() const
00128   {
00129     typedef typename Mesh::Face Face; // must use typedef for gcc 2.95.x
00130     return Face::is_triangle();
00131   }
00132 
00133   void reserve(unsigned int nV, unsigned int nE, unsigned int nF)
00134   {
00135     mesh_.reserve(nV, nE, nF);
00136   }
00137 
00138   // query number of faces, vertices, normals, texcoords
00139   size_t n_vertices()  const { return mesh_.n_vertices(); }   
00140   size_t n_faces()     const { return mesh_.n_faces(); }
00141   size_t n_edges()     const { return mesh_.n_edges(); }
00142 
00143 
00144 private:
00145 
00146   Mesh& mesh_;
00147 };
00148 
00149 
00150 //=============================================================================
00151 } // namespace IO
00152 } // namespace OpenMesh
00153 //=============================================================================
00154 #endif
00155 //=============================================================================

acg pic Project OpenMesh, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .