MCPcopy Create free account
hub / github.com/IfcOpenShell/IfcOpenShell / write

Method write

src/serializers/HdfSerializer.cpp:471–522  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

469}
470
471H5::Group HdfSerializer::write(const IfcGeom::Element* o) {
472 try {
473 return file.openGroup(o->guid());
474 } catch (H5::Exception&) {}
475
476 H5::Group element_group = file.createGroup(o->guid());
477
478 typedef std::string const & (IfcGeom::Element::*string_member_fun)(void) const;
479 typedef int (IfcGeom::Element::*int_member_fun)(void) const;
480
481 static const std::vector<std::pair<const char* const, string_member_fun>> data_pairs_string = {
482 {"type", &IfcGeom::Element::type},
483 {"name", &IfcGeom::Element::name },
484 {"guid", &IfcGeom::Element::guid },
485 {"context", &IfcGeom::Element::context },
486 {"unique_id", &IfcGeom::Element::unique_id }
487 };
488
489 static const std::vector<std::pair<const char* const, int_member_fun>> data_pairs_int = {
490 {"id", &IfcGeom::Element::id},
491 {"parent_id", &IfcGeom::Element::parent_id },
492 };
493
494 H5::DataSpace attrdspace(H5S_SCALAR);
495
496 for (auto& p : data_pairs_string) {
497 H5::Attribute att = element_group.createAttribute(p.first, str_type, attrdspace);
498 att.write(str_type, ((*o).*(p.second))());
499 }
500
501 for (auto& p : data_pairs_int) {
502 H5::Attribute att = element_group.createAttribute(p.first, H5::PredType::NATIVE_INT, attrdspace);
503 int value = ((*o).*(p.second))();
504 att.write(H5::PredType::NATIVE_INT, &value);
505 }
506
507 hsize_t dims_4x4[2]{ 4, 4 };
508 H5::DataSpace dataspace_4x4(2, dims_4x4);
509
510 auto placement_dataset = element_group.createDataSet(DATASET_NAME_PLACEMENT, H5::PredType::NATIVE_DOUBLE, dataspace_4x4);
511 const auto& m = o->transformation().data()->ccomponents();
512 // @todo check, is this needed, can we use the storage of Eigen?
513 double m44[4][4] = {
514 { m(0,0), m(1,0), m(2,0), m(3,0) },
515 { m(0,1), m(1,1), m(2,1), m(3,1) },
516 { m(0,2), m(1,2), m(2,2), m(3,2) },
517 { m(0,3), m(1,3), m(2,3), m(3,3) }
518 };
519 placement_dataset.write(m44, H5::PredType::NATIVE_DOUBLE);
520
521 return element_group;
522}
523
524H5::Group HdfSerializer::createRepresentationGroup(const H5::Group& element_group, const std::string& gid) {
525 // the part before the hyphen is the representation id

Callers 3

write_datasetFunction · 0.45
serializeFunction · 0.45

Calls 12

copyFunction · 0.85
write_datasetFunction · 0.85
dataMethod · 0.80
reserveMethod · 0.80
writeFunction · 0.70
guidMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
idMethod · 0.45
sizeMethod · 0.45
edgesMethod · 0.45
materialsMethod · 0.45

Tested by

no test coverage detected