Skip to content

Commit 4a3b6f3

Browse files
Create vtk_save.h
1 parent 43f9eb9 commit 4a3b6f3

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

src/io/vtk_save.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#pragma once
2+
#include <vector>
3+
#include <string>
4+
#include <fstream>
5+
#include "../struct/particle.h"
6+
7+
inline void SaveVTK(const std::vector<Particle>& p, const std::string& filename)
8+
{
9+
std::ofstream out(filename);
10+
if (!out) return;
11+
12+
const size_t N = p.size();
13+
out << "# vtk DataFile Version 3.0\n";
14+
out << "NEXT snapshot\n";
15+
out << "ASCII\n";
16+
out << "DATASET POLYDATA\n";
17+
18+
// draw points
19+
out << "POINTS " << N << " float\n";
20+
for (const auto& a : p)
21+
out << a.x << " " << a.y << " " << a.z << "\n";
22+
23+
// draw vertices
24+
out << "VERTICES " << N << " " << N*2 << "\n";
25+
for (size_t i = 0; i < N; i++)
26+
out << "1 " << i << "\n";
27+
28+
// that too
29+
out << "POINT_DATA " << N << "\n";
30+
out << "VECTORS velocity float\n";
31+
for (const auto& a : p)
32+
out << a.vx << " " << a.vy << " " << a.vz << "\n";
33+
34+
out << "SCALARS mass float 1\n";
35+
out << "LOOKUP_TABLE default\n";
36+
for (const auto& a : p)
37+
out << a.m << "\n";
38+
}

0 commit comments

Comments
 (0)