object.cpp
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 ** Format:
00006 ** <obj_num>
00007 **
00008 ** <obj_name>
00009 ** <obj_pattern filename>
00010 ** <marker_width>
00011 ** <centerX centerY>
00012 **
00013 ** ...
00014 **
00015 **      eg
00016 **
00017 **      #pattern 1
00018 **      Hiro
00019 **      Data/hiroPatt 
00020 **      80.0
00021 **      0.0 0.0
00022 **
00023 */
00024 
00025 #include <stdio.h>
00026 #include <stdlib.h>
00027 #include <string.h>
00028 #include <AR/ar.h>
00029 #include <ros/ros.h>
00030 #include <ros/package.h>
00031 
00032 #include "ar_kinect/object.h"
00033 
00034 namespace ar_object
00035 {
00036 
00037   static char *get_buff (char *buf, int n, FILE * fp);
00038 
00039   ObjectData_T *read_ObjData (char *name, char *dir, int *objectnum)
00040   {
00041     FILE *fp;
00042     ObjectData_T *object;
00043     char buf[256], buf1[256];
00044     int i;
00045       //std::string package_path = ros::package::getPath (ROS_PACKAGE_NAME);
00046 
00047     ROS_INFO ("Opening Data File %s", name);
00048 
00049     if ((fp = fopen (name, "r")) == NULL)
00050     {
00051       ROS_INFO ("Can't find the file - quitting");
00052       ROS_BREAK ();
00053     }
00054 
00055     get_buff (buf, 256, fp);
00056     if (sscanf (buf, "%d", objectnum) != 1)
00057     {
00058       fclose (fp);
00059       ROS_BREAK ();
00060     }
00061 
00062     ROS_INFO ("About to load %d Models", *objectnum);
00063 
00064     object = (ObjectData_T *) malloc (sizeof (ObjectData_T) * *objectnum);
00065     if (object == NULL)
00066       ROS_BREAK ();
00067 
00068     for (i = 0; i < *objectnum; i++)
00069     {
00070       object[i].visible = 0;
00071 
00072       get_buff (buf, 256, fp);
00073       if (sscanf (buf, "%s", object[i].name) != 1)
00074       {
00075         fclose (fp);
00076         free (object);
00077         ROS_BREAK ();
00078       }
00079 
00080       ROS_INFO ("Read in No.%d", i + 1);
00081 
00082       get_buff (buf, 256, fp);
00083       if (sscanf (buf, "%s", buf1) != 1)
00084       {
00085         fclose (fp);
00086         free (object);
00087         ROS_BREAK ();
00088       }
00089 
00090       sprintf (buf, "%s/%s", dir, buf1);
00091       if ((object[i].id = arLoadPatt (buf)) < 0)
00092       {
00093         fclose (fp);
00094         free (object);
00095         ROS_BREAK ();
00096       }
00097 
00098       get_buff (buf, 256, fp);
00099       if (sscanf (buf, "%lf", &object[i].marker_width) != 1)
00100       {
00101         fclose (fp);
00102         free (object);
00103         ROS_BREAK ();
00104       }
00105 
00106       get_buff (buf, 256, fp);
00107       if (sscanf (buf, "%lf %lf", &object[i].marker_center[0], &object[i].marker_center[1]) != 2)
00108       {
00109           object[i].marker_center[0] = 0;
00110           object[i].marker_center[1] = 0;
00111 
00112           ROS_WARN("File error, during center read.");
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_bounding_box
Author(s): Andreas Koch
autogenerated on Sun Jan 5 2014 11:40:39