/[opencvs]/eyes/gpu/build_grey.c
ViewVC logotype

Contents of /eyes/gpu/build_grey.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations)
Sun Feb 10 01:01:35 2013 UTC (5 years, 9 months ago) by hib
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +7 -0 lines
File MIME type: text/plain
It works, and it is hella fast.
for 1024x1024 it takes 2 1/2 minutes without attenuation, 2 with attenuation
1
2
3 /*
4 This builds 256 shades of grey - the proper way
5 Well, proper to make it look good to a human being, anyways.
6 572e-9 - red
7 544e-9 - green
8 430e-9 - blue
9
10 */
11
12 #include <stdio.h>
13 #include <math.h>
14 #include <stdlib.h>
15 #include "holo_complex.h"
16
17 /*
18 computer_generated_hologram_c V1.0
19
20 Copyright (C) 2011 Hibbard M. Engler
21
22 This program is free software: you can redistribute it and/or modify
23 it under the terms of the GNU General Public License as published by
24 the Free Software Foundation, either version 3 of the License, or
25 (at your option) any later version.
26
27 This program is distributed in the hope that it will be useful,
28 but WITHOUT ANY WARRANTY; without even the implied warranty of
29 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 GNU General Public License for more details.
31
32 You should have received a copy of the GNU General Public License
33 along with this program. If not, see <http://www.gnu.org/licenses/>.
34
35 */
36
37
38
39
40
41
42 int fieldi(char *x,int fieldnum) {
43 while (fieldnum && *x) {
44 if ((*x == '|')||(*x == ' ')) fieldnum--;
45 x++;
46 }
47 return atoi(x);
48 }
49
50
51 real fieldd(char *x,int fieldnum) {
52 while (fieldnum && *x) {
53 if ((*x == '|')||(*x == ' ')) fieldnum--;
54 x++;
55 }
56 return atof(x);
57 }
58
59
60
61 int main (int argc,char *argv[]) {
62
63 /*
64 source random_seed x size y size x dpi y dpi fromx tox+1 fromy toy+1 r g b
65
66 And then the source has
67
68 x(pix), y(pix) z(meters),amp,wavelength(m),phase(m)
69
70 1000 points of light!
71
72 100 1 meter
73 100 2
74 100 3
75 100 4
76 100 5
77 100 6
78 100 7
79 100 8
80 100 9
81 100 10
82 Fuck!
83 */
84 char *fname;
85 int random_seed;
86 int xsize;
87 int ysize;
88 real xdpi;
89 real ydpi;
90 int fromx;
91 int tox;
92 int fromy;
93 int toy;
94 fname=argv[1];
95 random_seed=atoi(argv[2]);
96 xsize = atoi(argv[3]);
97 ysize = atoi(argv[4]);
98 xdpi = atof(argv[5]);
99 ydpi = atof(argv[6]);
100 fromx = atoi(argv[7]);
101 tox = atoi(argv[8]);
102 fromy = atoi(argv[9]);
103 toy = atoi(argv[10]);
104
105 int yspan;
106 int xspan;
107 yspan = toy-fromy;
108 xspan = tox-fromx;
109
110 real x_sampling_rate;
111 real y_sampling_rate;
112
113 x_sampling_rate = 1.0/(xdpi) * 0.0254;
114 y_sampling_rate = 1.0/(ydpi) * 0.0254; /* rates are in meters */
115
116
117 real *elements;
118 elements=calloc(sizeof(real),yspan*xspan);
119
120 point_source_array psax;
121 point_source_array *psa = &(psax);
122 psa->point_sources = NULL;
123 psa_clear_point_source_array(psa);
124
125 {
126 FILE *xf;
127 xf=fopen(fname,"r");
128 char buf[10000];
129 while (fgets(buf,9999,xf)) {
130 real x,y,z,amp,wl,pha;
131 x=fieldd(buf,0);
132 y=fieldd(buf,1);
133 z=fieldd(buf,2);
134 amp=fieldd(buf,3);
135 wl=fieldd(buf,4);
136 pha = fieldd(buf,5);
137 point_source ps;
138 x = x / xdpi * 0.0254; /* convert form pixel to meter */
139 y = y / ydpi * 0.0254; /* convert form pixel to meter */
140 ps = point_source_init_xyz_amp_lamda_phase(x,y,z,amp,wl,pha);
141 psa_add_point_source(psa,ps);
142 }
143 fclose(xf);
144 }
145
146 int attenuate=0; /* 1 for attenuation */
147
148 /* compute the area */
149 int i;
150 int y;
151 int x;
152 real z=0.0;
153 for (y=fromy;y<toy;y++) {
154 real yy = ((real)(y))*y_sampling_rate;
155 for (x=fromx;x<tox;x++) {
156 real v;
157 real xx = ((real)(x))*x_sampling_rate;
158
159 /* get the phase and amplituyde - could be done once yo */
160 point3d n;
161 n.x = xx;
162 n.y = yy;
163 n.z = z;
164 elements[(y-fromy)*xspan+(x-fromx)] =apply_point_sources(psa,0.,n,attenuate);
165 }
166 }
167
168 /*{int i;
169 for (i=0;i<xspan;i++) {
170 printf("%d %lf\n",i,elements[i]);
171 }
172 }*/
173
174
175 holo_output_vary_grey_background(elements,xspan,yspan);
176
177 exit(0);
178 }
179
180

  ViewVC Help
Powered by ViewVC 1.1.5