- add: unittests for texcoords and normals

- add: set normals per halfedge if requested

refs #838

git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@596 fdac6126-5c0c-442c-9429-916003d36597
This commit is contained in:
Matthias Möller
2012-06-18 13:14:58 +00:00
parent 6e38652af2
commit 6d4008c948
3 changed files with 142 additions and 4 deletions

View File

@@ -86,7 +86,7 @@ public:
typedef std::vector<VertexHandle> VHandles;
ImporterT(Mesh& _mesh) : mesh_(_mesh) {}
ImporterT(Mesh& _mesh) : mesh_(_mesh), halfedgeNormals_() {}
virtual VertexHandle add_vertex(const Vec3f& _point)
@@ -131,8 +131,24 @@ public:
failed_faces_.push_back(_indices);
return fh;
}
}
//write the half edge normals
if (mesh_.has_halfedge_normals())
{
//iterate over all incoming haldedges of the added face
for (typename Mesh::FaceHalfedgeIter fh_iter = mesh_.fh_begin(fh);
fh_iter != mesh_.fh_end(fh); ++fh_iter)
{
//and write the normals to it
typename Mesh::HalfedgeHandle heh = fh_iter.current_halfedge_handle();
typename Mesh::VertexHandle vh = mesh_.to_vertex_handle(heh);
typename std::map<VertexHandle,Normal>::iterator it_heNs = halfedgeNormals_.find(vh);
if (it_heNs != halfedgeNormals_.end())
mesh_.set_normal(heh,it_heNs->second);
}
halfedgeNormals_.clear();
}
}
return fh;
}
@@ -142,6 +158,11 @@ public:
{
if (mesh_.has_vertex_normals())
mesh_.set_normal(_vh, vector_cast<Normal>(_normal));
//saves normals for half edges.
//they will be written, when the face is added
if (mesh_.has_halfedge_normals())
halfedgeNormals_[_vh] = _normal;
}
virtual void set_color(VertexHandle _vh, const Vec4uc& _color)
@@ -309,6 +330,8 @@ private:
Mesh& mesh_;
std::vector<VHandles> failed_faces_;
// stores normals for halfedges of the next face
std::map<VertexHandle,Normal> halfedgeNormals_;
};

View File

@@ -424,6 +424,9 @@ read(std::istream& _in, BaseImporter& _bi, Options& _opt)
std::getline(stream,faceLine);
std::stringstream lineData( faceLine );
FaceHandle fh;
BaseImporter::VHandles faceVertices;
// work on the line until nothing left to read
while ( !lineData.eof() )
{
@@ -487,6 +490,7 @@ read(std::istream& _in, BaseImporter& _bi, Options& _opt)
}
// Obj counts from 1 and not zero .. array counts from zero therefore -1
vhandles.push_back(VertexHandle(value-1));
faceVertices.push_back(VertexHandle(value-1));
if (_opt.vertex_has_color())
_bi.set_color(vhandles.back(), colors[value-1]);
break;
@@ -531,11 +535,16 @@ read(std::istream& _in, BaseImporter& _bi, Options& _opt)
component = 0;
nV++;
fh = _bi.add_face(faceVertices);
//clear vertices handles, so no face will be added twice
if (fh.is_valid())
faceVertices.clear();
}
size_t n_faces = _bi.n_faces();
FaceHandle fh = _bi.add_face(vhandles);
if( !vhandles.empty() && fh.is_valid() )
_bi.add_face_texcoords( fh, vhandles[0], face_texcoords );