diff --git a/gui/include/application.hpp b/gui/include/application.hpp index c2ee3320..59fbf0b4 100644 --- a/gui/include/application.hpp +++ b/gui/include/application.hpp @@ -103,6 +103,7 @@ class Application { RpcClient::State updateServerParams(); void startConsumer(); + void stopConsumer(); bool consume(const RpcClient::DataType& packet); diff --git a/gui/src/application.cpp b/gui/src/application.cpp index d028cef0..54d6d66b 100644 --- a/gui/src/application.cpp +++ b/gui/src/application.cpp @@ -72,8 +72,6 @@ Application::Application() : width_(1440), height_(1080) { } Application::~Application() { - running_ = false; - rpc_client_.reset(); consumer_thread_.join(); @@ -150,6 +148,8 @@ void Application::spin(const std::string& endpoint) { glfwSwapBuffers(glfw_window_); } + + stopConsumer(); } void Application::connectServer() { @@ -304,6 +304,10 @@ void Application::startConsumer() { }); } +void Application::stopConsumer() { + running_ = false; +} + bool Application::consume(const RpcClient::DataType& packet) { if (std::holds_alternative(packet)) { const auto& data = std::get(packet); diff --git a/recon/include/recon/preprocessing.hpp b/recon/include/recon/preprocessing.hpp index b8a6f0ec..9ad7932b 100644 --- a/recon/include/recon/preprocessing.hpp +++ b/recon/include/recon/preprocessing.hpp @@ -134,30 +134,34 @@ inline void copyToSinogram(T1 *dst, size_t col_count, int32_t offset) { // (chunk_idx, rows, cols) -> (rows, chunk_idx, cols). - if (offset >= 0) { + if (offset == 0) { for (size_t j = 0; j < row_count; ++j) { - for (size_t k = col_count - offset; k < col_count; ++k) { + for (size_t k = 0; k < col_count; ++k) { + dst[(row_count - 1 - j) * chunk_size * col_count + chunk_idx * col_count + k] = + src[chunk_idx * col_count * row_count + j * col_count + k]; + } + } + } else if (offset < 0) { + for (size_t j = 0; j < row_count; ++j) { + for (size_t k = col_count + offset; k < col_count; ++k) { dst[(row_count - 1 - j) * chunk_size * col_count + chunk_idx * col_count + k] = 0; } - for (size_t k = 0; k < col_count - offset; ++k) { + for (size_t k = 0; k < col_count + offset; ++k) { dst[(row_count - 1 - j) * chunk_size * col_count + chunk_idx * col_count + k] = src[chunk_idx * col_count * row_count + j * col_count + k - offset]; } } - } else { - for (size_t j = 0; j < row_count; ++j) { - for (size_t k = 0; k < static_cast(-offset); ++k) { + for (size_t k = 0; k < static_cast(offset); ++k) { dst[(row_count - 1 - j) * chunk_size * col_count + chunk_idx * col_count + k] = 0; } - for (size_t k = -offset; k < col_count; ++k) { + for (size_t k = offset; k < col_count; ++k) { dst[(row_count - 1 - j) * chunk_size * col_count + chunk_idx * col_count + k] = - src[chunk_idx * col_count * row_count + j * col_count + k + offset]; + src[chunk_idx * col_count * row_count + j * col_count + k - offset]; } } - } } diff --git a/recon/tests/test_preprocessing.cpp b/recon/tests/test_preprocessing.cpp index 14e12c6b..6651857b 100644 --- a/recon/tests/test_preprocessing.cpp +++ b/recon/tests/test_preprocessing.cpp @@ -154,16 +154,21 @@ TEST(TestPreprocessing, TestComputeReciprocal) { TEST(TestPreprocessing, TestCopyToSinogram) { // (chunk_idx, rows, cols) -> (rows, chunk_idx, cols). - Tensor src ({2, 3, 4}, std::vector(24, 1)); + Tensor src ({2, 3, 4}, {1, 2, 3, 4, + 5, 6, 7, 8, + 9, 0, 9, 8, + 7, 6, 5, 4, + 3, 2, 1, 0, + 1, 2, 3, 4}); { Tensor dst ({3, 2, 4}); copyToSinogram(dst.data(), src, 0, 2, 3, 4, 0); - EXPECT_THAT(dst, ElementsAreArray({1, 1, 1, 1, + EXPECT_THAT(dst, ElementsAreArray({9, 0, 9, 8, 0, 0, 0, 0, - 1, 1, 1, 1, + 5, 6, 7, 8, 0, 0, 0, 0, - 1, 1, 1, 1, + 1, 2, 3, 4, 0, 0, 0, 0})); } @@ -171,33 +176,55 @@ TEST(TestPreprocessing, TestCopyToSinogram) { Tensor dst ({3, 2, 4}); copyToSinogram(dst.data(), src, 1, 2, 3, 4, 0); EXPECT_THAT(dst, ElementsAreArray({0, 0, 0, 0, - 1, 1, 1, 1, + 1, 2, 3, 4, 0, 0, 0, 0, - 1, 1, 1, 1, + 3, 2, 1, 0, 0, 0, 0, 0, - 1, 1, 1, 1})); + 7, 6, 5, 4})); } { Tensor dst ({3, 2, 4}); - copyToSinogram(dst.data(), src, 1, 2, 3, 4, 1); + copyToSinogram(dst.data(), src, 0, 2, 3, 4, 2); + EXPECT_THAT(dst, ElementsAreArray({0, 0, 9, 0, + 0, 0, 0, 0, + 0, 0, 5, 6, + 0, 0, 0, 0, + 0, 0, 1, 2, + 0, 0, 0, 0})); + } + + { + Tensor dst ({3, 2, 4}); + copyToSinogram(dst.data(), src, 1, 2, 3, 4, 2); EXPECT_THAT(dst, ElementsAreArray({0, 0, 0, 0, - 1, 1, 1, 0, + 0, 0, 1, 2, 0, 0, 0, 0, - 1, 1, 1, 0, + 0, 0, 3, 2, 0, 0, 0, 0, - 1, 1, 1, 0})); + 0, 0, 7, 6})); + } + + { + Tensor dst ({3, 2, 4}); + copyToSinogram(dst.data(), src, 0, 2, 3, 4, -2); + EXPECT_THAT(dst, ElementsAreArray({9, 8, 0, 0, + 0, 0, 0, 0, + 7, 8, 0, 0, + 0, 0, 0, 0, + 3, 4, 0, 0, + 0, 0, 0, 0})); } { Tensor dst ({3, 2, 4}); - copyToSinogram(dst.data(), src, 1, 2, 3, 4, -1); + copyToSinogram(dst.data(), src, 1, 2, 3, 4, -2); EXPECT_THAT(dst, ElementsAreArray({0, 0, 0, 0, - 0, 1, 1, 1, + 3, 4, 0, 0, 0, 0, 0, 0, - 0, 1, 1, 1, + 1, 0, 0, 0, 0, 0, 0, 0, - 0, 1, 1, 1})); + 5, 4, 0, 0})); } }