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;
93 typedef std::vector<VertexHandle> VHandles;
96 ImporterT(Mesh& _mesh) : mesh_(_mesh), halfedgeNormals_() {}
101 return mesh_.add_vertex(vector_cast<Point>(_point));
106 return mesh_.new_vertex();
109 virtual FaceHandle add_face(
const VHandles& _indices)
113 if (_indices.size() > 2)
115 VHandles::const_iterator it, it2, end(_indices.end());
119 for (it=_indices.begin(); it!=end; ++it)
120 if (! mesh_.is_valid_handle(*it))
122 omerr() <<
"ImporterT: Face contains invalid vertex index\n";
128 for (it=_indices.begin(); it!=end; ++it)
129 for (it2=it+1; it2!=end; ++it2)
132 omerr() <<
"ImporterT: Face has equal vertices\n";
133 failed_faces_.push_back(_indices);
139 fh = mesh_.add_face(_indices);
142 failed_faces_.push_back(_indices);
147 if (mesh_.has_halfedge_normals())
150 for (
typename Mesh::FaceHalfedgeIter fh_iter = mesh_.fh_begin(fh);
151 fh_iter != mesh_.fh_end(fh); ++fh_iter)
154 typename Mesh::HalfedgeHandle heh = *fh_iter;
155 typename Mesh::VertexHandle vh = mesh_.to_vertex_handle(heh);
156 typename std::map<VertexHandle,Normal>::iterator it_heNs = halfedgeNormals_.find(vh);
157 if (it_heNs != halfedgeNormals_.end())
158 mesh_.set_normal(heh,it_heNs->second);
160 halfedgeNormals_.clear();
168 virtual void set_point(
VertexHandle _vh,
const Vec3f& _point)
170 mesh_.set_point(_vh,vector_cast<Point>(_point));
173 virtual void set_normal(
VertexHandle _vh,
const Vec3f& _normal)
175 if (mesh_.has_vertex_normals())
176 mesh_.set_normal(_vh, vector_cast<Normal>(_normal));
180 if (mesh_.has_halfedge_normals())
181 halfedgeNormals_[_vh] = vector_cast<Normal>(_normal);
184 virtual void set_color(
VertexHandle _vh,
const Vec4uc& _color)
186 if (mesh_.has_vertex_colors())
187 mesh_.set_color(_vh, color_cast<Color>(_color));
190 virtual void set_color(
VertexHandle _vh,
const Vec3uc& _color)
192 if (mesh_.has_vertex_colors())
193 mesh_.set_color(_vh, color_cast<Color>(_color));
196 virtual void set_color(
VertexHandle _vh,
const Vec4f& _color)
198 if (mesh_.has_vertex_colors())
199 mesh_.set_color(_vh, color_cast<Color>(_color));
202 virtual void set_color(
VertexHandle _vh,
const Vec3f& _color)
204 if (mesh_.has_vertex_colors())
205 mesh_.set_color(_vh, color_cast<Color>(_color));
208 virtual void set_texcoord(
VertexHandle _vh,
const Vec2f& _texcoord)
210 if (mesh_.has_vertex_texcoords2D())
211 mesh_.set_texcoord2D(_vh, vector_cast<TexCoord2D>(_texcoord));
214 virtual void set_texcoord(
HalfedgeHandle _heh,
const Vec2f& _texcoord)
216 if (mesh_.has_halfedge_texcoords2D())
217 mesh_.set_texcoord2D(_heh, vector_cast<TexCoord2D>(_texcoord));
222 virtual void set_color(
EdgeHandle _eh,
const Vec4uc& _color)
224 if (mesh_.has_edge_colors())
225 mesh_.set_color(_eh, color_cast<Color>(_color));
228 virtual void set_color(
EdgeHandle _eh,
const Vec3uc& _color)
230 if (mesh_.has_edge_colors())
231 mesh_.set_color(_eh, color_cast<Color>(_color));
234 virtual void set_color(
EdgeHandle _eh,
const Vec4f& _color)
236 if (mesh_.has_edge_colors())
237 mesh_.set_color(_eh, color_cast<Color>(_color));
240 virtual void set_color(
EdgeHandle _eh,
const Vec3f& _color)
242 if (mesh_.has_edge_colors())
243 mesh_.set_color(_eh, color_cast<Color>(_color));
248 virtual void set_normal(
FaceHandle _fh,
const Vec3f& _normal)
250 if (mesh_.has_face_normals())
251 mesh_.set_normal(_fh, vector_cast<Normal>(_normal));
254 virtual void set_color(
FaceHandle _fh,
const Vec3uc& _color)
256 if (mesh_.has_face_colors())
257 mesh_.set_color(_fh, color_cast<Color>(_color));
260 virtual void set_color(
FaceHandle _fh,
const Vec4uc& _color)
262 if (mesh_.has_face_colors())
263 mesh_.set_color(_fh, color_cast<Color>(_color));
266 virtual void set_color(
FaceHandle _fh,
const Vec3f& _color)
268 if (mesh_.has_face_colors())
269 mesh_.set_color(_fh, color_cast<Color>(_color));
272 virtual void set_color(
FaceHandle _fh,
const Vec4f& _color)
274 if (mesh_.has_face_colors())
275 mesh_.set_color(_fh, color_cast<Color>(_color));
278 virtual void add_face_texcoords(
FaceHandle _fh,
VertexHandle _vh,
const std::vector<Vec2f>& _face_texcoords)
285 while( mesh_.to_vertex_handle(cur_heh) != _vh && cur_heh != end_heh )
286 cur_heh = mesh_.next_halfedge_handle( cur_heh);
288 for(
unsigned int i=0; i<_face_texcoords.size(); ++i)
290 set_texcoord( cur_heh, _face_texcoords[i]);
291 cur_heh = mesh_.next_halfedge_handle( cur_heh);
295 virtual void set_face_texindex(
FaceHandle _fh,
int _texId ) {
296 if ( mesh_.has_face_texture_index() ) {
297 mesh_.set_texture_index(_fh , _texId);
301 virtual void add_texture_information(
int _id , std::string _name ) {
304 if ( !mesh_.get_property_handle(property,
"TextureMapping") ) {
305 mesh_.add_property(property,
"TextureMapping");
308 if ( mesh_.property(property).find( _id ) == mesh_.property(property).end() )
309 mesh_.property(property)[_id] = _name;
314 virtual BaseKernel* kernel() {
return &mesh_; }
316 bool is_triangle_mesh()
const 317 {
return Mesh::is_triangles(); }
319 void reserve(
unsigned int nV,
unsigned int nE,
unsigned int nF)
321 mesh_.reserve(nV, nE, nF);
325 size_t n_vertices()
const {
return mesh_.n_vertices(); }
326 size_t n_faces()
const {
return mesh_.n_faces(); }
327 size_t n_edges()
const {
return mesh_.n_edges(); }
330 void prepare() { failed_faces_.clear(); }
335 if (!failed_faces_.empty())
337 omerr() << failed_faces_.size()
338 <<
" faces failed, adding them as isolated faces\n";
340 for (
unsigned int i=0; i<failed_faces_.size(); ++i)
342 VHandles& vhandles = failed_faces_[i];
345 for (
unsigned int j=0; j<vhandles.size(); ++j)
347 Point p = mesh_.point(vhandles[j]);
348 vhandles[j] = mesh_.add_vertex(p);
353 if (mesh_.has_vertex_status()) {
354 mesh_.status(vhandles[j]).set_fixed_nonmanifold(
true);
362 if (mesh_.has_face_status())
363 mesh_.status(fh).set_fixed_nonmanifold(
true);
366 if (mesh_.has_edge_status()) {
367 typename Mesh::FaceEdgeIter fe_it = mesh_.fe_iter(fh);
368 for(; fe_it.is_valid(); ++fe_it) {
369 mesh_.status(*fe_it).set_fixed_nonmanifold(
true);
374 failed_faces_.clear();
383 std::vector<VHandles> failed_faces_;
385 std::map<VertexHandle,Normal> halfedgeNormals_;
Add normals to mesh item (vertices/faces)
Definition: Attributes.hh:87
Add colors to mesh item (vertices/faces/edges)
Definition: Attributes.hh:88
Handle for a halfedge entity.
Definition: Handles.hh:128
This class template provides an importer module for OpenMesh meshes.
Definition: ImporterT.hh:85
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
Handle for a edge entity.
Definition: Handles.hh:135
Add 2D texture coordinates (vertices, halfedges)
Definition: Attributes.hh:92
This class provides the basic property management like adding/removing properties and access to prope...
Definition: BaseKernel.hh:99
Handle for a face entity.
Definition: Handles.hh:142
bool is_valid() const
The handle is valid iff the index is not equal to -1.
Definition: Handles.hh:77
This file provides some macros containing attribute usage.
Handle for a vertex entity.
Definition: Handles.hh:121
Base class for importer modules.
Definition: BaseImporter.hh:88
This file provides the streams omlog, omout, and omerr.
Handle representing a mesh property.
Definition: Property.hh:543