mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-08-05 09:07:39 +00:00
1.When capacity is greater than the num of filaments, always choose the map result that can be accommodated 2.In BestFit strategy,always try to fill up the existing capacity 3.In BestCost strategy, just try the group with fewest flush jira:NEW Signed-off-by: xun.zhang <xun.zhang@bambulab.com> Change-Id: Ifd6d64b77774039e57ffff26cf2243a4d3f89054 (cherry picked from commit cddf8cae27f4320f830b463e92703d3a6cf344e7)
97 lines
3.1 KiB
C++
97 lines
3.1 KiB
C++
#ifndef FILAMENT_GROUP_HPP
|
|
#define FILAMENT_GROUP_HPP
|
|
|
|
#include<chrono>
|
|
|
|
namespace Slic3r
|
|
{
|
|
using FlushMatrix = std::vector<std::vector<float>>;
|
|
|
|
struct FlushTimeMachine
|
|
{
|
|
private:
|
|
std::chrono::high_resolution_clock::time_point start;
|
|
|
|
public:
|
|
void time_machine_start()
|
|
{
|
|
start = std::chrono::high_resolution_clock::now();
|
|
}
|
|
|
|
int time_machine_end()
|
|
{
|
|
auto end = std::chrono::high_resolution_clock::now();
|
|
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
|
|
return duration.count();
|
|
}
|
|
};
|
|
|
|
enum FGStrategy {
|
|
BestCost,
|
|
BestFit
|
|
};
|
|
|
|
class FilamentGroup
|
|
{
|
|
public:
|
|
|
|
public:
|
|
FilamentGroup(const std::vector<FlushMatrix>& flush_matrix, const int filament_num, const std::vector<int>& max_group_size) :
|
|
m_flush_matrix{ flush_matrix },
|
|
m_filament_num{ filament_num },
|
|
m_max_group_size{ max_group_size }
|
|
{}
|
|
|
|
int calc_filament_group(const std::vector<std::vector<unsigned int>>& layer_filaments, const FGStrategy& g_strategy = FGStrategy::BestFit);
|
|
int calc_filament_group_by_enum(const std::vector<std::vector<unsigned int>>& layer_filaments,const FGStrategy& g_strategy);
|
|
int calc_filament_group_by_pam(const std::vector<std::vector<unsigned int>>& layer_filaments,const FGStrategy& g_strategy,int timeout_ms = 300);
|
|
|
|
std::vector<int> get_filament_map() const {return m_filament_labels;}
|
|
|
|
private:
|
|
std::vector<FlushMatrix>m_flush_matrix;
|
|
int m_filament_num;
|
|
std::vector<int>m_max_group_size;
|
|
std::vector<unsigned int>m_used_filaments;
|
|
public:
|
|
std::optional<std::function<bool(int, std::vector<int>&)>> get_custom_seq;
|
|
private:
|
|
std::vector<int>m_filament_labels;
|
|
std::vector<std::vector<unsigned int>>m_filament_orders;
|
|
|
|
};
|
|
|
|
class KMediods
|
|
{
|
|
enum INIT_TYPE
|
|
{
|
|
Random = 0,
|
|
Farthest
|
|
};
|
|
public:
|
|
KMediods(const std::vector<std::vector<float>>& distance_matrix, const int filament_num, const std::vector<int>& max_group_size) :
|
|
m_distance_matrix{ distance_matrix },
|
|
m_filament_num{ filament_num },
|
|
m_max_group_size{ max_group_size } {}
|
|
|
|
void fit(const FGStrategy& g_strategy,int timeout_ms = 300);
|
|
std::vector<int>get_filament_labels()const {
|
|
return m_filament_labels;
|
|
}
|
|
|
|
private:
|
|
std::vector<int>initialize(INIT_TYPE type)const;
|
|
std::vector<int>assign_label(const std::vector<int>& medoids,const FGStrategy&g_strategy)const;
|
|
int calc_cost(const std::vector<int>& labels, const std::vector<int>& medoids)const;
|
|
private:
|
|
std::vector<std::vector<float>>m_distance_matrix;
|
|
int m_filament_num;
|
|
std::vector<int>m_max_group_size;
|
|
std::vector<int>m_used_filaments;
|
|
mutable std::set<int>m_medoids_set;
|
|
private:
|
|
std::vector<int>m_filament_labels;
|
|
};
|
|
}
|
|
#endif // !FILAMENT_GROUP_HPP
|