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

Linux Cross Reference
Tina4/src/file/geom/geom2_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 Line2 *line2_sscanf(char *str)
 12 {
 13     int     label;
 14     Vec2    p1 = {Vec2_id};
 15     Vec2    p2 = {Vec2_id};
 16     Line2  *line;
 17 
 18     if (sscanf(str, "%*s %d %*d %*f %f %f %*f %f %f %*f ",
 19                &label,
 20                &vec2_x(p1), &vec2_y(p1),
 21                &vec2_x(p2), &vec2_y(p2)) != 5)
 22         return (NULL);
 23 
 24     line = line2_make(p1, p2, FROM_FILE);
 25     line->label = label;
 26     return (line);
 27 }
 28 
 29 static Conic *ellipse2_sscanf(char *str)
 30 {
 31     int     label;
 32     Vec2    center = {Vec2_id};
 33     float   theta, alpha, beta, t1, t2;
 34     Conic  *conic;
 35 
 36 
 37     if (sscanf(str, "%*s %d %f %f %*f %*f %*f %*f %*f %*f %*f %f %f %f %f %f",
 38                &label,
 39                &vec2_x(center), &vec2_y(center),
 40                &theta, &alpha, &beta, &t1, &t2) != 8)
 41         return (NULL);
 42     conic = conic_make(ELLIPSE, center, theta, alpha, beta, t1, t2, 0);
 43     conic->label = label;
 44     return (conic);
 45 }
 46 
 47 List   *geom2_read_fp(FILE * fp)
 48 {
 49     void   *geom;
 50     char    str[512];
 51     char    type_s[2];
 52     List   *list = NULL;
 53     int     type;
 54 
 55     while (fgets(str, 512, fp) != NULL)
 56     {
 57         (void) sscanf(str, "%s", type_s);
 58         switch (type_s[0])
 59         {
 60         case 'S':               /* straight line */
 61             geom = (void *) line2_sscanf(str);
 62             type = LINE2;
 63             break;
 64         case 'E':               /* ellipse section */
 65             geom = (void *) ellipse2_sscanf(str);
 66             type = CONIC2;
 67             break;
 68         default:
 69             continue;
 70         }
 71         if (geom != NULL)
 72             list = ref_addtostart(list, geom, type);
 73     }
 74 
 75     return (list_reverse(list));
 76 }
 77 
 78 List   *geom2_read(char *pathname)
 79 {
 80     char    temps[256];
 81     List   *geom;
 82     FILE   *fp;
 83 
 84     if ((fp = fopen(pathname, "r")) == NULL)
 85     {
 86         (void) string_append(temps, "can not open file ", pathname, 0);
 87         error(temps, non_fatal);
 88         return (NULL);
 89     }
 90     geom = geom2_read_fp(fp);
 91     (void) fclose(fp);
 92     return (geom);
 93 }
 94 
 95 List   *line2_read_geom(char *pathname) /* historical */
 96 
 97 {
 98     return (geom2_read(pathname));
 99 }
100 

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