Skip to content

Commit bc9f70b

Browse files
committed
feat: ui
1 parent 1dd4cc1 commit bc9f70b

File tree

7 files changed

+87
-41
lines changed

7 files changed

+87
-41
lines changed

lib/core/include/core/Laplacian.cuh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ std::tuple<float, float> gpuLaplacian(const Mat &h_oriImg) {
6868
return std::make_tuple(time, res);
6969
}
7070

71-
void cpuLaplacian(const Mat &src) {
71+
std::tuple<float, float> cpuLaplacian(const Mat &src) {
7272
Mat grayImage(src.size(), CV_8U, Scalar(0));
7373
ulonglong sum = 0;
7474

@@ -92,7 +92,12 @@ void cpuLaplacian(const Mat &src) {
9292
}
9393
timer.Stop();
9494

95-
printf("Cpu elapsed time: %f\n", timer.Elapsed());
96-
printf("Cpu res = %f\n", (float)sum / (rows * cols));
95+
auto time = timer.Elapsed();
96+
auto res = static_cast<float>(sum) / (rows * cols);
97+
98+
printf("Cpu elapsed time: %f\n", time);
99+
printf("Cpu res = %f\n", res);
100+
101+
return std::make_tuple(time, res);
97102
}
98103
} // namespace laplacian

lib/core/include/core/SMD.cuh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ std::tuple<float, float> gpuSMD(const Mat &h_oriImg) {
6767
return std::make_tuple(time, res);
6868
}
6969

70-
void cpuSMD(const Mat &src) {
70+
std::tuple<float, float> cpuSMD(const Mat &src) {
7171
Mat grayImage(src.size(), CV_8U, Scalar(0));
7272
ulonglong sum = 0;
7373

@@ -89,7 +89,12 @@ void cpuSMD(const Mat &src) {
8989
}
9090
timer.Stop();
9191

92-
printf("Cpu elapsed time: %f\n", timer.Elapsed());
93-
printf("Cpu res = %f\n", (float)sum / (rows * cols));
92+
auto time = timer.Elapsed();
93+
auto res = static_cast<float>(sum) / (rows * cols);
94+
95+
printf("Cpu elapsed time: %f\n", time);
96+
printf("Cpu res = %f\n", res);
97+
98+
return std::make_tuple(time, res);
9499
}
95100
} // namespace smd

lib/core/include/core/Tenengrad.cuh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ std::tuple<float, float> gpuTenengrad(const Mat &h_oriImg) {
7373
return std::make_tuple(time, res);
7474
}
7575

76-
void cpuTenengrad(const Mat &src) {
76+
std::tuple<float, float> cpuTenengrad(const Mat &src) {
7777
::utils::CpuTimer timer;
7878
timer.Start();
7979

@@ -106,8 +106,13 @@ void cpuTenengrad(const Mat &src) {
106106
}
107107
timer.Stop();
108108

109-
printf("Cpu elapsed time: %f\n", timer.Elapsed());
110-
printf("Cpu res = %f\n", (float)sum / (rows * cols));
109+
auto time = timer.Elapsed();
110+
auto res = static_cast<float>(sum) / (cols * rows);
111+
112+
printf("Cpu elapsed time: %f\n", time);
113+
printf("Cpu res = %f\n", res);
114+
115+
return std::make_tuple(time, res);
111116
}
112117

113118
} // namespace tenengrad

lib/ui/include/ui/app.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ int run(int argc, char *argv[]) {
5353
}
5454
};
5555

56+
auto clear_button = button("Clear");
57+
clear_button.on_click = [&](bool) {
58+
files.clear();
59+
list_size = 1;
60+
ptr_list.resize(list_size);
61+
content.resize(list_size);
62+
_view.refresh();
63+
};
64+
5665
constexpr view_limits files_limits = {{400, 200},
5766
{full_extent, full_extent}};
5867

@@ -61,7 +70,10 @@ int run(int argc, char *argv[]) {
6170
{10, 10, 10, 10},
6271
vtile(htile(left_margin(10, limit(files_limits,
6372
vscroller(hold(share(linked))))),
64-
left_margin(10, add_button)),
73+
left_margin(
74+
10,
75+
valign(0.5, vtile(top_margin(10, add_button),
76+
top_margin(10, clear_button))))),
6577
margin({10, 10, 10, 10}, make_buttons(_view, files)))),
6678
background);
6779
_app.run();

lib/ui/include/ui/buttons.h

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,38 @@
11
#pragma once
22

3-
#include <elements.hpp>
4-
#include "method_types.h"
53
#include "dialog.h"
4+
#include "method_types.h"
5+
#include <elements.hpp>
66

