[gegl/soc-2011-seamless-clone: 18/23] Make the refinement limitation a function argument



commit b67145880d383034768fc099e80d627e1411a935
Author: Barak Itkin <lightningismyname gmail com>
Date:   Sat Mar 24 17:35:56 2012 +0200

    Make the refinement limitation a function argument
    
    Instead of using the environment variable p2t_refine_steps, the limit is
    now a parameter to all the functions, and is also a parameter of the
    gegl operation itself. It won't crash now if the environment variable is
    missing (that was the state previously).

 operations/common/seamless-clone/make-mesh.c       |    5 +++--
 operations/common/seamless-clone/make-mesh.h       |    2 +-
 operations/common/seamless-clone/poly2tri-c/main.c |    2 +-
 .../seamless-clone/poly2tri-c/refine/refine.c      |   19 +++++++++++--------
 .../seamless-clone/poly2tri-c/refine/refine.h      |    2 +-
 .../common/seamless-clone/seamless-clone-prepare.c |    4 +++-
 operations/common/seamless-clone/seamless-clone.c  |    8 ++++++--
 7 files changed, 26 insertions(+), 16 deletions(-)
---
diff --git a/operations/common/seamless-clone/make-mesh.c b/operations/common/seamless-clone/make-mesh.c
index 736016b..acaa99b 100644
--- a/operations/common/seamless-clone/make-mesh.c
+++ b/operations/common/seamless-clone/make-mesh.c
@@ -238,7 +238,8 @@ sc_mesh_sampling_free (ScMeshSampling *self)
  */
 P2tRTriangulation*
 sc_make_fine_mesh (ScOutline     *outline,
-                   GeglRectangle *mesh_bounds)
+                   GeglRectangle *mesh_bounds,
+                   int            max_refine_steps)
 {
   GPtrArray *realOutline = (GPtrArray*) outline;
   gint i, N = realOutline->len;
@@ -268,7 +269,7 @@ 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);
+  T = p2tr_triangulate_and_refine (mesh_points, max_refine_steps);
 
   for (i = 0; i < N; i++)
     {
diff --git a/operations/common/seamless-clone/make-mesh.h b/operations/common/seamless-clone/make-mesh.h
index bc0427f..b242bfa 100644
--- a/operations/common/seamless-clone/make-mesh.h
+++ b/operations/common/seamless-clone/make-mesh.h
@@ -34,7 +34,7 @@ void          sc_sample_list_free    (ScSampleList *self);
 ScMeshSampling* sc_mesh_sampling_compute (ScOutline *outline, P2tRTriangulation *mesh);
 void            sc_mesh_sampling_free    (ScMeshSampling *self);
 
-P2tRTriangulation* sc_make_fine_mesh (ScOutline *outline, GeglRectangle *mesh_bounds);
+P2tRTriangulation* sc_make_fine_mesh (ScOutline *outline, GeglRectangle *mesh_bounds, int max_refine_steps);
 
 
 #endif
diff --git a/operations/common/seamless-clone/poly2tri-c/main.c b/operations/common/seamless-clone/poly2tri-c/main.c
index dc786a2..e3f6c73 100755
--- a/operations/common/seamless-clone/poly2tri-c/main.c
+++ b/operations/common/seamless-clone/poly2tri-c/main.c
@@ -217,7 +217,7 @@ gint main (int argc, char *argv[])
 
   read_points_file (input_file, &pts, &colors);
 
-  T = p2tr_triangulate_and_refine (pts);
+  T = p2tr_triangulate_and_refine (pts, refine_max_steps);
 
   p2tr_plot_svg (T,out);
 
diff --git a/operations/common/seamless-clone/poly2tri-c/refine/refine.c b/operations/common/seamless-clone/poly2tri-c/refine/refine.c
index b4d991a..df99d6a 100755
--- a/operations/common/seamless-clone/poly2tri-c/refine/refine.c
+++ b/operations/common/seamless-clone/poly2tri-c/refine/refine.c
@@ -501,16 +501,21 @@ SplitPermitted (P2tREdge *s, gdouble d)
 #define MIN_MAX_EDGE_LEN 0
 
 void
-DelaunayTerminator (P2tRTriangulation *T, GList *XEs, gdouble theta, deltafunc delta)
+DelaunayTerminator (P2tRTriangulation *T,
+                    GList             *XEs,
+                    gdouble            theta,
+                    deltafunc          delta,
+                    int                max_refine_steps)
 {
-  const gint STEPS = atoi (g_getenv ("p2t_refine_steps"));
-
+  const gint STEPS = max_refine_steps;
   GSequence *Qt;
   GQueue Qs;
 
   GList *Liter, Liter2;
   P2trHashSetIter Hiter;
 
+  p2tr_debug("Max refine point count is %d\n", max_refine_steps);
+  
   p2tr_validate_triangulation (T);
 
   P2tRTriangle *t;
@@ -518,8 +523,6 @@ DelaunayTerminator (P2tRTriangulation *T, GList *XEs, gdouble theta, deltafunc d
   g_queue_init (&Qs);
   Qt = g_sequence_new (NULL);
 
-  p2tr_debug ("Now we have %d triangles\n", g_hash_table_size (T->tris));
-
   if (STEPS == 0)
     return;
   
@@ -674,7 +677,7 @@ DelaunayTerminator (P2tRTriangulation *T, GList *XEs, gdouble theta, deltafunc d
  * Input must be a GPtrArray of P2tRPoint*
  */
 P2tRTriangulation*
-p2tr_triangulate_and_refine (GPtrArray *pts)
+p2tr_triangulate_and_refine (GPtrArray *pts, int max_refine_steps)
 {
   gint i, N = pts->len;
   GList *XEs = NULL, *iter;
@@ -689,7 +692,7 @@ p2tr_triangulate_and_refine (GPtrArray *pts)
     }
 
   T = p2tr_triangulateA ((P2tRPoint**)pts->pdata ,pts->len);
-  DelaunayTerminator (T,XEs,M_PI/6,p2tr_false_delta);
+  DelaunayTerminator (T,XEs,M_PI/6,p2tr_false_delta, max_refine_steps);
 
   foreach (iter, XEs)
   {
@@ -700,4 +703,4 @@ p2tr_triangulate_and_refine (GPtrArray *pts)
   g_list_free (XEs);
 
   return T;
-}
\ No newline at end of file
+}
diff --git a/operations/common/seamless-clone/poly2tri-c/refine/refine.h b/operations/common/seamless-clone/poly2tri-c/refine/refine.h
index 91fe871..8c95493 100755
--- a/operations/common/seamless-clone/poly2tri-c/refine/refine.h
+++ b/operations/common/seamless-clone/poly2tri-c/refine/refine.h
@@ -17,7 +17,7 @@ extern "C"
 #endif
 
 P2tRTriangulation*
-p2tr_triangulate_and_refine (GPtrArray *pts);
+p2tr_triangulate_and_refine (GPtrArray *pts, int max_refine_steps);
 
 
 
diff --git a/operations/common/seamless-clone/seamless-clone-prepare.c b/operations/common/seamless-clone/seamless-clone-prepare.c
index a30783c..2d5ff89 100644
--- a/operations/common/seamless-clone/seamless-clone-prepare.c
+++ b/operations/common/seamless-clone/seamless-clone-prepare.c
@@ -28,6 +28,8 @@
 #ifdef GEGL_CHANT_PROPERTIES
 gegl_chant_pointer (result, _("result"),
   _("A pointer to a pointer (gpointer*) to store the result in"))
+gegl_chant_int (max_refine_steps, _("Refinement Steps"), 0, 100000.0, 2000,
+                _("Maximal amount of refinement points to be used for the interpolation mesh"))
 #else
 
 #define GEGL_CHANT_TYPE_SINK
@@ -78,7 +80,7 @@ process (GeglOperation       *operation,
   result->outline = sc_outline_find_ccw (roi, input);
 
   /* Then, Generate the mesh */
-  result->mesh = sc_make_fine_mesh (result->outline, &result->mesh_bounds);
+  result->mesh = sc_make_fine_mesh (result->outline, &result->mesh_bounds, GEGL_CHANT_PROPERTIES (operation) -> max_refine_steps);
 
   /* Finally, Generate the mesh sample list for each point */
   result->sampling = sc_mesh_sampling_compute (result->outline, result->mesh);
diff --git a/operations/common/seamless-clone/seamless-clone.c b/operations/common/seamless-clone/seamless-clone.c
index 903411a..23b7fa7 100644
--- a/operations/common/seamless-clone/seamless-clone.c
+++ b/operations/common/seamless-clone/seamless-clone.c
@@ -18,6 +18,9 @@
  */
 
 #ifdef GEGL_CHANT_PROPERTIES
+gegl_chant_int (max_refine_steps, _("Refinement Steps"), 0, 100000.0, 2000,
+                _("Maximal amount of refinement points to be used for the interpolation mesh"))
+
 #else
 
 #define GEGL_CHANT_TYPE_COMPOSER
@@ -155,6 +158,7 @@ process (GeglOperation       *operation,
   P2tRImageConfig     imcfg;
 
   Babl               *format = babl_format("R'G'B'A float");
+  int                 max_refine_steps = GEGL_CHANT_PROPERTIES (operation)->max_refine_steps;
 
   g_debug ("seamless-clone.c::process");
   printf ("The aux_rect is: ");
@@ -170,8 +174,8 @@ process (GeglOperation       *operation,
   g_debug ("Finish making outline");
 
   /* Then, Generate the mesh */
-  g_debug ("Start making fine mesh");
-  mesh = sc_make_fine_mesh (outline, &mesh_bounds);
+  g_debug ("Start making fine mesh with at most %d points", max_refine_steps);
+  mesh = sc_make_fine_mesh (outline, &mesh_bounds, max_refine_steps);
   g_debug ("Finish making fine mesh");
 
   /* Finally, Generate the mesh sample list for each point */



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