mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-30 20:21:12 -06:00 
			
		
		
		
	Removed the legacy PreviewData.cpp,hpp
This commit is contained in:
		
							parent
							
								
									4ad30ecdc0
								
							
						
					
					
						commit
						80e8b5e985
					
				
					 11 changed files with 0 additions and 942 deletions
				
			
		|  | @ -87,8 +87,6 @@ add_library(libslic3r STATIC | |||
|     GCode/PostProcessor.hpp | ||||
| #    GCode/PressureEqualizer.cpp | ||||
| #    GCode/PressureEqualizer.hpp | ||||
|     GCode/PreviewData.cpp | ||||
|     GCode/PreviewData.hpp | ||||
|     GCode/PrintExtents.cpp | ||||
|     GCode/PrintExtents.hpp | ||||
|     GCode/SpiralVase.cpp | ||||
|  |  | |||
|  | @ -2,8 +2,6 @@ | |||
| #include "Config.hpp" | ||||
| #if ENABLE_GCODE_VIEWER | ||||
| #include "GCode.hpp" | ||||
| #else | ||||
| #include "GCode/PreviewData.hpp" | ||||
| #endif // ENABLE_GCODE_VIEWER
 | ||||
| #include "GCodeWriter.hpp" | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,521 +0,0 @@ | |||
| #include "PreviewData.hpp" | ||||
| #include <I18N.hpp> | ||||
| #include "Utils.hpp" | ||||
| 
 | ||||
| #include <boost/format.hpp> | ||||
| 
 | ||||
| #if !ENABLE_GCODE_VIEWER | ||||
| 
 | ||||
| //! macro used to mark string used at localization, 
 | ||||
| #define L(s) (s) | ||||
| 
 | ||||
| namespace Slic3r { | ||||
| 
 | ||||
| std::vector<unsigned char> Color::as_bytes() const | ||||
| { | ||||
|     std::vector<unsigned char> ret; | ||||
|     for (unsigned int i = 0; i < 4; ++i) | ||||
|     { | ||||
|         ret.push_back((unsigned char)(255.0f * rgba[i])); | ||||
|     } | ||||
|     return ret; | ||||
| } | ||||
| 
 | ||||
| GCodePreviewData::Extrusion::Layer::Layer(float z, const Paths& paths) | ||||
|     : z(z) | ||||
|     , paths(paths) | ||||
| { | ||||
| } | ||||
| 
 | ||||
| GCodePreviewData::Travel::Polyline::Polyline(EType type, EDirection direction, float feedrate, unsigned int extruder_id, const Polyline3& polyline) | ||||
|     : type(type) | ||||
|     , direction(direction) | ||||
|     , feedrate(feedrate) | ||||
|     , extruder_id(extruder_id) | ||||
|     , polyline(polyline) | ||||
| { | ||||
| } | ||||
| 
 | ||||
| GCodePreviewData::Range::Range() | ||||
| { | ||||
|     reset(); | ||||
| } | ||||
| 
 | ||||
| void GCodePreviewData::Range::reset() | ||||
| { | ||||
|     min_val = FLT_MAX; | ||||
|     max_val = -FLT_MAX; | ||||
| } | ||||
| 
 | ||||
| bool GCodePreviewData::Range::empty() const | ||||
| { | ||||
|     return min_val >= max_val; | ||||
| } | ||||
| 
 | ||||
| void GCodePreviewData::Range::update_from(float value) | ||||
| { | ||||
|     min_val = std::min(min_val, value); | ||||
|     max_val = std::max(max_val, value); | ||||
| } | ||||
| 
 | ||||
| void GCodePreviewData::Range::update_from(const RangeBase& other) | ||||
| { | ||||
|     min_val = std::min(min_val, other.min()); | ||||
|     max_val = std::max(max_val, other.max()); | ||||
| } | ||||
| 
 | ||||
| float GCodePreviewData::RangeBase::step_size() const | ||||
| { | ||||
|     return (max() - min()) / static_cast<float>(range_rainbow_colors.size() - 1); | ||||
| } | ||||
| 
 | ||||
| Color GCodePreviewData::RangeBase::get_color_at(float value) const | ||||
| { | ||||
|     // Input value scaled to the color range
 | ||||
|     float step = step_size(); | ||||
|     const float global_t = (step != 0.0f) ? std::max(0.0f, value - min()) / step : 0.0f; // lower limit of 0.0f
 | ||||
| 
 | ||||
|     constexpr std::size_t color_max_idx = range_rainbow_colors.size() - 1; | ||||
| 
 | ||||
|     // Compute the two colors just below (low) and above (high) the input value
 | ||||
|     const std::size_t color_low_idx = std::clamp(static_cast<std::size_t>(global_t), std::size_t{ 0 }, color_max_idx); | ||||
|     const std::size_t color_high_idx = std::clamp(color_low_idx + 1, std::size_t{ 0 }, color_max_idx); | ||||
| 
 | ||||
|     // Compute how far the value is between the low and high colors so that they can be interpolated
 | ||||
|     const float local_t = std::min(global_t - static_cast<float>(color_low_idx), 1.0f); // upper limit of 1.0f
 | ||||
| 
 | ||||
|     // Interpolate between the low and high colors in RGB space to find exactly which color the input value should get
 | ||||
|     Color ret; | ||||
|     for (unsigned int i = 0; i < 4; ++i) | ||||
|     { | ||||
|         ret.rgba[i] = lerp(range_rainbow_colors[color_low_idx].rgba[i], range_rainbow_colors[color_high_idx].rgba[i], local_t); | ||||
|     } | ||||
|     return ret; | ||||
| } | ||||
| 
 | ||||
| float GCodePreviewData::Range::min() const | ||||
| { | ||||
|     return min_val; | ||||
| } | ||||
| 
 | ||||
| float GCodePreviewData::Range::max() const | ||||
| { | ||||
|     return max_val; | ||||
| } | ||||
| 
 | ||||
| GCodePreviewData::LegendItem::LegendItem(const std::string& text, const Color& color) | ||||
|     : text(text) | ||||
|     , color(color) | ||||
| { | ||||
| } | ||||
| 
 | ||||
| const Color GCodePreviewData::Extrusion::Default_Extrusion_Role_Colors[erCount] = | ||||
| { | ||||
|     Color(0.0f, 0.0f, 0.0f, 1.0f),   // erNone
 | ||||
|     Color(1.0f, 0.0f, 0.0f, 1.0f),   // erPerimeter
 | ||||
|     Color(0.0f, 1.0f, 0.0f, 1.0f),   // erExternalPerimeter
 | ||||
|     Color(0.0f, 0.0f, 1.0f, 1.0f),   // erOverhangPerimeter
 | ||||
|     Color(1.0f, 1.0f, 0.0f, 1.0f),   // erInternalInfill
 | ||||
|     Color(1.0f, 0.0f, 1.0f, 1.0f),   // erSolidInfill
 | ||||
|     Color(0.0f, 1.0f, 1.0f, 1.0f),   // erTopSolidInfill
 | ||||
| //    Color(1.0f, 0.7f, 0.61f, 1.0f),   // erIroning
 | ||||
|     Color(1.0f, 0.55f, 0.41f, 1.0f),   // erIroning
 | ||||
|     Color(0.5f, 0.5f, 0.5f, 1.0f),   // erBridgeInfill
 | ||||
|     Color(1.0f, 1.0f, 1.0f, 1.0f),   // erGapFill
 | ||||
|     Color(0.5f, 0.0f, 0.0f, 1.0f),   // erSkirt
 | ||||
|     Color(0.0f, 0.5f, 0.0f, 1.0f),   // erSupportMaterial
 | ||||
|     Color(0.0f, 0.0f, 0.5f, 1.0f),   // erSupportMaterialInterface
 | ||||
|     Color(0.7f, 0.89f, 0.67f, 1.0f), // erWipeTower
 | ||||
|     Color(1.0f, 1.0f, 0.0f, 1.0f),   // erCustom
 | ||||
|     Color(0.0f, 0.0f, 0.0f, 1.0f)    // erMixed
 | ||||
| }; | ||||
| 
 | ||||
| const GCodePreviewData::Extrusion::EViewType GCodePreviewData::Extrusion::Default_View_Type = GCodePreviewData::Extrusion::FeatureType; | ||||
| 
 | ||||
| void GCodePreviewData::Extrusion::set_default() | ||||
| { | ||||
|     view_type = Default_View_Type; | ||||
| 
 | ||||
|     ::memcpy((void*)role_colors, (const void*)Default_Extrusion_Role_Colors, erCount * sizeof(Color)); | ||||
| 
 | ||||
|     for (unsigned int i = 0; i < erCount; ++i) | ||||
|         role_names[i] = ExtrusionEntity::role_to_string(ExtrusionRole(i)); | ||||
| 
 | ||||
|     role_flags = 0; | ||||
|     for (unsigned int i = 0; i < erCount; ++i) | ||||
|         role_flags |= 1 << i; | ||||
| } | ||||
| 
 | ||||
| bool GCodePreviewData::Extrusion::is_role_flag_set(ExtrusionRole role) const | ||||
| { | ||||
|     return is_role_flag_set(role_flags, role); | ||||
| } | ||||
| 
 | ||||
| bool GCodePreviewData::Extrusion::is_role_flag_set(unsigned int flags, ExtrusionRole role) | ||||
| { | ||||
|     return GCodeAnalyzer::is_valid_extrusion_role(role) && (flags & (1 << (role - erPerimeter))) != 0; | ||||
| } | ||||
| 
 | ||||
| size_t GCodePreviewData::Extrusion::memory_used() const | ||||
| { | ||||
|     size_t out = sizeof(*this); | ||||
|     out += SLIC3R_STDVEC_MEMSIZE(this->layers, Layer); | ||||
|     for (const Layer &layer : this->layers) { | ||||
|         out += SLIC3R_STDVEC_MEMSIZE(layer.paths, Path); | ||||
|         for (const Path &path : layer.paths) | ||||
| 			out += SLIC3R_STDVEC_MEMSIZE(path.polyline.points, Point); | ||||
|     } | ||||
| 	return out; | ||||
| } | ||||
| 
 | ||||
| const float GCodePreviewData::Travel::Default_Width = 0.075f; | ||||
| const float GCodePreviewData::Travel::Default_Height = 0.075f; | ||||
| const Color GCodePreviewData::Travel::Default_Type_Colors[Num_Types] = | ||||
| { | ||||
|     Color(0.0f, 0.0f, 0.75f, 1.0f), // Move
 | ||||
|     Color(0.0f, 0.75f, 0.0f, 1.0f), // Extrude
 | ||||
|     Color(0.75f, 0.0f, 0.0f, 1.0f), // Retract
 | ||||
| }; | ||||
| 
 | ||||
| void GCodePreviewData::Travel::set_default() | ||||
| { | ||||
|     width = Default_Width; | ||||
|     height = Default_Height; | ||||
|     ::memcpy((void*)type_colors, (const void*)Default_Type_Colors, Num_Types * sizeof(Color)); | ||||
|     color_print_idx = 0; | ||||
| 
 | ||||
|     is_visible = false; | ||||
| } | ||||
| 
 | ||||
| size_t GCodePreviewData::Travel::memory_used() const | ||||
| { | ||||
|     size_t out = sizeof(*this); | ||||
|     out += SLIC3R_STDVEC_MEMSIZE(this->polylines, Polyline); | ||||
| 	for (const Polyline &polyline : this->polylines) | ||||
| 		out += SLIC3R_STDVEC_MEMSIZE(polyline.polyline.points, Vec3crd); | ||||
|     return out; | ||||
| } | ||||
| 
 | ||||
| const Color GCodePreviewData::Retraction::Default_Color = Color(1.0f, 1.0f, 1.0f, 1.0f); | ||||
| 
 | ||||
| GCodePreviewData::Retraction::Position::Position(const Vec3crd& position, float width, float height) | ||||
|     : position(position) | ||||
|     , width(width) | ||||
|     , height(height) | ||||
| { | ||||
| } | ||||
| 
 | ||||
| void GCodePreviewData::Retraction::set_default() | ||||
| { | ||||
|     color = Default_Color; | ||||
|     is_visible = false; | ||||
| } | ||||
| 
 | ||||
| size_t GCodePreviewData::Retraction::memory_used() const | ||||
| { | ||||
| 	return sizeof(*this) + SLIC3R_STDVEC_MEMSIZE(this->positions, Position); | ||||
| } | ||||
| 
 | ||||
| void GCodePreviewData::Shell::set_default() | ||||
| { | ||||
|     is_visible = false; | ||||
| } | ||||
| 
 | ||||
| GCodePreviewData::GCodePreviewData() | ||||
| { | ||||
|     set_default(); | ||||
| } | ||||
| 
 | ||||
| void GCodePreviewData::set_default() | ||||
| { | ||||
|     extrusion.set_default(); | ||||
|     travel.set_default(); | ||||
|     retraction.set_default(); | ||||
|     unretraction.set_default(); | ||||
|     shell.set_default(); | ||||
|      | ||||
|     // Configure the color range for feedrate to match the default for travels and to enable extrusions since they are always visible
 | ||||
|     ranges.feedrate.set_mode(FeedrateKind::TRAVEL, travel.is_visible); | ||||
|     ranges.feedrate.set_mode(FeedrateKind::EXTRUSION, true); | ||||
| } | ||||
| 
 | ||||
| void GCodePreviewData::reset() | ||||
| { | ||||
|     ranges.width.reset(); | ||||
|     ranges.height.reset(); | ||||
|     ranges.feedrate.reset(); | ||||
|     ranges.fan_speed.reset(); | ||||
|     ranges.volumetric_rate.reset(); | ||||
|     extrusion.layers.clear(); | ||||
|     travel.polylines.clear(); | ||||
|     retraction.positions.clear(); | ||||
|     unretraction.positions.clear(); | ||||
| } | ||||
| 
 | ||||
| bool GCodePreviewData::empty() const | ||||
| { | ||||
|     return extrusion.layers.empty() && travel.polylines.empty() && retraction.positions.empty() && unretraction.positions.empty(); | ||||
| } | ||||
| 
 | ||||
| Color GCodePreviewData::get_extrusion_role_color(ExtrusionRole role) const | ||||
| { | ||||
|     return extrusion.role_colors[role]; | ||||
| } | ||||
| 
 | ||||
| Color GCodePreviewData::get_height_color(float height) const | ||||
| { | ||||
|     return ranges.height.get_color_at(height); | ||||
| } | ||||
| 
 | ||||
| Color GCodePreviewData::get_width_color(float width) const | ||||
| { | ||||
|     return ranges.width.get_color_at(width); | ||||
| } | ||||
| 
 | ||||
| Color GCodePreviewData::get_feedrate_color(float feedrate) const | ||||
| { | ||||
|     return ranges.feedrate.get_color_at(feedrate); | ||||
| } | ||||
| 
 | ||||
| Color GCodePreviewData::get_fan_speed_color(float fan_speed) const | ||||
| { | ||||
|     return ranges.fan_speed.get_color_at(fan_speed); | ||||
| } | ||||
| 
 | ||||
| Color GCodePreviewData::get_volumetric_rate_color(float rate) const | ||||
| { | ||||
|     return ranges.volumetric_rate.get_color_at(rate); | ||||
| } | ||||
| 
 | ||||
| void GCodePreviewData::set_extrusion_role_color(const std::string& role_name, float red, float green, float blue, float alpha) | ||||
| { | ||||
|     for (unsigned int i = 0; i < erCount; ++i) | ||||
|     { | ||||
|         if (role_name == extrusion.role_names[i]) | ||||
|         { | ||||
|             extrusion.role_colors[i] = Color(red, green, blue, alpha); | ||||
|             break; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void GCodePreviewData::set_extrusion_paths_colors(const std::vector<std::string>& colors) | ||||
| { | ||||
|     unsigned int size = (unsigned int)colors.size(); | ||||
| 
 | ||||
|     if (size % 2 != 0) | ||||
|         return; | ||||
| 
 | ||||
|     for (unsigned int i = 0; i < size; i += 2) | ||||
|     { | ||||
|         const std::string& color_str = colors[i + 1]; | ||||
| 
 | ||||
|         if (color_str.size() == 6) | ||||
|         { | ||||
|             bool valid = true; | ||||
|             for (int c = 0; c < 6; ++c) | ||||
|             { | ||||
|                 if (::isxdigit(color_str[c]) == 0) | ||||
|                 { | ||||
|                     valid = false; | ||||
|                     break; | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             if (valid) | ||||
|             { | ||||
|                 unsigned int color; | ||||
|                 std::stringstream ss; | ||||
|                 ss << std::hex << color_str; | ||||
|                 ss >> color; | ||||
| 
 | ||||
|                 float den = 1.0f / 255.0f; | ||||
| 
 | ||||
|                 float r = (float)((color & 0xFF0000) >> 16) * den; | ||||
|                 float g = (float)((color & 0x00FF00) >> 8) * den; | ||||
|                 float b = (float)(color & 0x0000FF) * den; | ||||
| 
 | ||||
|                 this->set_extrusion_role_color(colors[i], r, g, b, 1.0f); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| std::string GCodePreviewData::get_legend_title() const | ||||
| { | ||||
|     switch (extrusion.view_type) | ||||
|     { | ||||
|     case Extrusion::FeatureType: | ||||
|         return L("Feature type"); | ||||
|     case Extrusion::Height: | ||||
|         return L("Height (mm)"); | ||||
|     case Extrusion::Width: | ||||
|         return L("Width (mm)"); | ||||
|     case Extrusion::Feedrate: | ||||
|         return L("Speed (mm/s)"); | ||||
|     case Extrusion::FanSpeed: | ||||
|         return L("Fan Speed (%)"); | ||||
|     case Extrusion::VolumetricRate: | ||||
|         return L("Volumetric flow rate (mm³/s)"); | ||||
|     case Extrusion::Tool: | ||||
|         return L("Tool"); | ||||
|     case Extrusion::ColorPrint: | ||||
|         return L("Color Print"); | ||||
|     case Extrusion::Num_View_Types: | ||||
|         break; // just to supress warning about non-handled value
 | ||||
|     } | ||||
| 
 | ||||
|     return ""; | ||||
| } | ||||
| 
 | ||||
| GCodePreviewData::LegendItemsList GCodePreviewData::get_legend_items(const std::vector<float>& tool_colors,  | ||||
|                                                                      const std::vector<std::string>& cp_items) const | ||||
| { | ||||
|     struct Helper | ||||
|     { | ||||
|         static void FillListFromRange(LegendItemsList& list, const RangeBase& range, unsigned int decimals, float scale_factor) | ||||
|         { | ||||
|             list.reserve(range_rainbow_colors.size()); | ||||
| 
 | ||||
|             float step = range.step_size(); | ||||
|             if (step == 0.0f) | ||||
|             { | ||||
|                 char buf[1024]; | ||||
|                 sprintf(buf, "%.*f", decimals, scale_factor * range.min()); | ||||
|                 list.emplace_back(buf, range_rainbow_colors[0]); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 for (int i = static_cast<int>(range_rainbow_colors.size()) - 1; i >= 0; --i) | ||||
|                 { | ||||
|                     char buf[1024]; | ||||
|                     sprintf(buf, "%.*f", decimals, scale_factor * (range.min() + (float)i * step)); | ||||
|                     list.emplace_back(buf, range_rainbow_colors[i]); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     }; | ||||
| 
 | ||||
|     LegendItemsList items; | ||||
| 
 | ||||
|     switch (extrusion.view_type) | ||||
|     { | ||||
|     case Extrusion::FeatureType: | ||||
|         { | ||||
|             ExtrusionRole first_valid = erPerimeter; | ||||
|             ExtrusionRole last_valid = erCustom; | ||||
| 
 | ||||
|             items.reserve(last_valid - first_valid + 1); | ||||
|             for (unsigned int i = (unsigned int)first_valid; i <= (unsigned int)last_valid; ++i) | ||||
|             { | ||||
|                 items.emplace_back(Slic3r::I18N::translate(extrusion.role_names[i]), extrusion.role_colors[i]); | ||||
|             } | ||||
| 
 | ||||
|             break; | ||||
|         } | ||||
|     case Extrusion::Height: | ||||
|         { | ||||
|             Helper::FillListFromRange(items, ranges.height, 3, 1.0f); | ||||
|             break; | ||||
|         } | ||||
|     case Extrusion::Width: | ||||
|         { | ||||
|             Helper::FillListFromRange(items, ranges.width, 3, 1.0f); | ||||
|             break; | ||||
|         } | ||||
|     case Extrusion::Feedrate: | ||||
|         { | ||||
|             Helper::FillListFromRange(items, ranges.feedrate, 1, 1.0f); | ||||
|             break; | ||||
|         } | ||||
|     case Extrusion::FanSpeed: | ||||
|         { | ||||
|             Helper::FillListFromRange(items, ranges.fan_speed, 0, 1.0f); | ||||
|             break; | ||||
|         } | ||||
|     case Extrusion::VolumetricRate: | ||||
|         { | ||||
|             Helper::FillListFromRange(items, ranges.volumetric_rate, 3, 1.0f); | ||||
|             break; | ||||
|         } | ||||
|     case Extrusion::Tool: | ||||
|         { | ||||
|             unsigned int tools_colors_count = (unsigned int)tool_colors.size() / 4; | ||||
|             items.reserve(tools_colors_count); | ||||
|             for (unsigned int i = 0; i < tools_colors_count; ++i) | ||||
|             { | ||||
|                 Color color; | ||||
|                 ::memcpy((void*)color.rgba.data(), (const void*)(tool_colors.data() + i * 4), 4 * sizeof(float)); | ||||
|                 items.emplace_back((boost::format(Slic3r::I18N::translate(L("Extruder %d"))) % (i + 1)).str(), color); | ||||
|             } | ||||
| 
 | ||||
|             break; | ||||
|         } | ||||
|     case Extrusion::ColorPrint: | ||||
|         { | ||||
|             const int color_cnt = (int)tool_colors.size()/4; | ||||
|             const auto color_print_cnt = (int)cp_items.size(); | ||||
|             if (color_print_cnt == 1) // means "Default print color"
 | ||||
|             { | ||||
|                 Color color; | ||||
|                 ::memcpy((void*)color.rgba.data(), (const void*)(tool_colors.data()), 4 * sizeof(float)); | ||||
| 
 | ||||
|                 items.emplace_back(cp_items[0], color); | ||||
|                 break; | ||||
|             } | ||||
| 
 | ||||
|             if (color_cnt != color_print_cnt) | ||||
|                 break; | ||||
| 
 | ||||
|             for (int i = 0 ; i < color_print_cnt; ++i) | ||||
|             { | ||||
|                 Color color; | ||||
|                 ::memcpy((void*)color.rgba.data(), (const void*)(tool_colors.data() + i * 4), 4 * sizeof(float)); | ||||
|                  | ||||
|                 items.emplace_back(cp_items[i], color); | ||||
|             } | ||||
|             break; | ||||
|         } | ||||
|     case Extrusion::Num_View_Types: | ||||
|         break; // just to supress warning about non-handled value
 | ||||
|     } | ||||
| 
 | ||||
|     return items; | ||||
| } | ||||
| 
 | ||||
| // Return an estimate of the memory consumed by the time estimator.
 | ||||
| size_t GCodePreviewData::memory_used() const | ||||
| { | ||||
|     return  | ||||
|         this->extrusion.memory_used() +  | ||||
|         this->travel.memory_used() +  | ||||
|         this->retraction.memory_used() +  | ||||
|         this->unretraction.memory_used() +  | ||||
|         sizeof(shell) + sizeof(ranges); | ||||
| } | ||||
| 
 | ||||
| const std::vector<std::string>& GCodePreviewData::ColorPrintColors() | ||||
| { | ||||
|     static std::vector<std::string> color_print = {"#C0392B", "#E67E22", "#F1C40F", "#27AE60", "#1ABC9C", "#2980B9", "#9B59B6"}; | ||||
|     return color_print; | ||||
| } | ||||
| 
 | ||||
| Color operator + (const Color& c1, const Color& c2) | ||||
| { | ||||
|     return Color(std::clamp(c1.rgba[0] + c2.rgba[0], 0.0f, 1.0f), | ||||
|         std::clamp(c1.rgba[1] + c2.rgba[1], 0.0f, 1.0f), | ||||
|         std::clamp(c1.rgba[2] + c2.rgba[2], 0.0f, 1.0f), | ||||
|         std::clamp(c1.rgba[3] + c2.rgba[3], 0.0f, 1.0f)); | ||||
| } | ||||
| 
 | ||||
| Color operator * (float f, const Color& color) | ||||
| { | ||||
|     return Color(std::clamp(f * color.rgba[0], 0.0f, 1.0f), | ||||
|         std::clamp(f * color.rgba[1], 0.0f, 1.0f), | ||||
|         std::clamp(f * color.rgba[2], 0.0f, 1.0f), | ||||
|         std::clamp(f * color.rgba[3], 0.0f, 1.0f)); | ||||
| } | ||||
| 
 | ||||
| } // namespace Slic3r
 | ||||
| 
 | ||||
| #endif // !ENABLE_GCODE_VIEWER
 | ||||
|  | @ -1,398 +0,0 @@ | |||
| #ifndef slic3r_GCode_PreviewData_hpp_ | ||||
| #define slic3r_GCode_PreviewData_hpp_ | ||||
| 
 | ||||
| #if !ENABLE_GCODE_VIEWER | ||||
| 
 | ||||
| #include "../libslic3r.h" | ||||
| #include "../ExtrusionEntity.hpp" | ||||
| #include "../Point.hpp" | ||||
| 
 | ||||
| #include <tuple> | ||||
| #include <array> | ||||
| #include <vector> | ||||
| #include <bitset> | ||||
| #include <cstddef> | ||||
| #include <algorithm> | ||||
| #include <string> | ||||
| 
 | ||||
| #include <float.h> | ||||
| 
 | ||||
| namespace Slic3r { | ||||
| 
 | ||||
| // Represents an RGBA color
 | ||||
| struct Color | ||||
| { | ||||
|     std::array<float,4> rgba; | ||||
| 
 | ||||
|     Color(const float *argba) | ||||
|     { | ||||
|         memcpy(this->rgba.data(), argba, sizeof(float) * 4); | ||||
|     } | ||||
|     constexpr Color(float r = 1.f, float g = 1.f, float b = 1.f, float a = 1.f) : rgba{r,g,b,a} | ||||
|     { | ||||
|         // Intentionally empty
 | ||||
|     } | ||||
| 
 | ||||
|     std::vector<unsigned char> as_bytes() const; | ||||
| }; | ||||
| Color operator + (const Color& c1, const Color& c2); | ||||
| Color operator * (float f, const Color& color); | ||||
| 
 | ||||
| // Default colors for Ranges
 | ||||
| constexpr std::array<Color, 10> range_rainbow_colors{ | ||||
|     Color{0.043f, 0.173f, 0.478f, 1.0f}, | ||||
|     Color{0.075f, 0.349f, 0.522f, 1.0f}, | ||||
|     Color{0.110f, 0.533f, 0.569f, 1.0f}, | ||||
|     Color{0.016f, 0.839f, 0.059f, 1.0f}, | ||||
|     Color{0.667f, 0.949f, 0.000f, 1.0f}, | ||||
|     Color{0.988f, 0.975f, 0.012f, 1.0f}, | ||||
|     Color{0.961f, 0.808f, 0.039f, 1.0f}, | ||||
|     Color{0.890f, 0.533f, 0.125f, 1.0f}, | ||||
|     Color{0.820f, 0.408f, 0.188f, 1.0f}, | ||||
|     Color{0.761f, 0.322f, 0.235f, 1.0f}}; | ||||
| 
 | ||||
| class GCodePreviewData | ||||
| { | ||||
| public: | ||||
| 
 | ||||
|     // Color mapping to convert a float into a smooth rainbow of 10 colors.
 | ||||
|     class RangeBase | ||||
|     { | ||||
|     public: | ||||
|         virtual void reset() = 0; | ||||
|         virtual bool empty() const = 0; | ||||
|         virtual float min() const = 0; | ||||
|         virtual float max() const = 0; | ||||
|          | ||||
|         // Gets the step size using min(), max() and colors
 | ||||
|         float step_size() const; | ||||
|          | ||||
|         // Gets the color at a value using colors, min(), and max()
 | ||||
|         Color get_color_at(float value) const; | ||||
|     }; | ||||
| 
 | ||||
|     // Color mapping converting a float in a range between a min and a max into a smooth rainbow of 10 colors.
 | ||||
|     class Range : public RangeBase | ||||
|     { | ||||
|     public: | ||||
|         Range(); | ||||
| 
 | ||||
|         // RangeBase Overrides
 | ||||
|         void reset() override; | ||||
|         bool empty() const override; | ||||
|         float min() const override; | ||||
|         float max() const override; | ||||
|          | ||||
|         // Range-specific methods
 | ||||
|         void update_from(float value); | ||||
|         void update_from(const RangeBase& other); | ||||
| 
 | ||||
|         private: | ||||
|         float min_val; | ||||
|         float max_val; | ||||
|     }; | ||||
| 
 | ||||
|     // Like Range, but stores multiple ranges internally that are used depending on mode.
 | ||||
|     // Template param EnumRangeType must be an enum with values for each type of range that needs to be tracked in this MultiRange.
 | ||||
|     // The last enum value should be num_values. The numerical values of all enum values should range from 0 to num_values.
 | ||||
|     template <typename EnumRangeType> | ||||
|     class MultiRange : public RangeBase | ||||
|     { | ||||
|     public: | ||||
|         void reset() override | ||||
|         { | ||||
|             bounds = decltype(bounds){}; | ||||
|         } | ||||
| 
 | ||||
|         bool empty() const override | ||||
|         { | ||||
|             for (std::size_t i = 0; i < bounds.size(); ++i) | ||||
|             { | ||||
|                 if (bounds[i].min != bounds[i].max) | ||||
|                     return false; | ||||
|             } | ||||
|             return true; | ||||
|         } | ||||
| 
 | ||||
|         float min() const override | ||||
|         { | ||||
|             float min = FLT_MAX; | ||||
|             for (std::size_t i = 0; i < bounds.size(); ++i) | ||||
|             { | ||||
|                 // Only use bounds[i] if the current mode includes it
 | ||||
|                 if (mode.test(i)) | ||||
|                 { | ||||
|                     min = std::min(min, bounds[i].min); | ||||
|                 } | ||||
|             } | ||||
|             return min; | ||||
|         } | ||||
| 
 | ||||
|         float max() const override | ||||
|         { | ||||
|             float max = -FLT_MAX; | ||||
|             for (std::size_t i = 0; i < bounds.size(); ++i) | ||||
|             { | ||||
|                 // Only use bounds[i] if the current mode includes it
 | ||||
|                 if (mode.test(i)) | ||||
|                 { | ||||
|                     max = std::max(max, bounds[i].max); | ||||
|                 } | ||||
|             } | ||||
|             return max; | ||||
|         } | ||||
| 
 | ||||
|         void update_from(const float value, EnumRangeType range_type_value) | ||||
|         { | ||||
|             bounds[static_cast<std::size_t>(range_type_value)].update_from(value); | ||||
|         } | ||||
| 
 | ||||
|         void update_from(const MultiRange& other) | ||||
|         { | ||||
|             for (std::size_t i = 0; i < bounds.size(); ++i) | ||||
|             { | ||||
|                 bounds[i].update_from(other.bounds[i]); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         void set_mode(const EnumRangeType range_type_value, const bool enable) | ||||
|         { | ||||
|             mode.set(static_cast<std::size_t>(range_type_value), enable); | ||||
|         } | ||||
| 
 | ||||
|     private: | ||||
|         // Interval bounds
 | ||||
|         struct Bounds | ||||
|         { | ||||
|             float min{FLT_MAX}; | ||||
|             float max{-FLT_MAX}; | ||||
|             void update_from(const float value) | ||||
|             { | ||||
|                 min = std::min(min, value); | ||||
|                 max = std::max(max, value); | ||||
|             } | ||||
|             void update_from(const Bounds other_bounds) | ||||
|             { | ||||
|                 min = std::min(min, other_bounds.min); | ||||
|                 max = std::max(max, other_bounds.max); | ||||
|             } | ||||
|         }; | ||||
| 
 | ||||
|         std::array<Bounds, static_cast<std::size_t>(EnumRangeType::num_values)> bounds; | ||||
|         std::bitset<static_cast<std::size_t>(EnumRangeType::num_values)> mode; | ||||
|     }; | ||||
| 
 | ||||
|     // Enum distinguishing different kinds of feedrate data
 | ||||
|     enum class FeedrateKind | ||||
|     { | ||||
|         EXTRUSION = 0,  // values must go from 0 up to num_values
 | ||||
|         TRAVEL, | ||||
|         num_values  //must be last in the list of values
 | ||||
|     }; | ||||
| 
 | ||||
|     struct Ranges | ||||
|     { | ||||
|         // Color mapping by layer height.
 | ||||
|         Range height; | ||||
|         // Color mapping by extrusion width.
 | ||||
|         Range width; | ||||
|         // Color mapping by feedrate.
 | ||||
|         MultiRange<FeedrateKind> feedrate; | ||||
|         // Color mapping by fan speed.
 | ||||
|         Range fan_speed; | ||||
|         // Color mapping by volumetric extrusion rate.
 | ||||
|         Range volumetric_rate; | ||||
|     }; | ||||
| 
 | ||||
|     struct LegendItem | ||||
|     { | ||||
|         std::string text; | ||||
|         Color color; | ||||
| 
 | ||||
|         LegendItem(const std::string& text, const Color& color); | ||||
|     }; | ||||
| 
 | ||||
|     typedef std::vector<LegendItem> LegendItemsList; | ||||
| 
 | ||||
|     struct Extrusion | ||||
|     { | ||||
|         enum EViewType : unsigned char | ||||
|         { | ||||
|             FeatureType, | ||||
|             Height, | ||||
|             Width, | ||||
|             Feedrate, | ||||
|             FanSpeed, | ||||
|             VolumetricRate, | ||||
|             Tool, | ||||
|             ColorPrint, | ||||
|             Num_View_Types | ||||
|         }; | ||||
| 
 | ||||
|         static const Color Default_Extrusion_Role_Colors[erCount]; | ||||
|         static const std::string Default_Extrusion_Role_Names[erCount]; | ||||
|         static const EViewType Default_View_Type; | ||||
| 
 | ||||
| 		class Path | ||||
| 		{ | ||||
| 		public: | ||||
| 		    Polyline 		polyline; | ||||
| 		    ExtrusionRole 	extrusion_role; | ||||
| 		    // Volumetric velocity. mm^3 of plastic per mm of linear head motion. Used by the G-code generator.
 | ||||
| 		    float			mm3_per_mm; | ||||
| 		    // Width of the extrusion, used for visualization purposes.
 | ||||
| 		    float 			width; | ||||
| 		    // Height of the extrusion, used for visualization purposes.
 | ||||
| 		    float 			height; | ||||
| 		    // Feedrate of the extrusion, used for visualization purposes.
 | ||||
| 		    float 			feedrate; | ||||
| 		    // Id of the extruder, used for visualization purposes.
 | ||||
| 		    uint32_t		extruder_id; | ||||
| 		    // Id of the color, used for visualization purposes in the color printing case.
 | ||||
| 		    uint32_t	 	cp_color_id; | ||||
| 		    // Fan speed for the extrusion, used for visualization purposes.
 | ||||
| 		    float 			fan_speed; | ||||
| 		}; | ||||
| 		using Paths = std::vector<Path>; | ||||
| 
 | ||||
|         struct Layer | ||||
|         { | ||||
|             float z; | ||||
|             Paths paths; | ||||
| 
 | ||||
|             Layer(float z, const Paths& paths); | ||||
|         }; | ||||
| 
 | ||||
|         typedef std::vector<Layer> LayersList; | ||||
| 
 | ||||
|         EViewType view_type; | ||||
|         Color role_colors[erCount]; | ||||
|         std::string role_names[erCount]; | ||||
|         LayersList layers; | ||||
|         unsigned int role_flags; | ||||
| 
 | ||||
|         void set_default(); | ||||
|         bool is_role_flag_set(ExtrusionRole role) const; | ||||
| 
 | ||||
|         // Return an estimate of the memory consumed by the time estimator.
 | ||||
|         size_t memory_used() const; | ||||
| 
 | ||||
|         static bool is_role_flag_set(unsigned int flags, ExtrusionRole role); | ||||
|     }; | ||||
| 
 | ||||
|     struct Travel | ||||
|     { | ||||
|         enum EType : unsigned char | ||||
|         { | ||||
|             Move, | ||||
|             Extrude, | ||||
|             Retract, | ||||
|             Num_Types | ||||
|         }; | ||||
| 
 | ||||
|         static const float Default_Width; | ||||
|         static const float Default_Height; | ||||
|         static const Color Default_Type_Colors[Num_Types]; | ||||
| 
 | ||||
|         struct Polyline | ||||
|         { | ||||
|             enum EDirection | ||||
|             { | ||||
|                 Vertical, | ||||
|                 Generic, | ||||
|                 Num_Directions | ||||
|             }; | ||||
| 
 | ||||
|             EType type; | ||||
|             EDirection direction; | ||||
|             float feedrate; | ||||
|             unsigned int extruder_id; | ||||
|             Polyline3 polyline; | ||||
| 
 | ||||
|             Polyline(EType type, EDirection direction, float feedrate, unsigned int extruder_id, const Polyline3& polyline); | ||||
|         }; | ||||
| 
 | ||||
|         typedef std::vector<Polyline> PolylinesList; | ||||
| 
 | ||||
|         PolylinesList polylines; | ||||
|         float width; | ||||
|         float height; | ||||
|         Color type_colors[Num_Types]; | ||||
|         bool is_visible; | ||||
|         size_t color_print_idx; | ||||
| 
 | ||||
|         void set_default(); | ||||
| 
 | ||||
|         // Return an estimate of the memory consumed by the time estimator.
 | ||||
|         size_t memory_used() const; | ||||
|     }; | ||||
| 
 | ||||
|     struct Retraction | ||||
|     { | ||||
|         static const Color Default_Color; | ||||
| 
 | ||||
|         struct Position | ||||
|         { | ||||
|             Vec3crd position; | ||||
|             float width; | ||||
|             float height; | ||||
| 
 | ||||
|             Position(const Vec3crd& position, float width, float height); | ||||
|         }; | ||||
| 
 | ||||
|         typedef std::vector<Position> PositionsList; | ||||
| 
 | ||||
|         PositionsList positions; | ||||
|         Color color; | ||||
|         bool is_visible; | ||||
| 
 | ||||
|         void set_default(); | ||||
| 
 | ||||
|         // Return an estimate of the memory consumed by the time estimator.
 | ||||
|         size_t memory_used() const; | ||||
|     }; | ||||
| 
 | ||||
|     struct Shell | ||||
|     { | ||||
|         bool is_visible; | ||||
| 
 | ||||
|         void set_default(); | ||||
|     }; | ||||
| 
 | ||||
|     Extrusion extrusion; | ||||
|     Travel travel; | ||||
|     Retraction retraction; | ||||
|     Retraction unretraction; | ||||
|     Shell shell; | ||||
|     Ranges ranges; | ||||
| 
 | ||||
|     GCodePreviewData(); | ||||
| 
 | ||||
|     void set_default(); | ||||
|     void reset(); | ||||
|     bool empty() const; | ||||
| 
 | ||||
|     Color get_extrusion_role_color(ExtrusionRole role) const; | ||||
|     Color get_height_color(float height) const; | ||||
|     Color get_width_color(float width) const; | ||||
|     Color get_feedrate_color(float feedrate) const; | ||||
|     Color get_fan_speed_color(float fan_speed) const; | ||||
|     Color get_volumetric_rate_color(float rate) const; | ||||
| 
 | ||||
|     void set_extrusion_role_color(const std::string& role_name, float red, float green, float blue, float alpha); | ||||
|     void set_extrusion_paths_colors(const std::vector<std::string>& colors); | ||||
| 
 | ||||
|     std::string get_legend_title() const; | ||||
|     LegendItemsList get_legend_items(const std::vector<float>& tool_colors, const std::vector<std::string>& cp_items) const; | ||||
| 
 | ||||
|     // Return an estimate of the memory consumed by the time estimator.
 | ||||
|     size_t memory_used() const; | ||||
| 
 | ||||
|     static const std::vector<std::string>& ColorPrintColors(); | ||||
| }; | ||||
| 
 | ||||
| } // namespace Slic3r
 | ||||
| 
 | ||||
| #endif // !ENABLE_GCODE_VIEWER
 | ||||
| 
 | ||||
| #endif /* slic3r_GCode_PreviewData_hpp_ */ | ||||
|  | @ -22,9 +22,6 @@ | |||
| #include "SVG.hpp" | ||||
| #include <Eigen/Dense> | ||||
| #include "GCodeWriter.hpp" | ||||
| #if !ENABLE_GCODE_VIEWER | ||||
| #include "GCode/PreviewData.hpp" | ||||
| #endif // !ENABLE_GCODE_VIEWER
 | ||||
| 
 | ||||
| namespace Slic3r { | ||||
| 
 | ||||
|  |  | |||
|  | @ -16,9 +16,6 @@ | |||
| #include "libslic3r/ExtrusionEntity.hpp" | ||||
| #include "libslic3r/ExtrusionEntityCollection.hpp" | ||||
| #include "libslic3r/Geometry.hpp" | ||||
| #if !ENABLE_GCODE_VIEWER | ||||
| #include "libslic3r/GCode/PreviewData.hpp" | ||||
| #endif // !ENABLE_GCODE_VIEWER
 | ||||
| #include "libslic3r/Print.hpp" | ||||
| #include "libslic3r/SLAPrint.hpp" | ||||
| #include "libslic3r/Slicing.hpp" | ||||
|  |  | |||
|  | @ -19,9 +19,6 @@ | |||
| #include "libslic3r/SLAPrint.hpp" | ||||
| #include "libslic3r/Utils.hpp" | ||||
| #include "libslic3r/GCode/PostProcessor.hpp" | ||||
| #if !ENABLE_GCODE_VIEWER | ||||
| #include "libslic3r/GCode/PreviewData.hpp" | ||||
| #endif // !ENABLE_GCODE_VIEWER
 | ||||
| #include "libslic3r/Format/SL1.hpp" | ||||
| #include "libslic3r/Thread.hpp" | ||||
| #include "libslic3r/libslic3r.h" | ||||
|  |  | |||
|  | @ -4,7 +4,6 @@ | |||
| #include "libslic3r/GCode.hpp" | ||||
| #else | ||||
| #include "wxExtensions.hpp" | ||||
| #include "libslic3r/GCode/PreviewData.hpp" | ||||
| #endif // ENABLE_GCODE_VIEWER
 | ||||
| #include "GUI.hpp" | ||||
| #include "GUI_App.hpp" | ||||
|  |  | |||
|  | @ -5,9 +5,6 @@ | |||
| #include "polypartition.h" | ||||
| #include "libslic3r/ClipperUtils.hpp" | ||||
| #include "libslic3r/PrintConfig.hpp" | ||||
| #if !ENABLE_GCODE_VIEWER | ||||
| #include "libslic3r/GCode/PreviewData.hpp" | ||||
| #endif // !ENABLE_GCODE_VIEWER
 | ||||
| #include "libslic3r/GCode/ThumbnailData.hpp" | ||||
| #include "libslic3r/Geometry.hpp" | ||||
| #include "libslic3r/ExtrusionEntity.hpp" | ||||
|  |  | |||
|  | @ -1,7 +1,4 @@ | |||
| #include "libslic3r/libslic3r.h" | ||||
| #if !ENABLE_GCODE_VIEWER | ||||
| #include "libslic3r/GCode/PreviewData.hpp" | ||||
| #endif // !ENABLE_GCODE_VIEWER
 | ||||
| #include "GUI_Preview.hpp" | ||||
| #include "GUI_App.hpp" | ||||
| #include "GUI.hpp" | ||||
|  |  | |||
|  | @ -32,9 +32,6 @@ | |||
| #include "libslic3r/Format/STL.hpp" | ||||
| #include "libslic3r/Format/AMF.hpp" | ||||
| #include "libslic3r/Format/3mf.hpp" | ||||
| #if !ENABLE_GCODE_VIEWER | ||||
| #include "libslic3r/GCode/PreviewData.hpp" | ||||
| #endif // !ENABLE_GCODE_VIEWER
 | ||||
| #include "libslic3r/GCode/ThumbnailData.hpp" | ||||
| #include "libslic3r/Model.hpp" | ||||
| #include "libslic3r/SLA/Hollowing.hpp" | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 enricoturri1966
						enricoturri1966