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

Linux Cross Reference
Tina5/tina-tools/tinatool/tlbase/tlbaseImc_view.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_view.c,v $
 37  * Date    :  $Date: 2007/02/15 01:55:50 $
 38  * Version :  $Revision: 1.6 $
 39  * CVS Id  :  $Id: tlbaseImc_view.c,v 1.6 2007/02/15 01:55:50 paul Exp $
 40  *
 41  * Author  :  Legacy TINA
 42  *
 43  * Notes :
 44  *
 45  *********
 46 */
 47 
 48 #include "tlbaseImc_view.h"
 49 
 50 #if HAVE_CONFIG_H
 51 #include <config.h>
 52 #endif
 53 
 54 #include <stdio.h>
 55 #include <math.h>
 56 #include <tina/sys/sysDef.h>
 57 #include <tina/sys/sysPro.h>
 58 #include <tina/math/mathDef.h>
 59 #include <tina/math/mathPro.h>
 60 #include <tina/image/imgDef.h>
 61 #include <tina/image/imgPro.h>
 62 #include <tinatool/draw/drawDef.h>
 63 #include <tinatool/draw/drawPro.h>
 64 #include <tinatool/tlbase/tlbase_InfrDef.h>
 65 #include <tinatool/tlbase/tlbase_InfrPro.h>
 66 #include <tinatool/tlbase/tlbaseImc_imc.h>
 67 #include <tinatool/tlbase/tlbaseImc_view.h>
 68 #include <tinatool/gphx/x11/gphxX11_color.h>
 69 
 70 static Imrect *reg_a=NULL;
 71 static Imrect *copy_im=NULL;
 72 static int reg_type = 0;
 73 static Vec2 /* select */ selct;
 74 static double *stored_range =NULL;
 75 
 76 void    imcalc_reg_set(Imrect *im, int type)
 77 {
 78      if (im!=NULL)
 79      {
 80         if (reg_a!=NULL) im_free(reg_a);
 81         reg_a = im;
 82         reg_type = type;
 83      }
 84 }
 85 
 86 Imrect *imcalc_reg_get(void)
 87 {
 88     return(reg_a);
 89 }
 90 
 91 int imcalc_reg_type(void)
 92 {
 93     return(reg_type);
 94 }
 95 
 96 static void cmap_set_anaglyph(Tv *tv)
 97 {
 98     extern void tv_screen_cmap_find_and_install ();
 99 
100     if (tv && tv->tv_screen)
101       {
102           Bool (*cmap_create_fn) () = NULL;
103           extern void tv_cmap_create_fn_set ();
104 
105           tv->cmap_create_fn = tv_anag_cmap_create;
106           tv_screen_cmap_find_and_install (tv, tv->tv_screen);
107           tv_screen_color_set(tv->tv_screen, tv->cmap_data_visible->std_lut[tv->color]);
108       }
109 }
110 
111 static void cmap_set_standard(Tv *tv)
112 {
113     extern void tv_screen_cmap_find_and_install ();
114 
115     if (tv && tv->tv_screen )
116       {
117           Bool (*cmap_create_fn) () = NULL;
118           extern void tv_cmap_create_fn_set ();
119 
120           tv->cmap_create_fn = tv_standard_cmap_create;
121           tv_screen_cmap_find_and_install (tv, tv->tv_screen);
122           tv_screen_color_set(tv->tv_screen, tv->cmap_data_visible->std_lut[tv->color]);
123       }
124 }
125 
126 
127 
128 static void fulldraw(Tv * tv)
129 {
130     int     type;
131     Imrect *im,*im1,*im2;
132 
133     im = (Imrect *) stack_inspect(&type);
134     switch (type)
135     {
136     case IMRECT:
137         tv_erase(tv);
138         if (im->vtype!=complex_v)
139         {
140            cmap_set_standard(tv);
141            im1 = imf_scale_nzero(im, 0.0, 255.0);
142            tv_imrect2(tv, im1);
143            im_free(im1);
144         }
145         else 
146         {
147            cmap_set_anaglyph(tv);  
148            im1 = imf_scale_nzero(im_re(im), 0.0, 255.0); 
149            im2 = imf_scale_nzero(im_im(im), 0.0, 255.0); 
150            tv_imrect_anaglyph(tv, im1, im2, 0.0, 255.0);
151            im_free(im1); 
152            im_free(im2); 
153         }
154         break;
155     case EDGERECT:
156         tv_edges_conn(tv, im);
157         tv_strings(tv, im);
158         break;
159     }
160 }
161 
162 void    imcalc_draw(Tv *tv)
163 {
164     if (tv!=NULL)
165     {
166        tv_free_background(tv);
167        tv_repaint(tv);
168     }
169 }
170 
171 static void skeldraw(Tv * tv)
172 {
173     int     type;
174     Imrect *im;
175 
176     im = (Imrect *) stack_inspect(&type);
177     if (type == IMRECT)
178         tv_imrect_skel(tv, im);
179 }
180 
181 static void init(Tv * tv)
182 {
183     Imrect *im;
184     int     type;
185 
186     im = (Imrect *) stack_inspect(&type);
187     if ((type == IMRECT || type == EDGERECT) && im != NULL)
188         tv_camera2_image(tv, im->width, im->height);
189 }
190 
191 static void fulldraw2(Tv * tv)
192 {
193     int     type;
194     int     type2;
195     Imrect *im;
196     Imrect *im2;
197 
198     im = (Imrect *) stack_pop(&type);
199     if (im!=NULL)
200     {
201        im2 = (Imrect *) stack_inspect(&type2);
202        switch (type2)
203        {
204           case IMRECT:
205              tv_erase(tv);
206              im2 = imf_scale_nzero(im2, 0.0, 255.0);
207              tv_imrect2(tv, im2);
208              im_free(im2);
209              break;
210           case EDGERECT:
211              tv_edges_conn(tv, im2);
212              tv_strings(tv, im2);
213              break;
214        }
215        stack_push(im,type,im_free);
216     }
217 }
218 
219 static void skeldraw2(Tv * tv)
220 {
221     int     type;
222     int     type2;
223     Imrect *im;
224     Imrect *im2;
225 
226     im = (Imrect *) stack_pop(&type);
227     if (im!=NULL)
228     {
229        im2 = (Imrect *) stack_inspect(&type2);
230        if (type2 == IMRECT)
231            tv_imrect_skel(tv, im2);
232        stack_push(im,type,im_free);
233     }
234 }
235 
236 static void fulldrawreg(Tv * tv)
237 {
238     int     type;
239     int     type2;
240     Imrect *im;
241     Imrect *im2;
242 
243     if (reg_a!=NULL)
244     {
245        switch (reg_type)
246        {
247           case IMRECT:
248              tv_erase(tv);
249              im2 = imf_scale_nzero(reg_a, 0.0, 255.0);
250              tv_imrect2(tv, im2);
251              im_free(im2);
252              break;
253           case EDGERECT:
254              tv_edges_conn(tv, reg_a);
255              tv_strings(tv, reg_a);
256              break;
257        }
258     }
259 }
260 
261 static void skeldrawreg(Tv * tv)
262 {
263     int     type;
264     int     type2;
265     Imrect *im;
266 
267     if (reg_a!=NULL)
268     {
269        if (reg_type == IMRECT)
270           tv_imrect_skel(tv, reg_a);
271     }
272 }
273 
274 Tv     *imcalc_tv_make(void)
275 {
276     static Tv *tv;
277 
278     tv = tv_create("imcalc");
279     (void) tv_set_backdraw(tv, fulldraw);
280     (void) tv_set_skeldraw(tv, skeldraw);
281     tv_set_init(tv, init);
282     (void) tv_set_zoomlevel(tv, IMZOOM);
283 
284     return (tv);
285 }
286 
287 Tv     *imcal2_tv_make(void)
288 {
289     static Tv *tv;
290 
291     tv = tv_create("imcalc2");
292     (void) tv_set_backdraw(tv, fulldraw2);
293     (void) tv_set_skeldraw(tv, skeldraw2);
294     tv_set_init(tv, init);
295     (void) tv_set_zoomlevel(tv, IMZOOM);
296     return (tv);
297 }
298 
299 Tv     *imcmem_tv_make(void)
300 {
301     static Tv *tv;
302 
303     tv = tv_create("imcalc reg");
304     (void) tv_set_backdraw(tv, fulldrawreg);
305     (void) tv_set_skeldraw(tv, skeldrawreg);
306     tv_set_init(tv, init);
307     (void) tv_set_zoomlevel(tv, IMZOOM);
308     return (tv);
309 }
310 
311 void    imcalc_draw_scale(void)
312 {
313     Imrect *im;
314     int     type;
315 
316     im = (Imrect *) stack_inspect(&type);
317     if (type != IMRECT)
318         return;
319 
320     im = imf_scale(im, 0.0, 255.0);
321     tv_imrect2(imcalc_tv_get(), im);
322     im_free(im);
323 }
324 
325 static void grey_level(Tv * tv, Ipos pos)
326 {
327     Vec2    v = {Vec2_id};
328     Vec2    tv_backproj2();
329     int     x, y;
330     double  val;
331     Imrect *im;
332     int     type;
333 
334     im = (Imrect *) stack_inspect(&type);
335     if (type != IMRECT)
336     {
337         error("grey_level: no image on stack", warning);
338         return;
339     }
340     v = tv_backproj2(tv, pos);
341     x = tina_int(vec2_x(v));
342     y = tina_int(vec2_y(v));
343     val = im_get_pixf(im, y, x);
344 
345     format("pos %10d %10d:     grey level = %3.2f\n", x, y, val);
346 }
347 
348 static void store_loc(Tv * tv, Ipos pos)
349 {
350     Vec2    cp;
351     Vec2    tv_backproj2();
352     int     type;
353     Imrect *im;
354 
355     tv_save_draw(tv);
356     tv_set_overlay(tv);
357 
358     cp = tv_backproj2(tv, pos);
359     tv_bigdot2(tv, cp, 2);
360     tv_reset_draw(tv);
361 
362     selct = cp;
363 
364     im = (Imrect *) stack_inspect(&type);
365     if (type != IMRECT)
366     {
367         error("copy: no image on stack", warning);
368         return;
369     }
370     else
371     {
372         error("pasteing will permanently modify this image", warning);
373     }
374 
375     if (copy_im) im_free(copy_im);
376     copy_im = im_copy(im);
377 }
378 
379 static void copy_region(Tv * tv, Ipos pos)
380 {
381     Vec2    v = {Vec2_id};
382     Vec2    tv_backproj2();
383     int     x, y;
384     double  val, fac, range;
385     Imrect *im;
386     int     type;
387     Imregion       *roi;
388     float          *row1, *row2;
389     int             lx, ux, ly, uy;
390     int             i, j;
391 
392 
393     im = (Imrect *) stack_inspect(&type);
394     if (type != IMRECT)
395     {
396         error("grey_level: no image on stack", warning);
397         return;
398     }
399     if(stored_range!=NULL) range = *stored_range;
400     else return;
401 
402     imcalc_undo(im_copy(im),NULL,false);
403     v = tv_backproj2(tv, pos);
404 
405     roi = im->region;
406     if (roi == NULL)
407             return;
408     lx = roi->lx;
409     ux = roi->ux;
410     ly = roi->ly;
411     uy = roi->uy;
412 
413     row1 = fvector_alloc(lx, ux);
414     row2 = fvector_alloc(lx, ux);
415 
416     for (i = tina_int(v.el[1] - 3.0*range) ; 
417          i <  tina_int(v.el[1] + 3.0*range); 
418        ++i)
419     {
420          im_get_rowf(row1, copy_im, i - tina_int(v.el[1]-selct.el[1]), lx, ux);
421          im_get_rowf(row2, im, i, lx, ux);
422 
423          
424          for (j = tina_int(v.el[0] - 3.0*range); 
425               j < tina_int(v.el[0] + 3.0*range); ++j)
426          {
427                  fac = exp( -( (i-v.el[1])*(i-v.el[1]) + (j-v.el[0])*(j-v.el[0]) )/
428                               (2.0*range*range) );
429                  row2[j] = (1.0-fac)*row2[j] + fac*row1[j - tina_int(v.el[0]-selct.el[0])];
430          }
431          im_put_rowf(row2, im, i, tina_int(v.el[0] - 3.0*range), 
432                                   tina_int(v.el[0] + 3.0*range));
433     }
434 
435     fvector_free(row1, lx);
436     fvector_free(row2, lx);
437     imcalc_draw(tv);
438 }
439 
440 void set_copy_range(double *range)
441 {
442    stored_range = range;
443 }
444 
445 Tv_mouse imcalc_grey_level_mouse(void)
446 {
447     return (mouse_define(MOUSE_NAME, "grey",
448                          LEFT_DOWN, grey_level, LEFT_NAME, "print", 
449                          MIDDLE_DOWN, store_loc, MIDDLE_NAME, "copy", 
450                          RIGHT_DOWN, copy_region, RIGHT_NAME, "paste",
451                          NULL));
452 }
453 
454 
455 

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