exportCollada.cpp
Go to the documentation of this file.
00001 //
00002 // g++ -I. -I../../hrplib -I/usr/include/colladadom
00003 // -I/usr/include/colladadom/1.5 exportCollada.cpp BodyInfo_impl.cpp
00004 // ShapeSetInfo_impl.cpp VrmlUtil.cpp
00005 // ../../hrplib/hrpCorba/ModelLoaderSk.cpp -L../../lib -lhrpModel-3.1
00006 // -lhrpUtil-3.1 -lomniORB4 -lomniDynamic4 -lcollada15dom
00007 // -lboost_system
00008 //
00009 #include <list>
00010 #include <boost/foreach.hpp>
00011 #include <boost/tokenizer.hpp>
00012 
00013 #include "ModelLoader_impl.h"
00014 
00015 #ifdef _WIN32
00016 #include "winbase.h"
00017 #else
00018 #include <unistd.h>
00019 #endif /* _WIN32 */
00020 
00021 #include <iostream>
00022 
00023 #include "ColladaWriter.h"
00024 #include "BodyInfo_impl.h"
00025 
00026 using namespace std;
00027 
00028 int main(int argc, char* argv[])
00029 {
00030   CORBA::ORB_var orb = CORBA::ORB::_nil();
00031   
00032   try 
00033     {
00034       orb = CORBA::ORB_init(argc, argv);
00035       
00036       CORBA::Object_var obj;
00037       
00038       obj = orb->resolve_initial_references("RootPOA");
00039       PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
00040       if(CORBA::is_nil(poa))
00041         {
00042           throw string("error: failed to narrow root POA.");
00043         }
00044       
00045       PortableServer::POAManager_var poaManager = poa->the_POAManager();
00046       if(CORBA::is_nil(poaManager))
00047         {
00048           throw string("error: failed to narrow root POA manager.");
00049         }
00050       
00051       std::string inFileName, outFileName;
00052       
00053       std::list<ManipulatorInfo> listmanipulators;
00054       
00055       // get filename
00056       for(int i=0; i<(argc-1); ++i) 
00057         {
00058           if((strlen(argv[i]) > 1) && (argv[i][0] == '-')) 
00059             {
00060               
00061               if(argv[i][1] == 'i')
00062                 inFileName = std::string(argv[++i]);
00063               
00064               else if(argv[i][1] == 'o')
00065                 outFileName = std::string(argv[++i]);
00066               
00067               else if(argv[i][1] == 'a') 
00068                 {
00069                   std::string armProfStr = std::string(argv[++i]);
00070                   std::vector<std::string> armVec;
00071                   boost::char_separator<char> sep1(",");
00072                   boost::tokenizer< boost::char_separator<char> > armTolkens(armProfStr, sep1);
00073 #if 0
00074                   BOOST_FOREACH(std::string t, armTolkens)
00075                     {
00076                       //armVec.push_back(t);
00077                     }
00078 #else
00079                   ManipulatorInfo tmpinfo;
00080                   boost::tokenizer< boost::char_separator<char> >::iterator
00081                     armiter(armTolkens.begin());
00082                   tmpinfo.name = *(armiter++);
00083                   std::cout << "tmpinfo.name         = " << tmpinfo.name << "\n";
00084                   tmpinfo.basename = *(armiter++);
00085                   std::cout << "tmpinfo.basename     = " << tmpinfo.basename << "\n";
00086                   tmpinfo.effectorname = *(armiter++);
00087                   std::cout << "tmpinfo.effectorname = " << tmpinfo.effectorname << std::endl;
00088 
00089                   tmpinfo.translation[0] = boost::lexical_cast<double>(*(armiter++));
00090                   tmpinfo.translation[1] = boost::lexical_cast<double>(*(armiter++));
00091                   tmpinfo.translation[2] = boost::lexical_cast<double>(*(armiter++));
00092                   tmpinfo.rotation[0] = boost::lexical_cast<double>(*(armiter++));
00093                   tmpinfo.rotation[1] = boost::lexical_cast<double>(*(armiter++));
00094                   tmpinfo.rotation[2] = boost::lexical_cast<double>(*(armiter++));
00095                   tmpinfo.rotation[3] = boost::lexical_cast<double>(*(armiter++));
00096                   std::cout << "tmpinfo.translation = " << tmpinfo.translation[0] << ", " << tmpinfo.translation[1] << ", " << tmpinfo.translation[2] << std::endl;
00097                   std::cout << "tmpinfo.rotation = " << tmpinfo.rotation[0] << ", " << tmpinfo.rotation[1] << ", " << tmpinfo.rotation[2] << ", " << tmpinfo.rotation[3] << std::endl;
00098 
00099                   for(int i=0; armiter != armTolkens.end(); ++i,++armiter)
00100                     {
00101                       if(i % 2) 
00102                         {
00103                           tmpinfo.gripperdir.push_back(*armiter);
00104                           std::cout << "tmpinfo.gripperdir = " << *armiter;
00105                         }
00106                       else 
00107                         {
00108                           tmpinfo.grippernames.push_back(*armiter);
00109                           std::cout << "tmpinfo.grippernames = " << *armiter;
00110                         }
00111                       std::cout << std::endl;
00112                     }
00113                   listmanipulators.push_back(tmpinfo);
00114 #endif
00115                 }
00116             }
00117         }
00118       
00119 #if 1
00120       if((inFileName != "") && (outFileName != "")) 
00121         {
00122           BodyInfo_impl bI(poa);        
00123           
00124           bI.loadModelFile(inFileName.c_str());
00125           
00126           std::stringstream sstm;
00127           for (int i = 0; i < argc; i++)sstm << argv[i] << " ";
00128 
00129           ColladaWriter cW(listmanipulators, sstm.str().c_str());
00130           cW.Write(&bI);
00131           cW.Save(outFileName);
00132           std::cout << argv[0] << " " << inFileName << " was successfully exported to " << outFileName << std::endl;
00133         } 
00134       else
00135         {
00136           std::cerr << "Usage: " << argv[0] << " "
00137                     << "-i <inFileName> " << "-o <outFileName> "
00138                     << "-a <manipulator_name>,<frame_origin>,<frame_tip>,<px>,<py>,<pz>,<rotX>,<rotY>,<rotZ>,<rotTheta[rad]>,<gripper_joint>,<closing_direction>...\n see http://openrave.org/docs/latest_stable/collada_robot_extensions/"
00139                     << std::endl;
00140         }
00141 #endif    
00142     }
00143   catch (CORBA::SystemException& ex) 
00144     {
00145       cerr << ex._rep_id() << endl;
00146     }
00147   catch (const string& error)
00148     {
00149       cerr << error << endl;
00150     }
00151   
00152   try 
00153     {
00154       orb->destroy();
00155     }
00156   catch(...)
00157     {
00158       
00159     }
00160 
00161   return 0;
00162 }


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Apr 11 2019 03:30:16