00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef __EXPORTERT_HH__
00035 #define __EXPORTERT_HH__
00036
00037
00038
00039
00040
00041 #include <vector>
00042
00043
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
00053
00054 namespace OpenMesh {
00055 namespace IO {
00056
00057
00058
00059
00063 template <class Mesh>
00064 class ExporterT : public BaseExporter
00065 {
00066 public:
00067
00068
00069 ExporterT(const Mesh& _mesh) : mesh_(_mesh) {}
00070
00071
00072
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
00097
00098
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
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
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
00149 bool is_triangle_mesh() const
00150 {
00151 typedef typename Mesh::Face Face;
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 }
00168 }
00169
00170 #endif
00171