NEW:active "import obj color" in command line
jira: none Change-Id: I8bc5d4a1eea116305037b8194ff1d2e8aab83ce9 (cherry picked from commit 7df9f9d27d174b30a54ed27756d4a4a157557019)
This commit is contained in:
parent
4f86697f66
commit
b97d44dae4
|
@ -213,6 +213,7 @@ set(lisbslic3r_sources
|
|||
Arrange.cpp
|
||||
NormalUtils.cpp
|
||||
NormalUtils.hpp
|
||||
ObjColorUtils.cpp
|
||||
ObjColorUtils.hpp
|
||||
Orient.hpp
|
||||
Orient.cpp
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
#include "ObjColorUtils.hpp"
|
||||
|
||||
bool obj_color_deal_algo(std::vector<Slic3r::RGBA> & input_colors,
|
||||
std::vector<Slic3r::RGBA> & cluster_colors_from_algo,
|
||||
std::vector<int> & cluster_labels_from_algo,
|
||||
char & cluster_number)
|
||||
{
|
||||
QuantKMeans quant(10);
|
||||
quant.apply(input_colors, cluster_colors_from_algo, cluster_labels_from_algo, (int) cluster_number);
|
||||
if (cluster_number == -1) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
|
@ -3,7 +3,7 @@
|
|||
#include <ctime>
|
||||
|
||||
#include "opencv2/opencv.hpp"
|
||||
|
||||
#include "libslic3r/Color.hpp"
|
||||
class QuantKMeans
|
||||
{
|
||||
public:
|
||||
|
@ -260,3 +260,8 @@ public:
|
|||
return image8UC3;
|
||||
}
|
||||
};
|
||||
|
||||
bool obj_color_deal_algo(std::vector<Slic3r::RGBA> &input_colors,
|
||||
std::vector<Slic3r::RGBA>& cluster_colors_from_algo,
|
||||
std::vector<int>& cluster_labels_from_algo,
|
||||
char & cluster_number);
|
|
@ -157,6 +157,8 @@ set(SLIC3R_GUI_SOURCES
|
|||
GUI/GLTexture.cpp
|
||||
GUI/GLToolbar.hpp
|
||||
GUI/GLToolbar.cpp
|
||||
GUI/GuiColor.cpp
|
||||
GUI/GuiColor.hpp
|
||||
GUI/IMToolbar.hpp
|
||||
GUI/IMToolbar.cpp
|
||||
GUI/GCodeViewer.hpp
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include "DeviceManager.hpp"
|
||||
#include "libslic3r/Time.hpp"
|
||||
#include "libslic3r/Thread.hpp"
|
||||
#include "slic3r/Utils/ColorSpaceConvert.hpp"
|
||||
#include "GuiColor.hpp"
|
||||
|
||||
#include "GUI_App.hpp"
|
||||
#include "MsgDialog.hpp"
|
||||
|
@ -777,15 +777,6 @@ bool MachineObject::is_support_ams_mapping()
|
|||
return true;
|
||||
}
|
||||
|
||||
static float calc_color_distance(wxColour c1, wxColour c2)
|
||||
{
|
||||
float lab[2][3];
|
||||
RGB2Lab(c1.Red(), c1.Green(), c1.Blue(), &lab[0][0], &lab[0][1], &lab[0][2]);
|
||||
RGB2Lab(c2.Red(), c2.Green(), c2.Blue(), &lab[1][0], &lab[1][1], &lab[1][2]);
|
||||
|
||||
return DeltaE76(lab[0][0], lab[0][1], lab[0][2], lab[1][0], lab[1][1], lab[1][2]);
|
||||
}
|
||||
|
||||
void MachineObject::get_ams_colors(std::vector<wxColour> &ams_colors) {
|
||||
ams_colors.clear();
|
||||
ams_colors.reserve(amsList.size());
|
||||
|
@ -912,7 +903,7 @@ int MachineObject::ams_filament_mapping(std::vector<FilamentInfo> filaments, std
|
|||
val.tray_id = tray->second.id;
|
||||
wxColour c = wxColour(filaments[i].color);
|
||||
wxColour tray_c = AmsTray::decode_color(tray->second.color);
|
||||
val.distance = calc_color_distance(c, tray_c);
|
||||
val.distance = GUI::calc_color_distance(c, tray_c);
|
||||
if (filaments[i].type != tray->second.type) {
|
||||
val.distance = 999999;
|
||||
val.is_type_match = false;
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
#include "GuiColor.hpp"
|
||||
|
||||
namespace Slic3r { namespace GUI {
|
||||
wxColour convert_to_wxColour(const RGBA &color)
|
||||
{
|
||||
auto r = std::clamp((int) (color[0] * 255.f), 0, 255);
|
||||
auto g = std::clamp((int) (color[1] * 255.f), 0, 255);
|
||||
auto b = std::clamp((int) (color[2] * 255.f), 0, 255);
|
||||
auto a = std::clamp((int) (color[3] * 255.f), 0, 255);
|
||||
wxColour wx_color(r, g, b, a);
|
||||
return wx_color;
|
||||
}
|
||||
|
||||
RGBA convert_to_rgba(const wxColour &color)
|
||||
{
|
||||
RGBA rgba;
|
||||
rgba[0] = std::clamp(color.Red() / 255.f, 0.f, 1.f);
|
||||
rgba[1] = std::clamp(color.Green() / 255.f, 0.f, 1.f);
|
||||
rgba[2] = std::clamp(color.Blue() / 255.f, 0.f, 1.f);
|
||||
rgba[3] = std::clamp(color.Alpha() / 255.f, 0.f, 1.f);
|
||||
return rgba;
|
||||
}
|
||||
|
||||
float calc_color_distance(wxColour c1, wxColour c2)
|
||||
{
|
||||
float lab[2][3];
|
||||
RGB2Lab(c1.Red(), c1.Green(), c1.Blue(), &lab[0][0], &lab[0][1], &lab[0][2]);
|
||||
RGB2Lab(c2.Red(), c2.Green(), c2.Blue(), &lab[1][0], &lab[1][1], &lab[1][2]);
|
||||
|
||||
return DeltaE76(lab[0][0], lab[0][1], lab[0][2], lab[1][0], lab[1][1], lab[1][2]);
|
||||
}
|
||||
} }
|
|
@ -0,0 +1,13 @@
|
|||
#ifndef slic3r_GUI_Color_hpp_
|
||||
#define slic3r_GUI_Color_hpp_
|
||||
#include <wx/colour.h>
|
||||
#include "libslic3r/Color.hpp"
|
||||
#include "slic3r/Utils/ColorSpaceConvert.hpp"
|
||||
namespace Slic3r { namespace GUI {
|
||||
wxColour convert_to_wxColour(const RGBA &color);
|
||||
RGBA convert_to_rgba(const wxColour &color);
|
||||
float calc_color_distance(wxColour c1, wxColour c2);
|
||||
} // namespace GUI
|
||||
} // namespace Slic3r
|
||||
|
||||
#endif /* slic3r_GUI_Color_hpp_ */
|
|
@ -8,7 +8,6 @@
|
|||
#include "GUI_App.hpp"
|
||||
#include "MsgDialog.hpp"
|
||||
#include "Widgets/Button.hpp"
|
||||
#include "slic3r/Utils/ColorSpaceConvert.hpp"
|
||||
#include "MainFrame.hpp"
|
||||
#include "libslic3r/Config.hpp"
|
||||
#include "BitmapComboBox.hpp"
|
||||
|
@ -189,24 +188,7 @@ ObjColorDialog::ObjColorDialog(wxWindow * parent,
|
|||
|
||||
wxGetApp().UpdateDlgDarkUI(this);
|
||||
}
|
||||
RGBA convert_to_rgba(const wxColour &color)
|
||||
{
|
||||
RGBA rgba;
|
||||
rgba[0] = std::clamp(color.Red() / 255.f, 0.f, 1.f);
|
||||
rgba[1] = std::clamp(color.Green() / 255.f, 0.f, 1.f);
|
||||
rgba[2] = std::clamp(color.Blue() / 255.f, 0.f, 1.f);
|
||||
rgba[3] = std::clamp(color.Alpha() / 255.f, 0.f, 1.f);
|
||||
return rgba;
|
||||
}
|
||||
wxColour convert_to_wxColour(const RGBA &color)
|
||||
{
|
||||
auto r = std::clamp((int) (color[0] * 255.f), 0, 255);
|
||||
auto g = std::clamp((int) (color[1] * 255.f), 0, 255);
|
||||
auto b = std::clamp((int) (color[2] * 255.f), 0, 255);
|
||||
auto a = std::clamp((int) (color[3] * 255.f), 0, 255);
|
||||
wxColour wx_color(r,g,b,a);
|
||||
return wx_color;
|
||||
}
|
||||
|
||||
// This panel contains all control widgets for both simple and advanced mode (these reside in separate sizers)
|
||||
ObjColorPanel::ObjColorPanel(wxWindow * parent,
|
||||
std::vector<Slic3r::RGBA>& input_colors,
|
||||
|
@ -546,13 +528,6 @@ ComboBox *ObjColorPanel::CreateEditorCtrl(wxWindow *parent, int id) // wxRect la
|
|||
|
||||
void ObjColorPanel::deal_approximate_match_btn()
|
||||
{
|
||||
auto calc_color_distance = [](wxColour c1, wxColour c2) {
|
||||
float lab[2][3];
|
||||
RGB2Lab(c1.Red(), c1.Green(), c1.Blue(), &lab[0][0], &lab[0][1], &lab[0][2]);
|
||||
RGB2Lab(c2.Red(), c2.Green(), c2.Blue(), &lab[1][0], &lab[1][1], &lab[1][2]);
|
||||
|
||||
return DeltaE76(lab[0][0], lab[0][1], lab[0][2], lab[1][0], lab[1][1], lab[1][2]);
|
||||
};
|
||||
m_warning_text->SetLabelText("");
|
||||
if (m_result_icon_list.size() == 0) { return; }
|
||||
auto map_count = m_result_icon_list[0]->bitmap_combox->GetCount() -1;
|
||||
|
@ -693,8 +668,8 @@ void ObjColorPanel::deal_algo(char cluster_number, bool redraw_ui)
|
|||
return;
|
||||
}
|
||||
m_last_cluster_number = cluster_number;
|
||||
QuantKMeans quant(10);
|
||||
quant.apply(m_input_colors, m_cluster_colors_from_algo, m_cluster_labels_from_algo, (int)cluster_number);
|
||||
obj_color_deal_algo(m_input_colors, m_cluster_colors_from_algo, m_cluster_labels_from_algo, cluster_number);
|
||||
|
||||
m_cluster_colours.clear();
|
||||
m_cluster_colours.reserve(m_cluster_colors_from_algo.size());
|
||||
for (size_t i = 0; i < m_cluster_colors_from_algo.size(); i++) {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define _OBJ_COLOR_DIALOG_H_
|
||||
|
||||
#include "GUI_Utils.hpp"
|
||||
#include "libslic3r/Color.hpp"
|
||||
#include "GuiColor.hpp"
|
||||
#include <wx/sizer.h>
|
||||
#include <wx/spinctrl.h>
|
||||
#include <wx/stattext.h>
|
||||
|
|
|
@ -57,13 +57,14 @@
|
|||
#include "libslic3r/Utils.hpp"
|
||||
#include "libslic3r/PresetBundle.hpp"
|
||||
#include "libslic3r/ClipperUtils.hpp"
|
||||
|
||||
#include "libslic3r/ObjColorUtils.hpp"
|
||||
// For stl export
|
||||
#include "libslic3r/CSGMesh/ModelToCSGMesh.hpp"
|
||||
#include "libslic3r/CSGMesh/PerformCSGMeshBooleans.hpp"
|
||||
|
||||
#include "GUI.hpp"
|
||||
#include "GUI_App.hpp"
|
||||
#include "GuiColor.hpp"
|
||||
#include "GUI_ObjectList.hpp"
|
||||
#include "GUI_Utils.hpp"
|
||||
#include "GUI_Factories.hpp"
|
||||
|
@ -3961,14 +3962,13 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
|
|||
std::vector<Preset *> project_presets;
|
||||
bool is_xxx;
|
||||
Semver file_version;
|
||||
|
||||
//ObjImportColorFn obj_color_fun=nullptr;
|
||||
auto obj_color_fun = [this, &path](std::vector<RGBA> &input_colors, bool is_single_color, std::vector<unsigned char> &filament_ids,
|
||||
unsigned char &first_extruder_id) {
|
||||
if (!boost::iends_with(path.string(), ".obj")) { return; }
|
||||
const std::vector<std::string> extruder_colours = wxGetApp().plater()->get_extruder_colors_from_plater_config();
|
||||
ObjColorDialog color_dlg(nullptr, input_colors, is_single_color, extruder_colours, filament_ids, first_extruder_id);
|
||||
if (color_dlg.ShowModal() != wxID_OK) {
|
||||
if (color_dlg.ShowModal() != wxID_OK) {
|
||||
filament_ids.clear();
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue