89 typedef std::vector<VertexHandle> VHandles;
92 explicit ImporterT(Mesh& _mesh) : mesh_(_mesh), halfedgeNormals_() {}
107 return mesh_.new_vertex();
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]);
154 vhandles[j] = mesh_.add_vertex(p);
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);
214 mesh_.set_halfedge_handle(_vh, _heh);
219 if (mesh_.has_vertex_normals())
224 if (mesh_.has_halfedge_normals())
230 if (mesh_.has_vertex_normals())
235 if (mesh_.has_halfedge_normals())
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())
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())
300 if (mesh_.has_vertex_texcoords3D())
306 if (mesh_.has_halfedge_texcoords3D())
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())
360 if (mesh_.has_face_normals())
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_;