Example #1
0
/*
* Checks if an edge is a boundary and if not, checks it for being locally Delaunay.
* If it is not locally delaunay it is flipped and all its neighbor edges are checked, ad nauseam.
*/
void recursiveDelaunayFlip(Manifold &m, Walker w, bool isAffected) {
	if ( !boundary(m, w.halfedge()) ) {
		// Check if the current halfedge is locally Delaunay using the inCircle function
		Vec3d p1 = m.pos(w.opp().vertex());
		Vec3d p2 = m.pos(w.vertex());
		Vec3d p3 = m.pos(w.next().vertex());
		Vec3d p4 = m.pos(w.opp().next().vertex()); // This seems to return erroneus values every time
		if (isAffected == true) {
			cout << "Affected quadrillateral:" << endl;
			cout << "p1: " << p1 << endl;
			cout << "p2: " << p2 << endl;
			cout << "p3: " << p3 << endl;
			cout << "p4: " << p4 << endl;
		}
		if ( inCircle( p1, p3, p2, p4 ) || inCircle(p1, p2, p4, p3) ) {
			// Since either point was in a triangle circumcircle, flip the edge
			m.flip_edge(w.halfedge());
			cout << "Edge to be flipped: " << p1 << ", " << p2 << ". Other vertices: " << p3 << ", " << p4 << endl;
			// Recursively check all the edges that share a neighbour with the flipped edge
			recursiveDelaunayFlip(m, w.next(), true);
			recursiveDelaunayFlip(m, w.prev(), true);
			recursiveDelaunayFlip(m, w.opp().next(), true);
			recursiveDelaunayFlip(m, w.opp().prev(), true);
		}
	}
}
Example #2
0
void keyfun(unsigned char c, int x, int y)
{
	/*
	 * A little game, try to flip an edge when user presses any key.
	 * Not all edges can be flipped. Boundary edges cannot. Edges also
	 * cannot be flipped if it will render the mesh invalid.
	 */

	if(boundary(m, *flipper)) // If this is a boundary edge just drop the idea.
		cout << "boundary edge" << endl;
	else if(precond_flip_edge(m, *flipper))
  {
    m.flip_edge(*flipper);
		cout << "flipped" << endl;
  }
	else
  	cout << "could not flip" << endl;

	do
		{
			++flipper; // Get the next halfedge
			// If we have passed the last halfedge, go to the first.
			if(flipper==m.halfedges_end())
				{
					flipper = m.halfedges_begin();
					break;
				}
		}
	while(touched[*flipper] == 0); // Only visit halfedges marked '1'


	// Function call below informs glut that display should be called to
	// show the window again.
	glutPostRedisplay();
}