mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-06 07:51:47 +00:00
Renumber instances, add comments, update federate for group structure
This commit is contained in:
@@ -29,6 +29,7 @@
|
|||||||
|
|
||||||
#pragma warning(disable:4100)
|
#pragma warning(disable:4100)
|
||||||
|
|
||||||
|
// A comparison operator that is used to isolate the shared hierarchy
|
||||||
class ifc_inst_cmp {
|
class ifc_inst_cmp {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@@ -159,9 +160,10 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Office_A_20110811_optimized.ifc Office_S_20110811_optimized.ifc Office_MEP_20110811_optimized.ifc
|
// Usage: hdf5_federate Office_A_20110811_optimized.ifc Office_S_20110811_optimized.ifc Office_MEP_20110811_optimized.ifc
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
|
|
||||||
|
// A set of datatypes for the shared hierarchy
|
||||||
std::set<IfcSchema::Type::Enum> shared {
|
std::set<IfcSchema::Type::Enum> shared {
|
||||||
IfcSchema::Type::IfcSite,
|
IfcSchema::Type::IfcSite,
|
||||||
IfcSchema::Type::IfcConversionBasedUnit,
|
IfcSchema::Type::IfcConversionBasedUnit,
|
||||||
@@ -177,13 +179,14 @@ int main(int argc, char** argv) {
|
|||||||
IfcSchema::Type::IfcBuildingStorey
|
IfcSchema::Type::IfcBuildingStorey
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Open the set of input files
|
||||||
std::vector<IfcParse::IfcFile*> files;
|
std::vector<IfcParse::IfcFile*> files;
|
||||||
|
|
||||||
for (int i = 1; i < argc; ++i) {
|
for (int i = 1; i < argc; ++i) {
|
||||||
files.push_back(new IfcParse::IfcFile());
|
files.push_back(new IfcParse::IfcFile());
|
||||||
files.back()->Init(argv[i]);
|
files.back()->Init(argv[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Detect shared instances
|
||||||
std::set<IfcUtil::IfcBaseClass*> shared_instances;
|
std::set<IfcUtil::IfcBaseClass*> shared_instances;
|
||||||
|
|
||||||
for (auto& ty : shared) {
|
for (auto& ty : shared) {
|
||||||
@@ -206,6 +209,7 @@ int main(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Follow forward references for shared instances
|
||||||
std::set<IfcUtil::IfcBaseClass*> shared_instances_and_refs;
|
std::set<IfcUtil::IfcBaseClass*> shared_instances_and_refs;
|
||||||
|
|
||||||
for (auto& inst : shared_instances) {
|
for (auto& inst : shared_instances) {
|
||||||
@@ -224,6 +228,7 @@ int main(int argc, char** argv) {
|
|||||||
time(&now_);
|
time(&now_);
|
||||||
int now = (int)now_;
|
int now = (int)now_;
|
||||||
|
|
||||||
|
// Create a novel ownerhistory for the shared hierarchy
|
||||||
IfcSchema::IfcPerson* person = new IfcSchema::IfcPerson(std::string("tfk"), std::string("Krijnen"), std::string("Thomas"), boost::none, boost::none, boost::none, boost::none, boost::none);
|
IfcSchema::IfcPerson* person = new IfcSchema::IfcPerson(std::string("tfk"), std::string("Krijnen"), std::string("Thomas"), boost::none, boost::none, boost::none, boost::none, boost::none);
|
||||||
IfcSchema::IfcOrganization* org = new IfcSchema::IfcOrganization(std::string("TU/e"), "Eindhoven University of Technology", boost::none, boost::none, boost::none);
|
IfcSchema::IfcOrganization* org = new IfcSchema::IfcOrganization(std::string("TU/e"), "Eindhoven University of Technology", boost::none, boost::none, boost::none);
|
||||||
IfcSchema::IfcPersonAndOrganization* pando = new IfcSchema::IfcPersonAndOrganization(person, org, boost::none);
|
IfcSchema::IfcPersonAndOrganization* pando = new IfcSchema::IfcPersonAndOrganization(person, org, boost::none);
|
||||||
@@ -253,6 +258,7 @@ int main(int argc, char** argv) {
|
|||||||
shared_instances_and_refs.clear();
|
shared_instances_and_refs.clear();
|
||||||
shared_instances_and_refs.insert(shared_instances_and_refs_vector.begin(), shared_instances_and_refs_vector.end());
|
shared_instances_and_refs.insert(shared_instances_and_refs_vector.begin(), shared_instances_and_refs_vector.end());
|
||||||
|
|
||||||
|
// Assign the new ownerhistory to rooted elements in the shared hierarchy
|
||||||
std::for_each(shared_instances_and_refs.begin(), shared_instances_and_refs.end(), [owner_history](IfcUtil::IfcBaseClass* inst) {
|
std::for_each(shared_instances_and_refs.begin(), shared_instances_and_refs.end(), [owner_history](IfcUtil::IfcBaseClass* inst) {
|
||||||
const IfcParse::entity* e = inst->declaration().as_entity();
|
const IfcParse::entity* e = inst->declaration().as_entity();
|
||||||
if (e) {
|
if (e) {
|
||||||
@@ -273,21 +279,14 @@ int main(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
|
||||||
for (auto& i : shared_instances_and_refs) {
|
|
||||||
if (shared_instances.find(i) == shared_instances.end()) {
|
|
||||||
std::cerr << i->data().toString() << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cerr << "----" << std::endl;
|
|
||||||
*/
|
|
||||||
|
|
||||||
std::set<IfcUtil::IfcBaseClass*, ifc_inst_cmp> shared_instances_and_refs_unique(shared_instances_and_refs.begin(), shared_instances_and_refs.end());
|
std::set<IfcUtil::IfcBaseClass*, ifc_inst_cmp> shared_instances_and_refs_unique(shared_instances_and_refs.begin(), shared_instances_and_refs.end());
|
||||||
|
|
||||||
|
// Serialize models into different groups
|
||||||
|
|
||||||
IfcParse::Hdf5Settings settings;
|
IfcParse::Hdf5Settings settings;
|
||||||
settings.profile() = IfcParse::Hdf5Settings::standard_referenced;
|
settings.profile() = IfcParse::Hdf5Settings::standard_referenced;
|
||||||
|
settings.compress() = true;
|
||||||
|
settings.chunk_size() = 1024;
|
||||||
|
|
||||||
std::vector<std::string> names;
|
std::vector<std::string> names;
|
||||||
std::vector<std::pair<std::string::const_iterator, std::string::const_iterator>> fixes;
|
std::vector<std::pair<std::string::const_iterator, std::string::const_iterator>> fixes;
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ void generate_bounding_boxes(IfcParse::IfcFile& f, const std::string& fn) {
|
|||||||
return compound;
|
return compound;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Generate non-aa bounding boxes in local coordinates as a tuple of six doubles from existing IfcProductDefinitionShape instances
|
||||||
std::for_each(defs.begin(), defs.end(), [&kernel, &brep_as_compound, &str, N, &n, &settings](IfcSchema::IfcProductDefinitionShape* def) {
|
std::for_each(defs.begin(), defs.end(), [&kernel, &brep_as_compound, &str, N, &n, &settings](IfcSchema::IfcProductDefinitionShape* def) {
|
||||||
Bnd_Box box;
|
Bnd_Box box;
|
||||||
|
|
||||||
@@ -138,6 +139,7 @@ void find_geometric_types(IfcParse::IfcFile& f, const std::string& tfn) {
|
|||||||
return a->data().id() < b->data().id();
|
return a->data().id() < b->data().id();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Initial choice of geometric types
|
||||||
std::set<IfcSchema::Type::Enum> geometric_types{
|
std::set<IfcSchema::Type::Enum> geometric_types{
|
||||||
IfcSchema::Type::IfcStyledItem, IfcSchema::Type::IfcMaterialDefinitionRepresentation, IfcSchema::Type::IfcStyledRepresentation,
|
IfcSchema::Type::IfcStyledItem, IfcSchema::Type::IfcMaterialDefinitionRepresentation, IfcSchema::Type::IfcStyledRepresentation,
|
||||||
IfcSchema::Type::IfcSurfaceStyleRendering, IfcSchema::Type::IfcSurfaceStyle, IfcSchema::Type::IfcPresentationLayerAssignment,
|
IfcSchema::Type::IfcSurfaceStyleRendering, IfcSchema::Type::IfcSurfaceStyle, IfcSchema::Type::IfcPresentationLayerAssignment,
|
||||||
@@ -145,6 +147,7 @@ void find_geometric_types(IfcParse::IfcFile& f, const std::string& tfn) {
|
|||||||
};
|
};
|
||||||
std::set<IfcSchema::Type::Enum> other_types;
|
std::set<IfcSchema::Type::Enum> other_types;
|
||||||
|
|
||||||
|
// Find all instances
|
||||||
std::set<IfcUtil::IfcBaseClass*> geometric_instances;
|
std::set<IfcUtil::IfcBaseClass*> geometric_instances;
|
||||||
|
|
||||||
for (auto ty : geometric_types) {
|
for (auto ty : geometric_types) {
|
||||||
@@ -170,6 +173,7 @@ void find_geometric_types(IfcParse::IfcFile& f, const std::string& tfn) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Recurse over forward attributes
|
||||||
auto vist_geometric = [&f, &geometric_types, &geometric_instances, &N, &n](IfcUtil::IfcBaseEntity* def) {
|
auto vist_geometric = [&f, &geometric_types, &geometric_instances, &N, &n](IfcUtil::IfcBaseEntity* def) {
|
||||||
auto refs = f.traverse(def);
|
auto refs = f.traverse(def);
|
||||||
geometric_instances.insert(refs->begin(), refs->end());
|
geometric_instances.insert(refs->begin(), refs->end());
|
||||||
@@ -188,6 +192,7 @@ void find_geometric_types(IfcParse::IfcFile& f, const std::string& tfn) {
|
|||||||
|
|
||||||
std::for_each(defs.begin(), defs.end(), vist_geometric);
|
std::for_each(defs.begin(), defs.end(), vist_geometric);
|
||||||
|
|
||||||
|
// Include connection geometry (e.g space boundaries) as well
|
||||||
auto connection_geom = f.entitiesByType<IfcSchema::IfcConnectionGeometry>();
|
auto connection_geom = f.entitiesByType<IfcSchema::IfcConnectionGeometry>();
|
||||||
|
|
||||||
n = 0;
|
n = 0;
|
||||||
@@ -195,6 +200,7 @@ void find_geometric_types(IfcParse::IfcFile& f, const std::string& tfn) {
|
|||||||
|
|
||||||
std::for_each(connection_geom->begin(), connection_geom->end(), vist_geometric);
|
std::for_each(connection_geom->begin(), connection_geom->end(), vist_geometric);
|
||||||
|
|
||||||
|
// Traverse again all instances, but now to detect which geometric types are fully and only shared by geometric instances
|
||||||
std::function<void(IfcUtil::IfcBaseClass*, IfcUtil::IfcBaseClass*)> fn;
|
std::function<void(IfcUtil::IfcBaseClass*, IfcUtil::IfcBaseClass*)> fn;
|
||||||
fn = [&f, &geometric_instances, &other_types, &fn](IfcUtil::IfcBaseClass* root, IfcUtil::IfcBaseClass* inst) {
|
fn = [&f, &geometric_instances, &other_types, &fn](IfcUtil::IfcBaseClass* root, IfcUtil::IfcBaseClass* inst) {
|
||||||
if (geometric_instances.find(inst) == geometric_instances.end()) {
|
if (geometric_instances.find(inst) == geometric_instances.end()) {
|
||||||
@@ -235,8 +241,6 @@ void find_geometric_types(IfcParse::IfcFile& f, const std::string& tfn) {
|
|||||||
const size_t name = ty;
|
const size_t name = ty;
|
||||||
str.write((char*)&name, sizeof(size_t));
|
str.write((char*)&name, sizeof(size_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cin.get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
@@ -341,6 +345,7 @@ int main(int argc, char** argv) {
|
|||||||
auto id = f.FreshId();
|
auto id = f.FreshId();
|
||||||
int num_points_added = 0;
|
int num_points_added = 0;
|
||||||
|
|
||||||
|
// Create bounding box representation from the 6-tuple definitions
|
||||||
{
|
{
|
||||||
std::ifstream str(cache_fn.c_str(), std::ios_base::binary);
|
std::ifstream str(cache_fn.c_str(), std::ios_base::binary);
|
||||||
while (!str.eof()) {
|
while (!str.eof()) {
|
||||||
@@ -387,6 +392,8 @@ int main(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generate proper buckets of data and serialize
|
||||||
|
|
||||||
all_old_defs.insert(all_old_defs.end(), old_defs.begin(), old_defs.end());
|
all_old_defs.insert(all_old_defs.end(), old_defs.begin(), old_defs.end());
|
||||||
all_old_defs.insert(all_old_defs.end(), old_prop_defs.begin(), old_prop_defs.end());
|
all_old_defs.insert(all_old_defs.end(), old_prop_defs.begin(), old_prop_defs.end());
|
||||||
all_old_defs.insert(all_old_defs.end(), old_geom_defs.begin(), old_geom_defs.end());
|
all_old_defs.insert(all_old_defs.end(), old_geom_defs.begin(), old_geom_defs.end());
|
||||||
@@ -413,7 +420,7 @@ int main(int argc, char** argv) {
|
|||||||
IfcParse::Hdf5Settings settings;
|
IfcParse::Hdf5Settings settings;
|
||||||
settings.profile() = IfcParse::Hdf5Settings::padded;
|
settings.profile() = IfcParse::Hdf5Settings::padded;
|
||||||
settings.compress() = true;
|
settings.compress() = true;
|
||||||
settings.chunk_size() = 256;
|
settings.chunk_size() = 1024;
|
||||||
|
|
||||||
H5::H5File hdf(argv[1] + std::string(".hdf"), H5F_ACC_TRUNC);
|
H5::H5File hdf(argv[1] + std::string(".hdf"), H5F_ACC_TRUNC);
|
||||||
H5::H5File geom_hdf(argv[1] + std::string("-geometry.hdf"), H5F_ACC_TRUNC);
|
H5::H5File geom_hdf(argv[1] + std::string("-geometry.hdf"), H5F_ACC_TRUNC);
|
||||||
|
|||||||
@@ -196,7 +196,7 @@ public:
|
|||||||
space.selectElements(H5S_SELECT_SET, 1, &coord);
|
space.selectElements(H5S_SELECT_SET, 1, &coord);
|
||||||
const std::string path = IfcSchema::Type::ToString(pop->first[a]);
|
const std::string path = IfcSchema::Type::ToString(pop->first[a]);
|
||||||
|
|
||||||
std::string full_path = group->getObjName() + "/" + path + "_instances";
|
std::string full_path = group->getObjName() + "/" + path + "_objects" + "/" + path + "_instances";
|
||||||
|
|
||||||
root_file_->reference(ptr, full_path, space);
|
root_file_->reference(ptr, full_path, space);
|
||||||
ptr = static_cast<uint8_t*>(ptr) + sizeof(hdset_reg_ref_t);
|
ptr = static_cast<uint8_t*>(ptr) + sizeof(hdset_reg_ref_t);
|
||||||
|
|||||||
@@ -10,6 +10,8 @@
|
|||||||
#pragma message("warning: HDF5 compression support is recommended")
|
#pragma message("warning: HDF5 compression support is recommended")
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define RENUMBER_INSTANCES
|
||||||
|
|
||||||
// Some string definitions used throughout this code
|
// Some string definitions used throughout this code
|
||||||
namespace {
|
namespace {
|
||||||
const char* const select_bitmap = "select_bitmap";
|
const char* const select_bitmap = "select_bitmap";
|
||||||
@@ -2045,8 +2047,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef RENUMBER_INSTANCES
|
#ifdef RENUMBER_INSTANCES
|
||||||
std::string path = dataset_names_[pair[0]];
|
std::string path_ = dataset_names_[pair[0]];
|
||||||
return instance_name(path, pair[1]);
|
return instance_name(path_, pair[1]);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
auto ppair = std::make_pair(pair[0], pair[1]);
|
auto ppair = std::make_pair(pair[0], pair[1]);
|
||||||
|
|||||||
Reference in New Issue
Block a user