Skip to content

Commit e6dad76

Browse files
Improve video writer
1 parent 028ce5f commit e6dad76

File tree

5 files changed

+23
-5
lines changed

5 files changed

+23
-5
lines changed

run_2d.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ engine_exe="$root_dir/$build_dir/src/cpp/main_2d/pffdtd_2d"
1010
sim_name="Diffusor"
1111
sim_dir="$root_dir/data/sim_data/$sim_name/cpu"
1212

13-
fmax=1600
13+
fmax=1000
1414
duration=0.06
1515

1616
# Delete old sim

src/cpp/main_2d/engine.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
namespace pffdtd {
1010

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

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

45+
auto frame = std::vector<double>(sim.Nx * sim.Ny);
46+
4447
fmt::print(stdout, "111111111");
4548
for (auto i{0UL}; i < sim.Nt; ++i) {
4649
fmt::print(stdout, "\r\r\r\r\r\r\r\r\r");
@@ -112,7 +115,15 @@ auto run(Simulation2D const& sim) -> std::vector<double> {
112115
);
113116
});
114117

115-
queue.wait_and_throw();
118+
auto host = sycl::host_accessor{u0, sycl::read_only};
119+
for (auto i{0UL}; i < frame.size(); ++i) {
120+
frame[i] = std::abs(double(host.get_pointer()[i]));
121+
// if (sim.in_mask[i] == 0) {
122+
// frame[i] = 1.0;
123+
// }
124+
}
125+
126+
video.write(frame, Ny, Nx);
116127
}
117128

118129
auto save = std::vector<double>(Nt * Nr);

src/cpp/pffdtd/simulation_2d.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ namespace pffdtd {
1010
auto loadSimulation2D(std::filesystem::path const& path) -> Simulation2D {
1111
auto file = H5FReader{path.string().c_str()};
1212
return Simulation2D{
13+
.file = path,
14+
1315
.Nx = file.read<int64_t>("Nx"),
1416
.Ny = file.read<int64_t>("Ny"),
1517
.Nt = file.read<int64_t>("Nt"),

src/cpp/pffdtd/simulation_2d.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
namespace pffdtd {
88

99
struct Simulation2D {
10+
std::filesystem::path file;
11+
1012
int64_t Nx; // Number of x sample nodes
1113
int64_t Ny; // Number of y sample nodes
1214
int64_t Nt; // Number of time steps

src/cpp/pffdtd/video.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,12 @@ auto VideoWriter::write(std::span<double> buf, size_t width, size_t height)
3434
normalized.convertTo(normalized, CV_8U);
3535

3636
auto resized = cv::Mat{};
37-
cv::resize(input, resized, _size);
37+
cv::resize(normalized, resized, _size);
3838

39-
_writer.write(resized);
39+
auto rotated = cv::Mat{};
40+
cv::rotate(resized, rotated, cv::ROTATE_90_COUNTERCLOCKWISE);
41+
42+
_writer.write(rotated);
4043
}
4144

4245
} // namespace pffdtd

0 commit comments

Comments
 (0)