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

Linux Cross Reference
Tina6/tina-libs/tina/vision/visMatch_eindex.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/vision/visMatch_eindex.c,v $
 27  * Date    :  $Date: 2008/12/09 00:15:22 $
 28  * Version :  $Revision: 1.7 $
 29  * CVS Id  :  $Id: visMatch_eindex.c,v 1.7 2008/12/09 00:15:22 paul Exp $
 30  *
 31  * Author  : Legacy TINA
 32  *
 33  * Notes :
 34  * functions for constructing and handling a raster based 2D spatial index
 35  * of a set of edge contours, the first dimension of the index is the
 36  * raster. elements in the index are stored as an ordered list along
 37  * the raster. the second dimension of the index provides a spatial
 38  * jump along the list.
 39  * 
 40  * it is built prior to stereo matching
 41  * 
 42  * edge contours are indexed at a sub-string level, that is sub-strings
 43  * are constructed for that part of an edge contour that crosses a
 44  * specific raster. Edges may be defined at a much finer scale than the
 45  * scale of the "image" rasters as a result of prior projective scaling
 46  * and warping.
 47  * 
 48  * Edge strings that run in a near vertical direction across the image
 49  * will usually produce very short, mainly unit length, within raster
 50  * sub strings.
 51  * 
 52  * The type of the sub-string is used to indicate the direction it runs
 53  * (either forward of backward) along the raster
 54  * 
 55  * It is also useful to identify those longer sub-sections of edge
 56  * contours that are unique with respect to rasters, ie. sections of
 57  * strings which cross a set of rasters only once. Some strings
 58  * (without max or min in the y direction) only have a single section.
 59  * 
 60  * Each constituent "within raster" sub-string is given a label to
 61  * identify which "raster wise unique" edge sub-string it forms a part.
 62  * Basicly this results in the implicit segmentation of edge contours
 63  * at turning points wrt the y direction. 
 64  *
 65  *********
 66 */
 67 
 68 #include "visMatch_eindex.h"
 69 
 70 #if HAVE_CONFIG_H
 71   #include <config.h>
 72 #endif
 73 
 74 #include<math.h>
 75 #include<stdlib.h>
 76 #include <tina/sys/sysDef.h>
 77 #include <tina/sys/sysPro.h>
 78 #include <tina/math/mathDef.h>
 79 #include <tina/geometry/geomDef.h>
 80 #include <tina/geometry/geomPro.h>
 81 #include <tina/vision/vis_MatchDef.h>
 82 #include <tina/vision/vis_MatchPro.h>
 83 
 84 /* label for unique string sections (wrt epipolars) */
 85 static long int string_label = 0;       /* fist value used is 1 */
 86 
 87 /* add an edge countour string to a stereo index
 88  * 
 89  * involves identifying short sub-strings that run along the current
 90  * raster membership of a raster is defined by truncation of y
 91  * locations
 92  * 
 93  * if a string has gaps with respect to the row spacing (ie inbetween rows
 94  * without any data points on them) the index does not. The closest
 95  * available indexed sub-string is indexed again (perhaps repeatedly
 96  * for larger gaps). Due care must be taken when using the index.
 97  * 
 98  * label members of the raster wise unique edge sub-strings
 99  * 
100  * leave a hook from the edge to the sub-string it is part of using the
101  * SINDEX flexible property value of the Edgel */
102 static void es_add_to_index(List ** index, Tstring * string)
103 {
104     List *start;
105     List *end;
106     Tstring *laststr = NULL, *str;
107     int     row, lastrow = 0;
108     int     incrow = 0;
109 
110     if (index == NULL || string == NULL)
111         return;
112 
113     ++string_label;             /* new label for raster wise uniqueness */
114 
115     start = string->start;
116     while (1)
117     {
118         row = (int)floor(vec2_y(DD_EDGE_POS(start)));
119         if (incrow != 0 && incrow * (row - lastrow) < 0)
120             ++string_label;     /* a change row increment direction */
121         if (laststr != NULL)
122             incrow = row - lastrow;
123 
124         end = start;
125         while (1)               /* find rest of string on this raster */
126         {
127             if (end == string->end)
128                 break;
129             if (row != (int) vec2_y(DD_EDGE_POS(end->next)))
130                 break;
131             end = end->next;
132         }
133 
134         if (vec2_x(DD_EDGE_POS(start)) < vec2_x(DD_EDGE_POS(end)))
135             str = str_make(FORWARD, start, end);
136         else
137             str = str_make(BACKWARD, start, end);
138 
139         /* add the sub-string to the property list of the edges */
140         es_add_to_prop_list(str, (void *) str, SINDEX, (void (*) ()) NULL, false);      /* expensive */
141         /* add the current label to the property list sub-string */
142 
143         /*str->props = proplist_add(str->props, string_label, STRING, (void (*) ()) NULL);*/
144         str->props = proplist_add(str->props, (void *) string_label, STRING, (void (*) ()) NULL); /*JD, 2015.01.27*/
145 
146         index[row] = ref_addtostart((List *) index[row], (void *) str, STRING);
147 
148         /* fill the index over any gaps in the edge contour string */
149         if (laststr != NULL && abs(row - lastrow) != 1)
150         {
151             int     i, r1 = lastrow, r2 = row;
152 
153             ORDER(int, r1, r2);
154             for (i = r1 + 1; i < r2; ++i)
155             {
156                 if (abs(i - row) <= abs(i - lastrow))
157                     index[i] = ref_addtostart((List *) index[i], (void *) str, STRING);
158                 else
159                     index[i] = ref_addtostart((List *) index[i], (void *) laststr, STRING);
160             }
161         }
162         laststr = str;
163         lastrow = row;
164         if (end == string->end)
165             break;
166         start = end->next;
167     }
168 }
169 
170 /* function used to sort epipolar sub-strings along the raster
171  * 
172  * the type of the string determines the direction, FORWARD or BACKWARD,
173  * it runs along the raster */
174 static double first_xpos(Tstring * string)
175 {
176     if (string->type == FORWARD)
177         return (vec2_x(DD_EDGE_POS(string->start)));
178     else
179         return (vec2_x(DD_EDGE_POS(string->end)));
180 }
181 
182 /* main function for stereo index building
183  * 
184  * takes a list of edge strings representing contours and constructs a
185  * suitable stereo index for them
186  * 
187  * first finds a region that surrounds the edge locations this may have
188  * little to do with the region of the edgerect the latter is
189  * determined by storage requirements wrt original image the former may
190  * subsequently have been subject to a projective transformation
191  * 
192  * then each edge string is considered in tern and added to the rows
193  * 
194  * of the stereo index (this also sets the gross string labels)
195  * 
196  * each row of the index is sorted in the x direction and spatially
197  * indexed */
198 Rindex *strings_set_sindex(List * strings)
199 {
200     List   *sptr;
201     Rindex *sx;
202     Rindex *rx_alloc();
203     List  **index;
204     Imregion *region;
205     Imregion *strings_bounding_region();
206     int     ly, uy;
207     int     i;
208 
209     region = strings_bounding_region(strings);
210     if (region == NULL)
211     {
212         error("sindex: nil region", warning);
213         return (NULL);
214     }
215     ly = region->ly;
216     uy = region->uy;
217     sx = rx_alloc(region, SINDEX);
218     index = (List **) sx->index;
219 
220     for (sptr = strings; sptr != NULL; sptr = sptr->next)
221         es_add_to_index(index, (Tstring *) sptr->to);
222 
223     for (i = ly; i < uy; ++i)
224         index[i] = sort_list(index[i], first_xpos, NULL);
225 
226     return (sx);
227 }
228 
229 /* function for adding/replacing the stereo index of an edgerect
230  * 
231  * updates the SINDEX propety of the edgerect for future reference
232  * 
233  * function strings_set_sindex does the actual work */
234 void    er_set_sindex(Imrect * er)
235 /* edge rect ptr image */
236 {
237     List   *strings;
238     void    rx_free_links();
239     Rindex *sx;
240 
241     if (er == NULL || er->vtype != ptr_v)
242     {
243         error("sindex: passed non edge rect", warning);
244         return;
245     }
246     strings = (List *) prop_get(er->props, STRING);
247     if (strings == NULL)
248     {
249         error("sindex: no strings available", warning);
250         return;
251     }
252     sx = strings_set_sindex(strings);
253     if (sx == NULL)
254         return;
255 
256     er->props = proplist_addifnp(er->props, (void *) sx, SINDEX, rx_free_links, true);
257 }
258 
259 /* apply function to each stereo index sub-string of given string
260  * 
261  * uses the SINDEX property of the edgel to get to the sub-string and from
262  * their the next element and sub-string in the list. */
263 void    es_apply_to_sindex_strings(Tstring * es, void (*func) ( /* ??? */ ), void *data)
264 {
265     List *dptr;
266     List *end;
267 
268     if (es == NULL)
269         return;
270 
271     end = es->end;
272     for (dptr = es->start;; dptr = dptr->next)
273     {
274         Edgel  *e = (Edgel *) dptr->to;
275         Tstring *sub;
276 
277         sub = (Tstring *) prop_get(e->props, SINDEX);
278         if (sub != NULL)
279         {
280             func(sub, STRING, data);
281             dptr = sub->end;
282         }
283         if (dptr == end)
284             break;
285     }
286 }
287 
288 /* apply to every entry of the stereo index
289  * 
290  * note that some entries could have multiple entries */
291 void    er_apply_through_sindex(Imrect * er, void (*func) ( /* ??? */ ), void *data)
292 {
293     Rindex *sx;
294     List   *lptr;
295     int     i;
296 
297     if (er == NULL || (sx = (Rindex *) prop_get(er->props, SINDEX)) == NULL)
298         return;
299 
300     for (i = sx->region->ly; i < sx->region->uy; ++i)
301         for (lptr = (List *) (sx->index[i]); lptr != NULL; lptr = lptr->next)
302             func(lptr->to, lptr->type, data);
303 }
304 
305 /* copy edge string to string of sub-strings */
306 Tstring *string_of_sindex_strings(Tstring * es)
307 {
308     List *start;
309     List *end;
310     List *ptr;
311     List *substrings = NULL;
312 
313     if (es == NULL)
314         return (NULL);
315 
316     start = es->start;
317     end = es->end;
318 
319     for (ptr = start;; ptr = ptr->next)
320     {
321         Edgel  *edge = (Edgel *) ptr->to;
322         Tstring *sub;
323 
324         sub = (Tstring *) prop_get(edge->props, SINDEX);
325         if (sub == NULL)
326             continue;
327         substrings = dd_ref_addtostart(substrings, (void *) sub, STRING);
328         ptr = sub->end;
329         if (ptr == end)
330             break;
331     }
332     if (substrings == NULL)
333         return (NULL);
334     return (str_make(SINDEX, substrings, dd_get_end(substrings)));
335 }
336 

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