mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-11 16:57:53 -06:00
GCodeViewer -> Use rounded values for toolpaths height, width and volumetric rate to reduce the number of generated paths
This commit is contained in:
parent
5b579aee9a
commit
b156153405
2 changed files with 43 additions and 37 deletions
|
@ -85,19 +85,6 @@ static float acceleration_time_from_distance(float initial_feedrate, float dista
|
||||||
return (acceleration != 0.0f) ? (speed_from_distance(initial_feedrate, distance, acceleration) - initial_feedrate) / acceleration : 0.0f;
|
return (acceleration != 0.0f) ? (speed_from_distance(initial_feedrate, distance, acceleration) - initial_feedrate) / acceleration : 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
float round_to_nearest(float value, unsigned int decimals)
|
|
||||||
{
|
|
||||||
float res = 0.0f;
|
|
||||||
if (decimals == 0)
|
|
||||||
res = std::round(value);
|
|
||||||
else {
|
|
||||||
char buf[64];
|
|
||||||
sprintf(buf, "%.*g", decimals, value);
|
|
||||||
res = std::stof(buf);
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GCodeProcessor::CachedPosition::reset()
|
void GCodeProcessor::CachedPosition::reset()
|
||||||
{
|
{
|
||||||
std::fill(position.begin(), position.end(), FLT_MAX);
|
std::fill(position.begin(), position.end(), FLT_MAX);
|
||||||
|
@ -1392,13 +1379,13 @@ void GCodeProcessor::process_G1(const GCodeReader::GCodeLine& line)
|
||||||
float area_toolpath_cross_section = volume_extruded_filament / d_xyz;
|
float area_toolpath_cross_section = volume_extruded_filament / d_xyz;
|
||||||
|
|
||||||
// volume extruded filament / tool displacement = area toolpath cross section
|
// volume extruded filament / tool displacement = area toolpath cross section
|
||||||
m_mm3_per_mm = round_to_nearest(area_toolpath_cross_section, 3);
|
m_mm3_per_mm = area_toolpath_cross_section;
|
||||||
#if ENABLE_GCODE_VIEWER_DATA_CHECKING
|
#if ENABLE_GCODE_VIEWER_DATA_CHECKING
|
||||||
m_mm3_per_mm_compare.update(area_toolpath_cross_section, m_extrusion_role);
|
m_mm3_per_mm_compare.update(area_toolpath_cross_section, m_extrusion_role);
|
||||||
#endif // ENABLE_GCODE_VIEWER_DATA_CHECKING
|
#endif // ENABLE_GCODE_VIEWER_DATA_CHECKING
|
||||||
|
|
||||||
if (m_end_position[Z] > m_extruded_last_z + EPSILON) {
|
if (m_end_position[Z] > m_extruded_last_z + EPSILON) {
|
||||||
m_height = round_to_nearest(m_end_position[Z] - m_extruded_last_z, 4);
|
m_height = m_end_position[Z] - m_extruded_last_z;
|
||||||
#if ENABLE_GCODE_VIEWER_DATA_CHECKING
|
#if ENABLE_GCODE_VIEWER_DATA_CHECKING
|
||||||
m_height_compare.update(m_height, m_extrusion_role);
|
m_height_compare.update(m_height, m_extrusion_role);
|
||||||
#endif // ENABLE_GCODE_VIEWER_DATA_CHECKING
|
#endif // ENABLE_GCODE_VIEWER_DATA_CHECKING
|
||||||
|
@ -1407,13 +1394,13 @@ void GCodeProcessor::process_G1(const GCodeReader::GCodeLine& line)
|
||||||
|
|
||||||
if (m_extrusion_role == erExternalPerimeter)
|
if (m_extrusion_role == erExternalPerimeter)
|
||||||
// cross section: rectangle
|
// cross section: rectangle
|
||||||
m_width = round_to_nearest(delta_pos[E] * static_cast<float>(M_PI * sqr(1.05 * filament_radius)) / (d_xyz * m_height), 3);
|
m_width = delta_pos[E] * static_cast<float>(M_PI * sqr(1.05 * filament_radius)) / (d_xyz * m_height);
|
||||||
else if (m_extrusion_role == erBridgeInfill || m_extrusion_role == erNone)
|
else if (m_extrusion_role == erBridgeInfill || m_extrusion_role == erNone)
|
||||||
// cross section: circle
|
// cross section: circle
|
||||||
m_width = round_to_nearest(static_cast<float>(m_filament_diameters[m_extruder_id]) * std::sqrt(delta_pos[E] / d_xyz), 3);
|
m_width = static_cast<float>(m_filament_diameters[m_extruder_id]) * std::sqrt(delta_pos[E] / d_xyz);
|
||||||
else
|
else
|
||||||
// cross section: rectangle + 2 semicircles
|
// cross section: rectangle + 2 semicircles
|
||||||
m_width = round_to_nearest(delta_pos[E] * static_cast<float>(M_PI * sqr(filament_radius)) / (d_xyz * m_height) + static_cast<float>(1.0 - 0.25 * M_PI) * m_height, 3);
|
m_width = delta_pos[E] * static_cast<float>(M_PI * sqr(filament_radius)) / (d_xyz * m_height) + static_cast<float>(1.0 - 0.25 * M_PI) * m_height;
|
||||||
|
|
||||||
#if ENABLE_GCODE_VIEWER_DATA_CHECKING
|
#if ENABLE_GCODE_VIEWER_DATA_CHECKING
|
||||||
m_width_compare.update(m_width, m_extrusion_role);
|
m_width_compare.update(m_width, m_extrusion_role);
|
||||||
|
@ -1983,19 +1970,20 @@ void GCodeProcessor::process_T(const std::string& command)
|
||||||
|
|
||||||
void GCodeProcessor::store_move_vertex(EMoveType type)
|
void GCodeProcessor::store_move_vertex(EMoveType type)
|
||||||
{
|
{
|
||||||
MoveVertex vertex;
|
MoveVertex vertex = {
|
||||||
vertex.type = type;
|
type,
|
||||||
vertex.extrusion_role = m_extrusion_role;
|
m_extrusion_role,
|
||||||
vertex.position = Vec3f(m_end_position[X], m_end_position[Y], m_end_position[Z]) + m_extruder_offsets[m_extruder_id];
|
m_extruder_id,
|
||||||
vertex.delta_extruder = m_end_position[E] - m_start_position[E];
|
m_cp_color.current,
|
||||||
vertex.feedrate = m_feedrate;
|
Vec3f(m_end_position[X], m_end_position[Y], m_end_position[Z]) + m_extruder_offsets[m_extruder_id],
|
||||||
vertex.width = m_width;
|
m_end_position[E] - m_start_position[E],
|
||||||
vertex.height = m_height;
|
m_feedrate,
|
||||||
vertex.mm3_per_mm = m_mm3_per_mm;
|
m_width,
|
||||||
vertex.fan_speed = m_fan_speed;
|
m_height,
|
||||||
vertex.extruder_id = m_extruder_id;
|
m_mm3_per_mm,
|
||||||
vertex.cp_color_id = m_cp_color.current;
|
m_fan_speed,
|
||||||
vertex.time = static_cast<float>(m_result.moves.size());
|
static_cast<float>(m_result.moves.size())
|
||||||
|
};
|
||||||
m_result.moves.emplace_back(vertex);
|
m_result.moves.emplace_back(vertex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ static EMoveType buffer_type(unsigned char id) {
|
||||||
return static_cast<EMoveType>(static_cast<unsigned char>(EMoveType::Retract) + id);
|
return static_cast<EMoveType>(static_cast<unsigned char>(EMoveType::Retract) + id);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::array<float, 3> decode_color(const std::string& color) {
|
static std::array<float, 3> decode_color(const std::string& color) {
|
||||||
static const float INV_255 = 1.0f / 255.0f;
|
static const float INV_255 = 1.0f / 255.0f;
|
||||||
|
|
||||||
std::array<float, 3> ret = { 0.0f, 0.0f, 0.0f };
|
std::array<float, 3> ret = { 0.0f, 0.0f, 0.0f };
|
||||||
|
@ -56,7 +56,7 @@ std::array<float, 3> decode_color(const std::string& color) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::array<float, 3>> decode_colors(const std::vector<std::string>& colors) {
|
static std::vector<std::array<float, 3>> decode_colors(const std::vector<std::string>& colors) {
|
||||||
std::vector<std::array<float, 3>> output(colors.size(), { 0.0f, 0.0f, 0.0f });
|
std::vector<std::array<float, 3>> output(colors.size(), { 0.0f, 0.0f, 0.0f });
|
||||||
for (size_t i = 0; i < colors.size(); ++i) {
|
for (size_t i = 0; i < colors.size(); ++i) {
|
||||||
output[i] = decode_color(colors[i]);
|
output[i] = decode_color(colors[i]);
|
||||||
|
@ -64,6 +64,19 @@ std::vector<std::array<float, 3>> decode_colors(const std::vector<std::string>&
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static float round_to_nearest(float value, unsigned int decimals)
|
||||||
|
{
|
||||||
|
float res = 0.0f;
|
||||||
|
if (decimals == 0)
|
||||||
|
res = std::round(value);
|
||||||
|
else {
|
||||||
|
char buf[64];
|
||||||
|
sprintf(buf, "%.*g", decimals, value);
|
||||||
|
res = std::stof(buf);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
void GCodeViewer::VBuffer::reset()
|
void GCodeViewer::VBuffer::reset()
|
||||||
{
|
{
|
||||||
// release gpu memory
|
// release gpu memory
|
||||||
|
@ -98,9 +111,11 @@ bool GCodeViewer::Path::matches(const GCodeProcessor::MoveVertex& move) const
|
||||||
case EMoveType::Unretract:
|
case EMoveType::Unretract:
|
||||||
case EMoveType::Extrude:
|
case EMoveType::Extrude:
|
||||||
{
|
{
|
||||||
return type == move.type && role == move.extrusion_role && height == move.height && width == move.width &&
|
// use rounding to reduce the number of generated paths
|
||||||
feedrate == move.feedrate && fan_speed == move.fan_speed && volumetric_rate == move.volumetric_rate() &&
|
return type == move.type && role == move.extrusion_role && height == round_to_nearest(move.height, 2) &&
|
||||||
extruder_id == move.extruder_id && cp_color_id == move.cp_color_id;
|
width == round_to_nearest(move.width, 2) && feedrate == move.feedrate && fan_speed == move.fan_speed &&
|
||||||
|
volumetric_rate == round_to_nearest(move.volumetric_rate(), 2) && extruder_id == move.extruder_id &&
|
||||||
|
cp_color_id == move.cp_color_id;
|
||||||
}
|
}
|
||||||
case EMoveType::Travel:
|
case EMoveType::Travel:
|
||||||
{
|
{
|
||||||
|
@ -124,7 +139,10 @@ void GCodeViewer::TBuffer::reset()
|
||||||
void GCodeViewer::TBuffer::add_path(const GCodeProcessor::MoveVertex& move, unsigned int i_id, unsigned int s_id)
|
void GCodeViewer::TBuffer::add_path(const GCodeProcessor::MoveVertex& move, unsigned int i_id, unsigned int s_id)
|
||||||
{
|
{
|
||||||
Path::Endpoint endpoint = { i_id, s_id, move.position };
|
Path::Endpoint endpoint = { i_id, s_id, move.position };
|
||||||
paths.push_back({ move.type, move.extrusion_role, endpoint, endpoint, move.delta_extruder, move.height, move.width, move.feedrate, move.fan_speed, move.volumetric_rate(), move.extruder_id, move.cp_color_id });
|
// use rounding to reduce the number of generated paths
|
||||||
|
paths.push_back({ move.type, move.extrusion_role, endpoint, endpoint, move.delta_extruder,
|
||||||
|
round_to_nearest(move.height, 2), round_to_nearest(move.width, 2), move.feedrate, move.fan_speed,
|
||||||
|
round_to_nearest(move.volumetric_rate(), 2), move.extruder_id, move.cp_color_id });
|
||||||
}
|
}
|
||||||
|
|
||||||
GCodeViewer::Color GCodeViewer::Extrusions::Range::get_color_at(float value) const
|
GCodeViewer::Color GCodeViewer::Extrusions::Range::get_color_at(float value) const
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue