Some optimizations of the color print preview.
This commit is contained in:
parent
d30676ceee
commit
460cf820af
@ -479,16 +479,13 @@ GCodePreviewData::LegendItemsList GCodePreviewData::get_legend_items(const std::
|
||||
}
|
||||
case Extrusion::ColorPrint:
|
||||
{
|
||||
const size_t color_cnt = tool_colors.size()/4;
|
||||
const int color_cnt = (int)tool_colors.size()/4;
|
||||
|
||||
const auto color_print_cnt = cp_values.size();
|
||||
for (size_t i = color_print_cnt; i >= 0 ; --i)
|
||||
const auto color_print_cnt = (int)cp_values.size();
|
||||
for (int i = color_print_cnt; i >= 0 ; --i)
|
||||
{
|
||||
size_t val = i;
|
||||
while (val >= color_cnt)
|
||||
val -= color_cnt;
|
||||
GCodePreviewData::Color color;
|
||||
::memcpy((void*)color.rgba, (const void*)(tool_colors.data() + val * 4), 4 * sizeof(float));
|
||||
::memcpy((void*)color.rgba, (const void*)(tool_colors.data() + (i % color_cnt) * 4), 4 * sizeof(float));
|
||||
|
||||
if (color_print_cnt == 0) {
|
||||
items.emplace_back(Slic3r::I18N::translate(L("Default print color")), color);
|
||||
|
@ -7288,31 +7288,15 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c
|
||||
const float* color_tool(size_t tool) const { return tool_colors->data() + tool * 4; }
|
||||
int volume_idx(int extruder, int feature) const
|
||||
{
|
||||
return this->color_by_tool() ? std::min<int>(this->number_tools() - 1, std::max<int>(extruder - 1, 0)) : feature;
|
||||
return this->color_by_color_print() ? 0 : this->color_by_tool() ? std::min<int>(this->number_tools() - 1, std::max<int>(extruder - 1, 0)) : feature;
|
||||
}
|
||||
|
||||
// For coloring by a color_print(M600), return a parsed color.
|
||||
bool color_by_color_print() const { return color_print_values!=nullptr; }
|
||||
const float* color_print_by_layer_idx(const size_t layer_idx) const
|
||||
{
|
||||
double z = layers[layer_idx]->print_z;
|
||||
size_t layer = 0;
|
||||
const size_t clr_change_cnt = color_print_values->size();
|
||||
for (size_t i = 0; i < clr_change_cnt; i++)
|
||||
{
|
||||
if (z < (*color_print_values)[i]-EPSILON) {
|
||||
layer = i;
|
||||
break;
|
||||
}
|
||||
if (layer == 0 && i == clr_change_cnt - 1)
|
||||
layer = clr_change_cnt;
|
||||
}
|
||||
|
||||
const size_t clr_cnt = number_tools();
|
||||
while (layer >= clr_cnt)
|
||||
layer -= clr_cnt;
|
||||
|
||||
return color_tool(layer);
|
||||
auto it = std::lower_bound(color_print_values->begin(), color_print_values->end(), layers[layer_idx]->print_z - EPSILON);
|
||||
return color_tool((it - color_print_values->begin()) % number_tools());
|
||||
}
|
||||
} ctxt;
|
||||
|
||||
|
@ -737,9 +737,12 @@ void Preview::load_print_as_fff()
|
||||
if (m_gcode_preview_data->extrusion.view_type == GCodePreviewData::Extrusion::ColorPrint)
|
||||
{
|
||||
colors = GCodePreviewData::ColorPrintColors();
|
||||
|
||||
const auto& config = wxGetApp().preset_bundle->full_config();
|
||||
color_print_values = config.option<ConfigOptionFloats>("colorprint_heights")->values;
|
||||
if (! gcode_preview_data_valid) {
|
||||
//FIXME accessing full_config() is pretty expensive.
|
||||
// Only initialize color_print_values for the initial preview, not for the full preview where the color_print_values is extracted from the G-code.
|
||||
const auto& config = wxGetApp().preset_bundle->full_config();
|
||||
color_print_values = config.option<ConfigOptionFloats>("colorprint_heights")->values;
|
||||
}
|
||||
}
|
||||
else if (gcode_preview_data_valid || (m_gcode_preview_data->extrusion.view_type == GCodePreviewData::Extrusion::Tool) )
|
||||
{
|
||||
@ -758,10 +761,9 @@ void Preview::load_print_as_fff()
|
||||
color = "#FFFFFF";
|
||||
}
|
||||
|
||||
colors.push_back(color);
|
||||
colors.emplace_back(color);
|
||||
}
|
||||
if (!color_print_values.empty())
|
||||
color_print_values.clear();
|
||||
color_print_values.clear();
|
||||
}
|
||||
|
||||
if (IsShown())
|
||||
|
Loading…
Reference in New Issue
Block a user