52#ifndef __IMPORTERT_HH__
53#define __IMPORTERT_HH__
59#include <OpenMesh/Core/IO/importer/BaseImporter.hh>
60#include <OpenMesh/Core/Utils/vector_cast.hh>
61#include <OpenMesh/Core/Utils/color_cast.hh>
89 typedef std::vector<VertexHandle> VHandles;
92 explicit ImporterT(
Mesh& _mesh) : mesh_(_mesh), halfedgeNormals_() {}
97 return mesh_.
add_vertex(vector_cast<Point>(_point));
102 return mesh_.
add_vertex(vector_cast<Point>(_point));
112 return mesh_.new_edge(_vh0, _vh1);
115 virtual FaceHandle add_face(
const VHandles& _indices)
override
119 if (_indices.size() > 2)
121 VHandles::const_iterator it, it2, end(_indices.end());
125 if ( std::any_of(_indices.begin(),_indices.end(),[
this](
const VertexHandle& vh){ return !mesh_.is_valid_handle(vh); } ) )
127 omerr() <<
"ImporterT: Face contains invalid vertex index\n";
132 for (it=_indices.begin(); it!=end; ++it)
133 for (it2=it+1; it2!=end; ++it2)
136 omerr() <<
"ImporterT: Face has equal vertices\n";
142 fh = mesh_.add_face(_indices);
146 VHandles vhandles(_indices.size());
149 for (
unsigned int j=0; j<_indices.size(); ++j)
153 Point p = mesh_.point(_indices[j]);
157 if (mesh_.has_vertex_status()) {
158 mesh_.status(vhandles[j]).set_fixed_nonmanifold(
true);
163 fh = mesh_.add_face(vhandles);
166 if (mesh_.has_face_status())
167 mesh_.status(fh).set_fixed_nonmanifold(
true);
170 if (mesh_.has_edge_status()) {
172 for(; fe_it.is_valid(); ++fe_it) {
173 mesh_.status(*fe_it).set_fixed_nonmanifold(
true);
179 if (mesh_.has_halfedge_normals())
183 fh_iter != mesh_.fh_end(fh); ++fh_iter)
188 typename std::map<VertexHandle,Normal>::iterator it_heNs = halfedgeNormals_.find(vh);
189 if (it_heNs != halfedgeNormals_.end())
190 mesh_.set_normal(heh,it_heNs->second);
192 halfedgeNormals_.clear();
200 auto fh = mesh_.new_face();
201 mesh_.set_halfedge_handle(fh, _heh);
209 mesh_.set_point(_vh,vector_cast<Point>(_point));
214 mesh_.set_halfedge_handle(_vh, _heh);
219 if (mesh_.has_vertex_normals())
220 mesh_.set_normal(_vh, vector_cast<Normal>(_normal));
224 if (mesh_.has_halfedge_normals())
225 halfedgeNormals_[_vh] = vector_cast<Normal>(_normal);
230 if (mesh_.has_vertex_normals())
231 mesh_.set_normal(_vh, vector_cast<Normal>(_normal));
235 if (mesh_.has_halfedge_normals())
236 halfedgeNormals_[_vh] = vector_cast<Normal>(_normal);
241 if (mesh_.has_vertex_colors())
242 mesh_.set_color(_vh, color_cast<Color>(_color));
247 if (mesh_.has_vertex_colors())
248 mesh_.set_color(_vh, color_cast<Color>(_color));
253 if (mesh_.has_vertex_colors())
254 mesh_.set_color(_vh, color_cast<Color>(_color));
259 if (mesh_.has_vertex_colors())
260 mesh_.set_color(_vh, color_cast<Color>(_color));
265 if (mesh_.has_vertex_texcoords2D())
266 mesh_.set_texcoord2D(_vh, vector_cast<TexCoord2D>(_texcoord));
271 if (!mesh_.has_vertex_status())
272 mesh_.request_vertex_status();
273 mesh_.status(_vh) = _status;
278 mesh_.set_next_halfedge_handle(_heh, _next);
283 mesh_.set_face_handle(_heh, _fh);
286 virtual void request_face_texcoords2D()
override
288 if(!mesh_.has_halfedge_texcoords2D())
289 mesh_.request_halfedge_texcoords2D();
294 if (mesh_.has_halfedge_texcoords2D())
295 mesh_.set_texcoord2D(_heh, vector_cast<TexCoord2D>(_texcoord));
300 if (mesh_.has_vertex_texcoords3D())
301 mesh_.set_texcoord3D(_vh, vector_cast<TexCoord3D>(_texcoord));
306 if (mesh_.has_halfedge_texcoords3D())
307 mesh_.set_texcoord3D(_heh, vector_cast<TexCoord3D>(_texcoord));
312 if (!mesh_.has_halfedge_status())
313 mesh_.request_halfedge_status();
314 mesh_.status(_heh) = _status;
321 if (mesh_.has_edge_colors())
322 mesh_.set_color(_eh, color_cast<Color>(_color));
327 if (mesh_.has_edge_colors())
328 mesh_.set_color(_eh, color_cast<Color>(_color));
333 if (mesh_.has_edge_colors())
334 mesh_.set_color(_eh, color_cast<Color>(_color));
339 if (mesh_.has_edge_colors())
340 mesh_.set_color(_eh, color_cast<Color>(_color));
345 if (!mesh_.has_edge_status())
346 mesh_.request_edge_status();
347 mesh_.status(_eh) = _status;
354 if (mesh_.has_face_normals())
355 mesh_.set_normal(_fh, vector_cast<Normal>(_normal));
360 if (mesh_.has_face_normals())
361 mesh_.set_normal(_fh, vector_cast<Normal>(_normal));
366 if (mesh_.has_face_colors())
367 mesh_.set_color(_fh, color_cast<Color>(_color));
372 if (mesh_.has_face_colors())
373 mesh_.set_color(_fh, color_cast<Color>(_color));
378 if (mesh_.has_face_colors())
379 mesh_.set_color(_fh, color_cast<Color>(_color));
384 if (mesh_.has_face_colors())
385 mesh_.set_color(_fh, color_cast<Color>(_color));
390 if (!mesh_.has_face_status())
391 mesh_.request_face_status();
392 mesh_.status(_fh) = _status;
395 virtual void add_face_texcoords(
FaceHandle _fh,
VertexHandle _vh,
const std::vector<Vec2f>& _face_texcoords)
override
402 while( mesh_.to_vertex_handle(cur_heh) != _vh && cur_heh != end_heh )
403 cur_heh = mesh_.next_halfedge_handle( cur_heh);
405 for(
unsigned int i=0; i<_face_texcoords.size(); ++i)
407 set_texcoord( cur_heh, _face_texcoords[i]);
408 cur_heh = mesh_.next_halfedge_handle( cur_heh);
412 virtual void add_face_texcoords(
FaceHandle _fh,
VertexHandle _vh,
const std::vector<Vec3f>& _face_texcoords)
override
419 while( mesh_.to_vertex_handle(cur_heh) != _vh && cur_heh != end_heh )
420 cur_heh = mesh_.next_halfedge_handle( cur_heh);
422 for(
unsigned int i=0; i<_face_texcoords.size(); ++i)
424 set_texcoord( cur_heh, _face_texcoords[i]);
425 cur_heh = mesh_.next_halfedge_handle( cur_heh);
429 virtual void set_face_texindex(
FaceHandle _fh,
int _texId )
override
431 if ( mesh_.has_face_texture_index() ) {
432 mesh_.set_texture_index(_fh , _texId);
436 virtual void add_texture_information(
int _id , std::string _name )
override
440 if ( !mesh_.get_property_handle(property,
"TextureMapping") ) {
441 mesh_.add_property(property,
"TextureMapping");
444 if ( mesh_.property(property).find( _id ) == mesh_.property(property).end() ) {
445 mesh_.property(property)[_id] = _name;
451 virtual BaseKernel* kernel()
override {
return &mesh_; }
453 bool is_triangle_mesh()
const override
454 {
return Mesh::is_triangles(); }
456 void reserve(
unsigned int nV,
unsigned int nE,
unsigned int nF)
override
458 mesh_.reserve(nV, nE, nF);
462 size_t n_vertices()
const override {
return mesh_.n_vertices(); }
463 size_t n_faces()
const override {
return mesh_.n_faces(); }
464 size_t n_edges()
const override {
return mesh_.n_edges(); }
467 void prepare()
override{ }
470 void finish()
override { }
477 std::map<VertexHandle,Normal> halfedgeNormals_;
This file provides the streams omlog, omout, and omerr.
This file provides some macros containing attribute usage.
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
Base class for importer modules.
Definition: BaseImporter.hh:84
This class template provides an importer module for OpenMesh meshes.
Definition: ImporterT.hh:81
This class provides low-level property management like adding/removing properties and access to prope...
Definition: BaseKernel.hh:98
bool is_valid() const
The handle is valid iff the index is not negative.
Definition: Handles.hh:72
Handle for a vertex entity.
Definition: Handles.hh:121
Handle for a halfedge entity.
Definition: Handles.hh:128
Handle for a edge entity.
Definition: Handles.hh:135
Handle for a face entity.
Definition: Handles.hh:142
Polygonal mesh based on the ArrayKernel.
Definition: PolyMesh_ArrayKernelT.hh:96
Kernel::FaceEdgeIter FaceEdgeIter
Circulator.
Definition: PolyMeshT.hh:169
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
Definition: PolyMeshT.hh:136
Kernel::Normal Normal
Normal type.
Definition: PolyMeshT.hh:114
SmartVertexHandle new_vertex()
Uses default copy and assignment operator.
Definition: PolyMeshT.hh:201
Kernel::TexCoord2D TexCoord2D
TexCoord2D type.
Definition: PolyMeshT.hh:120
Kernel::TexCoord3D TexCoord3D
TexCoord3D type.
Definition: PolyMeshT.hh:122
SmartVertexHandle add_vertex(const Point _p)
Alias for new_vertex(const Point&).
Definition: PolyMeshT.hh:238
Kernel::HalfedgeHandle HalfedgeHandle
Scalar type.
Definition: PolyMeshT.hh:137
Kernel::FaceHalfedgeIter FaceHalfedgeIter
Circulator.
Definition: PolyMeshT.hh:168
Kernel::Point Point
Coordinate type.
Definition: PolyMeshT.hh:112
Kernel::Color Color
Color type.
Definition: PolyMeshT.hh:116
Add status information to a base class.
Definition: Status.hh:95
Handle representing a mesh property.
Definition: Property.hh:477