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

Contents of /eyes/build_diff.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (show annotations)
Tue Jul 12 06:05:08 2011 UTC (7 years, 5 months ago) by hib
Branch: MAIN
CVS Tags: HEAD
Changes since 1.4: +2 -2 lines
File MIME type: text/plain
encirculate is a proof in concept for japan.
1 /* Build_diff
2 This builds sections of a hologram based on parameters and an input file.
3 This is meant to take a bland filler background and spice it up, hopefully creating a
4 reflective hologram from the printout. Well, if ti doesn't work, the patterns
5 look neat anyways.
6
7 The resulting set will have the same average color as the color specified as long as the threshold
8 is at the .50 default.
9
10 The threshold can be changed to any point, which can reduce the brightness/darkness
11 of the resulting output - which might be good for printers that overspray too much
12 or good to sliver the effect somewhat.
13 */
14
15 /*
16
17 572e-9 - red
18 544e-9 - green
19 430e-9 - blue
20
21 */
22
23 #include <stdio.h>
24 #include <math.h>
25 #include <stdlib.h>
26 #include "holo_complex.h"
27
28
29
30 /*
31 computer_generated_hologram_c V1.0
32
33 Copyright (C) 2011 Hibbard M. Engler
34
35 This program is free software: you can redistribute it and/or modify
36 it under the terms of the GNU General Public License as published by
37 the Free Software Foundation, either version 3 of the License, or
38 (at your option) any later version.
39
40 This program is distributed in the hope that it will be useful,
41 but WITHOUT ANY WARRANTY; without even the implied warranty of
42 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43 GNU General Public License for more details.
44
45 You should have received a copy of the GNU General Public License
46 along with this program. If not, see <http://www.gnu.org/licenses/>.
47
48 */
49
50
51
52
53 int fieldi(char *x,int fieldnum) {
54 while (fieldnum && *x) {
55 if ((*x == '|')||(*x == ' ')) fieldnum--;
56 x++;
57 }
58 return atoi(x);
59 }
60
61
62 real fieldd(char *x,int fieldnum) {
63 while (fieldnum && *x) {
64 if ((*x == '|')||(*x == ' ')) fieldnum--;
65 x++;
66 }
67 return atof(x);
68 }
69
70
71
72 int main (int argc,char *argv[]) {
73
74 /*
75 source random_seed x size y size x dpi y dpi fromx tox+1 fromy toy+1 r g b diff threshold
76
77 And then the source has
78
79 x(pix), y(pix) z(meters),amp,wavelength(m),phase(m)
80
81 1000 points of light!
82
83 100 1 meter
84 100 2
85 100 3
86 100 4
87 100 5
88 100 6
89 100 7
90 100 8
91 100 9
92 100 10
93 Fuck!
94 */
95 char *fname;
96 int xsize;
97 int ysize;
98 real xdpi;
99 real ydpi;
100 int fromx;
101 int tox;
102 int fromy;
103 int toy;
104 int r;
105 int g;
106 int b;
107 int random_seed;
108 int maxrate;
109 real threshold;
110 fname=argv[1];
111 random_seed=atoi(argv[2]);
112 xsize = atoi(argv[3]);
113 ysize = atoi(argv[4]);
114 xdpi = atof(argv[5]);
115 ydpi = atof(argv[6]);
116 fromx = atoi(argv[7]);
117 tox = atoi(argv[8]);
118 fromy = atoi(argv[9]);
119 toy = atoi(argv[10]);
120 r = atoi(argv[11]);
121 g = atoi(argv[12]);
122 b = atoi(argv[13]);
123 maxrate = atoi(argv[14]); /* 128 for full rate , less to limit the effect some */
124 if (argc>15) {
125 threshold=atof(argv[15]);
126 }
127 else threshold=0.5;
128
129
130 int yspan;
131 int xspan;
132 yspan = toy-fromy;
133 xspan = tox-fromx;
134
135 real x_sampling_rate;
136 real y_sampling_rate;
137
138 x_sampling_rate = 1.0/(xdpi) * 0.0254;
139 y_sampling_rate = 1.0/(ydpi) * 0.0254; /* rates are in meters */
140 int attenuation=0; /* set to 1 to attenuate */
141
142 real *elements;
143 elements=calloc(sizeof(real),yspan*xspan);
144
145 point_source_array psax;
146 point_source_array *psa = &(psax);
147 psa->point_sources = NULL;
148 psa_clear_point_source_array(psa);
149
150 {
151 FILE *xf;
152 xf=fopen(fname,"r");
153 char buf[10000];
154 while (fgets(buf,9999,xf)) {
155 real x,y,z,amp,wl,pha;
156 x=fieldd(buf,0);
157 y=fieldd(buf,1);
158 z=fieldd(buf,2);
159 amp=fieldd(buf,3);
160 wl=fieldd(buf,4);
161 pha = fieldd(buf,5);
162 point_source ps;
163 x = x / xdpi * 0.0254; /* convert form pixel to meter */
164 y = y / ydpi * 0.0254; /* convert form pixel to meter */
165 ps = point_source_init_xyz_amp_lamda_phase(x,y,z,amp,wl,pha);
166 psa_add_point_source(psa,ps);
167 }
168 fclose(xf);
169 }
170
171
172 /* compute the area */
173 int i;
174 int y;
175 int x;
176 real z=0.0;
177 for (y=fromy;y<toy;y++) {
178 real yy = ((real)(y))*y_sampling_rate;
179 for (x=fromx;x<tox;x++) {
180 real v;
181 real xx = ((real)(x))*x_sampling_rate;
182 /* get the phase and amplituyde - could be done once yo */
183 point3d n;
184 n.x = xx;
185 n.y = yy;
186 n.z = z;
187 elements[(y-fromy)*xspan+(x-fromx)] =apply_point_sources(psa,0.,n,attenuation);
188 }
189 }
190
191
192 holo_output_vary_constant_background(elements,xspan,yspan,r,g,b,maxrate,threshold);
193 exit(0);
194 }
195
196

  ViewVC Help
Powered by ViewVC 1.1.5