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

Linux Cross Reference
Tina5/tina-tools/tinatool/tlbase/tlbaseImc_conn_mouse.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_conn_mouse.c,v $
 37  * Date    :  $Date: 2007/02/15 01:55:50 $
 38  * Version :  $Revision: 1.4 $
 39  * CVS Id  :  $Id: tlbaseImc_conn_mouse.c,v 1.4 2007/02/15 01:55:50 paul Exp $
 40  *
 41  * Author  :  Legacy TINA
 42  *
 43  * Notes :
 44  *
 45  *********
 46 */
 47 
 48 #include "tlbaseImc_conn_mouse.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 <tinatool/tlbase/tlbase_InfrDef.h>
 61 #include <tinatool/tlbase/tlbase_InfrPro.h>
 62 #include <tinatool/draw/drawDef.h>
 63 #include <tinatool/draw/drawPro.h>
 64 #include <tina/image/imgDef.h>
 65 #include <tina/image/imgPro.h>
 66 #include <tinatool/tlbase/tlbaseImc_imc.h>
 67 #include <tinatool/tlbase/tlbaseImc_tool.h>
 68 #include <tinatool/tlbase/tlbaseImc_view.h>
 69 
 70 static Imrect *connmask = NULL;
 71 static float old_x,old_y;
 72 static Vec2 p1 = {Vec2_id};
 73 static Vec2 p2 = {Vec2_id};
 74 static Tv *display_tv = NULL;
 75 
 76 static void pixelxy(int x, int y)
 77 {
 78    Vec2    v = {Vec2_id} ;
 79 
 80    v.el[0] = x+0.5;
 81    v.el[1] = y+0.5;
 82    tv_pixel2(display_tv,v);
 83 }
 84 
 85 /* 16.8.06 mjs changed from static in order to be able to access function externally */
 86 void  conn_add_regions(Tv *tv, Ipos pos)
 87 {
 88    Imrect *mask = NULL, *fmask=NULL, *fconnmask;
 89    Imregion roi;
 90    Vec2    v = {Vec2_id};
 91    int     i, j;
 92    int     x, y, x1, y1, x2, y2, n, type;
 93 
 94    display_tv = tv;
 95    tv_reset_draw(tv);
 96 
 97    if (stack_check_types(IMRECT, NULL) == false)
 98    {
 99      error("conn_add_regions: wrong type on stack", warning);
100      return;
101    }
102   mask = (Imrect *) stack_inspect(&type);
103 
104   roi = *(mask->region);
105   roi.lx -= 1;
106   roi.ux += 1;
107   roi.ly -= 1;
108   roi.uy += 1;
109 
110 
111   if (mask->vtype == complex_v)
112   {
113      fmask = im_im(mask);
114      mask = fmask;
115   }
116   if (connmask == NULL)
117      connmask = im_alloc(mask->height+2, mask->width+2, &roi, char_v);
118   x1 = tina_int(vec2_x(p1));
119   y1 = tina_int(vec2_y(p1));
120   x2 = tina_int(vec2_x(p2));
121   y2 = tina_int(vec2_y(p2));
122   if (x1>x2)
123   {
124      x1 = tina_int(vec2_x(p2));
125      x2 = tina_int(vec2_x(p1));
126   }
127   if (y1>y2)
128   {
129      y1 = tina_int(vec2_y(p2));
130      y2 = tina_int(vec2_y(p1));
131   }
132   tv_color_set(tv, red);
133   for (x = x1; x<=x2; x++)
134   {
135      for (y = y1; y<=y2 ; y++)
136      {
137         if (im_get_pix(mask, y, x) != 0 && im_get_pix(connmask, y, x)==0)
138            imc_connpixels(mask, connmask, roi,  x, y, pixelxy);
139      }
140   }
141   if (fmask!=NULL) im_free(fmask);
142 }
143 
144 static void conn_delete_pixel(Tv *tv, Ipos pos)
145 {
146    Imrect *mask;
147    Vec2    v = {Vec2_id};
148    int     x, y, type;
149    Complex pixval;
150 
151    mask = (Imrect *) stack_inspect(&type);
152    if (mask==NULL) return;
153    imcalc_undo(im_copy(mask),NULL,false);
154    v = tv_backproj2(tv, pos);
155    x = tina_int(vec2_x(v));
156    y = tina_int(vec2_y(v));
157    pixval.x =0;
158    pixval.y =0;
159    im_put_pixz(pixval,mask,y,x);
160    tv_color_set(tv, red);
161    tv_pixel2(tv,v);
162    old_x = x;
163    old_y = y;
164 }
165 
166 static void conn_delete_line(Tv *tv, Ipos pos)
167 {
168    Imrect *mask;
169    Vec2    v = {Vec2_id};
170    int     x, y, type;
171    float   frac_x, frac_y;
172    Complex pixval;
173 
174    mask = (Imrect *) stack_inspect(&type);
175    if (mask==NULL) return;
176    v = tv_backproj2(tv, pos);
177    x = tina_int(vec2_x(v));
178    y = tina_int(vec2_y(v));
179    pixval.x = 0;
180    pixval.y = 0;
181    tv_color_set(tv, red);
182    if (fabs(x-old_x)>fabs(y-old_y))
183    {
184       if (x<old_x)
185          for (frac_x=x;frac_x<old_x;frac_x++)
186          {
187             frac_y = y + (frac_x - x)*(old_y - y)/(old_x - x);
188             im_put_pixz(pixval,mask,tina_int(frac_y),tina_int(frac_x));
189             vec2_x(v) = tina_int(frac_x);
190             vec2_y(v) = tina_int(frac_y);
191             tv_pixel2(tv,v);
192          }
193       else
194         for (frac_x=x;frac_x>old_x;frac_x--)
195         {
196             frac_y = y + (frac_x - x)*(old_y - y)/(old_x - x);
197             im_put_pixz(pixval,mask,tina_int(frac_y),tina_int(frac_x));
198             vec2_x(v) = tina_int(frac_x);
199             vec2_y(v) = tina_int(frac_y);
200             tv_pixel2(tv,v);
201         }
202    }
203    else
204    {
205      if (y<old_y)
206          for (frac_y=y;frac_y<old_y;frac_y++)
207          {
208             frac_x = x + (frac_y - y)*(old_x - x)/(old_y - y);
209             im_put_pixz(pixval,mask,tina_int(frac_y),tina_int(frac_x));
210             vec2_x(v) = tina_int(frac_x);
211             vec2_y(v) = tina_int(frac_y);
212             tv_pixel2(tv,v);
213          }
214       else
215         for (frac_y=y;frac_y>old_y;frac_y--)
216         {
217             frac_x = x + (frac_y - y)*(old_x - x)/(old_y - y);
218             im_put_pixz(pixval,mask,tina_int(frac_y),tina_int(frac_x));
219             vec2_x(v) = tina_int(frac_x);
220             vec2_y(v) = tina_int(frac_y);
221             tv_pixel2(tv,v);
222         }
223    }
224    old_x = x;
225    old_y = y;
226 }
227 
228 static void conn_redraw(Tv *tv, Ipos pos)
229 {
230    imcalc_draw(tv);
231 }
232 
233  /* 16.8.06 mjs changed from static in order to be able to access function externally */
234 void conn_seg_regions(Tv *tv, Ipos pos)
235 {
236   Imrect *mask,*fmask,*xor_mask,*improd;
237   int     type;
238 
239   if (stack_check_types(IMRECT, NULL) == false)
240   {
241      error("conn_add_regions: wrong type on stack", warning);
242      return;
243   }
244   if (connmask==NULL)
245   {
246      format("no region selected \n");
247      return;
248   }
249   mask = (Imrect *) stack_pop(&type);
250   if (mask->vtype == complex_v)
251   {
252      fmask = im_im(mask);
253      xor_mask = im_re(mask);
254      improd = imf_prod(xor_mask,connmask);
255      imf_accum_inplace(connmask,-2.0,improd);
256      im_free(improd);
257      imf_accum_inplace(connmask,1.0,xor_mask);
258      im_free(mask);
259      im_free(xor_mask);
260      mask = fmask;
261   }
262 
263   stack_push((void *)imz_cmplx(connmask,mask), IMRECT, im_free);
264   im_free(mask);
265   im_free(connmask);
266   connmask = NULL;
267 
268   imcalc_draw(tv);
269   image_choice_reset();
270 }
271 
272 /* 16.8.06 mjs changed from static in order to be able to access function externally */
273 void conn_roi(Tv *tv, Ipos pos)
274 {
275    tv_set_overlay(tv);
276    p1 = p2 = tv_backproj2(tv, pos);
277    tv_rect2(tv, p1, p2);
278 } 
279 
280 static void conn_drag(Tv *tv, Ipos pos)
281 {
282    tv_rect2(tv, p1, p2);
283    p2 = tv_backproj2(tv, pos);
284    tv_rect2(tv, p1, p2);
285 }
286 
287 Tv_mouse     connmask_mouse(void)
288 {
289     return (mouse_define(MOUSE_NAME, "connect",
290                          LEFT_NAME, "add",
291                          LEFT_DOWN, conn_roi,
292                          LEFT_DRAG, conn_drag,
293                          LEFT_UP, conn_add_regions,
294                          MIDDLE_NAME, "delete",
295                          MIDDLE_DOWN, conn_delete_pixel,
296                          MIDDLE_DRAG, conn_delete_line,
297                          MIDDLE_UP, conn_redraw,
298                          RIGHT_NAME, "segment",
299                          RIGHT_DOWN, conn_seg_regions,
300                          NULL));
301 }
302 
303 

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