Rev 489 | Blame | Last modification | View Log | RSS feed
#include "HalfEdgeHandle.h"
#include "entities.h"
#include "Manifold.h"
#include "VertexHandle.h"
#include "FaceHandle.h"
#include "VertexCirculator.h"
namespace HMesh
{
/************************************
* ConstHalfEdgeHandle functions
*************************************/
bool is_boundary(ConstHalfEdgeHandle h)
{
return h.face() == NULL_CFH || h.opp().face() == NULL_CFH;
}
float length(ConstHalfEdgeHandle h)
{
return (h.vert().get().pos - h.opp().vert().get().pos).length();
}
/************************************
* HalfEdgeHandle functions
*************************************/
void link(HalfEdgeHandle h0, HalfEdgeHandle h1)
{
h0.get().next_idx = h1.get_idx();
h1.get().prev_idx = h0.get_idx();
}
void glue(HalfEdgeHandle h0, HalfEdgeHandle h1)
{
h0.get().opp_idx = h1.get_idx();
h1.get().opp_idx = h0.get_idx();
}
bool flip(HalfEdgeHandle h)
{
FaceHandle f = h.face();
HalfEdgeHandle ho = h.opp();
FaceHandle fo = ho.face();
if(f == NULL_FH || fo == NULL_FH){
return false;
}
// We can only flip an edge if both incident polygons are triangles.
if(no_edges(f) != 3 || no_edges(fo) !=3){
return false;
}
// non boundary vertices with a valency of less than 4(less than 3 after operation) degenerates mesh.
VertexHandle v = h.vert();
ConstVertexHandle cv(v);
VertexHandle vo = ho.vert();
ConstVertexHandle cvo(vo);
if((valency(v) < 4 && !is_boundary(v)) || (valency(vo) < 4 && !is_boundary(vo))){
return false;
}
// Disallow flip if vertices being connected already are.
VertexHandle vn = h.next().vert();
VertexHandle von = ho.next().vert();
if(is_connected(vn, von)){
return false;
}
HalfEdgeHandle hn = h.next();
HalfEdgeHandle hp = h.prev();
HalfEdgeHandle hon = ho.next();
HalfEdgeHandle hop = ho.prev();
hop.get().face_idx = f.get_idx();
hp.get().face_idx = fo.get_idx();
f.get().last_idx = h.get_idx();
fo.get().last_idx = ho.get_idx();
link(hn, h);
link(h, hop);
link(hop, hn);
link(hon, ho);
link(ho, hp);
link(hp, hon);
h.get().vert_idx = von.get_idx();
ho.get().vert_idx = vn.get_idx();
v.get().out_idx = hn.get_idx();
vo.get().out_idx = hon.get_idx();
check_boundary_consistency(v);
check_boundary_consistency(vo);
return true;
}
}