- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# Core/IO/exporter/ExporterT.hh

    00001 /*===========================================================================*\
    00002  *                                                                           *
    00003  *                               OpenMesh                                    *
    00004  *      Copyright (C) 2001-2005 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 exporter module for arbitrary OpenMesh meshes
    00030 //
    00031 //=============================================================================
    00032
    00033
    00034 #ifndef __EXPORTERT_HH__
    00035 #define __EXPORTERT_HH__
    00036
    00037
    00038 //=== INCLUDES ================================================================
    00039
    00040 // C++
    00041 #include <vector>
    00042
    00043 // OpenMesh
    00044 #include <OpenMesh/Core/System/config.hh>
    00045 #include <OpenMesh/Core/Math/VectorT.hh>
    00046 #include <OpenMesh/Core/Utils/GenProg.hh>
    00047 #include <OpenMesh/Core/Utils/vector_cast.hh>
    00048 #include <OpenMesh/Core/Utils/color_cast.hh>
    00049 #include <OpenMesh/Core/IO/exporter/BaseExporter.hh>
    00050
    00051
    00052 //=== NAMESPACES ==============================================================
    00053
    00054 namespace OpenMesh {
    00055 namespace IO {
    00056
    00057
    00058 //=== EXPORTER CLASS ==========================================================
    00059
    00063 template <class Mesh>
    00064 class ExporterT : public BaseExporter
    00065 {
    00066 public:
    00067
    00068   // Constructor
    00069   ExporterT(const Mesh& _mesh) : mesh_(_mesh) {}
    00070
    00071
    00072   // get vertex data
    00073
    00074   Vec3f  point(VertexHandle _vh)    const
    00075   {
    00076     return vector_cast<Vec3f>(mesh_.point(_vh));
    00077   }
    00078
    00079   Vec3f  normal(VertexHandle _vh)   const
    00080   {
    00081     return (mesh_.has_vertex_normals()
    00082             ? vector_cast<Vec3f>(mesh_.normal(_vh))
    00083             : Vec3f(0.0f, 0.0f, 0.0f));
    00084   }
    00085
    00086   Vec3uc color(VertexHandle _vh)    const
    00087   {
    00088     return (mesh_.has_vertex_colors()
    00089             ? color_cast<Vec3uc>(mesh_.color(_vh))
    00090             : Vec3uc(0, 0, 0));
    00091   }
    00092
    00093   Vec2f  texcoord(VertexHandle _vh) const
    00094   {
    00095 #if defined(OM_CC_GCC) && (OM_CC_VERSION<30000)
    00096     // Workaround!
    00097     // gcc 2.95.3 exits with internal compiler error at the
    00098     // code below!??? **)
    00099     if (mesh_.has_vertex_texcoords2D())
    00100       return vector_cast<Vec2f>(mesh_.texcoord2D(_vh));
    00101     return Vec2f(0.0f, 0.0f);
    00102 #else // **)
    00103     return (mesh_.has_vertex_texcoords2D()
    00104             ? vector_cast<Vec2f>(mesh_.texcoord2D(_vh))
    00105             : Vec2f(0.0f, 0.0f));
    00106 #endif
    00107   }
    00108
    00109
    00110   // get face data
    00111
    00112   unsigned int get_vhandles(FaceHandle _fh,
    00113                             std::vector<VertexHandle>& _vhandles) const
    00114   {
    00115     unsigned int count(0);
    00116     _vhandles.clear();
    00117     for (typename Mesh::CFVIter fv_it=mesh_.cfv_iter(_fh); fv_it; ++fv_it)
    00118     {
    00119       _vhandles.push_back(fv_it.handle());
    00120       ++count;
    00121     }
    00122     return count;
    00123   }
    00124
    00125   Vec3f  normal(FaceHandle _fh)   const
    00126   {
    00127     return (mesh_.has_face_normals()
    00128             ? vector_cast<Vec3f>(mesh_.normal(_fh))
    00129             : Vec3f(0.0f, 0.0f, 0.0f));
    00130   }
    00131
    00132   Vec3uc  color(FaceHandle _fh)   const
    00133   {
    00134     return (mesh_.has_face_colors()
    00135             ? vector_cast<Vec3uc>(mesh_.color(_fh))
    00136             : Vec3uc(0, 0, 0));
    00137   }
    00138
    00139   virtual const BaseKernel* kernel() { return &mesh_; }
    00140
    00141
    00142   // query number of faces, vertices, normals, texcoords
    00143   size_t n_vertices()  const { return mesh_.n_vertices(); }
    00144   size_t n_faces()     const { return mesh_.n_faces(); }
    00145   size_t n_edges()     const { return mesh_.n_edges(); }
    00146
    00147
    00148   // property information
    00149   bool is_triangle_mesh() const
    00150   {
    00151     typedef typename Mesh::Face Face; // must use typedef for gcc 2.95.x
    00152     return Face::is_triangle();
    00153   }
    00154   bool has_vertex_normals()   const { return mesh_.has_vertex_normals();   }
    00155   bool has_vertex_colors()    const { return mesh_.has_vertex_colors();    }
    00156   bool has_vertex_texcoords() const { return mesh_.has_vertex_texcoords2D(); }
    00157   bool has_face_normals()     const { return mesh_.has_face_normals();     }
    00158   bool has_face_colors()      const { return mesh_.has_face_colors();      }
    00159
    00160 private:
    00161
    00162    const Mesh& mesh_;
    00163 };
    00164
    00165
    00166 //=============================================================================
    00167 } // namespace IO
    00168 } // namespace OpenMesh
    00169 //=============================================================================
    00170 #endif
    00171 //=============================================================================