57#ifndef __IMPORTERT_HH__
58#define __IMPORTERT_HH__
64#include <OpenMesh/Core/IO/importer/BaseImporter.hh>
65#include <OpenMesh/Core/Utils/vector_cast.hh>
66#include <OpenMesh/Core/Utils/color_cast.hh>
89 typedef typename Mesh::Point Point;
94 typedef std::vector<VertexHandle> VHandles;
97 ImporterT(Mesh& _mesh) : mesh_(_mesh), halfedgeNormals_() {}
102 return mesh_.add_vertex(vector_cast<Point>(_point));
107 return mesh_.new_vertex();
110 virtual FaceHandle add_face(
const VHandles& _indices)
114 if (_indices.size() > 2)
116 VHandles::const_iterator it, it2, end(_indices.end());
120 for (it=_indices.begin(); it!=end; ++it)
121 if (! mesh_.is_valid_handle(*it))
123 omerr() <<
"ImporterT: Face contains invalid vertex index\n";
129 for (it=_indices.begin(); it!=end; ++it)
130 for (it2=it+1; it2!=end; ++it2)
133 omerr() <<
"ImporterT: Face has equal vertices\n";
139 fh = mesh_.add_face(_indices);
143 VHandles vhandles(_indices.size());
146 for (
unsigned int j=0; j<_indices.size(); ++j)
150 Point p = mesh_.point(_indices[j]);
151 vhandles[j] = mesh_.add_vertex(p);
154 if (mesh_.has_vertex_status()) {
155 mesh_.status(vhandles[j]).set_fixed_nonmanifold(
true);
163 if (mesh_.has_face_status())
164 mesh_.status(fh).set_fixed_nonmanifold(
true);
167 if (mesh_.has_edge_status()) {
168 typename Mesh::FaceEdgeIter fe_it = mesh_.fe_iter(fh);
169 for(; fe_it.is_valid(); ++fe_it) {
170 mesh_.status(*fe_it).set_fixed_nonmanifold(
true);
176 if (mesh_.has_halfedge_normals())
179 for (
typename Mesh::FaceHalfedgeIter fh_iter = mesh_.fh_begin(fh);
180 fh_iter != mesh_.fh_end(fh); ++fh_iter)
183 typename Mesh::HalfedgeHandle heh = *fh_iter;
184 typename Mesh::VertexHandle vh = mesh_.to_vertex_handle(heh);
185 typename std::map<VertexHandle,Normal>::iterator it_heNs = halfedgeNormals_.find(vh);
186 if (it_heNs != halfedgeNormals_.end())
187 mesh_.set_normal(heh,it_heNs->second);
189 halfedgeNormals_.clear();
199 mesh_.set_point(_vh,vector_cast<Point>(_point));
204 if (mesh_.has_vertex_normals())
205 mesh_.set_normal(_vh, vector_cast<Normal>(_normal));
209 if (mesh_.has_halfedge_normals())
210 halfedgeNormals_[_vh] = vector_cast<Normal>(_normal);
215 if (mesh_.has_vertex_colors())
216 mesh_.set_color(_vh, color_cast<Color>(_color));
221 if (mesh_.has_vertex_colors())
222 mesh_.set_color(_vh, color_cast<Color>(_color));
227 if (mesh_.has_vertex_colors())
228 mesh_.set_color(_vh, color_cast<Color>(_color));
233 if (mesh_.has_vertex_colors())
234 mesh_.set_color(_vh, color_cast<Color>(_color));
239 if (mesh_.has_vertex_texcoords2D())
240 mesh_.set_texcoord2D(_vh, vector_cast<TexCoord2D>(_texcoord));
245 if (mesh_.has_halfedge_texcoords2D())
246 mesh_.set_texcoord2D(_heh, vector_cast<TexCoord2D>(_texcoord));
251 if (mesh_.has_vertex_texcoords3D())
252 mesh_.set_texcoord3D(_vh, vector_cast<TexCoord3D>(_texcoord));
257 if (mesh_.has_halfedge_texcoords3D())
258 mesh_.set_texcoord3D(_heh, vector_cast<TexCoord3D>(_texcoord));
266 if (mesh_.has_edge_colors())
267 mesh_.set_color(_eh, color_cast<Color>(_color));
272 if (mesh_.has_edge_colors())
273 mesh_.set_color(_eh, color_cast<Color>(_color));
278 if (mesh_.has_edge_colors())
279 mesh_.set_color(_eh, color_cast<Color>(_color));
284 if (mesh_.has_edge_colors())
285 mesh_.set_color(_eh, color_cast<Color>(_color));
292 if (mesh_.has_face_normals())
293 mesh_.set_normal(_fh, vector_cast<Normal>(_normal));
298 if (mesh_.has_face_colors())
299 mesh_.set_color(_fh, color_cast<Color>(_color));
304 if (mesh_.has_face_colors())
305 mesh_.set_color(_fh, color_cast<Color>(_color));
310 if (mesh_.has_face_colors())
311 mesh_.set_color(_fh, color_cast<Color>(_color));
316 if (mesh_.has_face_colors())
317 mesh_.set_color(_fh, color_cast<Color>(_color));
320 virtual void add_face_texcoords(
FaceHandle _fh,
VertexHandle _vh,
const std::vector<Vec2f>& _face_texcoords)
327 while( mesh_.to_vertex_handle(cur_heh) != _vh && cur_heh != end_heh )
328 cur_heh = mesh_.next_halfedge_handle( cur_heh);
330 for(
unsigned int i=0; i<_face_texcoords.size(); ++i)
332 set_texcoord( cur_heh, _face_texcoords[i]);
333 cur_heh = mesh_.next_halfedge_handle( cur_heh);
337 virtual void add_face_texcoords(
FaceHandle _fh,
VertexHandle _vh,
const std::vector<Vec3f>& _face_texcoords)
344 while( mesh_.to_vertex_handle(cur_heh) != _vh && cur_heh != end_heh )
345 cur_heh = mesh_.next_halfedge_handle( cur_heh);
347 for(
unsigned int i=0; i<_face_texcoords.size(); ++i)
349 set_texcoord( cur_heh, _face_texcoords[i]);
350 cur_heh = mesh_.next_halfedge_handle( cur_heh);
354 virtual void set_face_texindex(
FaceHandle _fh,
int _texId ) {
355 if ( mesh_.has_face_texture_index() ) {
356 mesh_.set_texture_index(_fh , _texId);
360 virtual void add_texture_information(
int _id , std::string _name ) {
363 if ( !mesh_.get_property_handle(property,
"TextureMapping") ) {
364 mesh_.add_property(property,
"TextureMapping");
367 if ( mesh_.property(property).find( _id ) == mesh_.property(property).end() )
368 mesh_.property(property)[_id] = _name;
373 virtual BaseKernel* kernel() {
return &mesh_; }
375 bool is_triangle_mesh()
const
376 {
return Mesh::is_triangles(); }
378 void reserve(
unsigned int nV,
unsigned int nE,
unsigned int nF)
380 mesh_.reserve(nV, nE, nF);
384 size_t n_vertices()
const {
return mesh_.n_vertices(); }
385 size_t n_faces()
const {
return mesh_.n_faces(); }
386 size_t n_edges()
const {
return mesh_.n_edges(); }
399 std::map<VertexHandle,Normal> halfedgeNormals_;
This file provides some macros containing attribute usage.
This file provides the streams omlog, omout, and omerr.
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
@ Normal
Add normals to mesh item (vertices/faces)
Definition: Attributes.hh:87
@ TexCoord2D
Add 2D texture coordinates (vertices, halfedges)
Definition: Attributes.hh:92
@ TexCoord3D
Add 3D texture coordinates (vertices, halfedges)
Definition: Attributes.hh:93
@ Color
Add colors to mesh item (vertices/faces/edges)
Definition: Attributes.hh:88
Base class for importer modules.
Definition: BaseImporter.hh:89
This class template provides an importer module for OpenMesh meshes.
Definition: ImporterT.hh:86
This class provides low-level property management like adding/removing properties and access to prope...
Definition: BaseKernel.hh:103
bool is_valid() const
The handle is valid iff the index is not equal to -1.
Definition: Handles.hh:77
Handle for a vertex entity.
Definition: Handles.hh:126
Handle for a halfedge entity.
Definition: Handles.hh:133
Handle for a edge entity.
Definition: Handles.hh:140
Handle for a face entity.
Definition: Handles.hh:147
Handle representing a mesh property.
Definition: Property.hh:544