[gegl/soc-2011-seamless-clone: 25/35] Update the seamless-clone operation to use the new poly2tri-c lib



commit 416ee751e0059e31b6525993258073952cf01b1d
Author: Barak Itkin <lightningismyname gmail com>
Date:   Sat Jun 2 13:23:32 2012 +0300

    Update the seamless-clone operation to use the new poly2tri-c lib
    
    * GEGL now depends on poly2tri-c (git commit 566e50 or later)
    * The old version of poly2tri-c was removed from GEGL's repo

 configure.ac                                       |   14 +-
 gegl.pc.in                                         |    2 +-
 operations/common/seamless-clone/Makefile.am       |    5 +-
 operations/common/seamless-clone/find-outline.c    |    4 +-
 operations/common/seamless-clone/make-mesh.c       |   64 +-
 operations/common/seamless-clone/make-mesh.h       |    4 +-
 .../common/seamless-clone/poly2tri-c/.gitignore    |    7 -
 .../common/seamless-clone/poly2tri-c/Makefile.am   |   20 -
 .../seamless-clone/poly2tri-c/common/.gitignore    |    7 -
 .../seamless-clone/poly2tri-c/common/Makefile.am   |   10 -
 .../seamless-clone/poly2tri-c/common/cutils.h      |   39 -
 .../poly2tri-c/common/poly2tri-private.h           |   34 -
 .../seamless-clone/poly2tri-c/common/shapes.c      |  736 ----------
 .../seamless-clone/poly2tri-c/common/shapes.h      |  262 ----
 .../seamless-clone/poly2tri-c/common/utils.c       |   95 --
 .../seamless-clone/poly2tri-c/common/utils.h       |   63 -
 operations/common/seamless-clone/poly2tri-c/main.c |  260 ----
 .../common/seamless-clone/poly2tri-c/poly2tri.h    |   39 -
 .../seamless-clone/poly2tri-c/refine/.gitignore    |    7 -
 .../seamless-clone/poly2tri-c/refine/Makefile.am   |   10 -
 .../seamless-clone/poly2tri-c/refine/refine.c      |  706 ---------
 .../seamless-clone/poly2tri-c/refine/refine.h      |   29 -
 .../poly2tri-c/refine/triangulation.c              | 1494 --------------------
 .../poly2tri-c/refine/triangulation.h              |  323 -----
 .../seamless-clone/poly2tri-c/refine/utils.h       |   71 -
 .../seamless-clone/poly2tri-c/render/.gitignore    |    7 -
 .../seamless-clone/poly2tri-c/render/Makefile.am   |   10 -
 .../seamless-clone/poly2tri-c/render/mesh-render.c |  354 -----
 .../seamless-clone/poly2tri-c/render/mesh-render.h |   73 -
 .../seamless-clone/poly2tri-c/render/svg-plot.c    |  330 -----
 .../seamless-clone/poly2tri-c/render/svg-plot.h    |   98 --
 .../seamless-clone/poly2tri-c/sweep/.gitignore     |    7 -
 .../seamless-clone/poly2tri-c/sweep/Makefile.am    |   12 -
 .../poly2tri-c/sweep/advancing_front.c             |  224 ---
 .../poly2tri-c/sweep/advancing_front.h             |   88 --
 .../common/seamless-clone/poly2tri-c/sweep/cdt.c   |   90 --
 .../common/seamless-clone/poly2tri-c/sweep/cdt.h   |  101 --
 .../common/seamless-clone/poly2tri-c/sweep/sweep.c |  932 ------------
 .../common/seamless-clone/poly2tri-c/sweep/sweep.h |  270 ----
 .../poly2tri-c/sweep/sweep_context.c               |  313 ----
 .../poly2tri-c/sweep/sweep_context.h               |  133 --
 .../common/seamless-clone/seamless-clone-common.c  |   16 +-
 .../common/seamless-clone/seamless-clone-common.h  |   10 +-
 .../common/seamless-clone/seamless-clone-prepare.c |    6 +-
 .../common/seamless-clone/seamless-clone-render.c  |    6 +-
 operations/common/seamless-clone/seamless-clone.c  |    6 +-
 operations/common/seamless-clone/seamless-clone.h  |    6 +-
 47 files changed, 76 insertions(+), 7321 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 8508fba..af62f51 100644
