[opengtl-commits] [685] add a stereographic projection filter

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


Revision: 685
Author:   cyrille
Date:     2009-03-25 17:26:19 +0100 (Wed, 25 Mar 2009)

Log Message:
-----------
add a stereographic projection filter

Added Paths:
-----------
    trunk/shiva-collections/filters/StereographicProjection.shiva


Added: trunk/shiva-collections/filters/StereographicProjection.shiva
===================================================================
--- trunk/shiva-collections/filters/StereographicProjection.shiva	                        (rev 0)
+++ trunk/shiva-collections/filters/StereographicProjection.shiva	2009-03-25 16:26:19 UTC (rev 685)
@@ -0,0 +1,96 @@
+// Inspired from frank reitberger (http://www.prinzipiell.com)
+<
+  parameters: <
+    xcenter: <
+      label: "X center";
+      type: float;
+      minValue: 0;
+      maxValue: 1;
+      defaultValue: 0.5;
+    >;
+    ycenter: <
+      label: "Y center";
+      type: float;
+      minValue: 0;
+      maxValue: 1;
+      defaultValue: 0.5;
+    >;
+    zoom: <
+      label: "Zoom";
+      type: float;
+      minValue: 0;
+      maxValue: 5;
+      defaultValue: 1;
+    >;
+    scale: <
+      label: "Scale";
+      type: float;
+      minValue: 0;
+      maxValue: 5;
+      defaultValue: 2.3;
+    >;
+    radius: <
+      label: "Radius";
+      type: float;
+      minValue: 0;
+      maxValue: 100;
+      defaultValue: 70;
+    >;
+    turn: <
+      label: "Turn";
+      type: float;
+      minValue: 0;
+      maxValue: 4;
+      defaultValue: 1;
+    >;
+    warp: <
+      label: "Warp";
+      type: float;
+      minValue: 0;
+      maxValue: 3.14159265;
+      defaultValue: 2.3;
+    >;
+  >;
+>;  
+kernel StereographicProjection
+{  
+  const float width = 1000.0;
+  const float height = 753.0;
+  const float2 center = { width * xcenter, height * ycenter };
+  const float2 xy0 = { center.x - width, -center.y + height };
+  const float2 xy_replication = {28.0, 28.0};
+  const float PI = 3.14159265;
+  const float PI2 = PI * PI * 2;
+  float length( float2 v)
+  {
+    v *= v;
+    return sqrt( v[0] + v[1] );
+  }
+  void evaluatePixel(image img, out pixel result)
+  {
+    // Comput polar coordinate
+    float2 pos = result.coord - center;
+    float r = length( pos );
+    float theta = atan2( pos.y, pos.x );
+    // Spectral radius
+    float spectral = scale * r;
+    // Damping
+    float damp     = -sin( warp ) + cos( warp ); 
+    float rad      = xy_replication.y * zoom;
+    float maxpi    = 2.0 * atan( scale );
+    float edgewise = 2.0 * atan( spectral / rad );
+    float meridian = theta + PI2 * turn;
+    // Adjust coordinates
+    float ny = (  xy_replication.y ) * ( 2.0 * edgewise / maxpi ) - (  xy_replication.y );
+    float nx = (  xy_replication.x - 1.0 )* meridian / PI - (  xy_replication.x );
+    float vx = radius * cos( nx );
+    float vy = radius * sin( ny  );
+    result = img.sampleNearest( center + float2(vx, vy * damp ) );
+    result[3] = 1.0;
+  }
+  region changed(region changed_input_region, int input_index, region input_DOD[])
+  {
+    return changed_input_region;
+  }
+}
+ 
\ No newline at end of file


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