exportCollada.cpp
Go to the documentation of this file.
1 //
2 // g++ -I. -I../../hrplib -I/usr/include/colladadom
3 // -I/usr/include/colladadom/1.5 exportCollada.cpp BodyInfo_impl.cpp
4 // ShapeSetInfo_impl.cpp VrmlUtil.cpp
5 // ../../hrplib/hrpCorba/ModelLoaderSk.cpp -L../../lib -lhrpModel-3.1
6 // -lhrpUtil-3.1 -lomniORB4 -lomniDynamic4 -lcollada15dom
7 // -lboost_system
8 //
9 #include <list>
10 #include <boost/foreach.hpp>
11 #include <boost/tokenizer.hpp>
12 
13 #include "ModelLoader_impl.h"
14 
15 #ifdef _WIN32
16 #include "winbase.h"
17 #else
18 #include <unistd.h>
19 #endif /* _WIN32 */
20 
21 #include <iostream>
22 
23 #include "ColladaWriter.h"
24 #include "BodyInfo_impl.h"
25 
26 using namespace std;
27 
28 int main(int argc, char* argv[])
29 {
30  CORBA::ORB_var orb = CORBA::ORB::_nil();
31 
32  try
33  {
34  orb = CORBA::ORB_init(argc, argv);
35 
36  CORBA::Object_var obj;
37 
38  obj = orb->resolve_initial_references("RootPOA");
39  PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
40  if(CORBA::is_nil(poa))
41  {
42  throw string("error: failed to narrow root POA.");
43  }
44 
45  PortableServer::POAManager_var poaManager = poa->the_POAManager();
46  if(CORBA::is_nil(poaManager))
47  {
48  throw string("error: failed to narrow root POA manager.");
49  }
50 
51  std::string inFileName, outFileName;
52 
53  std::list<ManipulatorInfo> listmanipulators;
54 
55  // get filename
56  for(int i=0; i<(argc-1); ++i)
57  {
58  if((strlen(argv[i]) > 1) && (argv[i][0] == '-'))
59  {
60 
61  if(argv[i][1] == 'i')
62  inFileName = std::string(argv[++i]);
63 
64  else if(argv[i][1] == 'o')
65  outFileName = std::string(argv[++i]);
66 
67  else if(argv[i][1] == 'a')
68  {
69  std::string armProfStr = std::string(argv[++i]);
70  std::vector<std::string> armVec;
71  boost::char_separator<char> sep1(",");
72  boost::tokenizer< boost::char_separator<char> > armTolkens(armProfStr, sep1);
73 #if 0
74  BOOST_FOREACH(std::string t, armTolkens)
75  {
76  //armVec.push_back(t);
77  }
78 #else
79  ManipulatorInfo tmpinfo;
80  boost::tokenizer< boost::char_separator<char> >::iterator
81  armiter(armTolkens.begin());
82  tmpinfo.name = *(armiter++);
83  std::cout << "tmpinfo.name = " << tmpinfo.name << "\n";
84  tmpinfo.basename = *(armiter++);
85  std::cout << "tmpinfo.basename = " << tmpinfo.basename << "\n";
86  tmpinfo.effectorname = *(armiter++);
87  std::cout << "tmpinfo.effectorname = " << tmpinfo.effectorname << std::endl;
88 
89  tmpinfo.translation[0] = boost::lexical_cast<double>(*(armiter++));
90  tmpinfo.translation[1] = boost::lexical_cast<double>(*(armiter++));
91  tmpinfo.translation[2] = boost::lexical_cast<double>(*(armiter++));
92  tmpinfo.rotation[0] = boost::lexical_cast<double>(*(armiter++));
93  tmpinfo.rotation[1] = boost::lexical_cast<double>(*(armiter++));
94  tmpinfo.rotation[2] = boost::lexical_cast<double>(*(armiter++));
95  tmpinfo.rotation[3] = boost::lexical_cast<double>(*(armiter++));
96  std::cout << "tmpinfo.translation = " << tmpinfo.translation[0] << ", " << tmpinfo.translation[1] << ", " << tmpinfo.translation[2] << std::endl;
97  std::cout << "tmpinfo.rotation = " << tmpinfo.rotation[0] << ", " << tmpinfo.rotation[1] << ", " << tmpinfo.rotation[2] << ", " << tmpinfo.rotation[3] << std::endl;
98 
99  for(int i=0; armiter != armTolkens.end(); ++i,++armiter)
100  {
101  if(i % 2)
102  {
103  tmpinfo.gripperdir.push_back(*armiter);
104  std::cout << "tmpinfo.gripperdir = " << *armiter;
105  }
106  else
107  {
108  tmpinfo.grippernames.push_back(*armiter);
109  std::cout << "tmpinfo.grippernames = " << *armiter;
110  }
111  std::cout << std::endl;
112  }
113  listmanipulators.push_back(tmpinfo);
114 #endif
115  }
116  }
117  }
118 
119 #if 1
120  if((inFileName != "") && (outFileName != ""))
121  {
122  BodyInfo_impl bI(poa);
123 
124  bI.loadModelFile(inFileName.c_str());
125 
126  std::stringstream sstm;
127  for (int i = 0; i < argc; i++)sstm << argv[i] << " ";
128 
129  ColladaWriter cW(listmanipulators, sstm.str().c_str());
130  cW.Write(&bI);
131  cW.Save(outFileName);
132  std::cout << argv[0] << " " << inFileName << " was successfully exported to " << outFileName << std::endl;
133  }
134  else
135  {
136  std::cerr << "Usage: " << argv[0] << " "
137  << "-i <inFileName> " << "-o <outFileName> "
138  << "-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/"
139  << std::endl;
140  }
141 #endif
142  }
143  catch (CORBA::SystemException& ex)
144  {
145  cerr << ex._rep_id() << endl;
146  }
147  catch (const string& error)
148  {
149  cerr << error << endl;
150  }
151 
152  try
153  {
154  orb->destroy();
155  }
156  catch(...)
157  {
158 
159  }
160 
161  return 0;
162 }
int main(int argc, char *argv[])
virtual bool Write(BodyInfo_impl *bodyInfo)
std::list< std::string > grippernames
Definition: ColladaWriter.h:48
void error(char *msg) const
Definition: minigzip.c:87
png_uint_32 i
Definition: png.h:2735
std::string name
Definition: ColladaWriter.h:46
std::list< std::string > gripperdir
Definition: ColladaWriter.h:49
std::string effectorname
Definition: ColladaWriter.h:47
void loadModelFile(const std::string &filename)
This function loads a model file and creates a BodyInfo object.
t
DblArray4 rotation
Definition: ColladaWriter.h:51
std::string basename
Definition: ColladaWriter.h:47
DblArray3 translation
Definition: ColladaWriter.h:52


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sat May 8 2021 02:42:37