~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/tools/imcalc/crt_tool.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* crt_tool.c
  2 
  3    Update: S.Crossley
  4    Date  : 9-5-96; version 2.0
  5 */
  6 
  7 #include <stdio.h>
  8 #include <sys/param.h>
  9 #include <string.h>
 10 #include <tina/all_tina.h>
 11 #include <tina/tw_Xfuncs.h>
 12 
 13 #define FOR_IM(_roi,_row,_col) for ((_row)=(_roi)->ly; (_row)<(_roi)->uy; (_row)++) \
 14                                  for ((_col)=(_roi)->lx; (_col)<(_roi)->ux; (_col)++)
 15 
 16 static int width = 256, height = 256;
 17 static double cx = 128.0, cy = 128.0;
 18 static double ax = 32.0, ay = 32.0;
 19 static double ex = 64.0, ey = 64.0;
 20 static double noise = 0.0;
 21 static double slant = PIBY4;
 22 static double tilt = PIBY4;
 23 static double gb_k = 16.0, gb_b = 1.0, theta = 0.0;
 24 static double overtake = 10.0, loops = 4.0;
 25 static void *pcx=NULL, *pcy=NULL, *pax=NULL, *pay=NULL;
 26 
 27 static char directory_name[MAXPATHLEN];
 28 static char file_name[MAXPATHLEN];
 29 static char pathname[MAXPATHLEN];
 30 
 31 /********** Callback functions **********/
 32 
 33 static void chequer_proc(void)
 34 {
 35   Imrect *im;
 36   Imrect *imf_checquer();
 37   
 38   im = imf_checquer(width,
 39                     height,
 40                     (int) ax,
 41                     (int) ay);
 42   stack_push((void *) im, IMRECT, im_free);
 43   imcalc_draw(imcalc_tv_get());
 44   imcalc_draw(imcal2_tv_get());
 45   image_choice_reset();
 46 }
 47 
 48 static void spiral_proc(void)
 49 {
 50   Imrect *im;
 51   
 52   im = imf_spiral(ax, ay, width, height,
 53                   overtake, loops);
 54   stack_push((void *) im, IMRECT, im_free);
 55   imcalc_draw(imcalc_tv_get());
 56   imcalc_draw(imcal2_tv_get());
 57   image_choice_reset();
 58 }
 59 
 60 static void rand_noise_proc(void)
 61 {
 62   Imrect *im;
 63   Imrect *imf_norm_noise();
 64   
 65   im = imf_norm_noise(width, height, (int) ax, (int) ay, 0.0, noise);
 66   stack_push((void *) im, IMRECT, im_free);
 67   imcalc_draw(imcalc_tv_get());
 68   imcalc_draw(imcal2_tv_get());
 69   image_choice_reset();
 70 }
 71 
 72 static void rect_proc(void)
 73 {
 74   int lx, ly, ux, uy;
 75   Imrect *im;
 76   Imrect *imf_rect();
 77   
 78   lx = cx - ax;
 79   ly = cy - ay;
 80   ux = cx + ax;
 81   uy = cy + ay;
 82 
 83   im = imf_rect(width, height, lx, ly, ux, uy);
 84   stack_push((void *) im, IMRECT, im_free);
 85   imcalc_draw(imcalc_tv_get());
 86   imcalc_draw(imcal2_tv_get());
 87   image_choice_reset();
 88 }
 89 
 90 static void ellipse_proc(void)
 91 {
 92   Imrect *im;
 93   Imrect *imf_ellipse();
 94 
 95   im = imf_ellipse(width, height, cx, cy, ax, ay);
 96   stack_push((void *) im, IMRECT, im_free);
 97   imcalc_draw(imcalc_tv_get());
 98   imcalc_draw(imcal2_tv_get());
 99   image_choice_reset();
100 }
101 
102 static void ellipse_subpix_proc(void)
103 {
104   Imrect *im;
105   Imrect *imf_subpix_ellipse();
106 
107   im = imf_subpix_ellipse(width, height, cx, cy, ax, ay);
108   stack_push((void *) im, IMRECT, im_free);
109   imcalc_draw(imcalc_tv_get());
110   imcalc_draw(imcal2_tv_get());
111   image_choice_reset();
112 }
113 
114 static void ellipsoid_subpix_proc(void)
115 {
116   Imrect *im;
117   Imrect *imf_subpix_ellipse();
118 
119   im = imf_subpix_ellipsoid(width, height, cx, cy, ax, ay);
120   stack_push((void *) im, IMRECT, im_free);
121   imcalc_draw(imcalc_tv_get());
122   imcalc_draw(imcal2_tv_get());
123   image_choice_reset();
124 }
125 
126 static void sellipse_subpix_proc(void)
127 {
128   Imrect *im;
129   Imrect *imf_subpix_sellipse();
130 
131   im = imf_subpix_sellipse(width, height, cx, cy, PI / 8.0, ax, ay, ex, ey);
132   stack_push((void *) im, IMRECT, im_free);
133   imcalc_draw(imcalc_tv_get());
134   imcalc_draw(imcal2_tv_get());
135   image_choice_reset();
136 }
137 
138 static void delta_proc(void)
139 {
140   Imrect *im;
141   Imrect *imf_delta();
142 
143   im = imf_delta(width, height, cx, cy);
144   stack_push((void *) im, IMRECT, im_free);
145   imcalc_draw(imcalc_tv_get());
146   imcalc_draw(imcal2_tv_get());
147   image_choice_reset();
148 }
149 
150 static void fshade_proc(void)
151 {
152   Imrect *im;
153   Imrect *shade_conv(double slant,double tilt,Imregion *roi);
154   Imregion *roi;
155   int type;
156 
157   if (stack_check_types(IMRECT, NULL) == false)
158     {
159       error("imcreate fshade: wrong types on stack", warning);
160       return;
161     }
162   im = (Imrect *) stack_inspect(&type);
163   roi = im->region;
164   
165   stack_push((void *) shade_conv(slant,tilt,roi) , IMRECT, im_free);
166   imcalc_draw(imcalc_tv_get());
167   imcalc_draw(imcal2_tv_get());
168   image_choice_reset();
169 }
170 
171 static void shade_proc(void)
172 {
173   Imrect *im;
174   Imrect *shade_conv(double slant,double tilt,Imregion *roi);
175   Imregion *roi;
176   int type;
177 
178   if (stack_check_types(IMRECT, NULL) == false)
179     {
180       error("imcreate shade: wrong types on stack", warning);
181       return;
182     }
183   im = (Imrect *) stack_inspect(&type);
184   roi = im->region;
185   
186   stack_push((void *) im_shading(im,slant,tilt,1.0), IMRECT, im_free);
187   imcalc_draw(imcalc_tv_get());
188   imcalc_draw(imcal2_tv_get());
189   image_choice_reset();
190 }
191 
192 static void gabor_proc(void)
193 {
194   Imrect *im;
195   Imrect *im_fgabor(Imregion *roi, double k, double b, double theta);
196   Imregion *roi;
197   int type;
198 
199   if (stack_check_types(IMRECT, NULL) == false)
200     {
201       error("imcalc_sum: wrong types on stack", warning);
202       return;
203     }
204   im = (Imrect *) stack_inspect(&type);
205   roi = im->region;
206   
207   stack_push((void *) im_fgabor(roi, gb_k, gb_b, theta) , IMRECT, im_free);
208   imcalc_draw(imcalc_tv_get());
209   imcalc_draw(imcal2_tv_get());
210   image_choice_reset();
211 }
212 
213 static void stereo_noise_proc(void)
214 {
215   Imrect *iml;
216   Imrect *obstcl;
217   Imrect *imr;
218   Imrect *iml1;
219   Imrect *imr1;
220   Imrect *imf_unif_noise();
221   int     w = ax;
222   int     h = ay;
223   int     sx = (width - ax - ex) / 2;
224   int     sy = (height - ay - ey) / 2;
225   int     dx = ex;
226   int     dy = ey;
227   
228   iml = imf_unif_noise(width, height, 1, 1, 0.0, 1.0);
229   imr = im_copy(iml);
230   obstcl = imf_unif_noise(w, h, 1, 1, 0.0, 1.0);
231   
232   
233   /** put obstacle on background **/
234   im_shift(obstcl, sy, sx);
235   im_copy_inplace(iml, obstcl);
236   im_shift(obstcl, dy, dx);
237   im_copy_inplace(imr, obstcl);
238   im_free(obstcl);
239   
240   /** add noise **/
241   iml1 = im_corrupt(iml, 1, 1, 0.0, noise);
242   im_free(iml);
243   imr1 = im_corrupt(imr, 1, 1, 0.0, noise);
244   im_free(imr);
245   
246   stack_push((void *) imr1, IMRECT, im_free);
247   stack_push((void *) iml1, IMRECT, im_free);
248   imcalc_draw(imcalc_tv_get());
249   imcalc_draw(imcal2_tv_get());
250   image_choice_reset();
251 }
252 
253 void  set_crt_params(float new_cx, float new_ax, float new_cy, float new_ay)
254 {
255    cx = new_cx;
256    (void) tw_fglobal_reset(pcx);
257    ax = new_ax;
258    (void) tw_fglobal_reset(pax);
259    cy = new_cy;
260    (void) tw_fglobal_reset(pcy);
261    ay = new_ay;
262    (void) tw_fglobal_reset(pay);
263 }
264 
265 /********** Tool creation **********/
266 
267 void image_create_tool(int x, int y)
268 {
269   static void *tv_screen = NULL;
270   
271   if (tv_screen)
272     {
273       tw_show_tool(tv_screen);
274       return;
275     }
276   tv_screen = tw_tool("Image Create Tool", x, y);
277   
278   tw_button("rect", rect_proc, NULL);
279   tw_button("spiral", spiral_proc, NULL);
280   tw_button("chequer", chequer_proc, NULL);
281   tw_button("noise", rand_noise_proc, NULL);
282   tw_button(" rds ", stereo_noise_proc, NULL);
283   tw_button("delta", delta_proc, NULL);
284   tw_button("shade",shade_proc,NULL);
285   
286   tw_newrow();
287   
288   tw_button("ellipse", ellipse_subpix_proc, NULL);
289   tw_button("ellipsoid", ellipsoid_subpix_proc, NULL);
290   tw_button("sellipse", sellipse_subpix_proc, NULL);
291   tw_button("fgabor",gabor_proc,NULL);
292   tw_button("fshade",fshade_proc,NULL);
293 
294   tw_newrow();
295   (void) tw_iglobal("width: ", &width, 6);
296   (void) tw_iglobal("height:", &height, 6);
297   tw_newrow();
298   pcx = (void *) tw_fglobal("cx:", &cx, 10);
299   pax = (void *) tw_fglobal("ax:", &ax, 10);
300   (void) tw_fglobal("ex:", &ex, 10);
301   tw_newrow();
302   pcy = (void *) tw_fglobal("cy:", &cy, 10);
303   pay = (void *) tw_fglobal("ay:", &ay, 10);
304   (void) tw_fglobal("ey:", &ey, 10);
305   tw_newrow();
306   (void) tw_fglobal("noise:", &noise, 10);
307   (void) tw_fglobal("slant:", &slant, 10);
308   (void) tw_fglobal("tilt:", &tilt, 10);
309   tw_newrow();
310   (void) tw_fglobal("gb k:", &gb_k, 10);
311   (void) tw_fglobal("gb b:", &gb_b, 10);
312   (void) tw_fglobal("theta:", &theta, 10);
313   tw_newrow();
314   (void) tw_fglobal("overtake:", &overtake, 10);
315   (void) tw_fglobal("loops:", &loops, 10);
316 
317   
318   tw_end_tool();
319 }
320 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.