object.cpp
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 <artoolkit/AR/ar.h>
00030 #include <ros/ros.h>
00031 #include <ros/package.h>
00032 
00033 #include "ar_pose/object.h"
00034 
00035 namespace ar_object
00036 {
00037 
00038   static char *get_buff (char *buf, int n, FILE * fp);
00039 
00040   ObjectData_T *read_ObjData (char *name, int *objectnum)
00041   {
00042     FILE *fp;
00043     ObjectData_T *object;
00044     char buf[256], buf1[256];
00045     int i;
00046       std::string package_path = ros::package::getPath (ROS_PACKAGE_NAME);
00047 
00048       ROS_INFO ("Opening Data File %s", name);
00049 
00050     if ((fp = fopen (name, "r")) == NULL)
00051     {
00052       ROS_INFO ("Can't find the file - quitting");
00053       ROS_BREAK ();
00054     }
00055 
00056     get_buff (buf, 256, fp);
00057     if (sscanf (buf, "%d", objectnum) != 1)
00058     {
00059       fclose (fp);
00060       ROS_BREAK ();
00061     }
00062 
00063     ROS_INFO ("About to load %d Models", *objectnum);
00064 
00065     object = (ObjectData_T *) malloc (sizeof (ObjectData_T) * *objectnum);
00066     if (object == NULL)
00067       ROS_BREAK ();
00068 
00069     for (i = 0; i < *objectnum; i++)
00070     {
00071       object[i].visible = 0;
00072 
00073       get_buff (buf, 256, fp);
00074       if (sscanf (buf, "%s", object[i].name) != 1)
00075       {
00076         fclose (fp);
00077         free (object);
00078         ROS_BREAK ();
00079       }
00080 
00081       ROS_INFO ("Read in No.%d", i + 1);
00082 
00083       get_buff (buf, 256, fp);
00084       if (sscanf (buf, "%s", buf1) != 1)
00085       {
00086         fclose (fp);
00087         free (object);
00088         ROS_BREAK ();
00089       }
00090 
00091       sprintf (buf, "%s/%s", package_path.c_str (), buf1);
00092       if ((object[i].id = arLoadPatt (buf)) < 0)
00093       {
00094         fclose (fp);
00095         free (object);
00096         ROS_BREAK ();
00097       }
00098 
00099       get_buff (buf, 256, fp);
00100       if (sscanf (buf, "%lf", &object[i].marker_width) != 1)
00101       {
00102         fclose (fp);
00103         free (object);
00104         ROS_BREAK ();
00105       }
00106 
00107       get_buff (buf, 256, fp);
00108       if (sscanf (buf, "%lf %lf", &object[i].marker_center[0], &object[i].marker_center[1]) != 2)
00109       {
00110         fclose (fp);
00111         free (object);
00112         ROS_BREAK ();
00113       }
00114     }
00115 
00116     fclose (fp);
00117 
00118     return (object);
00119   }
00120 
00121   static char *get_buff (char *buf, int n, FILE * fp)
00122   {
00123     char *ret;
00124 
00125     for (;;)
00126     {
00127       ret = fgets (buf, n, fp);
00128       if (ret == NULL)
00129         return (NULL);
00130       if (buf[0] != '\n' && buf[0] != '#')
00131         return (ret);
00132     }
00133   }
00134 }


ar_pose
Author(s): Ivan Dryanovsk, Bill Morris , Gautier Dumonteil
autogenerated on Thu Jun 6 2019 20:27:27