12#ifndef EXAMPLES_WRITEVTK_HPP_
13#define EXAMPLES_WRITEVTK_HPP_
25template <
typename Derived1,
typename Derived2,
typename Derived3>
26void writeMesh2vtk(
const std::string &fileName,
27 const Eigen::MatrixBase<Derived1> &P,
28 const Eigen::MatrixBase<Derived2> &E,
29 const Eigen::MatrixBase<Derived3> &Cdata,
30 bool isCellData =
false) {
32 myfile.open(fileName);
33 myfile <<
"# vtk DataFile Version 3.1\n";
34 myfile <<
"this file hopefully represents my surface now\n";
36 myfile <<
"DATASET UNSTRUCTURED_GRID\n";
38 myfile <<
"POINTS " << P.cols() <<
" FLOAT\n";
39 for (
auto i = 0; i < P.cols(); ++i)
40 myfile <<
float(P(0, i)) <<
" " << float(P(1, i)) <<
" " << float(P(2, i))
45 myfile <<
"CELLS " << E.cols() <<
" " << 5 * E.cols() <<
"\n";
46 for (
auto i = 0; i < E.cols(); ++i)
47 myfile <<
int(4) <<
" " << int(E(0, i)) <<
" " << int(E(1, i)) <<
" "
48 << int(E(2, i)) <<
" " << int(E(3, i)) <<
"\n";
51 myfile <<
"CELL_TYPES " << E.cols() <<
"\n";
52 for (
auto i = 0; i < E.cols(); ++i) myfile <<
int(9) <<
"\n";
56 myfile <<
"CELL_DATA " << E.cols() <<
"\n";
57 myfile <<
"SCALARS value FLOAT\n";
58 myfile <<
"LOOKUP_TABLE default\n";
59 for (
auto i = 0; i < E.cols(); ++i) myfile <<
float(Cdata(i)) <<
"\n";
62 myfile <<
"POINT_DATA " << P.cols() <<
"\n";
63 myfile <<
"SCALARS value FLOAT\n";
64 myfile <<
"LOOKUP_TABLE default\n";
65 for (
auto i = 0; i < P.cols(); ++i) myfile <<
float(Cdata(i)) <<
"\n";