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

Linux Cross Reference
Tina5/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: 2008/12/04 15:28:02 $
 38  * Version :  $Revision: 1.6 $
 39  * CVS Id  :  $Id: fileGeom3_read.c,v 1.6 2008/12/04 15:28:02 paul 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 static Conic3 *circle3_sscanf(char *str, int handed)
163 {
164     float   handupdate = (float)((handed == LEFT) ? -1.0 : 1.0);
165     int     label, flag=0;
166     Vec3    origin = {Vec3_id}, ex = {Vec3_id}, ey = {Vec3_id}, ez = {Vec3_id};
167     Vec2    p1 = {Vec2_id}, p2 = {Vec2_id}, p3 = {Vec2_id}, c;
168     float   p1x, p2x, p3x, p1y, p2y, p3y, p1z, p2z, p3z;
169     Conic  *conic;
170 
171     if (sscanf(str, "%*s %d %f %f %f %f %f %f %f %f %f",
172                &label,
173                &p1x, &p1y, &p1z, 
174                &p2x, &p2y, &p2z,
175                &p3x, &p3y, &p3z ) != 10)
176     return (NULL);
177 
178     if ( p1x == p2x && p2x == p3x ) 
179     {
180         vec2_x(p1) = p1z; vec2_y(p1) = p1y;
181         vec2_x(p2) = p2z; vec2_y(p2) = p2y;
182         vec2_x(p3) = p3z; vec2_y(p3) = p3y;
183         vec3_x(ex) = 0; vec3_y(ex) = 0; vec3_z(ex) = 1; 
184         vec3_x(ey) = 0; vec3_y(ey) = 1; vec3_z(ey) = 0; 
185         flag = 1;
186     }
187     else if ( p1y == p2y && p2y == p3y ) 
188     {
189         vec2_x(p1) = p1x; vec2_y(p1) = p1z;
190         vec2_x(p2) = p2x; vec2_y(p2) = p2z;
191         vec2_x(p3) = p3x; vec2_y(p3) = p3z;
192         vec3_x(ex) = 1; vec3_y(ex) = 0; vec3_z(ex) = 0; 
193         vec3_x(ey) = 0; vec3_y(ey) = 0; vec3_z(ey) = 1; 
194         flag = 2;
195     }
196     else if ( p1z == p2z && p2z == p3z ) 
197     {
198         vec2_x(p1) = p1x; vec2_y(p1) = p1y;
199         vec2_x(p2) = p2x; vec2_y(p2) = p2y;
200         vec2_x(p3) = p3x; vec2_y(p3) = p3y;
201         vec3_x(ex) = 1; vec3_y(ex) = 0; vec3_z(ex) = 0; 
202         vec3_x(ey) = 0; vec3_y(ey) = 1; vec3_z(ey) = 0;
203         flag = 3;
204     }
205     else printf("Error: 3pt circle plot only set up to work with circles lying on x, y or z planes at present\n");
206 
207     conic = conic_circ_3pt( p3, p2, p1 );
208     c = conic->center;
209 
210     if ( flag == 1 ) 
211     {
212         vec3_x(origin) = p1x; vec3_y(origin) = vec2_y(c); vec3_z(origin) = vec2_x(c);
213     }
214     if ( flag == 2 ) 
215     {
216         vec3_x(origin) = vec2_x(c); vec3_y(origin) = p1y; vec3_z(origin) = vec2_y(c);
217     }
218     if ( flag == 3 ) 
219     {
220         vec3_x(origin) = vec2_x(c); vec3_y(origin) = vec2_y(c); vec3_z(origin) = p1z;
221     }
222     conic->center.el[0] = 0.0;
223     conic->center.el[1] = 0.0;
224 
225     origin.el[1] *= handupdate;
226     ex.el[1] *= handupdate;
227     ey.el[1] *= handupdate;
228     ez = vec3_unit(vec3_cross(ex, ey));
229     conic->label = label;
230     return (conic3_make(conic, origin, ex, ey, ez));
231 }
232 
233 static Plane *plane_sscanf(char *str, int handed)
234 {
235     float   handupdate = (float)((handed == LEFT) ? -1.0 : 1.0);
236     int     label;
237     Vec3    p = {Vec3_id};
238     Vec3    n = {Vec3_id};
239     Plane  *plane;
240 
241     if (sscanf(str, "%*s %d %f %f %f %f %f %f",
242                &label,
243                &vec3_x(p), &vec3_y(p), &vec3_z(p),
244                &vec3_x(n), &vec3_y(n), &vec3_z(n)) != 7)
245         return (NULL);
246 
247     p.el[1] *= handupdate;
248     n.el[1] *= handupdate;
249     plane = plane_make(p, n, FROM_FILE);
250     plane->label = label;
251     return (plane);
252 }
253 
254 List   *geom3_read_fp(FILE * fp, int handed)
255 
256 /* LEFT or RIGHT handed coords */
257 {
258     void   *geom;
259     char    str[512];
260     char    type_s[2];
261     List   *list = NULL;
262     int     type;
263 
264     while (fgets(str, 512, fp) != NULL)
265     {
266         (void) sscanf(str, "%s", type_s);
267         switch (type_s[0])
268         {
269         case 'P':               /* point */
270             geom = (void *) point3_sscanf(str, handed);
271             type = POINT3;
272             break;
273         case 'S':               /* straight line */
274             geom = (void *) line3_sscanf(str, handed);
275             type = LINE3;
276             break;
277         case 'H':               /* ellipse section */
278             geom = (void *) hyperbola3_sscanf(str, handed);
279             type = CONIC3;
280             break;
281         case 'E':               /* ellipse section */
282             geom = (void *) ellipse3_sscanf(str, handed);
283             type = CONIC3;
284             break;
285         case 'C':               /* ellipse section */
286             geom = (void *) circle3_sscanf(str, handed);
287             type = CONIC3;
288             break;
289         case 'N':               /* plane section */
290             geom = (void *) plane_sscanf(str, handed);
291             type = PLANE;
292             break;
293         default:
294             continue;
295         }
296         if (geom != NULL)
297             list = ref_addtostart(list, geom, type);
298     }
299 
300     return (list_reverse(list));
301 }
302 
303 List   *geom3_read(char *pathname, int handed)
304 
305 /* LEFT or RIGHT handed coords */
306 {
307     char    temps[256];
308     List   *geom;
309     FILE   *fp;
310 
311     if ((fp = fopen(pathname, "r")) == NULL)
312     {
313         (void) string_append(temps, "can not open file ", pathname, 0);
314         error(temps, non_fatal);
315         return (NULL);
316     }
317     geom = geom3_read_fp(fp, handed);
318     (void) fclose(fp);
319     return (geom);
320 }
321 
322 List   *line3_read_geom(char *pathname, int handed)     /* historical */
323 
324 /* LEFT or RIGHT handed coords */
325 {
326     return (geom3_read(pathname, handed));
327 }
328 

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