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

Linux Cross Reference
Tina5/tina-libs/tina/geometry/geomLine_3fit.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 Lesser 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 Lesser General Public License for more details.
 14  *
 15  * You should have received a copy of the GNU Lesser 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  **********
 20  * 
 21  * Program :    TINA
 22  * File    :  $Source: /home/tina/cvs/tina-libs/tina/geometry/geomLine_3fit.c,v $
 23  * Date    :  $Date: 2008/10/30 09:43:59 $
 24  * Version :  $Revision: 1.4 $
 25  * CVS Id  :  $Id: geomLine_3fit.c,v 1.4 2008/10/30 09:43:59 neil Exp $
 26  *
 27  * Notes :
 28  *
 29  *********
 30 */
 31 
 32 
 33 #include "geomLine_3fit.h"
 34 
 35 #if HAVE_CONFIG_H
 36   #include <config.h>
 37 #endif
 38 
 39 #include <stdio.h>
 40 #include <math.h>
 41 #include <tina/sys/sysDef.h>
 42 #include <tina/sys/sysPro.h>
 43 #include <tina/math/mathDef.h>
 44 #include <tina/math/mathPro.h>
 45 #include <tina/geometry/geomDef.h>
 46 #include <tina/geometry/geomPro.h>
 47 #include <tina/geometry/geom_LineDef.h>
 48 #include <tina/geometry/geom_LinePro.h>
 49 #include <tina/geometry/geom_CurvePro.h>
 50 
 51 #define DISP_THRES 1.0
 52 #define DISP_GRAD 1.0
 53 #define RASTER_THRES 1.0
 54 #define HORIZ_THRES 0.995
 55 
 56 static Tstring *form_disp_str_rect(Line2 * line2)
 57 /* form disparity string relative to a line from matched rectified edge data */ 
 58 {
 59     Tstring *es;
 60     List    *dispstr = NULL;
 61     List    *dptr;
 62     Vec2     v = {Vec2_id};
 63     Vec2     p = {Vec2_id};
 64 
 65     if (line2 == NULL)
 66         return (NULL);
 67 
 68     v = line2->v;
 69     p = line2->p1;
 70     es = (Tstring *) prop_get(line2->props, STRING);
 71     if (es == NULL)
 72         return (NULL);
 73 
 74     for (dptr = es->start; dptr!=NULL ; dptr = dptr->next)
 75     {
 76         Vec2    pm = {Vec2_id};
 77         Vec2   *pdisp = ts_ralloc(Vec2);
 78         Match *match1;
 79         float   x, y, d;
 80         Edgel *edge1, *edge2;
 81 
 82         edge1 = dptr->to;
 83         /* get the edgel that it matched to */
 84         match1 = (Match *)prop_get(edge1->props, MATCH);
 85         if (match1 != NULL)
 86         {
 87            edge2 = (Edgel *)match1->to2;
 88            pm = edge2->pos;
 89            y = vec2_y(pm) - vec2_y(p);
 90            x = vec2_x(v) * y / vec2_y(v);
 91            d = vec2_x(pm) - vec2_x(p) - x;
 92            *pdisp = vec2(sqrt(x * x + y * y), d);
 93            dispstr = dd_ref_addtostart(dispstr, (void *) pdisp, VEC2);
 94         }
 95         if (dptr == es->end)
 96            break;
 97     }
 98 
 99     dispstr = sort_ddlist(dispstr, vec2_get_x, NULL);
100     return (str_make(STRING, dispstr, dd_get_end(dispstr)));
101 }
102 
103 static Tstring *form_disp_str(Line2 * line2)
104 {
105     Tstring *es;
106     List *dispstr = NULL;
107     List   *mlist;
108     List   *mptr;
109     Vec2    v = {Vec2_id};
110     Vec2    p = {Vec2_id};
111 
112     if (line2 == NULL)
113         return (NULL);
114 
115     v = line2->v;
116     p = line2->p1;
117     es = (Tstring *) prop_get(line2->props, STRING);
118     if (es == NULL)
119         return (NULL);
120 
121     mlist = es_get_list_of_matches(es);
122     for (mptr = mlist; mptr != NULL; mptr = mptr->next)
123     {
124         List *dptr;
125         List *end;
126 
127         es = (Tstring *) ((Match *) mptr->to)->to2;
128         end = es->end;
129         for (dptr = es->start;; dptr = dptr->next)
130         {
131             Vec2    pm = {Vec2_id};
132             Vec2   *pdisp = ts_ralloc(Vec2);
133             float   x, y, d;
134 
135             pm = DD_EDGE_POS(dptr);
136             y = vec2_y(pm) - vec2_y(p);
137             x = vec2_x(v) * y / vec2_y(v);
138             d = vec2_x(pm) - vec2_x(p) - x;
139             *pdisp = vec2(sqrt(x * x + y * y), d);
140             dispstr = dd_ref_addtostart(dispstr, (void *) pdisp, VEC2);
141             if (dptr == end)
142                 break;
143         }
144     }
145 
146     dispstr = sort_ddlist(dispstr, vec2_get_x, NULL);
147     return (str_make(STRING, dispstr, dd_get_end(dispstr)));
148 }
149 
150 Line3  *line3_disp_from2d(Line2 * line2)
151 {
152     Tstring *dispstr;
153     Line2  *lined;
154     Vec3    p1 = {Vec3_id};
155     Vec3    p2 = {Vec3_id};
156     Vec2    p = {Vec2_id};
157 
158     if (line2 == NULL)
159         return (NULL);
160 
161     /* test for horizontal 2D line */
162     if (fabs(vec2_x(line2->v)) > HORIZ_THRES ||
163         fabs(vec2_y(line2->p1) - vec2_y(line2->p2)) < RASTER_THRES)
164         return (NULL);
165 
166     dispstr = form_disp_str(line2);
167     if (dispstr == NULL || dispstr->count < 5)
168     {
169         str_rm(dispstr, rfree);
170         return (NULL);
171     }
172     lined = line2_best_fit(dispstr->start, dispstr->end, DISP_THRES);
173     if (lined == NULL || fabs(vec2_y(lined->v) / vec2_x(lined->v)) > DISP_GRAD)
174     {
175         line2_free(lined);
176         return (NULL);
177     }
178     p1 = p2 = vec3_of_vec2(line2->p1);
179     p = vec2_times(vec2_x(lined->p1), line2->v);        /* 2d offset of p1 */
180     p1 = vec3_sum(p1, vec3_of_vec2(p));
181     vec3_z(p1) = vec2_y(lined->p1);     /* add disparity */
182     p = vec2_times(vec2_x(lined->p2), line2->v);        /* 2d offset of p2 */
183     p2 = vec3_sum(p2, vec3_of_vec2(p));
184     vec3_z(p2) = vec2_y(lined->p2);     /* add disparity */
185     line2_free(lined);
186     return (line3_make(p1, p2, DISPARITY));     /* has no string
187                                                  * property */
188 }
189 
190 Line3  *line3_disp_from2d_rect(Line2 * line2)
191 {
192     Tstring *dispstr;
193     Line2  *lined;
194     Vec3    p1 = {Vec3_id};
195     Vec3    p2 = {Vec3_id};
196     Vec2    p = {Vec2_id};
197 
198     if (line2 == NULL)
199         return (NULL);
200 
201     /* test for horizontal 2D line */
202     if (fabs(vec2_x(line2->v)) > HORIZ_THRES ||
203         fabs(vec2_y(line2->p1) - vec2_y(line2->p2)) < RASTER_THRES)
204         return (NULL);
205 
206     dispstr = form_disp_str_rect(line2);
207     if (dispstr == NULL || dispstr->count < 5)
208     {
209         str_rm(dispstr, rfree);
210         return (NULL);
211     }
212     lined = line2_best_fit(dispstr->start, dispstr->end, DISP_THRES);
213     if (lined == NULL || fabs(vec2_y(lined->v) / vec2_x(lined->v)) > DISP_GRAD)
214     {
215         line2_free(lined);
216         return (NULL);
217     }
218     p1 = p2 = vec3_of_vec2(line2->p1);
219     p = vec2_times(vec2_x(lined->p1), line2->v);        /* 2d offset of p1 */
220     p1 = vec3_sum(p1, vec3_of_vec2(p));
221     vec3_z(p1) = vec2_y(lined->p1);     /* add disparity */
222     p = vec2_times(vec2_x(lined->p2), line2->v);        /* 2d offset of p2 */
223     p2 = vec3_sum(p2, vec3_of_vec2(p));
224     vec3_z(p2) = vec2_y(lined->p2);     /* add disparity */
225     line2_free(lined);
226     return (line3_make(p1, p2, DISPARITY));     /* has no string
227                                                  * property */
228 }
229 
230 Line3  *line3_from_line2_rect(Line2 * line2)
231 {
232     Line3  *line3;
233 
234     if (line2 == NULL)
235         return (NULL);
236 
237     line3 = line3_disp_from2d_rect(line2);
238     line3_par_proj_3d(line3);
239 
240     if (line3 == NULL)
241         return (NULL);
242 
243     line3->props = proplist_add(line3->props, (void *) line2, LINE2,
244                                 (void (*) ()) NULL);
245     line2->props = proplist_add(line2->props, (void *) line3, LINE3,
246                                 (void (*) ()) NULL);
247 
248     return (line3);
249 }
250 
251 Line3  *line3_from_line2(Line2 * line2)
252 {
253     Line3  *line3;
254 
255     if (line2 == NULL)
256         return (NULL);
257 
258     line3 = line3_disp_from2d(line2);
259     line3_par_proj_3d(line3);
260 
261     if (line3 == NULL)
262         return (NULL);
263 
264     line3->props = proplist_add(line3->props, (void *) line2, LINE2,
265                                 (void (*) ()) NULL);
266     line2->props = proplist_add(line2->props, (void *) line3, LINE3,
267                                 (void (*) ()) NULL);
268 
269     return (line3);
270 }
271 

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