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

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

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

  1 /* imc_tool.c
  2 
  3 */
  4 
  5 #include <stdio.h>
  6 #include <tina/sys.h>
  7 #include <tina/sysfuncs.h>
  8 #include <tina/math.h>
  9 #include <tina/mathfuncs.h>
 10 #include <tina/vision.h>
 11 #include <tina/visionfuncs.h>
 12 #include <tina/tv.h>
 13 #include <tina/tvfuncs.h>
 14 #include <tina/toolsfuncs.h>
 15 #include <tina/tw_Xfuncs.h>
 16 #include <tina/draw.h>
 17 
 18 /* EXTERNS  */
 19 
 20 extern void tw_show_tool();
 21 extern void *tw_tool();
 22 extern void *tw_fglobal();
 23 extern void *tw_iglobal();
 24 extern void imcalc_draw(Tv *tv);
 25 extern void redraw_graph_plot(Tv *tv);
 26 
 27 static int connect = 2;
 28 static int sx = 0, sy = 0;
 29 static int lr = 0, ud = 0;
 30 static double scale = 255.0, sigma = 1.0;
 31 static double thresh = 128.0, constant = 1.0;
 32 static double range = 5.0;
 33 static int old_connect = 2;
 34 static int old_sx = 0, old_sy = 0;
 35 static int old_lr = 0, old_ud = 0;
 36 static double old_scale = 255.0, old_sigma = 1.0;
 37 static double old_thresh = 128.0, old_constant = 1.0;
 38 static double old_range = 5.0;
 39 static void *psx, *psy, *plr, *pud, *pcon;
 40 static void *pth,*psc,*psi,*pac,*pco,*pra;
 41 
 42 void im_free();
 43 extern Tv *imcalc_tv_get();
 44 extern Tv *imcal2_tv_get();
 45 extern Tv *imcmem_tv_get();
 46 extern Tv *imcalc_tv_make();
 47 extern Tv *imcal2_tv_make();
 48 extern Tv *imcmem_tv_make();
 49 extern Tv *imcalc_graph_tv_make();
 50 extern void imcalc_reg_set(Imrect *im,int type);
 51 extern Imrect *imcalc_reg_get(void);
 52 extern void imcalc_xy_norm(double constant, double sigma, double thresh);
 53 static void *image_choice=NULL;
 54 
 55 
 56 /********** Support functions **********/
 57 
 58 void image_choice_reset(void)
 59 {
 60     int vtype;
 61     Imrect *im;
 62     int type;
 63 
 64     if (im = (Imrect *)stack_inspect(&type))
 65     {
 66 
 67         vtype = im->vtype;
 68         switch (vtype)
 69         {
 70         case char_v:
 71         case uchar_v:
 72             tw_choice_reset(image_choice, 1);
 73             break;
 74         case short_v:
 75         case ushort_v:
 76         case uint_v:
 77         case int_v:
 78             tw_choice_reset(image_choice, 2);
 79             break;
 80         case float_v:
 81             tw_choice_reset(image_choice, 3);
 82             break;
 83         case complex_v:
 84             tw_choice_reset(image_choice, 4);
 85             break;
 86         case ptr_v:
 87             tw_choice_reset(image_choice, 5);
 88             break;
 89         }
 90 /*
 91         if (imcalc_tv_get()!=NULL)
 92             tv_set_roi(imcalc_tv_get(),im->region);
 93 */
 94     }
 95 }
 96 
 97 static void tv_proc(void)
 98 {
 99     imcalc_tv_set(imcalc_tv_make());
100     imcal2_tv_set(imcal2_tv_make());
101     imcmem_tv_set(imcmem_tv_make());
102     imcalc_graph_tv_set(imcalc_graph_tv_make());
103     tv_set_next(imcalc_tv_get());
104 }
105 
106 /********** Callback functions **********/
107 
108 static void clear_all_proc(void)
109 {
110     extern void imcalc_undo(Imrect * im1 , Imrect * im2 , Bool f);
111     stack_clear();
112     imcalc_undo(NULL,NULL,false);
113     tv_erase(imcalc_tv_get());
114     tv_erase(imcal2_tv_get());
115 }
116 
117 static void     clear_proc()
118 {
119     extern void imcalc_undo(Imrect * im1 , Imrect * im2 , Bool f);
120     Imrect         *im1,*im2;
121     int             type;
122 
123     im1 = (Imrect *) stack_pop(&type);
124     im2 = (Imrect *) stack_pop(&type);
125     imcalc_undo(im1,im2,false);
126     stack_push( im_copy(im2), IMRECT, im_free );
127     imcalc_draw(imcalc_tv_get());
128     imcalc_draw(imcal2_tv_get());
129     redraw_graph_plot(imcalc_tv_get());
130     image_choice_reset();
131 }
132 
133 static void     store_proc()
134 {
135     Imrect         *im;
136     int             type;
137 
138     im = (Imrect *) stack_inspect(&type);
139     imcalc_reg_set(im_copy(im),type);
140     imcalc_draw(imcmem_tv_get());
141 }
142 
143 static void     fetch_proc()
144 {
145     Imrect         *im1;
146 
147     stack_push(im_copy(imcalc_reg_get()), imcalc_reg_type(), im_free);
148     imcalc_draw(imcalc_tv_get());
149     imcalc_draw(imcal2_tv_get());
150     redraw_graph_plot(imcalc_tv_get());
151     image_choice_reset();
152 }
153 
154 static void dup_proc(void)
155 {
156     Imrect *im;
157     int type;
158 
159     im = (Imrect *) stack_inspect(&type);
160     if (type != IMRECT)
161         return;
162 
163     stack_push((void *) im_copy(im), type, im_free);
164     imcalc_draw(imcal2_tv_get());
165     image_choice_reset();
166 }
167 
168 static void flip_proc(void)
169 {
170     stack_flip();
171     imcalc_draw(imcalc_tv_get());
172     imcalc_draw(imcal2_tv_get());
173     redraw_graph_plot(imcalc_tv_get());
174     image_choice_reset();
175 }
176 
177 static void roi_proc(void)
178 {
179     Tv     *tv = imcalc_tv_get();
180     void set_crt_params(float a, float b, float c ,float d);
181     Imregion roi;
182 
183     if (tv == NULL || tv->tv_screen == NULL)
184         return;
185     roi = *tv_get_im_roi(tv);
186     imcalc_roi(&roi);
187     set_crt_params((float)((roi.lx+roi.ux)/2.0),
188                  fabs(roi.ux-roi.lx)/2.0,
189                  (float)((roi.ly+roi.uy)/2.0),
190                  fabs(roi.uy-roi.ly)/2.0);
191 
192     imcalc_draw(imcalc_tv_get());
193 }
194 
195 static void scat_proc(void)
196 {
197     Tv     *tv = imcalc_tv_get();
198     extern void imcalc_scat(Imregion *roi,float scale);
199  
200     if (tv == NULL || tv->tv_screen == NULL)
201         return;
202     imcalc_scat(tv_get_im_roi(tv),scale);
203     imcalc_draw(imcalc_tv_get());
204     imcalc_draw(imcal2_tv_get());
205     image_choice_reset();
206 }
207 
208 static void iscat_proc(void)
209 {
210     Tv     *tv = imcalc_tv_get();
211     extern void imcalc_iscat(Imregion *roi, float scale);
212  
213     if (tv == NULL || tv->tv_screen == NULL)
214         return;
215     imcalc_iscat(tv_get_im_roi(tv), scale);
216     imcalc_draw(imcalc_tv_get());
217     imcalc_draw(imcal2_tv_get());
218     image_choice_reset();
219 }
220 
221 static void dscat_proc(void)
222 {
223     Tv     *tv = imcalc_tv_get();
224     extern void imcalc_dscat(Imregion *roi, float scale);
225 
226     if (tv == NULL || tv->tv_screen == NULL)
227         return;
228     imcalc_dscat(tv_get_im_roi(tv), scale);
229     imcalc_draw(imcalc_tv_get());
230     imcalc_draw(imcal2_tv_get());
231     image_choice_reset();
232 }
233 
234 static void hist_proc(void)
235 {
236     Tv     *tv = imcalc_tv_get();
237     Imregion *roi;
238     extern void imcalc_hist(double *k, double range, double*var, Imregion *roi);
239  
240     if (tv == NULL || tv->tv_screen == NULL)
241         return;
242     roi = tv_get_im_roi(tv);
243     imcalc_hist(&thresh, range, &constant, roi);
244     constant = 1.0/constant;
245     (void) tw_fglobal_reset(pth);
246     (void) tw_fglobal_reset(pco);
247     imcalc_draw(imcalc_tv_get());
248     imcalc_draw(imcal2_tv_get());
249     image_choice_reset();
250 }
251 
252 static void zpad_proc(void)
253 {
254     imcalc_zpad(range);
255     imcalc_draw(imcalc_tv_get());
256     redraw_graph_plot(imcalc_tv_get());
257     image_choice_reset();
258 }
259 
260 static void rescale_proc(void)
261 {
262     imcalc_scale(0.0, scale);
263     imcalc_draw(imcalc_tv_get());
264     redraw_graph_plot(imcalc_tv_get());
265     image_choice_reset();
266 }
267 
268 static void sum_proc(void)
269 {
270     imcalc_sum();
271     imcalc_draw(imcalc_tv_get());
272     imcalc_draw(imcal2_tv_get());
273     redraw_graph_plot(imcalc_tv_get());
274     image_choice_reset();
275 }
276 
277 static void add_proc(void)
278 {
279     imcalc_add(constant);
280     imcalc_draw(imcalc_tv_get());
281     redraw_graph_plot(imcalc_tv_get());
282     image_choice_reset();
283 }
284 
285 static void diff_proc(void)
286 {
287     imcalc_diff();
288     imcalc_draw(imcalc_tv_get());
289     imcalc_draw(imcal2_tv_get());
290     redraw_graph_plot(imcalc_tv_get());
291     image_choice_reset();
292 }
293 
294 static void prod_proc(void)
295 {
296     imcalc_prod();
297     imcalc_draw(imcalc_tv_get());
298     imcalc_draw(imcal2_tv_get());
299     redraw_graph_plot(imcalc_tv_get());
300     image_choice_reset();
301 }
302 
303 static void div_proc(void)
304 {
305     imcalc_div(constant);
306     imcalc_draw(imcalc_tv_get());
307     imcalc_draw(imcal2_tv_get());
308     redraw_graph_plot(imcalc_tv_get());
309     image_choice_reset();
310 }
311 
312 static void minus_proc(void)
313 {
314     imcalc_minus();
315     imcalc_draw(imcalc_tv_get());
316     redraw_graph_plot(imcalc_tv_get());
317     image_choice_reset();
318 }
319 
320 static void times_proc(void)
321 {
322     imcalc_times(constant);
323     imcalc_draw(imcalc_tv_get());
324     redraw_graph_plot(imcalc_tv_get());
325     image_choice_reset();
326 }
327 
328 static void maxsel_proc(void)
329 {
330     imcalc_maxsel();
331     imcalc_draw(imcalc_tv_get());
332     redraw_graph_plot(imcalc_tv_get());
333     image_choice_reset();
334 }
335 
336 static void bshift_proc(void)
337 {
338     imcalc_bshift(sx,sy);
339     imcalc_draw(imcalc_tv_get());
340     redraw_graph_plot(imcalc_tv_get());
341 }
342 
343 static void     shift_proc()
344 {
345     imcalc_shift(sx,sy);
346     imcalc_draw(imcalc_tv_get());
347     redraw_graph_plot(imcalc_tv_get());
348 }
349 
350 static void aratio_proc(void)
351 {
352     imcalc_aratio(constant);
353     imcalc_draw(imcalc_tv_get());
354     redraw_graph_plot(imcalc_tv_get());
355     image_choice_reset();
356 }
357 
358 static void bratio_proc(void)
359 {
360     imcalc_bratio(constant);
361     imcalc_draw(imcalc_tv_get());
362     redraw_graph_plot(imcalc_tv_get());
363     image_choice_reset();
364 }
365 
366 static void sample_proc(void)
367 {
368     imcalc_sample(constant);
369     imcalc_draw(imcalc_tv_get());
370     redraw_graph_plot(imcalc_tv_get());
371     image_choice_reset();
372 }
373 
374 static void sqrt_proc(void)
375 {
376     imcalc_sqrt();
377     imcalc_draw(imcalc_tv_get());
378     redraw_graph_plot(imcalc_tv_get());
379     image_choice_reset();
380 }
381 
382 static void csqrt_proc(void)
383 {
384     imcalc_csqrt();
385     imcalc_draw(imcalc_tv_get());
386     redraw_graph_plot(imcalc_tv_get());
387     image_choice_reset();
388 }
389 
390 static void dilate_proc(void)
391 {
392     imcalc_dilate(range);
393     imcalc_draw(imcalc_tv_get());
394     redraw_graph_plot(imcalc_tv_get());
395     image_choice_reset();
396 }
397 
398 static void erode_proc(void)
399 {
400     imcalc_erode(range);
401     imcalc_draw(imcalc_tv_get());
402     redraw_graph_plot(imcalc_tv_get());
403     image_choice_reset();
404 }
405 
406 static void sqr_proc(void)
407 {
408     imcalc_sqr();
409     imcalc_draw(imcalc_tv_get());
410     redraw_graph_plot(imcalc_tv_get());
411     image_choice_reset();
412 }
413 
414 static void log_proc(void)
415 {
416     imcalc_log();
417     imcalc_draw(imcalc_tv_get());
418     redraw_graph_plot(imcalc_tv_get());
419     image_choice_reset();
420 }
421 
422 static void exp_proc(void)
423 {
424     imcalc_exp();
425     imcalc_draw(imcalc_tv_get());
426     redraw_graph_plot(imcalc_tv_get());
427     image_choice_reset();
428 }
429 
430 static void sin_proc(void)
431 {
432     imcalc_sin();
433     imcalc_draw(imcalc_tv_get());
434     redraw_graph_plot(imcalc_tv_get());
435     image_choice_reset();
436 }
437 
438 static void asin_proc(void)
439 {
440     imcalc_asin();
441     imcalc_draw(imcalc_tv_get());
442     redraw_graph_plot(imcalc_tv_get());
443     image_choice_reset();
444 }
445 
446 static void erf_proc(void)
447 {
448     imcalc_erf(&thresh);
449     imcalc_draw(imcalc_tv_get());
450     redraw_graph_plot(imcalc_tv_get());
451     tw_fglobal_reset(pth);
452     image_choice_reset();
453 }
454 
455 static void arg_proc(void)
456 {
457     imcalc_arg();
458     imcalc_draw(imcalc_tv_get());
459     redraw_graph_plot(imcalc_tv_get());
460     image_choice_reset();
461 }
462 
463 static void cis_proc(void)
464 {
465     imcalc_cis();
466     imcalc_draw(imcalc_tv_get());
467     redraw_graph_plot(imcalc_tv_get());
468     image_choice_reset();
469 }
470 
471 static void fft_proc(void)
472 {
473     imcalc_fft();
474     imcalc_draw(imcalc_tv_get());
475     redraw_graph_plot(imcalc_tv_get());
476     image_choice_reset();
477 }
478 
479 static void fft_inverse_proc(void)
480 {
481     imcalc_fft_inverse();
482     imcalc_draw(imcalc_tv_get());
483     redraw_graph_plot(imcalc_tv_get());
484     image_choice_reset();
485 }
486 
487 static void     optf_proc(void)
488 {
489     imcalc_optf(constant);
490     imcalc_draw(imcalc_tv_get());
491     redraw_graph_plot(imcalc_tv_get());
492 }
493 
494 static void powspec_proc(void)
495 {
496     imcalc_power_spectrum();
497     imcalc_draw(imcalc_tv_get());
498     redraw_graph_plot(imcalc_tv_get());
499     image_choice_reset();
500 }
501 
502 static void conj_proc(void)
503 {
504     imcalc_conj();
505     imcalc_draw(imcalc_tv_get());
506     redraw_graph_plot(imcalc_tv_get());
507 }
508 
509 static void real_proc(void)
510 {
511     imcalc_real();
512     imcalc_draw(imcalc_tv_get());
513     redraw_graph_plot(imcalc_tv_get());
514     image_choice_reset();
515 }
516 
517 static void imag_proc(void)
518 {
519     imcalc_imag();
520     imcalc_draw(imcalc_tv_get());
521     redraw_graph_plot(imcalc_tv_get());
522     image_choice_reset();
523 }
524 
525 static void xy_norm_proc(void)
526 {
527     imcalc_xy_norm(constant, sigma, thresh);
528     imcalc_draw(imcalc_tv_get());
529     redraw_graph_plot(imcalc_tv_get());
530     image_choice_reset();
531 }
532 
533 static void z_norm_proc(void)
534 {
535     void imcalc_z_norm(double *constant, Imregion *roi);
536     Imregion *roi;
537     Tv *tv = imcalc_tv_get();
538 
539     if (tv == NULL || tv->tv_screen == NULL)
540        roi = NULL;
541     else
542        roi = tv_get_im_roi(tv);
543 
544     imcalc_z_norm(&constant, roi);
545     (void) tw_fglobal_reset(pco);
546 }
547 
548 static void rm_dc_proc(void)
549 {
550     imcalc_rm_dc();
551     imcalc_draw(imcalc_tv_get());
552     redraw_graph_plot(imcalc_tv_get());
553     image_choice_reset();
554 }
555 
556 static void quad_proc(void)
557 {
558     imcalc_quad();
559     imcalc_draw(imcalc_tv_get());
560     redraw_graph_plot(imcalc_tv_get());
561     image_choice_reset();
562 }
563 
564 static void fgradx_proc(void)
565 {
566     imcalc_fgradx();
567     imcalc_draw(imcalc_tv_get());
568     redraw_graph_plot(imcalc_tv_get());
569 }
570 
571 static void fgrady_proc(void)
572 {
573     imcalc_fgrady();
574     imcalc_draw(imcalc_tv_get());
575     redraw_graph_plot(imcalc_tv_get());
576 }
577 
578 static void max_dir_proc(void)
579 {
580     imcalc_max_dir(thresh);
581     imcalc_draw(imcalc_tv_get());
582     image_choice_reset();
583 }
584 
585 static void nmax_proc(void)
586 {
587     imcalc_nmax(thresh,connect);
588     imcalc_draw(imcalc_tv_get());
589     image_choice_reset();
590 }
591 
592 static void thresh_proc(void)
593 {
594     imcalc_thresh(thresh);
595     imcalc_draw(imcalc_tv_get());
596     redraw_graph_plot(imcalc_tv_get());
597 }
598 
599 static void gauss_proc(void)
600 {
601     double acc;
602     acc = exp(-range*range/(2.0*sigma*sigma));
603     imcalc_gauss(sigma, acc);
604     imcalc_draw(imcalc_tv_get());
605     redraw_graph_plot(imcalc_tv_get());
606     image_choice_reset();
607 }
608 
609 static void lsf_smooth_proc(void)
610 {
611     imcalc_lsf_smooth(sigma, lr, ud);
612     imcalc_draw(imcalc_tv_get());
613     redraw_graph_plot(imcalc_tv_get());
614     image_choice_reset();
615 }
616 
617 static void median_proc(void)
618 {
619     imcalc_median();
620     imcalc_draw(imcalc_tv_get());
621     redraw_graph_plot(imcalc_tv_get());
622     image_choice_reset();
623 }
624 
625 static void rank_proc(void)
626 {
627     imcalc_rank((int)range,constant);
628     imcalc_draw(imcalc_tv_get());
629     redraw_graph_plot(imcalc_tv_get());
630     image_choice_reset();
631 }
632 
633 static void dx_proc(void)
634 {
635     imcalc_diffx();
636     imcalc_draw(imcalc_tv_get());
637     redraw_graph_plot(imcalc_tv_get());
638     image_choice_reset();
639 }
640 
641 static void dy_proc(void)
642 {
643     imcalc_diffy();
644     imcalc_draw(imcalc_tv_get());
645     redraw_graph_plot(imcalc_tv_get());
646     image_choice_reset();
647 }
648 
649 static void laplacian_proc(void)
650 {
651     imcalc_laplacian();
652     imcalc_draw(imcalc_tv_get());
653     redraw_graph_plot(imcalc_tv_get());
654     image_choice_reset();
655 }
656 
657 static void sqrgrad_proc(void)
658 {
659     imcalc_sqrgrad();
660     imcalc_draw(imcalc_tv_get());
661     redraw_graph_plot(imcalc_tv_get());
662     image_choice_reset();
663 }
664 
665 static void ddn_proc(void)
666 {
667     imcalc_ddn();
668     imcalc_draw(imcalc_tv_get());
669     redraw_graph_plot(imcalc_tv_get());
670     image_choice_reset();
671 }
672 
673 static void ddt_proc(void)
674 {
675     imcalc_ddt();
676     imcalc_draw(imcalc_tv_get());
677     redraw_graph_plot(imcalc_tv_get());
678     image_choice_reset();
679 }
680 
681 static void tsmooth_proc(void)
682 {
683     imcalc_tsmooth();
684     imcalc_draw(imcalc_tv_get());
685     redraw_graph_plot(imcalc_tv_get());
686     image_choice_reset();
687 }
688 
689 static void curv_proc(void)
690 {
691     imcalc_curv(constant,constant);
692     imcalc_draw(imcalc_tv_get());
693     redraw_graph_plot(imcalc_tv_get());
694     image_choice_reset();
695 }
696 
697 /* beth made this */
698 static void noise_proc(void)
699 {
700     Tv     *tv = imcalc_tv_get();
701     Imregion *roi;
702 
703     if (tv == NULL || tv->tv_screen == NULL)
704        roi = NULL;
705     else
706        roi = tv_get_im_roi(tv);
707     imcalc_noise(&constant,roi);
708     (void) tw_fglobal_reset(pco);
709 /* not necessary NAT
710     imcalc_draw(imcalc_tv_get());
711     imcalc_draw(imcal2_tv_get());
712     redraw_graph_plot(imcalc_tv_get());
713     image_choice_reset();
714 */
715 
716     return;
717 }
718 
719 static void window_proc(void)
720 {
721     imcalc_window(thresh,constant);
722     imcalc_draw(imcalc_tv_get());
723     redraw_graph_plot(imcalc_tv_get());
724     image_choice_reset();
725 }
726 
727 static void gwintz_bskel_proc(void)
728 {
729     Imrect *im1, *im2; /* working images */
730     unsigned long pixel_count;
731     int type;
732 
733     im1 = (Imrect *) stack_pop( &type );
734     im2 = (Imrect *) im_alloc(im1->height, im1->width, im1->region, im1->vtype);
735 
736     imcbthin1n( im1, im2, &pixel_count );
737     stack_push( im1, IMRECT, im_free );
738     imcalc_draw(imcalc_tv_get());
739     im_free( im2 );
740 }
741 
742 
743 static void create_tool_proc(void)
744 {
745     image_create_tool(100, 100);
746 }
747 
748 /* sic 22-4-96
749    function to print standard set of image information
750    to tina window display */
751 
752 static void image_info_proc(void)
753 {
754   Imrect *im;
755   char textout[100];
756   int type;
757 
758   /* check for an image on the stack, if not return with a warning */
759 
760   if (stack_check_types(IMRECT, NULL) == false)
761     {
762       error("\nimage_info_proc: non-imrect type on stack", warning);
763       return;
764     }
765 
766   im = (Imrect *) stack_pop(&type);
767 
768   format("\nImage Information\n-----------------\ndata type = ");
769   format_vtype(im->vtype);
770   sprintf(textout, "\nstored width = %i\nstored height = %i", im->width, im->height);
771   format(textout);
772   sprintf(textout, "\nactual width = %i\nactual height = %i", 
773           im->region->ux-im->region->lx, im->region->uy-im->region->ly);
774   format(textout);
775   sprintf(textout, "\nregion : lx = %i\n         ly = %i", im->region->lx, im->region->ly);
776   format(textout);
777   sprintf(textout, "\n         ux = %i\n         uy = %i", im->region->ux, im->region->uy);
778   format(textout);
779 
780   stack_push((void *) im, IMRECT, im_free);
781 }
782 
783 static void max_pos_proc(void)
784 {
785     Imrect *im;
786     int     type;
787     Vec2    pos = {Vec2_id};
788     Vec2    vec2();
789     Tv     *tv;
790     Tv     *imcalc_tv_get();
791     int     x, y;
792     float   max;
793 
794     im = (Imrect *) stack_inspect(&type);
795     if (type != IMRECT)
796         return;
797 
798     max = im_locate_max(im, &y, &x);
799     format("max value %5.3f \n",max);
800     thresh = max;
801     tw_fglobal_reset(pth);
802 
803     tv = imcalc_tv_get();
804     tv_set_color(tv, red);
805     pos = vec2((double) x, (double) y);
806     tv_cross2(tv, pos, 5);
807 }
808 
809 static void max_interest_proc(void)
810 {
811     Imrect *im;
812     int     type;
813     Vec2    pos = {Vec2_id};
814     Vec2    vec2();
815     Tv     *tv;
816     Tv     *imcalc_tv_get();
817     int     x, y;
818 
819     im = (Imrect *) stack_inspect(&type);
820     if (type != IMRECT)
821         return;
822 
823     im_locate_interest(im, &y, &x);
824 
825     tv = imcalc_tv_get();
826     tv_set_color(tv, red);
827     pos = vec2((double) x, (double) y);
828     tv_cross2(tv, pos, 5);
829 }
830 
831 static void imcalc_undo_proc()
832 {
833     extern void imcalc_undo(Imrect *im1, Imrect*im2, Bool f);
834     imcalc_undo(NULL,NULL,true);
835     imcalc_draw(imcalc_tv_get());
836     imcalc_draw(imcal2_tv_get());
837     redraw_graph_plot(imcalc_tv_get());
838     image_choice_reset();
839 
840 }
841 
842 
843 /********** Choice item callbacks **********/
844 
845 /**** Tv choice callback ****/
846 
847 static void tv_choice_proc(int val)
848 {
849     switch (val)
850     {
851         case 0:
852         tv_set_next(imcalc_tv_get());
853         break;
854         case 1:
855         tv_set_next(imcal2_tv_get());
856         break;
857         case 2:
858         tv_set_next(imcmem_tv_get());
859         break;
860         case 3:
861         tv_set_next(imcalc_graph_tv_get());
862     }
863 }
864 
865 /**** Imcalc mouse choice callback ****/
866 
867 static void imcalc_mouse_choice_proc(int val)
868 {
869     Tv_mouse connmask_mouse();
870     Tv_mouse imcalc_grey_level_mouse();
871     Tv_mouse imcalc_prof_mouse();
872     Tv_mouse null_mouse();
873 
874     switch (val)
875     {
876     case 0:
877         tv_set_mouse(imcalc_tv_get(), imcalc_grey_level_mouse());
878         graph_set_type(PL_CTR_DATA);
879         break;
880     case 1:
881         tv_set_mouse(imcalc_tv_get(), connmask_mouse());
882         graph_set_type(PL_CTR_DATA);
883         break;
884     case 2:
885         tv_set_mouse(imcalc_tv_get(), imcalc_prof_mouse());
886         graph_set_type(PL_GRAPH_DATA);
887         break;
888     case 3:
889         tv_set_mouse(imcalc_tv_get(), imcalc_prof_mouse());
890         graph_set_type(PL_HIST_DATA);
891         break;
892     }
893     (void) tv_set_activity(imcalc_tv_get(), MOUSE);
894     redraw_graph_plot(imcalc_tv_get());
895 }
896 
897 static void image_type_choice_proc(int val)
898 {
899     extern void imcalc_undo(Imrect * im1 , Imrect * im2 , Bool f);
900     Imrect *im,*im2;
901     int type, vtype;
902 
903     if (im=(Imrect *) stack_inspect(&type))
904     {
905         vtype = im->vtype;
906     }
907     switch (val)
908     {
909     case 0:
910         if (type == IMRECT || type==EDGERECT)
911         {
912            im = (Imrect *)stack_pop(&type);
913            im2 = im_bthresh(thresh, im);
914            stack_push((void *)im_cast(im2, uchar_v),IMRECT,im_free);
915            im_free(im2);
916            imcalc_undo(im,NULL,false);
917            imcalc_draw(imcalc_tv_get());
918         }
919         break;
920     case 1:
921         if (vtype != uchar_v &&type == IMRECT)
922         {
923            im = (Imrect *)stack_pop(&type);
924            stack_push((void *)im_cast(im, uchar_v),IMRECT,im_free);
925            imcalc_undo(im,NULL,false);
926            imcalc_draw(imcalc_tv_get());
927         }
928         break;
929     case 2:
930         if (vtype != short_v &&type == IMRECT)
931         {
932            im = (Imrect *)stack_pop(&type);
933            stack_push((void *)im_cast(im, short_v),IMRECT,im_free);
934            imcalc_undo(im,NULL,false);
935            imcalc_draw(imcalc_tv_get());
936         }
937         break;
938     case 3:
939         if (vtype != float_v && type==IMRECT)
940         {
941            im = (Imrect *)stack_pop(&type);
942            if (vtype != complex_v)
943            {
944               stack_push(im_cast(im, float_v),IMRECT,im_free);
945            }
946            else
947            {
948               stack_push((void *)im_im(im),IMRECT,im_free);
949               stack_push((void *)im_re(im),IMRECT,im_free);
950               imcalc_draw(imcal2_tv_get());
951            }
952            imcalc_undo(im,NULL,false);
953            imcalc_draw(imcalc_tv_get());
954         }
955         break;
956     case 4:
957         if (vtype != complex_v && type==IMRECT)
958         {
959            im = (Imrect *)stack_pop(&type);
960            im2 = stack_inspect(&type);
961            if (type==IMRECT&&im2->vtype!=complex_v)
962            {
963               im2 = (Imrect *)stack_pop(&type);
964               stack_push((void *)imz_cmplx(im, im2),IMRECT,im_free);
965               imcalc_undo(im,im2,false);
966            }
967            else
968            {
969               stack_push((void *)im,IMRECT,im_free);
970            }
971            imcalc_draw(imcalc_tv_get());
972            imcalc_draw(imcal2_tv_get());
973         }
974         break;
975     case 5:
976         if (vtype != ptr_v && type==IMRECT)
977         {
978            imcalc_nmax(thresh,connect);
979            imcalc_draw(imcalc_tv_get());
980         }
981         break;
982     }
983     redraw_graph_plot(imcalc_tv_get());
984 }
985 
986 /********** Paramter dialog callbacks **********/
987 
988 /**** Imcalc parameter dialog box callback ****/
989 
990 static void param_store_proc()
991 {
992    old_connect = connect;
993    old_sx = sx;
994    old_sy = sy;
995    old_lr = lr;
996    old_ud = ud;
997    old_scale = scale;
998    old_sigma = sigma;
999    old_thresh = thresh;
1000    old_constant = constant;
1001    old_range = range;
1002 }
1003 
1004 static void param_restore_proc()
1005 {
1006    connect = old_connect;
1007    sx = old_sx;
1008    sy = old_sy;
1009    lr = old_lr;
1010    ud = old_ud;
1011    scale = old_scale;
1012    sigma = old_sigma;
1013    thresh = old_thresh;
1014    constant = old_constant;
1015    range = old_range;
1016    (void) tw_fglobal_reset(psc);
1017    (void) tw_fglobal_reset(psi);
1018    (void) tw_fglobal_reset(pac);
1019    (void) tw_fglobal_reset(pth);
1020    (void) tw_fglobal_reset(pco);
1021    (void) tw_fglobal_reset(pra);
1022    (void) tw_iglobal_reset(pcon);
1023    (void) tw_iglobal_reset(psx);
1024    (void) tw_iglobal_reset(psy);
1025    (void) tw_iglobal_reset(plr);
1026    (void) tw_iglobal_reset(pud);
1027 }
1028 
1029 static void invert_const_proc()
1030 {
1031    if (constant!=0.0) constant = 1.0/constant;
1032    (void) tw_fglobal_reset(pco);
1033 }
1034 
1035 static void swap_const_proc()
1036 {
1037    double temp = constant;
1038    constant = thresh;
1039    thresh = temp;
1040    (void) tw_fglobal_reset(pco);
1041    (void) tw_fglobal_reset(pth);
1042 }
1043 
1044 static void imcalc_dialog_proc(void)
1045 {
1046     static void *dialog = NULL;
1047 
1048     if (dialog)
1049     {
1050         tw_show_dialog(dialog);
1051         return;
1052     }
1053     dialog = tw_dialog("Imcalc Parameters");
1054 
1055     psx = (void *) tw_iglobal("sx:", &sx, 2);
1056     psy = (void *) tw_iglobal("sy:", &sy, 2);
1057     tw_newrow();
1058     plr = (void *) tw_iglobal("left/right:", &lr, 2);
1059     pud = (void *) tw_iglobal("up/down:", &ud, 2);
1060     tw_newrow();
1061     psi = (void *) tw_fglobal("sigma     :", &sigma, 16);
1062     tw_newrow();
1063     pco = (void *) tw_fglobal("const     :", &constant, 16);
1064     tw_button("1/const", invert_const_proc, NULL); 
1065     tw_newrow();
1066     pra = (void *) tw_fglobal("range     :", &range, 16);
1067     tw_newrow();
1068     psc = (void* ) tw_fglobal("scale     :", &scale, 16);
1069     tw_newrow();
1070     pth = (void *) tw_fglobal("thres     :", &thresh, 16);
1071     tw_button("swap", swap_const_proc, NULL); 
1072     tw_newrow();
1073     pcon = (void *) tw_iglobal("connect:", &connect, 2);
1074     tw_button("store", param_store_proc, NULL);
1075     tw_button("restore", param_restore_proc, NULL);
1076 
1077     tw_end_dialog();
1078 }
1079 
1080 /********** Tool creation **********/
1081 
1082 void    imcalc_tool(int x, int y)
1083 {
1084     static void *tv_screen = NULL;
1085     Imrect *im;
1086     int vtype,type,val;
1087 
1088     if (tv_screen)
1089     {
1090         tw_show_tool(tv_screen);
1091         return;
1092     }
1093     tv_proc();
1094 
1095     tv_screen = tw_tool("Imcalc Tool", x, y);
1096 
1097     tw_choice("Tv List :    ",
1098               tv_choice_proc, 0, "imcalc", "imcalc2", "register", "graph", NULL);
1099 
1100     tw_newrow();
1101 
1102     tw_choice("Imcalc Mice: ",
1103            imcalc_mouse_choice_proc, 0, "grey", "conn", "prof", "hist", NULL);
1104     tw_help_button("imcalc_tool");
1105 
1106     tw_newrow();
1107     if (im=(Imrect *) stack_inspect(&type))
1108     {
1109         if(type==IMRECT)
1110         {
1111            vtype = im->vtype;
1112            if (vtype==uchar_v) val = 1;
1113            if (vtype==short_v) val = 2;
1114            if (vtype==ushort_v) val = 2;
1115            if (vtype==int_v) val = 2;
1116            if (vtype==float_v) val = 3;
1117            if (vtype==complex_v) val = 4;
1118            if (vtype==ptr_v) val = 5;
1119         }
1120         else val = 0;
1121     }
1122     else val = 0;
1123 
1124     image_choice = tw_choice("Image type:  ",
1125            image_type_choice_proc,val,"bin","chr","int","flt","cmp","ptr", NULL);
1126 
1127     tw_newrow();
1128 
1129     tw_button("Imcalc Params", imcalc_dialog_proc, NULL);
1130     tw_button(" Create Tool ", create_tool_proc, NULL);
1131 
1132     /* sic 22-4-96
1133        function to print standard set of image information
1134        to tina window display */
1135 
1136     tw_button(" Info ", image_info_proc, NULL);
1137     tw_button(" Undo ", imcalc_undo_proc, NULL);
1138 
1139     tw_newrow();
1140 
1141     tw_button(" C ", clear_proc, NULL);
1142     tw_button(" CA ", clear_all_proc, NULL);
1143     tw_button("store", store_proc, NULL);
1144     tw_button("fetch", fetch_proc, NULL);
1145     tw_button("dup", dup_proc, NULL);
1146     tw_button("flp", flip_proc, NULL);
1147     tw_button("roi", roi_proc, NULL);
1148 
1149     tw_newrow();
1150 
1151     tw_button("scale", rescale_proc, NULL);
1152     tw_button("xrat", bratio_proc, NULL);
1153     tw_button("yrat", aratio_proc, NULL);
1154     tw_button("smpl", sample_proc, NULL);
1155     tw_button("shift", shift_proc, NULL);
1156     tw_button("bshift", bshift_proc, NULL);
1157 
1158     tw_newrow();
1159 
1160     tw_button(" + ", sum_proc, NULL);
1161     tw_button(" - ", diff_proc, NULL);
1162     tw_button(" * ", prod_proc, NULL);
1163     tw_button(" / ", div_proc, NULL);
1164     tw_button("-1* ", minus_proc, NULL);
1165     tw_button(" +k ", add_proc, NULL);
1166     tw_button(" k* ", times_proc, NULL);
1167     tw_button("max", maxsel_proc, NULL);
1168 
1169     tw_newrow();
1170 
1171     tw_button("sqrt", sqrt_proc, NULL);
1172     tw_button("csqrt", csqrt_proc, NULL);
1173     tw_button("sqr", sqr_proc, NULL);
1174     tw_button("log", log_proc, NULL);
1175     tw_button("exp", exp_proc, NULL);
1176     tw_button("sin", sin_proc, NULL);
1177     tw_button("asin", asin_proc, NULL);
1178 
1179     tw_newrow();
1180 
1181     tw_button("thres", thresh_proc, NULL);
1182     tw_button(" lsf ", lsf_smooth_proc, NULL);
1183     tw_button(" med ", median_proc, NULL);
1184     tw_button("rank", rank_proc, NULL);
1185     tw_button("gauss", gauss_proc, NULL);
1186     tw_button("tsmooth", tsmooth_proc, NULL);
1187 
1188     tw_newrow();
1189 
1190     tw_button("diffx", dx_proc, NULL);
1191     tw_button("diffy", dy_proc, NULL);
1192     tw_button("grdsq", sqrgrad_proc, NULL);
1193     tw_button("lap", laplacian_proc, NULL);
1194     tw_button("ddn", ddn_proc, NULL);
1195     tw_button("ddt", ddt_proc, NULL);
1196     tw_button("crv", curv_proc, NULL);
1197 
1198     tw_newrow();
1199 
1200     tw_button("xy norm ", xy_norm_proc, NULL);
1201     tw_button("z norm ", z_norm_proc, NULL);
1202     tw_button("arg", arg_proc, NULL);
1203     tw_button("cis", cis_proc, NULL);
1204     tw_button("conj", conj_proc, NULL);
1205     tw_button("optf", optf_proc, NULL);
1206 
1207     tw_newrow();
1208 
1209     tw_button("rmdc", rm_dc_proc, NULL);
1210     tw_button("quad", quad_proc, NULL);
1211     tw_button("fft", fft_proc, NULL);
1212     tw_button("ffti", fft_inverse_proc, NULL);
1213     tw_button("power", powspec_proc, NULL);
1214     tw_button("fdx", fgradx_proc, NULL);
1215     tw_button("fdy", fgrady_proc, NULL);
1216 
1217     tw_newrow();
1218 
1219 /*
1220     tw_button("max con", nmax_proc, NULL);
1221 */
1222     tw_button("erfp", erf_proc, NULL);
1223     tw_button("max pos", max_pos_proc, NULL);
1224 /*    tw_button("max crv", max_interest_proc, NULL);
1225 */
1226     tw_button("skel", gwintz_bskel_proc,NULL);
1227     tw_button("erode", erode_proc, NULL);
1228     tw_button("dilate", dilate_proc, NULL);
1229     tw_button("zpad", zpad_proc, NULL);
1230     tw_newrow();
1231  
1232     tw_button("scat", scat_proc, NULL);
1233     tw_button("iscat", iscat_proc, NULL);
1234     tw_button("dscat", dscat_proc, NULL);
1235     tw_button("hist", hist_proc, NULL);
1236     tw_button("noise", noise_proc, NULL);
1237     tw_button("window", window_proc, NULL);
1238 
1239 
1240     tw_end_tool();
1241 }
1242 

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