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

Linux Cross Reference
Tina6/tina-libs/tina/file/fileGeom3_read.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**********
  2  * 
  3  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  4  * University of Manchester, UK.  All rights reserved.
  5  * 
  6  * Redistribution and use in source and binary forms, with or without modification, 
  7  * are permitted provided that the following conditions are met:
  8  * 
  9  *   . Redistributions of source code must retain the above copyright notice, 
 10  *     this list of conditions and the following disclaimer.
 11  *    
 12  *   . Redistributions in binary form must reproduce the above copyright notice,
 13  *     this list of conditions and the following disclaimer in the documentation 
 14  *     and/or other materials provided with the distribution.
 15  * 
 16  *   . Neither the name of the University of Manchester nor the names of its
 17  *     contributors may be used to endorse or promote products derived from this 
 18  *     software without specific prior written permission.
 19  * 
 20  * 
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  *
 33  **********
 34  * 
 35  * Program :    TINA
 36  * File    :  $Source: /home/tina/cvs/tina-libs/tina/file/fileGeom3_read.c,v $
 37  * Date    :  $Date: 2003/09/22 16:09:01 $
 38  * Version :  $Revision: 1.3 $
 39  * CVS Id  :  $Id: fileGeom3_read.c,v 1.3 2003/09/22 16:09:01 tony Exp $
 40  *
 41  * Author  :  Legacy TINA
 42  *
 43  * Notes   :
 44  * 
 45  *
 46  *********
 47 */
 48 
 49 #include "fileGeom3_read.h"
 50 
 51 #if HAVE_CONFIG_H
 52   #include <config.h>
 53 #endif
 54 
 55 #include <stdio.h>
 56 #include <tina/sys/sysPro.h>
 57 #include <tina/sys/sysDef.h>
 58 #include <tina/math/mathPro.h>
 59 #include <tina/math/mathDef.h>
 60 #include <tina/geometry/geomDef.h>
 61 #include <tina/geometry/geomPro.h>
 62 #include <tina/vision/visDef.h>
 63 #include <tina/vision/visPro.h>
 64 
 65 static Point3 *point3_sscanf(char *str, int handed)
 66 {
 67     float   handupdate = (float)((handed == LEFT) ? -1.0 : 1.0);
 68     int     label;
 69     Vec3    p1 = {Vec3_id};
 70     Point3 *point;
 71 
 72     if (sscanf(str, "%*s %d %*d %f %f %f ",
 73                &label,
 74                &vec3_x(p1), &vec3_y(p1), &vec3_z(p1)) != 4)
 75         return (NULL);
 76 
 77     p1.el[1] *= handupdate;
 78     point = point3_make(p1, FROM_FILE);
 79     point->label = label;
 80     return (point);
 81 }
 82 
 83 static Line3 *line3_sscanf(char *str, int handed)
 84 {
 85     float   handupdate = (float)((handed == LEFT) ? -1.0 : 1.0);
 86     int     label;
 87     Vec3    p1 = {Vec3_id};
 88     Vec3    p2 = {Vec3_id};
 89     Line3  *line;
 90 
 91     if (sscanf(str, "%*s %d %*d %*f %f %f %f %f %f %f ",
 92                &label,
 93                &vec3_x(p1), &vec3_y(p1), &vec3_z(p1),
 94                &vec3_x(p2), &vec3_y(p2), &vec3_z(p2)) != 7)
 95         return (NULL);
 96 
 97     p1.el[1] *= handupdate;
 98     p2.el[1] *= handupdate;
 99     line = line3_make(p1, p2, FROM_FILE);
100     line->label = label;
101     return (line);
102 }
103 
104 static Conic3 *hyperbola3_sscanf(char *str, int handed)
105 {
106     float   handupdate = (float)((handed == LEFT) ? -1.0 : 1.0);
107     int     label, branch;
108     Vec3    origin = {Vec3_id};
109     Vec3    ex = {Vec3_id};
110     Vec3    ey = {Vec3_id};
111     Vec3    ez = {Vec3_id};
112     float   theta, alpha, beta, t1, t2;
113     Conic  *conic;
114 
115     if (sscanf(str, "%*s %d %f %f %f %f %f %f %f %f %f %f %f %f %f %f %d",
116                &label,
117                &vec3_x(origin), &vec3_y(origin), &vec3_z(origin),
118                &vec3_x(ex), &vec3_y(ex), &vec3_z(ex),
119                &vec3_x(ey), &vec3_y(ey), &vec3_z(ey),
120                &theta, &alpha, &beta, &t1, &t2, &branch) != 16)
121         return (NULL);
122 
123     origin.el[1] *= handupdate;
124     ex.el[1] *= handupdate;
125     ey.el[1] *= handupdate;
126     ez = vec3_unit(vec3_cross(ex, ey));
127 
128     conic = conic_make(HYPERBOLA, vec2(0.0, 0.0), theta, alpha, beta, t1, t2, branch);
129     conic->label = label;
130     return (conic3_make(conic, origin, ex, ey, ez));
131 }
132 
133 static Conic3 *ellipse3_sscanf(char *str, int handed)
134 {
135     float   handupdate = (float)((handed == LEFT) ? -1.0 : 1.0);
136     int     label;
137     Vec3    origin = {Vec3_id};
138     Vec3    ex = {Vec3_id};
139     Vec3    ey = {Vec3_id};
140     Vec3    ez = {Vec3_id};
141     float   theta, alpha, beta, t1, t2;
142     Conic  *conic;
143 
144     if (sscanf(str, "%*s %d %f %f %f %f %f %f %f %f %f %f %f %f %f %f",
145                &label,
146                &vec3_x(origin), &vec3_y(origin), &vec3_z(origin),
147                &vec3_x(ex), &vec3_y(ex), &vec3_z(ex),
148                &vec3_x(ey), &vec3_y(ey), &vec3_z(ey),
149                &theta, &alpha, &beta, &t1, &t2) != 15)
150         return (NULL);
151 
152     origin.el[1] *= handupdate;
153     ex.el[1] *= handupdate;
154     ey.el[1] *= handupdate;
155     ez = vec3_unit(vec3_cross(ex, ey));
156 
157     conic = conic_make(ELLIPSE, vec2(0.0, 0.0), theta, alpha, beta, t1, t2, 0);
158     conic->label = label;
159     return (conic3_make(conic, origin, ex, ey, ez));
160 }
161 
162 
163 
164 static Conic3 *circle3_sscanf(char *str, int handed)
165 {
166     float   handupdate = (float)((handed == LEFT) ? -1.0 : 1.0);
167     int     label;
168     Vec3    origin = {Vec3_id}, ex = {Vec3_id}, ey = {Vec3_id}, ez = {Vec3_id}, v3a, v3b, v3c, v3x, v3x_, v3y, v3w, ref_pt;
169     Vec2    p1 = {Vec2_id}, p2 = {Vec2_id}, p3 = {Vec2_id}, c;
170     float   p1x, p2x, p3x, p1y, p2y, p3y, p1z, p2z, p3z, dp;
171     Conic  *conic;
172 
173     if (sscanf(str, "%*s %d %f %f %f %f %f %f %f %f %f",
174                &label,
175                &vec3_x(v3a), &vec3_y(v3a), &vec3_z(v3a), 
176                &vec3_x(v3b), &vec3_y(v3b), &vec3_z(v3b), 
177                &vec3_x(v3c), &vec3_y(v3c), &vec3_z(v3c) ) != 10)
178     return (NULL);
179 
180     v3x = vec3_diff( v3b, v3a );
181     v3x_ = vec3_unit( v3x );
182     v3w = vec3_diff( v3c, v3a );
183     dp = vec3_dot( v3w, v3x_ );
184     ref_pt = vec3_times( dp, v3x_ );
185     v3y = vec3_diff( v3w, ref_pt );
186 
187 
188     p1 = vec2( 0.0, 0.0 );
189     p2 = vec2( vec3_mod( v3x ), 0.0 );
190     if ( dp < 0.0 ) p3 = vec2( -vec3_mod( ref_pt ), vec3_mod( v3y ) );
191     else p3 = vec2( vec3_mod( ref_pt ), vec3_mod( v3y ) );
192 
193     ex = v3x_;
194     ey = vec3_unit(v3y);
195 
196     conic = conic_circ_3pt( p1, p2, p3 );
197     c = conic->center;
198 
199     origin = vec3_sum( v3a, vec3_times( vec2_x(c), ex ) );
200     origin = vec3_sum( origin, vec3_times( vec2_y(c), ey ) );
201 
202     conic->center = vec2(0.0,0.0);
203 
204     origin.el[1] *= handupdate;
205     ex.el[1] *= handupdate;
206     ey.el[1] *= handupdate;
207     ez = vec3_unit(vec3_cross(ex, ey));
208     conic->label = label;
209     return (conic3_make(conic, origin, ex, ey, ez));
210 }
211 
212 
213 
214 
215 static Plane *plane_sscanf(char *str, int handed)
216 {
217     float   handupdate = (float)((handed == LEFT) ? -1.0 : 1.0);
218     int     label;
219     Vec3    p = {Vec3_id};
220     Vec3    n = {Vec3_id};
221     Plane  *plane;
222 
223     if (sscanf(str, "%*s %d %f %f %f %f %f %f",
224                &label,
225                &vec3_x(p), &vec3_y(p), &vec3_z(p),
226                &vec3_x(n), &vec3_y(n), &vec3_z(n)) != 7)
227         return (NULL);
228 
229     p.el[1] *= handupdate;
230     n.el[1] *= handupdate;
231     plane = plane_make(p, n, FROM_FILE);
232     plane->label = label;
233     return (plane);
234 }
235 
236 List   *geom3_read_fp(FILE * fp, int handed)
237 /* LEFT or RIGHT handed coords */
238 {
239     void   *geom;
240     char    str[512];
241     char    type_s[2];
242     List   *list = NULL;
243     int     type;
244 
245     while (fgets(str, 512, fp) != NULL)
246     {
247         (void) sscanf(str, "%s", type_s);
248         switch (type_s[0])
249         {
250         case 'P':               /* point */
251             geom = (void *) point3_sscanf(str, handed);
252             type = POINT3;
253             break;
254         case 'S':               /* straight line */
255             geom = (void *) line3_sscanf(str, handed);
256             type = LINE3;
257             break;
258         case 'H':               /* ellipse section */
259             geom = (void *) hyperbola3_sscanf(str, handed);
260             type = CONIC3;
261             break;
262         case 'E':               /* ellipse section */
263             geom = (void *) ellipse3_sscanf(str, handed);
264             type = CONIC3;
265             break;
266         case 'C':               /* ellipse section */
267             geom = (void *) circle3_sscanf(str, handed);
268             type = CONIC3;
269             break;
270         case 'N':               /* plane section */
271             geom = (void *) plane_sscanf(str, handed);
272             type = PLANE;
273             break;
274         default:
275             continue;
276         }
277         if (geom != NULL)
278             list = ref_addtostart(list, geom, type);
279     }
280 
281     return (list_reverse(list));
282 }
283 
284 List   *geom3_read(char *pathname, int handed)
285 
286 /* LEFT or RIGHT handed coords */
287 {
288     char    temps[256];
289     List   *geom;
290     FILE   *fp;
291 
292     if ((fp = fopen(pathname, "r")) == NULL)
293     {
294         (void) string_append(temps, "can not open file ", pathname, 0);
295         error(temps, non_fatal);
296         return (NULL);
297     }
298     geom = geom3_read_fp(fp, handed);
299     (void) fclose(fp);
300     return (geom);
301 }
302 
303 List   *line3_read_geom(char *pathname, int handed)     /* historical */
304 
305 /* LEFT or RIGHT handed coords */
306 {
307     return (geom3_read(pathname, handed));
308 }
309 

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