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

Linux Cross Reference
Tina6/tina-tools/tinatool/tlbase/tlbaseImc_crt_tool.c

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

  1 /**********
  2  * 
  3  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  4  * University of Manchester, UK.  All rights reserved.
  5  * 
  6  * Redistribution and use in source and binary forms, with or without modification, 
  7  * are permitted provided that the following conditions are met:
  8  * 
  9  *   . Redistributions of source code must retain the above copyright notice, 
 10  *     this list of conditions and the following disclaimer.
 11  *    
 12  *   . Redistributions in binary form must reproduce the above copyright notice,
 13  *     this list of conditions and the following disclaimer in the documentation 
 14  *     and/or other materials provided with the distribution.
 15  * 
 16  *   . Neither the name of the University of Manchester nor the names of its
 17  *     contributors may be used to endorse or promote products derived from this 
 18  *     software without specific prior written permission.
 19  * 
 20  * 
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  *
 33  **********
 34  * 
 35  * Program :    TINA
 36  * File    :  $Source: /home/tina/cvs/tina-tools/tinatool/tlbase/tlbaseImc_crt_tool.c,v $
 37  * Date    :  $Date: 2007/02/15 01:55:50 $
 38  * Version :  $Revision: 1.3 $
 39  * CVS Id  :  $Id: tlbaseImc_crt_tool.c,v 1.3 2007/02/15 01:55:50 paul Exp $
 40  *
 41  * Author  :  Legacy TINA
 42  *
 43  * Notes :crt_tool.c 
 44  *         Update: S.Crossley
 45  *         Date  : 9-5-96; version 2.0
 46  *********
 47 */
 48 
 49 #include "tlbaseImc_crt_tool.h"
 50 
 51 #if HAVE_CONFIG_H
 52 #include <config.h>
 53 #endif
 54 
 55 #include <stdio.h>
 56 #include <sys/param.h>
 57 #include <string.h>
 58 #include <tinatool/wdgts/wdgtsDef.h>
 59 #include <tinatool/wdgts/wdgtsPro.h>
 60 #include <tina/image/imgDef.h>
 61 #include <tina/image/imgPro.h>
 62 #include <tina/math/mathDef.h>
 63 #include <tinatool/tlbase/tlbase_InfrDef.h>
 64 #include <tinatool/tlbase/tlbase_InfrPro.h>
 65 #include <tinatool/tlbase/tlbaseImc_imc.h>
 66 #include <tinatool/tlbase/tlbaseImc_view.h>
 67 #include <tinatool/tlbase/tlbaseImc_tool.h>
 68 
 69 
 70 #define FOR_IM(_roi,_row,_col) for ((_row)=(_roi)->ly; (_row)<(_roi)->uy; (_row)++) \
 71                                  for ((_col)=(_roi)->lx; (_col)<(_roi)->ux; (_col)++)
 72 
 73 static int width = 256, height = 256;
 74 static double cx = 128.0, cy = 128.0;
 75 static double ax = 32.0, ay = 32.0;
 76 static double ex = 64.0, ey = 64.0;
 77 static double noise = 0.0;
 78 static double slant = PIBY4;
 79 static double tilt = PIBY4;
 80 static double gb_k = 16.0, gb_b = 1.0, theta = 0.0;
 81 static double overtake = 10.0, loops = 4.0;
 82 static void *pcx=NULL, *pcy=NULL, *pax=NULL, *pay=NULL;
 83 
 84 static char directory_name[MAXPATHLEN];
 85 static char file_name[MAXPATHLEN];
 86 static char pathname[MAXPATHLEN];
 87 
 88 /********** Callback functions **********/
 89 
 90 static void chequer_proc(void)
 91 {
 92   Imrect *im;
 93   Imrect *imf_checquer();
 94   
 95   im = imf_checquer(width,
 96                     height,
 97                     (int) ax,
 98                     (int) ay);
 99   stack_push((void *) im, IMRECT, im_free);
100   imcalc_draw(imcalc_tv_get());
101   imcalc_draw(imcal2_tv_get());
102   image_choice_reset();
103 }
104 
105 static void spiral_proc(void)
106 {
107   Imrect *im;
108   
109   im = imf_spiral(ax, ay, width, height,
110                   overtake, loops);
111   stack_push((void *) im, IMRECT, im_free);
112   imcalc_draw(imcalc_tv_get());
113   imcalc_draw(imcal2_tv_get());
114   image_choice_reset();
115 }
116 
117 static void rand_noise_proc(void)
118 {
119   Imrect *im;
120   Imrect *imf_norm_noise();
121   
122   im = imf_norm_noise(width, height, (int) ax, (int) ay, 0.0, noise);
123   stack_push((void *) im, IMRECT, im_free);
124   imcalc_draw(imcalc_tv_get());
125   imcalc_draw(imcal2_tv_get());
126   image_choice_reset();
127 }
128 
129 static void rect_proc(void)
130 {
131   int lx, ly, ux, uy;
132   Imrect *im;
133   Imrect *imf_rect();
134   
135   lx = cx - ax;
136   ly = cy - ay;
137   ux = cx + ax;
138   uy = cy + ay;
139 
140   im = imf_rect(width, height, lx, ly, ux, uy);
141   stack_push((void *) im, IMRECT, im_free);
142   imcalc_draw(imcalc_tv_get());
143   imcalc_draw(imcal2_tv_get());
144   image_choice_reset();
145 }
146 
147 static void ellipse_proc(void)
148 {
149   Imrect *im;
150   Imrect *imf_ellipse();
151 
152   im = imf_ellipse(width, height, cx, cy, ax, ay);
153   stack_push((void *) im, IMRECT, im_free);
154   imcalc_draw(imcalc_tv_get());
155   imcalc_draw(imcal2_tv_get());
156   image_choice_reset();
157 }
158 
159 static void ellipse_subpix_proc(void)
160 {
161   Imrect *im;
162   Imrect *imf_subpix_ellipse();
163 
164   im = imf_subpix_ellipse(width, height, cx, cy, ax, ay);
165   stack_push((void *) im, IMRECT, im_free);
166   imcalc_draw(imcalc_tv_get());
167   imcalc_draw(imcal2_tv_get());
168   image_choice_reset();
169 }
170 
171 static void ellipsoid_subpix_proc(void)
172 {
173   Imrect *im;
174   Imrect *imf_subpix_ellipse();
175 
176   im = imf_subpix_ellipsoid(width, height, cx, cy, ax, ay);
177   stack_push((void *) im, IMRECT, im_free);
178   imcalc_draw(imcalc_tv_get());
179   imcalc_draw(imcal2_tv_get());
180   image_choice_reset();
181 }
182 
183 static void sellipse_subpix_proc(void)
184 {
185   Imrect *im;
186   Imrect *imf_subpix_sellipse();
187 
188   im = imf_subpix_sellipse(width, height, cx, cy, PI / 8.0, ax, ay, ex, ey);
189   stack_push((void *) im, IMRECT, im_free);
190   imcalc_draw(imcalc_tv_get());
191   imcalc_draw(imcal2_tv_get());
192   image_choice_reset();
193 }
194 
195 static void delta_proc(void)
196 {
197   Imrect *im;
198   Imrect *imf_delta();
199 
200   im = imf_delta(width, height, cx, cy);
201   stack_push((void *) im, IMRECT, im_free);
202   imcalc_draw(imcalc_tv_get());
203   imcalc_draw(imcal2_tv_get());
204   image_choice_reset();
205 }
206 
207 static void fshade_proc(void)
208 {
209   Imrect *im;
210   Imrect *shade_conv(double slant,double tilt,Imregion *roi);
211   Imregion *roi;
212   int type;
213 
214   if (stack_check_types(IMRECT, NULL) == false)
215     {
216       error("imcreate fshade: wrong types on stack", warning);
217       return;
218     }
219   im = (Imrect *) stack_inspect(&type);
220   roi = im->region;
221   
222   stack_push((void *) shade_conv(slant,tilt,roi) , IMRECT, im_free);
223   imcalc_draw(imcalc_tv_get());
224   imcalc_draw(imcal2_tv_get());
225   image_choice_reset();
226 }
227 
228 static void shade_proc(void)
229 {
230   Imrect *im;
231   Imrect *shade_conv(double slant,double tilt,Imregion *roi);
232   Imregion *roi;
233   int type;
234 
235   if (stack_check_types(IMRECT, NULL) == false)
236     {
237       error("imcreate shade: wrong types on stack", warning);
238       return;
239     }
240   im = (Imrect *) stack_inspect(&type);
241   roi = im->region;
242   
243   stack_push((void *) im_shading(im,slant,tilt,1.0), IMRECT, im_free);
244   imcalc_draw(imcalc_tv_get());
245   imcalc_draw(imcal2_tv_get());
246   image_choice_reset();
247 }
248 
249 static void gabor_proc(void)
250 {
251   Imrect *im;
252   Imrect *im_fgabor(Imregion *roi, double k, double b, double theta);
253   Imregion *roi;
254   int type;
255 
256   if (stack_check_types(IMRECT, NULL) == false)
257     {
258       error("imcalc_sum: wrong types on stack", warning);
259       return;
260     }
261   im = (Imrect *) stack_inspect(&type);
262   roi = im->region;
263   
264   stack_push((void *) im_fgabor(roi, gb_k, gb_b, theta) , IMRECT, im_free);
265   imcalc_draw(imcalc_tv_get());
266   imcalc_draw(imcal2_tv_get());
267   image_choice_reset();
268 }
269 
270 static void stereo_noise_proc(void)
271 {
272   Imrect *iml;
273   Imrect *obstcl;
274   Imrect *imr;
275   Imrect *iml1;
276   Imrect *imr1;
277   Imrect *imf_unif_noise();
278   int     w = ax;
279   int     h = ay;
280   int     sx = (width - ax - ex) / 2;
281   int     sy = (height - ay - ey) / 2;
282   int     dx = ex;
283   int     dy = ey;
284   
285   iml = imf_unif_noise(width, height, 1, 1, 0.0, 1.0);
286   imr = im_copy(iml);
287   obstcl = imf_unif_noise(w, h, 1, 1, 0.0, 1.0);
288   
289   
290   /** put obstacle on background **/
291   im_shift(obstcl, sy, sx);
292   im_copy_inplace(iml, obstcl);
293   im_shift(obstcl, dy, dx);
294   im_copy_inplace(imr, obstcl);
295   im_free(obstcl);
296   
297   /** add noise **/
298   iml1 = im_corrupt(iml, 1, 1, 0.0, noise);
299   im_free(iml);
300   imr1 = im_corrupt(imr, 1, 1, 0.0, noise);
301   im_free(imr);
302   
303   stack_push((void *) imr1, IMRECT, im_free);
304   stack_push((void *) iml1, IMRECT, im_free);
305   imcalc_draw(imcalc_tv_get());
306   imcalc_draw(imcal2_tv_get());
307   image_choice_reset();
308 }
309 
310 void  set_crt_params(float new_cx, float new_ax, float new_cy, float new_ay)
311 {
312    cx = new_cx;
313    (void) tw_fglobal_reset(pcx);
314    ax = new_ax;
315    (void) tw_fglobal_reset(pax);
316    cy = new_cy;
317    (void) tw_fglobal_reset(pcy);
318    ay = new_ay;
319    (void) tw_fglobal_reset(pay);
320 }
321 
322 /********** Tool creation **********/
323 
324 void image_create_tool(int x, int y)
325 {
326   static void *tv_screen = NULL;
327   
328   if (tv_screen)
329     {
330       tw_show_tool(tv_screen);
331       return;
332     }
333   tv_screen = tw_tool("Image Create Tool", x, y);
334   
335   tw_button("rect", rect_proc, NULL);
336   tw_button("spiral", spiral_proc, NULL);
337   tw_button("chequer", chequer_proc, NULL);
338   tw_button("noise", rand_noise_proc, NULL);
339   tw_button(" rds ", stereo_noise_proc, NULL);
340   tw_button("delta", delta_proc, NULL);
341   tw_button("shade",shade_proc,NULL);
342   
343   tw_newrow();
344   
345   tw_button("ellipse", ellipse_subpix_proc, NULL);
346   tw_button("ellipsoid", ellipsoid_subpix_proc, NULL);
347   tw_button("sellipse", sellipse_subpix_proc, NULL);
348   tw_button("fgabor",gabor_proc,NULL);
349   tw_button("fshade",fshade_proc,NULL);
350 
351   tw_newrow();
352   (void) tw_iglobal("width: ", &width, 6);
353   (void) tw_iglobal("height:", &height, 6);
354   tw_newrow();
355   pcx = (void *) tw_fglobal("cx:", &cx, 10);
356   pax = (void *) tw_fglobal("ax:", &ax, 10);
357   (void) tw_fglobal("ex:", &ex, 10);
358   tw_newrow();
359   pcy = (void *) tw_fglobal("cy:", &cy, 10);
360   pay = (void *) tw_fglobal("ay:", &ay, 10);
361   (void) tw_fglobal("ey:", &ey, 10);
362   tw_newrow();
363   (void) tw_fglobal("noise:", &noise, 10);
364   (void) tw_fglobal("slant:", &slant, 10);
365   (void) tw_fglobal("tilt:", &tilt, 10);
366   tw_newrow();
367   (void) tw_fglobal("gb k:", &gb_k, 10);
368   (void) tw_fglobal("gb b:", &gb_b, 10);
369   (void) tw_fglobal("theta:", &theta, 10);
370   tw_newrow();
371   (void) tw_fglobal("overtake:", &overtake, 10);
372   (void) tw_fglobal("loops:", &loops, 10);
373 
374   
375   tw_end_tool();
376 }
377 

~ [ 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.