Skip to content

Commit

Permalink
Improve video writer
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiashienzsch committed Jul 11, 2024
1 parent 028ce5f commit e6dad76
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion run_2d.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ engine_exe="$root_dir/$build_dir/src/cpp/main_2d/pffdtd_2d"
sim_name="Diffusor"
sim_dir="$root_dir/data/sim_data/$sim_name/cpu"

fmax=1600
fmax=1000
duration=0.06

# Delete old sim
Expand Down
15 changes: 13 additions & 2 deletions src/cpp/main_2d/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
namespace pffdtd {

auto run(Simulation2D const& sim) -> std::vector<double> {
auto video = VideoWriter{"out.avi", 30.0, 1000, 1000};
auto videoFile = sim.file.parent_path() / "out.avi";
auto video = VideoWriter{videoFile, 30.0, 1000, 1000};

auto const Nx = sim.Nx;
auto const Ny = sim.Ny;
Expand Down Expand Up @@ -41,6 +42,8 @@ auto run(Simulation2D const& sim) -> std::vector<double> {
auto out_ixy_buf = sycl::buffer<int64_t, 1>{sim.out_ixy};
auto src_sig_buf = sycl::buffer<double, 1>{sim.src_sig};

auto frame = std::vector<double>(sim.Nx * sim.Ny);

fmt::print(stdout, "111111111");
for (auto i{0UL}; i < sim.Nt; ++i) {
fmt::print(stdout, "\r\r\r\r\r\r\r\r\r");
Expand Down Expand Up @@ -112,7 +115,15 @@ auto run(Simulation2D const& sim) -> std::vector<double> {
);
});

queue.wait_and_throw();
auto host = sycl::host_accessor{u0, sycl::read_only};
for (auto i{0UL}; i < frame.size(); ++i) {
frame[i] = std::abs(double(host.get_pointer()[i]));
// if (sim.in_mask[i] == 0) {
// frame[i] = 1.0;
// }
}

video.write(frame, Ny, Nx);
}

auto save = std::vector<double>(Nt * Nr);
Expand Down
2 changes: 2 additions & 0 deletions src/cpp/pffdtd/simulation_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace pffdtd {
auto loadSimulation2D(std::filesystem::path const& path) -> Simulation2D {
auto file = H5FReader{path.string().c_str()};
return Simulation2D{
.file = path,

.Nx = file.read<int64_t>("Nx"),
.Ny = file.read<int64_t>("Ny"),
.Nt = file.read<int64_t>("Nt"),
Expand Down
2 changes: 2 additions & 0 deletions src/cpp/pffdtd/simulation_2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
namespace pffdtd {

struct Simulation2D {
std::filesystem::path file;

int64_t Nx; // Number of x sample nodes
int64_t Ny; // Number of y sample nodes
int64_t Nt; // Number of time steps
Expand Down
7 changes: 5 additions & 2 deletions src/cpp/pffdtd/video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ auto VideoWriter::write(std::span<double> buf, size_t width, size_t height)
normalized.convertTo(normalized, CV_8U);

auto resized = cv::Mat{};
cv::resize(input, resized, _size);
cv::resize(normalized, resized, _size);

_writer.write(resized);
auto rotated = cv::Mat{};
cv::rotate(resized, rotated, cv::ROTATE_90_COUNTERCLOCKWISE);

_writer.write(rotated);
}

} // namespace pffdtd

0 comments on commit e6dad76

Please sign in to comment.