[gimp/soc-2010-cage] Beginning of GimpCage data structure, with the computation of the coefficient (test needed)



commit 684c0df9f75529f6b344e8935cdcff4eccc5d8e5
Author: Michael Muré <batolettre gmail com>
Date:   Tue Jul 6 20:12:01 2010 +0200

    Beginning of GimpCage data structure, with the computation of the coefficient (test needed)

 app/core/gimpcage.c |  118 +++++++++++++++++++++++++++++++++++++++++++++++++++
 app/core/gimpcage.h |   23 ++++++----
 2 files changed, 131 insertions(+), 10 deletions(-)
---
diff --git a/app/core/gimpcage.c b/app/core/gimpcage.c
index 57017fd..a9ed17c 100644
--- a/app/core/gimpcage.c
+++ b/app/core/gimpcage.c
@@ -20,8 +20,15 @@
 #include "gimpcage.h"
 
 #include "core-types.h"
+#include "libgimpmath/gimpvector.h"
+#include <math.h>
+#include <gegl-buffer-iterator.h>
 
 
+G_DEFINE_TYPE (GimpCage, gimp_cage, G_TYPE_OBJECT)
+
+static void       gimp_cage_compute_coefficient (GimpCage *gc);
+
 static void
 gimp_cage_class_init (GimpCageClass *klass)
 {
@@ -31,5 +38,116 @@ gimp_cage_class_init (GimpCageClass *klass)
 static void
 gimp_cage_init (GimpCage *self)
 {
+  //Test Data
+  self->cage_vertice_number = 4;
+  self->cage_vertices = g_new(GimpVector2, self->cage_vertice_number);
+  self->cage_vertices_max = self->cage_vertice_number;
+
+  self->cage_vertices[0].x = 20;
+  self->cage_vertices[0].y = 20;
+  self->cage_vertices[1].x = 20;
+  self->cage_vertices[1].y = 100;
+  self->cage_vertices[2].x = 100;
+  self->cage_vertices[2].y = 100;
+  self->cage_vertices[3].x = 100;
+  self->cage_vertices[3].y = 20;
+  
+  self->extent.x = 20;
+  self->extent.y = 20;
+  self->extent.height = 80;
+  self->extent.width = 80;
+  
+  self->cage_vertices_coef = NULL;
+  self->cage_edges_coef = NULL;
+  
+  gimp_cage_compute_coefficient (self);
+}
+
+static void
+gimp_cage_compute_coefficient (GimpCage *gc)
+{
+  Babl *format;
+  GeglBufferIterator *i;
+  gint edge, vertice,j;
+  
+  g_return_if_fail (GIMP_IS_CAGE (gc));
+  
+  format = babl_format_n(babl_type("float"), gc->cage_vertice_number);
 
+  
+  if(gc->cage_vertices_coef != NULL)
+  {
+    gegl_buffer_destroy(gc->cage_vertices_coef);
+  }
+  
+  if(gc->cage_edges_coef != NULL)
+  {
+    gegl_buffer_destroy(gc->cage_edges_coef);
+  }
+  
+  gc->cage_vertices_coef = gegl_buffer_new(&gc->extent, format);
+  gc->cage_edges_coef = gegl_buffer_new(&gc->extent, format);
+  
+  gegl_buffer_clear(gc->cage_vertices_coef, &gc->extent);
+  gegl_buffer_clear(gc->cage_edges_coef, &gc->extent);
+  
+  i = gegl_buffer_iterator_new (gc->cage_vertices_coef, &gc->extent, format, GEGL_BUFFER_WRITE);
+  edge = gegl_buffer_iterator_add (i, gc->cage_edges_coef, &gc->extent, format, GEGL_BUFFER_WRITE);
+  vertice = 0;
+  
+  //iterate on GeglBuffer
+  while (gegl_buffer_iterator_next (i))
+  {
+    //iterate inside the roi
+    gint        n_pixels = i->length;
+    gfloat     *vertice_coef = i->data[vertice];
+    gfloat     *edge_coef = i->data[edge];
+    gint        x = i->roi->x; /* initial x                   */
+    gint        y = i->roi->y; /*           and y coordinates */
+    
+    while(n_pixels--)
+    {
+      for( j = 0; j < gc->cage_vertice_number; j++)
+      {
+        GimpVector2 v1,v2,a,b;
+        gfloat Q,S,R,BA,SRT,L0,L1,A0,A1,A10,L10;
+      
+        v1 = gc->cage_vertices[j];
+        v2 = gc->cage_vertices[(j+1)%gc->cage_vertice_number];
+      
+        a.x = v2.x - v1.x;
+        a.y = v2.y - v1.y;
+        b.x = v1.x - x;
+        b.y = v1.y - y;
+        Q = a.x * a.x + a.y * a.y;
+        S = b.x * b.x + b.y * b.y;
+        BA = b.x * a.y - b.y * a.x;
+        SRT = sqrt(4.0 * S * Q - R * R);
+        L0 = log(S);
+        L1 = log(S + Q + R);
+        A0 = atan2(R, SRT) / SRT;
+        A1 = atan2(2.0 * Q + R, SRT) / SRT;
+        A10 = A1 - A0;
+        L10 = L1 - L0;
+        
+        edge_coef[j] = 1.0 / (4.0 * M_PI) * ((4.0*S-R*R/Q) * A10 + R / (2.0 * Q) * L10 + L1 - 2.0);
+        
+        vertice_coef[j] += BA / (2.0 * M_PI) * (L10 /(2.0*Q) - A10 * (2.0 + R / Q));
+        vertice_coef[(j+1)%gc->cage_vertice_number] -= BA / (2.0 * M_PI) * (L10 / (2.0 * Q) - A10 * R / Q);
+        
+        vertice_coef += gc->cage_vertice_number;
+        edge_coef += gc->cage_vertice_number;
+      }
+      
+      /* update x and y coordinates */
+      x++;
+      if (x >= (i->roi->x + i->roi->width))
+      {
+        x = i->roi->x;
+        y++;
+      }
+      
+    }
+  }
+  
 }
diff --git a/app/core/gimpcage.h b/app/core/gimpcage.h
index 0221af3..c43fa8d 100644
--- a/app/core/gimpcage.h
+++ b/app/core/gimpcage.h
@@ -21,6 +21,10 @@
 #define __GIMP_CAGE_H__
 
 #include <glib-object.h>
+#include "libgimpmath/gimpmathtypes.h"
+#include <gegl.h>
+#include <gegl-buffer.h>
+
 
 #define GIMP_TYPE_CAGE            (gimp_cage_get_type ())
 #define GIMP_CAGE(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_CAGE, GimpCage))
@@ -34,18 +38,17 @@ typedef struct _GimpCageClass GimpCageClass;
 
 struct _GimpCage
 {
-  GObject    parent_instance;
+  GObject         parent_instance;
   
-  gint            cageVerticeNumber;
-  gfloat         *cageVerticeX;
-  gfloat         *cageVerticeY;
+  gint            cage_vertice_number; //number of vertices used by the cage
+  gint            cage_vertices_max; //number of vertices allocated in memory
+  GimpVector2    *cage_vertices;
   
-  gint            pointNumber;
-  gfloat        **CoordsVerticeX;
-  gfloat        **CoordsVerticeY;
-  gfloat        **CoordsEdgeX;
-  gfloat        **CoordsEdgeY;
-
+  GeglBuffer     *cage_vertices_coef;
+  GeglBuffer     *cage_edges_coef;
+  
+  //test data
+  GeglRectangle   extent;
 };
 
 



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