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

Linux Cross Reference
Tina5/tina-libs/tina/geometry/geomCurve_con_fltr.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/geomCurve_con_fltr.c,v $
 23  * Date    :  $Date: 2003/09/09 16:02:21 $
 24  * Version :  $Revision: 1.2 $
 25  * CVS Id  :  $Id: geomCurve_con_fltr.c,v 1.2 2003/09/09 16:02:21 ipoole Exp $
 26  *
 27  * Author  : Legacy TINA
 28  *
 29  * Notes : Avoids too many parameters in conic_filter & calling functions
 30  *
 31  *********
 32 */
 33 
 34 #include "geomCurve_con_fltr.h"
 35 
 36 #if HAVE_CONFIG_H
 37   #include <config.h>
 38 #endif
 39 
 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/geom_CurveDef.h>
 47 #include <tina/geometry/geomCurve_con_util.h>
 48 #include <tina/geometry/geomCurve_con_stat.h>
 49 #include <tina/geometry/geomCurve_conic_5pt.h>
 50 
 51 
 52 static double (*filter) () = NULL;      /* Filter to be applied */              /* static data! */
 53 
 54 double  (*conic_filter_get()) ( void /* ??? */ )
 55 {
 56     return (filter);
 57 }
 58 
 59 void    conic_filter_set(double (*newfilter) ( /* ??? */ ))
 60 {
 61     filter = newfilter;
 62 }
 63 
 64 /**
 65 sampling frequency on fitted curve
 66 **/
 67 
 68 static int sample = 4;          /* static data! */
 69 
 70 int     conic_sample_get(void)
 71 {
 72     return (sample);
 73 }
 74 
 75 void    conic_sample_set(int newsample)
 76 {
 77     sample = newsample;
 78 }
 79 
 80 /**
 81 nominal variance of fitted points
 82 **/
 83 
 84 static double var = 1.0;                /* static data! */
 85 
 86 double  conic_var_get(void)
 87 {
 88     return (var);
 89 }
 90 
 91 void    conic_var_set(double newvar)
 92 {
 93     var = newvar;
 94 }
 95 
 96 /**
 97 number of filter iterations
 98 **/
 99 
100 static int iter = 3;                    /* static data! */
101 
102 int     conic_iter_get(void)
103 {
104     return (iter);
105 }
106 
107 void    conic_iter_set(int newiter)
108 {
109     iter = newiter;
110 }
111 
112 /* Apply chosen filter to point string */
113 void    conic_filter(Conic * conic, List * start, List * end)
114 {
115     Conic_stat stats = {Conic_stat_id};
116     double  scale;
117     List *dptr;
118     Vec2    p = {Vec2_id};
119     Vec2    p1 = {Vec2_id};
120     Vec2    p2 = {Vec2_id};
121     int     i, j, len;
122 
123     if (conic == NULL || filter == NULL)
124         return;
125 
126     /** store copy of unfiltered conic **/
127     /* BUGFIX conic0 unused */
128     /* Conic   conic0; conic0 = *conic; */
129 
130     conic_normalise(conic);
131     scale = MAX(fabs(conic->alpha), fabs(conic->beta));
132 
133     /** filter at least 5 points **/
134     len = ddstr_length(start, end);
135     if (len / sample < 4)
136         sample = len / 4;
137 
138     for (i = 0; i < iter; ++i)
139     {
140         conic_stat_init(&stats, scale, 100.0);
141         for (dptr = start;;)
142         {
143             DD_GET_POS2(dptr, p);
144             filter(conic, &stats, p, var);
145             if (dptr == end)
146                 break;
147             for (j = 0; dptr != end && j < sample; ++j)
148                 dptr = dptr->next;
149         }
150         conic_correct(conic, stats.x);
151     }
152     conic_setup(conic);
153 
154     DD_GET_POS2(start, p1);
155     DD_GET_POS2(end, p2);
156     DD_GET_POS2(ddstr_mid_point(start, end), p);
157     conic_set_ends(conic, p1, p2, p);
158     conic->props = proplist_add(conic->props,
159                                 (void *) conic_stat_copy(&stats),
160                                 STATS,
161                                 rfree);
162 }
163 
164 /**
165 apply chosen filter to point string but limit result to an ellipse
166 **/
167 void    conic_ellipse_filter(Conic * conic, List * start, List * end, double min_aratio)
168 {
169     Conic_stat stats = {Conic_stat_id};
170     double  scale;
171     List *dptr;
172     Vec2    p = {Vec2_id};
173     Vec2    p1 = {Vec2_id};
174     Vec2    p2 = {Vec2_id};
175     int     i, j, len;
176     Conic   conic0 = {Conic_id};
177 
178     if (conic == NULL || filter == NULL)
179         return;
180 
181     /** store copy of unfiltered conic **/
182     conic0 = *conic;
183 
184     conic_normalise(conic);
185     scale = MAX(fabs(conic->alpha), fabs(conic->beta));
186 
187     /** filter at least 5 points **/
188     len = ddstr_length(start, end);
189     if (len / sample < 4)
190         sample = len / 4;
191 
192     for (i = 0; i < iter; ++i)
193     {
194         conic_stat_init(&stats, scale, 100.0);
195         for (dptr = start;;)
196         {
197             DD_GET_POS2(dptr, p);
198             filter(conic, &stats, p, var);
199             if (dptr == end)
200                 break;
201             for (j = 0; dptr != end && j < sample; ++j)
202                 dptr = dptr->next;
203         }
204         conic_correct(conic, stats.x);
205     }
206     conic_setup(conic);
207 
208     if (conic->type == HYPERBOLA || conic_aratio(conic) < min_aratio)
209     {
210         /** have made things worse, use saved copy **/
211         double  t1 = conic0.t1;
212         double  dt = conic0.t2 - conic0.t1;
213 
214         *conic = conic0;
215 
216         /** set up 5pt stats without changing conic **/
217         conic_stat_init(&stats, scale, 100.0);
218         filter(conic, &stats, conic_point(conic, t1), var);
219         filter(conic, &stats, conic_point(conic, t1 + 0.25 * dt), var);
220         filter(conic, &stats, conic_point(conic, t1 + 0.50 * dt), var);
221         filter(conic, &stats, conic_point(conic, t1 + 0.75 * dt), var);
222         filter(conic, &stats, conic_point(conic, t1 + 1.00 * dt), var);
223     }
224     DD_GET_POS2(start, p1);
225     DD_GET_POS2(end, p2);
226     DD_GET_POS2(ddstr_mid_point(start, end), p);
227     conic_set_ends(conic, p1, p2, p);
228     conic->props = proplist_add(conic->props,
229                                 (void *) conic_stat_copy(&stats),
230                                 STATS,
231                                 rfree);
232 }
233 
234 Conic  *conic_fit(List * start, List * end)
235 {
236     Conic  *conic = ddstr_conic_5pt(start, end);
237 
238     conic_filter(conic, start, end);
239     return (conic);
240 }
241 
242 Conic  *conic_ellipse_fit(List * start, List * end, double min_aratio)
243 {
244     Conic  *conic = ddstr_conic_ellipse_5pt(start, end, min_aratio);
245 
246     conic_ellipse_filter(conic, start, end, min_aratio);
247     return (conic);
248 }
249 

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