controllerclientcpp  0.6.1
 全て クラス ネームスペース ファイル 関数 変数 型定義 列挙型 列挙型の値 マクロ定義 ページ
mujinimportscene_robodia.cpp
説明を見る。
1 // -*- coding: utf-8 -*-
7 
8 #include <iostream>
9 
10 using namespace mujinclient;
11 
12 int main(int argc, char ** argv)
13 {
14  if( argc < 2 ) {
15  std::cout << "need username:password. Example: mujinclienttest myuser:mypass [url]\n\nurl - [optional] For example https://controller.mujin.co.jp/" << std::endl;
16  return 1;
17  }
18  try {
19  ControllerClientPtr controller;
20  if( argc >= 5 ) {
21  controller = CreateControllerClient(argv[1], argv[2], argv[3], argv[4]);
22  }
23  if( argc == 4 ) {
24  controller = CreateControllerClient(argv[1], argv[2], argv[3]);
25  }
26  else if( argc == 3 ) {
27  controller = CreateControllerClient(argv[1], argv[2]);
28  }
29  else {
30  controller = CreateControllerClient(argv[1]);
31  }
32  std::cout << "connected to controller v" << controller->GetVersion() << std::endl;
33 
34  //controller->SyncUpload_UTF16(L"c:\\controllerclientcpp\\V[XeXg\\V[XeXg.xml", L"mujin:/V[XeXg/", "cecrobodiaxml");
35  controller->SyncUpload_UTF8("../share/mujincontrollerclient/robodia_demo1/robodia_demo1.xml", "mujin:/robodia_demo1/", "cecrobodiaxml");
36 
37  // try to import the scene, if it already exists delete it and import again
38  std::string sceneuri = "mujin:/robodia_demo1.mujin.dae";
39  try {
40  controller->ImportSceneToCOLLADA_UTF8("mujin:/robodia_demo1/robodia_demo1.xml", "cecrobodiaxml", sceneuri);
41  }
42  catch(const MujinException& ex) {
43  if( ex.message().find("need to remove it first") != std::string::npos ) {
44  std::cout << "file already imported, would you like to delete and re-import? (yes/no) ";
45  std::string answer;
46  std::cin >> answer;
47  if( answer == std::string("yes") ) {
48  std::cout << "try removing the file and importing again" << std::endl;
49  SceneResource oldscene(controller,"robodia_demo1.mujin.dae");
50  oldscene.Delete();
51  controller->ImportSceneToCOLLADA_UTF8("mujin:/robodia_demo1/robodia_demo1.xml", "cecrobodiaxml", sceneuri);
52  }
53  }
54  else {
55  std::cout << "error importing scene" << ex.message() << std::endl;
56  }
57  }
58 
59  // create the resource and query info
60  // have to convert the URI into a primary-key for creating the resources
61  std::string scenepk = controller->GetScenePrimaryKeyFromURI_UTF8(sceneuri);
62  SceneResource scene(controller,scenepk);
63  std::vector<SceneResource::InstObjectPtr> instobjects;
64  scene.GetInstObjects(instobjects);
65  std::cout << "scene instance objects: ";
66  for(size_t i = 0; i < instobjects.size(); ++i) {
67  std::cout << instobjects[i]->name << ", ";
68  }
69  std::cout << std::endl;
70  }
71  catch(const MujinException& ex) {
72  std::cout << "exception thrown: " << ex.message() << std::endl;
73  }
74  // destroy all mujin controller resources
76 }