Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions gladius/src/ImageStackResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ namespace gladius
return 3;
case io::PixelFormat::GRAYSCALE_16BIT:
case io::PixelFormat::GRAYSCALE_8BIT:
case io::PixelFormat::GRAYSCALE_2BIT:
case io::PixelFormat::GRAYSCALE_1BIT:
return 1;
case io::PixelFormat::GRAYSCALE_ALPHA_16BIT:
case io::PixelFormat::GRAYSCALE_ALPHA_8BIT:
Expand Down
35 changes: 31 additions & 4 deletions gladius/src/io/3mf/ImageExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,36 @@ namespace gladius::io
return fileContents;
}

std::string colorTypeToString(LodePNGColorType colorType)
{
switch (colorType)
{
case LCT_GREY:
return "LCT_GREY";
case LCT_RGB:
return "LCT_RGB";
case LCT_PALETTE:
return "LCT_PALETTE";
case LCT_GREY_ALPHA:
return "LCT_GREY_ALPHA";
case LCT_RGBA:
return "LCT_RGBA";
default:
return "unknown";
}
}

PixelFormat fromPngColorType(LodePNGColorMode const & colorMode)
{
if (colorMode.bitdepth == 1)
{
return PixelFormat::GRAYSCALE_1BIT;
}
if (colorMode.bitdepth == 8)
if (colorMode.bitdepth == 2)
{
return PixelFormat::GRAYSCALE_8BIT;
}
if (colorMode.bitdepth == 4 || colorMode.bitdepth == 8)
{
switch (colorMode.colortype)
{
Expand All @@ -143,8 +166,10 @@ namespace gladius::io
return PixelFormat::RGB_8BIT;
case LCT_RGBA:
return PixelFormat::RGBA_8BIT;
case LCT_PALETTE:
return PixelFormat::RGBA_8BIT;
default:
throw std::runtime_error("Error: unsupported PNG color type");
throw std::runtime_error(fmt::format("Error: unsupported PNG color type {}", colorTypeToString(colorMode.colortype)));
}
}
if (colorMode.bitdepth == 16)
Expand All @@ -159,12 +184,14 @@ namespace gladius::io
return PixelFormat::RGB_16BIT;
case LCT_RGBA:
return PixelFormat::RGBA_16BIT;
case LCT_PALETTE:
return PixelFormat::RGBA_16BIT;
default:
throw std::runtime_error("Error: unsupported PNG color type");
throw std::runtime_error(fmt::format("Error: unsupported PNG color type {}", colorTypeToString(colorMode.colortype)));
}
}

throw std::runtime_error("Error: unsupported PNG bit depth");
throw std::runtime_error(fmt::format("Error: unsupported PNG bit depth {}", colorMode.bitdepth));
}

ImageStack ImageExtractor::loadImageStack(FileList const & filenames)
Expand Down
1 change: 1 addition & 0 deletions gladius/src/io/3mf/ImageStack.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace gladius::io
enum class PixelFormat
{
GRAYSCALE_1BIT,
GRAYSCALE_2BIT,
RGBA_8BIT,
RGB_8BIT,
GRAYSCALE_8BIT,
Expand Down
41 changes: 27 additions & 14 deletions gladius/src/io/ImageStackExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,29 @@ namespace gladius::io
auto v6 = mesh->AddVertex({bb.max.x, bb.max.y, bb.max.z});
auto v7 = mesh->AddVertex({bb.min.x, bb.max.y, bb.max.z});

mesh->AddTriangle({v0, v1, v2});
mesh->AddTriangle({v0, v2, v3});
// Bottom face
mesh->AddTriangle({v0, v2, v1});
mesh->AddTriangle({v0, v3, v2});

// Top face
mesh->AddTriangle({v4, v5, v6});
mesh->AddTriangle({v4, v6, v7});
mesh->AddTriangle({v0, v4, v7});
mesh->AddTriangle({v0, v7, v3});
mesh->AddTriangle({v1, v5, v6});
mesh->AddTriangle({v1, v6, v2});
mesh->AddTriangle({v0, v1, v5});

// Front face
mesh->AddTriangle({v0, v5, v4});
mesh->AddTriangle({v3, v7, v6});
mesh->AddTriangle({v0, v1, v5});

// Back face
mesh->AddTriangle({v3, v6, v2});
mesh->AddTriangle({v3, v7, v6});

// Left face
mesh->AddTriangle({v0, v7, v3});
mesh->AddTriangle({v0, v4, v7});

// Right face
mesh->AddTriangle({v1, v6, v5});
mesh->AddTriangle({v1, v2, v6});

mesh->SetName("Bounding Box");

Expand Down Expand Up @@ -265,18 +276,18 @@ namespace gladius::io

for (int y = 0; y < height; y++)
{
for (int x = 0 ; x < width; x++)
for (int x = 0; x < width; x++)
{
unsigned int indexTarget = (y * width + x) * numChannels;
unsigned int indexTarget = (y * width + width - x - 1) * numChannels;
unsigned int indexSource = ((height - y - 1) * width + x) * numChannels;
for (unsigned int i = 0; i < numChannels; ++i)
{
swappedData[indexTarget + i] = data[indexSource + i];
}
}
}
data = std::move(swappedData);

data = std::move(swappedData);
}

