mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-10 01:01:57 +00:00
* Add Missing Includes Across src/libslic3r Every libslic3r source and header now directly includes the headers declaring what it uses, rather than relying on the precompiled header or transitive includes. Generated with clang-tidy misc-include-cleaner, with libslic3r headers spelled libslic3r/... so they resolve outside the library's private include paths. MultiMaterialSegmentation.hpp, Support/SupportParameters.hpp and Format/STEP.hpp are made self-contained by hand. * Make the libslic3r Headers Compile on Their Own Each now includes, or forward-declares, what it uses instead of relying on what its includers happened to include first. Left out: I18N.hpp, which errors on purpose when included from GUI code, and VoxelizeCSGMesh.hpp and SLA/bicubic.h, which nothing includes and which no longer compile at all. * Add the Includes Missing From the Hand-Fixed libslic3r Headers clang-tidy would not edit these headers while they failed to compile on their own, so the first pass skipped them. With the headers now self-contained, a second pass adds the rest. * Keep Windows Setup Ahead of the Added libslic3r Includes Print.cpp and Thread.cpp open with a _WIN32 block that has to come first; without the precompiled header, Print.cpp otherwise reaches windows.h through OCCT with NONLS defined and boost/regex fails. OpenVDBUtils.cpp and SLA/SupportTreeBuilder.cpp had includes inside #ifndef NOMINMAX, which libslic3r defines on Windows, so those were skipped there. .clang-tidy also ignores the MSVC STL and UCRT internals, Boost.Multiprecision's fwd.hpp and CPython's Windows include directory. * Re-Add libslic3r Includes After the Clipper2 2.0.1 Migration Rebasing onto main took main's version of the files the Clipper2 migration rewrote, so their added includes are restored here, along with includes for main's new code. Clipper2's individual headers are now ignored by clang-tidy: they only build the Z variant through clipper2_z.hpp, which defines USINGZ first, so including clipper.core.h and the like directly broke ClipperZUtils.cpp.
217 lines
7.7 KiB
C++
217 lines
7.7 KiB
C++
#ifndef TOOL_ORDER_UTILS_HPP
|
|
#define TOOL_ORDER_UTILS_HPP
|
|
|
|
#include <utility>
|
|
#include <vector>
|
|
#include <optional>
|
|
#include <functional>
|
|
#include <limits>
|
|
#include <memory>
|
|
#include <set>
|
|
#include <unordered_set>
|
|
#include <unordered_map>
|
|
#include "../MultiNozzleUtils.hpp"
|
|
|
|
namespace Slic3r {
|
|
|
|
using FlushMatrix = std::vector<std::vector<float>>;
|
|
|
|
namespace MaxFlowGraph {
|
|
const int INF = std::numeric_limits<int>::max();
|
|
const int INVALID_ID = -1;
|
|
// Upper bound for MCMF edge cost to prevent int overflow in SPFA causing infinite loops
|
|
constexpr int MCMF_MAX_EDGE_COST = 10000000;
|
|
}
|
|
|
|
// Namespace-scope edge shared by the max-flow / min-cost-max-flow solvers below.
|
|
// The default cost keeps the plain max-flow solvers (which never read cost) source-compatible.
|
|
struct Edge
|
|
{
|
|
int from, to, capacity, cost, flow;
|
|
Edge(int u, int v, int cap, int cst = 0) : from(u), to(v), capacity(cap), cost(cst), flow(0) {}
|
|
};
|
|
|
|
class MaxFlowSolver
|
|
{
|
|
public:
|
|
MaxFlowSolver(const std::vector<int>& u_nodes, const std::vector<int>& v_nodes,
|
|
const std::unordered_map<int, std::vector<int>>& uv_link_limits = {},
|
|
const std::unordered_map<int, std::vector<int>>& uv_unlink_limits = {},
|
|
const std::vector<int>& u_capacity = {},
|
|
const std::vector<int>& v_capacity = {},
|
|
const std::vector<std::pair<std::set<int>, int>>& v_group_capacity = {}
|
|
);
|
|
std::vector<int> solve();
|
|
|
|
private:
|
|
void add_edge(int from, int to, int capacity);
|
|
|
|
int total_nodes;
|
|
int source_id;
|
|
int sink_id;
|
|
std::vector<Edge>edges;
|
|
std::vector<int>l_nodes;
|
|
std::vector<int>r_nodes;
|
|
std::vector<std::vector<int>>adj;
|
|
};
|
|
|
|
|
|
struct MinCostMaxFlow;
|
|
struct MaxFlowWithLowerBounds;
|
|
|
|
class GeneralMinCostSolver
|
|
{
|
|
public:
|
|
GeneralMinCostSolver(const std::vector<std::vector<float>>& matrix_,
|
|
const std::vector<int>& u_nodes,
|
|
const std::vector<int>& v_nodes);
|
|
|
|
std::vector<int> solve();
|
|
~GeneralMinCostSolver();
|
|
private:
|
|
std::unique_ptr<MinCostMaxFlow> m_solver;
|
|
};
|
|
|
|
class GeneralMinCostLowerBoundsSolver
|
|
{
|
|
public:
|
|
GeneralMinCostLowerBoundsSolver(
|
|
const std::vector<FlushMatrix> &matrix_,
|
|
const std::vector<int>& u_nodes,
|
|
const std::vector<int>& v_nodes,
|
|
const std::vector<int>& v_nodes_group,
|
|
const std::unordered_map<int, std::vector<int>>& uv_link_limits = {},
|
|
const std::unordered_map<int, std::vector<int>>& uv_unlink_limits = {});
|
|
|
|
std::vector<int> solve();
|
|
~GeneralMinCostLowerBoundsSolver();
|
|
|
|
private:
|
|
void build_feasible_graph(const std::unordered_set<int>& no_lower_groups);
|
|
|
|
void build_graph_with_feasible_result();
|
|
|
|
void add_edge_with_lower_bound(int from, int to, int lower, int upper, int cost);
|
|
|
|
int get_distance(const int idx_in_left,const int idx_in_right);
|
|
|
|
private:
|
|
std::unique_ptr<MaxFlowWithLowerBounds> m_solver_lower_bounds;
|
|
std::unique_ptr<MinCostMaxFlow> m_solver_min_cost;
|
|
|
|
std::vector<FlushMatrix> flush_matrix;
|
|
std::vector<int> l_nodes;
|
|
std::vector<int> r_nodes;
|
|
std::vector<int> r_nodes_group;
|
|
std::unordered_map<int, std::vector<int>> m_uv_link_limits;
|
|
std::unordered_map<int, std::vector<int>> m_uv_unlink_limits;
|
|
int num_groups = 0;
|
|
|
|
// support lower bounds
|
|
struct LowerBoundEdge{
|
|
int edge_id;
|
|
int lower;
|
|
};
|
|
|
|
std::vector<int> demand;
|
|
std::vector<LowerBoundEdge> lower_bound_edges;
|
|
|
|
int super_source = -1;
|
|
int super_sink = -1;
|
|
int source_id = -1;
|
|
int sink_id = -1;
|
|
int max_flow_edges = 0;
|
|
};
|
|
|
|
class GroupMinCostFlowSolver
|
|
{
|
|
public:
|
|
GroupMinCostFlowSolver(
|
|
const std::vector<FlushMatrix> &matrix_,
|
|
const std::vector<int> &u_nodes,
|
|
const std::vector<int> &v_nodes,
|
|
const std::vector<int> &v_nodes_group,
|
|
const std::unordered_map<int, std::vector<int>> &uv_link_limits = {},
|
|
const std::unordered_map<int, std::vector<int>> &uv_unlink_limits = {});
|
|
|
|
std::vector<int> solve();
|
|
~GroupMinCostFlowSolver();
|
|
|
|
private:
|
|
void build_graph();
|
|
int get_flush_cost(int l_idx, int r_idx);
|
|
|
|
std::unique_ptr<MinCostMaxFlow> m_solver;
|
|
std::vector<FlushMatrix> flush_matrix;
|
|
std::vector<int> l_nodes;
|
|
std::vector<int> r_nodes;
|
|
std::vector<int> r_nodes_group;
|
|
std::unordered_map<int, std::vector<int>> m_uv_link_limits;
|
|
std::unordered_map<int, std::vector<int>> m_uv_unlink_limits;
|
|
int num_groups = 0;
|
|
};
|
|
|
|
class MinFlushFlowSolver
|
|
{
|
|
public:
|
|
MinFlushFlowSolver(const std::vector<std::vector<float>>& matrix_,
|
|
const std::vector<int>& u_nodes,
|
|
const std::vector<int>& v_nodes,
|
|
const std::unordered_map<int, std::vector<int>>& uv_link_limits = {},
|
|
const std::unordered_map<int, std::vector<int>>& uv_unlink_limits = {},
|
|
const std::vector<int>& u_capacity = {},
|
|
const std::vector<int>& v_capacity = {},
|
|
const std::vector<std::pair<std::set<int>, int>>& v_group_capacity = {}
|
|
);
|
|
std::vector<int> solve();
|
|
~MinFlushFlowSolver();
|
|
private:
|
|
std::unique_ptr<MinCostMaxFlow> m_solver;
|
|
};
|
|
|
|
|
|
class MatchModeGroupSolver
|
|
{
|
|
public:
|
|
MatchModeGroupSolver(const std::vector<std::vector<float>>& matrix_,
|
|
const std::vector<int>& u_nodes,
|
|
const std::vector<int>& v_nodes,
|
|
const std::vector<int>& v_capacity,
|
|
const std::unordered_map<int, std::vector<int>>& uv_unlink_limits = {});
|
|
|
|
std::vector<int> solve();
|
|
~MatchModeGroupSolver();
|
|
private:
|
|
std::unique_ptr<MinCostMaxFlow> m_solver;
|
|
};
|
|
|
|
|
|
std::vector<unsigned int> get_extruders_order(const std::vector<std::vector<float>> &wipe_volumes,
|
|
const std::vector<unsigned int> &curr_layer_extruders,
|
|
const std::vector<unsigned int> &next_layer_extruders,
|
|
const std::optional<unsigned int> &start_extruder_id,
|
|
bool use_forcast = false,
|
|
float *cost = nullptr);
|
|
|
|
int reorder_filaments_for_minimum_flush_volume(const std::vector<unsigned int> &filament_lists,
|
|
const std::vector<int> &filament_maps,
|
|
const std::vector<std::vector<unsigned int>> &layer_filaments,
|
|
const std::vector<FlushMatrix> &flush_matrix,
|
|
std::optional<std::function<bool(int, std::vector<int> &)>> get_custom_seq,
|
|
std::vector<std::vector<unsigned int>> *filament_sequences,
|
|
const std::unordered_map<int, int>& nozzle_status = {});
|
|
|
|
// Order filaments within a per-nozzle grouping result (multi-nozzle extruders). Threads a
|
|
// NozzleStatusRecorder describing the initial physical nozzle occupancy so the reorder can reward
|
|
// keeping an already-loaded filament in place.
|
|
int reorder_filaments_for_multi_nozzle_extruder(const std::vector<unsigned int>& filament_lists,
|
|
const MultiNozzleUtils::LayeredNozzleGroupResult& nozzle_group_result,
|
|
const std::vector<std::vector<unsigned int>>& layer_filaments,
|
|
const std::vector<FlushMatrix>& flush_matrix,
|
|
const std::function<bool(int,std::vector<int>&)> get_custom_seq,
|
|
std::vector<std::vector<unsigned int>> * filament_sequences,
|
|
const MultiNozzleUtils::NozzleStatusRecorder& initial_status = {});
|
|
|
|
}
|
|
#endif // !TOOL_ORDER_UTILS_HPP
|