* Fix calls to depreciated wxPen constructor * Fix use of wxTimerEvent * Fix unrecognized character escape sequence * Fix signed/unsigned mismatch At least as much as possible without significantly altering parts of the application * Clean unreferenced variables * fix mistyped namespace selector * Update deprecated calls * Fix preprocessor statement * Remove empty switch statements * Change int vector used as bool to bool vector * Remove empty control statements and related unused code * Change multi character constant to string constant * Fix discarded return value json::parse was being called on the object, rather than statically like it should be. Also, the value was not being captured. * Rename ICON_SIZE def used by MultiMachine By having the definition in the header, it causes issues when other files define ICON_SIZE. By renaming it to MM_ICON_SIZE, this lessens the issue. It would probably be ideal to have the definitions in the respective .cpp that use them, but it would make it less convenient to update the values if needed in the future. * Remove unused includes * Fix linux/macOS compilation * Hide unused-function errors on non-Windows systems * Disable signed/unsigned comparison mismatch error * Remove/Disable more unused variables Still TODO: check double for loop in Print.cpp * Remove unused variable that was missed * Remove unused variables in libraries in the src folder * Apply temporary fix for subobject linkage error * Remove/Disable last set of unused variables reported by GCC * remove redundant for loop * fix misspelled ifdef check * Update message on dialog * Fix hard-coded platform specific modifier keys * Remove duplicate for loop * Disable -Wmisleading-indentation warning * disable -Wswitch warning * Remove unused local typedefs * Fix -Wunused-value * Fix pragma error on Windows from subobject linkage fix * Fix -Waddress * Fix null conversions (-Wconversion-null) --------- Co-authored-by: SoftFever <softfeverever@gmail.com>
98 lines
3.1 KiB
C++
98 lines
3.1 KiB
C++
#include <cmath>
|
|
#include "slic3r/Utils/ColorSpaceConvert.hpp"
|
|
|
|
#include "FlushVolCalc.hpp"
|
|
|
|
|
|
namespace Slic3r {
|
|
|
|
const int g_min_flush_volume_from_support = 420.f;
|
|
const int g_flush_volume_to_support = 230;
|
|
|
|
const int g_max_flush_volume = 800;
|
|
|
|
static float to_radians(float degree)
|
|
{
|
|
return degree / 180.f * M_PI;
|
|
}
|
|
|
|
|
|
static float get_luminance(float r, float g, float b)
|
|
{
|
|
return r * 0.3 + g * 0.59 + b * 0.11;
|
|
}
|
|
|
|
static float calc_triangle_3rd_edge(float edge_a, float edge_b, float degree_ab)
|
|
{
|
|
return std::sqrt(edge_a * edge_a + edge_b * edge_b - 2 * edge_a * edge_b * std::cos(to_radians(degree_ab)));
|
|
}
|
|
|
|
static float DeltaHS_BBS(float h1, float s1, float v1, float h2, float s2, float v2)
|
|
{
|
|
float h1_rad = to_radians(h1);
|
|
float h2_rad = to_radians(h2);
|
|
|
|
float dx = std::cos(h1_rad) * s1 * v1 - cos(h2_rad) * s2 * v2;
|
|
float dy = std::sin(h1_rad) * s1 * v1 - sin(h2_rad) * s2 * v2;
|
|
float dxy = std::sqrt(dx * dx + dy * dy);
|
|
return std::min(1.2f, dxy);
|
|
}
|
|
|
|
FlushVolCalculator::FlushVolCalculator(int min, int max, float multiplier)
|
|
:m_min_flush_vol(min), m_max_flush_vol(max), m_multiplier(multiplier)
|
|
{
|
|
}
|
|
|
|
int FlushVolCalculator::calc_flush_vol(unsigned char src_a, unsigned char src_r, unsigned char src_g, unsigned char src_b,
|
|
unsigned char dst_a, unsigned char dst_r, unsigned char dst_g, unsigned char dst_b)
|
|
{
|
|
// BBS: Transparent materials are treated as white materials
|
|
if (src_a == 0) {
|
|
src_r = src_g = src_b = 255;
|
|
}
|
|
if (dst_a == 0) {
|
|
dst_r = dst_g = dst_b = 255;
|
|
}
|
|
|
|
float src_r_f, src_g_f, src_b_f, dst_r_f, dst_g_f, dst_b_f;
|
|
float from_hsv_h, from_hsv_s, from_hsv_v;
|
|
float to_hsv_h, to_hsv_s, to_hsv_v;
|
|
|
|
src_r_f = (float)src_r / 255.f;
|
|
src_g_f = (float)src_g / 255.f;
|
|
src_b_f = (float)src_b / 255.f;
|
|
dst_r_f = (float)dst_r / 255.f;
|
|
dst_g_f = (float)dst_g / 255.f;
|
|
dst_b_f = (float)dst_b / 255.f;
|
|
|
|
// Calculate color distance in HSV color space
|
|
RGB2HSV(src_r_f, src_g_f,src_b_f, &from_hsv_h, &from_hsv_s, &from_hsv_v);
|
|
RGB2HSV(dst_r_f, dst_g_f, dst_b_f, &to_hsv_h, &to_hsv_s, &to_hsv_v);
|
|
float hs_dist = DeltaHS_BBS(from_hsv_h, from_hsv_s, from_hsv_v, to_hsv_h, to_hsv_s, to_hsv_v);
|
|
|
|
// 1. Color difference is more obvious if the dest color has high luminance
|
|
// 2. Color difference is more obvious if the source color has low luminance
|
|
float from_lumi = get_luminance(src_r_f, src_g_f, src_b_f);
|
|
float to_lumi = get_luminance(dst_r_f, dst_g_f, dst_b_f);
|
|
float lumi_flush = 0.f;
|
|
if (to_lumi >= from_lumi) {
|
|
lumi_flush = std::pow(to_lumi - from_lumi, 0.7f) * 560.f;
|
|
}
|
|
else {
|
|
lumi_flush = (from_lumi - to_lumi) * 80.f;
|
|
|
|
float inter_hsv_v = 0.67 * to_hsv_v + 0.33 * from_hsv_v;
|
|
hs_dist = std::min(inter_hsv_v, hs_dist);
|
|
}
|
|
float hs_flush = 230.f * hs_dist;
|
|
|
|
float flush_volume = calc_triangle_3rd_edge(hs_flush, lumi_flush, 120.f);
|
|
flush_volume = std::max(flush_volume, 60.f);
|
|
|
|
//float flush_multiplier = std::atof(m_flush_multiplier_ebox->GetValue().c_str());
|
|
flush_volume += m_min_flush_vol;
|
|
return std::min((int)flush_volume, m_max_flush_vol);
|
|
}
|
|
|
|
}
|