bool ImageStackExporter::advanceExport(ComputeCore & generator)
Expand Down Expand Up @@ -340,11 +351,13 @@ namespace gladius::io

Lib3MF_uint32 ImageStackExporter::getColumnCountPng() const
{
return m_rowCountWorld;
// return m_rowCountWorld;
return m_columnCountWorld;
}

Lib3MF_uint32 ImageStackExporter::getRowCountPng() const
{
return m_columnCountWorld;
// return m_columnCountWorld;
return m_rowCountWorld;
}
}
12 changes: 4 additions & 8 deletions gladius/src/io/ImageStackExporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "IExporter.h"

#include "EventLogger.h"
#include "kernel/types.h"

#include <filesystem>
#include <lib3mf/Cpp/lib3mf_implicit.hpp>
Expand All @@ -11,16 +12,13 @@

namespace gladius::io
{




Lib3MF::PMeshObject addBoundingBoxAsMesh(Lib3MF::PModel model, BoundingBox const & bb);

class ImageStackExporter : public IExporter
{
public:
explicit ImageStackExporter(events::SharedLogger logger);

void beginExport(const std::filesystem::path & fileName, ComputeCore & generator) override;
bool advanceExport(ComputeCore & generator) override;

Expand All @@ -38,7 +36,7 @@ namespace gladius::io

std::filesystem::path m_outputFilename{};

float m_layerIncrement_mm = 0.1f;
float m_layerIncrement_mm = 0.04f;
float m_bandwidth_mm = m_layerIncrement_mm * 2.f;
size_t m_qualityLevel = 1; // 3 = best quality, but insane high memory usage
double m_progress = 0.;
Expand All @@ -54,8 +52,6 @@ namespace gladius::io
Lib3MF_uint32 m_columnCountWorld = 0u;
Lib3MF_uint32 m_rowCountWorld = 0u;



events::SharedLogger m_logger;
};
}
11 changes: 0 additions & 11 deletions gladius/tests/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,4 @@ file(GLOB FONT_FILES
)
file(COPY ${FONT_FILES} DESTINATION "misc/fonts/")

# if(WIN32 AND NOT UNIX)
# configure_file(${CMAKE_SOURCE_DIR}/components/lib3mf/Bin/lib3mf.dll lib3mf.dll COPYONLY)
# endif()

# if(WIN32 AND NOT UNIX)
# configure_file(${CMAKE_SOURCE_DIR}/components/lib3mf/Bin/lib3mf.dll src/lib3mf.dll COPYONLY)
# else()
# configure_file(${CMAKE_SOURCE_DIR}/components/lib3mf/Bin/lib3mf.so src/lib3mf.so COPYONLY)
# configure_file(${CMAKE_SOURCE_DIR}/components/lib3mf/Bin/lib3mf.so src/lib3mf.so.2 COPYONLY)
# endif()

gtest_add_tests(TARGET ${BINARY})
9 changes: 4 additions & 5 deletions gladius/tests/unittests/ComputeCore_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,15 @@ namespace gladius_tests

auto const & payloadData = core->getPrimitives().data.getData();
auto const payloadDataHash = helper::computeHash(payloadData.cbegin(), payloadData.cend());
EXPECT_EQ(payloadDataHash, 9060768986935382616u);
EXPECT_EQ(payloadDataHash, 9702363036366401599u);

auto const parameter = core->getResourceContext().getParameterBuffer().getData();
for (auto const & param : parameter)
auto const parameter = core->getResourceContext().getParameterBuffer().getData(); for (auto const & param : parameter)
{
std::cout << param << std::endl;
}

auto const parameterHash = helper::computeHash(parameter.cbegin(), parameter.cend());
constexpr auto expectedHash = 16527889583062519464u;
constexpr auto expectedHash = 15121003317986780364u;
EXPECT_EQ(parameterHash, expectedHash);

EXPECT_TRUE(core->precomputeSdfForWholeBuildPlatform());
Expand All @@ -82,7 +81,7 @@ namespace gladius_tests

auto const & data = preComp.getData();
auto const hash = helper::computeHash(data.cbegin(), data.cend());
EXPECT_EQ(hash, 8853725864174386457);
EXPECT_EQ(hash, 17803807128366017585);

auto bBox = core->getBoundingBox();
EXPECT_TRUE(bBox.has_value());
Expand Down
21 changes: 14 additions & 7 deletions gladius/tests/unittests/ImageExtractor_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace gladius_tests

struct TestFiles
{
static auto constexpr Boundary3mf = "testdata/Boundary.3mf";
static auto constexpr Volumetric3mf = "testdata/box.imagestack.3mf";
};

TEST(ImageExtractor, Open_Valid3mfFile_ReturnsTrue)
Expand All @@ -18,7 +18,7 @@ namespace gladius_tests
io::ImageExtractor extractor;

// act
auto const result = extractor.loadFromArchive(TestFiles::Boundary3mf);
auto const result = extractor.loadFromArchive(TestFiles::Volumetric3mf);

// assert
EXPECT_TRUE(result);
Expand All @@ -37,10 +37,17 @@ namespace gladius_tests
{
// arrange
io::ImageExtractor extractor;
extractor.loadFromArchive(TestFiles::Boundary3mf);

std::filesystem::path currentPath = std::filesystem::current_path();
std::cout << "Current path is: " << currentPath << std::endl;
auto const completeFilePath = currentPath / TestFiles::Volumetric3mf;
std::cout << "Complete file path is: " << completeFilePath << std::endl;
ASSERT_TRUE(std::filesystem::exists(completeFilePath));

extractor.loadFromArchive(TestFiles::Volumetric3mf);

// act
auto const result = extractor.loadFileFromArchive("volume/layer_01.png");
auto const result = extractor.loadFileFromArchive("volume/1/layer_001.png");

// assert
EXPECT_FALSE(result.empty());
Expand All @@ -63,16 +70,16 @@ namespace gladius_tests
{
// arrange
io::ImageExtractor extractor;
extractor.loadFromArchive(TestFiles::Boundary3mf);
extractor.loadFromArchive(TestFiles::Volumetric3mf);

// act
io::ImageStack const imgStack = extractor.loadImageStack({"volume/layer_01.png"});
io::ImageStack const imgStack = extractor.loadImageStack({"volume/1/layer_001.png"});
auto firstImage = imgStack.front();
auto pngInfo = extractor.getPNGInfo();

constexpr auto numChannels = 4; // lodepng always decodes to RGBA
auto numPixels = firstImage.getWidth() * firstImage.getHeight();
auto numBytes = numPixels * numChannels * pngInfo.color.bitdepth / 8;
auto numBytes = numPixels * numChannels;
// assert
EXPECT_EQ(firstImage.getData().size(), numBytes);
}
Expand Down
Loading