Merge branch 'master' into lm_sla_supports_auto

This commit is contained in:
Lukas Matena 2018-12-19 12:25:58 +01:00
commit 75ef3431b3
77 changed files with 5581 additions and 1010 deletions

View file

@ -194,6 +194,10 @@ target_link_libraries(libslic3r
tbb
)
if(WIN32)
target_link_libraries(libslic3r Psapi.lib)
endif()
if(SLIC3R_PROFILE)
target_link_libraries(slic3r Shiny)
endif()

View file

@ -1,6 +1,7 @@
#ifndef slic3r_Channel_hpp_
#define slic3r_Channel_hpp_
#include <memory>
#include <deque>
#include <condition_variable>
#include <mutex>
@ -13,32 +14,26 @@ namespace Slic3r {
template<class T> class Channel
{
private:
using UniqueLock = std::unique_lock<std::mutex>;
using Queue = std::deque<T>;
public:
class Guard
using UniqueLock = std::unique_lock<std::mutex>;
template<class Ptr> class Unlocker
{
public:
Guard(UniqueLock lock, const Queue &queue) : m_lock(std::move(lock)), m_queue(queue) {}
Guard(const Guard &other) = delete;
Guard(Guard &&other) = delete;
~Guard() {}
Unlocker(UniqueLock lock) : m_lock(std::move(lock)) {}
Unlocker(const Unlocker &other) noexcept : m_lock(std::move(other.m_lock)) {} // XXX: done beacuse of MSVC 2013 not supporting init of deleter by move
Unlocker(Unlocker &&other) noexcept : m_lock(std::move(other.m_lock)) {}
Unlocker& operator=(const Unlocker &other) = delete;
Unlocker& operator=(Unlocker &&other) { m_lock = std::move(other.m_lock); }
// Access trampolines
size_t size() const noexcept { return m_queue.size(); }
bool empty() const noexcept { return m_queue.empty(); }
typename Queue::const_iterator begin() const noexcept { return m_queue.begin(); }
typename Queue::const_iterator end() const noexcept { return m_queue.end(); }
typename Queue::const_reference operator[](size_t i) const { return m_queue[i]; }
Guard& operator=(const Guard &other) = delete;
Guard& operator=(Guard &&other) = delete;
void operator()(Ptr*) { m_lock.unlock(); }
private:
UniqueLock m_lock;
const Queue &m_queue;
mutable UniqueLock m_lock; // XXX: mutable: see above
};
using Queue = std::deque<T>;
using LockedConstPtr = std::unique_ptr<const Queue, Unlocker<const Queue>>;
using LockedPtr = std::unique_ptr<Queue, Unlocker<Queue>>;
Channel() {}
~Channel() {}
@ -56,7 +51,7 @@ public:
{
{
UniqueLock lock(m_mutex);
m_queue.push_back(std::forward(item));
m_queue.push_back(std::forward<T>(item));
}
if (! silent) { m_condition.notify_one(); }
}
@ -82,19 +77,22 @@ public:
}
}
// Unlocked observers
// Thread unsafe! Keep in mind you need to re-verify the result after acquiring lock!
size_t size() const noexcept { return m_queue.size(); }
bool empty() const noexcept { return m_queue.empty(); }
// Unlocked observers/hints
// Thread unsafe! Keep in mind you need to re-verify the result after locking!
size_t size_hint() const noexcept { return m_queue.size(); }
Guard read() const
LockedConstPtr lock_read() const
{
return Guard(UniqueLock(m_mutex), m_queue);
return LockedConstPtr(&m_queue, Unlocker<const Queue>(UniqueLock(m_mutex)));
}
LockedPtr lock_rw()
{
return LockedPtr(&m_queue, Unlocker<Queue>(UniqueLock(m_mutex)));
}
private:
Queue m_queue;
std::mutex m_mutex;
mutable std::mutex m_mutex;
std::condition_variable m_condition;
};

View file

