Use the precision from the IfcGeometricRepresentationContext to dictate OCC modeler tolerances

This commit is contained in:
Thomas Krijnen
2013-11-24 15:44:27 +00:00
parent 0f53a877c7
commit bffb19a92f
7 changed files with 74 additions and 123 deletions
+27
View File
@@ -573,6 +573,32 @@ double UnitPrefixToValue( Ifc2x3::IfcSIPrefix::IfcSIPrefix v ) {
else return 1.0f;
}
void IfcGeomObjects::InitPrecision() {
Ifc2x3::IfcGeometricRepresentationContext::list rep_contexts = ifc_file->EntitiesByType<Ifc2x3::IfcGeometricRepresentationContext>();
// Currently, IfcGeometricRepresentationContext aren't used as much as they should be
// in the evaluation of shape representations, hence, we try to find the one with the
// lowest precision. Typically, a value of 1e-5 is encountered. This value is applied
// to all TopoDS_Shapes generated by one of the IfcGeom::convert() functions.
// TODO: Many of the empirically found tolerances should probably be substituted by
// one that is defined in the model file.
double lowest_precision_encountered = std::numeric_limits<double>::infinity();
bool any_precision_encountered = false;
for (Ifc2x3::IfcGeometricRepresentationContext::it it = rep_contexts->begin(); it != rep_contexts->end(); ++it) {
Ifc2x3::IfcGeometricRepresentationContext* rep_context = *it;
if (rep_context->is(Ifc2x3::Type::IfcGeometricRepresentationSubContext)) continue;
if (rep_context->hasPrecision()) {
const double precision = rep_context->Precision();
if (precision < lowest_precision_encountered) {
any_precision_encountered = true;
lowest_precision_encountered = precision;
}
}
}
if (any_precision_encountered) {
IfcGeom::SetValue(IfcGeom::GV_PRECISION, lowest_precision_encountered);
}
}
void IfcGeomObjects::InitUnits() {
// Set default units, set length to meters, angles to undefined
IfcGeom::SetValue(IfcGeom::GV_LENGTH_UNIT,1.0);
@@ -638,6 +664,7 @@ bool IfcGeomObjects::Init(const std::string fn) {
}
bool _Init() {
IfcGeomObjects::InitUnits();
IfcGeomObjects::InitPrecision();
shapereps = ifc_file->EntitiesByType<Ifc2x3::IfcShapeRepresentation>();
if ( ! shapereps ) return false;