From 83e5096570dca89d703fc2a266db5747605dfa8b Mon Sep 17 00:00:00 2001 From: Stinkfist0 Date: Thu, 10 Mar 2016 16:09:39 +0200 Subject: [PATCH] Support for --deflection-tolerance --- src/ifcconvert/IfcConvert.cpp | 13 +++++++------ src/ifcgeom/IfcGeomIteratorSettings.h | 14 ++++++++++++-- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/ifcconvert/IfcConvert.cpp b/src/ifcconvert/IfcConvert.cpp index 6cb987c2a0..a1ff5dc40e 100644 --- a/src/ifcconvert/IfcConvert.cpp +++ b/src/ifcconvert/IfcConvert.cpp @@ -121,7 +121,7 @@ int main(int argc, char** argv) { ("output-file", boost::program_options::value(), "output geometry file"); std::vector entity_vector/*, names*/; - //double deflection_tolerance; + double deflection_tolerance; boost::program_options::options_description geom_options; geom_options.add_options() ("plan", @@ -181,8 +181,8 @@ int main(int argc, char** argv) { "Disables computation of normals. Saves time and file size and is useful " "in instances where you're going to recompute normals for the exported " "model in other modelling application in any case.") - /*("deflection-tolerance", boost::program_options::value(&deflection_tolerance), - "Sets the deflection tolerance of the mesher, 1e-3 by default if not specified.")*/; + ("deflection-tolerance", boost::program_options::value(&deflection_tolerance), + "Sets the deflection tolerance of the mesher, 1e-3 by default if not specified."); std::string bounds; boost::program_options::options_description serializer_options; @@ -264,7 +264,7 @@ int main(int argc, char** argv) { const bool no_normals = vmap.count("no-normals") != 0 ; bool center_model = vmap.count("center-model") != 0 ; //const bool generate_uvs = vmap.count("generate-uvs") != 0 ; - //const bool deflection_tolerance_specified = vmap.count("deflection-tolerance") != 0 ; + const bool deflection_tolerance_specified = vmap.count("deflection-tolerance") != 0 ; boost::optional bounding_width, bounding_height; if (vmap.count("bounds") == 1) { int w, h; @@ -347,8 +347,9 @@ int main(int argc, char** argv) { settings.set(IfcGeom::IteratorSettings::NO_NORMALS, no_normals); settings.set(IfcGeom::IteratorSettings::CENTER_MODEL, center_model); //settings.set(IfcGeom::IteratorSettings::GENERATE_UVS, generate_uvs); - //if (deflection_tolerance_specified) - // settings.set_deflection_tolerance(deflection_tolerance); + if (deflection_tolerance_specified) { + settings.set_deflection_tolerance(deflection_tolerance); + } GeometrySerializer* serializer; if (output_extension == ".obj") { diff --git a/src/ifcgeom/IfcGeomIteratorSettings.h b/src/ifcgeom/IfcGeomIteratorSettings.h index 2d5a53a296..dbb62b5ee0 100644 --- a/src/ifcgeom/IfcGeomIteratorSettings.h +++ b/src/ifcgeom/IfcGeomIteratorSettings.h @@ -21,6 +21,7 @@ #define IFCGEOMITERATORSETTINGS_H #include "../ifcparse/IfcException.h" +#include "../ifcparse/IfcUtil.h" namespace IfcGeom { @@ -103,8 +104,17 @@ namespace IfcGeom /// Note that this is independent of the IFC length unit, one millimeter by default. double deflection_tolerance() const { return deflection_tolerance_; } - /// @todo Sanity check for the value - void set_deflection_tolerance(double value) { deflection_tolerance_ = value; } + + void set_deflection_tolerance(double value) + { + /// @todo Using deflection tolerance of 1e-6 or smaller hangs the conversion, research more in-depth. + /// This bug can be reproduced e.g. with the Duplex model that can be found from http://www.nibs.org/?page=bsa_commonbimfiles#project1 + deflection_tolerance_ = value; + if (deflection_tolerance_ <= 1e-6) { + Logger::Message(Logger::LOG_WARNING, "Deflection tolerance cannot be set to <= 1e-6, using default 1e-3"); + deflection_tolerance_ = 1e-3; + } + } /// Get boolean value for a single settings or for a combination of settings. bool get(SettingField setting) const