IfcGeom refactoring pt. 1

This commit is contained in:
Thomas Krijnen
2022-06-14 15:02:54 +02:00
parent 0f85890c72
commit d6f8448c83
90 changed files with 10675 additions and 5625 deletions
+50
View File
@@ -370,3 +370,53 @@ bool IfcGeom::util::is_nested_compound_of_solid(const TopoDS_Shape& s, int depth
return false;
}
}
namespace {
template <typename T> struct dimension_count {};
template <> struct dimension_count <gp_Trsf2d > { static const int n = 2; };
template <> struct dimension_count <gp_GTrsf2d> { static const int n = 2; };
template <> struct dimension_count < gp_Trsf > { static const int n = 3; };
template <> struct dimension_count < gp_GTrsf > { static const int n = 3; };
template <typename T>
bool is_identity_helper(const T& t, double tolerance) {
// Note the {1, n+1} range due to Open Cascade's 1-based indexing
// Note the {1, n+2} range due to the translation part of the matrix
for (int i = 1; i < dimension_count<T>::n + 2; ++i) {
for (int j = 1; j < dimension_count<T>::n + 1; ++j) {
const double iden_value = i == j ? 1. : 0.;
const double trsf_value = t.Value(j, i);
if (fabs(trsf_value - iden_value) > tolerance) {
return false;
}
}
}
return true;
}
}
bool IfcGeom::Kernel::is_identity(const gp_Trsf2d& t, double tolerance) {
return is_identity_helper(t, tolerance);
}
bool IfcGeom::Kernel::is_identity(const gp_GTrsf2d& t, double tolerance) {
return is_identity_helper(t, tolerance);
}
bool IfcGeom::Kernel::is_identity(const gp_Trsf& t, double tolerance) {
return is_identity_helper(t, tolerance);
}
bool IfcGeom::Kernel::is_identity(const gp_GTrsf& t, double tolerance) {
return is_identity_helper(t, tolerance);
}
inline IFC_PARSE_API gp_Trsf IfcGeom::Kernel::combine_offset_and_rotation(const gp_Vec & offset, const gp_Quaternion & rotation) {
auto offset_transform = gp_Trsf{};
offset_transform.SetTranslation(offset);
auto rotation_transform = gp_Trsf{};
rotation_transform.SetRotation(rotation);
return rotation_transform * offset_transform;
}
+50
View File
@@ -33,6 +33,12 @@
#include <boost/function.hpp>
#include <TopExp_Explorer.hxx>
#include <gp_Ax2.hxx>
#include <gp_Ax3.hxx>
#include <gp_Trsf2d.hxx>
#include <gp_GTrsf2d.hxx>
#include <gp_Trsf.hxx>
#include <gp_GTrsf.hxx>
namespace IfcGeom {
@@ -116,6 +122,32 @@ namespace IfcGeom {
IFC_PARSE_API static bool is_manifold(const TopoDS_Shape& a);
IFC_PARSE_API static IfcUtil::IfcBaseEntity* get_decomposing_entity(IfcUtil::IfcBaseEntity*, bool include_openings = true);
IFC_PARSE_API static std::map<std::string, IfcUtil::IfcBaseEntity*> get_layers(IfcUtil::IfcBaseEntity*);
// For axis placements detect equality early in order for the
// relatively computionaly expensive gp_Trsf calculation to be skipped
IFC_PARSE_API static bool axis_equal(const gp_Ax3& a, const gp_Ax3& b, double tolerance) {
if (!a.Location().IsEqual(b.Location(), tolerance)) return false;
// Note that the tolerance below is angular, above is linear. Since architectural
// objects are about 1m'ish in scale, it should be somewhat equivalent. Besides,
// this is mostly a filter for NULL or default values in the placements.
if (!a.Direction().IsEqual(b.Direction(), tolerance)) return false;
if (!a.XDirection().IsEqual(b.XDirection(), tolerance)) return false;
if (!a.YDirection().IsEqual(b.YDirection(), tolerance)) return false;
return true;
}
IFC_PARSE_API static bool axis_equal(const gp_Ax2d& a, const gp_Ax2d& b, double tolerance) {
if (!a.Location().IsEqual(b.Location(), tolerance)) return false;
if (!a.Direction().IsEqual(b.Direction(), tolerance)) return false;
return true;
}
IFC_PARSE_API static bool is_identity(const gp_Trsf2d& t, double tolerance);
IFC_PARSE_API static bool is_identity(const gp_GTrsf2d& t, double tolerance);
IFC_PARSE_API static bool is_identity(const gp_Trsf& t, double tolerance);
IFC_PARSE_API static bool is_identity(const gp_GTrsf& t, double tolerance);
IFC_PARSE_API static gp_Trsf combine_offset_and_rotation(const gp_Vec &offset, const gp_Quaternion& rotation);
};
namespace impl {
@@ -134,6 +166,24 @@ namespace IfcGeom {
namespace util {
bool is_nested_compound_of_solid(const TopoDS_Shape& s, int depth = 0);
}
class IFC_GEOM_API geometry_exception : public std::exception {
protected:
std::string message;
public:
geometry_exception(const std::string& m)
: message(m) {}
virtual ~geometry_exception() throw () {}
virtual const char* what() const throw() {
return message.c_str();
}
};
class IFC_GEOM_API too_many_faces_exception : public geometry_exception {
public:
too_many_faces_exception()
: geometry_exception("Too many faces for operation") {}
};
}
#endif