Fixing broken statistics.

This commit is contained in:
tamasmeszaros 2019-03-26 16:45:04 +01:00
parent 4c972549fb
commit 4d8800bc8a
3 changed files with 19 additions and 18 deletions

View File

@ -670,9 +670,8 @@ void SLAPrint::process()
} }
// Just get the first record that is form the model: // Just get the first record that is form the model:
auto slindex_it = po.closest_slice_record( auto slindex_it =
po.m_slice_index, float(bb3d.min(Z)), po.closest_slice_record(po.m_slice_index, float(bb3d.min(Z)));
std::numeric_limits<float>::infinity());
if(slindex_it == po.m_slice_index.end()) if(slindex_it == po.m_slice_index.end())
throw std::runtime_error(L("Slicing had to be stopped " throw std::runtime_error(L("Slicing had to be stopped "
@ -1272,7 +1271,7 @@ void SLAPrint::fill_statistics()
int sliced_layer_cnt = 0; int sliced_layer_cnt = 0;
for (const SliceRecord& layer : highest_obj_slice_index) for (const SliceRecord& layer : highest_obj_slice_index)
{ {
const double l_height = (layer.print_level() == highest_obj_slice_index.begin()->print_level()) ? init_layer_height : layer_height; const auto l_height = double(layer.layer_height());
// Calculation of the consumed material // Calculation of the consumed material
@ -1283,9 +1282,8 @@ void SLAPrint::fill_statistics()
{ {
const SliceRecord *record = nullptr; const SliceRecord *record = nullptr;
{ {
const SliceRecord& slr = po->closest_slice_to_slice_level(layer.slice_level(), float(EPSILON)); const SliceRecord& slr = po->closest_slice_to_slice_level(layer.slice_level());
if (!slr.is_valid()) if (!slr.is_valid()) continue;
continue;
record = &slr; record = &slr;
} }

View File

@ -124,7 +124,7 @@ public:
// Returns the current layer height // Returns the current layer height
float layer_height() const { return m_height; } float layer_height() const { return m_height; }
bool is_valid() const { return std::isnan(m_slice_z); } bool is_valid() const { return ! std::isnan(m_slice_z); }
const SLAPrintObject* print_obj() const { return m_po; } const SLAPrintObject* print_obj() const { return m_po; }
@ -158,7 +158,10 @@ private:
// //
// This method can be used in const or non-const contexts as well. // This method can be used in const or non-const contexts as well.
template<class Container, class T> template<class Container, class T>
static auto closest_slice_record(Container& cont, T lvl, T eps) -> decltype (cont.begin()) static auto closest_slice_record(
Container& cont,
T lvl,
T eps = std::numeric_limits<T>::max()) -> decltype (cont.begin())
{ {
if(cont.empty()) return cont.end(); if(cont.empty()) return cont.end();
if(cont.size() == 1 && std::abs(level<T>(cont.front()) - lvl) > eps) if(cont.size() == 1 && std::abs(level<T>(cont.front()) - lvl) > eps)
@ -207,22 +210,22 @@ public:
// max_epsilon gives the allowable deviation of the returned slice record's // max_epsilon gives the allowable deviation of the returned slice record's
// level. // level.
const SliceRecord& closest_slice_to_print_level( const SliceRecord& closest_slice_to_print_level(
coord_t print_level, coord_t max_epsilon = coord_t(SCALED_EPSILON)) const coord_t print_level,
coord_t max_epsilon = std::numeric_limits<coord_t>::max()) const
{ {
auto it = closest_slice_record(m_slice_index, print_level, max_epsilon); auto it = closest_slice_record(m_slice_index, print_level, max_epsilon);
if (it == m_slice_index.end()) return SliceRecord::EMPTY; return it == m_slice_index.end() ? SliceRecord::EMPTY : *it;
return *it;
} }
// Search slice index for the closest slice to given slice_level. // Search slice index for the closest slice to given slice_level.
// max_epsilon gives the allowable deviation of the returned slice record's // max_epsilon gives the allowable deviation of the returned slice record's
// level. // level. Use SliceRecord::is_valid() to check the result.
const SliceRecord& closest_slice_to_slice_level( const SliceRecord& closest_slice_to_slice_level(
float slice_level, float max_epsilon = float(EPSILON)) const float slice_level,
float max_epsilon = std::numeric_limits<float>::max()) const
{ {
auto it = closest_slice_record(m_slice_index, slice_level, max_epsilon); auto it = closest_slice_record(m_slice_index, slice_level, max_epsilon);
if (it == m_slice_index.end()) return SliceRecord::EMPTY; return it == m_slice_index.end() ? SliceRecord::EMPTY : *it;
return *it;
} }
protected: protected:

View File

@ -5027,7 +5027,7 @@ void GLCanvas3D::_render_sla_slices() const
// Offset to avoid OpenGL Z fighting between the object's horizontal surfaces and the triangluated surfaces of the cuts. // Offset to avoid OpenGL Z fighting between the object's horizontal surfaces and the triangluated surfaces of the cuts.
double plane_shift_z = 0.002; double plane_shift_z = 0.002;
if (! slice_low.is_valid()) { if (slice_low.is_valid()) {
const ExPolygons& obj_bottom = slice_low.get_slice(soModel); const ExPolygons& obj_bottom = slice_low.get_slice(soModel);
const ExPolygons& sup_bottom = slice_low.get_slice(soSupport); const ExPolygons& sup_bottom = slice_low.get_slice(soSupport);
// calculate model bottom cap // calculate model bottom cap
@ -5038,7 +5038,7 @@ void GLCanvas3D::_render_sla_slices() const
bottom_sup_triangles = triangulate_expolygons_3d(sup_bottom, clip_min_z - plane_shift_z, true); bottom_sup_triangles = triangulate_expolygons_3d(sup_bottom, clip_min_z - plane_shift_z, true);
} }
if (! slice_high.is_valid()) { if (slice_high.is_valid()) {
const ExPolygons& obj_top = slice_high.get_slice(soModel); const ExPolygons& obj_top = slice_high.get_slice(soModel);
const ExPolygons& sup_top = slice_high.get_slice(soSupport); const ExPolygons& sup_top = slice_high.get_slice(soSupport);
// calculate model top cap // calculate model top cap