From 5aaddd82a44475c37f933d476a10351f03ddee01 Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Mon, 16 Dec 2019 15:36:43 +0100 Subject: [PATCH] Remove bloat, add some clipping plane functionality. --- sandboxes/opencsg/Canvas.hpp | 14 +- sandboxes/opencsg/GLScene.cpp | 8 +- sandboxes/opencsg/main.cpp | 314 +++++++++++++++++----------------- 3 files changed, 168 insertions(+), 168 deletions(-) diff --git a/sandboxes/opencsg/Canvas.hpp b/sandboxes/opencsg/Canvas.hpp index 85d490ddf..17fd8f044 100644 --- a/sandboxes/opencsg/Canvas.hpp +++ b/sandboxes/opencsg/Canvas.hpp @@ -27,20 +27,8 @@ public: Slic3r::GL::Display::set_active(w, h); } - void repaint(long width, long height) override - { - Slic3r::GL::Display::repaint(width, height); - } - - using Slic3r::GL::Display::repaint; - void swap_buffers() override { SwapBuffers(); } - - void on_scroll(long v, long d, Slic3r::GL::MouseInput::WheelAxis wa) override - { - Slic3r::GL::Display::on_scroll(v, d, wa); - } - + template Canvas(Args &&...args): wxGLCanvas(std::forward(args)...) { diff --git a/sandboxes/opencsg/GLScene.cpp b/sandboxes/opencsg/GLScene.cpp index 5037ef6a5..02a4b7991 100644 --- a/sandboxes/opencsg/GLScene.cpp +++ b/sandboxes/opencsg/GLScene.cpp @@ -517,7 +517,13 @@ void Camera::view() glRotatef(m_rot.y(), 1.0, 0.0, 0.0); glRotatef(m_rot.x(), 0.0, 0.0, 1.0); - // glClipPlane() + if (m_clip_z > 0.) { + GLdouble plane[] = {0., 0., 1., m_clip_z}; + glClipPlane(GL_CLIP_PLANE0, plane); + glEnable(GL_CLIP_PLANE0); + } else { + glDisable(GL_CLIP_PLANE0); + } } void PerspectiveCamera::set_screen(long width, long height) diff --git a/sandboxes/opencsg/main.cpp b/sandboxes/opencsg/main.cpp index 6274f264a..ac18e177d 100644 --- a/sandboxes/opencsg/main.cpp +++ b/sandboxes/opencsg/main.cpp @@ -26,7 +26,6 @@ #include "slic3r/GUI/Job.hpp" #include "slic3r/GUI/ProgressStatusBar.hpp" -//#include "slic3r/GUI/3DEngine.hpp" using namespace Slic3r::GL; @@ -59,6 +58,10 @@ class MyFrame: public wxFrame m_print = std::make_unique(); m_print->apply(model, cfg); + Slic3r::PrintBase::TaskParams params; + params.to_object_step = Slic3r::slaposHollowing; + m_print->set_task(params); + m_print->set_status_callback([this](const Status &status) { update_status(status.percent, status.text); }); @@ -77,158 +80,7 @@ class MyFrame: public wxFrame }; public: - MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size): - wxFrame(nullptr, wxID_ANY, title, pos, size) - { - wxMenu *menuFile = new wxMenu; - menuFile->Append(wxID_OPEN); - menuFile->Append(wxID_EXIT); - wxMenuBar *menuBar = new wxMenuBar; - menuBar->Append( menuFile, "&File" ); - SetMenuBar( menuBar ); - - m_stbar = std::make_shared(this); - m_stbar->embed(this); - - SetStatusText( "Welcome to wxWidgets!" ); - - int attribList[] = - {WX_GL_RGBA, WX_GL_DOUBLEBUFFER, - // RGB channels each should be allocated with 8 bit depth. One - // should almost certainly get these bit depths by default. - WX_GL_MIN_RED, 8, WX_GL_MIN_GREEN, 8, WX_GL_MIN_BLUE, 8, - // Requesting an 8 bit alpha channel. Interestingly, the NVIDIA - // drivers would most likely work with some alpha plane, but - // glReadPixels would not return the alpha channel on NVIDIA if - // not requested when the GL context is created. - WX_GL_MIN_ALPHA, 8, WX_GL_DEPTH_SIZE, 8, WX_GL_STENCIL_SIZE, 8, - WX_GL_SAMPLE_BUFFERS, GL_TRUE, WX_GL_SAMPLES, 4, 0}; - - m_canvas = std::make_shared(this, wxID_ANY, attribList, - wxDefaultPosition, wxDefaultSize, - wxWANTS_CHARS | wxFULL_REPAINT_ON_RESIZE); - - wxPanel *control_panel = new wxPanel(this); - auto controlsizer = new wxBoxSizer(wxHORIZONTAL); - auto slider_sizer = new wxBoxSizer(wxVERTICAL); - auto console_sizer = new wxBoxSizer(wxVERTICAL); - - auto slider = new wxSlider(control_panel, wxID_ANY, 0, 0, 100, - wxDefaultPosition, wxDefaultSize, - wxSL_VERTICAL); - slider_sizer->Add(slider, 1, wxEXPAND); - - auto ms_toggle = new wxToggleButton(control_panel, wxID_ANY, "Multisampling"); - console_sizer->Add(ms_toggle, 0, wxALL | wxEXPAND, 5); - - auto csg_toggle = new wxToggleButton(control_panel, wxID_ANY, "CSG"); - csg_toggle->SetValue(true); - console_sizer->Add(csg_toggle, 0, wxALL | wxEXPAND, 5); - - auto add_combobox = [control_panel, console_sizer] - (const wxString &label, std::vector &&list) - { - auto widget = new wxComboBox(control_panel, wxID_ANY, list[0], - wxDefaultPosition, wxDefaultSize, - int(list.size()), list.data()); - - auto sz = new wxBoxSizer(wxHORIZONTAL); - sz->Add(new wxStaticText(control_panel, wxID_ANY, label), 0, - wxALL | wxALIGN_CENTER, 5); - sz->Add(widget, 1, wxALL | wxEXPAND, 5); - console_sizer->Add(sz, 0, wxEXPAND); - return widget; - }; - - auto add_spinctl = [control_panel, console_sizer] - (const wxString &label, int initial, int min, int max) - { - auto widget = new wxSpinCtrl( - control_panel, wxID_ANY, - wxString::Format("%d", initial), - wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, min, max, - initial); - - auto sz = new wxBoxSizer(wxHORIZONTAL); - sz->Add(new wxStaticText(control_panel, wxID_ANY, label), 0, - wxALL | wxALIGN_CENTER, 5); - sz->Add(widget, 1, wxALL | wxEXPAND, 5); - console_sizer->Add(sz, 0, wxEXPAND); - return widget; - }; - - auto convexity_spin = add_spinctl("Convexity", CSGSettings::DEFAULT_CONVEXITY, 0, 100); - - auto alg_select = add_combobox("Algorithm", {"Auto", "Goldfeather", "SCS"}); - auto depth_select = add_combobox("Depth Complexity", {"Off", "OcclusionQuery", "On"}); - depth_select->Disable(); - auto optimization_select = add_combobox("Optimization", { "Default", "ForceOn", "On", "Off" }); - - controlsizer->Add(slider_sizer, 0, wxEXPAND); - controlsizer->Add(console_sizer, 1, wxEXPAND); - - control_panel->SetSizer(controlsizer); - - auto sizer = new wxBoxSizer(wxHORIZONTAL); - sizer->Add(m_canvas.get(), 1, wxEXPAND); - sizer->Add(control_panel, 0, wxEXPAND); - SetSizer(sizer); - - Bind(wxEVT_MENU, &MyFrame::OnOpen, this, wxID_OPEN); - Bind(wxEVT_MENU, &MyFrame::OnExit, this, wxID_EXIT); - Bind(wxEVT_SHOW, &MyFrame::OnShown, this, GetId()); - Bind(wxEVT_SLIDER, [this, slider](wxCommandEvent &) { - m_canvas->move_clip_plane(double(slider->GetValue())); - }, slider->GetId()); - - Bind(wxEVT_TOGGLEBUTTON, [this, ms_toggle](wxCommandEvent &){ - enable_multisampling(ms_toggle->GetValue()); - m_canvas->repaint(); - }, ms_toggle->GetId()); - - Bind(wxEVT_TOGGLEBUTTON, [this, csg_toggle](wxCommandEvent &){ - CSGSettings settings = m_canvas->get_csgsettings(); - settings.enable_csg(csg_toggle->GetValue()); - m_canvas->apply_csgsettings(settings); - }, csg_toggle->GetId()); - - Bind(wxEVT_COMBOBOX, [this, alg_select, depth_select](wxCommandEvent &) - { - int sel = alg_select->GetSelection(); - depth_select->Enable(sel > 0); - CSGSettings settings = m_canvas->get_csgsettings(); - settings.set_algo(OpenCSG::Algorithm(sel)); - m_canvas->apply_csgsettings(settings); - }, alg_select->GetId()); - - Bind(wxEVT_COMBOBOX, [this, depth_select](wxCommandEvent &) - { - int sel = depth_select->GetSelection(); - CSGSettings settings = m_canvas->get_csgsettings(); - settings.set_depth_algo(OpenCSG::DepthComplexityAlgorithm(sel)); - m_canvas->apply_csgsettings(settings); - }, depth_select->GetId()); - - Bind(wxEVT_COMBOBOX, [this, optimization_select](wxCommandEvent &) - { - int sel = optimization_select->GetSelection(); - CSGSettings settings = m_canvas->get_csgsettings(); - settings.set_optimization(OpenCSG::Optimization(sel)); - m_canvas->apply_csgsettings(settings); - }, depth_select->GetId()); - - Bind(wxEVT_SPINCTRL, [this, convexity_spin](wxSpinEvent &) { - CSGSettings settings = m_canvas->get_csgsettings(); - int c = convexity_spin->GetValue(); - - if (c > 0) { - settings.set_convexity(unsigned(c)); - m_canvas->apply_csgsettings(settings); - } - }, convexity_spin->GetId()); - - m_canvas->set_scene(std::make_shared()); - } + MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size); private: @@ -270,8 +122,8 @@ class App : public wxApp { MyFrame *m_frame; public: bool OnInit() override { + m_frame = new MyFrame("PrusaSlicer OpenCSG Demo", wxDefaultPosition, wxSize(1024, 768)); - m_frame = new MyFrame( "PrusaSlicer OpenCSG Demo", wxDefaultPosition, wxSize(1024, 768) ); m_frame->Show( true ); return true; @@ -279,3 +131,157 @@ public: }; wxIMPLEMENT_APP(App); + +MyFrame::MyFrame(const wxString &title, const wxPoint &pos, const wxSize &size): + wxFrame(nullptr, wxID_ANY, title, pos, size) +{ + wxMenu *menuFile = new wxMenu; + menuFile->Append(wxID_OPEN); + menuFile->Append(wxID_EXIT); + wxMenuBar *menuBar = new wxMenuBar; + menuBar->Append( menuFile, "&File" ); + SetMenuBar( menuBar ); + + m_stbar = std::make_shared(this); + m_stbar->embed(this); + + SetStatusText( "Welcome to wxWidgets!" ); + + int attribList[] = + {WX_GL_RGBA, WX_GL_DOUBLEBUFFER, + // RGB channels each should be allocated with 8 bit depth. One + // should almost certainly get these bit depths by default. + WX_GL_MIN_RED, 8, WX_GL_MIN_GREEN, 8, WX_GL_MIN_BLUE, 8, + // Requesting an 8 bit alpha channel. Interestingly, the NVIDIA + // drivers would most likely work with some alpha plane, but + // glReadPixels would not return the alpha channel on NVIDIA if + // not requested when the GL context is created. + WX_GL_MIN_ALPHA, 8, WX_GL_DEPTH_SIZE, 8, WX_GL_STENCIL_SIZE, 8, + WX_GL_SAMPLE_BUFFERS, GL_TRUE, WX_GL_SAMPLES, 4, 0}; + + m_canvas = std::make_shared(this, wxID_ANY, attribList, + wxDefaultPosition, wxDefaultSize, + wxWANTS_CHARS | wxFULL_REPAINT_ON_RESIZE); + + wxPanel *control_panel = new wxPanel(this); + auto controlsizer = new wxBoxSizer(wxHORIZONTAL); + auto slider_sizer = new wxBoxSizer(wxVERTICAL); + auto console_sizer = new wxBoxSizer(wxVERTICAL); + + auto slider = new wxSlider(control_panel, wxID_ANY, 0, 0, 100, + wxDefaultPosition, wxDefaultSize, + wxSL_VERTICAL); + slider_sizer->Add(slider, 1, wxEXPAND); + + auto ms_toggle = new wxToggleButton(control_panel, wxID_ANY, "Multisampling"); + console_sizer->Add(ms_toggle, 0, wxALL | wxEXPAND, 5); + + auto csg_toggle = new wxToggleButton(control_panel, wxID_ANY, "CSG"); + csg_toggle->SetValue(true); + console_sizer->Add(csg_toggle, 0, wxALL | wxEXPAND, 5); + + auto add_combobox = [control_panel, console_sizer] + (const wxString &label, std::vector &&list) + { + auto widget = new wxComboBox(control_panel, wxID_ANY, list[0], + wxDefaultPosition, wxDefaultSize, + int(list.size()), list.data()); + + auto sz = new wxBoxSizer(wxHORIZONTAL); + sz->Add(new wxStaticText(control_panel, wxID_ANY, label), 0, + wxALL | wxALIGN_CENTER, 5); + sz->Add(widget, 1, wxALL | wxEXPAND, 5); + console_sizer->Add(sz, 0, wxEXPAND); + return widget; + }; + + auto add_spinctl = [control_panel, console_sizer] + (const wxString &label, int initial, int min, int max) + { + auto widget = new wxSpinCtrl( + control_panel, wxID_ANY, + wxString::Format("%d", initial), + wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, min, max, + initial); + + auto sz = new wxBoxSizer(wxHORIZONTAL); + sz->Add(new wxStaticText(control_panel, wxID_ANY, label), 0, + wxALL | wxALIGN_CENTER, 5); + sz->Add(widget, 1, wxALL | wxEXPAND, 5); + console_sizer->Add(sz, 0, wxEXPAND); + return widget; + }; + + auto convexity_spin = add_spinctl("Convexity", CSGSettings::DEFAULT_CONVEXITY, 0, 100); + + auto alg_select = add_combobox("Algorithm", {"Auto", "Goldfeather", "SCS"}); + auto depth_select = add_combobox("Depth Complexity", {"Off", "OcclusionQuery", "On"}); + auto optimization_select = add_combobox("Optimization", { "Default", "ForceOn", "On", "Off" }); + depth_select->Disable(); + + controlsizer->Add(slider_sizer, 0, wxEXPAND); + controlsizer->Add(console_sizer, 1, wxEXPAND); + + control_panel->SetSizer(controlsizer); + + auto sizer = new wxBoxSizer(wxHORIZONTAL); + sizer->Add(m_canvas.get(), 1, wxEXPAND); + sizer->Add(control_panel, 0, wxEXPAND); + SetSizer(sizer); + + Bind(wxEVT_MENU, &MyFrame::OnOpen, this, wxID_OPEN); + Bind(wxEVT_MENU, &MyFrame::OnExit, this, wxID_EXIT); + Bind(wxEVT_SHOW, &MyFrame::OnShown, this, GetId()); + + Bind(wxEVT_SLIDER, [this, slider](wxCommandEvent &) { + m_canvas->move_clip_plane(double(slider->GetValue())); + }, slider->GetId()); + + Bind(wxEVT_TOGGLEBUTTON, [this, ms_toggle](wxCommandEvent &){ + enable_multisampling(ms_toggle->GetValue()); + m_canvas->repaint(); + }, ms_toggle->GetId()); + + Bind(wxEVT_TOGGLEBUTTON, [this, csg_toggle](wxCommandEvent &){ + CSGSettings settings = m_canvas->get_csgsettings(); + settings.enable_csg(csg_toggle->GetValue()); + m_canvas->apply_csgsettings(settings); + }, csg_toggle->GetId()); + + Bind(wxEVT_COMBOBOX, [this, alg_select, depth_select](wxCommandEvent &) + { + int sel = alg_select->GetSelection(); + depth_select->Enable(sel > 0); + CSGSettings settings = m_canvas->get_csgsettings(); + settings.set_algo(OpenCSG::Algorithm(sel)); + m_canvas->apply_csgsettings(settings); + }, alg_select->GetId()); + + Bind(wxEVT_COMBOBOX, [this, depth_select](wxCommandEvent &) + { + int sel = depth_select->GetSelection(); + CSGSettings settings = m_canvas->get_csgsettings(); + settings.set_depth_algo(OpenCSG::DepthComplexityAlgorithm(sel)); + m_canvas->apply_csgsettings(settings); + }, depth_select->GetId()); + + Bind(wxEVT_COMBOBOX, [this, optimization_select](wxCommandEvent &) + { + int sel = optimization_select->GetSelection(); + CSGSettings settings = m_canvas->get_csgsettings(); + settings.set_optimization(OpenCSG::Optimization(sel)); + m_canvas->apply_csgsettings(settings); + }, depth_select->GetId()); + + Bind(wxEVT_SPINCTRL, [this, convexity_spin](wxSpinEvent &) { + CSGSettings settings = m_canvas->get_csgsettings(); + int c = convexity_spin->GetValue(); + + if (c > 0) { + settings.set_convexity(unsigned(c)); + m_canvas->apply_csgsettings(settings); + } + }, convexity_spin->GetId()); + + m_canvas->set_scene(std::make_shared()); +}