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

Linux Cross Reference
Tina6/tina-libs/tina/geometry/geomLine_3line.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_3line.c,v $
 27  * Date    :  $Date: 2005/01/09 17:49:25 $
 28  * Version :  $Revision: 1.2 $
 29  * CVS Id  :  $Id: geomLine_3line.c,v 1.2 2005/01/09 17:49:25 paul Exp $
 30  *
 31  * Notes : functions for manipulating 3D lines
 32  *
 33  *********
 34 */
 35 
 36 
 37 #include "geomLine_3line.h"
 38 
 39 #if HAVE_CONFIG_H
 40   #include <config.h>
 41 #endif
 42 
 43 #include <stdio.h>
 44 #include <math.h>
 45 #include <string.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_LineDef.h>
 51 #ifdef _PCC
 52 #include <memory.h>
 53 #endif
 54 
 55 Line3  *line3_alloc(unsigned int type)
 56 {
 57     Line3  *line = ts_ralloc(Line3);
 58 
 59     line->type = type;
 60     line->label = new_label();
 61     return (line);
 62 }
 63 
 64 Line3  *line3_make(Vec3 p1, Vec3 p2, int type)
 65 {
 66     Line3  *line = ts_ralloc(Line3);
 67 
 68     line->type = type;
 69     line->label = new_label();
 70     line->p1 = p1;
 71     line->p2 = p2;
 72     line->p = vec3_times(0.5, vec3_sum(p1, p2));
 73     line->v = vec3_diff(p2, p1);
 74     line->length = (float)vec3_mod(line->v);
 75     line->v = vec3_times(1.0 / line->length, line->v);
 76     line->props = NULL;
 77     return (line);
 78 }
 79 
 80 void    line3_remake(Line3 * line, int type)
 81 {
 82     if (line == NULL)
 83         return;
 84 
 85     line->type = type;
 86     line->p = vec3_times(0.5, vec3_sum(line->p1, line->p2));
 87     line->v = vec3_diff(line->p2, line->p1);
 88     line->length = (float)vec3_mod(line->v);
 89     line->v = vec3_times(1.0 / line->length, line->v);
 90 }
 91 
 92 void    line3_free(Line3 * line)
 93 {
 94     if (line == NULL)
 95         return;
 96     proplist_freelist(line->props);
 97     rfree((void *) line);
 98 }
 99 
100 Line3  *line3_copy(Line3 * line)/* identical copy that shares proplist */
101 
102 {
103     Line3  *copy;
104     List   *proplist_copy();
105 
106     if (line == NULL)
107         return (NULL);
108 
109     copy = ts_ralloc(Line3);
110     (void) memcpy((char *) copy, (char *) line, sizeof(Line3));
111     copy->props = proplist_copy(line->props);
112     return (copy);
113 }
114 
115 Line3  *line3_clone(Line3 * line)       /* identical copy with null
116                                          * proplist */
117 
118 {
119     Line3  *copy;
120 
121     if (line == NULL)
122         return (NULL);
123 
124     copy = ts_ralloc(Line3);
125     (void) memcpy((char *) copy, (char *) line, sizeof(Line3));
126     copy->props = NULL;
127     return (copy);
128 }
129 
130 Line3  *line3_negative(Line3 * line)
131 {
132     if (line == NULL)
133         return (NULL);
134 
135     line = line3_copy(line);
136     SWAP(Vec3, line->p1, line->p2);
137     line->v = vec3_minus(line->v);
138     return (line);
139 }
140 
141 void    line3_negate(Line3 * line)
142 {
143     if (line == NULL)
144         return;
145 
146     SWAP(Vec3, line->p1, line->p2);
147     line->v = vec3_minus(line->v);
148 }
149 
150 /* rough separation between mid points */
151 
152 double  line3_separation(Line3 * l1, Line3 * l2)
153 {
154     Vec3    c1 = {Vec3_id};
155     Vec3    c2 = {Vec3_id};
156 
157     if (l1 == NULL || l2 == NULL)
158         return (0.0);           /* meaningless */
159 
160     c1 = vec3_times(0.5, vec3_sum(l1->p1, l1->p2));
161     c2 = vec3_times(0.5, vec3_sum(l2->p1, l2->p2));
162 
163     return (vec3_mod(vec3_diff(c1, c2)));
164 }
165 
166 /* minimum separation between extended lines */
167 
168 double  line3_min_separation(Line3 * l1, Line3 * l2)
169 {
170     float   d1, d2, d3, d4;
171 
172     d1 = (float)vec3_mod(vec3_diff(l1->p1, l2->p1));
173     d2 = (float)vec3_mod(vec3_diff(l1->p1, l2->p2));
174     d3 = (float)vec3_mod(vec3_diff(l1->p2, l2->p1));
175     d4 = (float)vec3_mod(vec3_diff(l1->p2, l2->p2));
176 
177     d1 = MIN(d1, d2);
178     d3 = MIN(d3, d4);
179 
180     return (MIN(d1, d3));
181 }
182 
183 Vec3    vec3_along_line(Line3 *line, double frac)
184 {
185     Vec3 d = {Vec3_id};
186     
187     d = vec3_times(frac*line->length,line->v);
188     d = vec3_sum(line->p1, d);
189         
190     return(d); 
191 }
192 
193 Bool    line3_point_on_line(Line3 * line, Vec3 p, double thres)
194 {
195     Vec3    d = {Vec3_id};
196     double  dp;
197 
198     d = vec3_diff(p, line->p1);
199     dp = vec3_dot(line->v, d);
200     d = vec3_diff(d, vec3_times(dp, line->v));
201     return ((vec3_sqrmod(d) < SQR(thres)) ? true : false);
202 }
203 

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