diff --git a/library/phx/line_segments.hpp b/library/phx/line_segments.hpp new file mode 100644 index 0000000000000000000000000000000000000000..fed6e566f6c84d29c5ce9200479c7b3bacdf24fa --- /dev/null +++ b/library/phx/line_segments.hpp @@ -0,0 +1,19 @@ + +#ifndef LIBRARY_PHX_LINE_SEGMENTS_HPP_ +#define LIBRARY_PHX_LINE_SEGMENTS_HPP_ + +#include <vector> +#include <glm/glm.hpp> + +namespace phx { + + struct line_segments + { + std::vector<glm::vec3> vertices; + std::vector<glm::u8vec4> colors; + std::vector<std::uint32_t> indices; + float radius = 1.0f; + + }; +} +#endif \ No newline at end of file diff --git a/library/phx/pli_loader.cpp b/library/phx/pli_loader.cpp index 8ce4c4f86223bb735cbc175206fd1091da80ec23..c20e4a8640808296e530302c5961156549e4074c 100644 --- a/library/phx/pli_loader.cpp +++ b/library/phx/pli_loader.cpp @@ -18,8 +18,8 @@ SUPPRESS_WARNINGS_END namespace phx { - std::unique_ptr<phx::Resource> PLILoader::Load( - const ResourceDeclaration& declaration) { + std::unique_ptr<phx::Resource> PLILoader::Load(const ResourceDeclaration& declaration) + { //check for all important information if (declaration.find("file_name") == declaration.end() || @@ -138,22 +138,25 @@ namespace phx { glm::vec3(0) ); - tbb::parallel_for (std::size_t(0), size_vec[2], std::size_t(1), [&](std::size_t x) { - tbb::parallel_for (std::size_t(0), size_vec[3], std::size_t(1), [&](std::size_t y) { - tbb::parallel_for (std::size_t(0), size_vec[0], std::size_t(1), [&](std::size_t z) { - - const size_t padded_coord = - (x + zero_pad_) + (size_vec[2] + 2 * zero_pad_) * - (y + zero_pad_ + (size_vec[3] + 2 * zero_pad_) * (z + zero_pad_)); - - retardation_result[padded_coord] = retardation_data[z][x][y][0]; - transmittance_result[padded_coord] = transmittance_data[z][x][y][0]; - orientation_result[padded_coord] = - glm::vec3(orientation_data[z][0][x][y], - orientation_data[z][1][x][y], - orientation_data[z][2][x][y]); - }); - }); + //collapse nested loops for (hopefully) better performance + tbb::parallel_for(tbb::blocked_range3d<int>(std::size_t(0), size_vec[2], std::size_t(0), size_vec[3], std::size_t(0), size_vec[0]), [&](const tbb::blocked_range3d<int> &r) { + for (int x = r.pages().begin(), x_end = r.pages().end(); x < x_end; x++) { + for (int y = r.rows().begin(), y_end = r.rows().end(); y < y_end; y++) { + for (int z = r.cols().begin(), z_end = r.cols().end(); z < z_end; z++) { + + const size_t padded_coord = + (x + zero_pad_) + (size_vec[2] + 2 * zero_pad_) * + (y + zero_pad_ + (size_vec[3] + 2 * zero_pad_) * (z + zero_pad_)); + + retardation_result[padded_coord] = retardation_data[z][x][y][0]; + transmittance_result[padded_coord] = transmittance_data[z][x][y][0]; + orientation_result[padded_coord] = + glm::vec3(orientation_data[z][0][x][y], + orientation_data[z][1][x][y], + orientation_data[z][2][x][y]); + } + } + } }); //free memory @@ -166,6 +169,7 @@ namespace phx { resource->SetRetardation(retardation_result); resource->SetTransmittance(transmittance_result); + //free memory orientation_result.resize(0); transmittance_result.resize(0); retardation_result.resize(0); diff --git a/library/phx/pli_processor.cpp b/library/phx/pli_processor.cpp new file mode 100644 index 0000000000000000000000000000000000000000..da9d19625436c3d3e851e591b0daa4ac801d8ae1 --- /dev/null +++ b/library/phx/pli_processor.cpp @@ -0,0 +1,71 @@ + +#include "phx/pli_processor.hpp" +#include "phx/pli_loader.hpp" +#include "phx/pli_region.hpp" +#include "phx/resource_declaration.hpp" +#include "phx/resource_manager.hpp" +#include "phx/line_segments.hpp" +#include "phx/resource_utils.hpp" + +#include <string> + +namespace phx { + + line_segments make_hedgehog(Resource* resource, const float length = 1.0f, const float radius = 1.0f) + { + auto pli_region = dynamic_cast<PLIRegion *>(resource); + auto size = pli_region->GetSize(); + + //create return value + line_segments segments; + + segments.radius = radius; + + for (auto z = 0; z < size[0]; z++) + { + for (auto x = 0; x < size[1]; x++) + { + for (auto y = 0; y < size[2]; y++) + { + const auto center = glm::vec3(x, y, z); + const auto direction = glm::normalize(glm::vec3(pli_region->GetOrientation[z][0][x][y], pli_region->GetOrientation[z][1][x][y], pli_region->GetOrientation[z][2][x][y])); + + segments.vertices.push_back(center + length / 2.0f * direction); + segments.vertices.push_back(center - length / 2.0f * direction); + segments.colors.push_back(glm::u8vec4(glm::abs(direction) * 255.0f, 255)); + segments.colors.push_back(glm::u8vec4(glm::abs(direction) * 255.0f, 255)); + segments.indices.push_back(static_cast<std::uint32_t>(segments.vertices.size() - 2)); + segments.indices.push_back(static_cast<std::uint32_t>(segments.vertices.size() - 1)); + } + } + } + return segments; + } + + + + void pli_prepare_data() { + + //TODO: find out how ResourceDeclaration/ nlohmann-json works + //TODO: find out why Load doesn't work + std::string addr("O:/Documents/MSA0309_s0536-0695.h5"); + ResourceDeclaration& declaration( + (ResourceDeclaration)addr, { { "from",{ { "X", 0.0f },{ "Y", 0.0f },{ "Z", 0.0f } } }, + { "to",{ { "X", 360.0f },{ "Y", 560.0f },{ "Z", 25.0f } } }, + { "stride",{ { "X", 3.0f },{ "Y", 3.0f },{ "Z", 3.0f } } } }, + false); + + auto pli_resource = PLILoader::Load(declaration); + /* + auto pli_resource = ResourceUtils::LoadResourceFromFile<phx::PLIRegion>( + R"(O:\Documents\MSA0309_s0536-0695.h5)", + { { "from",{ { "X", 0.0f },{ "Y", 0.0f },{ "Z", 0.0f } } }, + { "to",{ { "X", 360.0f },{ "Y", 560.0f },{ "Z", 25.0f } } }, + { "stride",{ { "X", 3.0f },{ "Y", 3.0f },{ "Z", 3.0f } } } }); + + auto resource = dynamic_cast<Resource *>(pli_resource); + auto mesh = make_hedgehog(pli_resource, 1.0f, 1.0f); + */ + + } +} \ No newline at end of file diff --git a/library/phx/pli_processor.hpp b/library/phx/pli_processor.hpp new file mode 100644 index 0000000000000000000000000000000000000000..3ec26c3ed8ed1dc7f620eae87f6fdeb9ed5d5201 --- /dev/null +++ b/library/phx/pli_processor.hpp @@ -0,0 +1,18 @@ + +#ifndef LIBRARY_PHX_PLI_PROCESSOR_HPP_ +#define LIBRARY_PHX_PLI_PROCESSOR_HPP_ + + +#include "phx/pli_processor.hpp" +#include "phx/pli_region.hpp" +#include "phx/resource_declaration.hpp" +#include "phx/resource_manager.hpp" +#include "phx/line_segments.hpp" + + +namespace phx{ + line_segments make_hedgehog(Resource* resource, const float length = 1.0f, const float radius = 1.0f); + +} + +#endif \ No newline at end of file