13 paraviewo::VTUWriter file;
14 MeshAttributes points, fields;
20 void add_field(
const std::string& name,
const Eigen::MatrixXd& data)
23 points[name].values = DataMatrix<double>(data);
25 file.add_field(name, data);
27 void add_integer_field(
const std::string& name,
const DataMatrix<int64_t>& values)
30 points[name].values = values;
33 field.values = values;
34 file.add_field(name, field.doubles());
37 void add_cell_field(
const std::string& name,
const Eigen::MatrixXd& data)
40 fields[name].values = DataMatrix<double>(data);
42 file.add_cell_field(name, data);
44 void add_integer_cell_field(
const std::string& name,
const DataMatrix<int64_t>& values)
47 fields[name].values = values;
50 field.values = values;
51 file.add_cell_field(name, field.doubles());
56 void add_cell_field(
const std::string& name,
const MeshAttribute& field)
61 file.add_cell_field(name, field.doubles());
64 const std::string& path,
65 const Eigen::MatrixXd& V,
66 const Eigen::MatrixXi& C,
67 paraviewo::CellType type)
69 if (!output)
return file.write_mesh(path, V, C, type);
70 std::vector<paraviewo::CellElement> cells(C.rows());
71 for (Eigen::Index i = 0; i < C.rows(); ++i) {
72 cells[i].ctype = type;
73 for (Eigen::Index j = 0; j < C.cols(); ++j) cells[i].vertices.push_back(C(i, j));
75 return write_mesh(path, V, cells);
78 const std::string& path,
79 const Eigen::MatrixXd& V,
80 const std::vector<paraviewo::CellElement>& cells)
82 if (!output)
return file.write_mesh(path, V, cells);
84 data.V = DataMatrix<double>::Zero(V.rows(), 3);
85 data.V.leftCols(V.cols()) = V;
86 data.vertex_attributes = points;
87 std::map<CellType, std::vector<size_t>> rows;
88 for (
size_t i = 0; i < cells.size(); ++i) {
89 const auto& c = cells[i];
90 const auto type =
static_cast<CellType
>(
91 paraviewo::paraview_tags::VTKTag(
int(c.vertices.size()), c.ctype));
92 auto& block = data.cells[type].connectivity;
93 block.conservativeResize(block.rows() + 1, cell_size(type));
94 for (
size_t j = 0; j < c.vertices.size(); ++j)
95 block(block.rows() - 1, j) = c.vertices[j];
96 rows[type].push_back(i);
99 for (
const auto& [type, indices] : rows)
100 for (
const auto& [name, a] : fields) {
102 field.labels = a.labels;
103 field.values = std::visit(
104 [&indices](
const auto& values) -> AttributeValues {
105 std::decay_t<
decltype(values)> sub(indices.size(), values.cols());
106 for (
size_t r = 0; r < indices.size(); ++r)
107 sub.row(r) = values.row(indices[r]);
113 output->insert_or_assign(path, std::move(data));