3#include <boost/multi_array.hpp>
4#include <boost/array.hpp>
7#include "CustomLibraries/np.hpp"
8#include "CustomLibraries/np_to_matplot.hpp"
25 Plotter(
const boost::multi_array<double, 3> &u,
const matplot::vector_2d &Xp,
const matplot::vector_2d &Zp,
int num_levels,
int nt)
27 this->u.resize(boost::extents[u.shape()[0]][u.shape()[1]][u.shape()[2]]);
31 this->num_levels = num_levels;
35 std::cout <<
"min_u = " << min_u <<
" max_u = " << max_u <<
"\n";
36 this->levels = matplot::linspace(min_u, max_u, num_levels);
42 matplot::contourf(this->Xp, this->Zp, Up, this->levels);
43 matplot::save(save_directory +
"/contourf_" + format_num(index) +
".png");
49 for (
int i = begin_frame_index; i < end_frame_index; i++)
56 void animate(std::string output_file_name,
int begin_frame_index,
int end_frame_index,
int frame_rate)
59 std::string ffmpeg_render_command =
"ffmpeg -framerate " + std::to_string(frame_rate) +
" -pattern_type glob -i '" + save_directory +
"/*.png' -c:v libx264 -pix_fmt yuv420p " + output_file_name;
60 std::system(ffmpeg_render_command.c_str());
66 std::ofstream outfile;
67 outfile.open(save_directory +
"/frame_" + format_num(index) +
".csv");
68 for (std::size_t i = 0; i < Up.size(); i++)
70 for (std::size_t j = 0; j < Up[i].size(); j++)
73 if (j != Up[i].size() - 1)
84 for (
int i = begin_frame_index; i < end_frame_index; i++)
93 this->save_directory = save_directory;
97 std::string format_num(
int num,
int length = 8)
99 std::string str_num = std::to_string(num);
101 int str_length = str_num.length();
102 for (
int i = 0; i < length - str_length; i++)
103 str_num =
"0" + str_num;
107 boost::multi_array<double, 3> u;
108 matplot::vector_2d Xp;
109 matplot::vector_2d Zp;
112 std::vector<double> levels;
113 std::string save_directory =
"output";
This class is used to plot the wave field TODO: make it multithreaded.
matplot::vector_2d convert_to_matplot(const boost::multi_array< double, 2 > &arr)
Convert a 2D boost::multi_array to a matplot::vector_2d.
void setSaveDirectory(std::string save_directory)
Set the save directory for the rendered frames.
void animate(std::string output_file_name, int begin_frame_index, int end_frame_index, int frame_rate)
Renders a complete video animation of the wave field.
void renderAllFrames(int begin_frame_index, int end_frame_index)
Renders all frames of the wave field to form an animation to be saved on disk.
void exportAllFrames(int begin_frame_index, int end_frame_index)
Export all frames of the wave field to a .csv format for external use.
Plotter(const boost::multi_array< double, 3 > &u, const matplot::vector_2d &Xp, const matplot::vector_2d &Zp, int num_levels, int nt)
Constructor.
void exportFrame(int index)
Export a frame of the wave field to a .csv format for external use.
void renderFrame(int index)
Renders a frame of the wave field to a image on disk.
::value constexpr T min(boost::multi_array< T, ND > const &input_array)
Implements the numpy min function for an n-dimensionl multi array.
::value constexpr T max(boost::multi_array< T, ND > const &input_array)
Implements the numpy max function for an n-dimensionl multi array.