50 #ifndef __IMPORTERT_HH__
51 #define __IMPORTERT_HH__
57 #include <OpenMesh/Core/IO/importer/BaseImporter.hh>
58 #include <OpenMesh/Core/Utils/vector_cast.hh>
59 #include <OpenMesh/Core/Utils/color_cast.hh>
82 typedef typename Mesh::Point Point;
86 typedef std::vector<VertexHandle> VHandles;
89 ImporterT(Mesh& _mesh) : mesh_(_mesh), halfedgeNormals_() {}
94 return mesh_.add_vertex(vector_cast<Point>(_point));
98 virtual FaceHandle add_face(
const VHandles& _indices)
102 if (_indices.size() > 2)
104 VHandles::const_iterator it, it2, end(_indices.end());
108 for (it=_indices.begin(); it!=end; ++it)
109 if (! mesh_.is_valid_handle(*it))
111 omerr() <<
"ImporterT: Face contains invalid vertex index\n";
117 for (it=_indices.begin(); it!=end; ++it)
118 for (it2=it+1; it2!=end; ++it2)
121 omerr() <<
"ImporterT: Face has equal vertices\n";
122 failed_faces_.push_back(_indices);
128 fh = mesh_.add_face(_indices);
131 failed_faces_.push_back(_indices);
136 if (mesh_.has_halfedge_normals())
139 for (
typename Mesh::FaceHalfedgeIter fh_iter = mesh_.fh_begin(fh);
140 fh_iter != mesh_.fh_end(fh); ++fh_iter)
143 typename Mesh::HalfedgeHandle heh = *fh_iter;
144 typename Mesh::VertexHandle vh = mesh_.to_vertex_handle(heh);
145 typename std::map<VertexHandle,Normal>::iterator it_heNs = halfedgeNormals_.find(vh);
146 if (it_heNs != halfedgeNormals_.end())
147 mesh_.set_normal(heh,it_heNs->second);
149 halfedgeNormals_.clear();
157 virtual void set_normal(
VertexHandle _vh,
const Vec3f& _normal)
159 if (mesh_.has_vertex_normals())
160 mesh_.set_normal(_vh, vector_cast<Normal>(_normal));
164 if (mesh_.has_halfedge_normals())
165 halfedgeNormals_[_vh] = vector_cast<Normal>(_normal);
168 virtual void set_color(
VertexHandle _vh,
const Vec4uc& _color)
170 if (mesh_.has_vertex_colors())
171 mesh_.set_color(_vh, color_cast<Color>(_color));
174 virtual void set_color(
VertexHandle _vh,
const Vec3uc& _color)
176 if (mesh_.has_vertex_colors())
177 mesh_.set_color(_vh, color_cast<Color>(_color));
180 virtual void set_color(
VertexHandle _vh,
const Vec4f& _color)
182 if (mesh_.has_vertex_colors())
183 mesh_.set_color(_vh, color_cast<Color>(_color));
186 virtual void set_color(
VertexHandle _vh,
const Vec3f& _color)
188 if (mesh_.has_vertex_colors())
189 mesh_.set_color(_vh, color_cast<Color>(_color));
192 virtual void set_texcoord(
VertexHandle _vh,
const Vec2f& _texcoord)
194 if (mesh_.has_vertex_texcoords2D())
195 mesh_.set_texcoord2D(_vh, vector_cast<TexCoord2D>(_texcoord));
198 virtual void set_texcoord(
HalfedgeHandle _heh,
const Vec2f& _texcoord)
200 if (mesh_.has_halfedge_texcoords2D())
201 mesh_.set_texcoord2D(_heh, vector_cast<TexCoord2D>(_texcoord));
206 virtual void set_color(
EdgeHandle _eh,
const Vec4uc& _color)
208 if (mesh_.has_edge_colors())
209 mesh_.set_color(_eh, color_cast<Color>(_color));
212 virtual void set_color(
EdgeHandle _eh,
const Vec3uc& _color)
214 if (mesh_.has_edge_colors())
215 mesh_.set_color(_eh, color_cast<Color>(_color));
218 virtual void set_color(
EdgeHandle _eh,
const Vec4f& _color)
220 if (mesh_.has_edge_colors())
221 mesh_.set_color(_eh, color_cast<Color>(_color));
224 virtual void set_color(
EdgeHandle _eh,
const Vec3f& _color)
226 if (mesh_.has_edge_colors())
227 mesh_.set_color(_eh, color_cast<Color>(_color));
232 virtual void set_normal(
FaceHandle _fh,
const Vec3f& _normal)
234 if (mesh_.has_face_normals())
235 mesh_.set_normal(_fh, vector_cast<Normal>(_normal));
238 virtual void set_color(
FaceHandle _fh,
const Vec3uc& _color)
240 if (mesh_.has_face_colors())
241 mesh_.set_color(_fh, color_cast<Color>(_color));
244 virtual void set_color(
FaceHandle _fh,
const Vec4uc& _color)
246 if (mesh_.has_face_colors())
247 mesh_.set_color(_fh, color_cast<Color>(_color));
250 virtual void set_color(
FaceHandle _fh,
const Vec3f& _color)
252 if (mesh_.has_face_colors())
253 mesh_.set_color(_fh, color_cast<Color>(_color));
256 virtual void set_color(
FaceHandle _fh,
const Vec4f& _color)
258 if (mesh_.has_face_colors())
259 mesh_.set_color(_fh, color_cast<Color>(_color));
262 virtual void add_face_texcoords(
FaceHandle _fh,
VertexHandle _vh,
const std::vector<Vec2f>& _face_texcoords)
269 while( mesh_.to_vertex_handle(cur_heh) != _vh && cur_heh != end_heh )
270 cur_heh = mesh_.next_halfedge_handle( cur_heh);
272 for(
unsigned int i=0; i<_face_texcoords.size(); ++i)
274 set_texcoord( cur_heh, _face_texcoords[i]);
275 cur_heh = mesh_.next_halfedge_handle( cur_heh);
279 virtual void set_face_texindex(
FaceHandle _fh,
int _texId ) {
280 if ( mesh_.has_face_texture_index() ) {
281 mesh_.set_texture_index(_fh , _texId);
285 virtual void add_texture_information(
int _id , std::string _name ) {
288 if ( !mesh_.get_property_handle(property,
"TextureMapping") ) {
289 mesh_.add_property(property,
"TextureMapping");
292 if ( mesh_.property(property).find( _id ) == mesh_.property(property).end() )
293 mesh_.property(property)[_id] = _name;
298 virtual BaseKernel* kernel() {
return &mesh_; }
300 bool is_triangle_mesh()
const
301 {
return Mesh::is_triangles(); }
303 void reserve(
unsigned int nV,
unsigned int nE,
unsigned int nF)
305 mesh_.reserve(nV, nE, nF);
309 size_t n_vertices()
const {
return mesh_.n_vertices(); }
310 size_t n_faces()
const {
return mesh_.n_faces(); }
311 size_t n_edges()
const {
return mesh_.n_edges(); }
314 void prepare() { failed_faces_.clear(); }
319 if (!failed_faces_.empty())
321 omerr() << failed_faces_.size()
322 <<
" faces failed, adding them as isolated faces\n";
324 for (
unsigned int i=0; i<failed_faces_.size(); ++i)
326 VHandles& vhandles = failed_faces_[i];
329 for (
unsigned int j=0; j<vhandles.size(); ++j)
331 Point p = mesh_.point(vhandles[j]);
332 vhandles[j] = mesh_.add_vertex(p);
337 if (mesh_.has_vertex_status()) {
338 mesh_.status(vhandles[j]).set_fixed_nonmanifold(
true);
346 if (mesh_.has_face_status())
347 mesh_.status(fh).set_fixed_nonmanifold(
true);
350 if (mesh_.has_edge_status()) {
351 typename Mesh::FaceEdgeIter fe_it = mesh_.fe_iter(fh);
352 for(; fe_it.is_valid(); ++fe_it) {
353 mesh_.status(*fe_it).set_fixed_nonmanifold(
true);
358 failed_faces_.clear();
367 std::vector<VHandles> failed_faces_;
369 std::map<VertexHandle,Normal> halfedgeNormals_;
Add colors to mesh item (vertices/faces/edges)
Definition: Attributes.hh:81
bool is_valid() const
The handle is valid iff the index is not equal to -1.
Definition: Handles.hh:70
Base class for importer modules.
Definition: BaseImporter.hh:81
Add 2D texture coordinates (vertices, halfedges)
Definition: Attributes.hh:85
Handle for a halfedge entity.
Definition: Handles.hh:121
This class template provides an importer module for OpenMesh meshes.
Definition: ImporterT.hh:78
This file provides some macros containing attribute usage.
Handle for a edge entity.
Definition: Handles.hh:128
Handle representing a mesh property.
Definition: Property.hh:532
Handle for a face entity.
Definition: Handles.hh:135
This class provides the basic property management like adding/removing properties and access to prope...
Definition: BaseKernel.hh:91
This file provides the streams omlog, omout, and omerr.
Handle for a vertex entity.
Definition: Handles.hh:114
Add normals to mesh item (vertices/faces)
Definition: Attributes.hh:80