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