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

@ -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);
};