Fixing the broken rasterizer.

Paths and holes cannot be added separately.
This commit is contained in:
tamasmeszaros 2019-04-01 12:15:47 +02:00
parent 4eb5d91a8f
commit 2baa651f1e
3 changed files with 61 additions and 18 deletions

View file

@ -331,8 +331,15 @@ inline std::vector<PolygonImpl> clipper_execute(
auto processPoly = [&retv, &processHole](ClipperLib::PolyNode *pptr) { auto processPoly = [&retv, &processHole](ClipperLib::PolyNode *pptr) {
PolygonImpl poly; PolygonImpl poly;
poly.Contour.swap(pptr->Contour); auto front_p = poly.Contour.front(); poly.Contour.swap(pptr->Contour);
poly.Contour.emplace_back(std::move(front_p));
assert(!pptr->IsHole());
if(pptr->IsOpen()) {
auto front_p = poly.Contour.front();
poly.Contour.emplace_back(front_p);
}
for(auto h : pptr->Childs) { processHole(h, poly); } for(auto h : pptr->Childs) { processHole(h, poly); }
retv.push_back(poly); retv.push_back(poly);
}; };
@ -340,8 +347,14 @@ inline std::vector<PolygonImpl> clipper_execute(
processHole = [&processPoly](ClipperLib::PolyNode *pptr, PolygonImpl& poly) processHole = [&processPoly](ClipperLib::PolyNode *pptr, PolygonImpl& poly)
{ {
poly.Holes.emplace_back(std::move(pptr->Contour)); poly.Holes.emplace_back(std::move(pptr->Contour));
auto front_p = poly.Holes.back().front();
poly.Holes.back().emplace_back(std::move(front_p)); assert(pptr->IsHole());
if(pptr->IsOpen()) {
auto front_p = poly.Holes.back().front();
poly.Holes.back().emplace_back(front_p);
}
for(auto c : pptr->Childs) processPoly(c); for(auto c : pptr->Childs) processPoly(c);
}; };

View file

@ -71,16 +71,41 @@ public:
clear(); clear();
} }
template<class Geometry> inline void draw(const Geometry &poly) { void draw(const ExPolygon &poly) {
agg::rasterizer_scanline_aa<> ras; agg::rasterizer_scanline_aa<> ras;
agg::scanline_p8 scanlines; agg::scanline_p8 scanlines;
auto&& path = to_path(poly); auto&& path = to_path(poly.contour);
if(m_o == Origin::TOP_LEFT) flipy(path); if(m_o == Origin::TOP_LEFT) flipy(path);
ras.add_path(path); ras.add_path(path);
for(auto h : poly.holes) {
auto&& holepath = to_path(h);
if(m_o == Origin::TOP_LEFT) flipy(holepath);
ras.add_path(holepath);
}
agg::render_scanlines(ras, scanlines, m_renderer);
}
void draw(const ClipperLib::Polygon &poly) {
agg::rasterizer_scanline_aa<> ras;
agg::scanline_p8 scanlines;
auto&& path = to_path(poly.Contour);
if(m_o == Origin::TOP_LEFT) flipy(path);
ras.add_path(path);
for(auto h : poly.Holes) {
auto&& holepath = to_path(h);
if(m_o == Origin::TOP_LEFT) flipy(holepath);
ras.add_path(holepath);
}
agg::render_scanlines(ras, scanlines, m_renderer); agg::render_scanlines(ras, scanlines, m_renderer);
} }
@ -186,14 +211,12 @@ void Raster::clear()
void Raster::draw(const ExPolygon &expoly) void Raster::draw(const ExPolygon &expoly)
{ {
m_impl->draw(expoly.contour); m_impl->draw(expoly);
for(auto& h : expoly.holes) m_impl->draw(h);
} }
void Raster::draw(const ClipperLib::Polygon &poly) void Raster::draw(const ClipperLib::Polygon &poly)
{ {
m_impl->draw(poly.Contour); m_impl->draw(poly);
for(auto& h : poly.Holes) m_impl->draw(h);
} }
void Raster::save(std::ostream& stream, Compression comp) void Raster::save(std::ostream& stream, Compression comp)

View file

@ -1084,9 +1084,15 @@ void SLAPrint::process()
SpinMutex mutex; SpinMutex mutex;
using Lock = std::lock_guard<SpinMutex>; using Lock = std::lock_guard<SpinMutex>;
// for (PrintLayer& layer : m_printer_input) // Going to parallel:
auto printlayerfn = [this, get_all_polygons, polyunion, polydiff, areafn, area_fill, display_area, exp_time, init_exp_time, fast_tilt, slow_tilt, delta_fade_time, auto printlayerfn = [this,
&mutex, &models_volume, &supports_volume, &estim_time, &slow_layers, &fast_layers, &fade_layer_time](size_t sliced_layer_cnt) // functions and read only vars
get_all_polygons, polyunion, polydiff, areafn,
area_fill, display_area, exp_time, init_exp_time, fast_tilt, slow_tilt, delta_fade_time,
// write vars
&mutex, &models_volume, &supports_volume, &estim_time, &slow_layers,
&fast_layers, &fade_layer_time](size_t sliced_layer_cnt)
{ {
PrintLayer& layer = m_printer_input[sliced_layer_cnt]; PrintLayer& layer = m_printer_input[sliced_layer_cnt];
@ -1141,9 +1147,9 @@ void SLAPrint::process()
} }
if(!supports_polygons.empty()) { if(!supports_polygons.empty()) {
/*if(model_polygons.empty()) */supports_polygons = polyunion(supports_polygons); if(model_polygons.empty()) supports_polygons = polyunion(supports_polygons);
/*else */ if(!model_polygons.empty())supports_polygons = polydiff(supports_polygons, model_polygons); else supports_polygons = polydiff(supports_polygons, model_polygons);
// allegedly, union of subject is done withing the diff // allegedly, union of subject is done withing the diff according to the pftPositive polyFillType
} }
double layer_support_area = 0; double layer_support_area = 0;
@ -1190,8 +1196,9 @@ void SLAPrint::process()
} }
}; };
for(size_t i = 0; i < m_printer_input.size(); ++i) printlayerfn(i); // sequential version for debugging:
// tbb::parallel_for<size_t, decltype(printlayerfn)>(0, m_printer_input.size(), printlayerfn); // for(size_t i = 0; i < m_printer_input.size(); ++i) printlayerfn(i);
tbb::parallel_for<size_t, decltype(printlayerfn)>(0, m_printer_input.size(), printlayerfn);
m_print_statistics.support_used_material = supports_volume * SCALING_FACTOR * SCALING_FACTOR; m_print_statistics.support_used_material = supports_volume * SCALING_FACTOR * SCALING_FACTOR;
m_print_statistics.objects_used_material = models_volume * SCALING_FACTOR * SCALING_FACTOR; m_print_statistics.objects_used_material = models_volume * SCALING_FACTOR * SCALING_FACTOR;