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 __IMPORTERT_HH__
00035 #define __IMPORTERT_HH__
00036
00037
00038
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
00047
00048
00049 namespace OpenMesh {
00050 namespace IO {
00051
00052
00053
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
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
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
00124
00125 virtual BaseKernel& kernel() { return mesh_; }
00126
00127 bool is_triangle_mesh() const
00128 {
00129 typedef typename Mesh::Face Face;
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
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 }
00152 }
00153
00154 #endif
00155