Commit cd3587d2 authored by Matthias Möller's avatar Matthias Möller

- decimater (incremental & mc) doesn't require normals anymore

- mod normalFlipping & normalDeviation computes normals, if mesh hasn't normals
- add 2 decimater unittest (decimating with normalFlipping and initialize all modules)

git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@1049 fdac6126-5c0c-442c-9429-916003d36597
parent 3bc356b2
......@@ -72,7 +72,7 @@ BaseDecimaterT<Mesh>::BaseDecimaterT(Mesh& _mesh) :
mesh_.request_vertex_status();
mesh_.request_edge_status();
mesh_.request_face_status();
mesh_.request_face_normals();
}
//-----------------------------------------------------------------------------
......@@ -83,7 +83,6 @@ BaseDecimaterT<Mesh>::~BaseDecimaterT() {
mesh_.release_vertex_status();
mesh_.release_edge_status();
mesh_.release_face_status();
mesh_.release_face_normals();
// dispose of modules
{
......
......@@ -172,6 +172,8 @@ size_t DecimaterT<Mesh>::decimate(size_t _n_collapses) {
heap_vertex(*v_it);
}
const bool update_normals = mesh_.has_face_normals();
// process heap
while ((!heap_->empty()) && (n_collapses < _n_collapses)) {
// get 1st heap entry
......@@ -196,11 +198,14 @@ size_t DecimaterT<Mesh>::decimate(size_t _n_collapses) {
mesh_.collapse(v0v1);
++n_collapses;
// update triangle normals
vf_it = mesh_.vf_iter(ci.v1);
for (; vf_it.is_valid(); ++vf_it)
if (!mesh_.status(*vf_it).deleted())
mesh_.set_normal(*vf_it, mesh_.calc_face_normal(*vf_it));
if (update_normals)
{
// update triangle normals
vf_it = mesh_.vf_iter(ci.v1);
for (; vf_it.is_valid(); ++vf_it)
if (!mesh_.status(*vf_it).deleted())
mesh_.set_normal(*vf_it, mesh_.calc_face_normal(*vf_it));
}
// post-process collapse
this->postprocess_collapse(ci);
......@@ -258,6 +263,8 @@ size_t DecimaterT<Mesh>::decimate_to_faces(size_t _nv, size_t _nf) {
heap_vertex(*v_it);
}
const bool update_normals = mesh_.has_face_normals();
// process heap
while ((!heap_->empty()) && (_nv < nv) && (_nf < nf)) {
// get 1st heap entry
......@@ -293,10 +300,13 @@ size_t DecimaterT<Mesh>::decimate_to_faces(size_t _nv, size_t _nf) {
mesh_.collapse(v0v1);
// update triangle normals
vf_it = mesh_.vf_iter(ci.v1);
for (; vf_it.is_valid(); ++vf_it)
if (!mesh_.status(*vf_it).deleted())
mesh_.set_normal(*vf_it, mesh_.calc_face_normal(*vf_it));
if (update_normals)
{
vf_it = mesh_.vf_iter(ci.v1);
for (; vf_it.is_valid(); ++vf_it)
if (!mesh_.status(*vf_it).deleted())
mesh_.set_normal(*vf_it, mesh_.calc_face_normal(*vf_it));
}
// post-process collapse
this->postprocess_collapse(ci);
......
......@@ -81,7 +81,6 @@ McDecimaterT<Mesh>::McDecimaterT(Mesh& _mesh) :
mesh_.request_halfedge_status();
mesh_.request_edge_status();
mesh_.request_face_status();
mesh_.request_face_normals();
}
......@@ -94,7 +93,6 @@ McDecimaterT<Mesh>::~McDecimaterT() {
mesh_.release_edge_status();
mesh_.release_halfedge_status();
mesh_.release_face_status();
mesh_.release_face_normals();
}
......@@ -118,6 +116,8 @@ size_t McDecimaterT<Mesh>::decimate(size_t _n_collapses) {
RandomNumberGenerator randGen(mesh_.n_halfedges());
#endif
const bool update_normals = mesh_.has_face_normals();
while ( n_collapses < _n_collapses) {
if (noCollapses > 20) {
......@@ -187,10 +187,13 @@ size_t McDecimaterT<Mesh>::decimate(size_t _n_collapses) {
collapsesUnchanged = false;
// update triangle normals
typename Mesh::VertexFaceIter vf_it = mesh_.vf_iter(ci.v1);
for (; vf_it.is_valid(); ++vf_it)
if (!mesh_.status(*vf_it).deleted())
mesh_.set_normal(*vf_it, mesh_.calc_face_normal(*vf_it));
if (update_normals)
{
typename Mesh::VertexFaceIter vf_it = mesh_.vf_iter(ci.v1);
for (; vf_it.is_valid(); ++vf_it)
if (!mesh_.status(*vf_it).deleted())
mesh_.set_normal(*vf_it, mesh_.calc_face_normal(*vf_it));
}
// post-process collapse
this->postprocess_collapse(ci);
......@@ -240,6 +243,8 @@ size_t McDecimaterT<Mesh>::decimate_to_faces(size_t _nv, size_t _nf) {
RandomNumberGenerator randGen(mesh_.n_halfedges());
#endif
const bool update_normals = mesh_.has_face_normals();
while ((_nv < nv) && (_nf < nf)) {
if (noCollapses > 20) {
......@@ -320,11 +325,14 @@ size_t McDecimaterT<Mesh>::decimate_to_faces(size_t _nv, size_t _nf) {
noCollapses = 0;
collapsesUnchanged = false;
// update triangle normals
typename Mesh::VertexFaceIter vf_it = mesh_.vf_iter(ci.v1);
for (; vf_it.is_valid(); ++vf_it)
if (!mesh_.status(*vf_it).deleted())
mesh_.set_normal(*vf_it, mesh_.calc_face_normal(*vf_it));
if (update_normals)
{
// update triangle normals
typename Mesh::VertexFaceIter vf_it = mesh_.vf_iter(ci.v1);
for (; vf_it.is_valid(); ++vf_it)
if (!mesh_.status(*vf_it).deleted())
mesh_.set_normal(*vf_it, mesh_.calc_face_normal(*vf_it));
}
// post-process collapse
this->postprocess_collapse(ci);
......
......@@ -108,12 +108,22 @@ public:
{
set_normal_deviation(_max_dev);
mesh_.add_property(normal_cones_);
const bool mesh_has_normals = _mesh.has_face_normals();
_mesh.request_face_normals();
if (!mesh_has_normals)
{
std::cerr << "Mesh has no face normals. Compute them automatically." << std::endl;
_mesh.update_face_normals();
}
}
/// Destructor
~ModNormalDeviationT() {
mesh_.remove_property(normal_cones_);
mesh_.release_face_normals();
}
......
......@@ -87,11 +87,21 @@ public:
ModNormalFlippingT( MeshT &_mesh) : Base(_mesh, true)
{
set_max_normal_deviation( 90.0f );
const bool mesh_has_normals = _mesh.has_face_normals();
_mesh.request_face_normals();
if (!mesh_has_normals)
{
std::cerr << "Mesh has no face normals. Compute them automatically." << std::endl;
_mesh.update_face_normals();
}
}
~ModNormalFlippingT()
{ }
{
Base::mesh().release_face_normals();
}
public:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment