From 16f2b0a0d25f204c59648be1ea6f27f74c969f96 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Tue, 13 Feb 2018 14:50:39 +0100 Subject: [PATCH] Renumber instances, add comments, update federate for group structure --- src/hdf5_usecases/federate.cpp | 25 +++++++++---------- src/hdf5_usecases/lod.cpp | 13 +++++++--- .../multifile_instance_locator.h | 2 +- src/ifcparse/IfcHdf5File.cpp | 6 +++-- 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/hdf5_usecases/federate.cpp b/src/hdf5_usecases/federate.cpp index 7a6ea5ed78b..8ecc42de216 100644 --- a/src/hdf5_usecases/federate.cpp +++ b/src/hdf5_usecases/federate.cpp @@ -29,6 +29,7 @@ #pragma warning(disable:4100) +// A comparison operator that is used to isolate the shared hierarchy class ifc_inst_cmp { public: @@ -159,9 +160,10 @@ class ifc_inst_cmp { } }; -// 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) { + // A set of datatypes for the shared hierarchy std::set shared { IfcSchema::Type::IfcSite, IfcSchema::Type::IfcConversionBasedUnit, @@ -177,13 +179,14 @@ int main(int argc, char** argv) { IfcSchema::Type::IfcBuildingStorey }; + // Open the set of input files std::vector files; - for (int i = 1; i < argc; ++i) { files.push_back(new IfcParse::IfcFile()); files.back()->Init(argv[i]); } + // Detect shared instances std::set shared_instances; for (auto& ty : shared) { @@ -206,6 +209,7 @@ int main(int argc, char** argv) { } } + // Follow forward references for shared instances std::set shared_instances_and_refs; for (auto& inst : shared_instances) { @@ -224,6 +228,7 @@ int main(int argc, char** argv) { time(&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::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); @@ -253,6 +258,7 @@ int main(int argc, char** argv) { shared_instances_and_refs.clear(); 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) { const IfcParse::entity* e = inst->declaration().as_entity(); 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 shared_instances_and_refs_unique(shared_instances_and_refs.begin(), shared_instances_and_refs.end()); - + // Serialize models into different groups + IfcParse::Hdf5Settings settings; settings.profile() = IfcParse::Hdf5Settings::standard_referenced; + settings.compress() = true; + settings.chunk_size() = 1024; std::vector names; std::vector> fixes; diff --git a/src/hdf5_usecases/lod.cpp b/src/hdf5_usecases/lod.cpp index 26fcb6fcd01..d976b365427 100644 --- a/src/hdf5_usecases/lod.cpp +++ b/src/hdf5_usecases/lod.cpp @@ -93,6 +93,7 @@ void generate_bounding_boxes(IfcParse::IfcFile& f, const std::string& fn) { 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) { 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(); }); + // Initial choice of geometric types std::set geometric_types{ IfcSchema::Type::IfcStyledItem, IfcSchema::Type::IfcMaterialDefinitionRepresentation, IfcSchema::Type::IfcStyledRepresentation, 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 other_types; + // Find all instances std::set geometric_instances; 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 refs = f.traverse(def); 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); + // Include connection geometry (e.g space boundaries) as well auto connection_geom = f.entitiesByType(); 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); + // Traverse again all instances, but now to detect which geometric types are fully and only shared by geometric instances std::function fn; fn = [&f, &geometric_instances, &other_types, &fn](IfcUtil::IfcBaseClass* root, IfcUtil::IfcBaseClass* inst) { 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; str.write((char*)&name, sizeof(size_t)); } - - std::cin.get(); } int main(int argc, char** argv) { @@ -341,6 +345,7 @@ int main(int argc, char** argv) { auto id = f.FreshId(); 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); 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_prop_defs.begin(), old_prop_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; settings.profile() = IfcParse::Hdf5Settings::padded; settings.compress() = true; - settings.chunk_size() = 256; + settings.chunk_size() = 1024; H5::H5File hdf(argv[1] + std::string(".hdf"), H5F_ACC_TRUNC); H5::H5File geom_hdf(argv[1] + std::string("-geometry.hdf"), H5F_ACC_TRUNC); diff --git a/src/hdf5_usecases/multifile_instance_locator.h b/src/hdf5_usecases/multifile_instance_locator.h index 27f41e42931..20b06596a2f 100644 --- a/src/hdf5_usecases/multifile_instance_locator.h +++ b/src/hdf5_usecases/multifile_instance_locator.h @@ -196,7 +196,7 @@ space.selectElements(H5S_SELECT_SET, 1, &coord); 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); ptr = static_cast(ptr) + sizeof(hdset_reg_ref_t); diff --git a/src/ifcparse/IfcHdf5File.cpp b/src/ifcparse/IfcHdf5File.cpp index e7c38699db8..51c69d2ef42 100644 --- a/src/ifcparse/IfcHdf5File.cpp +++ b/src/ifcparse/IfcHdf5File.cpp @@ -10,6 +10,8 @@ #pragma message("warning: HDF5 compression support is recommended") #endif +#define RENUMBER_INSTANCES + // Some string definitions used throughout this code namespace { const char* const select_bitmap = "select_bitmap"; @@ -2045,8 +2047,8 @@ class instance_resolver { } #ifdef RENUMBER_INSTANCES - std::string path = dataset_names_[pair[0]]; - return instance_name(path, pair[1]); + std::string path_ = dataset_names_[pair[0]]; + return instance_name(path_, pair[1]); #endif auto ppair = std::make_pair(pair[0], pair[1]);