[opengtl-commits] [689] make use of hints

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


Revision: 689
Author:   cyrille
Date:     2009-03-26 11:12:19 +0100 (Thu, 26 Mar 2009)

Log Message:
-----------
make use of hints

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


Modified: trunk/shiva-collections/filters/StereographicProjection.shiva
===================================================================
--- trunk/shiva-collections/filters/StereographicProjection.shiva	2009-03-26 10:04:30 UTC (rev 688)
+++ trunk/shiva-collections/filters/StereographicProjection.shiva	2009-03-26 10:12:19 UTC (rev 689)
@@ -1,4 +1,4 @@
-// Inspired from frank reitberger (http://www.prinzipiell.com)
+// Inspired from http://www.gimptalk.com/forum/topic/Mathmap-Codes-17481-2.html
 <
   parameters: <
     xcenter: <
@@ -27,7 +27,7 @@
       type: float;
       minValue: 0;
       maxValue: 5;
-      defaultValue: 2.3;
+      defaultValue: 1;
     >;
     radius: <
       label: "Radius";
@@ -40,7 +40,7 @@
       label: "Turn";
       type: float;
       minValue: 0;
-      maxValue: 4;
+      maxValue: 1;
       defaultValue: 1;
     >;
     warp: <
@@ -50,17 +50,20 @@
       maxValue: 3.14159265;
       defaultValue: 2.3;
     >;
+    background: <
+      label: "Background";
+      type: rgba;
+      defaultValue: {0.5,0.5,0.5,1.0};
+    >;
   >;
 >;  
 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 float2 center = { IMAGE_WIDTH * xcenter, IMAGE_HEIGHT * ycenter };
+  const float2 xy0 = { center.x - IMAGE_WIDTH, -center.y + IMAGE_HEIGHT };
+  const float2 xy_replication = {IMAGE_WIDTH * 0.5, IMAGE_HEIGHT * 0.5};
   const float PI = 3.14159265;
-  const float PI2 = PI * PI * 2;
+  const float PI2 = 2 * PI;
   float length( float2 v)
   {
     v *= v;
@@ -68,25 +71,48 @@
   }
   void evaluatePixel(image img, out pixel result)
   {
+// filter StereoNdeG (image in, float turn: 0-1 (0.00), float zoom: 0-5 
+// (1.00), float sc: 0-4 (1), float warp: 0-3.141592, color back) 
+// 
+// // // zeta=-sin(warp)*1+cos(warp); 
+// // // rho=sc*r; 
+// // radius=Y*zoom; 
+// // if r>radius then 
+// // back; 
+// // else 
+// // maxpi=2*atan(sc); 
+// // colat=2*atan(rho/radius); 
+// // long=(a+2*pi*turn)%(2*pi);
+// ny=((Y)*(2*colat/maxpi)-(Y)); 
+// nx=(X-1)*long/pi-X; 
+// in(xy:[nx,ny*zeta]); 
+// end 
+// end
     // 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;
+    // Compute radius
+    float radius = xy_replication.y * zoom;
+    float zeta     = -sin( warp ) + cos( warp ); 
+    if( r > radius / fabs(zeta) )
+//     if( r > 0.5 * radius )
+    {
+      result = background;
+    } else {
+      // Spectral radius
+      float rho = scale * r;
+      // Damping
+      float maxpi    = 2.0 * atan( scale );
+      float colat    = 2.0 * atan( rho / radius );
+      float meridian     = fmod(theta + PI2 * turn, PI2);
+      // Adjust coordinates
+      float ny = (  xy_replication.y ) * ( 2.0 * colat / maxpi ) - (  xy_replication.y );
+      float nx = (  xy_replication.x - 1.0 )* meridian / PI - (  xy_replication.x );
+      float2 pos = center + float2(nx, ny * zeta );
+      result = img.sampleNearest( pos );
+    }
+      result[3] = 1.0;
   }
   region changed(region changed_input_region, int input_index, region input_DOD[])
   {


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