12 #include <mrpt/core/bits_math.h> 13 #include <mrpt/core/format.h> 14 #include <mrpt/img/TColor.h> 15 #include <mrpt/math/TPolygon2D.h> 26 using namespace mvsim;
33 const std::string& inStr,
const std::string& varName,
34 const std::map<std::string, std::string>& variableNamesValues,
35 const char* functionNameContext)
const 37 const std::string str =
mvsim::parse(inStr, variableNamesValues);
41 if (std::string(frmt) == std::string(
"%s"))
43 std::string& val2 = *
reinterpret_cast<std::string*
>(
val);
47 else if (std::string(frmt) == std::string(
"%lf_deg"))
49 if (1 != ::sscanf(str.c_str(), frmt,
val))
51 "%s Error parsing attribute '%s'='%s' (Expected " 53 functionNameContext, varName.c_str(), str.c_str(), frmt));
54 double& ang = *
reinterpret_cast<double*
>(
val);
55 ang = mrpt::DEG2RAD(ang);
58 else if (std::string(frmt) == std::string(
"%bool"))
60 bool& bool_val = *
reinterpret_cast<bool*
>(
val);
62 const std::string sStr =
64 if (sStr ==
"1" || sStr ==
"true")
66 else if (sStr ==
"0" || sStr ==
"false")
70 "%s Error parsing 'bool' attribute '%s'='%s' (Expected " 72 functionNameContext, varName.c_str(), str.c_str()));
75 else if (std::string(frmt) == std::string(
"%color"))
78 if (!(str.size() > 1 && str[0] ==
'#'))
80 "%s Error parsing '%s'='%s' (Expected " 81 "format:'#RRGGBB[AA]')",
82 functionNameContext, varName.c_str(), str.c_str()));
84 unsigned int r,
g,
b,
a = 0xff;
85 int ret = ::sscanf(str.c_str() + 1,
"%2x%2x%2x%2x", &r, &g, &b, &a);
86 if (ret != 3 && ret != 4)
88 "%s Error parsing '%s'='%s' (Expected " 89 "format:'#RRGGBB[AA]')",
90 functionNameContext, varName.c_str(), str.c_str()));
91 mrpt::img::TColor& col = *
reinterpret_cast<mrpt::img::TColor*
>(
val);
92 col = mrpt::img::TColor(r, g, b, a);
96 else if (!strncmp(frmt,
"%pose2d", strlen(
"%pose2d")))
99 int ret = ::sscanf(str.c_str(),
"%lf %lf %lf", &x, &y, &yaw);
102 "%s Error parsing '%s'='%s' (Expected format:'X Y " 104 functionNameContext, varName.c_str(), str.c_str()));
107 yaw = mrpt::DEG2RAD(yaw);
112 if (!strcmp(frmt,
"%pose2d"))
118 else if (!strcmp(frmt,
"%pose2d_ptr3d"))
126 "%s Error: Unknown format specifier '%s'", functionNameContext,
132 if (1 != ::sscanf(str.c_str(), frmt,
val))
134 "%s Error parsing attribute '%s'='%s' (Expected " 136 functionNameContext, varName.c_str(), str.c_str(), frmt));
143 const std::map<std::string, std::string>& variableNamesValues,
144 const char* functionNameContext)
146 for (
const auto&
param : params)
150 if (attr && attr->
value())
152 attr->
value(), attr->
name(), variableNamesValues,
153 functionNameContext);
160 const std::map<std::string, std::string>& variableNamesValues,
161 const char* functionNameContext)
163 TParameterDefinitions::const_iterator it_param =
164 params.find(xml_node.
name());
166 if (it_param != params.end())
169 it_param->second.parse(
170 xml_node.
value(), xml_node.
name(), variableNamesValues,
171 functionNameContext);
181 const std::map<std::string, std::string>& variableNamesValues,
182 const char* functionNameContext)
188 *node, params, variableNamesValues, functionNameContext);
199 const std::string&
s,
bool allow_missing_angle,
200 double default_angle_radians)
203 v.
phi = mrpt::RAD2DEG(default_angle_radians);
205 int na = ::sscanf(s.c_str(),
"%lf %lf %lf", &v.
x, &v.
y, &v.
phi);
208 v.
phi = mrpt::DEG2RAD(v.
phi);
210 if ((na != 3 && !allow_missing_angle) ||
211 (na != 2 && na != 3 && allow_missing_angle))
212 throw std::runtime_error(
213 mrpt::format(
"Malformed pose string: '%s'", s.c_str()));
224 const char* functionNameContext)
229 pt_node = pt_node->next_sibling(
"pt"))
231 if (!pt_node->value())
233 "%s Error: <pt> node seems empty.", functionNameContext));
236 const char* str_val = pt_node->value();
237 if (2 != ::sscanf(str_val,
"%lf %lf", &pt.
x, &pt.
y))
239 "%s Error parsing <pt> node: '%s' (Expected format:'<pt>X " 241 functionNameContext, str_val));
243 out_poly.push_back(pt);
246 if (out_poly.size() < 3)
248 "%s Error: <shape> node requires 3 or more <pt>X Y</pt> " 250 functionNameContext));
GLboolean GLboolean GLboolean GLboolean a
GLint GLint GLint GLint GLint GLint y
std::map< std::string, TParamEntry > TParameterDefinitions
void parse_xmlnode_children_as_param(const rapidxml::xml_node< char > &xml_node, const TParameterDefinitions ¶ms, const std::map< std::string, std::string > &variableNamesValues={}, const char *functionNameContext="")
bool parse_xmlnode_as_param(const rapidxml::xml_node< char > &xml_node, const TParameterDefinitions ¶ms, const std::map< std::string, std::string > &variableNamesValues={}, const char *functionNameContext="")
void parse_xmlnode_attribs(const rapidxml::xml_node< char > &xml_node, const TParameterDefinitions ¶ms, const std::map< std::string, std::string > &variableNamesValues={}, const char *functionNameContext="")
xml_node< Ch > * first_node(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
std::string BASE_IMPEXP lowerCase(const std::string &str)
GLint GLint GLint GLint GLint x
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
std::string parse(const std::string &input, const std::map< std::string, std::string > &variableNamesValues={})
xml_attribute< Ch > * first_attribute(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
xml_node< Ch > * next_sibling(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
GLdouble GLdouble GLdouble r
std::string BASE_IMPEXP trim(const std::string &str)
void parse_xmlnode_shape(const rapidxml::xml_node< char > &xml_node, mrpt::math::TPolygon2D &out_poly, const char *functionNameContext="")
GLdouble GLdouble GLdouble b
mrpt::math::TPose2D parseXYPHI(const std::string &s, bool allow_missing_angle=false, double default_angle_radians=0.0)