Added Triangle 1 to 4 split

This commit is contained in:
Jan Möbius
2017-04-26 16:58:38 +02:00
parent d62d4ffa6c
commit 986f98f0b9
2 changed files with 175 additions and 0 deletions

View File

@@ -337,6 +337,64 @@ public:
inline VertexHandle split_copy(FaceHandle _fh, const Point& _p)
{ const VertexHandle vh = this->add_vertex(_p); PolyMesh::split_copy(_fh, vh); return vh; }
/** \brief Face split (= 1-to-4) split, splits edges at midpoints and adds 4 new faces in the interior).
*
* @param _fh Face handle that should be splitted
*/
inline void split(FaceHandle _fh)
{
// Collect halfedges of face
HalfedgeHandle he0 = this->halfedge_handle(_fh);
HalfedgeHandle he1 = this->next_halfedge_handle(he0);
HalfedgeHandle he2 = this->next_halfedge_handle(he1);
EdgeHandle eh0 = this->edge_handle(he0);
EdgeHandle eh1 = this->edge_handle(he1);
EdgeHandle eh2 = this->edge_handle(he2);
// Collect points of face
VertexHandle p0 = this->to_vertex_handle(he0);
VertexHandle p1 = this->to_vertex_handle(he1);
VertexHandle p2 = this->to_vertex_handle(he2);
// Calculate midpoint coordinates
const Point new0 = (this->point(p0) + this->point(p2)) * static_cast< typename Point::value_type >(0.5);
const Point new1 = (this->point(p0) + this->point(p1)) * static_cast< typename Point::value_type >(0.5);
const Point new2 = (this->point(p1) + this->point(p2)) * static_cast< typename Point::value_type >(0.5);
// Add vertices at midpoint coordinates
VertexHandle v0 = this->add_vertex(new0);
VertexHandle v1 = this->add_vertex(new1);
VertexHandle v2 = this->add_vertex(new2);
const bool split0 = !this->is_boundary(he0);
const bool split1 = !this->is_boundary(he1);
const bool split2 = !this->is_boundary(he2);
// delete original face
this->delete_face(_fh);
// split boundary edges of deleted face ( if not boundary )
if ( split0 ) {
this->split(eh0,v0);
}
if ( split1 ) {
this->split(eh1,v1);
}
if ( split2 ) {
this->split(eh2,v2);
}
// Retriangulate
this->add_face(v0 , p0, v1);
this->add_face(p2, v0 , v2);
this->add_face(v2,v1,p1);
this->add_face(v2 , v0, v1);
}
/** \brief Face split (= 1-to-3 split, calls corresponding PolyMeshT function).
*
* The properties of the new faces will be undefined!