@ -96,7 +96,6 @@ static void extract_model_from_archive(
const char *model_xml = strstr(scene_xml_data.data(), model_name_tag);
const char *zero_tag = "<zero>";
const char *zero_xml = strstr(scene_xml_data.data(), zero_tag);
float trafo[3][4] = { 0 };
Vec3d instance_rotation = Vec3d::Zero();
Vec3d instance_scaling_factor = Vec3d::Ones();
Vec3d instance_offset = Vec3d::Zero();
@ -124,19 +123,7 @@ static void extract_model_from_archive(
"[%f, %f, %f]", zero, zero+1, zero+2) == 3) {
instance_scaling_factor = Vec3d((double)scale[0], (double)scale[1], (double)scale[2]);
instance_rotation = Vec3d(-(double)rotation[0], -(double)rotation[1], -(double)rotation[2]);
Eigen::Matrix3f mat_rot, mat_scale, mat_trafo;
mat_rot = Eigen::AngleAxisf(-rotation[2], Eigen::Vector3f::UnitZ()) *
Eigen::AngleAxisf(-rotation[1], Eigen::Vector3f::UnitY()) *
Eigen::AngleAxisf(-rotation[0], Eigen::Vector3f::UnitX());
mat_scale = Eigen::Scaling(scale[0], scale[1], scale[2]);
mat_trafo = mat_rot * mat_scale;
for (size_t r = 0; r < 3; ++ r) {
for (size_t c = 0; c < 3; ++ c)
trafo[r][c] += mat_trafo(r, c);
}
instance_offset = Vec3d((double)(position[0] - zero[0]), (double)(position[1] - zero[1]), (double)(position[2] - zero[2]));
// CHECK_ME -> Is the following correct ?
trafo[2][3] = position[2] / (float)instance_scaling_factor(2);
trafo_set = true;
}
const char *group_tag = "<group>";
@ -189,8 +176,6 @@ static void extract_model_from_archive(
// All the faces have been read.
stl_get_size(&stl);
mesh.repair();
// Transform the model.
stl_transform(&stl, &trafo[0][0]);
if (std::abs(stl.stats.min(2)) < EPSILON)
stl.stats.min(2) = 0.;
// Add a mesh to a model.
@ -274,8 +259,6 @@ static void extract_model_from_archive(
memcpy((void*)stl.facet_start, facets.data(), facets.size() * 50);
stl_get_size(&stl);
mesh.repair();
// Transform the model.
stl_transform(&stl, &trafo[0][0]);
// Add a mesh to a model.
if (mesh.facets_count() > 0)
mesh_valid = true;
@ -329,7 +312,7 @@ bool load_prus(const char *path, Model *model)
if (! mz_zip_reader_file_stat(&archive, i, &stat))
continue;
std::vector<char> buffer;
buffer.assign((size_t)stat.m_uncomp_size + 1, 0);
buffer.assign((size_t)stat.m_uncomp_size, 0);
res = mz_zip_reader_extract_file_to_mem(&archive, stat.m_filename, (char*)buffer.data(), (size_t)stat.m_uncomp_size, 0);
if (res == MZ_FALSE)
std::runtime_error(std::string("Error while extracting a file from ") + path);

View file

@ -423,7 +423,7 @@ void GCode::do_export(Print *print, const char *path, GCodePreviewData *preview_
print->set_started(psGCodeExport);
BOOST_LOG_TRIVIAL(info) << "Exporting G-code...";
BOOST_LOG_TRIVIAL(info) << "Exporting G-code..." << log_memory_info();
// Remove the old g-code if it exists.
boost::nowide::remove(path);
@ -435,9 +435,11 @@ void GCode::do_export(Print *print, const char *path, GCodePreviewData *preview_
if (file == nullptr)
throw std::runtime_error(std::string("G-code export to ") + path + " failed.\nCannot open the file for writing.\n");
m_enable_analyzer = preview_data != nullptr;
try {
m_placeholder_parser_failed_templates.clear();
this->_do_export(*print, file, preview_data);
this->_do_export(*print, file);
fflush(file);
if (ferror(file)) {
fclose(file);
@ -453,15 +455,6 @@ void GCode::do_export(Print *print, const char *path, GCodePreviewData *preview_
}
fclose(file);
if (print->config().remaining_times.value) {
BOOST_LOG_TRIVIAL(debug) << "Processing remaining times for normal mode";
m_normal_time_estimator.post_process_remaining_times(path_tmp, 60.0f);
if (m_silent_time_estimator_enabled) {
BOOST_LOG_TRIVIAL(debug) << "Processing remaining times for silent mode";
m_silent_time_estimator.post_process_remaining_times(path_tmp, 60.0f);
}
}
if (! m_placeholder_parser_failed_templates.empty()) {
// G-code export proceeded, but some of the PlaceholderParser substitutions failed.
std::string msg = std::string("G-code export to ") + path + " failed due to invalid custom G-code sections:\n\n";
@ -475,12 +468,30 @@ void GCode::do_export(Print *print, const char *path, GCodePreviewData *preview_
throw std::runtime_error(msg);
}
if (print->config().remaining_times.value) {
BOOST_LOG_TRIVIAL(debug) << "Processing remaining times for normal mode";
m_normal_time_estimator.post_process_remaining_times(path_tmp, 60.0f);
m_normal_time_estimator.reset();
if (m_silent_time_estimator_enabled) {
BOOST_LOG_TRIVIAL(debug) << "Processing remaining times for silent mode";
m_silent_time_estimator.post_process_remaining_times(path_tmp, 60.0f);
m_silent_time_estimator.reset();
}
}
// starts analyzer calculations
if (m_enable_analyzer) {
BOOST_LOG_TRIVIAL(debug) << "Preparing G-code preview data";
m_analyzer.calc_gcode_preview_data(*preview_data);
m_analyzer.reset();
}
if (rename_file(path_tmp, path) != 0)
throw std::runtime_error(
std::string("Failed to rename the output G-code file from ") + path_tmp + " to " + path + '\n' +
"Is " + path_tmp + " locked?" + '\n');
BOOST_LOG_TRIVIAL(info) << "Exporting G-code finished";
BOOST_LOG_TRIVIAL(info) << "Exporting G-code finished" << log_memory_info();
print->set_done(psGCodeExport);
// Write the profiler measurements to file
@ -488,7 +499,7 @@ void GCode::do_export(Print *print, const char *path, GCodePreviewData *preview_
PROFILE_OUTPUT(debug_out_path("gcode-export-profile.txt").c_str());
}
void GCode::_do_export(Print &print, FILE *file, GCodePreviewData *preview_data)
void GCode::_do_export(Print &print, FILE *file)
{
PROFILE_FUNC();
@ -558,7 +569,6 @@ void GCode::_do_export(Print &print, FILE *file, GCodePreviewData *preview_data)
// resets analyzer
m_analyzer.reset();
m_enable_analyzer = preview_data != nullptr;
// resets analyzer's tracking data
m_last_mm3_per_mm = GCodeAnalyzer::Default_mm3_per_mm;
@ -1034,12 +1044,6 @@ void GCode::_do_export(Print &print, FILE *file, GCodePreviewData *preview_data)
_write(file, full_config);
}
print.throw_if_canceled();
// starts analyzer calculations
if (preview_data != nullptr) {
BOOST_LOG_TRIVIAL(debug) << "Preparing G-code preview data";
m_analyzer.calc_gcode_preview_data(*preview_data);
}
}
std::string GCode::placeholder_parser_process(const std::string &name, const std::string &templ, unsigned int current_extruder_id, const DynamicConfig *config_override)
@ -1231,7 +1235,7 @@ void GCode::process_layer(
const Print &print,
// Set of object & print layers of the same PrintObject and with the same print_z.
const std::vector<LayerToPrint> &layers,
const LayerTools &layer_tools,
const LayerTools &layer_tools,
// If set to size_t(-1), then print all copies of all objects.
// Otherwise print a single copy of a single object.
const size_t single_object_idx)
@ -1644,6 +1648,11 @@ void GCode::process_layer(
// printf("G-code after filter:\n%s\n", out.c_str());
_write(file, gcode);
BOOST_LOG_TRIVIAL(trace) << "Exported layer " << layer.id() << " print_z " << print_z <<
", time estimator memory: " <<
format_memsize_MB(m_normal_time_estimator.memory_used() + m_silent_time_estimator_enabled ? m_silent_time_estimator.memory_used() : 0) <<
", analyzer memory: " <<
format_memsize_MB(m_analyzer.memory_used());
}
void GCode::apply_print_config(const PrintConfig &print_config)

View file

@ -180,7 +180,7 @@ public:
static void append_full_config(const Print& print, std::string& str);
protected:
void _do_export(Print &print, FILE *file, GCodePreviewData *preview_data);
void _do_export(Print &print, FILE *file);
// Object and support extrusions of the same PrintObject at the same print_z.
struct LayerToPrint

View file

@ -4,6 +4,7 @@
#include "../libslic3r.h"
#include "../PrintConfig.hpp"
#include "../Utils.hpp"
#include "Print.hpp"
#include "Analyzer.hpp"
@ -852,6 +853,16 @@ void GCodeAnalyzer::_calc_gcode_preview_unretractions(GCodePreviewData& preview_
}
}
// Return an estimate of the memory consumed by the time estimator.
size_t GCodeAnalyzer::memory_used() const
{
size_t out = sizeof(*this);
for (const std::pair<GCodeMove::EType, GCodeMovesList> &kvp : m_moves_map)
out += sizeof(kvp) + SLIC3R_STDVEC_MEMSIZE(kvp.second, GCodeMove);
out += m_process_output.size();
return out;
}
GCodePreviewData::Color operator + (const GCodePreviewData::Color& c1, const GCodePreviewData::Color& c2)
{
return GCodePreviewData::Color(clamp(0.0f, 1.0f, c1.rgba[0] + c2.rgba[0]),

View file

@ -120,6 +120,9 @@ public:
// Calculates all data needed for gcode visualization
void calc_gcode_preview_data(GCodePreviewData& preview_data);
// Return an estimate of the memory consumed by the time estimator.
size_t memory_used() const;
static bool is_valid_extrusion_role(ExtrusionRole role);
private:

View file

@ -2,6 +2,7 @@
#include "PreviewData.hpp"
#include <float.h>
#include <I18N.hpp>
#include "Utils.hpp"
#include <boost/format.hpp>
@ -205,6 +206,18 @@ bool GCodePreviewData::Extrusion::is_role_flag_set(unsigned int flags, Extrusion
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, ExtrusionPath);
for (const ExtrusionPath &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 GCodePreviewData::Color GCodePreviewData::Travel::Default_Type_Colors[Num_Types] =
@ -224,6 +237,15 @@ void GCodePreviewData::Travel::set_default()
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 GCodePreviewData::Color GCodePreviewData::Retraction::Default_Color = GCodePreviewData::Color(1.0f, 1.0f, 1.0f, 1.0f);
GCodePreviewData::Retraction::Position::Position(const Vec3crd& position, float width, float height)
@ -239,6 +261,11 @@ void GCodePreviewData::Retraction::set_default()
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;
@ -483,4 +510,15 @@ GCodePreviewData::LegendItemsList GCodePreviewData::get_legend_items(const std::
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);
}
} // namespace Slic3r

View file

@ -99,6 +99,9 @@ public:
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);
};
@ -144,6 +147,9 @@ public:
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
@ -166,6 +172,9 @@ public:
bool is_visible;
void set_default();
// Return an estimate of the memory consumed by the time estimator.
size_t memory_used() const;
};
struct Shell
@ -199,6 +208,9 @@ public:
std::string get_legend_title() const;
LegendItemsList get_legend_items(const std::vector<float>& tool_colors, const std::vector</*double*/std::pair<double, double>>& cp_values) const;
// Return an estimate of the memory consumed by the time estimator.
size_t memory_used() const;
};
GCodePreviewData::Color operator + (const GCodePreviewData::Color& c1, const GCodePreviewData::Color& c2);

View file

@ -315,6 +315,20 @@ public:
return *this;
};
// Let the firmware back up the active speed override value.
Writer& speed_override_backup()
{
m_gcode += "M220 B\n";
return *this;
};
// Let the firmware restore the active speed override value.
Writer& speed_override_restore()
{
m_gcode += "M220 R\n";
return *this;
};
// Set digital trimpot motor
Writer& set_extruder_trimpot(int current)
{
@ -473,7 +487,6 @@ WipeTowerPrusaMM::material_type WipeTowerPrusaMM::parse_material(const char *nam
return INVALID;
}
// Returns gcode to prime the nozzles at the front edge of the print bed.
WipeTower::ToolChangeResult WipeTowerPrusaMM::prime(
// print_z of the first layer.
@ -501,12 +514,15 @@ WipeTower::ToolChangeResult WipeTowerPrusaMM::prime(
.set_initial_tool(m_current_tool)
.append(";--------------------\n"
"; CP PRIMING START\n")
.append(";--------------------\n")
.speed_override(100);
.append(";--------------------\n");
if (m_retain_speed_override)
writer.speed_override_backup();
writer.speed_override(100);
writer.set_initial_position(xy(0.f, 0.f)) // Always move to the starting position
.travel(cleaning_box.ld, 7200)
.set_extruder_trimpot(750); // Increase the extruder driver current to allow fast ramming.
.travel(cleaning_box.ld, 7200);
if (m_set_extruder_trimpot)
writer.set_extruder_trimpot(750); // Increase the extruder driver current to allow fast ramming.
for (size_t idx_tool = 0; idx_tool < tools.size(); ++ idx_tool) {
unsigned int tool = tools[idx_tool];
@ -533,8 +549,11 @@ WipeTower::ToolChangeResult WipeTowerPrusaMM::prime(
// in the output gcode - we should not remember emitting them (we will output them twice in the worst case)
// Reset the extruder current to a normal value.
writer.set_extruder_trimpot(550)
.feedrate(6000)
if (m_set_extruder_trimpot)
writer.set_extruder_trimpot(550);
if (m_retain_speed_override)
writer.speed_override_restore();
writer.feedrate(6000)
.flush_planner_queue()
.reset_extruder()
.append("; CP PRIMING END\n"
@ -600,14 +619,17 @@ WipeTower::ToolChangeResult WipeTowerPrusaMM::tool_change(unsigned int tool, boo
"; CP TOOLCHANGE START\n")
.comment_with_value(" toolchange #", m_num_tool_changes + 1) // the number is zero-based
.comment_material(m_filpar[m_current_tool].material)
.append(";--------------------\n")
.speed_override(100);
.append(";--------------------\n");
if (m_retain_speed_override)
writer.speed_override_backup();
writer.speed_override(100);
xy initial_position = cleaning_box.ld + WipeTower::xy(0.f,m_depth_traversed);
writer.set_initial_position(initial_position, m_wipe_tower_width, m_wipe_tower_depth, m_internal_rotation);
// Increase the extruder driver current to allow fast ramming.
writer.set_extruder_trimpot(750);
if (m_set_extruder_trimpot)
writer.set_extruder_trimpot(550);
// Ram the hot material out of the melt zone, retract the filament into the cooling tubes and let it cool.
if (tool != (unsigned int)-1){ // This is not the last change.
@ -635,8 +657,11 @@ WipeTower::ToolChangeResult WipeTowerPrusaMM::tool_change(unsigned int tool, boo
}
}
writer.set_extruder_trimpot(550) // Reset the extruder current to a normal value.
.feedrate(6000)
if (m_set_extruder_trimpot)
writer.set_extruder_trimpot(550); // Reset the extruder current to a normal value.
if (m_retain_speed_override)
writer.speed_override_restore();
writer.feedrate(6000)
.flush_planner_queue()
.reset_extruder()
.append("; CP TOOLCHANGE END\n"
@ -881,14 +906,15 @@ void WipeTowerPrusaMM::toolchange_Change(
case FLEX: speed_override = 35; break;
default: speed_override = 100;
}
writer.set_tool(new_tool)
.speed_override(speed_override)
.flush_planner_queue();
writer.set_tool(new_tool);
if (m_retain_speed_override)
assert(speed_override == 100);
else
writer.speed_override(speed_override);
writer.flush_planner_queue();
m_current_tool = new_tool;
}
void WipeTowerPrusaMM::toolchange_Load(
PrusaMultiMaterial::Writer &writer,
const box_coordinates &cleaning_box)
@ -916,12 +942,10 @@ void WipeTowerPrusaMM::toolchange_Load(
.resume_preview();
// Reset the extruder current to the normal value.
writer.set_extruder_trimpot(550);
if (m_set_extruder_trimpot)
writer.set_extruder_trimpot(550);
}
// Wipe the newly loaded filament until the end of the assigned wipe area.
void WipeTowerPrusaMM::toolchange_Wipe(
PrusaMultiMaterial::Writer &writer,

View file

@ -44,7 +44,8 @@ public:
// width -- width of wipe tower in mm ( default 60 mm - leave as it is )
// wipe_area -- space available for one toolchange in mm
WipeTowerPrusaMM(float x, float y, float width, float rotation_angle, float cooling_tube_retraction,
float cooling_tube_length, float parking_pos_retraction, float extra_loading_move, float bridging,
float cooling_tube_length, float parking_pos_retraction, float extra_loading_move,
float bridging, bool set_extruder_trimpot,
const std::vector<std::vector<float>>& wiping_matrix, unsigned int initial_tool) :
m_wipe_tower_pos(x, y),
m_wipe_tower_width(width),
@ -57,6 +58,7 @@ public:
m_parking_pos_retraction(parking_pos_retraction),
m_extra_loading_move(extra_loading_move),
m_bridging(bridging),
m_set_extruder_trimpot(set_extruder_trimpot),
m_current_tool(initial_tool),
wipe_volumes(wiping_matrix)
{}
@ -73,6 +75,11 @@ public:
m_filpar.push_back(FilamentParameters());
m_filpar[idx].material = material;
if (material == FLEX || material == SCAFF || material == PVA) {
// MMU2 lowers the print speed using the speed override (M220) for printing of soluble PVA/BVOH and flex materials.
// Therefore it does not make sense to use the new M220 B and M220 R (backup / restore).
m_retain_speed_override = false;
}
m_filpar[idx].temperature = temp;
m_filpar[idx].first_layer_temperature = first_layer_temp;
m_filpar[idx].loading_speed = loading_speed;
@ -212,6 +219,8 @@ private:
float m_parking_pos_retraction = 0.f;
float m_extra_loading_move = 0.f;
float m_bridging = 0.f;
bool m_set_extruder_trimpot = false;
bool m_retain_speed_override = true;
bool m_adhesion = true;
float m_perimeter_width = 0.4 * Width_To_Nozzle_Ratio; // Width of an extrusion line, also a perimeter spacing for 100% infill.

View file

@ -290,7 +290,8 @@ namespace Slic3r {
// buffer line to export only when greater than 64K to reduce writing calls
std::string export_line;
char time_line[64];
while (std::getline(in, gcode_line))
G1LineIdToBlockIdMap::const_iterator it_line_id = _g1_line_ids.begin();
while (std::getline(in, gcode_line))
{
if (!in.good())
{
@ -310,29 +311,29 @@ namespace Slic3r {
// add remaining time lines where needed
_parser.parse_line(gcode_line,
[this, &g1_lines_count, &last_recorded_time, &time_line, &gcode_line, time_mask, interval](GCodeReader& reader, const GCodeReader::GCodeLine& line)
[this, &it_line_id, &g1_lines_count, &last_recorded_time, &time_line, &gcode_line, time_mask, interval](GCodeReader& reader, const GCodeReader::GCodeLine& line)
{
if (line.cmd_is("G1"))
{
++g1_lines_count;
if (!line.has_e())
return;
assert(it_line_id == _g1_line_ids.end() || it_line_id->first >= g1_lines_count);
G1LineIdToBlockIdMap::const_iterator it = _g1_line_ids.find(g1_lines_count);
if ((it != _g1_line_ids.end()) && (it->second < (unsigned int)_blocks.size()))
{
const Block& block = _blocks[it->second];
if (block.elapsed_time != -1.0f)
const Block *block = nullptr;
if (it_line_id != _g1_line_ids.end() && it_line_id->first == g1_lines_count) {
if (line.has_e() && it_line_id->second < (unsigned int)_blocks.size())
block = &_blocks[it_line_id->second];
++it_line_id;
}
if (block != nullptr && block->elapsed_time != -1.0f) {
float block_remaining_time = _time - block->elapsed_time;
if (std::abs(last_recorded_time - block_remaining_time) > interval)
{
float block_remaining_time = _time - block.elapsed_time;
if (std::abs(last_recorded_time - block_remaining_time) > interval)
{
sprintf(time_line, time_mask.c_str(), std::to_string((int)(100.0f * block.elapsed_time / _time)).c_str(), _get_time_minutes(block_remaining_time).c_str());
gcode_line += time_line;
sprintf(time_line, time_mask.c_str(), std::to_string((int)(100.0f * block->elapsed_time / _time)).c_str(), _get_time_minutes(block_remaining_time).c_str());
gcode_line += time_line;
last_recorded_time = block_remaining_time;
}
last_recorded_time = block_remaining_time;
}
}
}
@ -667,6 +668,15 @@ namespace Slic3r {
return _get_time_minutes(get_time());
}
// Return an estimate of the memory consumed by the time estimator.
size_t GCodeTimeEstimator::memory_used() const
{
size_t out = sizeof(*this);
out += SLIC3R_STDVEC_MEMSIZE(this->_blocks, Block);
out += SLIC3R_STDVEC_MEMSIZE(this->_g1_line_ids, G1LineIdToBlockId);
return out;
}
void GCodeTimeEstimator::_reset()
{
_curr.reset();
@ -1072,7 +1082,7 @@ namespace Slic3r {
// adds block to blocks list
_blocks.emplace_back(block);
_g1_line_ids.insert(G1LineIdToBlockIdMap::value_type(get_g1_line_id(), (unsigned int)_blocks.size() - 1));
_g1_line_ids.emplace_back(G1LineIdToBlockIdMap::value_type(get_g1_line_id(), (unsigned int)_blocks.size() - 1));
}
void GCodeTimeEstimator::_processG4(const GCodeReader::GCodeLine& line)
@ -1223,7 +1233,8 @@ namespace Slic3r {
return;
// see http://reprap.org/wiki/G-code#M203:_Set_maximum_feedrate
float factor = (dialect == gcfMarlin) ? 1.0f : MMMIN_TO_MMSEC;
// http://smoothieware.org/supported-g-codes
float factor = (dialect == gcfMarlin || dialect == gcfSmoothie) ? 1.0f : MMMIN_TO_MMSEC;
if (line.has_x())
set_axis_max_feedrate(X, line.x() * factor);

View file

@ -209,7 +209,8 @@ namespace Slic3r {
typedef std::map<Block::EMoveType, MoveStats> MovesStatsMap;
#endif // ENABLE_MOVE_STATS
typedef std::map<unsigned int, unsigned int> G1LineIdToBlockIdMap;
typedef std::pair<unsigned int, unsigned int> G1LineIdToBlockId;
typedef std::vector<G1LineIdToBlockId> G1LineIdToBlockIdMap;
private:
EMode _mode;
@ -338,6 +339,9 @@ namespace Slic3r {
// Returns the estimated time, in minutes (integer)
std::string get_time_minutes() const;
// Return an estimate of the memory consumed by the time estimator.
size_t memory_used() const;
private:
void _reset();
void _reset_time();

View file

@ -17,6 +17,16 @@ Layer::~Layer()
m_regions.clear();
}
// Test whether whether there are any slices assigned to this layer.
bool Layer::empty() const
{
for (const LayerRegion *layerm : m_regions)
if (layerm != nullptr && ! layerm->slices.empty())
// Non empty layer.
return false;
return true;
}
LayerRegion* Layer::add_region(PrintRegion* print_region)
{
m_regions.emplace_back(new LayerRegion(this, print_region));

View file

@ -114,7 +114,8 @@ public:
LayerRegion* get_region(int idx) { return m_regions[idx]; }
LayerRegion* add_region(PrintRegion* print_region);
const LayerRegionPtrs& regions() const { return m_regions; }
// Test whether whether there are any slices assigned to this layer.
bool empty() const;
void make_slices();
void merge_slices();
template <class T> bool any_internal_region_slice_contains(const T &item) const {

View file

@ -34,23 +34,22 @@ bool Line::intersection_infinite(const Line &other, Point* point) const
return true;
}
/* distance to the closest point of line */
double Line::distance_to(const Point &point) const
// Distance to the closest point of line.
double Line::distance_to_squared(const Point &point, const Point &a, const Point &b)
{
const Line &line = *this;
const Vec2d v = (line.b - line.a).cast<double>();
const Vec2d va = (point - line.a).cast<double>();
const Vec2d v = (b - a).cast<double>();
const Vec2d va = (point - a).cast<double>();
const double l2 = v.squaredNorm(); // avoid a sqrt
if (l2 == 0.0)
// line.a == line.b case
return va.norm();
// Consider the line extending the segment, parameterized as line.a + t (line.b - line.a).
// a == b case
return va.squaredNorm();
// Consider the line extending the segment, parameterized as a + t (b - a).
// We find projection of this point onto the line.
// It falls where t = [(this-line.a) . (line.b-line.a)] / |line.b-line.a|^2
// It falls where t = [(this-a) . (b-a)] / |b-a|^2
const double t = va.dot(v) / l2;
if (t < 0.0) return va.norm(); // beyond the 'a' end of the segment
else if (t > 1.0) return (point - line.b).cast<double>().norm(); // beyond the 'b' end of the segment
return (t * v - va).norm();
if (t < 0.0) return va.squaredNorm(); // beyond the 'a' end of the segment
else if (t > 1.0) return (point - b).cast<double>().squaredNorm(); // beyond the 'b' end of the segment
return (t * v - va).squaredNorm();
}
double Line::perp_distance_to(const Point &point) const

View file

@ -31,7 +31,8 @@ public:
Point midpoint() const { return (this->a + this->b) / 2; }
bool intersection_infinite(const Line &other, Point* point) const;
bool operator==(const Line &rhs) const { return this->a == rhs.a && this->b == rhs.b; }
double distance_to(const Point &point) const;
double distance_to_squared(const Point &point) const { return distance_to_squared(point, this->a, this->b); }
double distance_to(const Point &point) const { return distance_to(point, this->a, this->b); }
double perp_distance_to(const Point &point) const;
bool parallel_to(double angle) const;
bool parallel_to(const Line &line) const { return this->parallel_to(line.direction()); }
@ -43,6 +44,9 @@ public:
bool intersection(const Line& line, Point* intersection) const;
double ccw(const Point& point) const { return point.ccw(*this); }
static double distance_to_squared(const Point &point, const Point &a, const Point &b);
static double distance_to(const Point &point, const Point &a, const Point &b) { return sqrt(distance_to_squared(point, a, b)); }
Point a;
Point b;
};

View file

@ -809,6 +809,25 @@ TriangleMesh ModelObject::raw_mesh() const
return mesh;
}
// Non-transformed (non-rotated, non-scaled, non-translated) sum of all object volumes.
TriangleMesh ModelObject::full_raw_mesh() const
{
TriangleMesh mesh;
for (const ModelVolume *v : this->volumes)
#if ENABLE_MODELVOLUME_TRANSFORM
{
TriangleMesh vol_mesh(v->mesh);
vol_mesh.transform(v->get_matrix());
mesh.merge(vol_mesh);
}
#else
{
mesh.merge(v->mesh);
}
#endif // ENABLE_MODELVOLUME_TRANSFORM
return mesh;
}
// A transformed snug bounding box around the non-modifier object volumes, without the translation applied.
// This bounding box is only used for the actual slicing.
BoundingBoxf3 ModelObject::raw_bounding_box() const
@ -964,6 +983,16 @@ void ModelObject::mirror(Axis axis)
this->invalidate_bounding_box();
}
void ModelObject::scale_mesh(const Vec3d &versor)
{
for (ModelVolume *v : this->volumes)
{
v->scale_geometry(versor);
v->set_offset(versor.cwiseProduct(v->get_offset()));
}
this->invalidate_bounding_box();
}
size_t ModelObject::materials_count() const
{
std::set<t_model_material_id> material_ids;
@ -1495,6 +1524,12 @@ void ModelVolume::mirror(Axis axis)
#endif // ENABLE_MODELVOLUME_TRANSFORM
}
void ModelVolume::scale_geometry(const Vec3d& versor)
{
mesh.scale(versor);
m_convex_hull.scale(versor);
}
#if !ENABLE_MODELVOLUME_TRANSFORM
void ModelInstance::set_rotation(const Vec3d& rotation)
{

View file

@ -218,6 +218,8 @@ public:
// Non-transformed (non-rotated, non-scaled, non-translated) sum of non-modifier object volumes.
// Currently used by ModelObject::mesh() and to calculate the 2D envelope for 2D platter.
TriangleMesh raw_mesh() const;
// Non-transformed (non-rotated, non-scaled, non-translated) sum of all object volumes.
TriangleMesh full_raw_mesh() const;
// A transformed snug bounding box around the non-modifier object volumes, without the translation applied.
// This bounding box is only used for the actual slicing.
BoundingBoxf3 raw_bounding_box() const;
@ -235,6 +237,9 @@ public:
void rotate(double angle, Axis axis);
void rotate(double angle, const Vec3d& axis);
void mirror(Axis axis);
void scale_mesh(const Vec3d& versor);
size_t materials_count() const;
size_t facets_count() const;
bool needed_repair() const;
@ -329,6 +334,8 @@ public:
void rotate(double angle, const Vec3d& axis);
void mirror(Axis axis);
void scale_geometry(const Vec3d& versor);
#if ENABLE_MODELVOLUME_TRANSFORM
// translates the mesh and the convex hull so that the origin of their vertices is in the center of this volume's bounding box
void center_geometry();

View file

@ -162,45 +162,51 @@ bool MultiPoint::first_intersection(const Line& line, Point* intersection) const
return found;
}
//FIXME This is very inefficient in term of memory use.
// The recursive algorithm shall run in place, not allocating temporary data in each recursion.
Points
MultiPoint::_douglas_peucker(const Points &points, const double tolerance)
std::vector<Point> MultiPoint::_douglas_peucker(const std::vector<Point>& pts, const double tolerance)
{
assert(points.size() >= 2);
Points results;
double dmax = 0;
size_t index = 0;
Line full(points.front(), points.back());
for (Points::const_iterator it = points.begin() + 1; it != points.end(); ++it) {
// we use shortest distance, not perpendicular distance
double d = full.distance_to(*it);
if (d > dmax) {
index = it - points.begin();
dmax = d;
std::vector<Point> result_pts;
if (! pts.empty()) {
const Point *anchor = &pts.front();
size_t anchor_idx = 0;
const Point *floater = &pts.back();
size_t floater_idx = pts.size() - 1;
result_pts.reserve(pts.size());
result_pts.emplace_back(*anchor);
if (anchor_idx != floater_idx) {
assert(pts.size() > 1);
std::vector<size_t> dpStack;
dpStack.reserve(pts.size());
dpStack.emplace_back(floater_idx);
for (;;) {
double max_distSq = 0.0;
size_t furthest_idx = anchor_idx;
// find point furthest from line seg created by (anchor, floater) and note it
for (size_t i = anchor_idx + 1; i < floater_idx; ++ i) {
double dist = Line::distance_to_squared(pts[i], *anchor, *floater);
if (dist > max_distSq) {
max_distSq = dist;
furthest_idx = i;
}
}
// remove point if less than tolerance
if (max_distSq <= tolerance) {
result_pts.emplace_back(*floater);
anchor_idx = floater_idx;
anchor = floater;
assert(dpStack.back() == floater_idx);
dpStack.pop_back();
if (dpStack.empty())
break;
floater_idx = dpStack.back();
} else {
floater_idx = furthest_idx;
dpStack.emplace_back(floater_idx);
}
floater = &pts[floater_idx];
}
}
}
if (dmax >= tolerance) {
Points dp0;
dp0.reserve(index + 1);
dp0.insert(dp0.end(), points.begin(), points.begin() + index + 1);
// Recursive call.
Points dp1 = MultiPoint::_douglas_peucker(dp0, tolerance);
results.reserve(results.size() + dp1.size() - 1);
results.insert(results.end(), dp1.begin(), dp1.end() - 1);
dp0.clear();
dp0.reserve(points.size() - index);
dp0.insert(dp0.end(), points.begin() + index, points.end());
// Recursive call.
dp1 = MultiPoint::_douglas_peucker(dp0, tolerance);
results.reserve(results.size() + dp1.size());
results.insert(results.end(), dp1.begin(), dp1.end());
} else {
results.push_back(points.front());
results.push_back(points.back());
}
return results;
return result_pts;
}
// Visivalingam simplification algorithm https://github.com/slic3r/Slic3r/pull/3825

View file

@ -8,13 +8,14 @@
#include "SupportMaterial.hpp"
#include "GCode.hpp"
#include "GCode/WipeTowerPrusaMM.hpp"
#include <algorithm>
#include <unordered_set>
#include <boost/log/trivial.hpp>
#include "Utils.hpp"
#include "PrintExport.hpp"
#include <algorithm>
#include <unordered_set>
#include <boost/filesystem/path.hpp>
#include <boost/log/trivial.hpp>
//! macro used to mark string used at localization,
//! return same string
@ -213,6 +214,7 @@ bool Print::invalidate_state_by_config_options(const std::vector<t_config_option
|| opt_key == "filament_cooling_final_speed"
|| opt_key == "filament_ramming_parameters"
|| opt_key == "gcode_flavor"
|| opt_key == "high_current_on_filament_swap"
|| opt_key == "infill_first"
|| opt_key == "single_extruder_multi_material"
|| opt_key == "spiral_vase"
@ -1051,10 +1053,12 @@ Print::ApplyStatus Print::apply(const Model &model, const DynamicPrintConfig &co
goto print_object_end;
} else {
this_region_config = region_config_from_model_volume(m_default_region_config, volume, num_extruders);
for (size_t i = 0; i < region_id; ++ i)
if (m_regions[i]->config().equals(this_region_config))
// Regions were merged. Reset this print_object.
goto print_object_end;
for (size_t i = 0; i < region_id; ++i) {
const PrintRegion &region_other = *m_regions[i];
if (region_other.m_refcnt != 0 && region_other.config().equals(this_region_config))
// Regions were merged. Reset this print_object.
goto print_object_end;
}
this_region_config_set = true;
}
}
@ -1092,8 +1096,10 @@ Print::ApplyStatus Print::apply(const Model &model, const DynamicPrintConfig &co
bool fresh = print_object.region_volumes.empty();
unsigned int volume_id = 0;
for (const ModelVolume *volume : model_object.volumes) {
if (! volume->is_model_part() && ! volume->is_modifier())
continue;
if (! volume->is_model_part() && ! volume->is_modifier()) {
++ volume_id;
continue;
}
int region_id = -1;
if (&print_object == &print_object0) {
// Get the config applied to this volume.
@ -1101,9 +1107,10 @@ Print::ApplyStatus Print::apply(const Model &model, const DynamicPrintConfig &co
// Find an existing print region with the same config.
int idx_empty_slot = -1;
for (int i = 0; i < (int)m_regions.size(); ++ i) {
if (m_regions[i]->m_refcnt == 0)
idx_empty_slot = i;
else if (config.equals(m_regions[i]->config())) {
if (m_regions[i]->m_refcnt == 0) {
if (idx_empty_slot == -1)
idx_empty_slot = i;
} else if (config.equals(m_regions[i]->config())) {
region_id = i;
break;
}
@ -1469,7 +1476,7 @@ void Print::auto_assign_extruders(ModelObject* model_object) const
// Slicing process, running at a background thread.
void Print::process()
{
BOOST_LOG_TRIVIAL(info) << "Staring the slicing process.";
BOOST_LOG_TRIVIAL(info) << "Staring the slicing process." << log_memory_info();
for (PrintObject *obj : m_objects)
obj->make_perimeters();
this->set_status(70, "Infilling layers");
@ -1501,7 +1508,7 @@ void Print::process()
}
this->set_done(psWipeTower);
}
BOOST_LOG_TRIVIAL(info) << "Slicing process finished.";
BOOST_LOG_TRIVIAL(info) << "Slicing process finished." << log_memory_info();
}
// G-code export process, running at a background thread.
@ -1768,7 +1775,8 @@ void Print::_make_wipe_tower()
float(m_config.wipe_tower_width.value),
float(m_config.wipe_tower_rotation_angle.value), float(m_config.cooling_tube_retraction.value),
float(m_config.cooling_tube_length.value), float(m_config.parking_pos_retraction.value),
float(m_config.extra_loading_move.value), float(m_config.wipe_tower_bridging), wipe_volumes,
float(m_config.extra_loading_move.value), float(m_config.wipe_tower_bridging),
m_config.high_current_on_filament_swap.value, wipe_volumes,
m_wipe_tower_data.tool_ordering.first_extruder());
//wipe_tower.set_retract();

View file

@ -107,8 +107,8 @@ public:
// adds region_id, too, if necessary
void add_region_volume(unsigned int region_id, int volume_id) {
if (region_id >= region_volumes.size())
region_volumes.resize(region_id + 1);
region_volumes[region_id].push_back(volume_id);
region_volumes.resize(region_id + 1);
region_volumes[region_id].emplace_back(volume_id);
}
// This is the *total* layer count (including support layers)
// this value is not supposed to be compared with Layer::id

View file

@ -925,6 +925,15 @@ void PrintConfigDef::init_fff_params()
def->mode = comExpert;
def->default_value = new ConfigOptionEnum<GCodeFlavor>(gcfRepRap);
def = this->add("high_current_on_filament_swap", coBool);
def->label = L("High extruder current on filament swap");
def->tooltip = L("It may be beneficial to increase the extruder motor current during the filament exchange"
" sequence to allow for rapid ramming feed rates and to overcome resistance when loading"
" a filament with an ugly shaped tip.");
def->cli = "high-current-on-filament-swap!";
def->mode = comExpert;
def->default_value = new ConfigOptionBool(0);
def = this->add("infill_acceleration", coFloat);
def->label = L("Infill");
def->tooltip = L("This is the acceleration your printer will use for infill. Set zero to disable "
@ -2394,8 +2403,10 @@ void PrintConfigDef::init_sla_params()
def->tooltip = L("Display orientation");
def->cli = "display-orientation=s";
def->enum_keys_map = &ConfigOptionEnum<SLADisplayOrientation>::get_enum_values();
def->enum_values.push_back("Landscape");
def->enum_values.push_back("Portrait");
def->enum_values.push_back("landscape");
def->enum_values.push_back("portrait");
def->enum_labels.push_back(L("Landscape"));
def->enum_labels.push_back(L("Portrait"));
def->default_value = new ConfigOptionEnum<SLADisplayOrientation>(sladoPortrait);
def = this->add("printer_correction", coFloats);

View file

@ -36,7 +36,7 @@ enum GCodeFlavor {
};
enum PrintHostType {
htOctoPrint, htDuet,
htOctoPrint, htDuet, htSL1,
};
enum InfillPattern {
@ -155,8 +155,8 @@ template<> inline const t_config_enum_values& ConfigOptionEnum<FilamentType>::ge
template<> inline const t_config_enum_values& ConfigOptionEnum<SLADisplayOrientation>::get_enum_values() {
static const t_config_enum_values keys_map = {
{ "Landscape", sladoLandscape},
{ "Portrait", sladoPortrait}
{ "landscape", sladoLandscape},
{ "portrait", sladoPortrait}
};
return keys_map;
@ -627,6 +627,7 @@ public:
ConfigOptionBool variable_layer_height;
ConfigOptionFloat cooling_tube_retraction;
ConfigOptionFloat cooling_tube_length;
ConfigOptionBool high_current_on_filament_swap;
ConfigOptionFloat parking_pos_retraction;
ConfigOptionBool remaining_times;
ConfigOptionBool silent_mode;
@ -695,6 +696,7 @@ protected:
OPT_PTR(variable_layer_height);
OPT_PTR(cooling_tube_retraction);
OPT_PTR(cooling_tube_length);
OPT_PTR(high_current_on_filament_swap);
OPT_PTR(parking_pos_retraction);
OPT_PTR(remaining_times);
OPT_PTR(silent_mode);

View file

@ -5,6 +5,7 @@
#include "SupportMaterial.hpp"
#include "Surface.hpp"
#include "Slicing.hpp"
#include "Utils.hpp"
#include <utility>
#include <boost/log/trivial.hpp>
@ -132,7 +133,7 @@ void PrintObject::make_perimeters()
return;
m_print->set_status(20, "Generating perimeters");
BOOST_LOG_TRIVIAL(info) << "Generating perimeters...";
BOOST_LOG_TRIVIAL(info) << "Generating perimeters..." << log_memory_info();
// merge slices if they were split into types
if (this->typed_slices) {
@ -253,7 +254,7 @@ void PrintObject::prepare_infill()
// Decide what surfaces are to be filled.
// Here the S_TYPE_TOP / S_TYPE_BOTTOMBRIDGE / S_TYPE_BOTTOM infill is turned to just S_TYPE_INTERNAL if zero top / bottom infill layers are configured.
// Also tiny S_TYPE_INTERNAL surfaces are turned to S_TYPE_INTERNAL_SOLID.
BOOST_LOG_TRIVIAL(info) << "Preparing fill surfaces...";
BOOST_LOG_TRIVIAL(info) << "Preparing fill surfaces..." << log_memory_info();
for (auto *layer : m_layers)
for (auto *region : layer->m_regions) {
region->prepare_fill_surfaces();
@ -384,6 +385,14 @@ void PrintObject::generate_support_material()
m_print->set_status(85, "Generating support material");
this->_generate_support_material();
m_print->throw_if_canceled();
} else {
#if 0
// Printing without supports. Empty layer means some objects or object parts are levitating,
// therefore they cannot be printed without supports.
for (const Layer *layer : m_layers)
if (layer->empty())
throw std::runtime_error("Levitating objects cannot be printed without supports.");
#endif
}
this->set_done(posSupportMaterial);
}
@ -522,11 +531,13 @@ bool PrintObject::invalidate_state_by_config_options(const std::vector<t_config_
|| opt_key == "perimeter_speed"
|| opt_key == "small_perimeter_speed"
|| opt_key == "solid_infill_speed"
|| opt_key == "top_solid_infill_speed"
|| opt_key == "wipe_into_infill" // when these these two are changed, we only need to invalidate the wipe tower,
|| opt_key == "wipe_into_objects" // which we already did at the very beginning - nothing more to be done
) {
// these options only affect G-code export, so nothing to invalidate
|| opt_key == "top_solid_infill_speed") {
invalidated |= m_print->invalidate_step(psGCodeExport);
} else if (
opt_key == "wipe_into_infill"
|| opt_key == "wipe_into_objects") {
invalidated |= m_print->invalidate_step(psWipeTower);
invalidated |= m_print->invalidate_step(psGCodeExport);
} else {
// for legacy, if we can't handle this option let's invalidate all steps
this->invalidate_all_steps();
@ -547,15 +558,15 @@ bool PrintObject::invalidate_step(PrintObjectStep step)
// propagate to dependent steps
if (step == posPerimeters) {
invalidated |= this->invalidate_step(posPrepareInfill);
invalidated |= this->invalidate_steps({ posPrepareInfill, posInfill });
invalidated |= m_print->invalidate_steps({ psSkirt, psBrim });
} else if (step == posPrepareInfill) {
invalidated |= this->invalidate_step(posInfill);
} else if (step == posInfill) {
invalidated |= m_print->invalidate_steps({ psSkirt, psBrim });
} else if (step == posSlice) {
invalidated |= this->invalidate_steps({ posPerimeters, posSupportMaterial });
invalidated |= m_print->invalidate_step(psWipeTower);
invalidated |= this->invalidate_steps({ posPerimeters, posPrepareInfill, posInfill, posSupportMaterial });
invalidated |= m_print->invalidate_steps({ psSkirt, psBrim });
} else if (step == posSupportMaterial)
invalidated |= m_print->invalidate_steps({ psSkirt, psBrim });
@ -591,7 +602,7 @@ bool PrintObject::has_support_material() const
// If a part of a region is of stBottom and stTop, the stBottom wins.
void PrintObject::detect_surfaces_type()
{
BOOST_LOG_TRIVIAL(info) << "Detecting solid surfaces...";
BOOST_LOG_TRIVIAL(info) << "Detecting solid surfaces..." << log_memory_info();
// Interface shells: the intersecting parts are treated as self standing objects supporting each other.
// Each of the objects will have a full number of top / bottom layers, even if these top / bottom layers
@ -783,7 +794,7 @@ void PrintObject::detect_surfaces_type()
void PrintObject::process_external_surfaces()
{
BOOST_LOG_TRIVIAL(info) << "Processing external surfaces...";
BOOST_LOG_TRIVIAL(info) << "Processing external surfaces..." << log_memory_info();
for (size_t region_id = 0; region_id < this->region_volumes.size(); ++region_id) {
const PrintRegion &region = *m_print->regions()[region_id];
@ -808,7 +819,7 @@ void PrintObject::discover_vertical_shells()
{
PROFILE_FUNC();
BOOST_LOG_TRIVIAL(info) << "Discovering vertical shells...";
BOOST_LOG_TRIVIAL(info) << "Discovering vertical shells..." << log_memory_info();
struct DiscoverVerticalShellsCacheEntry
{
@ -1192,7 +1203,7 @@ void PrintObject::discover_vertical_shells()
sparse infill */
void PrintObject::bridge_over_infill()
{
BOOST_LOG_TRIVIAL(info) << "Bridge over infill...";
BOOST_LOG_TRIVIAL(info) << "Bridge over infill..." << log_memory_info();
for (size_t region_id = 0; region_id < this->region_volumes.size(); ++ region_id) {
const PrintRegion &region = *m_print->regions()[region_id];
@ -1377,7 +1388,7 @@ bool PrintObject::update_layer_height_profile()
// this should be idempotent
void PrintObject::_slice()
{
BOOST_LOG_TRIVIAL(info) << "Slicing objects...";
BOOST_LOG_TRIVIAL(info) << "Slicing objects..." << log_memory_info();
this->typed_slices = false;
@ -1463,10 +1474,8 @@ void PrintObject::_slice()
BOOST_LOG_TRIVIAL(debug) << "Slicing objects - removing top empty layers";
while (! m_layers.empty()) {
const Layer *layer = m_layers.back();
for (size_t region_id = 0; region_id < this->region_volumes.size(); ++ region_id)
if (layer->m_regions[region_id] != nullptr && ! layer->m_regions[region_id]->slices.empty())
// Non empty layer.
goto end;
if (! layer->empty())
goto end;
delete layer;
m_layers.pop_back();
if (! m_layers.empty())
@ -1701,7 +1710,7 @@ void PrintObject::_make_perimeters()
if (! this->set_started(posPerimeters))
return;
BOOST_LOG_TRIVIAL(info) << "Generating perimeters...";
BOOST_LOG_TRIVIAL(info) << "Generating perimeters..." << log_memory_info();
// merge slices if they were split into types
if (this->typed_slices) {

View file

@ -612,7 +612,9 @@ double ray_mesh_intersect(const Vec3d& s,
const Vec3d& dir,
const EigenMesh3D& m);
PointSet normals(const PointSet& points, const EigenMesh3D& mesh);
PointSet normals(const PointSet& points, const EigenMesh3D& mesh,
double eps = 0.05, // min distance from edges
std::function<void()> throw_on_cancel = [](){});
inline Vec2d to_vec2(const Vec3d& v3) {
return {v3(X), v3(Y)};
@ -1049,7 +1051,7 @@ bool SLASupportTree::generate(const PointSet &points,
tifcl();
// calculate the normals to the triangles belonging to filtered points
auto nmls = sla::normals(filt_pts, mesh);
auto nmls = sla::normals(filt_pts, mesh, cfg.head_front_radius_mm, tifcl);
head_norm.resize(count, 3);
head_pos.resize(count, 3);

View file

@ -1,3 +1,4 @@
#include <cmath>
#include "SLA/SLASupportTree.hpp"
#include "SLA/SLABoilerPlate.hpp"
#include "SLA/SLASpatIndex.hpp"
@ -9,15 +10,8 @@
#include "boost/geometry/index/rtree.hpp"
#include <igl/ray_mesh_intersect.h>
//#if !defined(_MSC_VER) || defined(_WIN64)
#if 1
#define IGL_COMPATIBLE
#endif
#ifdef IGL_COMPATIBLE
#include <igl/point_mesh_squared_distance.h>
#endif
#include <igl/remove_duplicate_vertices.h>
#include "SLASpatIndex.hpp"
#include "ClipperUtils.hpp"
@ -84,33 +78,124 @@ size_t SpatIndex::size() const
return m_impl->m_store.size();
}
PointSet normals(const PointSet& points, const EigenMesh3D& mesh) {
if(points.rows() == 0 || mesh.V.rows() == 0 || mesh.F.rows() == 0) return {};
#ifdef IGL_COMPATIBLE
bool point_on_edge(const Vec3d& p, const Vec3d& e1, const Vec3d& e2,
double eps = 0.05)
{
using Line3D = Eigen::ParametrizedLine<double, 3>;
auto line = Line3D::Through(e1, e2);
double d = line.distance(p);
return std::abs(d) < eps;
}
template<class Vec> double distance(const Vec& pp1, const Vec& pp2) {
auto p = pp2 - pp1;
return std::sqrt(p.transpose() * p);
}
PointSet normals(const PointSet& points, const EigenMesh3D& emesh,
double eps,
std::function<void()> throw_on_cancel) {
if(points.rows() == 0 || emesh.V.rows() == 0 || emesh.F.rows() == 0)
return {};
Eigen::VectorXd dists;
Eigen::VectorXi I;
PointSet C;
// We need to remove duplicate vertices and have a true index triangle
// structure
EigenMesh3D mesh;
Eigen::VectorXi SVI, SVJ;
igl::remove_duplicate_vertices(emesh.V, emesh.F, 1e-6,
mesh.V, SVI, SVJ, mesh.F);
igl::point_mesh_squared_distance( points, mesh.V, mesh.F, dists, I, C);
PointSet ret(I.rows(), 3);
for(int i = 0; i < I.rows(); i++) {
throw_on_cancel();
auto idx = I(i);
auto trindex = mesh.F.row(idx);
auto& p1 = mesh.V.row(trindex(0));
auto& p2 = mesh.V.row(trindex(1));
auto& p3 = mesh.V.row(trindex(2));
const Vec3d& p1 = mesh.V.row(trindex(0));
const Vec3d& p2 = mesh.V.row(trindex(1));
const Vec3d& p3 = mesh.V.row(trindex(2));
Eigen::Vector3d U = p2 - p1;
Eigen::Vector3d V = p3 - p1;
ret.row(i) = U.cross(V).normalized();
// We should check if the point lies on an edge of the hosting triangle.
// If it does than all the other triangles using the same two points
// have to be searched and the final normal should be some kind of
// aggregation of the participating triangle normals. We should also
// consider the cases where the support point lies right on a vertex
// of its triangle. The procedure is the same, get the neighbor
// triangles and calculate an average normal.
const Vec3d& p = C.row(i);
// mark the vertex indices of the edge. ia and ib marks and edge ic
// will mark a single vertex.
int ia = -1, ib = -1, ic = -1;
if(std::abs(distance(p, p1)) < eps) {
ic = trindex(0);
}
else if(std::abs(distance(p, p2)) < eps) {
ic = trindex(1);
}
else if(std::abs(distance(p, p3)) < eps) {
ic = trindex(2);
}
else if(point_on_edge(p, p1, p2, eps)) {
ia = trindex(0); ib = trindex(1);
}
else if(point_on_edge(p, p2, p3, eps)) {
ia = trindex(1); ib = trindex(2);
}
else if(point_on_edge(p, p1, p3, eps)) {
ia = trindex(0); ib = trindex(2);
}
std::vector<Vec3i> neigh;
if(ic >= 0) { // The point is right on a vertex of the triangle
for(int n = 0; n < mesh.F.rows(); ++n) {
throw_on_cancel();
Vec3i ni = mesh.F.row(n);
if((ni(X) == ic || ni(Y) == ic || ni(Z) == ic))
neigh.emplace_back(ni);
}
}
else if(ia >= 0 && ib >= 0) { // the point is on and edge
// now get all the neigboring triangles
for(int n = 0; n < mesh.F.rows(); ++n) {
throw_on_cancel();
Vec3i ni = mesh.F.row(n);
if((ni(X) == ia || ni(Y) == ia || ni(Z) == ia) &&
(ni(X) == ib || ni(Y) == ib || ni(Z) == ib))
neigh.emplace_back(ni);
}
}
if(!neigh.empty()) { // there were neighbors to count with
Vec3d sumnorm(0, 0, 0);
for(const Vec3i& tri : neigh) {
const Vec3d& pt1 = mesh.V.row(tri(0));
const Vec3d& pt2 = mesh.V.row(tri(1));
const Vec3d& pt3 = mesh.V.row(tri(2));
Eigen::Vector3d U = pt2 - pt1;
Eigen::Vector3d V = pt3 - pt1;
sumnorm += U.cross(V).normalized();
}
sumnorm /= neigh.size();
ret.row(i) = sumnorm;
}
else { // point lies safely within its triangle
Eigen::Vector3d U = p2 - p1;
Eigen::Vector3d V = p3 - p1;
ret.row(i) = U.cross(V).normalized();
}
}
return ret;
#else // TODO: do something on 32 bit windows
return {};
#endif
}
double ray_mesh_intersect(const Vec3d& s,
@ -223,7 +308,7 @@ Segments model_boundary(const EigenMesh3D& emesh, double offs)
pp.emplace_back(p);
}
ExPolygons merged = union_ex(offset(pp, float(scale_(offs))), true);
ExPolygons merged = union_ex(Slic3r::offset(pp, float(scale_(offs))), true);
for(auto& expoly : merged) {
auto lines = expoly.lines();

View file

@ -436,10 +436,17 @@ std::vector<float> SLAPrint::calculate_heights(const BoundingBoxf3& bb3d, float
return heights;
}
template<class...Args>
void report_status(SLAPrint& p, int st, const std::string& msg, Args&&...args) {
BOOST_LOG_TRIVIAL(info) << st << "% " << msg;
p.set_status(st, msg, std::forward<Args>(args)...);
}
void SLAPrint::process()
{
using namespace sla;
using ExPolygon = Slic3r::ExPolygon;
// Assumption: at this point the print objects should be populated only with
// the model objects we have to process and the instances are also filtered
@ -556,9 +563,11 @@ void SLAPrint::process()
// scaling for the sub operations
double d = *stthis / (objcount * 100.0);
ctl.statuscb = [this, init, d](unsigned st, const std::string& msg){
set_status(int(init + st*d), msg);
ctl.statuscb = [this, init, d](unsigned st, const std::string& msg)
{
report_status(*this, int(init + st*d), msg);
};
ctl.stopcondition = [this](){ return canceled(); };
ctl.cancelfn = [this]() { throw_if_canceled(); };
@ -568,9 +577,9 @@ void SLAPrint::process()
// Create the unified mesh
auto rc = SlicingStatus::RELOAD_SCENE;
set_status(-1, L("Visualizing supports"));
report_status(*this, -1, L("Visualizing supports"));
po.m_supportdata->support_tree_ptr->merged_mesh();
set_status(-1, L("Visualizing supports"), rc);
report_status(*this, -1, L("Visualizing supports"), rc);
} catch(sla::SLASupportsStoppedException&) {
// no need to rethrow
// throw_if_canceled();
@ -613,7 +622,7 @@ void SLAPrint::process()
po.throw_if_canceled();
auto rc = SlicingStatus::RELOAD_SCENE;
set_status(-1, L("Visualizing supports"), rc);
report_status(*this, -1, L("Visualizing supports"), rc);
};
// Slicing the support geometries similarly to the model slicing procedure.
@ -772,8 +781,12 @@ void SLAPrint::process()
auto lvlcnt = unsigned(m_printer_input.size());
printer.layers(lvlcnt);
// slot is the portion of 100% that is realted to rasterization
unsigned slot = PRINT_STEP_LEVELS[slapsRasterize];
// ist: initial state; pst: previous state
unsigned ist = max_objstatus, pst = ist;
// coefficient to map the rasterization state (0-99) to the allocated
// portion (slot) of the process state
double sd = (100 - ist) / 100.0;
SpinMutex slck;
@ -810,11 +823,11 @@ void SLAPrint::process()
// Finish the layer for later saving it.
printer.finish_layer(level_id);
// Status indication
// Status indication guarded with the spinlock
auto st = ist + unsigned(sd*level_id*slot/m_printer_input.size());
{ std::lock_guard<SpinMutex> lck(slck);
if( st > pst) {
set_status(int(st), PRINT_STEP_LABELS[slapsRasterize]);
report_status(*this, int(st), PRINT_STEP_LABELS[slapsRasterize]);
pst = st;
}
}
@ -862,9 +875,14 @@ void SLAPrint::process()
unsigned st = min_objstatus;
unsigned incr = 0;
BOOST_LOG_TRIVIAL(info) << "Start slicing process.";
// TODO: this loop could run in parallel but should not exhaust all the CPU
// power available
for(SLAPrintObject * po : m_objects) {
BOOST_LOG_TRIVIAL(info) << "Slicing object " << po->model_object()->name;
for(size_t s = 0; s < objectsteps.size(); ++s) {
auto currentstep = objectsteps[s];
@ -876,8 +894,7 @@ void SLAPrint::process()
st += unsigned(incr * ostepd);
if(po->m_stepmask[currentstep] && po->set_started(currentstep)) {
set_status(int(st), OBJ_STEP_LABELS[currentstep]);
report_status(*this, int(st), OBJ_STEP_LABELS[currentstep]);
pobj_program[currentstep](*po);
po->set_done(currentstep);
}
@ -902,7 +919,7 @@ void SLAPrint::process()
if(m_stepmask[currentstep] && set_started(currentstep))
{
set_status(int(st), PRINT_STEP_LABELS[currentstep]);
report_status(*this, int(st), PRINT_STEP_LABELS[currentstep]);
print_program[currentstep]();
set_done(currentstep);
}
@ -911,7 +928,7 @@ void SLAPrint::process()
}
// If everything vent well
set_status(100, L("Slicing done"));
report_status(*this, 100, L("Slicing done"));
}
bool SLAPrint::invalidate_state_by_config_options(const std::vector<t_config_option_key> &opt_keys)

View file

@ -36,6 +36,12 @@
#define ENABLE_REMOVE_TABS_FROM_PLATER (1 && ENABLE_1_42_0)
// Constrains the camera target into the scene bounding box
#define ENABLE_CONSTRAINED_CAMERA_TARGET (1 && ENABLE_1_42_0)
// Use wxDataViewRender instead of wxDataViewCustomRenderer
#define ENABLE_NONCUSTOM_DATA_VIEW_RENDERING (0 && ENABLE_1_42_0)
// Adds background texture to toolbars
#define ENABLE_TOOLBAR_BACKGROUND_TEXTURE (1 && ENABLE_1_42_0)
// Renders a small sphere in the center of the bounding box of the current selection when no gizmo is active
#define ENABLE_RENDER_SELECTION_CENTER (0 && ENABLE_1_42_0)
#endif // _technologies_h_

View file

@ -11,7 +11,13 @@
namespace Slic3r {
extern void set_logging_level(unsigned int level);
extern unsigned get_logging_level();
extern void trace(unsigned int level, const char *message);
// Format memory allocated, separate thousands by comma.
extern std::string format_memsize_MB(size_t n);
// Return string to be added to the boost::log output to inform about the current process memory allocation.
// The string is non-empty only if the loglevel >= info (3).
extern std::string log_memory_info();
extern void disable_multi_threading();
// Set a path with GUI resource files.
@ -182,7 +188,12 @@ public:
void reset() { closure = Closure(); }
};
} // namespace Slic3r
#if WIN32
#define SLIC3R_STDVEC_MEMSIZE(NAME, TYPE) NAME.capacity() * ((sizeof(TYPE) + __alignof(TYPE) - 1) / __alignof(TYPE)) * __alignof(TYPE)
#else
#define SLIC3R_STDVEC_MEMSIZE(NAME, TYPE) NAME.capacity() * ((sizeof(TYPE) + alignof(TYPE) - 1) / alignof(TYPE)) * alignof(TYPE)
#endif
#endif // slic3r_Utils_hpp_

View file

@ -8,6 +8,7 @@
#ifdef WIN32
#include <windows.h>
#include <psapi.h>
#else
#include <unistd.h>
#endif
@ -58,6 +59,18 @@ void set_logging_level(unsigned int level)
);
}
unsigned get_logging_level()
{
switch (logSeverity) {
case boost::log::trivial::fatal : return 0;
case boost::log::trivial::error : return 1;
case boost::log::trivial::warning : return 2;
case boost::log::trivial::info : return 3;
case boost::log::trivial::debug : return 4;
default: return 1;
}
}
// Force set_logging_level(<=error) after loading of the DLL.
// Switch boost::filesystem to utf8.
static struct RunOnInit {
@ -365,4 +378,71 @@ std::string xml_escape(std::string text)
return text;
}
std::string format_memsize_MB(size_t n)
{
std::string out;
size_t n2 = 0;
size_t scale = 1;
// Round to MB
n += 500000;
n /= 1000000;
while (n >= 1000) {
n2 = n2 + scale * (n % 1000);
n /= 1000;
scale *= 1000;
}
char buf[8];
sprintf(buf, "%d", n);
out = buf;
while (scale != 1) {
scale /= 1000;
n = n2 / scale;
n2 = n2 % scale;
sprintf(buf, ",%03d", n);
out += buf;
}
return out + "MB";
}
#ifdef WIN32
#ifndef PROCESS_MEMORY_COUNTERS_EX
// MingW32 doesn't have this struct in psapi.h
typedef struct _PROCESS_MEMORY_COUNTERS_EX {
DWORD cb;
DWORD PageFaultCount;
SIZE_T PeakWorkingSetSize;
SIZE_T WorkingSetSize;
SIZE_T QuotaPeakPagedPoolUsage;
SIZE_T QuotaPagedPoolUsage;
SIZE_T QuotaPeakNonPagedPoolUsage;
SIZE_T QuotaNonPagedPoolUsage;
SIZE_T PagefileUsage;
SIZE_T PeakPagefileUsage;
SIZE_T PrivateUsage;
} PROCESS_MEMORY_COUNTERS_EX, *PPROCESS_MEMORY_COUNTERS_EX;
#endif /* PROCESS_MEMORY_COUNTERS_EX */
std::string log_memory_info()
{
std::string out;
if (logSeverity <= boost::log::trivial::info) {
HANDLE hProcess = ::OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, ::GetCurrentProcessId());
if (hProcess != nullptr) {
PROCESS_MEMORY_COUNTERS_EX pmc;
if (GetProcessMemoryInfo(hProcess, (PROCESS_MEMORY_COUNTERS*)&pmc, sizeof(pmc)))
out = " WorkingSet: " + format_memsize_MB(pmc.WorkingSetSize) + " PrivateBytes: " + format_memsize_MB(pmc.PrivateUsage) + " Pagefile(peak): " + format_memsize_MB(pmc.PagefileUsage) + "(" + format_memsize_MB(pmc.PeakPagefileUsage) + ")";
CloseHandle(hProcess);
}
}
return out;
}
#else
std::string log_memory_info()
{
return std::string();
}
#endif
}; // namespace Slic3r