world2yaml.cpp
Go to the documentation of this file.
1 #include <tinyxml.h>
2 #include <fstream>
3 #include <vector>
4 #include <boost/algorithm/string.hpp>
6 #include <sstream>
7 
8 // tutorial demo program
9 //#include <stdafx.h>
10 
11 
12 // ----------------------------------------------------------------------
13 // STDOUT dump and indenting utility functions
14 // ----------------------------------------------------------------------
15 const unsigned int NUM_INDENTS_PER_SPACE=2;
16 std::ofstream ofs("test.txt");
17 
18 const char * getIndent( unsigned int numIndents )
19 {
20  static const char * pINDENT=" + ";
21  static const unsigned int LENGTH=strlen( pINDENT );
22  unsigned int n=numIndents*NUM_INDENTS_PER_SPACE;
23  if ( n > LENGTH ) n = LENGTH;
24 
25  return &pINDENT[ LENGTH-n ];
26 }
27 
28 // same as getIndent but no "+" at the end
29 const char * getIndentAlt( unsigned int numIndents )
30 {
31  static const char * pINDENT=" ";
32  static const unsigned int LENGTH=strlen( pINDENT );
33  unsigned int n=numIndents*NUM_INDENTS_PER_SPACE;
34  if ( n > LENGTH ) n = LENGTH;
35 
36  return &pINDENT[ LENGTH-n ];
37 }
38 
39 int dump_attribs_to_stdout(TiXmlElement* pElement, unsigned int indent)
40 {
41  if ( !pElement ) return 0;
42 
43  TiXmlAttribute* pAttrib=pElement->FirstAttribute();
44  int i=0;
45  int ival;
46  double dval;
47  const char* pIndent=getIndent(indent);
48  printf("\n");
49  while (pAttrib)
50  {
51  printf( "%s%s: value=[%s]", pIndent, pAttrib->Name(), pAttrib->Value());
52 
53  if (pAttrib->QueryIntValue(&ival)==TIXML_SUCCESS) printf( " int=%d", ival);
54  if (pAttrib->QueryDoubleValue(&dval)==TIXML_SUCCESS) printf( " d=%1.1f", dval);
55  printf( "\n" );
56  i++;
57  pAttrib=pAttrib->Next();
58  }
59  return i;
60 }
61 
62 void dump_include_model( TiXmlNode* pParent, unsigned int indent = 0 ){
63  TiXmlNode* pChild;
64  TiXmlText* pText;
65  int t = pParent->Type();
66  std::cout << "-" << std::endl;
67  for ( pChild = pParent->FirstChild(); pChild != 0; pChild = pChild->NextSibling())
68  {
69  TiXmlNode* pChild2;
70  std::string type = pChild->Value();
71  //std::cout << pChild->Value() << std::endl;
72 
73  if(type == "uri"){
74 
75  //std::cout << "uuuuuuuuuuurrrrrrrrrrrrrrrriiiiiiiiiiiiI" << std::endl;
76  std::cout << getIndentAlt(indent) << "model: \"" << pChild->FirstChild()->Value() << "\"" << std::endl;
77  }else if(type == "name"){
78  //std::cout << "namerrrrrrrrrrrriiiiiiiiiiiiI" << std::endl;
79  std::cout << getIndentAlt(indent) << "name: \"" << pChild->FirstChild()->Value() << "\"" << std::endl;
80  }else if(type == "pose"){
81  // btQuaternion qua(
82  std::string child_value = pChild->FirstChild()->Value();
83  std::vector<std::string> v;
84  boost::algorithm::split( v, child_value, boost::algorithm::is_space() );
85  //std::cout << getIndentAlt(indent) << "pose: " << pChild->FirstChild()->Value() << std::endl;
86  std::cout << getIndentAlt(indent) << "pose:" << std::endl;
87  std::cout << getIndentAlt(indent + 1) << "position:" << std::endl;
88  std::cout << getIndentAlt(indent + 2) << "x: " << v[0] << std::endl;
89  std::cout << getIndentAlt(indent + 2) << "y: " << v[1] << std::endl;
90  std::cout << getIndentAlt(indent + 2) << "z: " << v[2] << std::endl;
91 
92  std::string s = v[3];
93  //std::istringstream r_str(s.c_str());
94  std::istringstream r_str(v[3]);
95  int r,p,y;
96  r_str >> r;
97  std::istringstream p_str(v[4]);
98  p_str >> p;
99  std::istringstream y_str(v[5]);
100  y_str >> y;
101 
102  // istr << v[4];
103  //istr >> p;
104  //istr << v[5];
105  //istr >> y;
106 
107  //btQuaternion qua(y,p,r);
108  //tf::Quaternion qua(y,p,r);
109  tf::Matrix3x3 mat;
110  mat.setRPY(r,p,y);
112  mat.getRotation(q);
113  std::cout << getIndentAlt(indent + 1) << "orientation:" << std::endl;
114  //double x = q.x();
115  std::cout << getIndentAlt(indent + 2) << "x: " << q.x() << std::endl;
116  std::cout << getIndentAlt(indent + 2) << "y: " << q.y() << std::endl;
117  std::cout << getIndentAlt(indent + 2) << "z: " << q.z() << std::endl;
118  std::cout << getIndentAlt(indent + 2) << "w: " << q.w() << std::endl;
119  //std::cout << getIndentAlt(indent + 2) << "y: " << q.y << std::endl;
120  //std::cout << getIndentAlt(indent + 2) << "z: " << q.z << std::endl;
121 
122 
123  /*
124  for(int i=0; i< 3; i++){
125  std::cout << v[i] << "," << std::endl;
126  }*/
127  //std::cout << "poserrrrrrrrrrrriiiiiiiiiiiiI" << std::endl;
128 
129  }
130  }
131  std::cout << getIndentAlt(indent) << "frmae-id: \"map\"" << std::endl;
132  std::cout << getIndentAlt(indent) << "robot: false" << std::endl;
133 }
134 
135 
136 void dump_to_stdout( TiXmlNode* pParent, unsigned int indent = 0 )
137 {
138  if ( !pParent ) return;
139 
140  TiXmlNode* pChild;
141  TiXmlText* pText;
142  int t = pParent->Type();
143  //printf( "%s", getIndent(indent));
144  int num;
145  //std::cout << "aaaaa" << std::endl;
146  //std::cout << pParent->Value() << std::endl;
147  std::string value = pParent->Value();
148  if ( value == "include"){
149  //std::cout << "aaaaaaaaaaaaa" << std::endl;
150  dump_include_model(pParent, 1);
151  }
152 
153  /*
154  switch ( t )
155  {
156  case TiXmlNode::TINYXML_DOCUMENT:
157  printf( "Document" );
158  break;
159 
160  case TiXmlNode::TINYXML_ELEMENT:
161  printf( "Element [%s]", pParent->Value() );
162  num=dump_attribs_to_stdout(pParent->ToElement(), indent+1);
163  switch(num)
164  {
165  case 0: printf( " (No attributes)"); break;
166  case 1: printf( "%s1 attribute", getIndentAlt(indent)); break;
167  default: printf( "%s%d attributes", getIndentAlt(indent), num); break;
168  }
169  break;
170 
171  case TiXmlNode::TINYXML_COMMENT:
172  printf( "Comment: [%s]", pParent->Value());
173  break;
174 
175  case TiXmlNode::TINYXML_UNKNOWN:
176  printf( "Unknown" );
177  break;
178 
179  case TiXmlNode::TINYXML_TEXT:
180  pText = pParent->ToText();
181  printf( "Text: [%s]", pText->Value() );
182  break;
183 
184  case TiXmlNode::TINYXML_DECLARATION:
185  printf( "Declaration" );
186  break;
187  default:
188  break;
189  }
190  printf( "\n" );
191  */
192  for ( pChild = pParent->FirstChild(); pChild != 0; pChild = pChild->NextSibling())
193  {
194  dump_to_stdout( pChild, indent+1 );
195  }
196 }
197 
198 void dump_to_stdout(const char* pFilename)
199 {
200  TiXmlDocument doc(pFilename);
201  bool loadOkay = doc.LoadFile();
202  if (loadOkay)
203  {
204  printf("\n%s:\n", pFilename);
205  dump_to_stdout( &doc ); // defined later in the tutorial
206  }
207  else
208  {
209  printf("Failed to load file \"%s\"\n", pFilename);
210  }
211 }
212 
213 
214 
215 int main(int argc, char** argv){
216 
217  //ofs<<"aa"<<std::endl;
218  dump_to_stdout("vrc_final_task1.world");
219 
220  return 0;
221 
222 
223 }
224 
dump_include_model
void dump_include_model(TiXmlNode *pParent, unsigned int indent=0)
Definition: world2yaml.cpp:62
tf::Matrix3x3
tf::Matrix3x3::setRPY
void setRPY(tfScalar roll, tfScalar pitch, tfScalar yaw)
t
int t
NUM_INDENTS_PER_SPACE
const unsigned int NUM_INDENTS_PER_SPACE
Definition: world2yaml.cpp:15
value
value
p
p
getIndentAlt
const char * getIndentAlt(unsigned int numIndents)
Definition: world2yaml.cpp:29
tf::Matrix3x3::getRotation
void getRotation(Quaternion &q) const
transformable_joy_configure.s
s
Definition: transformable_joy_configure.py:85
doc
doc
transform_broadcaster.h
dump_attribs_to_stdout
int dump_attribs_to_stdout(TiXmlElement *pElement, unsigned int indent)
Definition: world2yaml.cpp:39
LENGTH
pointer LENGTH(context *, int, pointer *)
q
q
dump_to_stdout
void dump_to_stdout(TiXmlNode *pParent, unsigned int indent=0)
Definition: world2yaml.cpp:136
dummy_camera.r
r
Definition: dummy_camera.py:14
y
y
num
num
ofs
std::ofstream ofs("test.txt")
getIndent
const char * getIndent(unsigned int numIndents)
Definition: world2yaml.cpp:18
n
GLfloat n[6][3]
tf::Quaternion
v
GLfloat v[8][3]
main
int main(int argc, char **argv)
Definition: world2yaml.cpp:215


jsk_interactive_marker
Author(s): furuta
autogenerated on Fri Aug 2 2024 08:50:24