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

Linux Cross Reference
Tina5/tina-libs/tina/vision/visCalib_lines.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/vision/visCalib_lines.c,v $
 23  * Date    :  $Date: 2008/10/02 11:53:05 $
 24  * Version :  $Revision: 1.7 $
 25  * CVS Id  :  $Id: visCalib_lines.c,v 1.7 2008/10/02 11:53:05 neil Exp $
 26  *
 27  * Author  : Legacy TINA
 28  *
 29  * Notes :
 30  *
 31  *********
 32 */
 33 
 34 #include "visCalib_lines.h"
 35 
 36 #if HAVE_CONFIG_H
 37   #include <config.h>
 38 #endif
 39 
 40 #include <math.h>
 41 #include <stdio.h>
 42 #include <tina/sys/sysDef.h>
 43 #include <tina/sys/sysPro.h>
 44 #include <tina/math/mathDef.h>
 45 #include <tina/geometry/geomDef.h>
 46 #include <tina/geometry/geomPro.h>
 47 #include <tina/vision/visCalib_grid.h>
 48 
 49 static double min_linex(Line2 * line)
 50 {
 51     if (line->p1.el[0] < line->p2.el[0])
 52         return (line->p1.el[0]);
 53     else
 54         return (line->p2.el[0]);
 55 }
 56 
 57 static double min_liney(Line2 * line)
 58 {
 59     if (line->p1.el[1] < line->p2.el[1])
 60         return (line->p1.el[1]);
 61     else
 62         return (line->p2.el[1]);
 63 }
 64 
 65 
 66 static List *remerge(List * line_list, double join_thres)
 67 {
 68     List   *ptr1 = NULL;
 69     List   *ptr2 = NULL;
 70     Line2  *line1 = NULL;
 71     Line2  *line2 = NULL;
 72     Tstring *s1, *s2, *snew, *es_combine();
 73 
 74     for (ptr1 = line_list; ptr1 != NULL; ptr1 = ptr1->next)
 75     {
 76         line1 = ptr1->to;
 77         if (line1 != NULL && line2 != NULL)
 78         {
 79             if (vec2_mod(vec2_diff(line2->p1, line1->p1)) < join_thres
 80              || vec2_mod(vec2_diff(line2->p1, line1->p2)) < join_thres
 81              || vec2_mod(vec2_diff(line2->p2, line1->p1)) < join_thres
 82             || vec2_mod(vec2_diff(line2->p2, line1->p2)) < join_thres)
 83             {
 84                 s1 = prop_get(line1->props, STRING);
 85                 s2 = prop_get(line2->props, STRING);
 86                 snew = es_combine(s1, s2);
 87                 line_list = list_rm_el(line_list, ptr1, line2_free);
 88                 line1 = line2_fit(snew->start, snew->end);
 89                 ptr1 = link_alloc((void *) line1, LINE2);
 90                 link_addafter(ptr2, ptr1);
 91                 line_list = list_rm_el(line_list, ptr2, line2_free);
 92             }
 93         }
 94         ptr2 = ptr1;
 95         line2 = line1;
 96     }
 97     return (line_list);
 98 }
 99 
100 
101 void    colinear_2Dlist(List * lines, List ** co_horizlist, List ** co_vertlist, double co_thres, double join_thres, int orient)
102 {
103     List   *ptr1;
104     List   *co_linelist;
105     Line2  *line1;
106     Line2  *refline;
107     float   grad;
108     
109     while (lines != NULL)
110     {
111         ptr1 = lines;
112         line1 = ptr1->to;
113         lines = list_rm_el(lines, ptr1, (void (*) ()) NULL);
114         co_linelist = ref_addtostart((List *) NULL, (void *) line1, LINE2);
115         refline = colinear_2Dlines(&co_linelist, &lines, co_thres);
116 if ( orient == 0 )
117 {
118         if (fabs(refline->p1.el[0] - refline->p2.el[0])
119             > fabs(refline->p1.el[1] - refline->p2.el[1]))
120         {
121             co_linelist = sort_list(co_linelist, min_linex, NULL);
122             co_linelist = remerge(co_linelist, join_thres);
123             *co_horizlist = ref_addtostart((List *) * co_horizlist, (void *) co_linelist, LIST);
124         } else
125         {
126             co_linelist = sort_list(co_linelist, min_liney, NULL);
127             co_linelist = remerge(co_linelist, join_thres);
128             *co_vertlist = ref_addtostart((List *) * co_vertlist, (void *) co_linelist, LIST);
129         }
130 }
131 else
132 {
133     grad =  (refline->p1.el[0] - refline->p2.el[0]) / (refline->p1.el[1] - refline->p2.el[1]);
134 
135     if (  ((grad / fabs(grad) == -1.0) && (orient == 1)) ||  ((grad / fabs(grad) == 1.0) && (orient == -1))  )
136         {
137             co_linelist = sort_list(co_linelist, min_linex, NULL);
138             co_linelist = remerge(co_linelist, join_thres);
139             *co_horizlist = ref_addtostart((List *) * co_horizlist, (void *) co_linelist, LIST);
140         } else
141         {
142             co_linelist = sort_list(co_linelist, min_liney, NULL);
143             co_linelist = remerge(co_linelist, join_thres);
144             *co_vertlist = ref_addtostart((List *) * co_vertlist, (void *) co_linelist, LIST);
145         }
146 
147 
148 
149 }
150 
151 
152 
153 
154     }
155     *co_horizlist = sort_list(*co_horizlist, min_intery, NULL);
156     *co_vertlist = sort_list(*co_vertlist, min_interx, NULL);
157 }
158 

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