21 #include <boost/algorithm/string.hpp> 22 #include <rapidxml.hpp> 23 #include <rapidxml_utils.hpp> 28 : marker_lifetime_(marker_lifetime),
29 dome_config_path_(dome_config_path),
30 mild_config_path_(mild_config_path)
48 visualization_msgs::MarkerArray markers;
50 std::string abs_xml_path;
51 if (boost::starts_with(xml_path,
".")) {
55 abs_xml_path = xml_path;
59 rapidxml::file<> xmlFile(abs_xml_path.c_str());
60 rapidxml::xml_document<> doc;
61 doc.parse<0>(xmlFile.data());
63 rapidxml::xml_node<> *root_node = doc.first_node();
65 rapidxml::xml_node<> *child_node = root_node->first_node();
68 rapidxml::xml_attribute<> *name_attribute = child_node->first_attribute(
"name");
69 rapidxml::xml_attribute<> *scale_attribute = child_node->first_attribute(
"scale");
70 rapidxml::xml_attribute<> *mesh_attribute = child_node->first_attribute(
"mesh");
71 rapidxml::xml_attribute<> *mat_attribute = child_node->first_attribute(
"use_mat");
72 if (name_attribute && scale_attribute && mesh_attribute && mat_attribute) {
73 std::string name = name_attribute->value();
74 std::string mesh = mesh_attribute->value();
75 std::string scale = scale_attribute->value();
76 std::string pose_string = child_node->value();
77 bool use_mat = boost::lexical_cast<
bool>(mat_attribute->value());
78 std::vector<double> pose_vec;
79 std::vector<double> scale_vec;
80 if (
parseDoubleCsv(pose_string, pose_vec,
" ,") && pose_vec.size() == 7) {
81 if (
parseDoubleCsv(scale, scale_vec,
" ,") && scale_vec.size() == 3) {
82 markers.markers.push_back(
createMarker(name, mesh, pose_vec, scale_vec, i, use_mat));
88 child_node = child_node->next_sibling();
91 }
catch(std::runtime_error err) {
93 }
catch (rapidxml::parse_error err) {
95 }
catch (boost::bad_lexical_cast err) {
103 std::vector<std::string> strvec;
105 boost::algorithm::trim_if(csv_in, boost::algorithm::is_any_of(delim));
106 boost::algorithm::split(strvec, csv_in, boost::algorithm::is_any_of(delim), boost::algorithm::token_compress_on);
107 for (std::string str : strvec) {
109 csv_out.push_back(boost::lexical_cast<double>(str));
110 }
catch (boost::bad_lexical_cast err) {
118 visualization_msgs::Marker
MarkerHelper::createMarker(
const std::string &name,
const std::string &mesh,
const std::vector<double> &pose,
const std::vector<double> &scale,
int id,
bool use_mat) {
119 visualization_msgs::Marker m;
121 m.header.frame_id =
"/map";
122 m.type = visualization_msgs::Marker::MESH_RESOURCE;
123 m.action = visualization_msgs::Marker::ADD;
129 m.mesh_resource = mesh;
130 m.mesh_use_embedded_materials = use_mat;
133 m.scale.x = scale.at(0);
134 m.scale.y = scale.at(1);
135 m.scale.z = scale.at(2);
136 m.pose.position.x = pose.at(0);
137 m.pose.position.y = pose.at(1);
138 m.pose.position.z = pose.at(2);
139 m.pose.orientation.w = pose.at(3);
140 m.pose.orientation.x = pose.at(4);
141 m.pose.orientation.y = pose.at(5);
142 m.pose.orientation.z = pose.at(6);
std::string dome_config_path_
visualization_msgs::MarkerArray getAllMarkersMild()
visualization_msgs::Marker createMarker(const std::string &name, const std::string &mesh, const std::vector< double > &pose, const std::vector< double > &scale, int id, bool use_mat)
visualization_msgs::MarkerArray getAllMarkersDome()
std::string mild_config_path_
bool parseDoubleCsv(std::string csv_in, std::vector< double > &csv_out, std::string delim)
#define ROS_DEBUG_STREAM(args)
ROSLIB_DECL std::string getPath(const std::string &package_name)
visualization_msgs::MarkerArray parseXmlFile(std::string xml_path)