Skip to content

Commit

Permalink
Merge pull request #841 from wildmeshing/teseo/outv
Browse files Browse the repository at this point in the history
always export vertex attributes in paraview
  • Loading branch information
teseoch authored Nov 27, 2024
2 parents e1bdd48 + fb571b5 commit 574cfec
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 13 deletions.
49 changes: 37 additions & 12 deletions src/wmtk/io/ParaviewWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,49 @@ ParaviewWriter::ParaviewInternalWriter::~ParaviewInternalWriter()
void ParaviewWriter::ParaviewInternalWriter::write(
const std::string& name,
const int64_t stride,
const std::vector<double>& val)
const std::vector<double>& val,
const bool is_cell_field)
{
Eigen::MatrixXd tmp =
Eigen::Map<const Eigen::MatrixXd>(&val[0], stride, val.size() / stride).transpose();

if (stride == 1 || stride == 2 || stride == 3) {
m_paraview_file->add_cell_field(name, tmp);
if (is_cell_field) {
m_paraview_file->add_cell_field(name, tmp);
} else {
m_paraview_file->add_field(name, tmp);
}
} else if (stride % 3 == 0) {
for (int64_t i = 0; i < stride; i += 3) {
m_paraview_file->add_cell_field(
name + "_" + std::to_string(i / 3),
tmp.block(0, i, tmp.rows(), 3));
if (is_cell_field) {
m_paraview_file->add_cell_field(
name + "_" + std::to_string(i / 3),
tmp.block(0, i, tmp.rows(), 3));
} else {
m_paraview_file->add_field(
name + "_" + std::to_string(i / 3),
tmp.block(0, i, tmp.rows(), 3));
}
}
} else if (stride % 2 == 0) {
for (int64_t i = 0; i < stride; i += 2) {
m_paraview_file->add_cell_field(
name + "_" + std::to_string(i / 2),
tmp.block(0, i, tmp.rows(), 2));
if (is_cell_field) {
m_paraview_file->add_cell_field(
name + "_" + std::to_string(i / 2),
tmp.block(0, i, tmp.rows(), 2));
} else {
m_paraview_file->add_field(
name + "_" + std::to_string(i / 2),
tmp.block(0, i, tmp.rows(), 2));
}
}
} else {
for (int64_t i = 0; i < stride; ++i) {
m_paraview_file->add_cell_field(name + "_" + std::to_string(i), tmp.col(i));
if (is_cell_field) {
m_paraview_file->add_cell_field(name + "_" + std::to_string(i), tmp.col(i));
} else {
m_paraview_file->add_field(name + "_" + std::to_string(i), tmp.col(i));
}
}
}
}
Expand Down Expand Up @@ -198,9 +219,13 @@ void ParaviewWriter::write_internal(
for (int i = 0; i < m_writers.size(); ++i) {
if (m_enabled[i]) m_writers[i].vertices() = V;
}

} else if (m_enabled[type])
m_writers[type].write(name, stride, val);
} else if (m_enabled[type]) {
m_writers[type].write(name, stride, val, true);
} else if (type == 0) { // vertex attrs are always written
for (size_t i = 0; i < m_writers.size(); ++i) {
if (m_enabled[i]) m_writers[i].write(name, stride, val, false);
}
}
}


Expand Down
6 changes: 5 additions & 1 deletion src/wmtk/io/ParaviewWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ class ParaviewWriter : public MeshWriter
const Eigen::MatrixXi& elements,
const bool enabled);

void write(const std::string& name, const int64_t stride, const std::vector<double>& val);
void write(
const std::string& name,
const int64_t stride,
const std::vector<double>& val,
const bool is_cell_field);


Eigen::MatrixXd& vertices() { return m_vertices; }
Expand Down
10 changes: 10 additions & 0 deletions tests/io/test_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ TEST_CASE("paraview_2d", "[io]")
mesh->serialize(writer);
}

TEST_CASE("paraview_2d_vtag", "[io.]")
{
auto mesh = read_mesh(WMTK_DATA_DIR "/fan.msh");
mesh->register_attribute<int64_t>("tag", PrimitiveType::Triangle, 1);
mesh->register_attribute<int64_t>("tag1", PrimitiveType::Vertex, 1);

ParaviewWriter writer("paraview_2d_vtag", "vertices", *mesh, false, false, true, false);
mesh->serialize(writer);
}

TEST_CASE("hdf5_3d", "[io]")
{
Eigen::Matrix<int64_t, 2, 4> T;
Expand Down

0 comments on commit 574cfec

Please sign in to comment.