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;
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);
141 virtual void set_normal(
VertexHandle _vh,
const Vec3f& _normal)
143 if (mesh_.has_vertex_normals())
144 mesh_.set_normal(_vh, vector_cast<Normal>(_normal));
147 virtual void set_color(
VertexHandle _vh,
const Vec4uc& _color)
149 if (mesh_.has_vertex_colors())
150 mesh_.set_color(_vh, color_cast<Color>(_color));
153 virtual void set_color(
VertexHandle _vh,
const Vec3uc& _color)
155 if (mesh_.has_vertex_colors())
156 mesh_.set_color(_vh, color_cast<Color>(_color));
160 virtual void set_texcoord(
VertexHandle _vh,
const Vec2f& _texcoord)
162 if (mesh_.has_vertex_texcoords2D())
163 mesh_.set_texcoord2D(_vh, vector_cast<TexCoord2D>(_texcoord));
166 virtual void set_texcoord(
HalfedgeHandle _heh,
const Vec2f& _texcoord)
168 if (mesh_.has_halfedge_texcoords2D())
169 mesh_.set_texcoord2D(_heh, vector_cast<TexCoord2D>(_texcoord));
174 virtual void set_color(
EdgeHandle _eh,
const Vec4uc& _color)
176 if (mesh_.has_edge_colors())
177 mesh_.set_color(_eh, color_cast<Color>(_color));
180 virtual void set_color(
EdgeHandle _eh,
const Vec3uc& _color)
182 if (mesh_.has_edge_colors())
183 mesh_.set_color(_eh, color_cast<Color>(_color));
188 virtual void set_normal(
FaceHandle _fh,
const Vec3f& _normal)
190 if (mesh_.has_face_normals())
191 mesh_.set_normal(_fh, vector_cast<Normal>(_normal));
194 virtual void set_color(
FaceHandle _fh,
const Vec3uc& _color)
196 if (mesh_.has_face_colors())
197 mesh_.set_color(_fh, color_cast<Color>(_color));
200 virtual void set_color(
FaceHandle _fh,
const Vec4uc& _color)
202 if (mesh_.has_face_colors())
203 mesh_.set_color(_fh, color_cast<Color>(_color));
206 virtual void add_face_texcoords(
FaceHandle _fh,
VertexHandle _vh,
const std::vector<Vec2f>& _face_texcoords)
213 while( mesh_.to_vertex_handle(cur_heh) != _vh && cur_heh != end_heh )
214 cur_heh = mesh_.next_halfedge_handle( cur_heh);
216 for(
unsigned int i=0; i<_face_texcoords.size(); ++i)
218 set_texcoord( cur_heh, _face_texcoords[i]);
219 cur_heh = mesh_.next_halfedge_handle( cur_heh);
223 virtual void set_face_texindex(
FaceHandle _fh,
int _texId ) {
224 if ( mesh_.has_face_texture_index() ) {
225 mesh_.set_texture_index(_fh , _texId);
229 virtual void add_texture_information(
int _id , std::string _name ) {
232 if ( !mesh_.get_property_handle(property,
"TextureMapping") ) {
233 mesh_.add_property(property,
"TextureMapping");
236 if ( mesh_.property(property).find( _id ) == mesh_.property(property).end() )
237 mesh_.property(property)[_id] = _name;
242 virtual BaseKernel* kernel() {
return &mesh_; }
244 bool is_triangle_mesh()
const
245 {
return Mesh::is_triangles(); }
247 void reserve(
unsigned int nV,
unsigned int nE,
unsigned int nF)
249 mesh_.reserve(nV, nE, nF);
253 size_t n_vertices()
const {
return mesh_.n_vertices(); }
254 size_t n_faces()
const {
return mesh_.n_faces(); }
255 size_t n_edges()
const {
return mesh_.n_edges(); }
258 void prepare() { failed_faces_.clear(); }
263 if (!failed_faces_.empty())
265 omerr() << failed_faces_.size()
266 <<
" faces failed, adding them as isolated faces\n";
268 for (
unsigned int i=0; i<failed_faces_.size(); ++i)
270 VHandles& vhandles = failed_faces_[i];
273 for (
unsigned int j=0; j<vhandles.size(); ++j)
275 Point p = mesh_.point(vhandles[j]);
276 vhandles[j] = mesh_.add_vertex(p);
281 if (mesh_.has_vertex_status()) {
282 mesh_.status(vhandles[j]).set_fixed_nonmanifold(
true);
290 if (mesh_.has_face_status())
291 mesh_.status(fh).set_fixed_nonmanifold(
true);
294 if (mesh_.has_edge_status()) {
295 typename Mesh::FaceEdgeIter fe_it = mesh_.fe_iter(fh);
296 for(; fe_it; ++fe_it) {
297 mesh_.status(fe_it).set_fixed_nonmanifold(
true);
302 failed_faces_.clear();
311 std::vector<VHandles> failed_faces_;