Commit b7ee88d6 authored by Philip Trettner's avatar Philip Trettner
Browse files

fixed triangulate_naive for inner valence 2

parent fba09a7e
#include "triangulate.hh"
#include <polymesh/properties.hh>
#include <vector>
void polymesh::triangulate_naive(polymesh::Mesh& m)
{
auto is_inner_valence2 = [](vertex_handle v) { return !v.is_boundary() && valence(v) == 2; };
std::vector<vertex_handle> vs;
for (auto f : m.faces())
{
......@@ -16,8 +20,23 @@ void polymesh::triangulate_naive(polymesh::Mesh& m)
// remove
m.faces().remove(f);
// find non-valence 2
auto si = 0;
for (auto i = 0u; i < vs.size(); ++i)
{
if (!is_inner_valence2(vs[i]))
{
si = i;
break;
}
}
POLYMESH_ASSERT(!is_inner_valence2(vs[si]) && "could not find start vertex (second vertex must not be inner valence 2)");
si--; // make sure v1 is never valence 2
if (si < 0)
si += int(vs.size());
// triangulate
for (auto i = 2u; i < vs.size(); ++i)
m.faces().add(vs[0], vs[i - 1], vs[i]);
m.faces().add(vs[si], vs[(si + i - 1) % vs.size()], vs[(si + i) % vs.size()]);
}
}
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