object.c
Go to the documentation of this file.
00001 
00002 /* 
00003 ** ARToolKit object parsing function 
00004 **   - reads in object data from object file in Data/object_data
00005 **
00006 */
00007 
00008 #ifdef _WIN32
00009 #include <windows.h>
00010 #endif
00011 #include <stdio.h>
00012 #ifndef __APPLE__
00013 #include <malloc.h>
00014 #endif
00015 #include <stdlib.h>
00016 #include <AR/ar.h>
00017 #include "object.h"
00018 
00019 static char *get_buff( char *buf, int n, FILE *fp );
00020 
00021 ObjectData_T *read_objectdata( char *name, int *objectnum )
00022 {
00023     FILE          *fp;
00024     ObjectData_T  *object;
00025     char           buf[256], buf1[256];
00026     int            i;
00027 
00028     if( (fp=fopen(name, "r")) == NULL ) return(0);
00029 
00030     get_buff(buf, 256, fp);
00031     if( sscanf(buf, "%d", objectnum) != 1 ) {fclose(fp); return(0);}
00032 
00033     object = (ObjectData_T *)malloc( sizeof(ObjectData_T) * *objectnum );
00034     if( object == NULL ) return(0);
00035 
00036     for( i = 0; i < *objectnum; i++ ) {
00037         get_buff(buf, 256, fp);
00038         if( sscanf(buf, "%s", object[i].name) != 1 ) {
00039           fclose(fp); free(object); return(0);}
00040 
00041         get_buff(buf, 256, fp);
00042         if( sscanf(buf, "%s", buf1) != 1 ) {
00043           fclose(fp); free(object); return(0);}
00044         
00045         if( (object[i].id = arLoadPatt(buf1)) < 0 )
00046             {fclose(fp); free(object); return(0);}
00047 
00048         object[i].visible = 0;
00049 
00050         get_buff(buf, 256, fp);
00051         if( sscanf(buf, "%lf", &object[i].marker_width) != 1 ) {
00052             fclose(fp); free(object); return(0);
00053         }
00054 
00055         printf("No.%d: %20s\n", i+1, &(object[i].name[0]) );
00056     }
00057 
00058     fclose(fp);
00059 
00060     return( object );
00061 }
00062 
00063 static char *get_buff( char *buf, int n, FILE *fp )
00064 {
00065     char *ret;
00066 
00067     for(;;) {
00068         ret = fgets( buf, n, fp );
00069         if( ret == NULL ) return(NULL);
00070         if( buf[0] != '\n' && buf[0] != '#' ) return(ret);
00071     }
00072 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines


ar_recog
Author(s): Graylin Trevor Jay and Christopher Crick
autogenerated on Fri Jan 25 2013 12:15:00