diff --git a/FastROI/ConsoleApplication2/ConsoleApplication2.cpp b/FastROI/ConsoleApplication2/ConsoleApplication2.cpp new file mode 100644 index 0000000..6aa98f2 --- /dev/null +++ b/FastROI/ConsoleApplication2/ConsoleApplication2.cpp @@ -0,0 +1,37 @@ +// ConsoleExample.cpp : 이 파일에는 'main' 함수가 포함됩니다. 거기서 프로그램 실행이 시작되고 종료됩니다. +// + +#include +#include +#include +#include + +#include "fastDonut.h" + + + +int main() +{ + + cv::namedWindow("result", cv::WINDOW_NORMAL); + + cv::Mat result(cv::Size(4000, 4000), CV_8UC3); + + while (true) { + + auto vertical_lines = fast::fastDonut(2000, 2000, 1000, 1, 0.5, 1); + + result = cv::Scalar(0, 0, 0); + for (auto& vertical_line : vertical_lines) { + for (auto& calPoint : vertical_line) { + if (calPoint.x < 0 || calPoint.x >= 4000 || calPoint.y < 0 || calPoint.y >= 4000) + continue; + + cv::circle(result, cv::Point((int)calPoint.x, (int)calPoint.y), 2, cv::Scalar(0, 255, 0), -1); + } + } + cv::imshow("result", result); + if (cv::waitKey(1) == 27)break; + } +} + diff --git a/FastROI/ConsoleApplication2/ConsoleApplication2.vcxproj b/FastROI/ConsoleApplication2/ConsoleApplication2.vcxproj new file mode 100644 index 0000000..4084f9d --- /dev/null +++ b/FastROI/ConsoleApplication2/ConsoleApplication2.vcxproj @@ -0,0 +1,155 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {5e63e966-9b2e-4bb0-90d8-8b3e9bb9fdb9} + ConsoleApplication2 + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + + + false + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpp17 + $(SolutionDir)fastROI\;%(AdditionalIncludeDirectories) + + + Console + true + $(OutDir);%(AdditionalLibraryDirectories) + fastROI.lib;%(AdditionalDependencies) + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpp17 + $(SolutionDir)fastROI\;%(AdditionalIncludeDirectories) + + + Console + true + true + true + fastROI.lib;%(AdditionalDependencies) + $(OutDir);%(AdditionalLibraryDirectories) + + + + + + + + + \ No newline at end of file diff --git a/FastROI/ConsoleApplication2/ConsoleApplication2.vcxproj.filters b/FastROI/ConsoleApplication2/ConsoleApplication2.vcxproj.filters new file mode 100644 index 0000000..3314900 --- /dev/null +++ b/FastROI/ConsoleApplication2/ConsoleApplication2.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 소스 파일 + + + \ No newline at end of file diff --git a/FastROI/ConsoleApplication2/ConsoleApplication2.vcxproj.user b/FastROI/ConsoleApplication2/ConsoleApplication2.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/FastROI/ConsoleApplication2/ConsoleApplication2.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/FastROI/ConsoleExample/ConsoleExample1.cpp b/FastROI/ConsoleExample/ConsoleExample1.cpp index dfdc23a..606db4c 100644 --- a/FastROI/ConsoleExample/ConsoleExample1.cpp +++ b/FastROI/ConsoleExample/ConsoleExample1.cpp @@ -18,15 +18,15 @@ int main() std::chrono::high_resolution_clock::time_point _start; _start = std::chrono::high_resolution_clock::now(); - int count = 0; + int count = 0; while (true) { - + result = cv::Scalar(0, 0, 0); - + std::vector> vertical_lines = fast::rectROI(2000, 2000, angle, 1000, 1000, false, 50); - + for (auto vertical_line : vertical_lines) { for (auto calPoint : vertical_line) { if (calPoint.x < 0 || calPoint.x >= 4000 || calPoint.y < 0 || calPoint.y >= 4000) @@ -42,4 +42,3 @@ int main() if (angle++ > 360) angle = 0; } } - diff --git a/FastROI/FastROI.sln b/FastROI/FastROI.sln index 87af7ea..5a25851 100644 --- a/FastROI/FastROI.sln +++ b/FastROI/FastROI.sln @@ -5,7 +5,12 @@ VisualStudioVersion = 17.0.31903.59 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fastROI", "fastROI\fastROI.vcxproj", "{8F4B183C-08FD-43B7-ADD3-98F7D7635DA0}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ConsoleExample", "ConsoleExample\ConsoleExample.vcxproj", "{EBCC182D-B2EF-46D9-B74F-92533CB680C3}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ConsoleExample1", "ConsoleExample\ConsoleExample.vcxproj", "{EBCC182D-B2EF-46D9-B74F-92533CB680C3}" + ProjectSection(ProjectDependencies) = postProject + {8F4B183C-08FD-43B7-ADD3-98F7D7635DA0} = {8F4B183C-08FD-43B7-ADD3-98F7D7635DA0} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ConsoleApplication2", "ConsoleApplication2\ConsoleApplication2.vcxproj", "{5E63E966-9B2E-4BB0-90D8-8B3E9BB9FDB9}" ProjectSection(ProjectDependencies) = postProject {8F4B183C-08FD-43B7-ADD3-98F7D7635DA0} = {8F4B183C-08FD-43B7-ADD3-98F7D7635DA0} EndProjectSection @@ -34,6 +39,14 @@ Global {EBCC182D-B2EF-46D9-B74F-92533CB680C3}.Release|x64.Build.0 = Release|x64 {EBCC182D-B2EF-46D9-B74F-92533CB680C3}.Release|x86.ActiveCfg = Release|Win32 {EBCC182D-B2EF-46D9-B74F-92533CB680C3}.Release|x86.Build.0 = Release|Win32 + {5E63E966-9B2E-4BB0-90D8-8B3E9BB9FDB9}.Debug|x64.ActiveCfg = Debug|x64 + {5E63E966-9B2E-4BB0-90D8-8B3E9BB9FDB9}.Debug|x64.Build.0 = Debug|x64 + {5E63E966-9B2E-4BB0-90D8-8B3E9BB9FDB9}.Debug|x86.ActiveCfg = Debug|Win32 + {5E63E966-9B2E-4BB0-90D8-8B3E9BB9FDB9}.Debug|x86.Build.0 = Debug|Win32 + {5E63E966-9B2E-4BB0-90D8-8B3E9BB9FDB9}.Release|x64.ActiveCfg = Release|x64 + {5E63E966-9B2E-4BB0-90D8-8B3E9BB9FDB9}.Release|x64.Build.0 = Release|x64 + {5E63E966-9B2E-4BB0-90D8-8B3E9BB9FDB9}.Release|x86.ActiveCfg = Release|Win32 + {5E63E966-9B2E-4BB0-90D8-8B3E9BB9FDB9}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/FastROI/fastROI/compile.cpp b/FastROI/fastROI/compile.cpp index 195e9cf..a7acf48 100644 --- a/FastROI/fastROI/compile.cpp +++ b/FastROI/fastROI/compile.cpp @@ -1 +1,2 @@ #include "fastRect.h" +#include "fastDonut.h" \ No newline at end of file diff --git a/FastROI/fastROI/fastDonut.cpp b/FastROI/fastROI/fastDonut.cpp new file mode 100644 index 0000000..5b9ecb5 --- /dev/null +++ b/FastROI/fastROI/fastDonut.cpp @@ -0,0 +1,94 @@ +#define _USE_MATH_DEFINES + +#include "fastDonut.h" + +#include +#include + + + + +std::vector> fast::fastDonut(int center_x, int center_y, int radius, double start_ratio, double end_ratio, double step_angle) { + + if (radius == 0) { + HVERROR(error, "Invalid box roi range"); + } + + if (step_angle <= 0) { + HVERROR(error, "Invalid step angle"); + } + + if (start_ratio <= 0 && end_ratio <= 0) { + HVERROR(error, "Invalid ratio"); + } + + + + int start_radius = (int)((double)radius * start_ratio); + int end_radius = (int)((double)radius * end_ratio); + + int distance_radius = (int)fabs(start_radius - end_radius); + if (distance_radius == 0) { + HVERROR(error, "Invalid start ratio and end ratio"); + } + + int aligned_distance_radius = distance_radius + (distance_radius % 4); + int min_radius = start_radius > end_radius ? end_radius : start_radius; + int max_radius = start_radius > end_radius ? start_radius : end_radius; + + + /// Radius SIMD + std::vector vector_radius; // Radius vector + vector_radius.resize(aligned_distance_radius * 2); + + + int sign = 1; + if (start_radius > end_radius) + sign = -1; + + int current_radius = start_radius; + for (int radius = 0; radius < distance_radius * 2;) { + vector_radius[radius] = current_radius; + vector_radius[radius + 1] = current_radius; + radius += 2; + current_radius += sign; + } + + /// Coordinate SIMD + std::vector vector_cordinate_table = { (double)center_x , (double)center_y, (double)center_x , (double)center_y }; // cordinate vector + const __m256d simd_coordinate = _mm256_load_pd(vector_cordinate_table.data()); // cordinate simd + + + + std::vector> combine_vertical_xy; + int doubleDistance = distance_radius * 2; + int chunk_size = sizeof(double) * 4; + + for (double angle = 0; angle < 360;) { + + /// trigonometric SIMD + double x_cos = sin(angle * M_PI / 180); + double y_sine = cos(angle * M_PI / 180); + std::vector vector_trigonometric_table = { x_cos ,y_sine, x_cos ,y_sine }; // trigonometric vector + const __m256d simd_trigonometric = _mm256_load_pd(vector_trigonometric_table.data()); // trigonometric simd + + + std::vector vertical_xy; + vertical_xy.resize(aligned_distance_radius); + void* vertical_xy_ptr = vertical_xy.data(); + for (int simd_skip = 0; simd_skip < doubleDistance;) { + + const __m256d simd_radius = _mm256_load_pd(vector_radius.data() + simd_skip); // radius simd + __m256d chunk_mul = _mm256_mul_pd(simd_radius, simd_trigonometric); + __m256d start_result = _mm256_add_pd(chunk_mul, simd_coordinate); + memcpy((((double*)vertical_xy_ptr) + simd_skip), &start_result, chunk_size); + simd_skip += 4; + } + vertical_xy.resize(distance_radius); + combine_vertical_xy.push_back(vertical_xy); + + angle += step_angle; + } + + return combine_vertical_xy; +} diff --git a/FastROI/fastROI/fastDonut.h b/FastROI/fastROI/fastDonut.h new file mode 100644 index 0000000..822d2c4 --- /dev/null +++ b/FastROI/fastROI/fastDonut.h @@ -0,0 +1,19 @@ +#pragma once + +#ifndef FAST_DOUNUT +#define FAST_DOUNUT + +#include +#include + +#include "macro.h" +#include "calPoint.h" + +namespace fast { + FAST_API_EXPORT std::vector> fastDonut(int center_x, int center_y, int radius, double start_ratio, double end_ratio, double step_angle); +} + + + + +#endif \ No newline at end of file diff --git a/FastROI/fastROI/fastROI.vcxproj b/FastROI/fastROI/fastROI.vcxproj index ead7757..a26a3b0 100644 --- a/FastROI/fastROI/fastROI.vcxproj +++ b/FastROI/fastROI/fastROI.vcxproj @@ -142,10 +142,12 @@ + + diff --git a/FastROI/fastROI/fastROI.vcxproj.filters b/FastROI/fastROI/fastROI.vcxproj.filters index a217c4a..0b09c96 100644 --- a/FastROI/fastROI/fastROI.vcxproj.filters +++ b/FastROI/fastROI/fastROI.vcxproj.filters @@ -21,6 +21,9 @@ 소스 파일 + + 소스 파일 + @@ -32,5 +35,8 @@ 헤더 파일 + + 헤더 파일 + \ No newline at end of file diff --git a/FastROI/fastROI/fastRect.cpp b/FastROI/fastROI/fastRect.cpp index f58567a..5fa2e9a 100644 --- a/FastROI/fastROI/fastRect.cpp +++ b/FastROI/fastROI/fastRect.cpp @@ -5,10 +5,6 @@ #include "fastRect.h" - - - - #include #include @@ -234,7 +230,6 @@ std::vector> fast::rectROI(int center_x, int center_ __m256d start_result = _mm256_add_pd(chunk_mul, simd_vertical_xy); memcpy((((double*)start_vertical_xy_ptr) + index), &start_result, chunk_size); } - combine_vertical_xy.push_back(vertical_xy); } diff --git a/FastROI/lib/Debug/fastDonut.h b/FastROI/lib/Debug/fastDonut.h new file mode 100644 index 0000000..822d2c4 --- /dev/null +++ b/FastROI/lib/Debug/fastDonut.h @@ -0,0 +1,19 @@ +#pragma once + +#ifndef FAST_DOUNUT +#define FAST_DOUNUT + +#include +#include + +#include "macro.h" +#include "calPoint.h" + +namespace fast { + FAST_API_EXPORT std::vector> fastDonut(int center_x, int center_y, int radius, double start_ratio, double end_ratio, double step_angle); +} + + + + +#endif \ No newline at end of file diff --git a/FastROI/lib/Debug/fastROI.dll b/FastROI/lib/Debug/fastROI.dll index 997521d..04a7007 100644 Binary files a/FastROI/lib/Debug/fastROI.dll and b/FastROI/lib/Debug/fastROI.dll differ diff --git a/FastROI/lib/Debug/fastROI.lib b/FastROI/lib/Debug/fastROI.lib index f36a0c0..18da0b0 100644 Binary files a/FastROI/lib/Debug/fastROI.lib and b/FastROI/lib/Debug/fastROI.lib differ diff --git a/FastROI/lib/Release/fastDonut.h b/FastROI/lib/Release/fastDonut.h new file mode 100644 index 0000000..822d2c4 --- /dev/null +++ b/FastROI/lib/Release/fastDonut.h @@ -0,0 +1,19 @@ +#pragma once + +#ifndef FAST_DOUNUT +#define FAST_DOUNUT + +#include +#include + +#include "macro.h" +#include "calPoint.h" + +namespace fast { + FAST_API_EXPORT std::vector> fastDonut(int center_x, int center_y, int radius, double start_ratio, double end_ratio, double step_angle); +} + + + + +#endif \ No newline at end of file diff --git a/FastROI/lib/Release/fastROI.dll b/FastROI/lib/Release/fastROI.dll index 85d5428..9501f6c 100644 Binary files a/FastROI/lib/Release/fastROI.dll and b/FastROI/lib/Release/fastROI.dll differ diff --git a/FastROI/lib/Release/fastROI.lib b/FastROI/lib/Release/fastROI.lib index f36a0c0..18da0b0 100644 Binary files a/FastROI/lib/Release/fastROI.lib and b/FastROI/lib/Release/fastROI.lib differ diff --git a/images/fastDonut.png b/images/fastDonut.png new file mode 100644 index 0000000..b1f65b3 Binary files /dev/null and b/images/fastDonut.png differ diff --git a/images/fastDonut_demo.png b/images/fastDonut_demo.png new file mode 100644 index 0000000..14d8667 Binary files /dev/null and b/images/fastDonut_demo.png differ