Simulation of extrusion in a plane, useful for finding out under / over-extruions.

This commit is contained in:
bubnikv 2016-04-11 17:10:13 +02:00
parent 9716ee8eca
commit ed83ff37f8
3 changed files with 1155 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,60 @@
#ifndef slic3r_ExtrusionSimulator_hpp_
#define slic3r_ExtrusionSimulator_hpp_
#include "libslic3r.h"
#include "Config.hpp"
#include "ExtrusionEntity.hpp"
#include "BoundingBox.hpp"
namespace Slic3r {
enum ExtrusionSimulationType
{
ExtrusionSimulationSimple,
ExtrusionSimulationDontSpread,
ExtrisopmSimulationSpreadNotOverfilled,
ExtrusionSimulationSpreadFull,
ExtrusionSimulationSpreadExcess,
};
// An opaque class, to keep the boost stuff away from the header.
class ExtrusionSimulatorImpl;
class ExtrusionSimulator
{
public:
ExtrusionSimulator();
~ExtrusionSimulator();
// Size of the image, that will be returned by image_ptr().
// The image may be bigger than the viewport as many graphics drivers
// expect the size of a texture to be rounded to a power of two.
void set_image_size(const Point &image_size);
// Which part of the image shall be rendered to?
void set_viewport(const BoundingBox &viewport);
// Shift and scale of the rendered extrusion paths into the viewport.
void set_bounding_box(const BoundingBox &bbox);
// Reset the extrusion accumulator to zero for all buckets.
void reset_accumulator();
// Paint a thick path into an extrusion buffer.
// A simple implementation is provided now, splatting a rectangular extrusion for each linear segment.
// In the future, spreading and suqashing of a material will be simulated.
void extrude_to_accumulator(const ExtrusionPath &path, const Point &shift, ExtrusionSimulationType simulationType);
// Evaluate the content of the accumulator and paint it into the viewport.
// After this call the image_ptr() call will return a valid image.
void evaluate_accumulator(ExtrusionSimulationType simulationType);
// An RGBA image of image_size, to be loaded into a GPU texture.
const void* image_ptr() const;
private:
Point image_size;
BoundingBox viewport;
BoundingBox bbox;
ExtrusionSimulatorImpl *pimpl;
};
}
#endif /* slic3r_ExtrusionSimulator_hpp_ */

View File

@ -0,0 +1,50 @@
%module{Slic3r::XS};
%{
#include <xsinit.h>
#include "libslic3r/ExtrusionSimulator.hpp"
%}
%name{Slic3r::ExtrusionSimulator} class ExtrusionSimulator {
~ExtrusionSimulator();
%name{_new} ExtrusionSimulator();
Clone<ExtrusionSimulator> clone()
%code{% RETVAL = THIS; %};
void set_image_size(Point *image_size)
%code{% THIS->set_image_size(*image_size); %};
void set_viewport(BoundingBox *viewport)
%code{% THIS->set_viewport(*viewport); %};
void set_bounding_box(BoundingBox *bbox)
%code{% THIS->set_bounding_box(*bbox); %};
void reset_accumulator();
void extrude_to_accumulator(ExtrusionPath *path, Point *shift, ExtrusionSimulationType simulationType)
%code{% THIS->extrude_to_accumulator(*path, *shift, simulationType); %};
void evaluate_accumulator(ExtrusionSimulationType simulationType);
void* image_ptr()
%code{% RETVAL = const_cast<void*>(const_cast<Slic3r::ExtrusionSimulator*>(THIS)->image_ptr()); %};
%{
%}
};
%package{Slic3r::ExtrusionSimulator};
%{
IV
_constant()
ALIAS:
EXTRSIM_SIMPLE = ExtrusionSimulationSimple
EXTRSIM_DONT_SPREAD = ExtrusionSimulationDontSpread
EXTRSIM_SPREAD_NFULL = ExtrisopmSimulationSpreadNotOverfilled
EXTRSIM_SPREAD_FULL = ExtrusionSimulationSpreadFull
EXTRSIM_SPREAD_EXCESS = ExtrusionSimulationSpreadExcess
PROTOTYPE:
CODE:
RETVAL = ix;
OUTPUT: RETVAL
%}