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

Linux Cross Reference
Tina5/tina-libs/tina/geometry/geomLine_3trans.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/geomLine_3trans.c,v $
 23  * Date    :  $Date: 2003/05/22 12:55:01 $
 24  * Version :  $Revision: 1.2 $
 25  * CVS Id  :  $Id: geomLine_3trans.c,v 1.2 2003/05/22 12:55:01 tony Exp $
 26  *
 27  * Notes :
 28  *
 29  *********
 30 */
 31 
 32 
 33 #include "geomLine_3trans.h"
 34 
 35 #if HAVE_CONFIG_H
 36   #include <config.h>
 37 #endif
 38 
 39 #include <tina/sys/sysDef.h>
 40 #include <tina/sys/sysPro.h>
 41 #include <tina/math/mathDef.h>
 42 #include <tina/math/mathPro.h>
 43 #include <tina/geometry/geomDef.h>
 44 #include <tina/geometry/geom_LineDef.h>
 45 #include <tina/geometry/geom_TransDef.h>
 46 #include <tina/geometry/geom_TransPro.h>
 47 
 48 
 49 void    line3_transform(Line3 * line, Transform3 trans)
 50 {
 51     if (line == NULL)
 52         return;
 53 
 54     line->p1 = trans3_pos(trans, line->p1);
 55     line->p2 = trans3_pos(trans, line->p2);
 56     line->p = trans3_pos(trans, line->p);
 57     line->v = trans3_vec(trans, line->v);
 58 }
 59 
 60 double  overlap_length(double a1, double a2, double b1, double b2)
 61 {
 62     if (a1 > a2)
 63         SWAP(double, a1, a2);
 64     if (b1 > b2)
 65         SWAP(double, b1, b2);
 66     if (a1 > b2 || a2 < b1)
 67         return (0.0);
 68     if (a1 < b1)
 69         a1 = b1;
 70     if (a2 > b2)
 71         a2 = b2;
 72     return (a2 - a1);
 73 }
 74 
 75 int     line3_on_and_overlap(Line3 * l1, Line3 * l2, double length_ratio, double posth)
 76 {
 77     Vec3    p1 = {Vec3_id};
 78     Vec3    p2 = {Vec3_id};
 79     float   d1, d2;
 80     float   min_length;
 81 
 82     /* find end points of l2 w.r.t. l1->p1 */
 83     p1 = vec3_diff(l2->p1, l1->p1);
 84     p2 = vec3_diff(l2->p2, l1->p1);
 85 
 86     /* and their distances from l1->p1 along direction l1->v */
 87     d1 = (float) vec3_dot(l1->v, p1);
 88     d2 = (float) vec3_dot(l1->v, p2);
 89 
 90     min_length = (float) tina_fmin(l1->length, l2->length);
 91 
 92     if (overlap_length(d1, d2, 0.0, l1->length) < min_length * length_ratio)
 93         return (0);
 94 
 95     if (d1 > d2)
 96         SWAP(float, d1, d2);
 97 
 98     /* find distances from overlaping endpoints to other line */
 99     if (d1 < 0)                 /* use l1->p1 */
100         p1 = vec3_projperp(vec3_diff(l1->p1, l2->p1), l2->v);
101     else                        /* use l2->p1 */
102         p1 = vec3_diff(p1, vec3_times(d1, l1->v));
103 
104     if (d2 > l1->length)        /* use l1->p2 */
105         p2 = vec3_projperp(vec3_diff(l1->p2, l2->p1), l2->v);
106     else                        /* use l2->p1 */
107         p2 = vec3_diff(p2, vec3_times(d2, l1->v));
108 
109     posth *= posth;
110     return (vec3_sqrmod(p1) < posth && vec3_sqrmod(p2) < posth);
111 }
112 
113 int     line3_coincident(Line3 * l1, Line3 * l2, double doterror, double poserror)
114 
115 /* BUG */
116 {
117     if (l1 == NULL || l2 == NULL)
118         return (0);
119 
120     if (vec3_dot(l1->v, l2->v) < 0)
121         return (0);             /* pointing in opposite directions */
122 
123     return (line3_on_and_overlap(l1, l2, 0.5, poserror));
124 }
125 
126 Bool    line3_within_error(Line3 * l1, Line3 * l2)
127 {
128     Iso_error *iso1;
129     Iso_error *iso2;
130 
131     if (l1 == NULL || l2 == NULL)
132         return (false);
133 
134     iso1 = (Iso_error *) prop_get(l1->props, ISO_ERROR);
135     iso2 = (Iso_error *) prop_get(l2->props, ISO_ERROR);
136 
137     if (iso1 == NULL || iso2 == NULL)
138         return (false);
139 
140     if (!line3_coincident(l1, l2, iso1->dot * iso2->dot, iso1->pos + iso2->pos))
141         return (false);
142 
143     return (true);
144 }
145 

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