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

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

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