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

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

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