Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #include <stdio.h>
00008 #include <stdlib.h>
00009 #include <string.h>
00010 #include <AR/ar.h>
00011 #include <AR/arvrml.h>
00012 #include "object.h"
00013
00014 static char *get_buff(char *buf, int n, FILE *fp)
00015 {
00016 char *ret;
00017
00018 for(;;) {
00019 ret = fgets(buf, n, fp);
00020 if (ret == NULL) return(NULL);
00021 if (buf[0] != '\n' && buf[0] != '#') return(ret);
00022 }
00023 }
00024
00025 ObjectData_T *read_VRMLdata( char *name, int *objectnum )
00026 {
00027 FILE *fp;
00028 ObjectData_T *object;
00029 char buf[256], buf1[256];
00030 int i;
00031
00032 printf("Opening model file %s\n", name);
00033
00034 if ((fp=fopen(name, "r")) == NULL) return(0);
00035
00036 get_buff(buf, 256, fp);
00037 if (sscanf(buf, "%d", objectnum) != 1) {
00038 fclose(fp); return(0);
00039 }
00040
00041 printf("About to load %d models.\n", *objectnum);
00042
00043 if ((object = (ObjectData_T *)malloc(sizeof(ObjectData_T) * (*objectnum))) == NULL) exit (-1);
00044
00045 for (i = 0; i < *objectnum; i++) {
00046
00047 get_buff(buf, 256, fp);
00048 if (sscanf(buf, "%s %s", buf1, object[i].name) != 2) {
00049 fclose(fp); free(object); return(0);
00050 }
00051
00052 printf("Model %d: %20s\n", i + 1, &(object[i].name[0]));
00053
00054 if (strcmp(buf1, "VRML") == 0) {
00055 object[i].vrml_id = arVrmlLoadFile(object[i].name);
00056 printf("VRML id - %d \n", object[i].vrml_id);
00057 if (object[i].vrml_id < 0) {
00058 fclose(fp); free(object); return(0);
00059 }
00060 } else {
00061 object[i].vrml_id = -1;
00062 }
00063 object[i].vrml_id_orig = object[i].vrml_id;
00064 object[i].visible = 0;
00065
00066 get_buff(buf, 256, fp);
00067 if (sscanf(buf, "%s", buf1) != 1) {
00068 fclose(fp); free(object); return(0);
00069 }
00070
00071 if ((object[i].id = arLoadPatt(buf1)) < 0) {
00072 fclose(fp); free(object); return(0);
00073 }
00074
00075 get_buff(buf, 256, fp);
00076 if (sscanf(buf, "%lf", &object[i].marker_width) != 1) {
00077 fclose(fp); free(object); return(0);
00078 }
00079
00080 get_buff(buf, 256, fp);
00081 if (sscanf(buf, "%lf %lf", &object[i].marker_center[0], &object[i].marker_center[1]) != 2) {
00082 fclose(fp); free(object); return(0);
00083 }
00084
00085 }
00086
00087 fclose(fp);
00088
00089 return( object );
00090 }