Skip to content

Commit 100514a

Browse files
committed
refactor: cleanup BasicDrawPane
1 parent 4b1bfa5 commit 100514a

File tree

2 files changed

+28
-52
lines changed

2 files changed

+28
-52
lines changed

include/gui.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,15 @@ class BasicDrawPane : public wxPanel
2020
{
2121

2222
public:
23-
BasicDrawPane(wxPanel *parent, cv::Size, bool canUndo);
23+
BasicDrawPane(wxPanel *, cv::Size);
2424

2525
CLD cld;
2626
cv::Mat dis;
27-
cv::Mat temp;
2827
std::string processingS;
29-
void paintEvent(wxPaintEvent &evt);
30-
void paintNow(bool);
31-
void render(wxDC &dc, bool);
28+
void render();
3229
DECLARE_EVENT_TABLE()
3330
private:
34-
bool activateDraw;
31+
wxClientDC dc_;
3532
};
3633

3734
class MyFrame : public wxFrame
@@ -53,7 +50,7 @@ class MyFrame : public wxFrame
5350
void addlog(wxString info, const wxColour &color);
5451
void activateRenderLoop(bool on);
5552

56-
protected:
53+
private:
5754
bool render_loop_on;
5855
int ETF_kernel;
5956
int ETF_iteration;

src/gui.cpp

Lines changed: 24 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ MyFrame::MyFrame(const wxString &title, const wxPoint &pos, const wxSize &size)
9797
dp->SetSizer(dps);
9898

9999

100-
drawPane = new BasicDrawPane(dp, cv::Size(256, 256), true);
100+
drawPane = new BasicDrawPane(dp, cv::Size(256, 256));
101101
dps->Add(drawPane, 1, wxEXPAND);
102102

103103
// wxTextCtrl: http://docs.wxwidgets.org/trunk/classwx_text_ctrl.html
@@ -267,7 +267,7 @@ void MyFrame::OnClean(wxCommandEvent &event)
267267
{
268268
drawPane->cld.init(cv::Size(300, 300));
269269
ETF_iteration = FDoG_iteration = 0;
270-
drawPane->paintNow(true); //execute clean action
270+
drawPane->render();
271271

272272
wxSize img(drawPane->cld.originalImg.cols, drawPane->cld.originalImg.rows);
273273
dp->SetMinSize(img);
@@ -312,7 +312,7 @@ void MyFrame::OnIterativeFDoG(wxCommandEvent &event)
312312
wxString s;
313313
s.Printf("FDoG: %d iterations", ++FDoG_iteration);
314314
SetStatusText(s, 2);
315-
drawPane->paintNow(true);
315+
drawPane->render();
316316
}
317317

318318
//Comboboxes
@@ -335,7 +335,7 @@ void MyFrame::OnProcessingBox(wxCommandEvent &event)
335335
}
336336

337337
addlog("[Mode Changed] " + s, wxColour(*wxBLACK));
338-
drawPane->paintNow(true);
338+
drawPane->render();
339339
activateRenderLoop(render_loop_on);
340340
}
341341

@@ -346,8 +346,6 @@ void MyFrame::OnSliderETFkernel(wxCommandEvent &event)
346346
ETF_kernel = slider_ETFkernel->GetValue();
347347
s.Printf("ETF kernel size : %d", ETF_kernel);
348348
slider_ETFkernel_t->SetLabel(s);
349-
350-
//drawPane->cld.genCLD();
351349
}
352350

353351
void MyFrame::OnSliderRho(wxCommandEvent &event)
@@ -358,7 +356,7 @@ void MyFrame::OnSliderRho(wxCommandEvent &event)
358356
slider_rho_t->SetLabel(s);
359357

360358
drawPane->cld.genCLD();
361-
drawPane->paintNow(true); //execute action
359+
drawPane->render();
362360
}
363361

364362
void MyFrame::OnSliderSigmaM(wxCommandEvent &event)
@@ -369,7 +367,7 @@ void MyFrame::OnSliderSigmaM(wxCommandEvent &event)
369367
slider_sigma1_t->SetLabel(s);
370368

371369
drawPane->cld.genCLD();
372-
drawPane->paintNow(true); //execute action
370+
drawPane->render();
373371
}
374372

375373
void MyFrame::OnSliderSigmaC(wxCommandEvent &event)
@@ -380,7 +378,7 @@ void MyFrame::OnSliderSigmaC(wxCommandEvent &event)
380378
slider_sigma2_t->SetLabel(s);
381379

