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

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

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