[opengtl-commits] [230] add a few examples/tests for OpenShiva

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


Revision: 230
Author:   cyrille
Date:     2008-06-24 21:37:40 +0200 (Tue, 24 Jun 2008)

Log Message:
-----------
add a few examples/tests for OpenShiva

Added Paths:
-----------
    trunk/OpenGTL/OpenShiva/tests/convolution/
    trunk/OpenGTL/OpenShiva/tests/convolution/blur.shiva
    trunk/OpenGTL/OpenShiva/tests/imagegenerators/Gradient.shiva
    trunk/OpenGTL/OpenShiva/tests/imagegenerators/MandelbrotSet.shiva


Added: trunk/OpenGTL/OpenShiva/tests/convolution/blur.shiva
===================================================================
--- trunk/OpenGTL/OpenShiva/tests/convolution/blur.shiva	                        (rev 0)
+++ trunk/OpenGTL/OpenShiva/tests/convolution/blur.shiva	2008-06-24 19:37:40 UTC (rev 230)
@@ -0,0 +1,8 @@
+kernel Blur
+{
+  void evaluatePixel(image img, out pixel result)
+  {
+//    result = ( img.sampleNearest( result.x - 1, result.y) + img.sampleNearest( result.x, result.y )
+//              + img.sampleNearest( result.x + 1, result.y) ) / 3;
+  }
+}

Added: trunk/OpenGTL/OpenShiva/tests/imagegenerators/Gradient.shiva
===================================================================
--- trunk/OpenGTL/OpenShiva/tests/imagegenerators/Gradient.shiva	                        (rev 0)
+++ trunk/OpenGTL/OpenShiva/tests/imagegenerators/Gradient.shiva	2008-06-24 19:37:40 UTC (rev 230)
@@ -0,0 +1,7 @@
+kernel Gradient
+{
+  void evaluatePixel(out pixel result)
+  {
+    result[0] = 0.5*( result.x / 200 + result.y / 300 );
+  }
+}

Added: trunk/OpenGTL/OpenShiva/tests/imagegenerators/MandelbrotSet.shiva
===================================================================
--- trunk/OpenGTL/OpenShiva/tests/imagegenerators/MandelbrotSet.shiva	                        (rev 0)
+++ trunk/OpenGTL/OpenShiva/tests/imagegenerators/MandelbrotSet.shiva	2008-06-24 19:37:40 UTC (rev 230)
@@ -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.x - xaxis) * scale;
+    float x0 = x;
+    float y = (result.y - 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;
+    }
+  }
+}


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