| 469 | } |
| 470 | |
| 471 | H5::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 | |
| 524 | H5::Group HdfSerializer::createRepresentationGroup(const H5::Group& element_group, const std::string& gid) { |
| 525 | // the part before the hyphen is the representation id |