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));
107 return mesh_.new_edge(_vh0, _vh1);
110 virtual FaceHandle add_face(
const VHandles& _indices)
override 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]);
154 if (mesh_.has_vertex_status()) {
155 mesh_.status(vhandles[j]).set_fixed_nonmanifold(
true);
160 fh = mesh_.add_face(vhandles);
163 if (mesh_.has_face_status())
164 mesh_.status(fh).set_fixed_nonmanifold(
true);
167 if (mesh_.has_edge_status()) {
169 for(; fe_it.is_valid(); ++fe_it) {
170 mesh_.status(*fe_it).set_fixed_nonmanifold(
true);
176 if (mesh_.has_halfedge_normals())
180 fh_iter != mesh_.fh_end(fh); ++fh_iter)
183 typename Mesh::HalfedgeHandle heh = *fh_iter;
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();
197 auto fh = mesh_.new_face();
198 mesh_.set_halfedge_handle(fh, _heh);
206 mesh_.set_point(_vh,vector_cast<Point>(_point));
211 mesh_.set_halfedge_handle(_vh, _heh);
216 if (mesh_.has_vertex_normals())
217 mesh_.set_normal(_vh, vector_cast<Normal>(_normal));
221 if (mesh_.has_halfedge_normals())
222 halfedgeNormals_[_vh] = vector_cast<Normal>(_normal);
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_colors())
240 mesh_.set_color(_vh, color_cast<Color>(_color));
245 if (mesh_.has_vertex_colors())
246 mesh_.set_color(_vh, color_cast<Color>(_color));
251 if (mesh_.has_vertex_texcoords2D())
252 mesh_.set_texcoord2D(_vh, vector_cast<TexCoord2D>(_texcoord));
257 if (!mesh_.has_vertex_status())
258 mesh_.request_vertex_status();
259 mesh_.status(_vh) = _status;
264 mesh_.set_next_halfedge_handle(_heh, _next);
269 mesh_.set_face_handle(_heh, _fh);
275 if (mesh_.has_halfedge_texcoords2D())
276 mesh_.set_texcoord2D(_heh, vector_cast<TexCoord2D>(_texcoord));
281 if (mesh_.has_vertex_texcoords3D())
282 mesh_.set_texcoord3D(_vh, vector_cast<TexCoord3D>(_texcoord));
287 if (mesh_.has_halfedge_texcoords3D())
288 mesh_.set_texcoord3D(_heh, vector_cast<TexCoord3D>(_texcoord));
293 if (!mesh_.has_halfedge_status())
294 mesh_.request_halfedge_status();
295 mesh_.status(_heh) = _status;
302 if (mesh_.has_edge_colors())
303 mesh_.set_color(_eh, color_cast<Color>(_color));
308 if (mesh_.has_edge_colors())
309 mesh_.set_color(_eh, color_cast<Color>(_color));
314 if (mesh_.has_edge_colors())
315 mesh_.set_color(_eh, color_cast<Color>(_color));
320 if (mesh_.has_edge_colors())
321 mesh_.set_color(_eh, color_cast<Color>(_color));
326 if (!mesh_.has_edge_status())
327 mesh_.request_edge_status();
328 mesh_.status(_eh) = _status;
335 if (mesh_.has_face_normals())
336 mesh_.set_normal(_fh, vector_cast<Normal>(_normal));
341 if (mesh_.has_face_colors())
342 mesh_.set_color(_fh, color_cast<Color>(_color));
347 if (mesh_.has_face_colors())
348 mesh_.set_color(_fh, color_cast<Color>(_color));
353 if (mesh_.has_face_colors())
354 mesh_.set_color(_fh, color_cast<Color>(_color));
359 if (mesh_.has_face_colors())
360 mesh_.set_color(_fh, color_cast<Color>(_color));
365 if (!mesh_.has_face_status())
366 mesh_.request_face_status();
367 mesh_.status(_fh) = _status;
370 virtual void add_face_texcoords(
FaceHandle _fh,
VertexHandle _vh,
const std::vector<Vec2f>& _face_texcoords)
override 377 while( mesh_.to_vertex_handle(cur_heh) != _vh && cur_heh != end_heh )
378 cur_heh = mesh_.next_halfedge_handle( cur_heh);
380 for(
unsigned int i=0; i<_face_texcoords.size(); ++i)
382 set_texcoord( cur_heh, _face_texcoords[i]);
383 cur_heh = mesh_.next_halfedge_handle( cur_heh);
387 virtual void add_face_texcoords(
FaceHandle _fh,
VertexHandle _vh,
const std::vector<Vec3f>& _face_texcoords)
override 394 while( mesh_.to_vertex_handle(cur_heh) != _vh && cur_heh != end_heh )
395 cur_heh = mesh_.next_halfedge_handle( cur_heh);
397 for(
unsigned int i=0; i<_face_texcoords.size(); ++i)
399 set_texcoord( cur_heh, _face_texcoords[i]);
400 cur_heh = mesh_.next_halfedge_handle( cur_heh);
404 virtual void set_face_texindex(
FaceHandle _fh,
int _texId )
override 406 if ( mesh_.has_face_texture_index() ) {
407 mesh_.set_texture_index(_fh , _texId);
411 virtual void add_texture_information(
int _id , std::string _name )
override 415 if ( !mesh_.get_property_handle(property,
"TextureMapping") ) {
416 mesh_.add_property(property,
"TextureMapping");
419 if ( mesh_.property(property).find( _id ) == mesh_.property(property).end() )
420 mesh_.property(property)[_id] = _name;
425 virtual BaseKernel* kernel()
override {
return &mesh_; }
427 bool is_triangle_mesh()
const override 428 {
return Mesh::is_triangles(); }
430 void reserve(
unsigned int nV,
unsigned int nE,
unsigned int nF)
override 432 mesh_.reserve(nV, nE, nF);
436 size_t n_vertices()
const override {
return mesh_.n_vertices(); }
437 size_t n_faces()
const override {
return mesh_.n_faces(); }
438 size_t n_edges()
const override {
return mesh_.n_edges(); }
441 void prepare()
override{ }
444 void finish()
override { }
451 std::map<VertexHandle,Normal> halfedgeNormals_;
Handle for a edge entity.
Handle for a face entity.
Kernel::Color Color
Color type.
Kernel::FaceEdgeIter FaceEdgeIter
Circulator.
Kernel::Normal Normal
Normal type.
Handle for a halfedge entity.
Kernel::Point Point
Coordinate type.
Handle for a vertex entity.
bool is_valid() const
The handle is valid iff the index is not negative.
Kernel::TexCoord3D TexCoord3D
TexCoord3D type.
Kernel::TexCoord2D TexCoord2D
TexCoord2D type.
SmartVertexHandle add_vertex(const Point &_p)
Alias for new_vertex(const Point&).
Kernel::FaceHalfedgeIter FaceHalfedgeIter
Circulator.
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
SmartVertexHandle new_vertex()
Adds a new default-initialized vertex.