Zipped output and tryfixes for linux and mac build.
This commit is contained in:
parent
e36164c76b
commit
73b861287c
2 changed files with 38 additions and 15 deletions
|
@ -12,11 +12,14 @@
|
||||||
#include <boost/lexical_cast.hpp>
|
#include <boost/lexical_cast.hpp>
|
||||||
#include <boost/log/trivial.hpp>
|
#include <boost/log/trivial.hpp>
|
||||||
|
|
||||||
|
|
||||||
// For png export of the sliced model
|
// For png export of the sliced model
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
#include <wx/stdstream.h>
|
||||||
|
#include <wx/wfstream.h>
|
||||||
|
#include <wx/zipstrm.h>
|
||||||
|
|
||||||
#include "Rasterizer/Rasterizer.hpp"
|
#include "Rasterizer/Rasterizer.hpp"
|
||||||
#include "tbb/parallel_for.h"
|
#include "tbb/parallel_for.h"
|
||||||
|
|
||||||
|
@ -1300,11 +1303,26 @@ public:
|
||||||
|
|
||||||
template<> // Implementation for PNG raster output
|
template<> // Implementation for PNG raster output
|
||||||
class FilePrinter<Print::FilePrinterFormat::PNG> {
|
class FilePrinter<Print::FilePrinterFormat::PNG> {
|
||||||
|
|
||||||
|
struct Layer {
|
||||||
|
Raster first;
|
||||||
|
std::stringstream second;
|
||||||
|
|
||||||
|
Layer() {}
|
||||||
|
Layer(const Raster::Resolution& res, const Raster::PixelDim& pd):
|
||||||
|
first(res, pd) {}
|
||||||
|
|
||||||
|
Layer(const Layer&) = delete;
|
||||||
|
Layer(Layer&& m):
|
||||||
|
first(std::move(m.first)), second(std::move(m.second)) {}
|
||||||
|
};
|
||||||
|
|
||||||
// We will save the compressed PNG data into stringstreams which can be done
|
// We will save the compressed PNG data into stringstreams which can be done
|
||||||
// in parallel. Later we can write every layer to the disk sequentially.
|
// in parallel. Later we can write every layer to the disk sequentially.
|
||||||
std::vector<std::pair<Raster, std::stringstream>> layers_rst_;
|
std::vector<Layer> layers_rst_;
|
||||||
Raster::Resolution res_;
|
Raster::Resolution res_;
|
||||||
Raster::PixelDim pxdim_;
|
Raster::PixelDim pxdim_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline FilePrinter(unsigned width_px, unsigned height_px,
|
inline FilePrinter(unsigned width_px, unsigned height_px,
|
||||||
double width_mm, double height_mm,
|
double width_mm, double height_mm,
|
||||||
|
@ -1355,25 +1373,28 @@ public:
|
||||||
|
|
||||||
inline void save(const std::string& path) {
|
inline void save(const std::string& path) {
|
||||||
|
|
||||||
|
wxFFileOutputStream zipfile(path + "zippedout.zip");
|
||||||
|
|
||||||
|
if(!zipfile.IsOk()) {
|
||||||
|
BOOST_LOG_TRIVIAL(error) << "Can't create zip file for layers!";
|
||||||
|
}
|
||||||
|
|
||||||
|
wxZipOutputStream zipstream(zipfile);
|
||||||
|
wxStdOutputStream pngstream(zipstream);
|
||||||
|
|
||||||
for(unsigned i = 0; i < layers_rst_.size(); i++) {
|
for(unsigned i = 0; i < layers_rst_.size(); i++) {
|
||||||
if(layers_rst_[i].second.rdbuf()->in_avail() > 0) {
|
if(layers_rst_[i].second.rdbuf()->in_avail() > 0) {
|
||||||
|
|
||||||
char lyrnum[6];
|
char lyrnum[6];
|
||||||
std::sprintf(lyrnum, "%.5d", i);
|
std::sprintf(lyrnum, "%.5d", i);
|
||||||
std::string loc = path + "layer" + lyrnum + ".png";
|
auto zfilename = std::string("layer") + lyrnum + ".png";
|
||||||
|
zipstream.PutNextEntry(zfilename);
|
||||||
std::fstream out(loc, std::fstream::out | std::fstream::binary);
|
pngstream << layers_rst_[i].second.rdbuf();
|
||||||
if(out.good()) {
|
|
||||||
out << layers_rst_[i].second.rdbuf();
|
|
||||||
} else {
|
|
||||||
BOOST_LOG_TRIVIAL(error) << "Can't create file for layer "
|
|
||||||
<< i;
|
|
||||||
}
|
|
||||||
|
|
||||||
out.close();
|
|
||||||
layers_rst_[i].second.str("");
|
layers_rst_[i].second.str("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
zipstream.Close();
|
||||||
|
zipfile.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveLayer(unsigned lyr, const std::string& path) {
|
void saveLayer(unsigned lyr, const std::string& path) {
|
||||||
|
|
|
@ -16,7 +16,9 @@
|
||||||
#include <agg/agg_path_storage.h>
|
#include <agg/agg_path_storage.h>
|
||||||
|
|
||||||
// For png compression
|
// For png compression
|
||||||
#if defined(WIN32) || defined(__APPLE__ )
|
#if !defined(__linux__) || \
|
||||||
|
(defined(__linux__) && ((_POSIX_C_SOURCE >= 200112L || \
|
||||||
|
_XOPEN_SOURCE >= 600) && ! _GNU_SOURCE))
|
||||||
inline char *strerror_r(int errnum, char *buf, size_t buflen) {
|
inline char *strerror_r(int errnum, char *buf, size_t buflen) {
|
||||||
strerror_s(buf, buflen, errnum);
|
strerror_s(buf, buflen, errnum);
|
||||||
return buf;
|
return buf;
|
||||||
|
|
Loading…
Reference in a new issue