Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 #include "urdf/model.h"
00038 #include <iostream>
00039 #include <fstream>
00040 
00041 using namespace urdf;
00042 
00043 void printTree(boost::shared_ptr<const Link> link,int level = 0)
00044 {
00045   level+=2;
00046   int count = 0;
00047   for (std::vector<boost::shared_ptr<Link> >::const_iterator child = link->child_links.begin(); child != link->child_links.end(); child++)
00048   {
00049     if (*child)
00050     {
00051       for(int j=0;j<level;j++) std::cout << "  "; 
00052       std::cout << "child(" << (count++)+1 << "):  " << (*child)->name  << std::endl;
00053       
00054       printTree(*child,level);
00055     }
00056     else
00057     {
00058       for(int j=0;j<level;j++) std::cout << " "; 
00059       std::cout << "root link: " << link->name << " has a null child!" << *child << std::endl;
00060     }
00061   }
00062 
00063 }
00064 
00065 
00066 int main(int argc, char** argv)
00067 {
00068   if (argc < 2){
00069     std::cerr << "Expect URDF or COLLADA xml file to parse" << std::endl;
00070     return -1;
00071   }
00072 
00073   urdf::Model robot;
00074   if (!robot.initFile(argv[1])){
00075     std::cerr << "ERROR: Model Parsing the xml failed" << std::endl;
00076     return -1;
00077   }
00078   std::cout << "robot name is: " << robot.getName() << std::endl;
00079 
00080   
00081   std::cout << "---------- Successfully Parsed XML ---------------" << std::endl;
00082   
00083   boost::shared_ptr<const Link> root_link=robot.getRoot();
00084   if (!root_link) return -1;
00085 
00086   std::cout << "root Link: " << root_link->name << " has " << root_link->child_links.size() << " child(ren)" << std::endl;
00087 
00088   
00089   printTree(root_link);
00090   return 0;
00091 }
00092