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

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

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