--- a/configure.ac
+++ b/configure.ac
@@ -52,6 +52,7 @@ m4_define([pango_required_version], [0.0.0])
 m4_define([pangocairo_required_version], [0.0.0])
 m4_define([png_required_version], [0.0.0])
 m4_define([sdl_required_version], [0.0.0])
+m4_define([poly2tri-c_required_version], [0.0.0])
 
 AC_INIT(gegl, gegl_major_version.gegl_minor_version.gegl_micro_version)
 
@@ -455,6 +456,14 @@ PKG_CHECK_MODULES(DEP,
 DEP_CFLAGS=`$PKG_CONFIG --cflags $GLIB_PACKAGES gthread-2.0`
 DEP_LIBS=`$PKG_CONFIG --libs $GLIB_PACKAGES gthread-2.0`
 
+
+PKG_CHECK_MODULES(P2TC,
+                  poly2tri-c >= poly2tri-c_required_version, ,
+                  AC_MSG_ERROR([
+        *** Poly2tri-C not found. You can find it on http://code.google.com/p/poly2tri-c/
+        *** Errors follow:
+            $P2TC_PKG_ERRORS]))
+
 ######################
 # gettext i18n support
 ######################
@@ -1092,11 +1101,6 @@ operations/core/Makefile
 operations/common/Makefile
 operations/common/perlin/Makefile
 operations/common/seamless-clone/Makefile
-operations/common/seamless-clone/poly2tri-c/Makefile
-operations/common/seamless-clone/poly2tri-c/common/Makefile
-operations/common/seamless-clone/poly2tri-c/refine/Makefile
-operations/common/seamless-clone/poly2tri-c/render/Makefile
-operations/common/seamless-clone/poly2tri-c/sweep/Makefile
 operations/external/Makefile
 operations/generated/Makefile
 operations/transform/Makefile
diff --git a/gegl.pc.in b/gegl.pc.in
index 614bb78..adf8dc2 100644
--- a/gegl.pc.in
+++ b/gegl.pc.in
@@ -7,6 +7,6 @@ pluginsdir= libdir@/@PACKAGE_NAME -@GEGL_API_VERSION@
 Name: GEGL
 Description: Generic Graphics Library 
 Version: @GEGL_REAL_VERSION@
-Requires: @GLIB_PACKAGES@ babl
+Requires: @GLIB_PACKAGES@ babl poly2tri-c
 Libs: -L${libdir} -l PACKAGE_NAME@- GEGL_API_VERSION@
 Cflags: -I${includedir}/@PACKAGE_NAME -@GEGL_API_VERSION@
diff --git a/operations/common/seamless-clone/Makefile.am b/operations/common/seamless-clone/Makefile.am
index 88df97e..96820b1 100644
--- a/operations/common/seamless-clone/Makefile.am
+++ b/operations/common/seamless-clone/Makefile.am
@@ -1,8 +1,7 @@
-SUBDIRS = poly2tri-c
-
 include $(top_srcdir)/operations/Makefile-common.am
 
-AM_LDFLAGS += $(op_libs) poly2tri-c/libpoly2tri-c.la
+AM_LDFLAGS += $(op_libs) $(P2TC_LIBS)
+AM_CFLAGS  += $(op_cflags) $(P2TC_CFLAGS)
 
 sc_common_files =		\
  	make-mesh.c		\
diff --git a/operations/common/seamless-clone/find-outline.c b/operations/common/seamless-clone/find-outline.c
index dde64f3..cb329da 100644
--- a/operations/common/seamless-clone/find-outline.c
+++ b/operations/common/seamless-clone/find-outline.c
@@ -31,8 +31,8 @@
 #include <stdio.h> /* TODO: get rid of this debugging way! */
 
 #include "seamless-clone.h"
-#include "poly2tri-c/poly2tri.h"
-#include "poly2tri-c/refine/triangulation.h"
+#include <poly2tri-c/p2t/poly2tri.h>
+#include <poly2tri-c/refine/refine.h>
 
 /* Define the directions
  *
diff --git a/operations/common/seamless-clone/make-mesh.c b/operations/common/seamless-clone/make-mesh.c
index acaa99b..15f606f 100644
--- a/operations/common/seamless-clone/make-mesh.c
+++ b/operations/common/seamless-clone/make-mesh.c
@@ -26,9 +26,8 @@
 #include <gegl.h>
 #include <stdio.h> /* TODO: get rid of this debugging way! */
 
-#include "poly2tri-c/poly2tri.h"
-#include "poly2tri-c/refine/triangulation.h"
-#include "poly2tri-c/refine/refine.h"
+#include <poly2tri-c/p2t/poly2tri.h>
+#include <poly2tri-c/refine/refine.h>
 #include "seamless-clone.h"
 
 #define g_ptr_array_index_cyclic(array,index_) g_ptr_array_index(array,(index_)%((array)->len))
@@ -186,28 +185,20 @@ sc_sample_list_free (ScSampleList *self)
 }
 
 ScMeshSampling*
