57 #ifndef __IMPORTERT_HH__ 58 #define __IMPORTERT_HH__ 64 #include <OpenMesh/Core/IO/importer/BaseImporter.hh> 65 #include <OpenMesh/Core/Utils/vector_cast.hh> 66 #include <OpenMesh/Core/Utils/color_cast.hh> 94 typedef std::vector<VertexHandle> VHandles;
102 return mesh_.
add_vertex(vector_cast<Point>(_point));
110 virtual FaceHandle add_face(
const VHandles& _indices)
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);
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();
199 mesh_.set_point(_vh,vector_cast<Point>(_point));
204 if (mesh_.has_vertex_normals())
205 mesh_.set_normal(_vh, vector_cast<Normal>(_normal));
209 if (mesh_.has_halfedge_normals())
210 halfedgeNormals_[_vh] = vector_cast<Normal>(_normal);
215 if (mesh_.has_vertex_colors())
216 mesh_.set_color(_vh, color_cast<Color>(_color));
221 if (mesh_.has_vertex_colors())
222 mesh_.set_color(_vh, color_cast<Color>(_color));
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_texcoords2D())
240 mesh_.set_texcoord2D(_vh, vector_cast<TexCoord2D>(_texcoord));
245 if (mesh_.has_halfedge_texcoords2D())
246 mesh_.set_texcoord2D(_heh, vector_cast<TexCoord2D>(_texcoord));
251 if (mesh_.has_vertex_texcoords3D())
252 mesh_.set_texcoord3D(_vh, vector_cast<TexCoord3D>(_texcoord));
257 if (mesh_.has_halfedge_texcoords3D())
258 mesh_.set_texcoord3D(_heh, vector_cast<TexCoord3D>(_texcoord));
266 if (mesh_.has_edge_colors())
267 mesh_.set_color(_eh, color_cast<Color>(_color));
272 if (mesh_.has_edge_colors())
273 mesh_.set_color(_eh, color_cast<Color>(_color));
278 if (mesh_.has_edge_colors())
279 mesh_.set_color(_eh, color_cast<Color>(_color));
284 if (mesh_.has_edge_colors())
285 mesh_.set_color(_eh, color_cast<Color>(_color));
292 if (mesh_.has_face_normals())
293 mesh_.set_normal(_fh, vector_cast<Normal>(_normal));
298 if (mesh_.has_face_colors())
299 mesh_.set_color(_fh, color_cast<Color>(_color));
304 if (mesh_.has_face_colors())
305 mesh_.set_color(_fh, color_cast<Color>(_color));
310 if (mesh_.has_face_colors())
311 mesh_.set_color(_fh, color_cast<Color>(_color));
316 if (mesh_.has_face_colors())
317 mesh_.set_color(_fh, color_cast<Color>(_color));
320 virtual void add_face_texcoords(
FaceHandle _fh,
VertexHandle _vh,
const std::vector<Vec2f>& _face_texcoords)
327 while( mesh_.to_vertex_handle(cur_heh) != _vh && cur_heh != end_heh )
328 cur_heh = mesh_.next_halfedge_handle( cur_heh);
330 for(
unsigned int i=0; i<_face_texcoords.size(); ++i)
332 set_texcoord( cur_heh, _face_texcoords[i]);
333 cur_heh = mesh_.next_halfedge_handle( cur_heh);
337 virtual void add_face_texcoords(
FaceHandle _fh,
VertexHandle _vh,
const std::vector<Vec3f>& _face_texcoords)
344 while( mesh_.to_vertex_handle(cur_heh) != _vh && cur_heh != end_heh )
345 cur_heh = mesh_.next_halfedge_handle( cur_heh);
347 for(
unsigned int i=0; i<_face_texcoords.size(); ++i)
349 set_texcoord( cur_heh, _face_texcoords[i]);
350 cur_heh = mesh_.next_halfedge_handle( cur_heh);
354 virtual void set_face_texindex(
FaceHandle _fh,
int _texId ) {
355 if ( mesh_.has_face_texture_index() ) {
356 mesh_.set_texture_index(_fh , _texId);
360 virtual void add_texture_information(
int _id , std::string _name ) {
363 if ( !mesh_.get_property_handle(property,
"TextureMapping") ) {
364 mesh_.add_property(property,
"TextureMapping");
367 if ( mesh_.property(property).find( _id ) == mesh_.property(property).end() )
368 mesh_.property(property)[_id] = _name;
373 virtual BaseKernel* kernel() {
return &mesh_; }
375 bool is_triangle_mesh()
const 376 {
return Mesh::is_triangles(); }
378 void reserve(
unsigned int nV,
unsigned int nE,
unsigned int nF)
380 mesh_.reserve(nV, nE, nF);
384 size_t n_vertices()
const {
return mesh_.n_vertices(); }
385 size_t n_faces()
const {
return mesh_.n_faces(); }
386 size_t n_edges()
const {
return mesh_.n_edges(); }
399 std::map<VertexHandle,Normal> halfedgeNormals_;
Kernel::TexCoord3D TexCoord3D
TexCoord3D type.
Kernel::FaceHalfedgeIter FaceHalfedgeIter
Circulator.
Kernel::FaceEdgeIter FaceEdgeIter
Circulator.
Kernel::Color Color
Color type.
Handle for a edge entity.
Kernel::Normal Normal
Normal type.
bool is_valid() const
The handle is valid iff the index is not equal to -1.
VertexHandle new_vertex()
Adds a new default-initialized vertex.
Handle for a halfedge entity.
Handle for a vertex entity.
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
Kernel::TexCoord2D TexCoord2D
TexCoord2D type.
VertexHandle add_vertex(const Point &_p)
Alias for new_vertex(const Point&).
Handle for a face entity.
Kernel::Point Point
Coordinate type.