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

Linux Cross Reference
Tina4/src/file/geom/geom3_read.c

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

  1 /**@(#)
  2   */
  3 #include <stdio.h>
  4 #include <tina/sys.h>
  5 #include <tina/sysfuncs.h>
  6 #include <tina/math.h>
  7 #include <tina/mathfuncs.h>
  8 #include <tina/vision.h>
  9 #include <tina/visionfuncs.h>
 10 
 11 static Point3 *point3_sscanf(char *str, int handed)
 12 {
 13     float   handupdate = (float)((handed == LEFT) ? -1.0 : 1.0);
 14     int     label;
 15     Vec3    p1 = {Vec3_id};
 16     Point3 *point;
 17 
 18     if (sscanf(str, "%*s %d %*d %f %f %f ",
 19                &label,
 20                &vec3_x(p1), &vec3_y(p1), &vec3_z(p1)) != 4)
 21         return (NULL);
 22 
 23     p1.el[1] *= handupdate;
 24     point = point3_make(p1, FROM_FILE);
 25     point->label = label;
 26     return (point);
 27 }
 28 
 29 static Line3 *line3_sscanf(char *str, int handed)
 30 {
 31     float   handupdate = (float)((handed == LEFT) ? -1.0 : 1.0);
 32     int     label;
 33     Vec3    p1 = {Vec3_id};
 34     Vec3    p2 = {Vec3_id};
 35     Line3  *line;
 36 
 37     if (sscanf(str, "%*s %d %*d %*f %f %f %f %f %f %f ",
 38                &label,
 39                &vec3_x(p1), &vec3_y(p1), &vec3_z(p1),
 40                &vec3_x(p2), &vec3_y(p2), &vec3_z(p2)) != 7)
 41         return (NULL);
 42 
 43     p1.el[1] *= handupdate;
 44     p2.el[1] *= handupdate;
 45     line = line3_make(p1, p2, FROM_FILE);
 46     line->label = label;
 47     return (line);
 48 }
 49 
 50 static Conic3 *ellipse3_sscanf(char *str, int handed)
 51 {
 52     float   handupdate = (float)((handed == LEFT) ? -1.0 : 1.0);
 53     int     label;
 54     Vec3    origin = {Vec3_id};
 55     Vec3    ex = {Vec3_id};
 56     Vec3    ey = {Vec3_id};
 57     Vec3    ez = {Vec3_id};
 58     float   theta, alpha, beta, t1, t2;
 59     Conic  *conic;
 60 
 61     if (sscanf(str, "%*s %d %f %f %f %f %f %f %f %f %f %f %f %f %f %f",
 62                &label,
 63                &vec3_x(origin), &vec3_y(origin), &vec3_z(origin),
 64                &vec3_x(ex), &vec3_y(ex), &vec3_z(ex),
 65                &vec3_x(ey), &vec3_y(ey), &vec3_z(ey),
 66                &theta, &alpha, &beta, &t1, &t2) != 15)
 67         return (NULL);
 68 
 69     origin.el[1] *= handupdate;
 70     ex.el[1] *= handupdate;
 71     ey.el[1] *= handupdate;
 72     ez = vec3_unit(vec3_cross(ex, ey));
 73 
 74     conic = conic_make(ELLIPSE, vec2(0.0, 0.0), theta, alpha, beta, t1, t2, 0);
 75     conic->label = label;
 76     return (conic3_make(conic, origin, ex, ey, ez));
 77 }
 78 
 79 static Plane *plane_sscanf(char *str, int handed)
 80 {
 81     float   handupdate = (float)((handed == LEFT) ? -1.0 : 1.0);
 82     int     label;
 83     Vec3    p = {Vec3_id};
 84     Vec3    n = {Vec3_id};
 85     Plane  *plane;
 86 
 87     if (sscanf(str, "%*s %d %f %f %f %f %f %f",
 88                &label,
 89                &vec3_x(p), &vec3_y(p), &vec3_z(p),
 90                &vec3_x(n), &vec3_y(n), &vec3_z(n)) != 7)
 91         return (NULL);
 92 
 93     p.el[1] *= handupdate;
 94     n.el[1] *= handupdate;
 95     plane = plane_make(p, n, FROM_FILE);
 96     plane->label = label;
 97     return (plane);
 98 }
 99 
100 List   *geom3_read_fp(FILE * fp, int handed)
101 
102 /* LEFT or RIGHT handed coords */
103 {
104     void   *geom;
105     char    str[512];
106     char    type_s[2];
107     List   *list = NULL;
108     int     type;
109 
110     while (fgets(str, 512, fp) != NULL)
111     {
112         (void) sscanf(str, "%s", type_s);
113         switch (type_s[0])
114         {
115         case 'P':               /* point */
116             geom = (void *) point3_sscanf(str, handed);
117             type = POINT3;
118             break;
119         case 'S':               /* straight line */
120             geom = (void *) line3_sscanf(str, handed);
121             type = LINE3;
122             break;
123         case 'E':               /* ellipse section */
124             geom = (void *) ellipse3_sscanf(str, handed);
125             type = CONIC3;
126             break;
127         case 'N':               /* plane section */
128             geom = (void *) plane_sscanf(str, handed);
129             type = PLANE;
130             break;
131         default:
132             continue;
133         }
134         if (geom != NULL)
135             list = ref_addtostart(list, geom, type);
136     }
137 
138     return (list_reverse(list));
139 }
140 
141 List   *geom3_read(char *pathname, int handed)
142 
143 /* LEFT or RIGHT handed coords */
144 {
145     char    temps[256];
146     List   *geom;
147     FILE   *fp;
148 
149     if ((fp = fopen(pathname, "r")) == NULL)
150     {
151         (void) string_append(temps, "can not open file ", pathname, 0);
152         error(temps, non_fatal);
153         return (NULL);
154     }
155     geom = geom3_read_fp(fp, handed);
156     (void) fclose(fp);
157     return (geom);
158 }
159 
160 List   *line3_read_geom(char *pathname, int handed)     /* historical */
161 
162 /* LEFT or RIGHT handed coords */
163 {
164     return (geom3_read(pathname, handed));
165 }
166 

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