-sc_mesh_sampling_compute (ScOutline         *outline,
-                          P2tRTriangulation *mesh)
+sc_mesh_sampling_compute (ScOutline *outline,
+                          P2trMesh  *mesh)
 {
-  GPtrArray  *points = g_ptr_array_new ();
   GHashTable *pt2sample = g_hash_table_new (g_direct_hash, g_direct_equal);
-  gint i;
-
-  /* Note that the get_points function increases the refcount of the
-   * returned points, so we must unref them when done with them
-   */
-  p2tr_triangulation_get_points (mesh, points);
+  P2trPoint  *pt = NULL;
+  P2trHashSetIter iter;
 
-  for (i = 0; i < points->len; i++)
+  p2tr_hash_set_iter_init (&iter, mesh->points);
+  while (p2tr_hash_set_iter_next (&iter, (gpointer*) &pt))
     {
-	  P2tRPoint    *pt = (P2tRPoint*) g_ptr_array_index (points, i);
-	  ScSampleList *sl = sc_sample_list_compute (outline, pt->x, pt->y);
-	  g_hash_table_insert (pt2sample, pt, sl);
-	}
+      ScSampleList *sl = sc_sample_list_compute (outline, pt->c.x, pt->c.y);
+      g_hash_table_insert (pt2sample, pt, sl);
+    }
 
-  /* We will unref the points when freeing the hash table */
-  g_ptr_array_free (points, TRUE);
-  	
   return pt2sample;
 }
 
@@ -217,7 +208,7 @@ sc_mesh_sampling_entry_free_hfunc (gpointer point,
                                    gpointer unused)
 {
   /* Unref the point returned from triangulation_get_points */
-  p2tr_point_unref ((P2tRPoint*)point);
+  p2tr_point_unref ((P2trPoint*)point);
   /* Free the sampling list */
   sc_sample_list_free ((ScSampleList*)sampling_list);
 }
@@ -236,7 +227,7 @@ sc_mesh_sampling_free (ScMeshSampling *self)
  * @mesh_bounds: A rectangle in which the bounds of the mesh should be
  *               stored
  */
-P2tRTriangulation*
+P2trMesh*
 sc_make_fine_mesh (ScOutline     *outline,
                    GeglRectangle *mesh_bounds,
                    int            max_refine_steps)
