21 #ifndef GEOMTOOLS_STL_TOOLS_H 22 #define GEOMTOOLS_STL_TOOLS_H 1 34 #pragma clang diagnostic push 35 #pragma clang diagnostic ignored "-Wunused-parameter" 37 #include <boost/spirit/include/qi.hpp> 39 #pragma clang diagnostic pop 42 #include <boost/spirit/include/phoenix_core.hpp> 43 #include <boost/spirit/include/phoenix_operator.hpp> 44 #include <boost/spirit/include/phoenix_object.hpp> 45 #include <boost/spirit/include/phoenix_fusion.hpp> 46 #include <boost/spirit/include/phoenix_stl.hpp> 47 #include <boost/fusion/include/adapt_struct.hpp> 66 friend std::ostream &
operator<<(std::ostream & out_,
91 friend std::ostream &
operator<<(std::ostream & out_,
111 friend std::ostream &
operator<<( std::ostream & out_,
const solid & sld_);
134 (std::vector<geomtools::stl::vertex>,vertices)
139 (std::vector<geomtools::stl::facet>,facets)
140 (std::string, dummy_name)
152 template <
typename Iterator>
153 struct vertex_parser :
154 boost::spirit::qi::grammar<Iterator,
156 boost::spirit::qi::ascii::space_type>
158 vertex_parser () : vertex_parser::base_type(start)
161 boost::spirit::qi::lit(
"vertex")
162 > boost::spirit::qi::double_
163 > boost::spirit::qi::double_
164 > boost::spirit::qi::double_
170 boost::spirit::qi::rule<Iterator,
172 boost::spirit::qi::ascii::space_type> start;
176 template <
typename Iterator>
177 struct facet_parser : boost::spirit::qi::grammar<Iterator,
179 boost::spirit::qi::locals<std::string>,
180 boost::spirit::qi::ascii::space_type>
182 facet_parser () : facet_parser::base_type(facet_grammar,
"geomtools::stl::facet_grammar")
186 boost::spirit::qi::lit(
"facet")
187 > boost::spirit::qi::lit(
"normal")
188 > boost::spirit::qi::double_
189 > boost::spirit::qi::double_
190 > boost::spirit::qi::double_
191 > boost::spirit::qi::no_skip[boost::spirit::qi::omit[*boost::spirit::qi::blank] > boost::spirit::qi::eol]
192 > boost::spirit::qi::lit(
"outer")
193 > boost::spirit::qi::lit(
"loop")
194 > boost::spirit::qi::no_skip[boost::spirit::qi::omit[*boost::spirit::qi::blank] > boost::spirit::qi::eol]
197 > boost::spirit::qi::repeat(3)[vertex_grammar
198 > boost::spirit::qi::no_skip[boost::spirit::qi::omit[*boost::spirit::qi::blank]
199 > boost::spirit::qi::eol]
202 > boost::spirit::qi::lit(
"endloop")
203 > boost::spirit::qi::no_skip[boost::spirit::qi::omit[*boost::spirit::qi::blank] > boost::spirit::qi::eol]
204 > boost::spirit::qi::lit(
"endfacet")
205 > boost::spirit::qi::no_skip[boost::spirit::qi::omit[*boost::spirit::qi::blank] > boost::spirit::qi::eol]
208 facet_grammar.name(
"geomtools::stl::facet_grammar");
209 vertex_grammar.name(
"geomtools::stl::vertex_grammar");
211 boost::spirit::qi::on_error<boost::spirit::qi::fail>
215 << boost::phoenix::val(
"Error! Expecting ")
216 << boost::spirit::qi::_4
217 << boost::phoenix::val(
" here: \"")
218 << boost::phoenix::construct<std::string>(boost::spirit::qi::_3,
219 boost::spirit::qi::_2)
220 << boost::phoenix::val(
"\"")
228 geomtools::stl::vertex_parser<Iterator> vertex_grammar;
229 boost::spirit::qi::rule<Iterator,
231 boost::spirit::qi::locals<std::string>,
232 boost::spirit::qi::ascii::space_type> facet_grammar;
238 template <
typename Iterator>
239 struct solid_parser : boost::spirit::qi::grammar<Iterator,
241 boost::spirit::qi::locals<std::string>,
242 boost::spirit::qi::ascii::space_type>
244 solid_parser () : solid_parser::base_type(solid_grammar,
"geomtools::stl:solid_grammar")
248 boost::spirit::qi::lexeme[ boost::spirit::qi::alpha >> *boost::spirit::qi::alnum]
252 boost::spirit::qi::lit(
"solid")
254 > boost::spirit::qi::omit[ boost::spirit::qi::lexeme[ *(boost::spirit::qi::char_ - boost::spirit::qi::eol) ]]
256 > boost::spirit::qi::no_skip[boost::spirit::qi::omit[*boost::spirit::qi::blank] > boost::spirit::qi::eol]
257 > boost::spirit::qi::repeat(4, boost::spirit::qi::inf)[facet_grammar]
258 > boost::spirit::qi::lit(
"endsolid")
260 > boost::spirit::qi::omit[boost::spirit::qi::lexeme[ *(boost::spirit::qi::char_ - boost::spirit::qi::eol) ]]
261 > boost::spirit::qi::no_skip[boost::spirit::qi::omit[*boost::spirit::qi::blank] > boost::spirit::qi::eol]
264 solid_grammar.name(
"geomtools::stl::solid_grammar");
265 facet_grammar.name(
"geomtools::stl::solid::facet_grammar");
266 name_grammar.name(
"geomtools::stl::solid::name_grammar");
268 boost::spirit::qi::on_error<boost::spirit::qi::fail>
272 << boost::phoenix::val(
"Error! Expecting ")
273 << boost::spirit::qi::_4
274 << boost::phoenix::val(
" here: \"")
275 << boost::phoenix::construct<std::string>(boost::spirit::qi::_3, boost::spirit::qi::_2)
276 << boost::phoenix::val(
"\"")
284 boost::spirit:: qi::rule<Iterator, std::string(), boost::spirit::qi::ascii::space_type> name_grammar;
285 geomtools::stl::facet_parser<Iterator> facet_grammar;
286 boost::spirit::qi::rule<Iterator,
288 boost::spirit::qi::locals<std::string>,
289 boost::spirit::qi::ascii::space_type> solid_grammar;
300 class tessellated_solid;
312 class stl_to_geomtools_converter
316 bool is_debug ()
const;
318 void set_debug (
bool);
320 bool is_check_normal ()
const;
322 void set_check_normal (
bool);
324 bool is_fix_attempt ()
const;
326 void set_fix_attempt (
bool);
328 bool is_lock_ts ()
const;
330 void set_lock_ts (
bool d_);
332 double get_length_unit ()
const;
334 void set_length_unit (
double u_);
337 stl_to_geomtools_converter ();
339 int convert (
const solid & solid_, tessellated_solid & ts_);
341 static void fix_broken_facets (tessellated_solid & ts_,
bool verbose_ =
true);
349 double _length_unit_;
357 #endif // GEOMTOOLS_STL_TOOLS_H