Skip to content

Commit

Permalink
added --sec_tol command line parameter for defining secant tolerance …
Browse files Browse the repository at this point in the history
…when reading OpenSCAD csg
  • Loading branch information
arnholm committed Oct 7, 2020
1 parent 9b8961e commit 835fbf3
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
5 changes: 3 additions & 2 deletions csg_parser/csg_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
#include <vector>
#include <iomanip>

csg_parser::csg_parser(std::istream& csg)
csg_parser::csg_parser(std::istream& csg, double secant_tolerance)
: m_root(std::make_shared<csg_node>())
, m_secant_tolerance(secant_tolerance)
{
// read the whole file into a string
std::ostringstream sstr;
Expand Down Expand Up @@ -90,7 +91,7 @@ bool csg_parser::to_xcsg(cf_xmlTree& tree)
cf_xmlNode root;
if(tree.get_root(root)) {
root.add_property("version","1.0");
root.add_property("secant_tolerance","0.05");
root.add_property("secant_tolerance",m_secant_tolerance);

m_root->to_xcsg(root);
if(m_root->dimension() < 2) throw std::runtime_error("Undetermined .csg model dimension, conversion failed.");
Expand Down
3 changes: 2 additions & 1 deletion csg_parser/csg_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class csg_parser {
typedef std::pair<std::string,std::pair<size_t,size_t>> func_data; // <signature,<tree_level,line>>

// parse openscad.csg file and build the openscad tree
csg_parser(std::istream& csg);
csg_parser(std::istream& csg, double secant_tolerance);
virtual ~csg_parser();

// create an xcsg tree
Expand All @@ -39,6 +39,7 @@ class csg_parser {
void init_func(const std::string& csg);

private:
double m_secant_tolerance;
std::shared_ptr<csg_node> m_root; // openscad tree
};

Expand Down
6 changes: 6 additions & 0 deletions xcsg/boost_command_line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ boost_command_line::boost_command_line(int argc , char **argv)
, m_version_shown(false)
, m_max_bool(std::numeric_limits<size_t>::max())
, m_export_dir(false,"")
, m_secant_tolerance(0.05)
{
generic.add_options()
("help,h", "Show this help message.")
Expand All @@ -59,6 +60,7 @@ boost_command_line::boost_command_line(int argc , char **argv)
("off", "OFF output format (Geomview Object File Format)")
("export_dir", po::value<std::string>(), "Export output files to directory")
("max_bool", po::value<size_t>(), "Max number of booleans allowed")
("sec_tol", po::value<double>(), "Secant tolerance when importing OpenSCAD csg (0.05)")
("fullpath", "Show full file paths.")
;

Expand Down Expand Up @@ -147,6 +149,10 @@ boost_command_line::boost_command_line(int argc , char **argv)
m_max_bool = get<size_t>("max_bool");
}

if(vm.count("sec_tol") > 0) {
m_secant_tolerance = get<double>("sec_tol");
}

// some things are counted as errors without error message
// this causes m_parse_ok to be false and the program stops
if(out_count == 0) error_count++;
Expand Down
3 changes: 3 additions & 0 deletions xcsg/boost_command_line.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class boost_command_line {

size_t max_bool() const { return m_max_bool; }

double secant_tolerance() { return m_secant_tolerance; }

std::pair<bool,std::string> export_dir() { return m_export_dir; }

private:
Expand All @@ -49,6 +51,7 @@ class boost_command_line {
bool m_help_shown;
bool m_version_shown;
size_t m_max_bool;
double m_secant_tolerance;
std::pair<bool,std::string> m_export_dir;
};

Expand Down
2 changes: 1 addition & 1 deletion xcsg/xcsg_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ bool xcsg_main::run()

cout << "Converting from OpenSCAD " << xcsg_file << endl;
std::ifstream csg(xcsg_file);
csg_parser parser(csg);
csg_parser parser(csg,m_cmd.secant_tolerance());
parser.to_xcsg(tree);

file.SetExt("xcsg");
Expand Down

0 comments on commit 835fbf3

Please sign in to comment.