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

Linux Cross Reference
Tina6/tina-libs/tina/geometry/geomIndx_wxlists.c

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

  1 /**********
  2  * 
  3  * This file is part of the TINA Open Source Image Analysis Environment
  4  * henceforth known as TINA
  5  *
  6  * TINA is free software; you can redistribute it and/or modify
  7  * it under the terms of the GNU General Public License as 
  8  * published by the Free Software Foundation.
  9  *
 10  * TINA is distributed in the hope that it will be useful,
 11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  * GNU General Public License for more details.
 14  *
 15  * You should have received a copy of the GNU General Public License
 16  * along with TINA; if not, write to the Free Software Foundation, Inc., 
 17  * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 18  *
 19  * ANY users of TINA who require exemption from the existing licence must
 20  * negotiate a new licence with Dr. Neil.A.Thacker, the sole agent for
 21  * the University of Manchester.
 22  *
 23  **********
 24  * 
 25  * Program :    TINA
 26  * File    :  $Source: /home/tina/cvs/tina-libs/tina/geometry/geomIndx_wxlists.c,v $
 27  * Date    :  $Date: 2002/12/09 11:51:23 $
 28  * Version :  $Revision: 1.1.1.1 $
 29  * CVS Id  :  $Id: geomIndx_wxlists.c,v 1.1.1.1 2002/12/09 11:51:23 cvstina Exp $
 30  *
 31  * Notes : functions to support generic list based image index binning
 32  *
 33  *********
 34 */
 35 
 36 
 37 #include "geomIndx_wxlists.h"
 38 
 39 #if HAVE_CONFIG_H
 40   #include <config.h>
 41 #endif
 42 
 43 #include <math.h>
 44 #include <stdio.h>
 45 #include <tina/sys/sysDef.h>
 46 #include <tina/sys/sysPro.h>
 47 #include <tina/math/mathDef.h>
 48 #include <tina/math/mathPro.h>
 49 #include <tina/geometry/geom_IndxDef.h>
 50 #include <tina/geometry/geomIndx_windex.h>
 51 #include <tina/geometry/geomDef.h>
 52 
 53 
 54 void    wx_add_entry(Windex * w, void *ptr, int type, int i, int j)
 55 {
 56     if (i < 0 || i >= w->m || j < 0 || j >= w->n)
 57         return;
 58 
 59     if (link_get_by_ref((List *) w->index[i][j], ptr) != NULL)
 60         return;                 /* already referenced */
 61     w->index[i][j] = ref_addtostart((List *) w->index[i][j], (void *) ptr, type);
 62 }
 63 
 64 void    wx_rm_entry(Windex * w, void *ptr, int i, int j)
 65 {
 66     if (i < 0 || i >= w->m || j < 0 || j >= w->n)
 67         return;
 68 
 69     w->index[i][j] = list_rm_ref((List *) w->index[i][j], ptr, (void (*) ()) NULL);
 70 }
 71 
 72 void    wx_delete_entry(Windex * w, void *entry)
 73 {
 74     void ***index;
 75     int     n, m;
 76     int     i, j;
 77 
 78     if (w == NULL)
 79         return;
 80 
 81     m = w->m;
 82     n = w->n;
 83     index = w->index;
 84 
 85     for (i = 0; i < m; ++i)
 86         for (j = 0; j < n; ++j)
 87             index[i][j] = list_rm_ref((List *) index[i][j], entry, (void (*) ()) NULL);
 88 }
 89 
 90 void    wx_replace_entry(Windex * w, void *entry, List * entry_list)
 91 {
 92     List ***index;
 93     List   *copy;
 94     int     n, m;
 95     int     i, j;
 96 
 97     if (w == NULL)
 98         return;
 99 
100     m = w->m;
101     n = w->n;
102     index = (List ***) w->index;
103 
104     for (i = 0; i < m; ++i)
105         for (j = 0; j < n; ++j)
106         {
107             if (link_get_by_ref(index[i][j], entry) != NULL)
108             {
109                 index[i][j] = list_rm_ref(index[i][j], entry, (void (*) ()) NULL);
110                 copy = list_copy(entry_list, (void *(*) ()) NULL, NULL);
111                 index[i][j] = list_append(copy, index[i][j]);
112             }
113         }
114 }
115 
116 void    wx_duplicate_entry(Windex * w, void *entry1, void *entry2, int type)
117 {
118     List ***index;
119     int     n, m;
120     int     i, j;
121 
122     if (w == NULL)
123         return;
124 
125     m = w->m;
126     n = w->n;
127     index = (List ***) w->index;
128 
129     for (i = 0; i < m; ++i)
130         for (j = 0; j < n; ++j)
131             if (link_get_by_ref(index[i][j], entry1) != NULL)
132                 index[i][j] = ref_addtostart((List *) index[i][j], (void *) entry2, type);
133 }
134 
135 static double wx_inth(Windex * w, Vec2 p, Vec2 v, int y)
136 {
137     if (w == NULL)
138         return (0.0);
139 
140     y *= (w->region->uy - w->region->ly) / w->m;
141     y += (int)floor(w->region->ly - vec2_y(p));
142 
143     return (vec2_x(p) + vec2_x(v) * y / vec2_y(v));
144 }
145 
146 static double wx_intv(Windex * w, Vec2 p, Vec2 v, int x)
147 {
148     if (w == NULL)
149         return (0.0);
150 
151     x *= (w->region->ux - w->region->lx) / w->n;
152     x += (int)floor(w->region->lx - vec2_x(p));
153 
154     return (vec2_y(p) + vec2_y(v) * x / vec2_x(v));
155 }
156 
157 void    wx_add_str2(Tstring * str, int type, Windex * w)
158 /* string of 2d positions */
159 
160 /* a suitable window index */
161 {
162     List *ptr;
163     List *start;
164     List *end;
165     Vec2    v = {Vec2_id};
166     Ipos    p = {Ipos_id};
167     Ipos    pnew = {Ipos_id};
168 
169     if (str == NULL)
170         return;
171 
172     start = str->start;
173     end = str->end;
174 
175     ptr = start;
176     DD_GET_POS2(ptr, v);
177     p = wx_get_index(w, v);
178     wx_add_entry(w, (void *) str, type, ipos_y(p), ipos_x(p));
179     do
180     {
181         ptr = ptr->next;
182         DD_GET_POS2(ptr, v);
183         pnew = wx_get_index(w, v);
184         if (ipos_equal(pnew, p) == false)
185         {
186             p = pnew;
187             wx_add_entry(w, (void *) str, type, ipos_y(p), ipos_x(p));
188         }
189     }
190     while (ptr != end);
191 }
192 
193 void    wx_add_line(Windex * w, void *ptr, int type, Vec2 p1, Vec2 p2)
194 {
195     Vec2    v = {Vec2_id};
196     Ipos    i1 = {Ipos_id};
197     Ipos    i2 = {Ipos_id};
198     int     m, n;
199 
200     if (w == NULL)
201         return;
202 
203     m = w->m;
204     n = w->n;
205     v = vec2_diff(p2, p1);
206 
207     if (fabs(vec2_x(v)) > fabs(vec2_y(v)))      /* horizontal */
208     {
209         int     fi, li, fj, lj;
210         int     i, j, inc;
211 
212         if (vec2_y(v) < 0)
213         {
214             SWAP(Vec2, p1, p2)
215             /* BUG passing  double AND Vec2 to vec2 */
216             /* v = vec2(-1.0, v); */
217                 v = vec2(-1.0, 0.0);
218         }
219         i1 = wx_get_index(w, p1);
220         i2 = wx_get_index(w, p2);
221 
222         if (i2.y < 0 || i1.y >= m)
223             return;
224 
225         inc = (vec2_x(v) > 0) ? 1 : -1;
226 
227         if (i1.y < 0)
228         {
229             fi = 0;
230             fj = (int)floor(wx_inth(w, p1, v, 0));
231         } else
232         {
233             fi = i1.y;
234             fj = i1.x;
235         }
236 
237         if (i2.y >= m)
238         {
239             li = m;
240             lj = (int)floor(wx_inth(w, p1, v, m));
241         } else
242         {
243             li = i2.y;
244             lj = i2.x;
245         }
246 
247         j = fj;
248         for (i = fi; i < li; ++i, j -= inc)     /* --j to include above
249                                                  * and below raster */
250         {
251             int     nj = (int)floor(wx_inth(w, p1, v, i + 1));
252 
253             if (nj > lj)        /* only true on last iteration */
254                 nj = lj;
255 
256             for (; j <= nj; j += inc)
257                 wx_add_entry(w, ptr, type, i, j);
258         }
259     } else
260     {
261         int     fi, li, fj, lj;
262         int     i, j, inc;
263 
264         if (vec2_x(v) < 0)
265         {
266             SWAP(Vec2, p1, p2)
267             /* BUG passing  double AND Vec2 to vec2 */
268             /* v = vec2(-1.0, v); */
269                 v = vec2(-1.0, 0.0);
270         }
271         i1 = wx_get_index(w, p1);
272         i2 = wx_get_index(w, p2);
273 
274         if (i2.x < 0 || i1.x >= n)
275             return;
276 
277         inc = (vec2_y(v) > 0) ? 1 : -1;
278 
279         if (i1.x < 0)
280         {
281             fj = 0;
282             fi = (int)floor(wx_intv(w, p1, v, 0));
283         } else
284         {
285             fj = i1.x;
286             fi = i1.y;
287         }
288 
289         if (i2.x >= m)
290         {
291             lj = m;
292             li = (int)floor(wx_intv(w, p1, v, n));
293         } else
294         {
295             lj = i2.x;
296             li = i2.y;
297         }
298 
299         i = fi;
300         for (j = fj; j < lj; ++j, i -= inc)     /* --j to include above
301                                                  * and below raster */
302         {
303             int     ni = (int)floor(wx_intv(w, p1, v, j + 1));
304 
305             if (ni > li)        /* only true on last iteration */
306                 ni = li;
307 
308             for (; i <= ni; i += inc)
309                 wx_add_entry(w, ptr, type, i, j);
310         }
311     }
312 }
313 

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