[opengtl-commits] [597] add more kernels to the collection

[ Thread Index | Date Index | More lists.tuxfamily.org/opengtl-commits Archives ]


Revision: 597
Author:   cyrille
Date:     2009-03-12 17:57:55 +0100 (Thu, 12 Mar 2009)

Log Message:
-----------
add more kernels to the collection

Added Paths:
-----------
    trunk/shiva-collections/filters/blur.shiva
    trunk/shiva-collections/filters/oilify.shiva
    trunk/shiva-collections/generators/MandelbrotSet.shiva
    trunk/shiva-collections/generators/PerlinNoise.shiva


Copied: trunk/shiva-collections/filters/blur.shiva (from rev 560, trunk/OpenGTL/OpenShiva/tests/convolution/blur.shiva)
===================================================================
--- trunk/shiva-collections/filters/blur.shiva	                        (rev 0)
+++ trunk/shiva-collections/filters/blur.shiva	2009-03-12 16:57:55 UTC (rev 597)
@@ -0,0 +1,7 @@
+kernel Blur
+{
+  void evaluatePixel(image img, out pixel result)
+  {
+    result = ( img.sampleNearest( result.coord ) + img.sampleNearest( result.coord - 1.0 ) + img.sampleNearest( result.coord + 1.0 ) ) / 3.0;
+  }
+}


Property changes on: trunk/shiva-collections/filters/blur.shiva
___________________________________________________________________
Name: svn:mergeinfo
   + 

Copied: trunk/shiva-collections/filters/oilify.shiva (from rev 560, trunk/OpenGTL/OpenShiva/tests/convolution/oilify.shiva)
===================================================================
--- trunk/shiva-collections/filters/oilify.shiva	                        (rev 0)
+++ trunk/shiva-collections/filters/oilify.shiva	2009-03-12 16:57:55 UTC (rev 597)
@@ -0,0 +1,40 @@
+kernel Oilify
+{
+  int intensity( float4 px )
+  {
+     int v = (0.5 * px[1] + 0.3 * px[2] + 0.2 * px[0]) * 255;
+     if( v < 0 ) return 0;
+     if( v > 255) return 255;
+     return v;
+  }
+  void evaluatePixel(image4 img, out pixel4 result)
+  {
+    int xc = result.coord.x;
+    int yc = result.coord.y;
+    int histogram[256];
+    for(int i = 0; i < 255; ++i)
+    {
+      histogram[i] = 0;
+    }
+    float4 max_px;
+    int max = 0;
+    for( int y = yc - 4; y < yc + 4; ++y)
+    {
+      for( int x = xc - 4; x < xc + 4; ++x)
+       {
+          float4 px = img.sampleNearest( float2(x,y ) );
+          int hv = ++histogram[ intensity( px ) ];
+          if( hv > max )
+          {
+             max_px = px;
+             max = hv;
+          }
+       }
+    }
+    result = max_px;
+  }
+  region changed(region changed_input_region, int input_index, region input_DOD[])
+  {
+    return changed_input_region;
+  }
+}


Property changes on: trunk/shiva-collections/filters/oilify.shiva
___________________________________________________________________
Name: svn:mergeinfo
   + 

Copied: trunk/shiva-collections/generators/MandelbrotSet.shiva (from rev 560, trunk/OpenGTL/OpenShiva/tests/imagegenerators/MandelbrotSet.shiva)
===================================================================
--- trunk/shiva-collections/generators/MandelbrotSet.shiva	                        (rev 0)
+++ trunk/shiva-collections/generators/MandelbrotSet.shiva	2009-03-12 16:57:55 UTC (rev 597)
@@ -0,0 +1,47 @@
+kernel MandelbrotSet
+{
+  void evaluatePixel(out pixel result)
+  {
+    // Parameters
+    float xaxis = 700.0;
+    float yaxis = 500.0;
+    float scale = 1 / 400.0;
+    int max_iteration = 25;
+    // Do it
+    float x = (result.coord[0] - xaxis) * scale;
+    float x0 = x;
+    float y = (result.coord[1] - yaxis) * scale;
+    float y0 = y;
+
+    int iteration = 0;
+    while(  (x*x + y*y) <= (2*2)  and iteration < max_iteration)
+    {
+      float xtemp = x*x - y*y + x0;
+      y = 2*x*y + y0;
+      x = xtemp;
+      ++iteration;
+    }
+    int v = (765 * iteration)/max_iteration;
+    if( iteration == max_iteration)
+    {
+      result[0] = 0.0;
+      result[1] = 0.0;
+      result[2] = 0.0;
+    } if ( v >= 510 )
+    {
+      result[0] = 1.0;
+      result[1] = 1.0;
+      result[2] = (v - 510 ) / 255.0;
+    }
+    else if( v > 255 )
+    {
+      result[0] = 1.0;
+      result[1] = 1.0;
+      result[2] = (v - 255) / 255.0;
+    } else {
+      result[0] = v;
+      result[1] = 0.0;
+      result[2] = 0.0;
+    }
+  }
+}


