Support for user definable variable layer thickness, the C++ backend.

This commit is contained in:
bubnikv 2016-12-12 17:53:38 +01:00
parent 2ab86a4895
commit 1ea958158a
7 changed files with 924 additions and 44 deletions

View file

@ -22,22 +22,13 @@ std::pair<float, float> face_z_span(const stl_facet *f)
void SlicingAdaptive::prepare()
{
// 1) Collect faces of all meshes.
{
int nfaces_total = 0;
for (std::vector<const TriangleMesh*>::const_iterator it_mesh = m_meshes.begin(); it_mesh != m_meshes.end(); ++ it_mesh)
nfaces_total += (*it_mesh)->stl.stats.number_of_facets;
m_faces.reserve(nfaces_total);
}
m_max_z = 0;
for (std::vector<const TriangleMesh*>::const_iterator it_mesh = m_meshes.begin(); it_mesh != m_meshes.end(); ++ it_mesh) {
const stl_facet *faces = (*it_mesh)->stl.facet_start;
int nfaces = (*it_mesh)->stl.stats.number_of_facets;
for (int i = 0; i < nfaces; ++ i) {
const stl_facet *facet = faces + i;
m_faces.push_back(facet);
m_max_z = std::max(std::max(m_max_z, facet->vertex[0].z), std::max(facet->vertex[1].z, facet->vertex[2].z));
}
}
int nfaces_total = 0;
for (std::vector<const TriangleMesh*>::const_iterator it_mesh = m_meshes.begin(); it_mesh != m_meshes.end(); ++ it_mesh)
nfaces_total += (*it_mesh)->stl.stats.number_of_facets;
m_faces.reserve(nfaces_total);
for (std::vector<const TriangleMesh*>::const_iterator it_mesh = m_meshes.begin(); it_mesh != m_meshes.end(); ++ it_mesh)
for (int i = 0; i < (*it_mesh)->stl.stats.number_of_facets; ++ i)
m_faces.push_back((*it_mesh)->stl.facet_start + i);
// 2) Sort faces lexicographically by their Z span.
std::sort(m_faces.begin(), m_faces.end(), [](const stl_facet *f1, const stl_facet *f2) {
@ -54,7 +45,7 @@ void SlicingAdaptive::prepare()
float SlicingAdaptive::cusp_height(float z, float cusp_value, int &current_facet)
{
float height = m_layer_height_max;
float height = m_slicing_params.max_layer_height;
bool first_hit = false;
// find all facets intersecting the slice-layer
@ -81,10 +72,10 @@ float SlicingAdaptive::cusp_height(float z, float cusp_value, int &current_facet
}
// lower height limit due to printer capabilities
height = std::max(height, m_layer_height_min);
height = std::max(height, float(m_slicing_params.min_layer_height));
// check for sloped facets inside the determined layer and correct height if necessary
if (height > m_layer_height_min) {
if (height > m_slicing_params.min_layer_height) {
for (; ordered_id < int(m_faces.size()); ++ ordered_id) {
std::pair<float, float> zspan = face_z_span(m_faces[ordered_id]);
// facet's minimum is higher than slice_z + height -> end loop
@ -119,7 +110,7 @@ float SlicingAdaptive::cusp_height(float z, float cusp_value, int &current_facet
}
}
// lower height limit due to printer capabilities again
height = std::max(height, m_layer_height_min);
height = std::max(height, float(m_slicing_params.min_layer_height));
}
// Slic3r::debugf "cusp computation, layer-bottom at z:%f, cusp_value:%f, resulting layer height:%f\n", unscale $z, $cusp_value, $height;
@ -133,7 +124,7 @@ float SlicingAdaptive::horizontal_facet_distance(float z)
for (size_t i = 0; i < m_faces.size(); ++ i) {
std::pair<float, float> zspan = face_z_span(m_faces[i]);
// facet's minimum is higher than max forward distance -> end loop
if (zspan.first > z + m_layer_height_max)
if (zspan.first > z + m_slicing_params.max_layer_height)
break;
// min_z == max_z -> horizontal facet
if (zspan.first > z && zspan.first == zspan.second)
@ -141,9 +132,9 @@ float SlicingAdaptive::horizontal_facet_distance(float z)
}
// objects maximum?
return (z + m_layer_height_max > m_max_z) ?
std::max<float>(m_max_z - z, 0.f) :
m_layer_height_max;
return (z + m_slicing_params.max_layer_height > m_slicing_params.object_print_z_height()) ?
std::max<float>(m_slicing_params.object_print_z_height() - z, 0.f) :
m_slicing_params.max_layer_height;
}
}; // namespace Slic3r