Skip to content

Commit

Permalink
Merge pull request #339 from zhujun98/dev
Browse files Browse the repository at this point in the history
Fix copy sinogram with offset
  • Loading branch information
zhujun98 authored Aug 29, 2024
2 parents 8294e27 + 1e64e3d commit c52c62f
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 26 deletions.
1 change: 1 addition & 0 deletions gui/include/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class Application {
RpcClient::State updateServerParams();

void startConsumer();
void stopConsumer();

bool consume(const RpcClient::DataType& packet);

Expand Down
8 changes: 6 additions & 2 deletions gui/src/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ Application::Application() : width_(1440), height_(1080) {
}

Application::~Application() {
running_ = false;

rpc_client_.reset();
consumer_thread_.join();

Expand Down Expand Up @@ -150,6 +148,8 @@ void Application::spin(const std::string& endpoint) {

glfwSwapBuffers(glfw_window_);
}

stopConsumer();
}

void Application::connectServer() {
Expand Down Expand Up @@ -304,6 +304,10 @@ void Application::startConsumer() {
});
}

void Application::stopConsumer() {
running_ = false;
}

bool Application::consume(const RpcClient::DataType& packet) {
if (std::holds_alternative<rpc::ProjectionData>(packet)) {
const auto& data = std::get<rpc::ProjectionData>(packet);
Expand Down
22 changes: 13 additions & 9 deletions recon/include/recon/preprocessing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>(-offset); ++k) {
for (size_t k = 0; k < static_cast<size_t>(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];
}
}

}
}

Expand Down
57 changes: 42 additions & 15 deletions recon/tests/test_preprocessing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,50 +154,77 @@ TEST(TestPreprocessing, TestComputeReciprocal) {
TEST(TestPreprocessing, TestCopyToSinogram) {

// (chunk_idx, rows, cols) -> (rows, chunk_idx, cols).
Tensor<int, 3> src ({2, 3, 4}, std::vector<int>(24, 1));
Tensor<int, 3> 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<int, 3> 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}));
}

{
Tensor<int, 3> 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<int, 3> 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<int, 3> 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<int, 3> 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<int, 3> 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}));
}
}

Expand Down

0 comments on commit c52c62f

Please sign in to comment.