From 12983ea4fe0a88c1b72dd3852c7b541d6f78e55e Mon Sep 17 00:00:00 2001 From: johltn Date: Thu, 18 Feb 2021 10:35:51 +0100 Subject: [PATCH] Move HDF compound type definitions to constructor --- src/serializers/HdfSerializer.cpp | 117 ++++++++++++++---------------- src/serializers/HdfSerializer.h | 6 ++ 2 files changed, 60 insertions(+), 63 deletions(-) diff --git a/src/serializers/HdfSerializer.cpp b/src/serializers/HdfSerializer.cpp index 9db71fcad2..d5d0c8a70d 100644 --- a/src/serializers/HdfSerializer.cpp +++ b/src/serializers/HdfSerializer.cpp @@ -20,8 +20,6 @@ #include "HdfSerializer.h" - - #include "../ifcgeom_schema_agnostic/IfcGeomRenderStyles.h" #include "../ifcparse/utils.h" @@ -30,15 +28,55 @@ #include +typedef struct s1_t { + int a, b, c; +} s1_t; + + +typedef struct s2_t { + double a, b, c; +} s2_t; HdfSerializer::HdfSerializer(const std::string& obj_filename, const std::string& mtl_filename, const SerializerSettings& settings) : GeometrySerializer(settings) , mtl_filename(obj_filename) + , DATASET_NAME_POSITIONS("Positions") + , DATASET_NAME_NORMALS("Normals") + , DATASET_NAME_INDICES("Indices") + , mtype1(sizeof(s1_t)) + , mtype2(sizeof(s2_t)) + , mtype3(sizeof(s1_t)) { - guids = {}; + + H5::IntType Intdatatype(H5::PredType::NATIVE_INT); + H5::FloatType datatype(H5::PredType::NATIVE_DOUBLE); + datatype.setOrder(H5T_ORDER_LE); + Intdatatype.setOrder(H5T_ORDER_LE); + + const H5std_string MEMBER1("V1"); + const H5std_string MEMBER2("V2"); + const H5std_string MEMBER3("V3"); + mtype1.insertMember(MEMBER1, HOFFSET(s1_t, a), H5::PredType::NATIVE_INT); + mtype1.insertMember(MEMBER2, HOFFSET(s1_t, c), H5::PredType::NATIVE_INT); + mtype1.insertMember(MEMBER3, HOFFSET(s1_t, b), H5::PredType::NATIVE_INT); + + const H5std_string POS1("X"); + const H5std_string POS2("Y"); + const H5std_string POS3("Z"); + mtype2.insertMember(POS1, HOFFSET(s2_t, a), datatype); + mtype2.insertMember(POS2, HOFFSET(s2_t, b), datatype); + mtype2.insertMember(POS3, HOFFSET(s2_t, c), datatype); + + const H5std_string NOR1("X"); + const H5std_string NOR2("Y"); + const H5std_string NOR3("Z"); + mtype3.insertMember(NOR1, HOFFSET(s1_t, a), Intdatatype); + mtype3.insertMember(NOR2, HOFFSET(s1_t, b), Intdatatype); + mtype3.insertMember(NOR3, HOFFSET(s1_t, c), Intdatatype); + } @@ -81,10 +119,6 @@ void HdfSerializer::write(const IfcGeom::TriangulationElement* o) { elementGroup = file.createGroup(guid); meshGroup = elementGroup.createGroup("Triangle Mesh"); - H5std_string DATASET_NAME_POSITIONS("Positions"); - H5std_string DATASET_NAME_NORMALS("Normals"); - H5std_string DATASET_NAME_INDICES("Indices"); - const int RANK = 2; hsize_t dimsf[2]; dimsf[0] = vcount; @@ -96,65 +130,24 @@ void HdfSerializer::write(const IfcGeom::TriangulationElement* o) { dimsfaces[1] = 1; H5::DataSpace face_dataspace(RANK, dimsfaces); - H5::IntType Intdatatype(H5::PredType::NATIVE_INT); - H5::FloatType datatype(H5::PredType::NATIVE_DOUBLE); - datatype.setOrder(H5T_ORDER_LE); - typedef struct s1_t { - int a, b, c; - } s1_t; - - - typedef struct s2_t { - double a, b, c; - } s2_t; - - - const H5std_string MEMBER1("V1"); - const H5std_string MEMBER2("V2"); - const H5std_string MEMBER3("V3"); - H5::CompType mtype1(sizeof(s1_t)); - mtype1.insertMember(MEMBER1, HOFFSET(s1_t, a), H5::PredType::NATIVE_INT); - mtype1.insertMember(MEMBER2, HOFFSET(s1_t, c), H5::PredType::NATIVE_INT); - mtype1.insertMember(MEMBER3, HOFFSET(s1_t, b), H5::PredType::NATIVE_INT); indicesDataset = meshGroup.createDataSet(DATASET_NAME_INDICES, mtype1, face_dataspace); - - const H5std_string POS1("X"); - const H5std_string POS2("Y"); - const H5std_string POS3("Z"); - H5::CompType mtype2(sizeof(s2_t)); - mtype2.insertMember(POS1, HOFFSET(s2_t, a), datatype); - mtype2.insertMember(POS2, HOFFSET(s2_t, b), datatype); - mtype2.insertMember(POS3, HOFFSET(s2_t, c), datatype); positionsDataset = meshGroup.createDataSet(DATASET_NAME_POSITIONS, mtype2, dataspace); - - - const H5std_string NOR1("X"); - const H5std_string NOR2("Y"); - const H5std_string NOR3("Z"); - H5::CompType mtype3(sizeof(s1_t)); - mtype3.insertMember(NOR1, HOFFSET(s1_t, a), Intdatatype); - mtype3.insertMember(NOR2, HOFFSET(s1_t, b), Intdatatype); - mtype3.insertMember(NOR3, HOFFSET(s1_t, c), Intdatatype); normalsDataset = meshGroup.createDataSet(DATASET_NAME_NORMALS, mtype3, dataspace); - - - for (std::vector::const_iterator it = mesh.faces().begin(); it != mesh.faces().end(); ) { + for (std::vector::const_iterator it = mesh.verts().begin(); it != mesh.verts().end(); ) { const real_t x = *(it++); const real_t y = *(it++); const real_t z = *(it++); - int_data_container.push_back(x); - int_data_container.push_back(y); - int_data_container.push_back(z); + double_data_container.push_back(x); + double_data_container.push_back(y); + double_data_container.push_back(z); } + positionsDataset.write(double_data_container.data(), mtype2); + double_data_container.clear(); - indicesDataset.write(int_data_container.data(), mtype1); - - int_data_container.clear(); - for (std::vector::const_iterator it = mesh.normals().begin(); it != mesh.normals().end(); ) { const real_t x = *(it++); const real_t y = *(it++); @@ -168,21 +161,19 @@ void HdfSerializer::write(const IfcGeom::TriangulationElement* o) { int_data_container.clear(); - - for (std::vector::const_iterator it = mesh.verts().begin(); it != mesh.verts().end(); ) { + for (std::vector::const_iterator it = mesh.faces().begin(); it != mesh.faces().end(); ) { const real_t x = *(it++); const real_t y = *(it++); const real_t z = *(it++); - double_data_container.push_back(x); - double_data_container.push_back(y); - double_data_container.push_back(z); + int_data_container.push_back(x); + int_data_container.push_back(y); + int_data_container.push_back(z); } - - positionsDataset.write(double_data_container.data(), mtype2); - double_data_container.clear(); - + indicesDataset.write(int_data_container.data(), mtype1); + int_data_container.clear(); + } } diff --git a/src/serializers/HdfSerializer.h b/src/serializers/HdfSerializer.h index 62c8b887a8..0333a2ef0d 100644 --- a/src/serializers/HdfSerializer.h +++ b/src/serializers/HdfSerializer.h @@ -40,6 +40,12 @@ private: std::set guids; std::vector double_data_container; std::vector int_data_container; + const H5std_string DATASET_NAME_POSITIONS; + const H5std_string DATASET_NAME_NORMALS; + const H5std_string DATASET_NAME_INDICES; + H5::CompType mtype1; + H5::CompType mtype2; + H5::CompType mtype3; public: