SLAArchive framework refactor
This commit is contained in:
parent
6c397e291c
commit
66f60de556
@ -94,6 +94,8 @@ set(SLIC3R_SOURCES
|
|||||||
Format/objparser.hpp
|
Format/objparser.hpp
|
||||||
Format/STL.cpp
|
Format/STL.cpp
|
||||||
Format/STL.hpp
|
Format/STL.hpp
|
||||||
|
Format/SLAArchive.hpp
|
||||||
|
Format/SLAArchive.cpp
|
||||||
Format/SL1.hpp
|
Format/SL1.hpp
|
||||||
Format/SL1.cpp
|
Format/SL1.cpp
|
||||||
Format/SL1_SVG.hpp
|
Format/SL1_SVG.hpp
|
||||||
|
@ -3,8 +3,10 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "SLAArchive.hpp"
|
||||||
|
|
||||||
#include "libslic3r/Zipper.hpp"
|
#include "libslic3r/Zipper.hpp"
|
||||||
#include "libslic3r/SLAPrint.hpp"
|
#include "libslic3r/PrintConfig.hpp"
|
||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
|
|
||||||
|
74
src/libslic3r/Format/SLAArchive.cpp
Normal file
74
src/libslic3r/Format/SLAArchive.cpp
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
#include "SLAArchive.hpp"
|
||||||
|
|
||||||
|
#include "SL1.hpp"
|
||||||
|
#include "SL1_SVG.hpp"
|
||||||
|
#include "pwmx.hpp"
|
||||||
|
|
||||||
|
#include "libslic3r/libslic3r.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
|
#include <tuple>
|
||||||
|
|
||||||
|
namespace Slic3r {
|
||||||
|
|
||||||
|
using ArchiveFactory = std::function<std::unique_ptr<SLAArchive>(const SLAPrinterConfig&)>;
|
||||||
|
|
||||||
|
struct ArchiveEntry {
|
||||||
|
const char *ext;
|
||||||
|
ArchiveFactory factoryfn;
|
||||||
|
};
|
||||||
|
|
||||||
|
static const std::map<std::string, ArchiveEntry> REGISTERED_ARCHIVES {
|
||||||
|
{
|
||||||
|
"SL1",
|
||||||
|
{ "sl1", [] (const auto &cfg) { return std::make_unique<SL1Archive>(cfg); } }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"SL2",
|
||||||
|
{ "sl2", [] (const auto &cfg) { return std::make_unique<SL1_SVGArchive>(cfg); } }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pwmx",
|
||||||
|
{ "pwmx", [] (const auto &cfg) { return std::make_unique<PwmxArchive>(cfg); } }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
std::unique_ptr<SLAArchive>
|
||||||
|
SLAArchive::create(const std::string &archtype, const SLAPrinterConfig &cfg)
|
||||||
|
{
|
||||||
|
auto entry = REGISTERED_ARCHIVES.find(archtype);
|
||||||
|
|
||||||
|
if (entry != REGISTERED_ARCHIVES.end())
|
||||||
|
return entry->second.factoryfn(cfg);
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::vector<const char*>& SLAArchive::registered_archives()
|
||||||
|
{
|
||||||
|
static std::vector<const char*> archnames;
|
||||||
|
|
||||||
|
if (archnames.empty()) {
|
||||||
|
archnames.reserve(REGISTERED_ARCHIVES.size());
|
||||||
|
|
||||||
|
for (auto &[name, _] : REGISTERED_ARCHIVES)
|
||||||
|
archnames.emplace_back(name.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
return archnames;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *SLAArchive::get_extension(const char *archtype)
|
||||||
|
{
|
||||||
|
static const char* DEFAULT_EXT = "zip";
|
||||||
|
|
||||||
|
auto entry = REGISTERED_ARCHIVES.find(archtype);
|
||||||
|
if (entry != REGISTERED_ARCHIVES.end())
|
||||||
|
return entry->second.ext;
|
||||||
|
|
||||||
|
return DEFAULT_EXT;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Slic3r
|
64
src/libslic3r/Format/SLAArchive.hpp
Normal file
64
src/libslic3r/Format/SLAArchive.hpp
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
#ifndef SLAARCHIVE_HPP
|
||||||
|
#define SLAARCHIVE_HPP
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "libslic3r/SLA/RasterBase.hpp"
|
||||||
|
#include "libslic3r/Execution/ExecutionTBB.hpp"
|
||||||
|
#include "libslic3r/GCode/ThumbnailData.hpp"
|
||||||
|
|
||||||
|
namespace Slic3r {
|
||||||
|
|
||||||
|
class SLAPrint;
|
||||||
|
class SLAPrinterConfig;
|
||||||
|
|
||||||
|
class SLAArchive {
|
||||||
|
protected:
|
||||||
|
std::vector<sla::EncodedRaster> m_layers;
|
||||||
|
|
||||||
|
virtual std::unique_ptr<sla::RasterBase> create_raster() const = 0;
|
||||||
|
virtual sla::RasterEncoder get_encoder() const = 0;
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual ~SLAArchive() = default;
|
||||||
|
|
||||||
|
// Fn have to be thread safe: void(sla::RasterBase& raster, size_t lyrid);
|
||||||
|
template<class Fn, class CancelFn, class EP = ExecutionTBB>
|
||||||
|
void draw_layers(
|
||||||
|
size_t layer_num,
|
||||||
|
Fn && drawfn,
|
||||||
|
CancelFn cancelfn = []() { return false; },
|
||||||
|
const EP & ep = {})
|
||||||
|
{
|
||||||
|
m_layers.resize(layer_num);
|
||||||
|
execution::for_each(
|
||||||
|
ep, size_t(0), m_layers.size(),
|
||||||
|
[this, &drawfn, &cancelfn](size_t idx) {
|
||||||
|
if (cancelfn()) return;
|
||||||
|
|
||||||
|
sla::EncodedRaster &enc = m_layers[idx];
|
||||||
|
auto rst = create_raster();
|
||||||
|
drawfn(*rst, idx);
|
||||||
|
enc = rst->encode(get_encoder());
|
||||||
|
},
|
||||||
|
execution::max_concurrency(ep));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Export the print into an archive using the provided filename.
|
||||||
|
virtual void export_print(const std::string fname,
|
||||||
|
const SLAPrint &print,
|
||||||
|
const ThumbnailsList &thumbnails,
|
||||||
|
const std::string &projectname = "") = 0;
|
||||||
|
|
||||||
|
// Factory method to create an archiver instance
|
||||||
|
static std::unique_ptr<SLAArchive> create(const std::string &archtype, const SLAPrinterConfig&);
|
||||||
|
|
||||||
|
// Get the names of currently known archiver implementations
|
||||||
|
static const std::vector<const char *> & registered_archives();
|
||||||
|
|
||||||
|
// Get the default file extension belonging to an archive format
|
||||||
|
static const char *get_extension(const char *archtype);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Slic3r
|
||||||
|
#endif // SLAARCHIVE_HPP
|
@ -1,6 +1,7 @@
|
|||||||
#include "pwmx.hpp"
|
#include "pwmx.hpp"
|
||||||
#include "GCode/ThumbnailData.hpp"
|
#include "GCode/ThumbnailData.hpp"
|
||||||
#include "SLA/RasterBase.hpp"
|
#include "SLA/RasterBase.hpp"
|
||||||
|
#include "libslic3r/SLAPrint.hpp"
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -278,7 +279,8 @@ void fill_header(pwmx_format_header &h,
|
|||||||
std::float_t bottle_cost;
|
std::float_t bottle_cost;
|
||||||
std::float_t material_density;
|
std::float_t material_density;
|
||||||
auto &cfg = print.full_print_config();
|
auto &cfg = print.full_print_config();
|
||||||
std::string mnotes = cfg.option("material_notes")->serialize();
|
auto mat_opt = cfg.option("material_notes");
|
||||||
|
std::string mnotes = mat_opt? cfg.option("material_notes")->serialize() : "";
|
||||||
// create a config parser from the material notes
|
// create a config parser from the material notes
|
||||||
Slic3r::PwmxFormatDynamicConfig mat_cfg;
|
Slic3r::PwmxFormatDynamicConfig mat_cfg;
|
||||||
SLAPrintStatistics stats = print.print_statistics();
|
SLAPrintStatistics stats = print.print_statistics();
|
||||||
|
@ -3,7 +3,9 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "libslic3r/SLAPrint.hpp"
|
#include "SLAArchive.hpp"
|
||||||
|
|
||||||
|
#include "libslic3r/PrintConfig.hpp"
|
||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
|
|
||||||
|
@ -245,15 +245,8 @@ SLAPrint::ApplyStatus SLAPrint::apply(const Model &model, DynamicPrintConfig con
|
|||||||
// Handle changes to object config defaults
|
// Handle changes to object config defaults
|
||||||
m_default_object_config.apply_only(config, object_diff, true);
|
m_default_object_config.apply_only(config, object_diff, true);
|
||||||
|
|
||||||
if (!m_archiver || !printer_diff.empty()) {
|
if (!m_archiver || !printer_diff.empty())
|
||||||
if (m_printer_config.sla_archive_format.value == "SL1")
|
m_archiver = SLAArchive::create(m_printer_config.sla_archive_format.value.c_str(), m_printer_config);
|
||||||
m_archiver = std::make_unique<SL1Archive>(m_printer_config);
|
|
||||||
else if (m_printer_config.sla_archive_format.value == "SL2")
|
|
||||||
m_archiver = std::make_unique<SL1_SVGArchive>(m_printer_config);
|
|
||||||
else if (m_printer_config.sla_archive_format.value == "pwmx") {
|
|
||||||
m_archiver = std::make_unique<PwmxArchive>(m_printer_config);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ModelObjectStatus {
|
struct ModelObjectStatus {
|
||||||
enum Status {
|
enum Status {
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include "Point.hpp"
|
#include "Point.hpp"
|
||||||
#include "MTUtils.hpp"
|
#include "MTUtils.hpp"
|
||||||
#include "Zipper.hpp"
|
#include "Zipper.hpp"
|
||||||
|
#include "Format/SLAArchive.hpp"
|
||||||
#include "GCode/ThumbnailData.hpp"
|
#include "GCode/ThumbnailData.hpp"
|
||||||
|
|
||||||
#include "libslic3r/Execution/ExecutionTBB.hpp"
|
#include "libslic3r/Execution/ExecutionTBB.hpp"
|
||||||
@ -390,45 +391,6 @@ struct SLAPrintStatistics
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class SLAArchive {
|
|
||||||
protected:
|
|
||||||
std::vector<sla::EncodedRaster> m_layers;
|
|
||||||
|
|
||||||
virtual std::unique_ptr<sla::RasterBase> create_raster() const = 0;
|
|
||||||
virtual sla::RasterEncoder get_encoder() const = 0;
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual ~SLAArchive() = default;
|
|
||||||
|
|
||||||
// Fn have to be thread safe: void(sla::RasterBase& raster, size_t lyrid);
|
|
||||||
template<class Fn, class CancelFn, class EP = ExecutionTBB>
|
|
||||||
void draw_layers(
|
|
||||||
size_t layer_num,
|
|
||||||
Fn && drawfn,
|
|
||||||
CancelFn cancelfn = []() { return false; },
|
|
||||||
const EP & ep = {})
|
|
||||||
{
|
|
||||||
m_layers.resize(layer_num);
|
|
||||||
execution::for_each(
|
|
||||||
ep, size_t(0), m_layers.size(),
|
|
||||||
[this, &drawfn, &cancelfn](size_t idx) {
|
|
||||||
if (cancelfn()) return;
|
|
||||||
|
|
||||||
sla::EncodedRaster &enc = m_layers[idx];
|
|
||||||
auto rst = create_raster();
|
|
||||||
drawfn(*rst, idx);
|
|
||||||
enc = rst->encode(get_encoder());
|
|
||||||
},
|
|
||||||
execution::max_concurrency(ep));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Export the print into an archive using the provided filename.
|
|
||||||
virtual void export_print(const std::string fname,
|
|
||||||
const SLAPrint &print,
|
|
||||||
const ThumbnailsList &thumbnails,
|
|
||||||
const std::string &projectname = "") = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This class is the high level FSM for the SLA printing process.
|
* @brief This class is the high level FSM for the SLA printing process.
|
||||||
*
|
*
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "SLAImportJob.hpp"
|
#include "SLAImportJob.hpp"
|
||||||
|
|
||||||
|
#include "libslic3r/SLAPrint.hpp"
|
||||||
#include "libslic3r/Format/SL1.hpp"
|
#include "libslic3r/Format/SL1.hpp"
|
||||||
|
|
||||||
#include "slic3r/GUI/GUI.hpp"
|
#include "slic3r/GUI/GUI.hpp"
|
||||||
|
@ -4,4 +4,6 @@ target_link_libraries(${_TEST_NAME}_tests test_common libnest2d )
|
|||||||
set_property(TARGET ${_TEST_NAME}_tests PROPERTY FOLDER "tests")
|
set_property(TARGET ${_TEST_NAME}_tests PROPERTY FOLDER "tests")
|
||||||
|
|
||||||
# catch_discover_tests(${_TEST_NAME}_tests TEST_PREFIX "${_TEST_NAME}: ")
|
# catch_discover_tests(${_TEST_NAME}_tests TEST_PREFIX "${_TEST_NAME}: ")
|
||||||
add_test(${_TEST_NAME}_tests ${_TEST_NAME}_tests "${CATCH_EXTRA_ARGS} exclude:[NotWorking]")
|
set(_catch_args "exclude:[NotWorking]")
|
||||||
|
list(APPEND _catch_args "${CATCH_EXTRA_ARGS}")
|
||||||
|
add_test(${_TEST_NAME}_tests ${_TEST_NAME}_tests ${_catch_args})
|
||||||
|
@ -3,7 +3,8 @@ add_executable(${_TEST_NAME}_tests ${_TEST_NAME}_tests_main.cpp
|
|||||||
sla_print_tests.cpp
|
sla_print_tests.cpp
|
||||||
sla_test_utils.hpp sla_test_utils.cpp
|
sla_test_utils.hpp sla_test_utils.cpp
|
||||||
sla_supptgen_tests.cpp
|
sla_supptgen_tests.cpp
|
||||||
sla_raycast_tests.cpp)
|
sla_raycast_tests.cpp
|
||||||
|
sla_archive_export_tests.cpp)
|
||||||
target_link_libraries(${_TEST_NAME}_tests test_common libslic3r)
|
target_link_libraries(${_TEST_NAME}_tests test_common libslic3r)
|
||||||
set_property(TARGET ${_TEST_NAME}_tests PROPERTY FOLDER "tests")
|
set_property(TARGET ${_TEST_NAME}_tests PROPERTY FOLDER "tests")
|
||||||
|
|
||||||
|
37
tests/sla_print/sla_archive_export_tests.cpp
Normal file
37
tests/sla_print/sla_archive_export_tests.cpp
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#include <catch2/catch.hpp>
|
||||||
|
#include <test_utils.hpp>
|
||||||
|
|
||||||
|
#include "libslic3r/SLAPrint.hpp"
|
||||||
|
#include "libslic3r/Format/SLAArchive.hpp"
|
||||||
|
|
||||||
|
#include <boost/filesystem.hpp>
|
||||||
|
|
||||||
|
using namespace Slic3r;
|
||||||
|
|
||||||
|
TEST_CASE("Archive export test", "[sla_archives]") {
|
||||||
|
constexpr const char *PNAME = "20mm_cube";
|
||||||
|
|
||||||
|
for (auto &archname : SLAArchive::registered_archives()) {
|
||||||
|
INFO(std::string("Testing archive type: ") + archname);
|
||||||
|
SLAPrint print;
|
||||||
|
SLAFullPrintConfig fullcfg;
|
||||||
|
|
||||||
|
auto m = Model::read_from_file(TEST_DATA_DIR PATH_SEPARATOR + std::string(PNAME) + ".obj", nullptr);
|
||||||
|
|
||||||
|
fullcfg.set("sla_archive_format", archname);
|
||||||
|
|
||||||
|
DynamicPrintConfig cfg;
|
||||||
|
cfg.apply(fullcfg);
|
||||||
|
|
||||||
|
print.apply(m, cfg);
|
||||||
|
print.process();
|
||||||
|
|
||||||
|
ThumbnailsList thumbnails;
|
||||||
|
auto outputfname = std::string("output.") + SLAArchive::get_extension(archname);
|
||||||
|
|
||||||
|
print.export_print(outputfname, thumbnails, PNAME);
|
||||||
|
|
||||||
|
// Not much can be checked about the archives...
|
||||||
|
REQUIRE(boost::filesystem::exists(outputfname));
|
||||||
|
}
|
||||||
|
}
|
@ -15,4 +15,6 @@ if (WIN32)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
# catch_discover_tests(${_TEST_NAME}_tests TEST_PREFIX "${_TEST_NAME}: ")
|
# catch_discover_tests(${_TEST_NAME}_tests TEST_PREFIX "${_TEST_NAME}: ")
|
||||||
add_test(${_TEST_NAME}_tests ${_TEST_NAME}_tests "${CATCH_EXTRA_ARGS} exclude:[NotWorking]")
|
set(_catch_args "exclude:[NotWorking]")
|
||||||
|
list(APPEND _catch_args "${CATCH_EXTRA_ARGS}")
|
||||||
|
add_test(${_TEST_NAME}_tests ${_TEST_NAME}_tests ${_catch_args})
|
||||||
|
Loading…
Reference in New Issue
Block a user