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 ** Format:
00007 ** <obj_num>
00008 **
00009 ** <obj_name>
00010 ** <obj_pattern filename>
00011 ** <marker_width>
00012 ** <centerX centerY>
00013 **
00014 ** ...
00015 **
00016 **      eg
00017 **
00018 **      #pattern 1
00019 **      Hiro
00020 **      Data/hiroPatt 
00021 **      80.0
00022 **      0.0 0.0
00023 **
00024 */
00025 
00026 #include <stdio.h>
00027 #include <stdlib.h>
00028 #include <string.h>
00029 #include <AR/ar.h>
00030 #include "object.h"
00031 
00032 static char *get_buff( char *buf, int n, FILE *fp );
00033 
00034 ObjectData_T *read_ObjData( char *name, int *objectnum )
00035 {
00036     FILE          *fp;
00037     ObjectData_T  *object;
00038     char           buf[256], buf1[256];
00039     int            i;
00040 
00041         printf("Opening Data File %s\n",name);
00042 
00043     if( (fp=fopen(name, "r")) == NULL ) {
00044                 printf("Can't find the file - quitting \n");
00045                 return(0);
00046         }
00047 
00048     get_buff(buf, 256, fp);
00049     if( sscanf(buf, "%d", objectnum) != 1 ) {fclose(fp); return(0);}
00050 
00051         printf("About to load %d Models\n",*objectnum);
00052 
00053     object = (ObjectData_T *)malloc( sizeof(ObjectData_T) * *objectnum );
00054     if( object == NULL ) return(0);
00055 
00056     for( i = 0; i < *objectnum; i++ ) {
00057                 object[i].visible = 0;        
00058                 
00059                 get_buff(buf, 256, fp);
00060         if( sscanf(buf, "%s", object[i].name) != 1 ) {
00061             fclose(fp); free(object); return(0);
00062         }
00063 
00064                 printf("Read in No.%d \n", i+1);
00065 
00066         get_buff(buf, 256, fp);
00067         if( sscanf(buf, "%s", buf1) != 1 ) {
00068           fclose(fp); free(object); return(0);}
00069         
00070         if( (object[i].id = arLoadPatt(buf1)) < 0 )
00071             {fclose(fp); free(object); return(0);}
00072 
00073         get_buff(buf, 256, fp);
00074         if( sscanf(buf, "%lf", &object[i].marker_width) != 1 ) {
00075             fclose(fp); free(object); return(0);
00076         }
00077 
00078         get_buff(buf, 256, fp);
00079         if( sscanf(buf, "%lf %lf", &object[i].marker_center[0],
00080             &object[i].marker_center[1]) != 2 ) {
00081             fclose(fp); free(object); return(0);
00082         }
00083         
00084     }
00085 
00086     fclose(fp);
00087 
00088     return( object );
00089 }
00090 
00091 static char *get_buff( char *buf, int n, FILE *fp )
00092 {
00093     char *ret;
00094 
00095     for(;;) {
00096         ret = fgets( buf, n, fp );
00097         if( ret == NULL ) return(NULL);
00098         if( buf[0] != '\n' && buf[0] != '#' ) return(ret);
00099     }
00100 }
 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