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));
99 return mesh_.new_vertex();
102 virtual FaceHandle add_face(
const VHandles& _indices)
106 if (_indices.size() > 2)
108 VHandles::const_iterator it, it2, end(_indices.end());
112 for (it=_indices.begin(); it!=end; ++it)
113 if (! mesh_.is_valid_handle(*it))
115 omerr() <<
"ImporterT: Face contains invalid vertex index\n";
121 for (it=_indices.begin(); it!=end; ++it)
122 for (it2=it+1; it2!=end; ++it2)
125 omerr() <<
"ImporterT: Face has equal vertices\n";
126 failed_faces_.push_back(_indices);
132 fh = mesh_.add_face(_indices);
135 failed_faces_.push_back(_indices);
140 if (mesh_.has_halfedge_normals())
143 for (
typename Mesh::FaceHalfedgeIter fh_iter = mesh_.fh_begin(fh);
144 fh_iter != mesh_.fh_end(fh); ++fh_iter)
147 typename Mesh::HalfedgeHandle heh = *fh_iter;
148 typename Mesh::VertexHandle vh = mesh_.to_vertex_handle(heh);
149 typename std::map<VertexHandle,Normal>::iterator it_heNs = halfedgeNormals_.find(vh);
150 if (it_heNs != halfedgeNormals_.end())
151 mesh_.set_normal(heh,it_heNs->second);
153 halfedgeNormals_.clear();
161 virtual void set_point(
VertexHandle _vh,
const Vec3f& _point)
163 mesh_.set_point(_vh,vector_cast<Point>(_point));
166 virtual void set_normal(
VertexHandle _vh,
const Vec3f& _normal)
168 if (mesh_.has_vertex_normals())
169 mesh_.set_normal(_vh, vector_cast<Normal>(_normal));
173 if (mesh_.has_halfedge_normals())
174 halfedgeNormals_[_vh] = vector_cast<Normal>(_normal);
177 virtual void set_color(
VertexHandle _vh,
const Vec4uc& _color)
179 if (mesh_.has_vertex_colors())
180 mesh_.set_color(_vh, color_cast<Color>(_color));
183 virtual void set_color(
VertexHandle _vh,
const Vec3uc& _color)
185 if (mesh_.has_vertex_colors())
186 mesh_.set_color(_vh, color_cast<Color>(_color));
189 virtual void set_color(
VertexHandle _vh,
const Vec4f& _color)
191 if (mesh_.has_vertex_colors())
192 mesh_.set_color(_vh, color_cast<Color>(_color));
195 virtual void set_color(
VertexHandle _vh,
const Vec3f& _color)
197 if (mesh_.has_vertex_colors())
198 mesh_.set_color(_vh, color_cast<Color>(_color));
201 virtual void set_texcoord(
VertexHandle _vh,
const Vec2f& _texcoord)
203 if (mesh_.has_vertex_texcoords2D())
204 mesh_.set_texcoord2D(_vh, vector_cast<TexCoord2D>(_texcoord));
207 virtual void set_texcoord(
HalfedgeHandle _heh,
const Vec2f& _texcoord)
209 if (mesh_.has_halfedge_texcoords2D())
210 mesh_.set_texcoord2D(_heh, vector_cast<TexCoord2D>(_texcoord));
215 virtual void set_color(
EdgeHandle _eh,
const Vec4uc& _color)
217 if (mesh_.has_edge_colors())
218 mesh_.set_color(_eh, color_cast<Color>(_color));
221 virtual void set_color(
EdgeHandle _eh,
const Vec3uc& _color)
223 if (mesh_.has_edge_colors())
224 mesh_.set_color(_eh, color_cast<Color>(_color));
227 virtual void set_color(
EdgeHandle _eh,
const Vec4f& _color)
229 if (mesh_.has_edge_colors())
230 mesh_.set_color(_eh, color_cast<Color>(_color));
233 virtual void set_color(
EdgeHandle _eh,
const Vec3f& _color)
235 if (mesh_.has_edge_colors())
236 mesh_.set_color(_eh, color_cast<Color>(_color));
241 virtual void set_normal(
FaceHandle _fh,
const Vec3f& _normal)
243 if (mesh_.has_face_normals())
244 mesh_.set_normal(_fh, vector_cast<Normal>(_normal));
247 virtual void set_color(
FaceHandle _fh,
const Vec3uc& _color)
249 if (mesh_.has_face_colors())
250 mesh_.set_color(_fh, color_cast<Color>(_color));
253 virtual void set_color(
FaceHandle _fh,
const Vec4uc& _color)
255 if (mesh_.has_face_colors())
256 mesh_.set_color(_fh, color_cast<Color>(_color));
259 virtual void set_color(
FaceHandle _fh,
const Vec3f& _color)
261 if (mesh_.has_face_colors())
262 mesh_.set_color(_fh, color_cast<Color>(_color));
265 virtual void set_color(
FaceHandle _fh,
const Vec4f& _color)
267 if (mesh_.has_face_colors())
268 mesh_.set_color(_fh, color_cast<Color>(_color));
271 virtual void add_face_texcoords(
FaceHandle _fh,
VertexHandle _vh,
const std::vector<Vec2f>& _face_texcoords)
278 while( mesh_.to_vertex_handle(cur_heh) != _vh && cur_heh != end_heh )
279 cur_heh = mesh_.next_halfedge_handle( cur_heh);
281 for(
unsigned int i=0; i<_face_texcoords.size(); ++i)
283 set_texcoord( cur_heh, _face_texcoords[i]);
284 cur_heh = mesh_.next_halfedge_handle( cur_heh);
288 virtual void set_face_texindex(
FaceHandle _fh,
int _texId ) {
289 if ( mesh_.has_face_texture_index() ) {
290 mesh_.set_texture_index(_fh , _texId);
294 virtual void add_texture_information(
int _id , std::string _name ) {
297 if ( !mesh_.get_property_handle(property,
"TextureMapping") ) {
298 mesh_.add_property(property,
"TextureMapping");
301 if ( mesh_.property(property).find( _id ) == mesh_.property(property).end() )
302 mesh_.property(property)[_id] = _name;
307 virtual BaseKernel* kernel() {
return &mesh_; }
309 bool is_triangle_mesh()
const
310 {
return Mesh::is_triangles(); }
312 void reserve(
unsigned int nV,
unsigned int nE,
unsigned int nF)
314 mesh_.reserve(nV, nE, nF);
318 size_t n_vertices()
const {
return mesh_.n_vertices(); }
319 size_t n_faces()
const {
return mesh_.n_faces(); }
320 size_t n_edges()
const {
return mesh_.n_edges(); }
323 void prepare() { failed_faces_.clear(); }
328 if (!failed_faces_.empty())
330 omerr() << failed_faces_.size()
331 <<
" faces failed, adding them as isolated faces\n";
333 for (
unsigned int i=0; i<failed_faces_.size(); ++i)
335 VHandles& vhandles = failed_faces_[i];
338 for (
unsigned int j=0; j<vhandles.size(); ++j)
340 Point p = mesh_.point(vhandles[j]);
341 vhandles[j] = mesh_.add_vertex(p);
346 if (mesh_.has_vertex_status()) {
347 mesh_.status(vhandles[j]).set_fixed_nonmanifold(
true);
355 if (mesh_.has_face_status())
356 mesh_.status(fh).set_fixed_nonmanifold(
true);
359 if (mesh_.has_edge_status()) {
360 typename Mesh::FaceEdgeIter fe_it = mesh_.fe_iter(fh);
361 for(; fe_it.is_valid(); ++fe_it) {
362 mesh_.status(*fe_it).set_fixed_nonmanifold(
true);
367 failed_faces_.clear();
376 std::vector<VHandles> failed_faces_;
378 std::map<VertexHandle,Normal> halfedgeNormals_;
Add normals to mesh item (vertices/faces)
Definition: Attributes.hh:80
This class provides the basic property management like adding/removing properties and access to prope...
Definition: BaseKernel.hh:91
Add colors to mesh item (vertices/faces/edges)
Definition: Attributes.hh:81
This file provides the streams omlog, omout, and omerr.
Add 2D texture coordinates (vertices, halfedges)
Definition: Attributes.hh:85
Handle for a vertex entity.
Definition: Handles.hh:114
Handle for a face entity.
Definition: Handles.hh:135
This file provides some macros containing attribute usage.
Handle for a halfedge entity.
Definition: Handles.hh:121
Handle for a edge entity.
Definition: Handles.hh:128
Base class for importer modules.
Definition: BaseImporter.hh:81
This class template provides an importer module for OpenMesh meshes.
Definition: ImporterT.hh:78
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:56
bool is_valid() const
The handle is valid iff the index is not equal to -1.
Definition: Handles.hh:70
Handle representing a mesh property.
Definition: Property.hh:540