mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-18 04:08:02 -06:00
sla::Raster interface clarified and covered with tests.
Also renamed sla::SupportTreeAlgorithm to SupportTreeBuildsteps.
This commit is contained in:
parent
705e82ec8e
commit
be7428d66e
15 changed files with 484 additions and 361 deletions
|
@ -15,7 +15,8 @@
|
|||
|
||||
namespace Slic3r { namespace sla {
|
||||
|
||||
// Implementation for PNG raster output
|
||||
// API to write the zipped sla output layers and metadata.
|
||||
// Implementation uses PNG raster output.
|
||||
// Be aware that if a large number of layers are allocated, it can very well
|
||||
// exhaust the available memory especially on 32 bit platform.
|
||||
// This class is designed to be used in parallel mode. Layers have an ID and
|
||||
|
@ -25,10 +26,6 @@ namespace Slic3r { namespace sla {
|
|||
class RasterWriter
|
||||
{
|
||||
public:
|
||||
enum Orientation {
|
||||
roLandscape,
|
||||
roPortrait
|
||||
};
|
||||
|
||||
// Used for addressing parameters of set_statistics()
|
||||
struct PrintStatistics
|
||||
|
@ -45,7 +42,7 @@ private:
|
|||
// A struct to bind the raster image data and its compressed bytes together.
|
||||
struct Layer {
|
||||
Raster raster;
|
||||
RawBytes rawbytes;
|
||||
PNGImage rawbytes;
|
||||
|
||||
Layer() = default;
|
||||
|
||||
|
@ -61,22 +58,21 @@ private:
|
|||
// parallel. Later we can write every layer to the disk sequentially.
|
||||
std::vector<Layer> m_layers_rst;
|
||||
Raster::Resolution m_res;
|
||||
Raster::PixelDim m_pxdim;
|
||||
std::array<bool, 2> m_mirror;
|
||||
double m_gamma;
|
||||
|
||||
Raster::PixelDim m_pxdim;
|
||||
Raster::Trafo m_trafo;
|
||||
double m_gamma;
|
||||
|
||||
std::map<std::string, std::string> m_config;
|
||||
|
||||
std::string createIniContent(const std::string& projectname) const;
|
||||
|
||||
static void flpXY(ClipperLib::Polygon& poly);
|
||||
static void flpXY(ExPolygon& poly);
|
||||
|
||||
public:
|
||||
RasterWriter(const Raster::Resolution &res,
|
||||
const Raster::PixelDim &pixdim,
|
||||
const std::array<bool, 2> &mirror,
|
||||
double gamma = 1.);
|
||||
|
||||
// SLARasterWriter is using Raster in custom mirroring mode
|
||||
RasterWriter(const Raster::Resolution &res,
|
||||
const Raster::PixelDim & pixdim,
|
||||
const Raster::Trafo & trafo,
|
||||
double gamma = 1.);
|
||||
|
||||
RasterWriter(const RasterWriter& ) = delete;
|
||||
RasterWriter& operator=(const RasterWriter&) = delete;
|
||||
|
@ -86,45 +82,31 @@ public:
|
|||
inline void layers(unsigned cnt) { if(cnt > 0) m_layers_rst.resize(cnt); }
|
||||
inline unsigned layers() const { return unsigned(m_layers_rst.size()); }
|
||||
|
||||
template<class Poly> void draw_polygon(const Poly& p, unsigned lyr,
|
||||
Orientation o = roPortrait)
|
||||
template<class Poly> void draw_polygon(const Poly& p, unsigned lyr)
|
||||
{
|
||||
assert(lyr < m_layers_rst.size());
|
||||
|
||||
switch (o) {
|
||||
case roPortrait: {
|
||||
Poly poly(p);
|
||||
flpXY(poly);
|
||||
m_layers_rst[lyr].raster.draw(poly);
|
||||
break;
|
||||
}
|
||||
case roLandscape:
|
||||
m_layers_rst[lyr].raster.draw(p);
|
||||
break;
|
||||
}
|
||||
m_layers_rst[lyr].raster.draw(p);
|
||||
}
|
||||
|
||||
inline void begin_layer(unsigned lyr) {
|
||||
if(m_layers_rst.size() <= lyr) m_layers_rst.resize(lyr+1);
|
||||
m_layers_rst[lyr].raster.reset(m_res, m_pxdim, m_mirror, m_gamma);
|
||||
m_layers_rst[lyr].raster.reset(m_res, m_pxdim, m_trafo);
|
||||
}
|
||||
|
||||
inline void begin_layer() {
|
||||
m_layers_rst.emplace_back();
|
||||
m_layers_rst.front().raster.reset(m_res, m_pxdim, m_mirror, m_gamma);
|
||||
m_layers_rst.front().raster.reset(m_res, m_pxdim, m_trafo);
|
||||
}
|
||||
|
||||
inline void finish_layer(unsigned lyr_id) {
|
||||
assert(lyr_id < m_layers_rst.size());
|
||||
m_layers_rst[lyr_id].rawbytes =
|
||||
m_layers_rst[lyr_id].raster.save(Raster::Format::PNG);
|
||||
m_layers_rst[lyr_id].rawbytes.serialize(m_layers_rst[lyr_id].raster);
|
||||
m_layers_rst[lyr_id].raster.reset();
|
||||
}
|
||||
|
||||
inline void finish_layer() {
|
||||
if(!m_layers_rst.empty()) {
|
||||
m_layers_rst.back().rawbytes =
|
||||
m_layers_rst.back().raster.save(Raster::Format::PNG);
|
||||
m_layers_rst.back().rawbytes.serialize(m_layers_rst.back().raster);
|
||||
m_layers_rst.back().raster.reset();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue