simple_graspit_database.cpp
Go to the documentation of this file.
00001 #ifdef DOXYGEN_SHOULD_SKIP_THIS
00002 
00021 #endif  // DOXYGEN_SHOULD_SKIP_THIS
00022 
00023 #include <string>
00024 #include <vector>
00025 #include <stdio.h>
00026 #include <execinfo.h>
00027 #include <signal.h>
00028 #include <stdlib.h>
00029 #include <unistd.h>
00030 
00031 #include <grasp_planning_graspit/GraspItSceneManagerHeadless.h>
00032 #include <grasp_planning_graspit/GraspItSimpleDBManager.h>
00033 #include <grasp_planning_graspit/LogBinding.h>
00034 
00035 
00039 void print_trace(void)
00040 {
00041     void *array[10];
00042     size_t size;
00043     char **strings;
00044     size_t i;
00045 
00046     size = backtrace(array, 10);
00047     strings = backtrace_symbols(array, size);
00048 
00049     printf("Obtained %zd stack frames.\n", size);
00050 
00051     for (i = 0; i < size; i++)
00052         printf("%s\n", strings[i]);
00053 
00054     free(strings);
00055 }
00056 
00057 
00058 void handler(int sig)
00059 {
00060     print_trace();
00061     exit(1);
00062 }
00063 
00064 
00065 int run(int argc, char **argv)
00066 {
00067     if (argc < 4)
00068     {
00069         PRINTMSG("Usage: " << argv[0] << " <outputDir> <robotFile> <objectFile>");
00070         return 0;
00071     }
00072 
00073     std::string outputDirectory(argv[1]);
00074     std::string robotFilename(argv[2]);
00075     std::string objectFilename(argv[3]);
00076 
00077     PRINTMSG("Creating database");
00078     std::string name = "Database1";
00079     SHARED_PTR<GraspIt::GraspItSceneManager> graspitMgr(new GraspIt::GraspItSceneManagerHeadless());
00080 
00081     SHARED_PTR<GraspIt::GraspItSimpleDBManager> mgr(new GraspIt::GraspItSimpleDBManager(name, graspitMgr));
00082 
00083     std::string robotName("Robot1");
00084     std::string objectName("Object1");
00085 
00086     PRINTMSG("Now loading robot");
00087 
00088     int robotID = -1;
00089     int objectID = -1;
00090 
00091     // here we'd have to put the robot joint names, we'll leave this empty for this test fle
00092     std::vector<std::string> jointNames;
00093     if ((robotID = mgr->loadRobotToDatabase(robotFilename, robotName, jointNames)) < 0)
00094     {
00095         PRINTERROR("Could not load robot");
00096         return 0;
00097     }
00098 
00099     PRINTMSG("Now loading object");
00100 
00101     if ((objectID = mgr->loadObjectToDatabase(objectFilename, objectName, true)) < 0)
00102     {
00103         PRINTERROR("Could not load object");
00104         return 0;
00105     }
00106 
00107     // Now objects should be in the database only, but not in the world.
00108     // Re-add them to test if the world still workds afterwards:
00109     PRINTMSG("Now loading robot to world");
00110     if (mgr->loadToWorld(robotID, GraspIt::EigenTransform::Identity()) != 0)
00111     {
00112         PRINTERROR("Could not add the robot to the graspit world");
00113         return 0;
00114     }
00115 
00116     PRINTMSG("Now loading object to world");
00117     if (mgr->loadToWorld(objectID, GraspIt::EigenTransform::Identity()) != 0)
00118     {
00119         PRINTERROR("Could not add the object to the graspit world");
00120         return 0;
00121     }
00122 
00123     PRINTMSG("Saving world files");
00124 
00125     // test to see if it worked: save as world
00126     bool createDir = true;  // if true, the directory will be created, if it doesn't exist.
00127     graspitMgr->saveGraspItWorld(outputDirectory + "/dbtest/world.xml", createDir);
00128     graspitMgr->saveInventorWorld(outputDirectory + "/dbtest/world.iv", createDir);
00129 
00130     PRINTMSG("Quitting program.");
00131     return 0;
00132 }
00133 
00134 int main(int argc, char **argv)
00135 {
00136     signal(SIGSEGV, handler);
00137     signal(SIGABRT, handler);
00138 
00139     PRINT_INIT_STD();
00140 
00141     int ret = run(argc, argv);
00142     PRINTMSG("Result of run(): " << ret);
00143     return 0;
00144 }


grasp_planning_graspit
Author(s): Jennifer Buehler
autogenerated on Wed May 8 2019 02:53:36