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 Vec3uc color(EdgeHandle _eh) const
00135 {
00136 return (mesh_.has_edge_colors()
00137 ? color_cast<Vec3uc>(mesh_.color(_eh))
00138 : Vec3uc(0, 0, 0));
00139 }
00140
00141 Vec4uc colorA(EdgeHandle _eh) const
00142 {
00143 return (mesh_.has_edge_colors()
00144 ? color_cast<Vec4uc>(mesh_.color(_eh))
00145 : Vec4uc(0, 0, 0, 0));
00146 }
00147
00148
00149
00150
00151 unsigned int get_vhandles(FaceHandle _fh,
00152 std::vector<VertexHandle>& _vhandles) const
00153 {
00154 unsigned int count(0);
00155 _vhandles.clear();
00156 for (typename Mesh::CFVIter fv_it=mesh_.cfv_iter(_fh); fv_it; ++fv_it)
00157 {
00158 _vhandles.push_back(fv_it.handle());
00159 ++count;
00160 }
00161 return count;
00162 }
00163
00164 Vec3f normal(FaceHandle _fh) const
00165 {
00166 return (mesh_.has_face_normals()
00167 ? vector_cast<Vec3f>(mesh_.normal(_fh))
00168 : Vec3f(0.0f, 0.0f, 0.0f));
00169 }
00170
00171 Vec3uc color(FaceHandle _fh) const
00172 {
00173 return (mesh_.has_face_colors()
00174 ? color_cast<Vec3uc>(mesh_.color(_fh))
00175 : Vec3uc(0, 0, 0));
00176 }
00177
00178 Vec4uc colorA(FaceHandle _fh) const
00179 {
00180 return (mesh_.has_face_colors()
00181 ? color_cast<Vec4uc>(mesh_.color(_fh))
00182 : Vec4uc(0, 0, 0, 0));
00183 }
00184
00185 virtual const BaseKernel* kernel() { return &mesh_; }
00186
00187
00188
00189 size_t n_vertices() const { return mesh_.n_vertices(); }
00190 size_t n_faces() const { return mesh_.n_faces(); }
00191 size_t n_edges() const { return mesh_.n_edges(); }
00192
00193
00194
00195 bool is_triangle_mesh() const
00196 { return Mesh::is_triangles(); }
00197
00198 bool has_vertex_normals() const { return mesh_.has_vertex_normals(); }
00199 bool has_vertex_colors() const { return mesh_.has_vertex_colors(); }
00200 bool has_vertex_texcoords() const { return mesh_.has_vertex_texcoords2D(); }
00201 bool has_edge_colors() const { return mesh_.has_edge_colors(); }
00202 bool has_face_normals() const { return mesh_.has_face_normals(); }
00203 bool has_face_colors() const { return mesh_.has_face_colors(); }
00204
00205 private:
00206
00207 const Mesh& mesh_;
00208 };
00209
00210
00211
00212 }
00213 }
00214
00215 #endif
00216