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

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

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