Use compound types for the 3 datasets

This commit is contained in:
johltn
2021-02-17 10:38:27 +01:00
parent ba5751e535
commit b69b2fb960
+65 -33
View File
@@ -116,17 +116,12 @@ void HdfSerializer::write(const IfcGeom::TriangulationElement<real_t>* o){
const int fcount = (int)mesh.faces().size() / 3;
if (guid == "2OBrcmyk58NupXoVOHUvr4") {
Logger::Status("Found");
}
if (std::find(guids.begin(), guids.end(), guid) != guids.end())
{
elementGroup = file.openGroup(guid);
meshGroup = elementGroup.openGroup("Triangle Mesh");
positionsDataset = meshGroup.openDataSet("Positions");
} else {
guids.insert(guid);
@@ -140,48 +135,55 @@ void HdfSerializer::write(const IfcGeom::TriangulationElement<real_t>* o){
const int RANK = 2;
hsize_t dimsf[2];
dimsf[0] = vcount;
dimsf[1] = 3;
dimsf[1] = 1;
H5::DataSpace dataspace(RANK, dimsf);
hsize_t dimsfaces[2];
dimsfaces[0] = fcount;
dimsfaces[1] = 3;
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);
positionsDataset = meshGroup.createDataSet(DATASET_NAME_POSITIONS, datatype, dataspace);
normalsDataset = meshGroup.createDataSet(DATASET_NAME_NORMALS, Intdatatype, dataspace);
indicesDataset = meshGroup.createDataSet(DATASET_NAME_INDICES, Intdatatype, face_dataspace);
typedef struct s1_t {
int a, b, c;
} s1_t;
for (std::vector<real_t>::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++);
double_data_container.push_back(x);
double_data_container.push_back(y);
double_data_container.push_back(z);
}
positionsDataset.write(double_data_container.data(), H5::PredType::NATIVE_DOUBLE);
double_data_container.clear();
typedef struct s2_t {
double a, b, c;
} s2_t;
for (std::vector<real_t>::const_iterator it = mesh.normals().begin(); it != mesh.normals().end(); ) {
const real_t x = *(it++);
const real_t y = *(it++);
const real_t z = *(it++);
int_data_container.push_back((int)x);
int_data_container.push_back((int)y);
int_data_container.push_back((int)z);
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);
}
normalsDataset.write(int_data_container.data(), H5::PredType::NATIVE_INT);
int_data_container.clear();
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);
@@ -195,9 +197,39 @@ void HdfSerializer::write(const IfcGeom::TriangulationElement<real_t>* o){
}
indicesDataset.write(int_data_container.data(), H5::PredType::NATIVE_INT);
indicesDataset.write(int_data_container.data(), mtype1);
int_data_container.clear();
for (std::vector<real_t>::const_iterator it = mesh.normals().begin(); it != mesh.normals().end(); ) {
const real_t x = *(it++);
const real_t y = *(it++);
const real_t z = *(it++);
int_data_container.push_back((int)x);
int_data_container.push_back((int)y);
int_data_container.push_back((int)z);
}
normalsDataset.write(int_data_container.data(), mtype3);
int_data_container.clear();
for (std::vector<real_t>::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++);
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();
}
}