More work

This commit is contained in:
Thomas Krijnen
2019-08-16 17:40:13 +02:00
parent dae35f59ce
commit ddeaf5a375
52 changed files with 4083 additions and 4184 deletions
+37 -43
View File
@@ -27,18 +27,17 @@
#include "../../ifcparse/Argument.h"
#include "../../ifcgeom/schema_agnostic/IfcGeomRepresentation.h"
#include "../../ifcgeom/schema_agnostic/IfcGeomIteratorSettings.h"
#include "../../ifcgeom/settings.h"
#include "ifc_geom_api.h"
namespace IfcGeom {
namespace ifcopenshell { namespace geometry {
template <typename P>
class Matrix {
private:
std::vector<P> _data;
std::vector<double> _data;
public:
Matrix(const ElementSettings& settings, const IfcGeom::ConversionResultPlacement* trsf) {
Matrix(const element_settings& settings, const ConversionResultPlacement* trsf) {
// Convert the gp_Trsf into a 4x3 Matrix
// Note that in case the CONVERT_BACK_UNITS setting is enabled
// the translation component of the matrix needs to be divided
@@ -49,30 +48,29 @@ namespace IfcGeom {
const double trsf_value = (trsf == nullptr)
? (i == j ? 1. : 0.)
: trsf->Value(j,i);
const double matrix_value = (i == 4 && settings.get(IteratorSettings::CONVERT_BACK_UNITS))
const double matrix_value = (i == 4 && settings.get(settings::CONVERT_BACK_UNITS))
? trsf_value / settings.unit_magnitude()
: trsf_value;
_data.push_back(static_cast<P>(matrix_value));
_data.push_back(static_cast<double>(matrix_value));
}
}
}
const std::vector<P>& data() const { return _data; }
const std::vector<double>& data() const { return _data; }
};
template <typename P>
class Transformation {
private:
ElementSettings settings_;
element_settings settings_;
ConversionResultPlacement* trsf_;
Matrix<P> matrix_;
Matrix matrix_;
public:
Transformation(const ElementSettings& settings, const IfcGeom::ConversionResultPlacement* trsf)
Transformation(const element_settings& settings, const ConversionResultPlacement* trsf)
: settings_(settings)
, trsf_(trsf ? trsf->clone() : nullptr)
, matrix_(settings, trsf)
{}
const IfcGeom::ConversionResultPlacement* data() const { return trsf_; }
const Matrix<P>& matrix() const { return matrix_; }
const ConversionResultPlacement* data() const { return trsf_; }
const Matrix& matrix() const { return matrix_; }
Transformation inverted() const {
return Transformation(settings_, trsf_->inverted());
@@ -83,7 +81,6 @@ namespace IfcGeom {
}
};
template <typename P = double, typename PP = P>
class Element {
private:
int _id;
@@ -93,17 +90,17 @@ namespace IfcGeom {
std::string _guid;
std::string _context;
std::string _unique_id;
Transformation<PP> _transformation;
Transformation _transformation;
IfcUtil::IfcBaseEntity* product_;
std::vector<const IfcGeom::Element<P, PP>*> _parents;
std::vector<const Element*> _parents;
public:
friend bool operator == (const Element<P, PP> & element1, const Element<P, PP> & element2) {
friend bool operator == (const Element & element1, const Element & element2) {
return element1.id() == element2.id();
}
// Use the id to compare, or the elevation is the elements are IfcBuildingStoreys and the elevation is set
friend bool operator < (const Element<P, PP> & element1, const Element<P, PP> & element2) {
friend bool operator < (const Element & element1, const Element & element2) {
if (element1.type() == "IfcBuildingStorey" && element2.type() == "IfcBuildingStorey") {
size_t attr_index = element1.product()->declaration().attribute_index("Elevation");
Argument* elev_attr1 = element1.product()->data().getArgument(attr_index);
@@ -127,13 +124,13 @@ namespace IfcGeom {
const std::string& guid() const { return _guid; }
const std::string& context() const { return _context; }
const std::string& unique_id() const { return _unique_id; }
const Transformation<PP>& transformation() const { return _transformation; }
const Transformation& transformation() const { return _transformation; }
IfcUtil::IfcBaseEntity* product() const { return product_; }
const std::vector<const IfcGeom::Element<P, PP>*> parents() const { return _parents; }
void SetParents(std::vector<const IfcGeom::Element<P, PP>*> newparents) { _parents = newparents; }
const std::vector<const Element*> parents() const { return _parents; }
void SetParents(std::vector<const Element*> newparents) { _parents = newparents; }
Element(const ElementSettings& settings, int id, int parent_id, const std::string& name, const std::string& type,
const std::string& guid, const std::string& context, const IfcGeom::ConversionResultPlacement* trsf, IfcUtil::IfcBaseEntity* product)
Element(const element_settings& settings, int id, int parent_id, const std::string& name, const std::string& type,
const std::string& guid, const std::string& context, const ConversionResultPlacement* trsf, IfcUtil::IfcBaseEntity* product)
: _id(id), _parent_id(parent_id), _name(name), _type(type), _guid(guid), _context(context), _transformation(settings, trsf)
, product_(product)
{
@@ -162,17 +159,16 @@ namespace IfcGeom {
virtual ~Element() {}
};
template <typename P = double, typename PP = P>
class NativeElement : public Element<P, PP> {
class NativeElement : public Element {
private:
boost::shared_ptr<Representation::BRep> _geometry;
public:
const boost::shared_ptr<Representation::BRep>& geometry_pointer() const { return _geometry; }
const Representation::BRep& geometry() const { return *_geometry; }
NativeElement(int id, int parent_id, const std::string& name, const std::string& type, const std::string& guid,
const std::string& context, const IfcGeom::ConversionResultPlacement* trsf, const boost::shared_ptr<Representation::BRep>& geometry,
const std::string& context, const ConversionResultPlacement* trsf, const boost::shared_ptr<Representation::BRep>& geometry,
IfcUtil::IfcBaseEntity* product)
: Element<P, PP>(geometry->settings() ,id, parent_id, name, type, guid, context, trsf, product)
: Element(geometry->settings() ,id, parent_id, name, type, guid, context, trsf, product)
, _geometry(geometry)
{}
@@ -184,19 +180,18 @@ namespace IfcGeom {
NativeElement& operator=(const NativeElement& other);
};
template <typename P = double, typename PP = P>
class TriangulationElement : public Element<P, PP> {
class TriangulationElement : public Element {
private:
boost::shared_ptr< Representation::Triangulation<P> > _geometry;
boost::shared_ptr<Representation::Triangulation> _geometry;
public:
const Representation::Triangulation<P>& geometry() const { return *_geometry; }
const boost::shared_ptr< Representation::Triangulation<P> >& geometry_pointer() const { return _geometry; }
TriangulationElement(const NativeElement<P, PP>& shape_model)
: Element<P, PP>(shape_model)
, _geometry(boost::shared_ptr<Representation::Triangulation<P> >(new Representation::Triangulation<P>(shape_model.geometry())))
const Representation::Triangulation& geometry() const { return *_geometry; }
const boost::shared_ptr< Representation::Triangulation >& geometry_pointer() const { return _geometry; }
TriangulationElement(const NativeElement& shape_model)
: Element(shape_model)
, _geometry(boost::shared_ptr<Representation::Triangulation >(new Representation::Triangulation(shape_model.geometry())))
{}
TriangulationElement(const Element<P, PP>& element, const boost::shared_ptr<Representation::Triangulation<P> >& geometry)
: Element<P, PP>(element)
TriangulationElement(const Element& element, const boost::shared_ptr<Representation::Triangulation >& geometry)
: Element(element)
, _geometry(geometry)
{}
private:
@@ -204,14 +199,13 @@ namespace IfcGeom {
TriangulationElement& operator=(const TriangulationElement& other);
};
template <typename P = double, typename PP = P>
class SerializedElement : public Element<P, PP> {
class SerializedElement : public Element {
private:
Representation::Serialization* _geometry;
public:
const Representation::Serialization& geometry() const { return *_geometry; }
SerializedElement(const NativeElement<P, PP>& shape_model)
: Element<P, PP>(shape_model)
SerializedElement(const NativeElement& shape_model)
: Element(shape_model)
, _geometry(new Representation::Serialization(shape_model.geometry()))
{}
virtual ~SerializedElement() {
@@ -221,6 +215,6 @@ namespace IfcGeom {
SerializedElement(const SerializedElement& other);
SerializedElement& operator=(const SerializedElement& other);
};
}
}}
#endif