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 for (it=_indices.begin(); it!=end; ++it)
126 if (! mesh_.is_valid_handle(*it))
128 omerr() <<
"ImporterT: Face contains invalid vertex index\n";
134 for (it=_indices.begin(); it!=end; ++it)
135 for (it2=it+1; it2!=end; ++it2)
138 omerr() <<
"ImporterT: Face has equal vertices\n";
144 fh = mesh_.add_face(_indices);
148 VHandles vhandles(_indices.size());
151 for (
unsigned int j=0; j<_indices.size(); ++j)
155 Point p = mesh_.point(_indices[j]);
159 if (mesh_.has_vertex_status()) {
160 mesh_.status(vhandles[j]).set_fixed_nonmanifold(
true);
165 fh = mesh_.add_face(vhandles);
168 if (mesh_.has_face_status())
169 mesh_.status(fh).set_fixed_nonmanifold(
true);
172 if (mesh_.has_edge_status()) {
174 for(; fe_it.is_valid(); ++fe_it) {
175 mesh_.status(*fe_it).set_fixed_nonmanifold(
true);
181 if (mesh_.has_halfedge_normals())
185 fh_iter != mesh_.fh_end(fh); ++fh_iter)
190 typename std::map<VertexHandle,Normal>::iterator it_heNs = halfedgeNormals_.find(vh);
191 if (it_heNs != halfedgeNormals_.end())
192 mesh_.set_normal(heh,it_heNs->second);
194 halfedgeNormals_.clear();
202 auto fh = mesh_.new_face();
203 mesh_.set_halfedge_handle(fh, _heh);
211 mesh_.set_point(_vh,vector_cast<Point>(_point));
216 mesh_.set_halfedge_handle(_vh, _heh);
221 if (mesh_.has_vertex_normals())
222 mesh_.set_normal(_vh, vector_cast<Normal>(_normal));
226 if (mesh_.has_halfedge_normals())
227 halfedgeNormals_[_vh] = vector_cast<Normal>(_normal);
232 if (mesh_.has_vertex_normals())
233 mesh_.set_normal(_vh, vector_cast<Normal>(_normal));
237 if (mesh_.has_halfedge_normals())
238 halfedgeNormals_[_vh] = vector_cast<Normal>(_normal);
243 if (mesh_.has_vertex_colors())
244 mesh_.set_color(_vh, color_cast<Color>(_color));
249 if (mesh_.has_vertex_colors())
250 mesh_.set_color(_vh, color_cast<Color>(_color));
255 if (mesh_.has_vertex_colors())
256 mesh_.set_color(_vh, color_cast<Color>(_color));
261 if (mesh_.has_vertex_colors())
262 mesh_.set_color(_vh, color_cast<Color>(_color));
267 if (mesh_.has_vertex_texcoords2D())
268 mesh_.set_texcoord2D(_vh, vector_cast<TexCoord2D>(_texcoord));
273 if (!mesh_.has_vertex_status())
274 mesh_.request_vertex_status();
275 mesh_.status(_vh) = _status;
280 mesh_.set_next_halfedge_handle(_heh, _next);
285 mesh_.set_face_handle(_heh, _fh);
291 if (mesh_.has_halfedge_texcoords2D())
292 mesh_.set_texcoord2D(_heh, vector_cast<TexCoord2D>(_texcoord));
297 if (mesh_.has_vertex_texcoords3D())
298 mesh_.set_texcoord3D(_vh, vector_cast<TexCoord3D>(_texcoord));
303 if (mesh_.has_halfedge_texcoords3D())
304 mesh_.set_texcoord3D(_heh, vector_cast<TexCoord3D>(_texcoord));
309 if (!mesh_.has_halfedge_status())
310 mesh_.request_halfedge_status();
311 mesh_.status(_heh) = _status;
318 if (mesh_.has_edge_colors())
319 mesh_.set_color(_eh, color_cast<Color>(_color));
324 if (mesh_.has_edge_colors())
325 mesh_.set_color(_eh, color_cast<Color>(_color));
330 if (mesh_.has_edge_colors())
331 mesh_.set_color(_eh, color_cast<Color>(_color));
336 if (mesh_.has_edge_colors())
337 mesh_.set_color(_eh, color_cast<Color>(_color));
342 if (!mesh_.has_edge_status())
343 mesh_.request_edge_status();
344 mesh_.status(_eh) = _status;
351 if (mesh_.has_face_normals())
352 mesh_.set_normal(_fh, vector_cast<Normal>(_normal));
357 if (mesh_.has_face_normals())
358 mesh_.set_normal(_fh, vector_cast<Normal>(_normal));
363 if (mesh_.has_face_colors())
364 mesh_.set_color(_fh, color_cast<Color>(_color));
369 if (mesh_.has_face_colors())
370 mesh_.set_color(_fh, color_cast<Color>(_color));
375 if (mesh_.has_face_colors())
376 mesh_.set_color(_fh, color_cast<Color>(_color));
381 if (mesh_.has_face_colors())
382 mesh_.set_color(_fh, color_cast<Color>(_color));
387 if (!mesh_.has_face_status())
388 mesh_.request_face_status();
389 mesh_.status(_fh) = _status;
392 virtual void add_face_texcoords(
FaceHandle _fh,
VertexHandle _vh,
const std::vector<Vec2f>& _face_texcoords)
override
399 while( mesh_.to_vertex_handle(cur_heh) != _vh && cur_heh != end_heh )
400 cur_heh = mesh_.next_halfedge_handle( cur_heh);
402 for(
unsigned int i=0; i<_face_texcoords.size(); ++i)
404 set_texcoord( cur_heh, _face_texcoords[i]);
405 cur_heh = mesh_.next_halfedge_handle( cur_heh);
409 virtual void add_face_texcoords(
FaceHandle _fh,
VertexHandle _vh,
const std::vector<Vec3f>& _face_texcoords)
override
416 while( mesh_.to_vertex_handle(cur_heh) != _vh && cur_heh != end_heh )
417 cur_heh = mesh_.next_halfedge_handle( cur_heh);
419 for(
unsigned int i=0; i<_face_texcoords.size(); ++i)
421 set_texcoord( cur_heh, _face_texcoords[i]);
422 cur_heh = mesh_.next_halfedge_handle( cur_heh);
426 virtual void set_face_texindex(
FaceHandle _fh,
int _texId )
override
428 if ( mesh_.has_face_texture_index() ) {
429 mesh_.set_texture_index(_fh , _texId);
433 virtual void add_texture_information(
int _id , std::string _name )
override
437 if ( !mesh_.get_property_handle(property,
"TextureMapping") ) {
438 mesh_.add_property(property,
"TextureMapping");
441 if ( mesh_.property(property).find( _id ) == mesh_.property(property).end() )
442 mesh_.property(property)[_id] = _name;
447 virtual BaseKernel* kernel()
override {
return &mesh_; }
449 bool is_triangle_mesh()
const override
450 {
return Mesh::is_triangles(); }
452 void reserve(
unsigned int nV,
unsigned int nE,
unsigned int nF)
override
454 mesh_.reserve(nV, nE, nF);
458 size_t n_vertices()
const override {
return mesh_.n_vertices(); }
459 size_t n_faces()
const override {
return mesh_.n_faces(); }
460 size_t n_edges()
const override {
return mesh_.n_edges(); }
463 void prepare()
override{ }
466 void finish()
override { }
473 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: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
SmartVertexHandle add_vertex(const Point &_p)
Alias for new_vertex(const Point&).
Definition: PolyMeshT.hh:235
Kernel::TexCoord3D TexCoord3D
TexCoord3D type.
Definition: PolyMeshT.hh:122
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:545