/[opencvs]/eyes/holo_complex.h
ViewVC logotype

Contents of /eyes/holo_complex.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (show annotations)
Mon Oct 6 06:39:39 2014 UTC (4 years, 1 month ago) by hib
Branch: MAIN
CVS Tags: HEAD
Changes since 1.8: +4 -1 lines
File MIME type: text/plain
Doing cleanup from burner eyes
1
2 #include <stdio.h>
3 #include <math.h>
4 #include <stdlib.h>
5
6 /*
7 computer_generated_hologram_c V1.0
8
9 holo_complex.h
10 Include this file if you are going to do the hologram complex stuff.
11
12
13 $Revision: 1.9 $
14 $Log: holo_complex.h,v $
15 Revision 1.9 2014/10/06 06:39:39 hib
16 Doing cleanup from burner eyes
17
18 Revision 1.8 2011-10-18 03:37:19 hib
19 axnay the table based lookup - locality of reference killed it -it was real slow.
20
21 Revision 1.7 2011-10-18 03:31:35 hib
22 intermediary where the sin and square root are done with a lookup table.
23 It ran slower!
24
25 Revision 1.6 2011-10-15 22:01:46 hib
26 Added build_double, find_gery_range, and fp_to_txt so that we can do some real cool stuff
27 like having the sin and cosine at the same time, for color, and
28 attenuate and all that. We are starting from scratch. Which sucks, because
29 it will take that much longer for 2880 - but the effect will be beautiful
30 This time - we are going to start at the center part and then expand from there.
31 So we can get something cool out earlier. and we can test it computing the real version
32 oh yeah we now limit based on the nyquest frequency so we can really speed things up.
33
34 Revision 1.5 2011-07-12 06:05:09 hib
35 encirculate is a proof in concept for japan.
36
37 Revision 1.4 2011-06-23 05:07:56 hib
38 adding stuff - ben ,arissa partially done. Havent started stephanie.
39 Kelly and vikroia are shipped - did a demo of edition 2 of enlightenment
40 and building first version of japan
41 .
42
43 Revision 1.3 2011-06-05 05:18:17 hib
44 kelly and viktoria are done. Enlightenment is being cranked out at 1800x1800.
45 Just started work on Japan and enlightenment second edition - with alpha appropriated hologram pixels.
46 And also can print money with any percentage value I want - to save ink.
47
48 Revision 1.2 2011-05-26 00:01:50 hib
49 Added maxrate to dullen the effect of the hologram - this should keep the printing of black a bit more under control, but not always.
50
51 Revision 1.4 2011-05-25 23:00:52 hib
52 holo_complex - got rid of useless functions left over from the java conversion.
53 Now this thing is lean and mean, much closer to what we need.
54
55 */
56
57 /*
58 computer_generated_hologram_c V1.0
59
60 Copyright (C) 2011 Hibbard M. Engler
61
62 This program is free software: you can redistribute it and/or modify
63 it under the terms of the GNU General Public License as published by
64 the Free Software Foundation, either version 3 of the License, or
65 (at your option) any later version.
66
67 This program is distributed in the hope that it will be useful,
68 but WITHOUT ANY WARRANTY; without even the implied warranty of
69 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
70 GNU General Public License for more details.
71
72 You should have received a copy of the GNU General Public License
73 along with this program. If not, see <http://www.gnu.org/licenses/>.
74
75 */
76 typedef double real;
77
78
79
80 #define PI 3.1415926535897932384626433832795028
81
82
83
84 /* complex psuedo functions */
85 #define cset(c,r,i) {c=r;}
86 #define csetpol(c,amplitude,phase) {c.re =amplitude*cos(phase); c.im = amplitude * sin(phase);}
87 #define cplus(a,b,c) {c.re = a.re + b.re;c.im = a.im + b.im;}
88 #define cminus(a,b,c) { c.re = a.re - b.re; c.im = a.im - b.im;}
89 #define ctimes(a,b,c) { c.re = a.re * b.re - a.im * b.im; c.im = a.im * b.re + b.re * a.im;}
90 #define ctimes_d (a,x,c) { c.re = a.re * x; c.im = a.im * x;}
91 #define cpluseq = (c,b) { c.re += b.re;c.im += b.im;}
92 #define cconjugate(a,c) { c.re = a.re; c.im = -a.im;}
93 #define camplitude(a) (sqrt(a.re*a.re+a.im*a.im))
94 #define cphase(a) (atan2(a.im,a.re))
95 #define creal(a) (a.re)
96 #define cimaginary(a) (a.im)
97 #define crandomize_phase(a,c) ((c)=randomize_phase2(a))
98
99 #define new_c2d(a,x,y) { a.array = malloc(x*y*sizeof(complex));}
100 #define free_c2d(a) { if (a.array) {free(a.array); a.array=NULL;}}
101 #define c2d(a,x,y) (a.array[a.x*y+x]);
102 #define c2dset(a,x,y,c) (a.array[a.x*y+x]=(c))
103
104
105 #define point3d_distance_points(a,b) (sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y) + (a.z-b.z) * (a.z-b.z)))
106 #define point3d_distance_squared_points(a,b) (((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y) + (a.z-b.z) * (a.z-b.z)))
107 #define point3d_distance(a) (sqrt(a.x*a.x + a.y*a.y + a.z*a.z))
108
109 #define point_source_lamda_default 670e-9; /* red light wavelength approx */
110 #define TWOPI 6.28318531
111 #define C 3e+8 //speed of light (m/s)
112 #define ONE_OVER_C 3.333333333333333333e-9
113
114
115 /* Complex data type - soon we wille schew this and just use cosine because we only care about real yo */
116 struct complex {
117 real re;
118 real im;
119 };
120
121 typedef struct complex complex;
122
123
124
125 /* 3 dimensional point - used for point sources */
126 struct point3d {
127 real x;
128 real y;
129 real z;
130 };
131
132
133 typedef struct point3d point3d;
134
135
136
137
138
139 /* point source - we will usually have many of these */
140
141 struct point_source
142 {
143 point3d point; /* where it is */
144 complex wave; /* probably the phase of the wave or something */
145 real amp; /* better to store this */
146 real phase; /* ditto */
147 real lamda; //approx wavelength of red light (m) but this could be different
148 /* one thing I was thinking of doing, is doing the point source 3 times -
149 one for each color of each rod - base on being printed out at 720 dpi
150 the rgb effect should allow us to see something in space - maybee */
151 real one_over_lamda_times_twopi; /* he he he speed increase */
152 real max_distance_pixels; /* max distance in pixels to go before we end up so far away we start aliasing - new! */
153 real max_distance_m; /* max distance in meters */
154 real max_distance_m_squared; /* max distance in meters squared */
155 };
156
157 typedef struct point_source point_source;
158
159
160 /* This is dynamically grown X2 over and over again */
161 struct point_source_array {
162 int size;
163 int alloc_size;
164 point_source * point_sources;
165 };
166
167 typedef struct point_source_array point_source_array;
168
169
170
171 /* The complex photo plat is what is struck on to make the actual picture
172 We will probably eschew this quickly too as we just need a real photo plate */
173 struct complex_photo_plate {
174 int max_x_res;
175 int max_y_res;
176 real x_sampling_rate;
177 real y_sampling_rate;
178 int x_offset;
179 int y_offset;
180 real *elements;
181 };
182
183 typedef struct complex_photo_plate complex_photo_plate;
184
185
186
187
188 /* A kiss is not real, but it is what we wish was real */
189 struct real_photo_plate {
190 int min, max, median;
191 complex_photo_plate plate;
192 /* BufferedImage im; */
193 int output_type;
194 char * descr;
195 };
196 typedef struct real_photo_plate real_photo_plate;
197
198
199
200
201 /*Complex2darray is malloc and free*/
202 struct complex2darray {
203 int x; int y;
204 complex * array;
205 };
206
207
208
209
210
211 /* Randomize the phase to make the effect look better.
212 In actuality, the phase should be determined by z position or something
213 because oif this, we need to set the random number being used - so we can reconstruct the
214 same image over and over again, and also make sub-images like my eyes will demand
215 */
216 complex crandomize_phase2(complex a);
217
218
219 /* Set it up with a point, wave, and lamda */
220 point_source point_source_init_point(point3d p,complex wave, real lamda);
221
222 point_source point_source_init_xyz_amp_lamda_phase(real x, real y, real z, real amp, real lamda, real phase);
223
224 point_source point_source_init_xyz_amp_lamda_phase_atten(real x, real y, real z, real amp, real lamda,
225 real phase, real atten);
226
227
228 void psa_add_point_source(point_source_array *psa,point_source ps);
229
230 void psa_clear_point_source_array(point_source_array *psa);
231
232 void psa_randomize_phases(point_source_array *psa);
233
234 void cpp_initialize_plate(complex_photo_plate *cpp,int xResolution, int yResolution, int x_offset, int y_offset,
235 real xSampling, real ySampling, int center);
236
237
238 void cpp_initialize_plate_xysxsyc(complex_photo_plate *cpp,
239 int xResolution, int yResolution,
240 real xSampling, real ySampling, int center);
241
242 int holo_output_simple(real *elements,int xspan,int yspan);
243
244
245 int find_the_two_colors (int r,int g,int b,int maxrate, int *rl, int *rh, int *gl, int *gh, int *bl, int *bh);
246
247 int holo_output_vary_constant_background(real *elements,int xspan, int yspan
248 ,int r,int g,int b,int maxrate,real threshold /* usually 0.5*/);
249 /* This is used to vary a constant color to fluxuate congruent to our hologram. */
250
251
252
253
254 int holo_output_vary_grey_background(real *elements,int xspan, int yspan);
255 /* This makes a normalized grey scale image that can be used to apply the hologram at any one of 256 different levels
256 This is good for doing the duality calculations - so that the dots are not longer random, but help make up a hologram */
257
258
259
260 real apply_point_sources(point_source_array *psa,real spot,point3d n,int attenuation); /* the magic code! */
261
262 int holo_sample();
263
264
265
266
267 void set_max_nyquest_point(point_source *p,real factor,real xdpi,real ydpi);
268 /* sets the calculated distance that would be the farthest to go in pixels from the center point.
269 This is useful to stop the aliasing of frequencies, and also
270 as an added bonus, allows us to eliminate points from the list if they are not in the current range that we
271 are computing for
272 */
273
274
275 point_source point_source_init_xyz_amp_lamda_phase_atten_nyquest
276 (real x, real y, real z, real amp, real lamda, real phase, real atten,real factor,real xdpi,real ydpi);
277
278
279
280
281
282
283
284
285
286 void apply_point_sources_complex(point_source_array *psa,real spot,real spoti,point3d n,int attenuation,real *pe);
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308 int compute_grey_from_files(int file_count,char *file_names[],real *grays,int offset,int span,int gmin,int gmax,real min,real max);
309 /* reading double files where they are double precision real/imiginary - figure out the grey scale ranges */
310
311
312 void find_min_max_from_files(int file_count,char *file_names[],int offset,int span,real *pmin, real *pmax) ;
313

  ViewVC Help
Powered by ViewVC 1.1.5