]> O.S.I.I.S - jp/vkvg.git/commitdiff
first concluent test with seidel triangulation
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Mon, 23 Apr 2018 18:36:51 +0000 (20:36 +0200)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Mon, 23 Apr 2018 18:36:51 +0000 (20:36 +0200)
CMakeLists.txt
src/seidel/construct.c
src/seidel/interface.h
src/seidel/misc.c
src/seidel/monotone.c
src/seidel/tri.c
src/seidel/triangulate.h
src/vkvg_context.c

index 80347241299b615a2e8d4619c00998df5f5b88c7..1740bb027f15b0e9ddf9a569bd94e9b99bf82788 100644 (file)
@@ -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})
 
index 800e364904c317be97382f55a8004bfc8e20f515..12eceb8c3b9fd21886f70dde1f5f509dd16201ce 100644 (file)
@@ -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;
 
index 077392d7f0b226bae8884ddedb22dac0890d913e..ad4cf6c12747a27ca90ab5d1733a674e26259e0a 100644 (file)
@@ -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 */
index 7cac3dd87c6bd54ec64fe04b83172a0206a20187..ebba8dbc4419605288afc67288488dc9b86d72b9 100644 (file)
@@ -2,11 +2,11 @@
 #include <sys/time.h>
 #include <math.h>
 
-#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);
 }
index 20c51daf1c91df09061c989eab7e3decb8a21f96..f7076ff0bdd08da429d0b39adc56088917f338ea 100644 (file)
@@ -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];
index 35185d7d65f5234af620a4717954c2b668f8c30f..7a5c0789f73fc13fc61a461df7aaed501e8d0de2 100644 (file)
@@ -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;
index ee323c60c498525f19b263741b3d9e6eee09f0b5..3ae2f7cbaca050cdd4b64b552017bad785bf1db1 100644 (file)
@@ -6,7 +6,7 @@
 #include <stdio.h>
 
 typedef struct {
-  double x, y;
+  float x, y;
 } point_t, vector_t;
 
 
index cd59d27a5322fce86d3fc4b0116feab6ed282aa7..81d6c7496ba63276ec3bcfee47dc4d1e6722a476 100644 (file)
@@ -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; i<pathPointCount;i++){
             v.pos = ctx->points[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; i<pathPointCount-2;i++){
+            _add_triangle_indices (ctx,
+                    triOut[i][2] + firstVertIdx,
+                    triOut[i][1] + firstVertIdx,
+                    triOut[i][0] + firstVertIdx);
         }
-        if (ecps_count == 3)
-            _add_triangle_indices(ctx, ecp_current->next->idx, ecp_current->idx, ecp_current->next->next->idx);
 
         ptrPath+=2;
     }