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

Linux Cross Reference
Tina5/tina-libs/tina/geometry/geomCurve_conic2.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_conic2.c,v $
 23  * Date    :  $Date: 2005/01/09 17:49:25 $
 24  * Version :  $Revision: 1.3 $
 25  * CVS Id  :  $Id: geomCurve_conic2.c,v 1.3 2005/01/09 17:49:25 paul Exp $
 26  *
 27  * Author  : Legacy TINA
 28  *
 29  * Notes : recover unbroken (in pixel sence) string of Vec2 from conic
 30  *
 31  *********
 32 */
 33 
 34 #include "geomCurve_conic2.h"
 35 
 36 #if HAVE_CONFIG_H
 37   #include <config.h>
 38 #endif
 39 
 40 #include <math.h>
 41 #include <stdlib.h>
 42 #include <tina/sys/sysDef.h>
 43 #include <tina/sys/sysPro.h>
 44 #include <tina/math/mathDef.h>
 45 #include <tina/math/mathPro.h>
 46 #include <tina/geometry/geom_CurveDef.h>
 47 #include <tina/geometry/geomCurve_con_util.h>
 48 #include <tina/geometry/geomCurve_conic2.h>
 49 
 50 
 51 static Conic *conic;            /* static data! */
 52 
 53 static List *conic2_chop(double t1, double t2, Vec2 v1, Vec2 v2)
 54 {
 55     int     x1, y1, x2, y2;
 56     double  t;
 57     Vec2    v = {Vec2_id};
 58 
 59     x1 = (int)floor(vec2_x(v1));
 60     y1 = (int)floor(vec2_y(v1));
 61     x2 = (int)floor(vec2_x(v2));
 62     y2 = (int)floor(vec2_y(v2));
 63     if (x1 == x2 && y1 == y2)   /* same pixel */
 64         return (NULL);
 65     if (abs(x1 - x2) <= 1 && abs(y1 - y2) <= 1) /* neighbours */
 66         return (dd_link_alloc((void *) vec2_make(v2), VEC2));
 67 
 68     t = (t1 + t2) * 0.5;
 69     v = conic_point(conic, t);
 70     return (dd_append(conic2_chop(t1, t, v1, v), conic2_chop(t, t2, v, v2)));
 71 }
 72 
 73 Tstring *conic2_string(Conic * c)
 74 {
 75     List *list;
 76     Tstring *str;
 77     double  t1, t2, tm;
 78     Vec2    v1 = {Vec2_id};
 79     Vec2    v2 = {Vec2_id};
 80     Vec2    vm = {Vec2_id};
 81     int     x1, x2, y1, y2;
 82 
 83     if (c == NULL)
 84         return (NULL);
 85 
 86     conic = c;
 87     t1 = c->t1;
 88     t2 = c->t2;
 89     tm = (t1 + t2) * 0.5;
 90     v1 = conic_point(c, t1);
 91     v2 = conic_point(c, t2);
 92     vm = conic_point(c, tm);
 93     list = dd_link_alloc((void *) vec2_make(v1), VEC2);
 94     list = dd_append(list, conic2_chop(t1, tm, v1, vm));
 95     list = dd_append(list, conic2_chop(tm, t2, vm, v2));
 96 
 97     str = str_make(STRING, list, dd_get_end(list));
 98     if (str == NULL || str->count <= 3)
 99         return (str);
100 
101     x1 = (int)floor(vec2_x(v1));
102     x2 = (int)floor(vec2_x(v2));
103     y1 = (int)floor(vec2_y(v1));
104     y2 = (int)floor(vec2_y(v2));
105     if (abs(x1 - x2) <= 1 && abs(y1 - y2) <= 1) /* neighbours */
106     {
107         if (x1 == x2 && y1 == y2)       /* in same pixel */
108         {
109             str->start = str->start->next;
110             (void) dd_link_rm(list, rfree);     /* same as start */
111         }
112         str->type = LOOP;
113         str->start->last = str->end;
114         str->end->next = str->start;
115     }
116     return (str);
117 }
118 

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