From: Jean-Philippe Bruyère Date: Mon, 23 Apr 2018 18:36:51 +0000 (+0200) Subject: first concluent test with seidel triangulation X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=009a43b4eba0c21de18c74ade304f61bfa7bc83f;p=jp%2Fvkvg.git first concluent test with seidel triangulation --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 8034724..1740bb0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,7 +85,7 @@ if(GLSLC AND XXD) #add_definitions( -DDEBUG_VK_PERF=true ) endif() -FILE(GLOB VKVG_SRC src/*.c) #src/seidel/*.c) +FILE(GLOB VKVG_SRC src/*.c src/seidel/*.c) ADD_LIBRARY(${PROJECT_NAME} SHARED ${VKVG_SRC} ${SHADERS}) diff --git a/src/seidel/construct.c b/src/seidel/construct.c index 800e364..12eceb8 100644 --- a/src/seidel/construct.c +++ b/src/seidel/construct.c @@ -190,10 +190,10 @@ static int init_query_structure(segnum) tr[t1].hi = tr[t2].hi = tr[t4].lo = qs[i1].yval; tr[t1].lo = tr[t2].lo = tr[t3].hi = qs[i3].yval; - tr[t4].hi.y = (double) (INFINITY); - tr[t4].hi.x = (double) (INFINITY); - tr[t3].lo.y = (double) -1* (INFINITY); - tr[t3].lo.x = (double) -1* (INFINITY); + tr[t4].hi.y = (float) (INFINITY); + tr[t4].hi.x = (float) (INFINITY); + tr[t3].lo.y = (float) -1* (INFINITY); + tr[t3].lo.x = (float) -1* (INFINITY); tr[t1].rseg = tr[t2].lseg = segnum; tr[t1].u0 = tr[t2].u0 = t4; tr[t1].d0 = tr[t2].d0 = t3; @@ -228,7 +228,7 @@ static int is_left_of(segnum, v) point_t *v; { segment_t *s = &seg[segnum]; - double area; + float area; if (_greater_than(&s->v1, &s->v0)) /* seg. going upwards */ { @@ -842,7 +842,7 @@ static int add_segment(segnum) else { int tmpseg = tr[tr[t].d0].rseg; - double y0, yt; + float y0, yt; point_t tmppt; int tnext, i_d0, i_d1; diff --git a/src/seidel/interface.h b/src/seidel/interface.h index 077392d..ad4cf6c 100644 --- a/src/seidel/interface.h +++ b/src/seidel/interface.h @@ -4,7 +4,7 @@ #define TRUE 1 #define FALSE 0 -extern int triangulate_polygon(int, int *, double (*)[2], int (*)[3]); -extern int is_point_inside_polygon(double *); +extern int triangulate_polygon(int, int *, float (*)[2], int (*)[3]); +extern int is_point_inside_polygon(float *); #endif /* __interface_h */ diff --git a/src/seidel/misc.c b/src/seidel/misc.c index 7cac3dd..ebba8db 100644 --- a/src/seidel/misc.c +++ b/src/seidel/misc.c @@ -2,11 +2,11 @@ #include #include -#ifdef __STDC__ -extern double log2(double); +/*#ifdef __STDC__ +extern float log2(float); #else -extern double log2(); -#endif +extern float log2(); +#endif*/ static int choose_idx; static int permute[SEGSIZE]; @@ -130,9 +130,9 @@ int math_logstar_n(n) int n; { register int i; - double v; + float v; - for (i = 0, v = (double) n; v >= 1; i++) + for (i = 0, v = (float) n; v >= 1; i++) v = log2(v); return (i - 1); @@ -144,10 +144,10 @@ int math_N(n, h) int h; { register int i; - double v; + float v; for (i = 0, v = (int) n; i < h; i++) v = log2(v); - return (int) ceil((double) 1.0*n/v); + return (int) ceil((float) 1.0*n/v); } diff --git a/src/seidel/monotone.c b/src/seidel/monotone.c index 20c51da..f7076ff 100644 --- a/src/seidel/monotone.c +++ b/src/seidel/monotone.c @@ -58,7 +58,7 @@ static int new_chain_element() } -static double get_angle(vp0, vpnext, vp1) +static float get_angle(vp0, vpnext, vp1) point_t *vp0; point_t *vpnext; point_t *vp1; @@ -88,7 +88,7 @@ static int get_vertex_positions(v0, v1, ip, iq) { vertexchain_t *vp0, *vp1; register int i; - double angle, temp; + float angle, temp; int tp, tq; vp0 = &vert[v0]; diff --git a/src/seidel/tri.c b/src/seidel/tri.c index 35185d7..7a5c078 100644 --- a/src/seidel/tri.c +++ b/src/seidel/tri.c @@ -72,7 +72,7 @@ int main(argc, argv) int triangulate_polygon(ncontours, cntr, vertices, triangles) int ncontours; int cntr[]; - double (*vertices)[2]; + float (*vertices)[2]; int (*triangles)[3]; { register int i; @@ -142,7 +142,7 @@ int triangulate_polygon(ncontours, cntr, vertices, triangles) */ int is_point_inside_polygon(vertex) - double vertex[2]; + float vertex[2]; { point_t v; int trnum, rseg; diff --git a/src/seidel/triangulate.h b/src/seidel/triangulate.h index ee323c6..3ae2f7c 100644 --- a/src/seidel/triangulate.h +++ b/src/seidel/triangulate.h @@ -6,7 +6,7 @@ #include typedef struct { - double x, y; + float x, y; } point_t, vector_t; diff --git a/src/vkvg_context.c b/src/vkvg_context.c index cd59d27..81d6c74 100644 --- a/src/vkvg_context.c +++ b/src/vkvg_context.c @@ -25,6 +25,7 @@ #include "vkvg_surface_internal.h" #include "vkvg_pattern.h" #include "vkh_queue.h" +#include "seidel/interface.h" #ifdef DEBUG static vec2 debugLinePoints[1000]; @@ -353,50 +354,26 @@ void vkvg_fill_preserve (VkvgContext ctx){ uint32_t pathPointCount = lastPtIdx - ctx->pathes[ptrPath] + 1; uint32_t firstVertIdx = ctx->vertCount; - ear_clip_point ecps[pathPointCount]; - uint32_t ecps_count = pathPointCount; - uint32_t i = 0; + float triIn[pathPointCount+1][2]; + memcpy(&triIn[1], &ctx->points[firstPtIdx], 2* sizeof(float) * pathPointCount); + int cpt[] = {pathPointCount}; + int triOut[pathPointCount-2][3]; - //init points link list - while (i < pathPointCount-1){ + triangulate_polygon(1, cpt, triIn, triOut); + + + for (int i=0; ipoints[i+firstPtIdx]; - ear_clip_point ecp = {v.pos, i+firstVertIdx, &ecps[i+1]}; - ecps[i] = ecp; _add_vertex(ctx, v); - i++; } - v.pos = ctx->points[i+firstPtIdx]; - ear_clip_point ecp = {v.pos, i+firstVertIdx, ecps}; - ecps[i] = ecp; - _add_vertex(ctx, v); - - ear_clip_point* ecp_current = ecps; - - while (ecps_count > 3) { - ear_clip_point* v0 = ecp_current->next, - *v1 = ecp_current, *v2 = ecp_current->next->next; - if (ecp_zcross (v0, v2, v1)<0){ - ecp_current = ecp_current->next; - continue; - } - ear_clip_point* vP = v2->next; - bool isEar = true; - while (vP!=v1){ - if (ptInTriangle (vP->pos, v0->pos, v2->pos, v1->pos)){ - isEar = false; - break; - } - vP = vP->next; - } - if (isEar){ - _add_triangle_indices (ctx, v0->idx, v1->idx, v2->idx); - v1->next = v2; - ecps_count --; - }else - ecp_current = ecp_current->next; + + firstVertIdx--;//indices start at 1 + for (int i=0; inext->idx, ecp_current->idx, ecp_current->next->next->idx); ptrPath+=2; }