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

Merge branch 'feature/halfedge_merge' into 'master'

Added halfedge_merge functionality.

See merge request !2
parents 0eef2c93 a88bb76a
......@@ -640,6 +640,55 @@ inline void low_level_api_mutable::halfedge_attach(halfedge_index h, vertex_inde
connect_prev_next(h1, h_next);
}
inline void low_level_api_mutable::halfedge_merge(halfedge_index h) const{
auto v_center = from_vertex_of(h);
assert(m.handle_of(v_center).adjacent_vertices().size() == 2 && "vertex_from must have valence 2");
// | |
// | h_prev h |
// v_from --------> v_center ---------> v_to
// | |
// | |
auto h_prev = prev_halfedge_of(h);
auto h_prev_opp = opposite(h_prev);
auto h_opp = opposite(h);
auto h_prev_prev = prev_halfedge_of(h_prev);
auto h_prev_opp_next = next_halfedge_of(h_prev_opp);
auto f_a = face_of(h);
auto f_b = face_of(h_opp);
//auto v_to = to_vertex_of(h);
auto v_from = from_vertex_of(h_prev);
// Set from vertex
to_vertex_of(h_opp) = v_from;
// Equivalent to
// from_vertex_of(h) = v_from;
connect_prev_next(h_prev_prev, h);
connect_prev_next(h_opp, h_prev_opp_next);
// fix vertex
if(outgoing_halfedge_of(v_from) == h_prev){
outgoing_halfedge_of(v_from) = h;
}
// fix adjacent faces
if(f_a.is_valid() && halfedge_of(f_a) == h_prev){
halfedge_of(f_a) = h;
}
if(f_b.is_valid() && halfedge_of(f_b) == h_prev_opp){
halfedge_of(f_b) = h_opp;
}
// remove
set_removed(edge_of(h_prev));
set_removed(v_center);
}
inline void low_level_api_mutable::vertex_collapse(vertex_index v) const
{
// isolated vertices are just removed
......
......@@ -800,6 +800,12 @@ void halfedge_collection<iterator>::attach(halfedge_handle h, vertex_handle v) c
low_level_api(this->mesh).halfedge_attach(h.idx, v.idx);
}
template <class iterator>
void halfedge_collection<iterator>::merge(halfedge_handle h) const
{
low_level_api(this->mesh).halfedge_merge(h.idx);
}
template <class iterator>
void halfedge_collection<iterator>::rotate_next(halfedge_handle h) const
{
......
......@@ -247,6 +247,10 @@ public:
/// attaches a given vertex to the to-vertex of a given half-edge
void halfedge_attach(halfedge_index h, vertex_index v) const;
/// merges the given and the previous halfedge.
/// The center vertex must have valence 2
void halfedge_merge(halfedge_index h) const;
/// collapse a vertex
void vertex_collapse(vertex_index v) const;
/// collapse a half-edge
......
......@@ -329,6 +329,10 @@ struct halfedge_collection : smart_collection<Mesh*, halfedge_tag, iterator>
/// Given an isolated vertex v, inserts a self-adjacent edge at the to-vertex to v
void attach(halfedge_handle h, vertex_handle v) const;
/// Merges the vertex_from into the vertex_to of this halfedge.
/// From_vertex must have valence 2
void merge(halfedge_handle h) const;
/// Moves the to-vertex of this half-edge to the same as the next half-edge
/// Preserves all attributes
/// NOTE: does not work on boundaries!
......
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