13 #include <boost/math/constants/constants.hpp> 14 #include <boost/spirit/include/qi.hpp> 15 #include <boost/spirit/include/phoenix.hpp> 16 #include <boost/version.hpp> 21 namespace qi = boost::spirit::qi;
22 namespace ascii = boost::spirit::ascii;
23 namespace phx = boost::phoenix;
25 typedef std::string::const_iterator
Iter;
28 namespace qi = boost::spirit::qi;
41 return deg * boost::math::constants::pi<T>() / static_cast<T>(180);
92 T x = t / boost::math::constants::root_half_pi<T>();
93 return static_cast<T
>(
fresnel_s(x) / boost::math::constants::root_two_div_pi<T>());
108 T x = t / boost::math::constants::root_half_pi<T>();
109 return static_cast<T
>(
fresnel_c(x) / boost::math::constants::root_two_div_pi<T>());
115 class Grammar :
public qi::grammar<Iter, FormulaParser::ValueType(), Skipper>
124 template<
typename Sig>
135 template<
typename Functor,
typename Function,
typename Arg1>
136 struct result<Functor(Function, Arg1&)>
152 template<
typename Function,
typename Arg1>
153 Arg1 operator()(
const Function f,
const Arg1 a1)
const 164 class unaryFunction_ :
165 public qi::symbols<typename std::iterator_traits<Iter>::value_type, FormulaParser::ValueType(*)(FormulaParser::ValueType)>
193 Grammar(
FormulaParser& formulaParser) : Grammar::base_type(start)
204 phx::function<func1_> func1;
206 start = expression > qi::eoi;
208 expression = term[_val = _1]
209 >> *((
'+' >> term[_val += _1])
210 | (
'-' >> term[_val -= _1]));
212 term = factor[_val = _1]
213 >> *((
'*' >> factor[_val *= _1])
214 | (
'/' >> factor[_val /= _1]));
216 factor = primary[_val = _1];
220 variable = as_string[alpha >> *(alnum | char_(
'_'))]
223 primary = double_[_val = _1]
224 |
'(' >> expression[_val = _1] >>
')' 225 | (
'-' >> primary[_val = -_1])
226 | (
'+' >> primary[_val = _1])
227 | (unaryFunction >>
'(' >> expression >>
')')[_val = func1(_1, _2)]
228 | variable[_val = _1];
232 qi::rule<Iter, FormulaParser::ValueType(), Skipper> start;
233 qi::rule<Iter, FormulaParser::ValueType(), Skipper> expression;
234 qi::rule<Iter, FormulaParser::ValueType(), Skipper> term;
235 qi::rule<Iter, FormulaParser::ValueType(), Skipper> factor;
236 qi::rule<Iter, FormulaParser::ValueType(), Skipper> variable;
237 qi::rule<Iter, FormulaParser::ValueType(), Skipper> primary;
246 std::string::const_iterator iter = input.begin();
247 std::string::const_iterator end = input.end();
252 if (!qi::phrase_parse(iter, end, Grammar(*
this), ascii::space, result))
255 "': Grammar could not be applied to the input " <<
"at all.";
258 catch (qi::expectation_failure<Iter>& e)
260 std::string parsed =
"";
262 for (
Iter i = input.begin(); i != e.first; i++)
267 "': Unexpected character '" << *e.first <<
"' after '" << parsed <<
"'";
275 if (m_Variables ==
nullptr)
282 return m_Variables->at(var);
284 catch (std::out_of_range&)
T cosd(const T t)
Returns the cosine of the given degree scalar.
T fresnelS(const T t)
Returns the fresnel integral sine at the given x-coordinate.
T sind(const T t)
Returns the sine of the given degree scalar.
DataCollection - Class to facilitate loading/accessing structured data.
double fresnel_c(double x)
T fresnelC(const T t)
Returns the fresnel integral cosine at the given x-coordinate.
T tand(const T t)
Returns the tangent of the given degree scalar.
T deg2rad(const T deg)
Transforms the given number from degrees to radians and returns it.
double fresnel_s(double x)
#define mitkThrowException(classname)