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

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

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