Further optimizations for SLA memory usage.

This commit is contained in:
tamasmeszaros 2019-04-25 18:48:31 +02:00
parent 17100ef2fe
commit afbe0d9e60
4 changed files with 36 additions and 26 deletions

View file

@ -248,20 +248,21 @@ RawBytes Raster::save(Raster::Compression comp)
{
assert(m_impl);
std::uint8_t *ptr = nullptr; size_t s = 0;
std::vector<std::uint8_t> data; size_t s = 0;
switch(comp) {
case Compression::PNG: {
void *rawdata = tdefl_write_image_to_png_file_in_memory(
m_impl->buffer().data(),
int(resolution().width_px),
int(resolution().height_px), 1, &s);
if(rawdata == nullptr) break;
ptr = static_cast<std::uint8_t*>(rawdata);
auto ptr = static_cast<std::uint8_t*>(rawdata);
data.reserve(s); std::copy(ptr, ptr + s, std::back_inserter(data));
MZ_FREE(rawdata);
break;
}
case Compression::RAW: {
@ -270,21 +271,19 @@ RawBytes Raster::save(Raster::Compression comp)
std::to_string(m_impl->resolution().height_px) + " " + "255 ";
auto sz = m_impl->buffer().size()*sizeof(Impl::TBuffer::value_type);
s = sz + header.size();
ptr = static_cast<std::uint8_t*>(MZ_MALLOC(s));
data.reserve(s);
auto buff = reinterpret_cast<std::uint8_t*>(m_impl->buffer().data());
std::copy(buff, buff+sz, ptr + header.size());
std::copy(header.begin(), header.end(), std::back_inserter(data));
std::copy(buff, buff+sz, std::back_inserter(data));
break;
}
}
return {ptr, s};
}
void RawBytes::MinzDeleter::operator()(uint8_t *rawptr)
{
MZ_FREE(rawptr);
return {std::move(data)};
}
}

View file

@ -15,18 +15,12 @@ class ExPolygon;
// Raw byte buffer paired with its size. Suitable for compressed PNG data.
class RawBytes {
class MinzDeleter {
public:
void operator()(std::uint8_t *rawptr);
};
std::vector<std::uint8_t> m_buffer;
public:
RawBytes() = default;
RawBytes(std::uint8_t *rawptr, size_t s): m_buffer(rawptr, rawptr + s) { MinzDeleter()(rawptr); }
RawBytes(std::vector<std::uint8_t>&& data): m_buffer(std::move(data)) {}
size_t size() const { return m_buffer.size(); }
const uint8_t * data() { return m_buffer.data(); }

View file

@ -846,6 +846,16 @@ public:
if(!meshcache_valid) merged_mesh();
return model_height;
}
// Intended to be called after the generation is fully complete
void clear_support_data() {
merged_mesh(); // in case the mesh is not generated, it should be...
m_heads.clear();
m_pillars.clear();
m_junctions.clear();
m_bridges.clear();
m_compact_bridges.clear();
}
};
@ -2285,6 +2295,7 @@ SLASupportTree::SLASupportTree(const std::vector<SupportPoint> &points,
{
m_impl->ground_level = emesh.ground_level() - cfg.object_elevation_mm;
generate(points, emesh, cfg, ctl);
m_impl->clear_support_data();
}
SLASupportTree::SLASupportTree(const SLASupportTree &c):

View file

@ -436,6 +436,12 @@ SLAPrint::ApplyStatus SLAPrint::apply(const Model &model, const DynamicPrintConf
if (new_objects)
update_apply_status(false);
}
if(m_objects.empty()) {
m_printer.release();
m_printer_input.clear();
m_print_statistics.clear();
}
#ifdef _DEBUG
check_model_ids_equal(m_model, model);
@ -669,7 +675,7 @@ void SLAPrint::process()
// Slicing the model object. This method is oversimplified and needs to
// be compared with the fff slicing algorithm for verification
auto slice_model = [this, ilhs, ilh](SLAPrintObject& po) {
TriangleMesh mesh = po.transformed_mesh();
const TriangleMesh& mesh = po.transformed_mesh();
// We need to prepare the slice index...
@ -708,7 +714,7 @@ void SLAPrint::process()
po.m_model_height_levels.emplace_back(it->slice_level());
}
mesh.require_shared_vertices(); // TriangleMeshSlicer needs this
// mesh.require_shared_vertices(); // TriangleMeshSlicer needs this
TriangleMeshSlicer slicer(&mesh);
po.m_model_slices.clear();
@ -1534,7 +1540,7 @@ SLAPrintObject::SLAPrintObject(SLAPrint *print, ModelObject *model_object):
Inherited(print, model_object),
m_stepmask(slaposCount, true),
m_transformed_rmesh( [this](TriangleMesh& obj){
obj = m_model_object->raw_mesh(); obj.transform(m_trafo);
obj = m_model_object->raw_mesh(); obj.transform(m_trafo); obj.require_shared_vertices();
})
{
}