5 using p_el = DOMElement*;
8 using p_impl = DOMImplementation*;
12 std::cout <<
"beginning safeSetAttribute" << std::endl;
13 XMLCh* xmlchKey = XMLString::transcode(key.c_str());
14 XMLCh* xmlchVal = XMLString::transcode(val.c_str());
16 pElem->setAttribute(xmlchKey, xmlchVal);
18 XMLString::release(&xmlchKey);
19 XMLString::release(&xmlchVal);
24 std::cout <<
"beginning safeSetTextContent" << std::endl;
25 XMLCh* xmlchText = XMLString::transcode(textContent.c_str());
27 pElem->setTextContent(xmlchText);
29 XMLString::release(&xmlchText);
30 std::cout <<
"safeSetTextContent finished" << std::endl << std::endl;
35 std::cout <<
"beginning safeTranscode" << std::endl;
36 char* cString = XMLString::transcode(xmlstring);
38 std::string s(cString);
40 XMLString::release(&cString);
42 std::cout <<
"safeTranscode finished" << std::endl << std::endl;
48 std::cout <<
"beginning safeCreateElement" << std::endl;
49 XMLCh* xmlchName = XMLString::transcode(name.c_str());
51 p_el pChild = pParent->createElement(xmlchName);
53 XMLString::release(&xmlchName);
55 std::cout <<
"safeCreateElement finished" << std::endl << std::endl;
61 XMLPlatformUtils::Initialize();
62 XMLPlatformUtils::Terminate();
67 std::cout <<
"entered pugi xml" << std::endl;
68 int n_steps = footsteps.rows();
70 pugi::xml_document doc;
72 pugi::xml_node declarationNode = doc.append_child(pugi::node_declaration);
74 declarationNode.append_attribute(
"version") =
"1.0";
76 declarationNode.append_attribute(
"encoding") =
"ISO-8859-1";
78 declarationNode.append_attribute(
"standalone") =
"yes";
80 pugi::xml_node sdf = doc.append_child(
"sdf");
82 sdf.append_attribute(
"version") =
"1.7";
84 pugi::xml_node model = sdf.append_child(
"model");
86 model.append_attribute(
"name") =
"footsteps";
88 pugi::xml_node elem_static = model.append_child(
"static");
90 elem_static.text().set(
"1");
92 pugi::xml_node pose = model.append_child(
"pose");
94 pose.text().set(
"0 0 0 0 0 0");
106 std::string footstep_name;
108 std::string color_string;
110 std::string pose_string;
112 pugi::xml_node footstep_model;
137 pugi::xml_node visual;
139 pugi::xml_node geometry;
141 pugi::xml_node cylinder;
143 pugi::xml_node radius;
145 pugi::xml_node length;
147 pugi::xml_node material;
149 pugi::xml_node ambient;
151 pugi::xml_node diffuse;
153 pugi::xml_node specular;
155 pugi::xml_node emissive;
157 for (
int i = 0; i < n_steps; ++i)
160 step = footsteps.row(i).transpose();
162 footstep_name =
"footstep " + std::to_string(i);
163 color_string = std::to_string(
c(0)) +
" " + std::to_string(
c(1)) +
" " + std::to_string(
c(2)) +
" 1";
164 pose_string = std::to_string(step(0)) +
" " + std::to_string(step(1)) +
" " + std::to_string(step(2)) +
" 0 0 0";
166 footstep_model = model.append_child(
"model");
167 footstep_model.append_attribute(
"name") = footstep_name.c_str();
169 elem_static = footstep_model.append_child(
"static");
170 elem_static.text().set(
"1");
172 link = footstep_model.append_child(
"link");
173 link.append_attribute(
"name") =
"footstep_link";
201 pose = link.append_child(
"pose");
202 pose.text().set(pose_string.c_str());
204 visual = link.append_child(
"visual");
205 visual.append_attribute(
"name") =
"footstep_visual";
207 geometry = visual.append_child(
"geometry");
208 cylinder = geometry.append_child(
"cylinder");
210 radius = cylinder.append_child(
"radius");
211 radius.text().set(
"0.02");
213 length = cylinder.append_child(
"length");
214 length.text().set(
"0.01");
216 material = visual.append_child(
"material");
218 ambient = material.append_child(
"ambient");
219 ambient.text().set(color_string.c_str());
221 diffuse = material.append_child(
"diffuse");
222 diffuse.text().set(color_string.c_str());
224 specular = material.append_child(
"specular");
225 specular.text().set(
"0.1 0.1 0.1 1");
227 emissive = material.append_child(
"emissive");
228 emissive.text().set(color_string.c_str());
231 std::stringstream ss;
240 std::cout <<
"getFootstepSDFString: about to initialize" << std::endl;
241 XMLPlatformUtils::Initialize();
242 std::cout <<
"right after initialization" << std::endl;
244 p_impl p_DOMImplementation =
nullptr;
246 XMLCh* core = XMLString::transcode(
"core");
248 p_DOMImplementation = DOMImplementationRegistry::getDOMImplementation(core);
249 std::cout <<
"right after registration" << std::endl;
251 XMLString::release(&core);
253 p_doc p_DOMDocument =
nullptr;
255 XMLCh* sdf = XMLString::transcode(
"sdf");
257 p_DOMDocument = p_DOMImplementation->createDocument(0, sdf, 0);
259 XMLString::release(&sdf);
261 p_el pRoot = p_DOMDocument->getDocumentElement();
265 int n_steps = footsteps.rows();
269 pRoot->appendChild(pModel);
275 pModel->appendChild(pStatic);
281 pModel->appendChild(pPose);
319 std::string footstep_name;
321 std::string color_string;
323 std::string pose_string;
324 std::cout <<
"xml:right before for loop" << std::endl;
325 for (
int i = 0; i < n_steps; ++i)
329 step = footsteps.row(i).transpose();
333 pModel->appendChild(pFootstep);
335 footstep_name =
"footstep " + std::to_string(i);
341 pFootstep->appendChild(pStatic);
345 color_string = std::to_string(
c(0)) +
" " + std::to_string(
c(1)) +
" " + std::to_string(
c(2)) +
" 1";
349 pFootstep->appendChild(pLink);
355 pLink->appendChild(pPose);
357 pose_string = std::to_string(step(0)) +
" " + std::to_string(step(1)) +
" " + std::to_string(step(2)) +
" 0 0 0";
363 pLink->appendChild(pVisual);
369 pVisual->appendChild(pGeometry);
373 pGeometry->appendChild(pCylinder);
377 pCylinder->appendChild(pRadius);
383 pCylinder->appendChild(pLength);
389 pVisual->appendChild(pMaterial);
393 pMaterial->appendChild(pAmbient);
399 pMaterial->appendChild(pDiffuse);
405 pMaterial->appendChild(pSpecular);
411 pMaterial->appendChild(pEmissive);
415 std::cout <<
"right after for loop" << std::endl;
417 DOMLSSerializer* p_LSSerializer =
nullptr;
419 p_LSSerializer = p_DOMImplementation->createLSSerializer();
421 std::string res = XMLString::transcode(p_LSSerializer->writeToString(p_DOMDocument));
423 p_DOMDocument->release();
425 p_LSSerializer->release();
427 XMLPlatformUtils::Terminate();
Eigen::Matrix3Xd interpolateColors(Eigen::Vector3d begin_rgb, Eigen::Vector3d end_rgb, int nsteps)
void safeSetTextContent(p_el pElem, std::string textContent)
std::string getFootstepSDFString(Eigen::MatrixX3d footsteps)
std::string getFootstepSDFStringPugi(Eigen::MatrixX3d footsteps)
void safeSetAttribute(p_el pElem, std::string key, std::string val)
std::string safeTranscode(XMLCh *xmlstring)
p_el safeCreateElement(p_doc pParent, std::string name)
DOMImplementation * p_impl