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
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 #ifndef __EXPORTERT_HH__
00051 #define __EXPORTERT_HH__
00052
00053
00054
00055
00056
00057 #include <vector>
00058
00059
00060 #include <OpenMesh/Core/System/config.h>
00061 #include <OpenMesh/Core/Geometry/VectorT.hh>
00062 #include <OpenMesh/Core/Utils/GenProg.hh>
00063 #include <OpenMesh/Core/Utils/vector_cast.hh>
00064 #include <OpenMesh/Core/Utils/color_cast.hh>
00065 #include <OpenMesh/Core/IO/exporter/BaseExporter.hh>
00066
00067
00068
00069
00070 namespace OpenMesh {
00071 namespace IO {
00072
00073
00074
00075
00079 template <class Mesh>
00080 class ExporterT : public BaseExporter
00081 {
00082 public:
00083
00084
00085 ExporterT(const Mesh& _mesh) : mesh_(_mesh) {}
00086
00087
00088
00089
00090 Vec3f point(VertexHandle _vh) const
00091 {
00092 return vector_cast<Vec3f>(mesh_.point(_vh));
00093 }
00094
00095 Vec3f normal(VertexHandle _vh) const
00096 {
00097 return (mesh_.has_vertex_normals()
00098 ? vector_cast<Vec3f>(mesh_.normal(_vh))
00099 : Vec3f(0.0f, 0.0f, 0.0f));
00100 }
00101
00102 Vec3uc color(VertexHandle _vh) const
00103 {
00104 return (mesh_.has_vertex_colors()
00105 ? color_cast<Vec3uc>(mesh_.color(_vh))
00106 : Vec3uc(0, 0, 0));
00107 }
00108
00109 Vec4uc colorA(VertexHandle _vh) const
00110 {
00111 return (mesh_.has_vertex_colors()
00112 ? color_cast<Vec4uc>(mesh_.color(_vh))
00113 : Vec4uc(0, 0, 0, 0));
00114 }
00115
00116 Vec2f texcoord(VertexHandle _vh) const
00117 {
00118 #if defined(OM_CC_GCC) && (OM_CC_VERSION<30000)
00119
00120
00121
00122 if (mesh_.has_vertex_texcoords2D())
00123 return vector_cast<Vec2f>(mesh_.texcoord2D(_vh));
00124 return Vec2f(0.0f, 0.0f);
00125 #else // **)
00126 return (mesh_.has_vertex_texcoords2D()
00127 ? vector_cast<Vec2f>(mesh_.texcoord2D(_vh))
00128 : Vec2f(0.0f, 0.0f));
00129 #endif
00130 }
00131
00132
00133
00134
00135 unsigned int get_vhandles(FaceHandle _fh,
00136 std::vector<VertexHandle>& _vhandles) const
00137 {
00138 unsigned int count(0);
00139 _vhandles.clear();
00140 for (typename Mesh::CFVIter fv_it=mesh_.cfv_iter(_fh); fv_it; ++fv_it)
00141 {
00142 _vhandles.push_back(fv_it.handle());
00143 ++count;
00144 }
00145 return count;
00146 }
00147
00148 Vec3f normal(FaceHandle _fh) const
00149 {
00150 return (mesh_.has_face_normals()
00151 ? vector_cast<Vec3f>(mesh_.normal(_fh))
00152 : Vec3f(0.0f, 0.0f, 0.0f));
00153 }
00154
00155 Vec3uc color(FaceHandle _fh) const
00156 {
00157 return (mesh_.has_face_colors()
00158 ? color_cast<Vec3uc>(mesh_.color(_fh))
00159 : Vec3uc(0, 0, 0));
00160 }
00161
00162 Vec4uc colorA(FaceHandle _fh) const
00163 {
00164 return (mesh_.has_face_colors()
00165 ? color_cast<Vec4uc>(mesh_.color(_fh))
00166 : Vec4uc(0, 0, 0, 0));
00167 }
00168
00169 virtual const BaseKernel* kernel() { return &mesh_; }
00170
00171
00172
00173 size_t n_vertices() const { return mesh_.n_vertices(); }
00174 size_t n_faces() const { return mesh_.n_faces(); }
00175 size_t n_edges() const { return mesh_.n_edges(); }
00176
00177
00178
00179 bool is_triangle_mesh() const
00180 { return Mesh::is_triangles(); }
00181
00182 bool has_vertex_normals() const { return mesh_.has_vertex_normals(); }
00183 bool has_vertex_colors() const { return mesh_.has_vertex_colors(); }
00184 bool has_vertex_texcoords() const { return mesh_.has_vertex_texcoords2D(); }
00185 bool has_face_normals() const { return mesh_.has_face_normals(); }
00186 bool has_face_colors() const { return mesh_.has_face_colors(); }
00187
00188 private:
00189
00190 const Mesh& mesh_;
00191 };
00192
00193
00194
00195 }
00196 }
00197
00198 #endif
00199