382380
drawPane->cld.genCLD();
383-
drawPane->paintNow(true); //execute action
381+
drawPane->render();
384382
}
385383

386384
void MyFrame::OnSliderTau(wxCommandEvent &event)
@@ -391,7 +389,7 @@ void MyFrame::OnSliderTau(wxCommandEvent &event)
391389
slider_t_t->SetLabel(s);
392390

393391
drawPane->cld.binaryThresholding(drawPane->cld.FDoG, drawPane->cld.result, drawPane->cld.tau);
394-
drawPane->paintNow(true); //execute action
392+
drawPane->render();
395393
}
396394

397395
void MyFrame::addlog(wxString info, const wxColour &color)
@@ -405,59 +403,41 @@ void MyFrame::addlog(wxString info, const wxColour &color)
405403
log->SetDefaultStyle(wxTextAttr(color));
406404
log->AppendText(s);
407405
}
406+
408407
void MyFrame::activateRenderLoop(bool on)
409408
{
410409
if (on) {
411410
start->SetLabel("Stop");
412411
Connect(wxID_ANY, wxEVT_IDLE, wxIdleEventHandler(MyFrame::onIdle));
413412
render_loop_on = true;
414413
addlog("-------Start iteration-------", wxColour(*wxBLACK));
415-
} else {
416-
start->SetLabel("Start");
417-
Disconnect(wxEVT_IDLE, wxIdleEventHandler(MyFrame::onIdle));
418-
//Connect(wxID_ANY, wxEVT_IDLE, wxIdleEventHandler(MyFrame::onIdle));
419-
render_loop_on = false;
420-
addlog("-------Stop iteration-------", wxColour(*wxBLACK));
414+
return;
421415
}
416+
417+
start->SetLabel("Start");
418+
Disconnect(wxEVT_IDLE, wxIdleEventHandler(MyFrame::onIdle));
419+
render_loop_on = false;
420+
addlog("-------Stop iteration-------", wxColour(*wxBLACK));
422421
}
422+
423423
void MyFrame::onIdle(wxIdleEvent &evt)
424424
{
425-
drawPane->paintNow(render_loop_on);
425+
if (!render_loop_on) return;
426+
drawPane->render();
426427
evt.RequestMore(); // render continuously, not only once on idle
427428
}
428429
#pragma endregion
429430

430431
#pragma region BasicDrawPane
431-
BasicDrawPane::BasicDrawPane(wxPanel *parent, cv::Size s, bool canUndo)
432+
BasicDrawPane::BasicDrawPane(wxPanel *parent, cv::Size s)
432433
: cld(s)
433434
, wxPanel(parent)
435+
, dc_(wxClientDC(this))
434436
{
435-
activateDraw = false;
436-
}
437-
438-
439-
//first frame
440-
void BasicDrawPane::paintEvent(wxPaintEvent &evt)
441-
{
442-
wxPaintDC dc(this);
443-
//render(dc);
444-
dis = cld.originalImg.clone();
445-
dis.convertTo(dis, CV_8UC1, 255);
446-
//cvtColor(dis, dis, CV_GRAY2RGB);
447-
wxImage img(dis.cols, dis.rows, dis.data, true);
448-
wxBitmap bmp(img);
449-
dc.DrawBitmap(bmp, 0, 0);
450-
}
451-
452-
//render loop
453-
void BasicDrawPane::paintNow(bool render_loop_on)
454-
{
455-
wxClientDC dc(this);
456-
render(dc, render_loop_on);
457437
}
458438

459-
//Main Render(iteration) Section
460-
void BasicDrawPane::render(wxDC &dc, bool render_loop_on)
439+
// Main Render(iteration) Section
440+
void BasicDrawPane::render()
461441
{
462442
dis = cld.originalImg.clone();
463443
cv::cvtColor(dis, dis, CV_GRAY2BGR);
@@ -479,8 +459,7 @@ void BasicDrawPane::render(wxDC &dc, bool render_loop_on)
479459
cv::cvtColor(dis, dis, CV_GRAY2BGR);
480460
}
481461

482-
wxImage img(dis.cols, dis.rows, dis.data, true);
483-
wxBitmap bmp(img);
484-
dc.DrawBitmap(bmp, 0, 0);
462+
wxBitmap bmp(wxImage(dis.cols, dis.rows, dis.data, true));
463+
dc_.DrawBitmap(bmp, 0, 0);
485464
}
486465
#pragma endregion

0 commit comments

Comments
 (0)