77
namespace ui {
88
using namespace cycfi::elements;
9-
auto make_buttons(view &_view, const std::vector<std::string> &files) {
10-
auto laplacian_button = button("Laplacian");
11-
laplacian_button.on_click = [&](bool) {
12-
auto dialog = make_dialog(_view, Method::Laplacian, files);
13-
_view.add(dialog);
14-
_view.refresh();
15-
};
16-
auto tenengrad_button = button("Tenengrad");
17-
tenengrad_button.on_click = [&](bool) {
18-
auto dialog = make_dialog(_view, Method::Tenengrad, files);
19-
_view.add(dialog);
20-
_view.refresh();
21-
};
22-
auto smd_button = button("SMD");
23-
smd_button.on_click = [&](bool) {
24-
auto dialog = make_dialog(_view, Method::SMD, files);
9+
10+
auto make_button(view &_view, Method method,
11+
const std::vector<std::string> &files) {
12+
auto on_click = [&_view, &files, method](bool) {
13+
auto dialog = make_dialog(_view, method, files);
14+
std::cout << MethodMap.at(method) << std::endl;
2515
_view.add(dialog);
2616
_view.refresh();
2717
};
28-
return htile(left_margin(10, laplacian_button),
29-
left_margin(10, tenengrad_button),
30-
left_margin(10, smd_button));
18+
auto _button = button(MethodMap.at(method));
19+
_button.on_click = on_click;
20+
return _button;
21+
}
22+
23+
auto make_buttons(view &_view, const std::vector<std::string> &files) {
24+
auto cpu_tenengrad_button = make_button(_view, Method::CPUTenengrad, files);
25+
auto gpu_tenengrad_button = make_button(_view, Method::GPUTenengrad, files);
26+
auto cpu_laplacian_button = make_button(_view, Method::CPULaplacian, files);
27+
auto gpu_laplacian_button = make_button(_view, Method::GPULaplacian, files);
28+
auto cpu_smd_button = make_button(_view, Method::CPUSMD, files);
29+
auto gpu_smd_button = make_button(_view, Method::GPUSMD, files);
30+
31+
return htile(left_margin(10, cpu_tenengrad_button),
32+
left_margin(10, gpu_tenengrad_button),
33+
left_margin(10, cpu_laplacian_button),
34+
left_margin(10, gpu_laplacian_button),
35+
left_margin(10, cpu_smd_button),
36+
left_margin(10, gpu_smd_button));
3137
}
3238
} // namespace ui

lib/ui/include/ui/compute.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
11
#pragma once
22

33
#include "core/Laplacian.cuh"
4-
#include "core/Tenengrad.cuh"
54
#include "core/SMD.cuh"
5+
#include "core/Tenengrad.cuh"
66
#include "method_types.h"
77
#include <tuple>
88
#include <vector>
9+
#include <iostream>
910

1011
namespace ui {
1112
auto compute(Method method, const std::vector<std::string> &files,
1213
const size_t index) {
1314
auto filepath = files[index];
1415
auto image = cv::imread(filepath);
1516
switch (method) {
16-
case Method::Laplacian:
17+
case Method::CPULaplacian:
18+
return laplacian::cpuLaplacian(image);
19+
case Method::GPULaplacian:
1720
return laplacian::gpuLaplacian(image);
18-
case Method::Tenengrad:
21+
case Method::GPUTenengrad:
1922
return tenengrad::gpuTenengrad(image);
20-
case Method::SMD:
23+
case Method::CPUTenengrad:
24+
return tenengrad::cpuTenengrad(image);
25+
case Method::CPUSMD:
26+
return smd::cpuSMD(image);
27+
case Method::GPUSMD:
2128
return smd::gpuSMD(image);
2229
default:
2330
return std::make_tuple(.0f, .0f);

lib/ui/include/ui/method_types.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,20 @@
44
#include <unordered_map>
55
namespace ui {
66
enum class Method {
7-
Tenengrad,
8-
Laplacian,
9-
SMD,
7+
CPUTenengrad,
8+
GPUTenengrad,
9+
CPULaplacian,
10+
GPULaplacian,
11+
CPUSMD,
12+
GPUSMD,
1013
};
1114

1215
const std::unordered_map<Method, std::string> MethodMap = {
13-
{Method::Tenengrad, "Tenengrad"},
14-
{Method::Laplacian, "Laplacian"},
15-
{Method::SMD, "SMD"},
16+
{Method::CPUTenengrad, "CPU Tenengrad"},
17+
{Method::GPUTenengrad, "GPU Tenengrad"},
18+
{Method::CPULaplacian, "CPU Laplacian"},
19+
{Method::GPULaplacian, "GPU Laplacian"},
20+
{Method::CPUSMD, "CPU SMD"},
21+
{Method::GPUSMD, "GPU SMD"},
1622
};
1723
} // namespace ui

0 commit comments

Comments
 (0)