/[opencvs]/eyes/build_double.c
ViewVC logotype

Contents of /eyes/build_double.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations)
Mon Oct 6 06:39:39 2014 UTC (3 years, 6 months ago) by hib
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +0 -1 lines
File MIME type: text/plain
Doing cleanup from burner eyes
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 real fromx;
91 real tox;
92 real fromy;
93 real toy;
94 int attenuate=0; /* 1 for attenuation */
95 float nyquest;
96 if (argc != 13) {
97 fprintf(stderr,"Usage:\n"
98 "build_double points.txt random_seed xsize ysize xdpi ydpi fromx tox fromy toy attenuate nyquest\n"
99 "Where\n"
100 " fname - filename with the format x|y|zm|amp|wl|pha\n"
101 " x,y - x and y in pixels\n"
102 " zm - z height in meters\n"
103 " amp - relative amplitude of source\n"
104 " wl wavelength of the light usually 5.32e-07 for green\n"
105 " pha - initial phase of point\n"
106 " xsize - size of the entire piece at the end\n"
107 " ysize - size of the entire piece at the end\n"
108 " xdpi - dots per inch in the x resolution\n"
109 " ydpi - dots per inch in the y resolution\n"
110 " fromx - from x position\n"
111 " tox - to x position\n"
112 " fromy - from y position\n"
113 " toy - to y position\n"
114 " Note - these can be floating point to get poitns inbetween but the output will not tell that\n"
115 " this is good for adding a second interleave like in the case of the heart hologram where we want to add 1440 points\n"
116 " attenuate - 0 for no attenuation based on distance, 1 for attenuations based on distance\n"
117 " attenuate of 1 is more realistic\n"
118 " nyquest - the nyquest factor to limit the aliasing caused when the wavelength\n"
119 " changes faster than the nyquest number of pixels (at the diagonal)\n"
120 " 1 would equate up to the nyquest point where we have even alterations\n"
121 " This speeds up complicated holograms immenselty, and makes the holographic effect better\n"
122 " but is not nearly as inticrate and beautiful as the aliased hologram\n"
123 " Then again, this will allow more complex point structures to be displayed\n"
124 "standard output gets a two dimensional array of points - double complex numbers with real first then imaginary x then y\n"
125 );
126 exit(-1);
127 }
128 fname=argv[1];
129 random_seed=atoi(argv[2]);
130 xsize = atoi(argv[3]);
131 ysize = atoi(argv[4]);
132 xdpi = atof(argv[5]);
133 ydpi = atof(argv[6]);
134 fromx = atof(argv[7]);
135 tox = atof(argv[8]);
136 fromy = atof(argv[9]);
137 toy = atof(argv[10]);
138 attenuate = atoi(argv[11]);
139 nyquest = atof(argv[12]);
140 fprintf(stderr,"nyq %lf attenuate %d\n",nyquest,attenuate);
141
142 int yspan;
143 int xspan;
144 yspan = toy-fromy;
145 xspan = tox-fromx;
146
147 real x_sampling_rate;
148 real y_sampling_rate;
149
150 x_sampling_rate = 1.0/(xdpi) * 0.0254;
151 y_sampling_rate = 1.0/(ydpi) * 0.0254; /* rates are in meters */
152
153 real xc,yc,hyp;
154 xc = (fromx+tox)*0.5;
155 yc = (fromy+toy)*0.5;
156 hyp=sqrt((tox-fromx)*(tox-fromx) + (toy-fromy)*(toy-fromy)) * 0.5;
157
158 real *elements;
159 elements=calloc(sizeof(real)*2,yspan*xspan); /* real imiganary combo */
160
161 point_source_array psax;
162 point_source_array *psa = &(psax);
163 psa->point_sources = NULL;
164 psa_clear_point_source_array(psa);
165
166 {
167 FILE *xf;
168 xf=fopen(fname,"r");
169 char buf[10000];
170 while (fgets(buf,9999,xf)) {
171 real x,y,z,amp,wl,pha;
172 real xm,ym;
173 x=fieldd(buf,0);
174 y=fieldd(buf,1);
175 z=fieldd(buf,2);
176 amp=fieldd(buf,3);
177 wl=fieldd(buf,4);
178 pha = fieldd(buf,5);
179 point_source ps;
180
181 xm = x / xdpi * 0.0254; /* convert form pixel to meter */
182 ym = y / ydpi * 0.0254; /* convert form pixel to meter */
183 if (nyquest != 0.0) {
184 ps = point_source_init_xyz_amp_lamda_phase_atten_nyquest
185 (xm,ym,z,amp,wl,pha,0.,nyquest,(double)(xdpi),(double)(ydpi));
186
187 real dist;
188 dist = sqrt((x-xc)*(x-xc) + (y-yc)*(y-yc));
189 /* fprintf(stderr,"dist is %lf x %lf y %lf\n",dist,x,y);*/
190 if ((ps.max_distance_pixels + hyp)*1.1 >= dist ) { /* 2.0 because might be a little in range */
191 psa_add_point_source(psa,ps); /* 1.1 is a fudge */
192 }
193 /* else {
194 fprintf(stderr,"skipping %lf,%lf as it is %lf away and max_distance is %lf\n",
195 x,y,dist,ps.max_distance_pixels);
196 }*/
197 } /* if we are doing nyquest stuff */
198 else {
199 ps = point_source_init_xyz_amp_lamda_phase(xm,ym,z,amp,wl,pha);
200 psa_add_point_source(psa,ps);
201 }
202 }
203 fprintf(stderr,"size %d\n",psa->size);
204 fclose(xf);
205 }
206
207
208
209 /* compute the area */
210 int i;
211 real yr;
212 real xr;
213 int y;
214 int x;
215 real z=0.0;
216 y=0;
217 for (yr=fromy;yr<toy;yr++) {
218 real yy = yr*y_sampling_rate;
219 x=0;
220 for (xr=fromx;xr<tox;xr++) {
221 real v;
222 real xx = xr*x_sampling_rate;
223
224 /* get the phase and amplituyde - could be done once yo */
225 point3d n;
226 n.x = xx;
227 n.y = yy;
228 n.z = z;
229 real *e;
230 int offset;
231 offset = y*xspan + x;
232 offset = offset + offset; /* so we have room for real and imaginary */
233 e=elements + offset;
234 apply_point_sources_complex(psa,0.,0.,n,attenuate,e);
235 /* fprintf(stderr,"%d,%d %lf,%lf %lf %lf\n",x,y,xx,yy,e[0],e[1]);*/
236 x++;
237 }
238 y++;
239 }
240
241 fwrite(elements,sizeof(real)*2*yspan*xspan,1,stdout);
242 exit(0);
243 }
244
245
246
247
248

  ViewVC Help
Powered by ViewVC 1.1.5