Property changes on: trunk/shiva-collections/generators/MandelbrotSet.shiva
___________________________________________________________________
Name: svn:mergeinfo
   + 

Copied: trunk/shiva-collections/generators/PerlinNoise.shiva (from rev 591, trunk/OpenGTL/OpenShiva/tests/imagegenerators/PerlinNoise.shiva)
===================================================================
--- trunk/shiva-collections/generators/PerlinNoise.shiva	                        (rev 0)
+++ trunk/shiva-collections/generators/PerlinNoise.shiva	2009-03-12 16:57:55 UTC (rev 597)
@@ -0,0 +1,129 @@
+<
+  parameters: <
+    amount: <
+      label: "Amount";
+      type: float;
+    >;
+    offset: <
+      label: "Offset";
+      type: float;
+    >;
+    factor: <
+      label: "Factor";
+      type: float;
+      defaultValue: 1.0;
+      maxValue: 10.0;
+    >;
+    xscale: <
+      label: "Horizontal scale";
+      type: float;
+      defaultValue: 4.0;
+      maxValue: 100.0;
+    >;
+    yscale: <
+      label: "Vertical scale";
+      type: float;
+      defaultValue: 4.0;
+      maxValue: 100.0;
+    >;
+    octaves: <
+      label: "Octaves";
+      type: int;
+      defaultValue: 2;
+      maxValue:10;
+    >;
+    width: <
+      label: "Image width";
+      type: int;
+      defaultValue: 800;
+      maxValue:10000;
+    >;
+    height: <
+      label: "Image height";
+      type: int;
+      defaultValue: 600;
+      maxValue:10000;
+    >;
+  >;
+>;
+kernel PerlinNoise
+{
+  const int RAND_MAX  = 2147483647;
+
+  dependent float grad_x[64];
+  dependent float grad_y[64];
+  dependent int permutation[64];
+  
+  float fade(float t)
+  {
+    return ((2.0*fabs(t)-3.0)*(t)*(t)+1.0);
+  }
+  
+  // Pregenerate grad_x, grad_y and permuation
+  void evaluateDependents()
+  {
+    // Init permutations
+    for(int i = 0; i < 64; ++i)
+    {
+       permutation[i] = i;
+    }
+    for (int i = 0; i < 1000; ++i) {
+      int j = rand() % 64;
+      int k = rand() % 64;
+      int t = permutation[j];
+      permutation[j] = permutation[k];
+      permutation[k] = t;
+    }
+    // Initialize the gradient table
+    for(int i = 0; i < 64; ++i)
+    {
+      grad_x[i] = rand() / float(RAND_MAX) - 0.5;
+      grad_y[i] = rand() / float(RAND_MAX) - 0.5;
+      float norm = 1.0 / sqrt(grad_x[i] * grad_x[i] + grad_y[i] * grad_y[i]);
+      grad_x[i] *= norm;
+      grad_y[i] *= norm;
+    }
+  }
+  
+  void evaluatePixel(out pixel4 result)
+  {
+    float total = 0.0;
+    int frequency = 1;
+    float x = (result.coord.x ) / float(width);
+    float y = (result.coord.y ) / float(height);
+    x *= xscale;
+    y *= yscale;
+    for(int oct = 0; oct < octaves; ++oct)
+    {
+      float xs = x * frequency;
+      float ys = y * frequency;
+      int xs_frac = int(xs);
+      int ys_frac = int(ys);
+      float intermtotal = 0.0;
+      for(int i = 0; i < 2; ++i)
+      {
+        for(int j = 0; j < 2; ++j)
+        {
+          int n = permutation[(xs_frac + i + permutation[(ys_frac + j) % 64]) % 64];
+          float vx = xs - xs_frac - i;
+          float vy = ys - ys_frac - j;
+          intermtotal += fade(vx) * fade(vy) * (grad_x[n] * vx + grad_y[n] * vy );
+        }
+      }
+      
+      total += intermtotal / frequency;
+      frequency *= 2;
+    }
+    total += offset;
+    total *= factor;
+    if( total > 1.0) total = 1.0;
+    if( total < 0) total = 0;
+    result = float4(total,total,total,1.0);
+  }
+  
+  region generated()
+  {
+    region reg1 = { 0, 0, 800, 600 };
+    return reg1;
+  }
+}


Property changes on: trunk/shiva-collections/generators/PerlinNoise.shiva
___________________________________________________________________
Name: svn:mergeinfo
   + 


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/