Skip to content

Commit

Permalink
Renumber instances, add comments, update federate for group structure
Browse files Browse the repository at this point in the history
  • Loading branch information
aothms committed Feb 13, 2018
1 parent 6dd22fd commit 16f2b0a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 19 deletions.
25 changes: 12 additions & 13 deletions src/hdf5_usecases/federate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#pragma warning(disable:4100)

// A comparison operator that is used to isolate the shared hierarchy
class ifc_inst_cmp {
public:

Expand Down Expand Up @@ -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<IfcSchema::Type::Enum> shared {
IfcSchema::Type::IfcSite,
IfcSchema::Type::IfcConversionBasedUnit,
Expand All @@ -177,13 +179,14 @@ int main(int argc, char** argv) {
IfcSchema::Type::IfcBuildingStorey
};

// Open the set of input files
std::vector<IfcParse::IfcFile*> files;

for (int i = 1; i < argc; ++i) {
files.push_back(new IfcParse::IfcFile());
files.back()->Init(argv[i]);
}

// Detect shared instances
std::set<IfcUtil::IfcBaseClass*> shared_instances;

for (auto& ty : shared) {
Expand All @@ -206,6 +209,7 @@ int main(int argc, char** argv) {
}
}

// Follow forward references for shared instances
std::set<IfcUtil::IfcBaseClass*> shared_instances_and_refs;

for (auto& inst : shared_instances) {
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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());


// Serialize models into different groups

IfcParse::Hdf5Settings settings;
settings.profile() = IfcParse::Hdf5Settings::standard_referenced;
settings.compress() = true;
settings.chunk_size() = 1024;

std::vector<std::string> names;
std::vector<std::pair<std::string::const_iterator, std::string::const_iterator>> fixes;
Expand Down
13 changes: 10 additions & 3 deletions src/hdf5_usecases/lod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -138,13 +139,15 @@ 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<IfcSchema::Type::Enum> geometric_types{
IfcSchema::Type::IfcStyledItem, IfcSchema::Type::IfcMaterialDefinitionRepresentation, IfcSchema::Type::IfcStyledRepresentation,
IfcSchema::Type::IfcSurfaceStyleRendering, IfcSchema::Type::IfcSurfaceStyle, IfcSchema::Type::IfcPresentationLayerAssignment,
IfcSchema::Type::IfcPresentationStyleAssignment, IfcSchema::Type::IfcColourRgb
};
std::set<IfcSchema::Type::Enum> other_types;

// Find all instances
std::set<IfcUtil::IfcBaseClass*> geometric_instances;

for (auto ty : geometric_types) {
Expand All @@ -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());
Expand All @@ -188,13 +192,15 @@ 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<IfcSchema::IfcConnectionGeometry>();

n = 0;
N = connection_geom->size();

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;
fn = [&f, &geometric_instances, &other_types, &fn](IfcUtil::IfcBaseClass* root, IfcUtil::IfcBaseClass* inst) {
if (geometric_instances.find(inst) == geometric_instances.end()) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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());
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/hdf5_usecases/multifile_instance_locator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t*>(ptr) + sizeof(hdset_reg_ref_t);
Expand Down
6 changes: 4 additions & 2 deletions src/ifcparse/IfcHdf5File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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]);
Expand Down

0 comments on commit 16f2b0a

Please sign in to comment.