-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
144 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
|
||
set(SRC_FILES | ||
HDF5Reader.hpp | ||
HDF5Reader.cpp | ||
HDF5Writer.hpp | ||
HDF5Writer.cpp | ||
MeshWriter.hpp | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#include "HDF5Reader.hpp" | ||
|
||
#include <wmtk/Mesh.hpp> | ||
#include <wmtk/utils/Logger.hpp> | ||
#include <wmtk/utils/Rational.hpp> | ||
|
||
#include <h5pp/h5pp.h> | ||
|
||
#include <regex> | ||
|
||
|
||
namespace wmtk { | ||
HDF5Reader::HDF5Reader() {} | ||
|
||
|
||
void HDF5Reader::read_aux(const std::filesystem::path& filename, Mesh& mesh) | ||
{ | ||
h5pp::File m_hdf5_file(filename, h5pp::FileAccess::READONLY); | ||
|
||
std::vector<long> capacities = | ||
m_hdf5_file.readAttribute<std::vector<long>>("WMTK", "capacities"); | ||
|
||
mesh.set_capacities(capacities); | ||
|
||
const auto dsets = m_hdf5_file.findDatasets("", "WMTK"); | ||
for (auto& s : dsets) { | ||
const std::string dataset = "WMTK/" + s; | ||
const long stride = m_hdf5_file.readAttribute<long>(dataset, "stride"); | ||
const long dimension = m_hdf5_file.readAttribute<long>(dataset, "dimension"); | ||
const std::string type = m_hdf5_file.readAttribute<std::string>(dataset, "type"); | ||
const std::string name = | ||
std::regex_replace(s, std::regex(std::to_string(dimension) + "/"), ""); | ||
|
||
auto pt = PrimitiveType(dimension); | ||
|
||
if (type == "long") { | ||
auto v = m_hdf5_file.readDataset<std::vector<long>>(dataset); | ||
set_attribute<long>(name, pt, stride, v, mesh); | ||
} else if (type == "char") { | ||
auto tmp = m_hdf5_file.readDataset<std::vector<short>>(dataset); | ||
std::vector<char> v; | ||
v.reserve(tmp.size()); | ||
for (auto val : tmp) v.push_back(char(val)); | ||
|
||
set_attribute<char>(name, pt, stride, v, mesh); | ||
} else if (type == "double") { | ||
auto v = m_hdf5_file.readDataset<std::vector<double>>(dataset); | ||
|
||
set_attribute<double>(name, pt, stride, v, mesh); | ||
} else if (type == "rational") { | ||
logger().error("We currently do not support reading rationals"); | ||
assert(false); // | ||
auto tmp = m_hdf5_file.readDataset<std::vector<std::array<std::string, 2>>>(dataset); | ||
|
||
std::vector<Rational> v; | ||
v.reserve(tmp.size()); | ||
for (auto val : tmp) v.emplace_back(val[0], val[1]); | ||
|
||
// set_attribute<Rational>(name, pt, stride, v, mesh); | ||
|
||
} else { | ||
logger().error("We currently do not support reading the type \"{}\"", type); | ||
assert(false); | ||
} | ||
} | ||
} | ||
|
||
template <typename T> | ||
void HDF5Reader::set_attribute( | ||
const std::string& name, | ||
PrimitiveType pt, | ||
long stride, | ||
const std::vector<T>& v, | ||
Mesh& mesh) | ||
{ | ||
auto handle = mesh.register_attribute<T>(name, pt, stride, true); | ||
auto accessor = attribute::AccessorBase<T>(mesh, handle); | ||
|
||
accessor.set_attribute(v); | ||
} | ||
|
||
|
||
} // namespace wmtk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
#include "MeshReader.hpp" | ||
|
||
#include <wmtk/Primitive.hpp> | ||
|
||
#include <filesystem> | ||
#include <vector> | ||
|
||
namespace wmtk { | ||
|
||
class Mesh; | ||
|
||
class HDF5Reader : public MeshReader | ||
{ | ||
public: | ||
HDF5Reader(); | ||
|
||
protected: | ||
void read_aux(const std::filesystem::path& filename, Mesh& mesh) override; | ||
|
||
private: | ||
template <typename T> | ||
void set_attribute( | ||
const std::string& name, | ||
PrimitiveType pt, | ||
long stride, | ||
const std::vector<T>& v, | ||
Mesh& mesh); | ||
}; | ||
} // namespace wmtk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,25 @@ | ||
#include "MeshReader.hpp" | ||
|
||
#include <wmtk/Mesh.hpp> | ||
#include <wmtk/utils/Logger.hpp> | ||
#include <wmtk/utils/Rational.hpp> | ||
|
||
#include <h5pp/h5pp.h> | ||
|
||
#include <regex> | ||
#include "HDF5Reader.hpp" | ||
|
||
#include <memory> | ||
|
||
namespace wmtk { | ||
MeshReader::MeshReader(const std::filesystem::path& filename) | ||
: m_filename(filename) | ||
{} | ||
|
||
|
||
void MeshReader::read(Mesh& mesh) | ||
void MeshReader::read(const std::filesystem::path& filename, Mesh& mesh) | ||
{ | ||
h5pp::File m_hdf5_file(m_filename, h5pp::FileAccess::READONLY); | ||
|
||
std::vector<long> capacities = | ||
m_hdf5_file.readAttribute<std::vector<long>>("WMTK", "capacities"); | ||
|
||
mesh.set_capacities(capacities); | ||
|
||
const auto dsets = m_hdf5_file.findDatasets("", "WMTK"); | ||
for (auto& s : dsets) { | ||
const std::string dataset = "WMTK/" + s; | ||
const long stride = m_hdf5_file.readAttribute<long>(dataset, "stride"); | ||
const long dimension = m_hdf5_file.readAttribute<long>(dataset, "dimension"); | ||
const std::string type = m_hdf5_file.readAttribute<std::string>(dataset, "type"); | ||
const std::string name = | ||
std::regex_replace(s, std::regex(std::to_string(dimension) + "/"), ""); | ||
|
||
auto pt = PrimitiveType(dimension); | ||
|
||
if (type == "long") { | ||
auto v = m_hdf5_file.readDataset<std::vector<long>>(dataset); | ||
set_attribute<long>(name, pt, stride, v, mesh); | ||
} else if (type == "char") { | ||
auto tmp = m_hdf5_file.readDataset<std::vector<short>>(dataset); | ||
std::vector<char> v; | ||
v.reserve(tmp.size()); | ||
for (auto val : tmp) v.push_back(char(val)); | ||
|
||
set_attribute<char>(name, pt, stride, v, mesh); | ||
} else if (type == "double") { | ||
auto v = m_hdf5_file.readDataset<std::vector<double>>(dataset); | ||
|
||
set_attribute<double>(name, pt, stride, v, mesh); | ||
} else if (type == "rational") { | ||
logger().error("We currently do not support reading rationals"); | ||
assert(false); // | ||
auto tmp = m_hdf5_file.readDataset<std::vector<std::array<std::string, 2>>>(dataset); | ||
|
||
std::vector<Rational> v; | ||
v.reserve(tmp.size()); | ||
for (auto val : tmp) v.emplace_back(val[0], val[1]); | ||
|
||
// set_attribute<Rational>(name, pt, stride, v, mesh); | ||
|
||
} else { | ||
logger().error("We currently do not support reading the type \"{}\"", type); | ||
assert(false); | ||
} | ||
std::unique_ptr<MeshReader> reader = nullptr; | ||
const auto extension = filename.extension().string(); | ||
if (extension == ".hdf5") { | ||
reader = std::make_unique<HDF5Reader>(); | ||
} | ||
} | ||
|
||
template <typename T> | ||
void MeshReader::set_attribute( | ||
const std::string& name, | ||
PrimitiveType pt, | ||
long stride, | ||
const std::vector<T>& v, | ||
Mesh& mesh) | ||
{ | ||
auto handle = mesh.register_attribute<T>(name, pt, stride, true); | ||
auto accessor = attribute::AccessorBase<T>(mesh, handle); | ||
|
||
accessor.set_attribute(v); | ||
if (!reader) | ||
throw std::runtime_error(extension + " not supported"); | ||
else | ||
reader->read_aux(filename, mesh); | ||
} | ||
|
||
|
||
} // namespace wmtk | ||
} // namespace wmtk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters