Merge branch 'et_adaptive_layer_height_2' of https://github.com/prusa3d/PrusaSlicer

This commit is contained in:
Enrico Turri 2019-12-02 12:47:15 +01:00
commit 89c42063de
2 changed files with 12 additions and 14 deletions

View File

@ -37,15 +37,14 @@ void SlicingAdaptive::prepare()
m_mesh = m_object->raw_mesh();
const ModelInstance* first_instance = m_object->instances.front();
m_mesh.transform(first_instance->get_matrix(), first_instance->is_left_handed());
for (stl_facet& facet : m_mesh.stl.facet_start)
{
facet.normal.normalize();
}
// 1) Collect faces from mesh.
m_faces.reserve(m_mesh.stl.stats.number_of_facets);
for (const stl_facet& face : m_mesh.stl.facet_start)
for (stl_facet& face : m_mesh.stl.facet_start)
{
face.normal.normalize();
m_faces.emplace_back(&face);
}
#else
// 1) Collect faces of all meshes.
int nfaces_total = 0;
@ -58,14 +57,10 @@ void SlicingAdaptive::prepare()
#endif // ENABLE_ADAPTIVE_LAYER_HEIGHT_PROFILE
// 2) Sort faces lexicographically by their Z span.
std::sort(m_faces.begin(), m_faces.end(), [](const stl_facet *f1, const stl_facet *f2) {
std::pair<float, float> span1 = face_z_span(f1);
std::pair<float, float> span2 = face_z_span(f2);
return span1 < span2;
});
std::sort(m_faces.begin(), m_faces.end(), [](const stl_facet *f1, const stl_facet *f2) { return face_z_span(f1) < face_z_span(f2); });
// 3) Generate Z components of the facet normals.
m_face_normal_z.assign(m_faces.size(), 0.f);
m_face_normal_z.assign(m_faces.size(), 0.0f);
for (size_t iface = 0; iface < m_faces.size(); ++ iface)
m_face_normal_z[iface] = m_faces[iface]->normal(2);
}
@ -115,7 +110,7 @@ float SlicingAdaptive::cusp_height(float z, float cusp_value, int &current_facet
// Compute cusp-height for this facet and check against height.
float normal_z = m_face_normal_z[ordered_id];
float cusp = (normal_z == 0.0f) ? (float)m_slicing_params.max_layer_height : abs(cusp_value / normal_z);
float cusp = (normal_z == 0.0f) ? (float)m_slicing_params.max_layer_height : std::abs(cusp_value / normal_z);
float z_diff = zspan.first - z;

View File

@ -640,6 +640,7 @@ void GLCanvas3D::LayersEditing::reset_layer_height_profile(GLCanvas3D& canvas)
#if ENABLE_ADAPTIVE_LAYER_HEIGHT_PROFILE
void GLCanvas3D::LayersEditing::adaptive_layer_height_profile(GLCanvas3D& canvas, float cusp)
{
this->update_slicing_parameters();
m_layer_height_profile = layer_height_profile_adaptive(*m_slicing_parameters, *m_model_object, cusp);
const_cast<ModelObject*>(m_model_object)->layer_height_profile = m_layer_height_profile;
m_layers_texture.valid = false;
@ -648,6 +649,8 @@ void GLCanvas3D::LayersEditing::adaptive_layer_height_profile(GLCanvas3D& canvas
void GLCanvas3D::LayersEditing::smooth_layer_height_profile(GLCanvas3D& canvas, const HeightProfileSmoothingParams& smoothing_params)
{
this->update_slicing_parameters();
m_layer_height_profile = smooth_height_profile(m_layer_height_profile, *m_slicing_parameters, smoothing_params);
const_cast<ModelObject*>(m_model_object)->layer_height_profile = m_layer_height_profile;
m_layers_texture.valid = false;