Build comprehensive representation id. Fix #225

This commit is contained in:
Thomas Krijnen
2017-06-28 15:24:49 +02:00
parent a90936a7de
commit 6f7afd4b2a
5 changed files with 64 additions and 40 deletions
+1 -1
View File
@@ -399,7 +399,7 @@ void ColladaSerializer::ColladaExporter::write(const IfcGeom::TriangulationEleme
const std::string name = serializer->settings().get(SerializerSettings::USE_ELEMENT_GUIDS) ? const std::string name = serializer->settings().get(SerializerSettings::USE_ELEMENT_GUIDS) ?
o->guid() : (serializer->settings().get(SerializerSettings::USE_ELEMENT_NAMES) ? o->guid() : (serializer->settings().get(SerializerSettings::USE_ELEMENT_NAMES) ?
o->name() : (serializer->settings().get(SerializerSettings::USE_ELEMENT_TYPES) ? o->type() + slabSuffix : o->unique_id())); o->name() : (serializer->settings().get(SerializerSettings::USE_ELEMENT_TYPES) ? o->type() + slabSuffix : o->unique_id()));
const std::string representation_id = "representation-" + boost::lexical_cast<std::string>(o->geometry().id()); const std::string representation_id = "representation-" + o->geometry().id();
std::vector<std::string> material_references; std::vector<std::string> material_references;
foreach(const IfcGeom::Material& material, mesh.materials()) { foreach(const IfcGeom::Material& material, mesh.materials()) {
if (!materials.contains(material)) { if (!materials.contains(material)) {
+25 -3
View File
@@ -1082,6 +1082,10 @@ template <typename P>
IfcGeom::BRepElement<P>* IfcGeom::Kernel::create_brep_for_representation_and_product( IfcGeom::BRepElement<P>* IfcGeom::Kernel::create_brep_for_representation_and_product(
const IteratorSettings& settings, IfcSchema::IfcRepresentation* representation, IfcSchema::IfcProduct* product) const IteratorSettings& settings, IfcSchema::IfcRepresentation* representation, IfcSchema::IfcProduct* product)
{ {
std::stringstream representation_id_builder;
representation_id_builder << representation->entity->id();
IfcGeom::Representation::BRep* shape; IfcGeom::Representation::BRep* shape;
IfcGeom::IfcRepresentationShapeItems shapes, shapes2; IfcGeom::IfcRepresentationShapeItems shapes, shapes2;
@@ -1098,6 +1102,17 @@ IfcGeom::BRepElement<P>* IfcGeom::Kernel::create_brep_for_representation_and_pro
std::vector< std::vector<Handle_Geom_Surface> > folded_layers; std::vector< std::vector<Handle_Geom_Surface> > folded_layers;
std::vector<const SurfaceStyle*> styles; std::vector<const SurfaceStyle*> styles;
if (convert_layerset(product, layers, styles, thickness)) { if (convert_layerset(product, layers, styles, thickness)) {
IfcSchema::IfcRelAssociates::list::ptr associations = product->HasAssociations();
for (IfcSchema::IfcRelAssociates::list::it it = associations->begin(); it != associations->end(); ++it) {
IfcSchema::IfcRelAssociatesMaterial* associates_material = (**it).as<IfcSchema::IfcRelAssociatesMaterial>();
if (associates_material) {
unsigned layerset_id = associates_material->RelatingMaterial()->entity->id();
representation_id_builder << "-layerset-" << layerset_id;
break;
}
}
if (product->as<IfcSchema::IfcWall>() && fold_layers(product->as<IfcSchema::IfcWall>(), shapes, layers, thickness, folded_layers)) { if (product->as<IfcSchema::IfcWall>() && fold_layers(product->as<IfcSchema::IfcWall>(), shapes, layers, thickness, folded_layers)) {
if (apply_folded_layerset(shapes, folded_layers, styles, shapes2)) { if (apply_folded_layerset(shapes, folded_layers, styles, shapes2)) {
std::swap(shapes, shapes2); std::swap(shapes, shapes2);
@@ -1136,6 +1151,11 @@ IfcGeom::BRepElement<P>* IfcGeom::Kernel::create_brep_for_representation_and_pro
ElementSettings element_settings(settings, getValue(GV_LENGTH_UNIT), product_type); ElementSettings element_settings(settings, getValue(GV_LENGTH_UNIT), product_type);
if (!settings.get(IfcGeom::IteratorSettings::DISABLE_OPENING_SUBTRACTIONS) && openings && openings->size()) { if (!settings.get(IfcGeom::IteratorSettings::DISABLE_OPENING_SUBTRACTIONS) && openings && openings->size()) {
representation_id_builder << "-openings";
for (IfcSchema::IfcRelVoidsElement::list::it it = openings->begin(); it != openings->end(); ++it) {
representation_id_builder << "-" << (*it)->entity->id();
}
IfcGeom::IfcRepresentationShapeItems opened_shapes; IfcGeom::IfcRepresentationShapeItems opened_shapes;
try { try {
#if OCC_VERSION_HEX < 0x60900 #if OCC_VERSION_HEX < 0x60900
@@ -1160,16 +1180,18 @@ IfcGeom::BRepElement<P>* IfcGeom::Kernel::create_brep_for_representation_and_pro
it->prepend(trsf); it->prepend(trsf);
} }
trsf = gp_Trsf(); trsf = gp_Trsf();
representation_id_builder << "-world-coords";
} }
shape = new IfcGeom::Representation::BRep(element_settings, representation->entity->id(), opened_shapes); shape = new IfcGeom::Representation::BRep(element_settings, representation_id_builder.str(), opened_shapes);
} else if (settings.get(IteratorSettings::USE_WORLD_COORDS)) { } else if (settings.get(IteratorSettings::USE_WORLD_COORDS)) {
for ( IfcGeom::IfcRepresentationShapeItems::iterator it = shapes.begin(); it != shapes.end(); ++ it ) { for ( IfcGeom::IfcRepresentationShapeItems::iterator it = shapes.begin(); it != shapes.end(); ++ it ) {
it->prepend(trsf); it->prepend(trsf);
} }
trsf = gp_Trsf(); trsf = gp_Trsf();
shape = new IfcGeom::Representation::BRep(element_settings, representation->entity->id(), shapes); representation_id_builder << "-world-coords";
shape = new IfcGeom::Representation::BRep(element_settings, representation_id_builder.str(), shapes);
} else { } else {
shape = new IfcGeom::Representation::BRep(element_settings, representation->entity->id(), shapes); shape = new IfcGeom::Representation::BRep(element_settings, representation_id_builder.str(), shapes);
} }
std::string context_string = ""; std::string context_string = "";
+7 -5
View File
@@ -340,6 +340,8 @@ namespace IfcGeom {
std::set<IfcSchema::IfcRepresentation*> mapped_representations_processed; std::set<IfcSchema::IfcRepresentation*> mapped_representations_processed;
bool geometry_reuse_ok_for_current_representation_;
BRepElement<P>* create_shape_model_for_next_entity() { BRepElement<P>* create_shape_model_for_next_entity() {
for (;;) { for (;;) {
IfcSchema::IfcRepresentation* representation; IfcSchema::IfcRepresentation* representation;
@@ -397,14 +399,14 @@ namespace IfcGeom {
// With world coords enabled, object transformations are directly applied to // With world coords enabled, object transformations are directly applied to
// the BRep. There is no way to re-use the geometry for multiple products. // the BRep. There is no way to re-use the geometry for multiple products.
const bool process_maps_for_current_representation = !settings.get(IteratorSettings::USE_WORLD_COORDS) && geometry_reuse_ok_for_current_representation_ = !settings.get(IteratorSettings::USE_WORLD_COORDS) &&
(!has_openings || settings.get(IteratorSettings::DISABLE_OPENING_SUBTRACTIONS)) && (!has_openings || settings.get(IteratorSettings::DISABLE_OPENING_SUBTRACTIONS)) &&
(!has_layers || !settings.get(IteratorSettings::APPLY_LAYERSETS)); (!has_layers || !settings.get(IteratorSettings::APPLY_LAYERSETS));
bool representation_processed_as_mapped_item = false; bool representation_processed_as_mapped_item = false;
IfcSchema::IfcRepresentation* representation_mapped_to = 0; IfcSchema::IfcRepresentation* representation_mapped_to = 0;
if (process_maps_for_current_representation) { if (geometry_reuse_ok_for_current_representation_) {
IfcSchema::IfcRepresentationItem::list::ptr items = representation->Items(); IfcSchema::IfcRepresentationItem::list::ptr items = representation->Items();
if (items->size() == 1) { if (items->size() == 1) {
IfcSchema::IfcRepresentationItem* item = *items->begin(); IfcSchema::IfcRepresentationItem* item = *items->begin();
@@ -457,7 +459,7 @@ namespace IfcGeom {
IfcSchema::IfcRepresentationMap::list::ptr maps = representation->RepresentationMap(); IfcSchema::IfcRepresentationMap::list::ptr maps = representation->RepresentationMap();
if (process_maps_for_current_representation && maps->size() == 1) { if (geometry_reuse_ok_for_current_representation_ && maps->size() == 1) {
IfcSchema::IfcRepresentationMap* map = *maps->begin(); IfcSchema::IfcRepresentationMap* map = *maps->begin();
if (kernel.is_identity_transform(map->MappingOrigin())) { if (kernel.is_identity_transform(map->MappingOrigin())) {
IfcSchema::IfcMappedItem::list::ptr items = map->MapUsage(); IfcSchema::IfcMappedItem::list::ptr items = map->MapUsage();
@@ -511,7 +513,7 @@ namespace IfcGeom {
Logger::SetProduct(product); Logger::SetProduct(product);
BRepElement<P>* element; BRepElement<P>* element;
if (ifcproduct_iterator == ifcproducts->begin() || settings.get(IteratorSettings::USE_WORLD_COORDS)) { if (ifcproduct_iterator == ifcproducts->begin() || !geometry_reuse_ok_for_current_representation_) {
element = kernel.create_brep_for_representation_and_product<P>(settings, representation, product); element = kernel.create_brep_for_representation_and_product<P>(settings, representation, product);
} else { } else {
element = kernel.create_brep_for_processed_representation(settings, representation, product, current_shape_model); element = kernel.create_brep_for_processed_representation(settings, representation, product, current_shape_model);
@@ -678,7 +680,7 @@ namespace IfcGeom {
} }
} else if (!settings.get(IteratorSettings::DISABLE_TRIANGULATION)) { } else if (!settings.get(IteratorSettings::DISABLE_TRIANGULATION)) {
try { try {
if (ifcproduct_iterator == ifcproducts->begin() || settings.get(IteratorSettings::USE_WORLD_COORDS)) { if (ifcproduct_iterator == ifcproducts->begin() || !geometry_reuse_ok_for_current_representation_) {
next_triangulation = new TriangulationElement<P>(*next_shape_model); next_triangulation = new TriangulationElement<P>(*next_shape_model);
} else { } else {
next_triangulation = new TriangulationElement<P>(*next_shape_model, current_triangulation->geometry_pointer()); next_triangulation = new TriangulationElement<P>(*next_shape_model, current_triangulation->geometry_pointer());
+10 -10
View File
@@ -29,7 +29,7 @@
IfcGeom::Representation::Serialization::Serialization(const BRep& brep) IfcGeom::Representation::Serialization::Serialization(const BRep& brep)
: Representation(brep.settings()) : Representation(brep.settings())
, _id(brep.getId()) , id_(brep.id())
{ {
TopoDS_Compound compound; TopoDS_Compound compound;
BRep_Builder builder; BRep_Builder builder;
@@ -40,18 +40,18 @@ IfcGeom::Representation::Serialization::Serialization(const BRep& brep)
if (it->hasStyle() && it->Style().Diffuse()) { if (it->hasStyle() && it->Style().Diffuse()) {
const IfcGeom::SurfaceStyle::ColorComponent& clr = *it->Style().Diffuse(); const IfcGeom::SurfaceStyle::ColorComponent& clr = *it->Style().Diffuse();
_surface_styles.push_back(clr.R()); surface_styles_.push_back(clr.R());
_surface_styles.push_back(clr.G()); surface_styles_.push_back(clr.G());
_surface_styles.push_back(clr.B()); surface_styles_.push_back(clr.B());
} else { } else {
_surface_styles.push_back(-1.); surface_styles_.push_back(-1.);
_surface_styles.push_back(-1.); surface_styles_.push_back(-1.);
_surface_styles.push_back(-1.); surface_styles_.push_back(-1.);
} }
if (it->hasStyle() && it->Style().Transparency()) { if (it->hasStyle() && it->Style().Transparency()) {
_surface_styles.push_back(1. - *it->Style().Transparency()); surface_styles_.push_back(1. - *it->Style().Transparency());
} else { } else {
_surface_styles.push_back(1.); surface_styles_.push_back(1.);
} }
if (settings().get(IteratorSettings::CONVERT_BACK_UNITS)) { if (settings().get(IteratorSettings::CONVERT_BACK_UNITS)) {
@@ -66,5 +66,5 @@ IfcGeom::Representation::Serialization::Serialization(const BRep& brep)
} }
std::stringstream sstream; std::stringstream sstream;
BRepTools::Write(compound,sstream); BRepTools::Write(compound,sstream);
_brep_data = sstream.str(); brep_data_ = sstream.str();
} }
+21 -21
View File
@@ -46,45 +46,45 @@ namespace IfcGeom {
Representation(const Representation&); //N/A Representation(const Representation&); //N/A
Representation& operator =(const Representation&); //N/A Representation& operator =(const Representation&); //N/A
protected: protected:
const ElementSettings _settings; const ElementSettings settings_;
public: public:
explicit Representation(const ElementSettings& settings) explicit Representation(const ElementSettings& settings)
: _settings(settings) : settings_(settings)
{} {}
const ElementSettings& settings() const { return _settings; } const ElementSettings& settings() const { return settings_; }
virtual ~Representation() {} virtual ~Representation() {}
}; };
class IFC_GEOM_API BRep : public Representation { class IFC_GEOM_API BRep : public Representation {
private: private:
unsigned int id; std::string id_;
const IfcGeom::IfcRepresentationShapeItems _shapes; const IfcGeom::IfcRepresentationShapeItems shapes_;
BRep(const BRep& other); BRep(const BRep& other);
BRep& operator=(const BRep& other); BRep& operator=(const BRep& other);
public: public:
BRep(const ElementSettings& settings, unsigned int id, const IfcGeom::IfcRepresentationShapeItems& shapes) BRep(const ElementSettings& settings, const std::string& id, const IfcGeom::IfcRepresentationShapeItems& shapes)
: Representation(settings) : Representation(settings)
, id(id) , id_(id)
, _shapes(shapes) , shapes_(shapes)
{} {}
virtual ~BRep() {} virtual ~BRep() {}
IfcGeom::IfcRepresentationShapeItems::const_iterator begin() const { return _shapes.begin(); } IfcGeom::IfcRepresentationShapeItems::const_iterator begin() const { return shapes_.begin(); }
IfcGeom::IfcRepresentationShapeItems::const_iterator end() const { return _shapes.end(); } IfcGeom::IfcRepresentationShapeItems::const_iterator end() const { return shapes_.end(); }
const IfcGeom::IfcRepresentationShapeItems& shapes() const { return _shapes; } const IfcGeom::IfcRepresentationShapeItems& shapes() const { return shapes_; }
const unsigned int& getId() const { return id; } const std::string& id() const { return id_; }
}; };
class IFC_GEOM_API Serialization : public Representation { class IFC_GEOM_API Serialization : public Representation {
private: private:
int _id; std::string id_;
std::string _brep_data; std::string brep_data_;
std::vector<double> _surface_styles; std::vector<double> surface_styles_;
public: public:
int id() const { return _id; } const std::string& brep_data() const { return brep_data_; }
const std::string& brep_data() const { return _brep_data; } const std::vector<double>& surface_styles() const { return surface_styles_; }
const std::vector<double>& surface_styles() const { return _surface_styles; }
Serialization(const BRep& brep); Serialization(const BRep& brep);
virtual ~Serialization() {} virtual ~Serialization() {}
const std::string& id() const { return id_; }
private: private:
Serialization(); Serialization();
Serialization(const Serialization&); Serialization(const Serialization&);
@@ -101,7 +101,7 @@ namespace IfcGeom {
typedef std::map<VertexKey, int> VertexKeyMap; typedef std::map<VertexKey, int> VertexKeyMap;
typedef std::pair<int, int> Edge; typedef std::pair<int, int> Edge;
int _id; std::string id_;
std::vector<P> _verts; std::vector<P> _verts;
std::vector<int> _faces; std::vector<int> _faces;
std::vector<int> _edges; std::vector<int> _edges;
@@ -112,7 +112,7 @@ namespace IfcGeom {
VertexKeyMap welds; VertexKeyMap welds;
public: public:
int id() const { return _id; } const std::string& id() const { return id_; }
const std::vector<P>& verts() const { return _verts; } const std::vector<P>& verts() const { return _verts; }
const std::vector<int>& faces() const { return _faces; } const std::vector<int>& faces() const { return _faces; }
const std::vector<int>& edges() const { return _edges; } const std::vector<int>& edges() const { return _edges; }
@@ -123,7 +123,7 @@ namespace IfcGeom {
Triangulation(const BRep& shape_model) Triangulation(const BRep& shape_model)
: Representation(shape_model.settings()) : Representation(shape_model.settings())
, _id(shape_model.getId()) , id_(shape_model.id())
{ {
for ( IfcGeom::IfcRepresentationShapeItems::const_iterator iit = shape_model.begin(); iit != shape_model.end(); ++ iit ) { for ( IfcGeom::IfcRepresentationShapeItems::const_iterator iit = shape_model.begin(); iit != shape_model.end(); ++ iit ) {