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);
288 virtual void request_face_texcoords2D()
override
290 if(!mesh_.has_halfedge_texcoords2D())
291 mesh_.request_halfedge_texcoords2D();
296 if (mesh_.has_halfedge_texcoords2D())
297 mesh_.set_texcoord2D(_heh, vector_cast<TexCoord2D>(_texcoord));
302 if (mesh_.has_vertex_texcoords3D())
303 mesh_.set_texcoord3D(_vh, vector_cast<TexCoord3D>(_texcoord));
308 if (mesh_.has_halfedge_texcoords3D())
309 mesh_.set_texcoord3D(_heh, vector_cast<TexCoord3D>(_texcoord));
314 if (!mesh_.has_halfedge_status())
315 mesh_.request_halfedge_status();
316 mesh_.status(_heh) = _status;
323 if (mesh_.has_edge_colors())
324 mesh_.set_color(_eh, color_cast<Color>(_color));
329 if (mesh_.has_edge_colors())
330 mesh_.set_color(_eh, color_cast<Color>(_color));
335 if (mesh_.has_edge_colors())
336 mesh_.set_color(_eh, color_cast<Color>(_color));
341 if (mesh_.has_edge_colors())
342 mesh_.set_color(_eh, color_cast<Color>(_color));
347 if (!mesh_.has_edge_status())
348 mesh_.request_edge_status();
349 mesh_.status(_eh) = _status;
356 if (mesh_.has_face_normals())
357 mesh_.set_normal(_fh, vector_cast<Normal>(_normal));
362 if (mesh_.has_face_normals())
363 mesh_.set_normal(_fh, vector_cast<Normal>(_normal));
368 if (mesh_.has_face_colors())
369 mesh_.set_color(_fh, color_cast<Color>(_color));
374 if (mesh_.has_face_colors())
375 mesh_.set_color(_fh, color_cast<Color>(_color));
380 if (mesh_.has_face_colors())
381 mesh_.set_color(_fh, color_cast<Color>(_color));
386 if (mesh_.has_face_colors())
387 mesh_.set_color(_fh, color_cast<Color>(_color));
392 if (!mesh_.has_face_status())
393 mesh_.request_face_status();
394 mesh_.status(_fh) = _status;
397 virtual void add_face_texcoords(
FaceHandle _fh,
VertexHandle _vh,
const std::vector<Vec2f>& _face_texcoords)
override
404 while( mesh_.to_vertex_handle(cur_heh) != _vh && cur_heh != end_heh )
405 cur_heh = mesh_.next_halfedge_handle( cur_heh);
407 for(
unsigned int i=0; i<_face_texcoords.size(); ++i)
409 set_texcoord( cur_heh, _face_texcoords[i]);
410 cur_heh = mesh_.next_halfedge_handle( cur_heh);
414 virtual void add_face_texcoords(
FaceHandle _fh,
VertexHandle _vh,
const std::vector<Vec3f>& _face_texcoords)
override
421 while( mesh_.to_vertex_handle(cur_heh) != _vh && cur_heh != end_heh )
422 cur_heh = mesh_.next_halfedge_handle( cur_heh);
424 for(
unsigned int i=0; i<_face_texcoords.size(); ++i)
426 set_texcoord( cur_heh, _face_texcoords[i]);
427 cur_heh = mesh_.next_halfedge_handle( cur_heh);
431 virtual void set_face_texindex(
FaceHandle _fh,
int _texId )
override
433 if ( mesh_.has_face_texture_index() ) {
434 mesh_.set_texture_index(_fh , _texId);
438 virtual void add_texture_information(
int _id , std::string _name )
override
442 if ( !mesh_.get_property_handle(property,
"TextureMapping") ) {
443 mesh_.add_property(property,
"TextureMapping");
446 if ( mesh_.property(property).find( _id ) == mesh_.property(property).end() )
447 mesh_.property(property)[_id] = _name;
452 virtual BaseKernel* kernel()
override {
return &mesh_; }
454 bool is_triangle_mesh()
const override
455 {
return Mesh::is_triangles(); }
457 void reserve(
unsigned int nV,
unsigned int nE,
unsigned int nF)
override
459 mesh_.reserve(nV, nE, nF);
463 size_t n_vertices()
const override {
return mesh_.n_vertices(); }
464 size_t n_faces()
const override {
return mesh_.n_faces(); }
465 size_t n_edges()
const override {
return mesh_.n_edges(); }
468 void prepare()
override{ }
471 void finish()
override { }
478 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:245
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:477