@@ -245,10 +236,13 @@ sc_make_fine_mesh (ScOutline     *outline,
   gint i, N = realOutline->len;
   gint min_x = G_MAXINT, max_x = -G_MAXINT, min_y = G_MAXINT, max_y = -G_MAXINT;
 
-  /* An array of P2tRPoint*, holding the outline points */
+  /* An array of P2tPoint*, holding the outline points */
   GPtrArray *mesh_points = g_ptr_array_new ();
 
-  P2tRTriangulation *T;
+  P2tCDT *rough_cdt;
+  P2trCDT *fine_cdt;
+  P2trMesh *result;
+  P2trDelaunayTerminator *refiner;
 
   for (i = 0; i < N; i++)
     {
@@ -261,7 +255,7 @@ sc_make_fine_mesh (ScOutline     *outline,
 
       /* No one should care if the points are given in reverse order,
        * and prepending to the GList is more efficient */
-      g_ptr_array_add (mesh_points, p2tr_point_new (pt->x, pt->y));
+      g_ptr_array_add (mesh_points, p2t_point_new_dd (pt->x, pt->y));
     }
 
   mesh_bounds->x = min_x;
@@ -269,14 +263,26 @@ sc_make_fine_mesh (ScOutline     *outline,
   mesh_bounds->width = max_x + 1 - min_x;
   mesh_bounds->height = max_y + 1 - min_y;
 
-  T = p2tr_triangulate_and_refine (mesh_points, max_refine_steps);
+  rough_cdt = p2t_cdt_new (mesh_points);
+  p2t_cdt_triangulate (rough_cdt);
+  fine_cdt = p2tr_cdt_new (rough_cdt);
+  /* We no longer need the rough CDT */
+  p2t_cdt_free (rough_cdt);
+
+  refiner = p2tr_dt_new (G_PI / 6, p2tr_dt_false_too_big, fine_cdt);
+  p2tr_dt_refine (refiner, max_refine_steps);
+  p2tr_dt_free (refiner);
+
+  p2tr_mesh_ref (result = fine_cdt->mesh);
+
+  p2tr_cdt_free_full (fine_cdt, FALSE);
 
   for (i = 0; i < N; i++)
     {
-      p2tr_point_unref ((P2tRPoint*) g_ptr_array_index (mesh_points, i));
-	}
+      p2t_point_free ((P2tPoint*) g_ptr_array_index (mesh_points, i));
+    }
 
   g_ptr_array_free (mesh_points, TRUE);
 
-  return T;
+  return result;
 }
diff --git a/operations/common/seamless-clone/make-mesh.h b/operations/common/seamless-clone/make-mesh.h
index b242bfa..503c1ff 100644
--- a/operations/common/seamless-clone/make-mesh.h
+++ b/operations/common/seamless-clone/make-mesh.h
@@ -31,10 +31,10 @@ typedef GHashTable ScMeshSampling;
 ScSampleList* sc_sample_list_compute (ScOutline *outline, gdouble Px, gdouble Py);
 void          sc_sample_list_free    (ScSampleList *self);
 
-ScMeshSampling* sc_mesh_sampling_compute (ScOutline *outline, P2tRTriangulation *mesh);
+ScMeshSampling* sc_mesh_sampling_compute (ScOutline *outline, P2trMesh *mesh);
 void            sc_mesh_sampling_free    (ScMeshSampling *self);
 
-P2tRTriangulation* sc_make_fine_mesh (ScOutline *outline, GeglRectangle *mesh_bounds, int max_refine_steps);
+P2trMesh*       sc_make_fine_mesh (ScOutline *outline, GeglRectangle *mesh_bounds, int max_refine_steps);
 
 
 #endif
diff --git a/operations/common/seamless-clone/seamless-clone-common.c b/operations/common/seamless-clone/seamless-clone-common.c
index 9e94efd..0bb8853 100644
--- a/operations/common/seamless-clone/seamless-clone-common.c
+++ b/operations/common/seamless-clone/seamless-clone-common.c
@@ -22,12 +22,12 @@
 #include <gegl-utils.h>
 
 static GeglBuffer*
-sc_compute_UVT_cache (P2tRTriangulation   *mesh,
+sc_compute_UVT_cache (P2trMesh            *mesh,
                       const GeglRectangle *area)
 {
   GeglBuffer         *uvt;
   GeglBufferIterator *iter;
-  P2tRImageConfig     config;
+  P2trImageConfig     config;
 
   uvt = gegl_buffer_new (area, SC_BABL_UVT_FORMAT);
 
@@ -44,7 +44,7 @@ sc_compute_UVT_cache (P2tRTriangulation   *mesh,
       config.x_samples = iter->roi[0].width;
       config.y_samples = iter->roi[0].height;
       p2tr_mesh_render_cache_uvt_exact (mesh,
-                                        (P2tRuvt*) iter->data[0],
+                                        (P2truvt*) iter->data[0],
                                         iter->length,
                                         &config);
     }
@@ -55,7 +55,7 @@ sc_compute_UVT_cache (P2tRTriangulation   *mesh,
 }
 
 static void
-sc_point_to_color_func (P2tRPoint *point,
+sc_point_to_color_func (P2trPoint *point,
                         gfloat    *dest,
                         gpointer   cci_p)
 {
@@ -187,9 +187,9 @@ sc_render_seamless (GeglBuffer          *bg,
 
   while (gegl_buffer_iterator_next (iter))
     {
-      P2tRImageConfig  imcfg;
+      P2trImageConfig  imcfg;
       float           *out_raw, *fg_raw;
-      P2tRuvt         *uvt_raw;
+      P2truvt         *uvt_raw;
       int              x, y;
       
       imcfg.min_x = iter->roi[out_index].x;
@@ -200,7 +200,7 @@ sc_render_seamless (GeglBuffer          *bg,
       imcfg.cpp = 4;
 
       out_raw = (gfloat*)iter->data[out_index];
-      uvt_raw = (P2tRuvt*)iter->data[uvt_index];
+      uvt_raw = (P2truvt*)iter->data[uvt_index];
       fg_raw = (gfloat*)iter->data[fg_index];
 
       p2tr_mesh_render_scanline2 (uvt_raw, out_raw, &imcfg, sc_point_to_color_func, &mesh_render_info);
@@ -255,7 +255,7 @@ sc_cache_free (ScCache *cache)
 {
   g_object_unref (cache->uvt);
   sc_mesh_sampling_free (cache->sampling);
-  p2tr_triangulation_free (cache->mesh);
+  p2tr_mesh_unref (cache->mesh);
   sc_outline_free (cache->outline);
   g_free (cache);
 }
diff --git a/operations/common/seamless-clone/seamless-clone-common.h b/operations/common/seamless-clone/seamless-clone-common.h
index 7982008..fcd653d 100644
--- a/operations/common/seamless-clone/seamless-clone-common.h
+++ b/operations/common/seamless-clone/seamless-clone-common.h
@@ -20,9 +20,9 @@
 #ifndef __SEAMLESS_CLONE_COMMON_H__
 #define __SEAMLESS_CLONE_COMMON_H__
 
-#include "poly2tri-c/poly2tri.h"
-#include "poly2tri-c/refine/triangulation.h"
-#include "poly2tri-c/render/mesh-render.h"
+#include <poly2tri-c/p2t/poly2tri.h>
+#include <poly2tri-c/refine/refine.h>
+#include <poly2tri-c/render/mesh-render.h>
 
 #include "find-outline.h"
 #include "make-mesh.h"
@@ -39,7 +39,7 @@ typedef struct {
 
 typedef struct {
   GeglRectangle      mesh_bounds;
-  P2tRTriangulation *mesh;
+  P2trMesh          *mesh;
   ScMeshSampling    *sampling;
   GeglBuffer        *uvt;
   ScOutline         *outline;
@@ -59,7 +59,7 @@ ScCache*   sc_generate_cache (GeglBuffer          *fg,
 
 void       sc_cache_free     (ScCache *cache);
 
-#define SC_BABL_UVT_TYPE   (babl_type_new ("uvt", "bits", sizeof (P2tRuvt) * 8, NULL))
+#define SC_BABL_UVT_TYPE   (babl_type_new ("uvt", "bits", sizeof (P2truvt) * 8, NULL))
 #define SC_BABL_UVT_FORMAT (babl_format_n (SC_BABL_UVT_TYPE, 3))
 
 #endif
diff --git a/operations/common/seamless-clone/seamless-clone-prepare.c b/operations/common/seamless-clone/seamless-clone-prepare.c
index 9357a66..32bd2ee 100644
--- a/operations/common/seamless-clone/seamless-clone-prepare.c
+++ b/operations/common/seamless-clone/seamless-clone-prepare.c
@@ -39,9 +39,9 @@ gegl_chant_int (max_refine_steps, _("Refinement Steps"), 0, 100000.0, 2000,
 #include <glib/gi18n-lib.h>
 #include "gegl-chant.h"
 
-#include "poly2tri-c/poly2tri.h"
-#include "poly2tri-c/refine/triangulation.h"
-#include "poly2tri-c/render/mesh-render.h"
+#include <poly2tri-c/p2t/poly2tri.h>
+#include <poly2tri-c/refine/refine.h>
+#include <poly2tri-c/render/mesh-render.h>
 #include "seamless-clone-common.h"
 
 static void
diff --git a/operations/common/seamless-clone/seamless-clone-render.c b/operations/common/seamless-clone/seamless-clone-render.c
index e4bd279..2887bd7 100644
--- a/operations/common/seamless-clone/seamless-clone-render.c
+++ b/operations/common/seamless-clone/seamless-clone-render.c
@@ -37,9 +37,9 @@ gegl_chant_pointer (prepare, _("prepare"),
 #include <glib/gi18n-lib.h>
 #include "gegl-chant.h"
 
-#include "poly2tri-c/poly2tri.h"
-#include "poly2tri-c/refine/triangulation.h"
-#include "poly2tri-c/render/mesh-render.h"
+#include <poly2tri-c/p2t/poly2tri.h>
+#include <poly2tri-c/refine/refine.h>
+#include <poly2tri-c/render/mesh-render.h>
 #include "seamless-clone-common.h"
 
 static GeglRectangle
diff --git a/operations/common/seamless-clone/seamless-clone.c b/operations/common/seamless-clone/seamless-clone.c
index 1a9813d..a8cac17 100644
--- a/operations/common/seamless-clone/seamless-clone.c
+++ b/operations/common/seamless-clone/seamless-clone.c
@@ -32,9 +32,9 @@ gegl_chant_int (max_refine_steps, _("Refinement Steps"), 0, 100000.0, 2000,
 
 #include <stdio.h> /* TODO: get rid of this debugging way! */
 
-#include "poly2tri-c/poly2tri.h"
-#include "poly2tri-c/refine/triangulation.h"
-#include "poly2tri-c/render/mesh-render.h"
+#include <poly2tri-c/p2t/poly2tri.h>
+#include <poly2tri-c/refine/refine.h>
+#include <poly2tri-c/render/mesh-render.h>
 #include "seamless-clone-common.h"
 
 static GeglRectangle
diff --git a/operations/common/seamless-clone/seamless-clone.h b/operations/common/seamless-clone/seamless-clone.h
index a4f8e0a..ac4f4dd 100644
--- a/operations/common/seamless-clone/seamless-clone.h
+++ b/operations/common/seamless-clone/seamless-clone.h
@@ -20,15 +20,15 @@
 #ifndef __SEAMLESS_CLONE_H__
 #define __SEAMLESS_CLONE_H__
 
-#include "poly2tri-c/poly2tri.h"
-#include "poly2tri-c/refine/triangulation.h"
+#include <poly2tri-c/p2t/poly2tri.h>
+#include <poly2tri-c/refine/refine.h>
 
 #include "find-outline.h"
 #include "make-mesh.h"
 
 typedef struct {
   ScOutline         *outline;
-  P2tRTriangulation *mesh;
+  P2trMesh          *mesh;
   GeglRectangle      mesh_bounds;
   ScMeshSampling    *sampling;
   GeglBuffer        *uvt;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]