diff --git a/input/for_illustation_mode.txt b/input/for_illustation_mode.txt index 9cc1af6..5473118 100644 --- a/input/for_illustation_mode.txt +++ b/input/for_illustation_mode.txt @@ -1,96 +1,140 @@ -17 78 --1.740453 0.802854 --1.689924 -1.150945 --0.772123 -1.339691 --0.741096 1.549564 --0.690567 -0.011229 -0.432306 0.830926 -0.460378 -0.965671 -1.886426 0.903913 -1.965027 -1.835897 -1.976256 -0.151588 -2.953155 -1.055500 -3.042985 0.471607 -3.278788 1.600094 -3.587578 -1.802211 -4.132172 0.224575 -4.530791 0.909527 -4.564478 -0.567051 --1.740453 0.802854 --1.689924 -1.150945 --1.689924 -1.150945 --0.772123 -1.339691 --0.741096 1.549564 --0.690567 -0.011229 --0.772123 -1.339691 --0.690567 -0.011229 --1.689924 -1.150945 --0.690567 -0.011229 --1.740453 0.802854 --0.690567 -0.011229 --1.740453 0.802854 --0.741096 1.549564 -0.432306 0.830926 -0.460378 -0.965671 -0.460378 -0.965671 -1.965027 -1.835897 -0.432306 0.830926 -1.886426 0.903913 --0.772123 -1.339691 -1.965027 -1.835897 --0.772123 -1.339691 -0.460378 -0.965671 --0.690567 -0.011229 -0.460378 -0.965671 --0.690567 -0.011229 -0.432306 0.830926 --0.741096 1.549564 -0.432306 0.830926 --0.741096 1.549564 -1.886426 0.903913 -1.976256 -0.151588 -2.953155 -1.055500 -3.042985 0.471607 -3.278788 1.600094 -2.953155 -1.055500 -3.042985 0.471607 -1.976256 -0.151588 -3.042985 0.471607 -4.530791 0.909527 -4.564478 -0.567051 -3.587578 -1.802211 -4.564478 -0.567051 -4.132172 0.224575 -4.564478 -0.567051 -4.132172 0.224575 -4.530791 0.909527 -2.953155 -1.055500 -3.587578 -1.802211 -2.953155 -1.055500 -4.564478 -0.567051 -2.953155 -1.055500 -4.132172 0.224575 -3.042985 0.471607 -4.132172 0.224575 -3.278788 1.600094 -4.132172 0.224575 -3.278788 1.600094 -4.530791 0.909527 -1.965027 -1.835897 -3.587578 -1.802211 -1.965027 -1.835897 -2.953155 -1.055500 -1.965027 -1.835897 -1.976256 -0.151588 -0.460378 -0.965671 -1.976256 -0.151588 -0.432306 0.830926 -1.976256 -0.151588 -1.886426 0.903913 -1.976256 -0.151588 -1.886426 0.903913 -3.042985 0.471607 -1.886426 0.903913 -3.278788 1.600094 --0.741096 1.549564 -3.278788 1.600094 +23 116 +-1.527054 0.022044 +-1.384770 -0.773547 +-1.238477 0.202405 +-1.150301 0.747495 +-1.000000 -0.478958 +-0.957916 -0.040080 +-0.665331 -0.603206 +-0.527054 0.667335 +-0.521042 0.412826 +-0.340681 0.062124 +0.232465 0.410822 +0.240481 -0.879759 +0.509018 -0.084168 +0.763527 0.358717 +0.799599 0.865731 +0.893788 -0.767535 +0.965932 -0.571142 +1.004008 0.020040 +1.096192 0.591182 +1.286573 -0.484970 +1.384770 0.739479 +1.402806 -0.889780 +1.434870 0.208417 +-1.527054 0.022044 +-1.384770 -0.773547 +-1.238477 0.202405 +-1.527054 0.022044 +-1.000000 -0.478958 +-0.957916 -0.040080 +-1.527054 0.022044 +-1.150301 0.747495 +-1.238477 0.202405 +-1.150301 0.747495 +-1.238477 0.202405 +-0.957916 -0.040080 +-1.527054 0.022044 +-0.957916 -0.040080 +-1.527054 0.022044 +-1.000000 -0.478958 +-1.384770 -0.773547 +-1.000000 -0.478958 +-0.527054 0.667335 +-0.521042 0.412826 +-0.340681 0.062124 +0.232465 0.410822 +0.240481 -0.879759 +-0.340681 0.062124 +-0.527054 0.667335 +0.232465 0.410822 +-0.521042 0.412826 +0.232465 0.410822 +-0.521042 0.412826 +-0.340681 0.062124 +-0.665331 -0.603206 +-0.340681 0.062124 +-0.665331 -0.603206 +0.240481 -0.879759 +-1.150301 0.747495 +-0.527054 0.667335 +-1.150301 0.747495 +-0.521042 0.412826 +-1.238477 0.202405 +-0.521042 0.412826 +-0.957916 -0.040080 +-0.521042 0.412826 +-0.957916 -0.040080 +-0.340681 0.062124 +-0.957916 -0.040080 +-0.665331 -0.603206 +-1.000000 -0.478958 +-0.665331 -0.603206 +-1.384770 -0.773547 +-0.665331 -0.603206 +-1.384770 -0.773547 +0.240481 -0.879759 +0.509018 -0.084168 +0.763527 0.358717 +0.763527 0.358717 +0.799599 0.865731 +0.893788 -0.767535 +0.965932 -0.571142 +0.965932 -0.571142 +1.004008 0.020040 +0.763527 0.358717 +1.004008 0.020040 +0.509018 -0.084168 +1.004008 0.020040 +0.509018 -0.084168 +0.965932 -0.571142 +0.509018 -0.084168 +0.893788 -0.767535 +1.384770 0.739479 +1.096192 0.591182 +1.402806 -0.889780 +1.434870 0.208417 +1.384770 0.739479 +1.434870 0.208417 +1.096192 0.591182 +1.434870 0.208417 +1.286573 -0.484970 +1.434870 0.208417 +1.286573 -0.484970 +1.402806 -0.889780 +0.799599 0.865731 +1.384770 0.739479 +0.799599 0.865731 +1.096192 0.591182 +0.763527 0.358717 +1.096192 0.591182 +1.004008 0.020040 +1.096192 0.591182 +1.004008 0.020040 +1.434870 0.208417 +1.004008 0.020040 +1.286573 -0.484970 +0.965932 -0.571142 +1.286573 -0.484970 +0.965932 -0.571142 +1.402806 -0.889780 +0.893788 -0.767535 +1.402806 -0.889780 +-1.150301 0.747495 +0.799599 0.865731 +-0.527054 0.667335 +0.799599 0.865731 +0.232465 0.410822 +0.799599 0.865731 +0.232465 0.410822 +0.763527 0.358717 +0.232465 0.410822 +0.509018 -0.084168 +-0.340681 0.062124 +0.509018 -0.084168 +0.240481 -0.879759 +0.509018 -0.084168 +0.240481 -0.879759 +0.893788 -0.767535 +0.240481 -0.879759 +1.402806 -0.889780 diff --git a/src/delaunay.c b/src/delaunay.c index 4a94f24..3bc0f55 100644 --- a/src/delaunay.c +++ b/src/delaunay.c @@ -854,8 +854,10 @@ int pointInCircle(DelaunayTriangulation *delTri, GLsizei i_p, GLsizei i_a, GLsiz * delTri: the DelaunayTriangulation structure * i_a,b,c: the index of the points of the triangle * center: the preallocated array that will contain the center + * + * returns: the diameter of the circle */ -void circleCenter(DelaunayTriangulation *delTri, GLsizei i_a, GLsizei i_b, GLsizei i_c, GLfloat center[2]) { +GLfloat circleCenter(DelaunayTriangulation *delTri, GLsizei i_a, GLsizei i_b, GLsizei i_c, GLfloat center[2]) { // https://www.codewars.com/kata/5705785658b58f387b001ffc GLfloat *point, *a, *b, *c; a = delTri->points[i_a]; @@ -876,6 +878,13 @@ void circleCenter(DelaunayTriangulation *delTri, GLsizei i_a, GLsizei i_b, GLsiz center[0] = (aa * dy_bc + bb * dy_ca + cc * dy_ab) / d; // WARNING: there is an error is the link, it is Bx - Ax (and not the opposite) center[1] = (aa * (c[0] - b[0]) + bb * (a[0] - c[0]) + cc * (b[0] - a[0])) / d; + + GLfloat dx, dy; + + dx = a[0] - center[0]; + dy = a[1] - center[1]; + + return sqrt(dx * dx + dy * dy); } /* @@ -1202,18 +1211,11 @@ void drawDelaunayTriangulation(DelaunayTriangulation *delTri, bov_window_t *wind rules_parameters.fontSize *= .7; bov_text_set_param(rules, rules_parameters); - // Default values - GLfloat defaultPointWidth; - GLfloat updatedPointWidth; - - defaultPointWidth = 0.01; - updatedPointWidth = 0.04; - // Points bov_points_t *pointsDraw = bov_points_new(delTri->points, delTri->n_points, GL_STATIC_DRAW); - bov_points_set_color(pointsDraw, (GLfloat[4]) {0.0, 0.0, 0.0, 1.0}); - bov_points_set_outline_color(pointsDraw, (GLfloat[4]) {0.3, 0.12, 0.0, 0.25}); - bov_points_set_width(pointsDraw, defaultPointWidth); + bov_points_set_color(pointsDraw, BASIC_POINTS_COLOR); + bov_points_set_outline_color(pointsDraw, BASIC_POINTS_OUTLINE_COLOR); + bov_points_set_width(pointsDraw, BASIC_POINTS_WIDTH); GLfloat bounds[][2] = {{0.0, 0.0}, {0.0, 0.0}}; @@ -1221,10 +1223,10 @@ void drawDelaunayTriangulation(DelaunayTriangulation *delTri, bov_window_t *wind GLsizei n_lines = 0; GLfloat (*linesPoints)[2] = NULL; bov_points_t *linesDraw = bov_points_new(linesPoints, n_lines, GL_STATIC_DRAW); - bov_points_set_color(linesDraw, (GLfloat[4]) {0.0, 0.0, 0.0, 1.0}); - bov_points_set_width(linesDraw, 0.004); - bov_points_set_outline_color(linesDraw, (GLfloat[4]) {0.3, 0.12, 0.0, 0.25}); - bov_points_set_outline_width(linesDraw, .002); + bov_points_set_color(linesDraw, TRIANGULATION_LINES_COLOR); + bov_points_set_width(linesDraw, TRIANGULATION_LINES_WIDTH); + bov_points_set_outline_color(linesDraw, TRIANGULATION_LINES_OUTLINE_COLOR); + bov_points_set_outline_width(linesDraw, 0.5 * TRIANGULATION_LINES_WIDTH); // If DelaunayTriangulation was computed, will display it if (delTri->success) { @@ -1254,27 +1256,27 @@ void drawDelaunayTriangulation(DelaunayTriangulation *delTri, bov_window_t *wind // Mouse GLfloat mousePoint[][2] = {{0.0, 0.0}}; bov_points_t *mouseDraw = bov_points_new(mousePoint, 1, GL_STATIC_DRAW); - bov_points_set_color(mouseDraw, (GLfloat[4]) {0.0, 0.0, 0.0, 0.0}); - bov_points_set_outline_color(mouseDraw, (GLfloat[4]) {0.3, 0.12, 0.0, 0.25}); - bov_points_set_width(mouseDraw, defaultPointWidth); + bov_points_set_color(mouseDraw, MOUSE_POINTS_COLOR); + bov_points_set_outline_color(mouseDraw, MOUSE_POINTS_OUTLINE_COLOR); + bov_points_set_width(mouseDraw, MOUSE_POINTS_WIDTH); bov_points_set_outline_width(mouseDraw, -.1); // Voronoi GLsizei n_triangles = 0; GLfloat (*voronoiCenters)[2] = NULL; bov_points_t *voronoiCentersDraw = bov_points_new(voronoiCenters, n_triangles, GL_STATIC_DRAW); - bov_points_set_color(voronoiCentersDraw, (GLfloat[4]) {0.0, 1.0, 0.0, 1.0}); - bov_points_set_outline_color(voronoiCentersDraw, (GLfloat[4]) {0.3, 0.12, 0.0, 0.25}); - bov_points_set_width(voronoiCentersDraw, defaultPointWidth); + bov_points_set_color(voronoiCentersDraw, VORONOI_POINTS_COLOR); + bov_points_set_outline_color(voronoiCentersDraw, VORONOI_POINTS_OUTLINE_COLOR); + bov_points_set_width(voronoiCentersDraw, VORONOI_POINTS_WIDTH); GLsizei n_voronoi_lines = 0; GLsizei (*voronoiNeighbors)[3] = NULL; GLfloat (*voronoiLines)[2] = NULL; bov_points_t *voronoiLinesDraw = bov_points_new(linesPoints, n_lines, GL_STATIC_DRAW); - bov_points_set_color(voronoiLinesDraw, (GLfloat[4]) {0.0, 0.0, 1.0, 1.0}); - bov_points_set_width(voronoiLinesDraw, 0.004); - bov_points_set_outline_color(voronoiLinesDraw, (GLfloat[4]) {0.3, 0.12, 0.0, 0.25}); - bov_points_set_outline_width(voronoiLinesDraw, .002); + bov_points_set_color(voronoiLinesDraw, VORONOI_LINES_COLOR); + bov_points_set_width(voronoiLinesDraw, VORONOI_LINES_WIDTH); + bov_points_set_outline_color(voronoiLinesDraw, VORONOI_LINES_OUTLINE_COLOR); + bov_points_set_outline_width(voronoiLinesDraw, .5 * VORONOI_LINES_WIDTH); // Write keystrokes in a file @@ -1433,9 +1435,9 @@ void drawDelaunayTriangulation(DelaunayTriangulation *delTri, bov_window_t *wind // Active points bov_points_t *activePointsDraw = bov_points_new(delTri->points, delTri->n_points, GL_STATIC_DRAW); - bov_points_set_color(activePointsDraw, (GLfloat[4]) {0.0, 1.0, 0.0, 1.0}); - bov_points_set_outline_color(activePointsDraw, (GLfloat[4]) {0.3, 1., 0.0, 0.25}); - bov_points_set_width(activePointsDraw, 2 * defaultPointWidth); + bov_points_set_color(activePointsDraw, ACTIVE_POINTS_COLOR); + bov_points_set_outline_color(activePointsDraw, ACTIVE_POINTS_OUTLINE_COLOR); + bov_points_set_width(activePointsDraw, ACTIVE_POINTS_WIDTH); // Trying to make the sleep time % to the inverse of the number of edges @@ -1526,7 +1528,7 @@ void drawDelaunayTriangulation(DelaunayTriangulation *delTri, bov_window_t *wind // Draws a red point where the mouse was when key was pressed bov_points_update(mouseDraw, mousePoint, 1); bov_points_set_color(mouseDraw, (GLfloat[4]) {1.0, 0.0, 0.0, 1.0}); - bov_points_set_width(mouseDraw, updatedPointWidth); + bov_points_set_width(mouseDraw, MOUSE_POINTS_WIDTH); GLsizei n_triangles = getNumberOfTriangles(delTri); @@ -1536,7 +1538,7 @@ void drawDelaunayTriangulation(DelaunayTriangulation *delTri, bov_window_t *wind else { bov_points_param_t param = bov_points_get_param(mouseDraw); param.fillColor[3] *= 0.95; - param.width -= (param.width - defaultPointWidth) / 10; + param.width -= (param.width - BASIC_POINTS_WIDTH) / 10; bov_points_set_param(mouseDraw, param); } @@ -1639,6 +1641,7 @@ DTDrawingParameters* initDTDrawingParameters(DelaunayTriangulation *delTri, DTDparams->linesDraw = linesDraw; DTDparams->FAST = FAST; DTDparams->sleep = sleep; + DTDparams->draw_circle = 1; GLfloat dy = bounds[1][1] - bounds[0][1]; @@ -1652,12 +1655,65 @@ DTDrawingParameters* initDTDrawingParameters(DelaunayTriangulation *delTri, DTDparams->divideLinesDraw = bov_points_new(DTDparams->divideLinesPoints, DTDparams->n_divides_max * 2, GL_STATIC_DRAW); DTDparams->divideLinesMask = calloc(DTDparams->n_divides_max, sizeof(char)); - bov_points_set_color(DTDparams->divideLinesDraw, (GLfloat[4]) {1.0, 0.0, 0.0, 0.8}); - bov_points_set_width(DTDparams->divideLinesDraw, 0.015); + bov_points_set_color(DTDparams->divideLinesDraw, DIVIDE_LINES_COLOR); + bov_points_set_width(DTDparams->divideLinesDraw, DIVIDE_LINES_WIDTH); + + GLfloat dtheta = 2 * M_PI / (GLfloat) N_POINTS; + GLfloat theta = 0.0; + + for (GLsizei i = 0; i < N_POINTS; i++) { + DTDparams->cos_[i] = cos(theta); + DTDparams->sin_[i] = sin(theta); + + theta += dtheta; + } + + DTDparams->searchPointsDraw = bov_points_new(DTDparams->delTri->points, DTDparams->delTri->n_points, GL_STATIC_DRAW); + DTDparams->circlePointsDraw = bov_points_new(DTDparams->circ, N_POINTS, GL_STATIC_DRAW); + DTDparams->searchPointsOrder = bov_order_new(DTDparams->searchPoints, 3, GL_STATIC_DRAW); + + bov_points_set_color(DTDparams->searchPointsDraw, SEARCHED_POINTS_COLOR); + bov_points_set_width(DTDparams->searchPointsDraw, SEARCHED_POINTS_WIDTH); + bov_points_set_color(DTDparams->circlePointsDraw, CIRCLE_LINES_COLOR); + bov_points_set_width(DTDparams->circlePointsDraw, CIRCLE_LINES_WIDTH); return DTDparams; } +/* + * Sets the new triplet of points to be the triangle from which the + * cicurmcicle will be computed. + * + * DTDparams: the DTDrawingParameters structure + * i_a,b,c: the point indices + */ +void setSearchPoints(DTDrawingParameters *DTDparams, + GLsizei i_a, GLsizei i_b ,GLsizei i_c) { + + DTDparams->searchPoints[0] = i_a; + DTDparams->searchPoints[1] = i_b; + DTDparams->searchPoints[2] = i_c; + + bov_order_update(DTDparams->searchPointsOrder, DTDparams->searchPoints, 3); + + GLfloat radius, center[2]; + radius = circleCenter(DTDparams->delTri, i_a, i_b, i_c, center); + + for (GLsizei i = 0; i < N_POINTS; i++) { + DTDparams->circ[i][0] = center[0] + radius * DTDparams->cos_[i]; + DTDparams->circ[i][1] = center[1] + radius * DTDparams->sin_[i]; + } + + bov_points_update(DTDparams->circlePointsDraw, DTDparams->circ, N_POINTS); + +} + +/* + * Adds a dividing line at pivot point. + * + * DTDparams: the DTDrawingParameters structure + * pivot: the pivot point (start of right half) + */ GLsizei addDivideLine(DTDrawingParameters *DTDparams, GLsizei pivot) { if (DTDparams->n_divides == DTDparams->n_divides_max) { printf("ERROR: Not enough space was allocated for divide lines\n"); @@ -1696,6 +1752,9 @@ void freeDTDrawingParameters(DTDrawingParameters *DTDparams) { if (DTDparams->divideLinesPoints != NULL) free(DTDparams->divideLinesPoints); if (DTDparams->divideLinesDraw != NULL) bov_points_delete(DTDparams->divideLinesDraw); if (DTDparams->divideLinesMask != NULL) free(DTDparams->divideLinesMask); + if (DTDparams->searchPointsDraw != NULL) bov_points_delete(DTDparams->searchPointsDraw); + if (DTDparams->circlePointsDraw != NULL) bov_points_delete(DTDparams->circlePointsDraw); + if (DTDparams->searchPointsOrder != NULL) bov_order_delete(DTDparams->searchPointsOrder); free(DTDparams); } } @@ -1731,6 +1790,11 @@ void reDrawTriangulation(DTDrawingParameters *DTDparams, bov_fast_lines_draw(DTDparams->window, DTDparams->divideLinesDraw, 2 * i, 2 * i + 2); } } + + if (DTDparams->draw_circle) { + bov_fast_line_loop_draw(DTDparams->window, DTDparams->circlePointsDraw, 0, BOV_TILL_END); + bov_fast_points_draw_with_order(DTDparams->window, DTDparams->searchPointsDraw, DTDparams->searchPointsOrder, 0, BOV_TILL_END); + } } else { bov_lines_draw(DTDparams->window, DTDparams->linesDraw, 0, BOV_TILL_END); @@ -1742,6 +1806,11 @@ void reDrawTriangulation(DTDrawingParameters *DTDparams, bov_lines_draw(DTDparams->window, DTDparams->divideLinesDraw, 2 * i, 2 * i + 2); } } + + if (DTDparams->draw_circle) { + bov_line_loop_draw(DTDparams->window, DTDparams->circlePointsDraw, 0, BOV_TILL_END); + bov_points_draw_with_order(DTDparams->window, DTDparams->searchPointsDraw, DTDparams->searchPointsOrder, 0, BOV_TILL_END); + } } bov_window_update(DTDparams->window); @@ -1765,7 +1834,9 @@ void triangulateDTIllustrated(DTDrawingParameters *DTDparams) { // Sort points by x coordinates then by y coordinate. qsort(DTDparams->delTri->points, DTDparams->delTri->n_points, 2 * sizeof(GLfloat), compare_points); + DTDparams->draw_circle = 0; reDrawTriangulation(DTDparams, 0, 0); + DTDparams->draw_circle = 1; /// Starts the triangulation using a divide and conquer approach. Edge *l, *r; @@ -1792,7 +1863,9 @@ void triangulateIllustrated(DelaunayTriangulation *delTri, GLsizei start, GLsize Edge *e = addEdge(delTri, start, start + 1); *el = e; *er = e->sym; + DTDparams->draw_circle = 0; reDrawTriangulation(DTDparams, start, end); + DTDparams->draw_circle = 1; return; } else if (n == 3) { @@ -1807,6 +1880,8 @@ void triangulateIllustrated(DelaunayTriangulation *delTri, GLsizei start, GLsize int cmp = pointCompareEdge(delTri, start + 2, a); + setSearchPoints(DTDparams, a->orig, a->dest, b->dest); + // Now will close the triangle formed by the three points if (cmp == 1) { c = connectEdges(delTri, b, a); @@ -1835,7 +1910,9 @@ void triangulateIllustrated(DelaunayTriangulation *delTri, GLsizei start, GLsize Edge *ldo, *ldi, *rdi, *rdo; GLsizei divide_index = addDivideLine(DTDparams, start + m); + DTDparams->draw_circle = 0; reDrawTriangulation(DTDparams, start, end); + DTDparams->draw_circle = 1; triangulateIllustrated(delTri, start, start + m, &ldo, &ldi, DTDparams); triangulateIllustrated(delTri, start + m, end, &rdi, &rdo, DTDparams); @@ -1843,6 +1920,7 @@ void triangulateIllustrated(DelaunayTriangulation *delTri, GLsizei start, GLsize // Computes the upper common tangent of left and right edges while (1) { + setSearchPoints(DTDparams, rdi->orig, rdi->dest, ldi->dest); if (pointCompareEdge(delTri, rdi->orig, ldi) == 1) { ldi = ldi->sym->onext; reDrawTriangulation(DTDparams, start, end); @@ -1857,6 +1935,7 @@ void triangulateIllustrated(DelaunayTriangulation *delTri, GLsizei start, GLsize } Edge *base; + DTDparams->draw_circle = 0; // Creates an edge between rdi.orig and ldi.orig base = connectEdges(delTri, ldi->sym, rdi); @@ -1871,6 +1950,7 @@ void triangulateIllustrated(DelaunayTriangulation *delTri, GLsizei start, GLsize rdo = base->sym; reDrawTriangulation(DTDparams, start, end); } + DTDparams->draw_circle = 1; Edge *lcand, *rcand, *tmp; int v_rcand, v_lcand; @@ -1885,6 +1965,7 @@ void triangulateIllustrated(DelaunayTriangulation *delTri, GLsizei start, GLsize v_rcand = (pointCompareEdge(delTri, rcand->dest, base) == 1); v_lcand = (pointCompareEdge(delTri, lcand->dest, base) == 1); + if (!(v_rcand || v_lcand)) { // Merge is done break; @@ -1898,6 +1979,7 @@ void triangulateIllustrated(DelaunayTriangulation *delTri, GLsizei start, GLsize tmp = rcand->onext; deleteEdge(delTri, rcand); rcand = tmp; + setSearchPoints(DTDparams, base->dest, base->orig, rcand->dest); reDrawTriangulation(DTDparams, start, end); } } @@ -1910,6 +1992,7 @@ void triangulateIllustrated(DelaunayTriangulation *delTri, GLsizei start, GLsize tmp = lcand->oprev; deleteEdge(delTri, lcand); lcand = tmp; + setSearchPoints(DTDparams, base->dest, base->orig, lcand->dest); reDrawTriangulation(DTDparams, start, end); } } @@ -1920,15 +2003,19 @@ void triangulateIllustrated(DelaunayTriangulation *delTri, GLsizei start, GLsize tmp = connectEdges(delTri, lcand, base->sym); base = tmp; + setSearchPoints(DTDparams, rcand->dest, rcand->orig, lcand->orig); reDrawTriangulation(DTDparams, start, end); } else { tmp = connectEdges(delTri, base->sym, rcand->sym); base = tmp; + setSearchPoints(DTDparams, rcand->dest, rcand->orig, lcand->orig); reDrawTriangulation(DTDparams, start, end); } } + DTDparams->draw_circle = 0; reDrawTriangulation(DTDparams, start, end); + DTDparams->draw_circle = 1; *el = ldo; *er = rdo; } diff --git a/src/delaunay.h b/src/delaunay.h index c20c685..2e95aa9 100644 --- a/src/delaunay.h +++ b/src/delaunay.h @@ -33,6 +33,51 @@ #define ROBUST 1 // If True, will use robust predicates but will add overhead (x1.3 slowdown) // Non robust methods may caude problems with colinear (or close to) points #define MIN_DIST 1E-10 // Minimim distance between two points (used to avoid placing multiple points at the same location) +#define N_POINTS 100 // Number of points to draw in a circle + +// Define some colors + +#define RED_COLOR (GLfloat[4]) {1.0, 0.0, 0.0, 1.0} +#define GREEN_COLOR (GLfloat[4]) {0.0, 1.0, 0.0, 1.0} +#define BLUE_COLOR (GLfloat[4]) {0.0, 0.0, 1.0, 1.0} +#define BLACK_COLOR (GLfloat[4]) {0.0, 0.0, 0.0, 1.0} +#define WHITE_COLOR (GLfloat[4]) {1.0, 1.0, 1.0, 1.0} +#define NONE_COLOR (GLfloat[4]) {0.0, 0.0, 0.0, 0.0} +#define DARK_RED_COLOR (GLfloat[4]) {0.722, 0.163, 0.0, 1.0} +#define MED_BLUE_COLOR (GLfloat[4]) {0.0, 0.565, 0.901, 1.0} +#define MED_BLUE_COLOR_25 (GLfloat[4]) {0.0, 0.565, 0.901, 0.25} +#define SEA_GREEN_COLOR (GLfloat[4]) {0.016, 0.73, 0.677, 1.0} +#define SEA_GREEN_COLOR_75 (GLfloat[4]) {0.016, 0.73, 0.677, 0.75} + +#define BASIC_POINTS_COLOR BLACK_COLOR +#define BASIC_POINTS_OUTLINE_COLOR (GLfloat[4]) {0.3, 0.12, 0.0, 0.25} +#define VORONOI_POINTS_COLOR DARK_RED_COLOR +#define VORONOI_POINTS_OUTLINE_COLOR (GLfloat[4]) {0.3, 0.12, 0.0, 0.25} +#define ACTIVE_POINTS_COLOR DARK_RED_COLOR +#define ACTIVE_POINTS_OUTLINE_COLOR (GLfloat[4]) {0.3, 1., 0.0, 0.25} +#define SEARCHED_POINTS_COLOR MED_BLUE_COLOR +#define MOUSE_POINTS_COLOR NONE_COLOR +#define MOUSE_POINTS_OUTLINE_COLOR (GLfloat[4]) {0.3, 0.12, 0.0, 0.25} + +#define TRIANGULATION_LINES_COLOR BLACK_COLOR +#define TRIANGULATION_LINES_OUTLINE_COLOR (GLfloat[4]) {0.3, 0.12, 0.0, 0.25} +#define VORONOI_LINES_COLOR MED_BLUE_COLOR +#define VORONOI_LINES_OUTLINE_COLOR MED_BLUE_COLOR_25 +#define DIVIDE_LINES_COLOR (GLfloat[4]) {1.0, 0.0, 0.0, 0.8} +#define CIRCLE_LINES_COLOR MED_BLUE_COLOR + +// Define some widths + +#define BASIC_POINTS_WIDTH 0.01 +#define VORONOI_POINTS_WIDTH BASIC_POINTS_WIDTH +#define ACTIVE_POINTS_WIDTH (2.0 * BASIC_POINTS_WIDTH) +#define SEARCHED_POINTS_WIDTH (1.5 * BASIC_POINTS_WIDTH) +#define MOUSE_POINTS_WIDTH 0.04 + +#define TRIANGULATION_LINES_WIDTH 0.004 +#define VORONOI_LINES_WIDTH TRIANGULATION_LINES_WIDTH +#define DIVIDE_LINES_WIDTH 0.002 +#define CIRCLE_LINES_WIDTH 0.004 typedef struct Edge { @@ -63,9 +108,15 @@ typedef struct DTDrawingParameters { DelaunayTriangulation *delTri; bov_window_t *window; GLfloat (*linesPoints)[2]; + GLfloat cos_[N_POINTS]; + GLfloat sin_[N_POINTS]; + GLfloat circ[N_POINTS][2]; + GLsizei searchPoints[3]; bov_points_t *pointsDraw, *activePointsDraw, *linesDraw; + bov_points_t *searchPointsDraw, *circlePointsDraw; + bov_order_t *searchPointsOrder; GLfloat y_min, y_max; - int FAST, sleep; + int FAST, sleep, draw_circle; GLsizei n_divides, n_divides_max; @@ -99,7 +150,7 @@ void deleteEdge(DelaunayTriangulation *delTri, Edge *e); static int compare_points(const void *a_v, const void *b_v); void getPointsBoudingBox(GLfloat points[][2], GLsizei n_points, GLfloat bounds[][2]); int pointInCircle(DelaunayTriangulation *delTri, GLsizei i_p, GLsizei i_a, GLsizei i_b, GLsizei i_c); -void circleCenter(DelaunayTriangulation *delTri, GLsizei i_a, GLsizei i_b, GLsizei i_c, GLfloat center[2]); +GLfloat circleCenter(DelaunayTriangulation *delTri, GLsizei i_a, GLsizei i_b, GLsizei i_c, GLfloat center[2]); int pointCompareEdge(DelaunayTriangulation *delTri, GLsizei i_p, Edge *e); GLfloat angleBetweenContiguousEdges(DelaunayTriangulation *delTri, Edge *e, Edge *f); @@ -117,6 +168,8 @@ DTDrawingParameters* initDTDrawingParameters(DelaunayTriangulation *delTri, bov_points_t *linesDraw, GLfloat bounds[][2], int FAST, int sleep); +void setSearchPoints(DTDrawingParameters *DTDparams, + GLsizei i_a, GLsizei i_b ,GLsizei i_c); GLsizei addDivideLine(DTDrawingParameters *DTDparams, GLsizei pivot); void deleteDivideLine(DTDrawingParameters *DTDparams, GLsizei index); void freeDTDrawingParameters(DTDrawingParameters *DTDparams); diff --git a/src/main.c b/src/main.c index da4607c..64068cb 100644 --- a/src/main.c +++ b/src/main.c @@ -284,7 +284,7 @@ int main(int argc, char *argv[]) bov_window_t* window = bov_window_new(-1, 1, "DelaunayTriangulation - Jérome Eertmans"); #if WHITE_BACKGROUND - bov_window_set_color(window, (GLfloat[]){1.0f, 1.f, 1.0f, 1.0f}); + bov_window_set_color(window, (GLfloat[]){1.0f, 1.0f, 1.0f, 1.0f}); #else bov_window_set_color(window, (GLfloat[]){0.9f, 0.85f, 0.8f, 1.0f}); #endif diff --git a/static/illustration.gif b/static/illustration.gif index 104f710..7cfaa7b 100644 Binary files a/static/illustration.gif and b/static/illustration.gif differ diff --git a/static/interact.gif b/static/interact.gif index c1118c3..06e61f4 100644 Binary files a/static/interact.gif and b/static/interact.gif differ