Model centered when exporting to png. Added some comments to the rasterization.

This commit is contained in:
tamasmeszaros 2018-05-21 13:46:41 +02:00
parent 0f552832da
commit 6b5c0073a7
4 changed files with 122 additions and 81 deletions

View file

@ -1,4 +1,6 @@
#include "Rasterizer.hpp"
#include <ExPolygon.hpp>
#include <cstdint>
// For rasterizing
@ -14,7 +16,7 @@
#include <agg/agg_rasterizer_scanline_aa.h>
#include <agg/agg_path_storage.h>
// For compression
// For png compression
#ifdef WIN32
inline char *strerror_r(int errnum, char *buf, size_t buflen) {
strerror_s(buf, buflen, errnum);
@ -70,9 +72,12 @@ public:
agg::rasterizer_scanline_aa<> ras;
agg::scanline_p8 scanlines;
ras.add_path(to_path(poly.contour));
auto&& path = to_path(poly.contour);
ras.add_path(path);
for(auto h : poly.holes) {
ras.add_path(to_path(h));
auto&& holepath = to_path(h);
ras.add_path(holepath);
}
agg::render_scanlines(ras, scanlines, renderer_);

View file

@ -2,20 +2,32 @@
#define RASTERIZER_HPP
#include <ostream>
#include <ExPolygon.hpp>
#include <memory>
namespace Slic3r {
class ExPolygon;
/**
* @brief Raster captures an antialiased monochrome canvas where vectorial
* polygons can be rasterized. Fill color is always white and the background is
* black. Countours are antialiased.
*
* It also supports saving the raster data into a standard output stream in raw
* or PNG format.
*/
class Raster {
class Impl;
std::unique_ptr<Impl> impl_;
public:
/// Supported compression types
enum class Compression {
RAW,
PNG
RAW, //!> Uncompressed pixel data
PNG //!> PNG compression
};
/// Type that represents a resolution in pixels.
struct Resolution {
unsigned width_px;
unsigned height_px;
@ -25,6 +37,7 @@ public:
}
};
/// Types that represents the dimension of a pixel in millimeters.
struct PixelDim {
double w_mm;
double h_mm;
@ -32,22 +45,32 @@ public:
w_mm(px_width_mm), h_mm(px_height_mm) {}
};
/// Constructor taking the resolution and the pixel dimension.
explicit Raster(const Resolution& r, const PixelDim& pd );
Raster();
~Raster();
Raster(const Raster& cpy);
Raster(Raster&& m);
~Raster();
/// Reallocated everything for the given resolution and pixel dimension.
void reset(const Resolution& r, const PixelDim& pd);
/**
* Release the allocated resources. Drawing in this state ends in
* unspecified behaviour.
*/
void reset();
/// Get the resolution of the raster.
Resolution resolution() const;
/// Clear the raster with black color.
void clear();
/// Draw a polygon with holes.
void draw(const ExPolygon& poly);
/// Save the raster on the specified stream.
void save(std::ostream& stream, Compression comp = Compression::RAW);
};