OSDN Git Service

dd263700aada4224d8fac6a37f8aa0bbf2202bab
[psychlops/silverlight.git] / dev3 / psychlops / extention / standard / figures.cs
1 \r
2 using System.Windows.Media.Imaging;\r
3 namespace Psychlops\r
4 {\r
5 \r
6     public static class Figures\r
7     {\r
8 \r
9                 public static void drawGrating(double wavelength, double contrast, double orientation, double phase)\r
10                 {\r
11                         double freq = 2 * Math.PI / wavelength;\r
12                         Canvas.default_buffer.ForEach(\r
13                                 (x, y) => new Color(.5 + .5 * Math.sin(phase + (Math.sin(orientation) * x - Math.cos(orientation) * y) * freq))\r
14                         );\r
15                 }\r
16 \r
17                 public static void drawGrating(ref Image img, int width, int height, double wavelength, double contrast, double orientation, double phase)\r
18             {\r
19                         double width_half = width / 2.0, height_half = height / 2.0;\r
20             if (img==null || img.width != width || img.height != height)\r
21                 img = new Image(width, height);\r
22             double freq = 2 * Math.PI / wavelength;\r
23                         img.field(\r
24                                 (x, y) => new Color(.5 +.5 * Math.sin(phase + (Math.sin(orientation)*x-Math.cos(orientation)*y) * freq))\r
25                         );\r
26             }\r
27                 public static void drawGaussian(ref Image img, double sigma, double factor)\r
28                 {\r
29                         int width = (int)(sigma * 8), height = (int)(sigma * 8);\r
30                         double width_half = width / 2.0, height_half = height / 2.0;\r
31                         if (img == null || img.width != width || img.height != height)\r
32                                 img = new Image(width, height);\r
33                         img.field(\r
34                                 (x, y) => new Color(factor * Math.gaussian(Math.radius(x - width_half, y - height_half), width / 8.0))\r
35                         );\r
36                 }\r
37 \r
38                 public static void drawGabor(ref Image img, double sigma, double wavelength, double contrast, double orientation, double phase)\r
39             {\r
40             int width = (int)(sigma * 8), height = (int)(sigma * 8);\r
41                         double width_half = width / 2.0, height_half = height / 2.0;\r
42             if (img==null || img.width != width || img.height != height)\r
43                 img = new Image(width, height);\r
44             double freq = 2 * Math.PI / wavelength;\r
45                         img.field(\r
46                                 (x, y) => new Color(.5 + Math.gaussian(Math.radius(x - width_half, y - height_half), width / 8.0) * .5 * Math.sin(phase + (Math.sin(orientation)*x-Math.cos(orientation)*y) * freq))\r
47                         );\r
48             }\r
49 \r
50     }\r
51 }\r