From 1f63a4f54f8460e9c55ae9a2de4b166fc2c69ce4 Mon Sep 17 00:00:00 2001 From: zhaoxi <535394140@qq.com> Date: Sat, 27 Apr 2024 01:38:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=88=E5=B9=B6=20core=20=E5=92=8C=20rmath?= =?UTF-8?q?=20=E6=A8=A1=E5=9D=97=EF=BC=8C=E5=B9=B6=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/intro.markdown | 2 +- doc/tutorials/modules/algorithm/dft.md | 15 + .../modules/{core => algorithm}/ekf.md | 2 +- .../modules/{rmath => algorithm}/ew_topsis.md | 4 +- doc/tutorials/modules/algorithm/fft.md | 15 + .../{core => algorithm}/func_iteration.md | 0 .../{core => algorithm}/interpolation.md | 2 +- .../modules/{core => algorithm}/kalman.md | 2 +- .../{core => algorithm}/least_square.md | 0 .../modules/{ort => algorithm}/ort.md | 4 +- .../modules/{rmath => algorithm}/ra_heap.md | 2 +- .../{core => algorithm}/runge_kutta.md | 2 +- .../{rmath => algorithm}/union_find.md | 2 +- .../{core => tools}/aggregate_reflect.md | 0 .../modules/{devices => tools}/camera.md | 4 +- .../modules/{devices => tools}/light.md | 4 +- .../modules/{core => tools}/opcua.md | 4 +- .../modules/{core => tools}/serial.md | 0 doc/tutorials/modules/tutorial_modules.md | 30 +- extra/combo/include/rmvl/combo/combo.h | 2 +- extra/combo/src/armor/armor.cpp | 2 +- extra/combo/src/armor/armor_cal.cpp | 2 +- extra/combo/src/rune/rune.cpp | 2 +- extra/compensator/CMakeLists.txt | 2 +- .../src/gyro_compensator/gyro_compensator.cpp | 2 +- extra/compensator/test/test_gravity.cpp | 2 +- .../decider/src/gyro_decider/gyro_decider.cpp | 2 +- .../decider/src/rune_decider/rune_decider.cpp | 4 +- .../translation_decider.cpp | 2 +- .../detector/src/gyro_detector/inference.cpp | 2 +- extra/detector/src/gyro_detector/match.cpp | 2 +- extra/feature/CMakeLists.txt | 13 +- extra/feature/src/light_blob/light_blob.cpp | 2 +- extra/feature/src/light_blob/para_init.cpp | 2 +- extra/feature/src/pilot/pilot.cpp | 2 +- extra/feature/src/tag/tag.cpp | 2 +- extra/group/src/gyro_group/calc.cpp | 2 +- extra/group/src/gyro_group/init.cpp | 2 +- extra/group/src/gyro_group/sync.cpp | 2 +- extra/group/test/test_gyro_group.cpp | 2 +- extra/predictor/CMakeLists.txt | 8 +- .../src/rune_tracker/vanish_process.cpp | 2 +- include/rmvl/rmvl.hpp | 4 - modules/camera/CMakeLists.txt | 2 +- modules/camera/src/camera/camutils.cpp | 2 +- modules/core/CMakeLists.txt | 6 +- modules/core/include/rmvl/core.hpp | 22 +- modules/core/include/rmvl/core/dataio.hpp | 1 - modules/core/include/rmvl/core/datastruct.hpp | 321 ++++++++++++++++++ .../include/rmvl/core}/ew_topsis.hpp | 16 +- .../include/rmvl/core/math.hpp} | 10 +- .../include/rmvl/core/transform.hpp} | 12 +- modules/{rmath => core}/src/transform.cpp | 2 +- .../{rmath => core}/test/test_ew_topsis.cpp | 4 +- modules/{rmath => core}/test/test_ra_heap.cpp | 2 +- .../{rmath => core}/test/test_union_find.cpp | 2 +- modules/rmath/CMakeLists.txt | 17 - modules/rmath/include/rmvl/rmath.hpp | 32 -- modules/rmath/include/rmvl/rmath/ra_heap.hpp | 203 ----------- .../rmath/include/rmvl/rmath/union_find.hpp | 165 --------- samples/camera/hik/CMakeLists.txt | 3 + samples/camera/mv/CMakeLists.txt | 6 + samples/detector/hik/CMakeLists.txt | 4 + samples/detector/mv/CMakeLists.txt | 4 + 64 files changed, 483 insertions(+), 516 deletions(-) create mode 100644 doc/tutorials/modules/algorithm/dft.md rename doc/tutorials/modules/{core => algorithm}/ekf.md (99%) rename doc/tutorials/modules/{rmath => algorithm}/ew_topsis.md (94%) create mode 100644 doc/tutorials/modules/algorithm/fft.md rename doc/tutorials/modules/{core => algorithm}/func_iteration.md (100%) rename doc/tutorials/modules/{core => algorithm}/interpolation.md (99%) rename doc/tutorials/modules/{core => algorithm}/kalman.md (99%) rename doc/tutorials/modules/{core => algorithm}/least_square.md (100%) rename doc/tutorials/modules/{ort => algorithm}/ort.md (80%) rename doc/tutorials/modules/{rmath => algorithm}/ra_heap.md (98%) rename doc/tutorials/modules/{core => algorithm}/runge_kutta.md (99%) rename doc/tutorials/modules/{rmath => algorithm}/union_find.md (98%) rename doc/tutorials/modules/{core => tools}/aggregate_reflect.md (100%) rename doc/tutorials/modules/{devices => tools}/camera.md (99%) rename doc/tutorials/modules/{devices => tools}/light.md (74%) rename doc/tutorials/modules/{core => tools}/opcua.md (99%) rename doc/tutorials/modules/{core => tools}/serial.md (100%) create mode 100644 modules/core/include/rmvl/core/datastruct.hpp rename modules/{rmath/include/rmvl/rmath => core/include/rmvl/core}/ew_topsis.hpp (93%) rename modules/{rmath/include/rmvl/rmath/uty_math.hpp => core/include/rmvl/core/math.hpp} (99%) rename modules/{rmath/include/rmvl/rmath/transform.h => core/include/rmvl/core/transform.hpp} (96%) rename modules/{rmath => core}/src/transform.cpp (97%) rename modules/{rmath => core}/test/test_ew_topsis.cpp (97%) rename modules/{rmath => core}/test/test_ra_heap.cpp (98%) rename modules/{rmath => core}/test/test_union_find.cpp (98%) delete mode 100755 modules/rmath/CMakeLists.txt delete mode 100755 modules/rmath/include/rmvl/rmath.hpp delete mode 100644 modules/rmath/include/rmvl/rmath/ra_heap.hpp delete mode 100644 modules/rmath/include/rmvl/rmath/union_find.hpp diff --git a/doc/intro.markdown b/doc/intro.markdown index c53a9af4..9813fdb5 100644 --- a/doc/intro.markdown +++ b/doc/intro.markdown @@ -42,7 +42,7 @@ RMVL 具有模块化结构,这意味着该软件包包含了多个共享或静 点击[此处](@ref tutorial_install)可以安装以上相机的 SDK -- @ref ml (**ml**),@ref rmath (**rmath**) +- @ref ml (**ml**), @ref opcua (**opcua**) - ... 以及其他包含在 `modules` 文件夹中的模块。 diff --git a/doc/tutorials/modules/algorithm/dft.md b/doc/tutorials/modules/algorithm/dft.md new file mode 100644 index 00000000..a3cb4e51 --- /dev/null +++ b/doc/tutorials/modules/algorithm/dft.md @@ -0,0 +1,15 @@ +离散傅里叶变换 {#tutorial_modules_dft} +============ + +@author 赵曦 +@date 2024/04/26 +@version 1.0 +@brief 离散傅里叶变换公式推导与使用 + +@prev_tutorial{tutorial_modules_ekf} + +@next_tutorial{tutorial_modules_fft} + +@tableofcontents + +------ \ No newline at end of file diff --git a/doc/tutorials/modules/core/ekf.md b/doc/tutorials/modules/algorithm/ekf.md similarity index 99% rename from doc/tutorials/modules/core/ekf.md rename to doc/tutorials/modules/algorithm/ekf.md index 6a7691c9..de06c12b 100644 --- a/doc/tutorials/modules/core/ekf.md +++ b/doc/tutorials/modules/algorithm/ekf.md @@ -8,7 +8,7 @@ @prev_tutorial{tutorial_modules_kalman} -@next_tutorial{tutorial_modules_union_find} +@next_tutorial{tutorial_modules_dft} @tableofcontents diff --git a/doc/tutorials/modules/rmath/ew_topsis.md b/doc/tutorials/modules/algorithm/ew_topsis.md similarity index 94% rename from doc/tutorials/modules/rmath/ew_topsis.md rename to doc/tutorials/modules/algorithm/ew_topsis.md index 50eed9b7..26f78573 100644 --- a/doc/tutorials/modules/rmath/ew_topsis.md +++ b/doc/tutorials/modules/algorithm/ew_topsis.md @@ -4,9 +4,9 @@ @author RoboMaster Vision Community @date 2023/01/11 -@prev_tutorial{tutorial_modules_ra_heap} +@prev_tutorial{tutorial_modules_runge_kutta} -@next_tutorial{tutorial_modules_ort} +@next_tutorial{tutorial_modules_kalman} @tableofcontents diff --git a/doc/tutorials/modules/algorithm/fft.md b/doc/tutorials/modules/algorithm/fft.md new file mode 100644 index 00000000..f4790c1d --- /dev/null +++ b/doc/tutorials/modules/algorithm/fft.md @@ -0,0 +1,15 @@ +快速傅里叶变换 {#tutorial_modules_fft} +============ + +@author 赵曦 +@date 2024/04/26 +@version 1.0 +@brief 快速傅里叶变换公式推导与使用 + +@prev_tutorial{tutorial_modules_dft} + +@next_tutorial{tutorial_modules_union_find} + +@tableofcontents + +------ \ No newline at end of file diff --git a/doc/tutorials/modules/core/func_iteration.md b/doc/tutorials/modules/algorithm/func_iteration.md similarity index 100% rename from doc/tutorials/modules/core/func_iteration.md rename to doc/tutorials/modules/algorithm/func_iteration.md diff --git a/doc/tutorials/modules/core/interpolation.md b/doc/tutorials/modules/algorithm/interpolation.md similarity index 99% rename from doc/tutorials/modules/core/interpolation.md rename to doc/tutorials/modules/algorithm/interpolation.md index 7e2ad705..00a4b8ae 100644 --- a/doc/tutorials/modules/core/interpolation.md +++ b/doc/tutorials/modules/algorithm/interpolation.md @@ -6,7 +6,7 @@ @version 1.0 @brief 从 **Lagrange 插值** 与 **Newton 插值** 两种基函数选取方式介绍函数插值 -@prev_tutorial{tutorial_modules_opcua} +@prev_tutorial{tutorial_modules_light} @next_tutorial{tutorial_modules_least_square} diff --git a/doc/tutorials/modules/core/kalman.md b/doc/tutorials/modules/algorithm/kalman.md similarity index 99% rename from doc/tutorials/modules/core/kalman.md rename to doc/tutorials/modules/algorithm/kalman.md index 90649055..d07c4a54 100644 --- a/doc/tutorials/modules/core/kalman.md +++ b/doc/tutorials/modules/algorithm/kalman.md @@ -7,7 +7,7 @@ @version 2.0 @brief 卡尔曼滤波详细公式推导 -@prev_tutorial{tutorial_modules_runge_kutta} +@prev_tutorial{tutorial_modules_ew_topsis} @next_tutorial{tutorial_modules_ekf} diff --git a/doc/tutorials/modules/core/least_square.md b/doc/tutorials/modules/algorithm/least_square.md similarity index 100% rename from doc/tutorials/modules/core/least_square.md rename to doc/tutorials/modules/algorithm/least_square.md diff --git a/doc/tutorials/modules/ort/ort.md b/doc/tutorials/modules/algorithm/ort.md similarity index 80% rename from doc/tutorials/modules/ort/ort.md rename to doc/tutorials/modules/algorithm/ort.md index 386cdd6c..3e88e2a8 100644 --- a/doc/tutorials/modules/ort/ort.md +++ b/doc/tutorials/modules/algorithm/ort.md @@ -4,9 +4,7 @@ ONNX-Runtime 分类网络部署库 {#tutorial_modules_ort} @author @date -@prev_tutorial{tutorial_modules_ew_topsis} - -@next_tutorial{tutorial_modules_camera} +@prev_tutorial{tutorial_modules_ra_heap} @tableofcontents diff --git a/doc/tutorials/modules/rmath/ra_heap.md b/doc/tutorials/modules/algorithm/ra_heap.md similarity index 98% rename from doc/tutorials/modules/rmath/ra_heap.md rename to doc/tutorials/modules/algorithm/ra_heap.md index f8cf246e..af8cbd13 100644 --- a/doc/tutorials/modules/rmath/ra_heap.md +++ b/doc/tutorials/modules/algorithm/ra_heap.md @@ -6,7 +6,7 @@ @prev_tutorial{tutorial_modules_union_find} -@next_tutorial{tutorial_modules_ew_topsis} +@next_tutorial{tutorial_modules_ort} @tableofcontents diff --git a/doc/tutorials/modules/core/runge_kutta.md b/doc/tutorials/modules/algorithm/runge_kutta.md similarity index 99% rename from doc/tutorials/modules/core/runge_kutta.md rename to doc/tutorials/modules/algorithm/runge_kutta.md index a76b0a02..37ca68da 100644 --- a/doc/tutorials/modules/core/runge_kutta.md +++ b/doc/tutorials/modules/algorithm/runge_kutta.md @@ -8,7 +8,7 @@ @prev_tutorial{tutorial_modules_func_iteration} -@next_tutorial{tutorial_modules_kalman} +@next_tutorial{tutorial_modules_ew_topsis} @tableofcontents diff --git a/doc/tutorials/modules/rmath/union_find.md b/doc/tutorials/modules/algorithm/union_find.md similarity index 98% rename from doc/tutorials/modules/rmath/union_find.md rename to doc/tutorials/modules/algorithm/union_find.md index e43d3672..c540ae7d 100644 --- a/doc/tutorials/modules/rmath/union_find.md +++ b/doc/tutorials/modules/algorithm/union_find.md @@ -4,7 +4,7 @@ @author RoboMaster Vision Community @date 2023/01/11 -@prev_tutorial{tutorial_modules_kalman} +@prev_tutorial{tutorial_modules_fft} @next_tutorial{tutorial_modules_ra_heap} diff --git a/doc/tutorials/modules/core/aggregate_reflect.md b/doc/tutorials/modules/tools/aggregate_reflect.md similarity index 100% rename from doc/tutorials/modules/core/aggregate_reflect.md rename to doc/tutorials/modules/tools/aggregate_reflect.md diff --git a/doc/tutorials/modules/devices/camera.md b/doc/tutorials/modules/tools/camera.md similarity index 99% rename from doc/tutorials/modules/devices/camera.md rename to doc/tutorials/modules/tools/camera.md index f60b95b5..4be23005 100644 --- a/doc/tutorials/modules/devices/camera.md +++ b/doc/tutorials/modules/tools/camera.md @@ -5,7 +5,9 @@ @date 2023/03/15 @brief 相机模块的基本使用,包括初始化、参数设置以及运行示例 -@prev_tutorial{tutorial_modules_ort} +@prev_tutorial{tutorial_modules_opcua} + +@next_tutorial{tutorial_modules_light} @tableofcontents diff --git a/doc/tutorials/modules/devices/light.md b/doc/tutorials/modules/tools/light.md similarity index 74% rename from doc/tutorials/modules/devices/light.md rename to doc/tutorials/modules/tools/light.md index 1175778b..652a44f7 100644 --- a/doc/tutorials/modules/devices/light.md +++ b/doc/tutorials/modules/tools/light.md @@ -4,7 +4,9 @@ @author 赵曦 @date 2023/10/05 -@prev_tutorial{tutorial_modules_ort} +@prev_tutorial{tutorial_modules_camera} + +@next_tutorial{tutorial_modules_interpolation} @tableofcontents diff --git a/doc/tutorials/modules/core/opcua.md b/doc/tutorials/modules/tools/opcua.md similarity index 99% rename from doc/tutorials/modules/core/opcua.md rename to doc/tutorials/modules/tools/opcua.md index 2163f490..c2642bb3 100644 --- a/doc/tutorials/modules/core/opcua.md +++ b/doc/tutorials/modules/tools/opcua.md @@ -8,7 +8,7 @@ @prev_tutorial{tutorial_modules_serial} -@next_tutorial{tutorial_modules_interpolation} +@next_tutorial{tutorial_modules_camera} @tableofcontents @@ -511,7 +511,7 @@ int main() #### 有代理 Pub/Sub -RMVL 目前暂不支持有代理的发布订阅机制。 +@warning RMVL 目前暂不支持有代理的发布订阅机制。 ### 参数加载 {#opcua_parameters} diff --git a/doc/tutorials/modules/core/serial.md b/doc/tutorials/modules/tools/serial.md similarity index 100% rename from doc/tutorials/modules/core/serial.md rename to doc/tutorials/modules/tools/serial.md diff --git a/doc/tutorials/modules/tutorial_modules.md b/doc/tutorials/modules/tutorial_modules.md index 72363f63..15073309 100644 --- a/doc/tutorials/modules/tutorial_modules.md +++ b/doc/tutorials/modules/tutorial_modules.md @@ -9,38 +9,42 @@ ------ -### 1. 核心模块、教程 +### 1. 工具类 -#### 1.1 工具类 +#### 通用工具 - @subpage tutorial_modules_aggregate_reflect + +#### 通信 + - @subpage tutorial_modules_serial - @subpage tutorial_modules_opcua -#### 1.2 算法类 +#### 硬件设备支持库 + +- @subpage tutorial_modules_camera +- @subpage tutorial_modules_light + +### 2. 算法类 -##### 数值计算 +#### 数值计算 - @subpage tutorial_modules_interpolation - @subpage tutorial_modules_least_square - @subpage tutorial_modules_func_iteration - @subpage tutorial_modules_runge_kutta -##### 数据处理 +#### 数据与信号处理 +- @subpage tutorial_modules_ew_topsis - @subpage tutorial_modules_kalman 和 @subpage tutorial_modules_ekf +- @subpage tutorial_modules_dft 和 @subpage tutorial_modules_fft -### 2. 数据结构与算法 +#### 数据结构与算法 - @subpage tutorial_modules_union_find - @subpage tutorial_modules_ra_heap -- @subpage tutorial_modules_ew_topsis -### 3. 机器学习与深度学习支持库 +#### 机器学习与深度学习支持库 - @subpage tutorial_modules_ort - -### 4. 硬件设备支持库 - -- @subpage tutorial_modules_camera -- @subpage tutorial_modules_light diff --git a/extra/combo/include/rmvl/combo/combo.h b/extra/combo/include/rmvl/combo/combo.h index aba7edbb..d6667000 100755 --- a/extra/combo/include/rmvl/combo/combo.h +++ b/extra/combo/include/rmvl/combo/combo.h @@ -11,7 +11,7 @@ #pragma once #include "rmvl/camera/camutils.hpp" -#include "rmvl/rmath/uty_math.hpp" +#include "rmvl/core/math.hpp" #include "rmvl/types.hpp" #include "rmvl/core/dataio.hpp" diff --git a/extra/combo/src/armor/armor.cpp b/extra/combo/src/armor/armor.cpp index 9a2e9680..dfdf3707 100755 --- a/extra/combo/src/armor/armor.cpp +++ b/extra/combo/src/armor/armor.cpp @@ -10,7 +10,7 @@ */ #include "rmvl/combo/armor.h" -#include "rmvl/rmath/transform.h" +#include "rmvl/core/transform.hpp" #include "rmvlpara/camera/camera.h" #include "rmvlpara/combo/armor.h" diff --git a/extra/combo/src/armor/armor_cal.cpp b/extra/combo/src/armor/armor_cal.cpp index 73adf3f2..ebbae852 100755 --- a/extra/combo/src/armor/armor_cal.cpp +++ b/extra/combo/src/armor/armor_cal.cpp @@ -13,7 +13,7 @@ #include #include "rmvl/combo/armor.h" -#include "rmvl/rmath/transform.h" +#include "rmvl/core/transform.hpp" #include "rmvlpara/combo/armor.h" diff --git a/extra/combo/src/rune/rune.cpp b/extra/combo/src/rune/rune.cpp index 52c3644b..77666866 100755 --- a/extra/combo/src/rune/rune.cpp +++ b/extra/combo/src/rune/rune.cpp @@ -9,7 +9,7 @@ * */ -#include "rmvl/rmath/transform.h" +#include "rmvl/core/transform.hpp" #include "rmvl/combo/rune.h" diff --git a/extra/compensator/CMakeLists.txt b/extra/compensator/CMakeLists.txt index d8fba16e..8ee70e20 100755 --- a/extra/compensator/CMakeLists.txt +++ b/extra/compensator/CMakeLists.txt @@ -16,7 +16,7 @@ rmvl_generate_para( # gravity_compensator rmvl_add_module( gravity_compensator - DEPENDS compensator rmath + DEPENDS compensator ) # gyro_compensator diff --git a/extra/compensator/src/gyro_compensator/gyro_compensator.cpp b/extra/compensator/src/gyro_compensator/gyro_compensator.cpp index 8b768917..d6896c57 100755 --- a/extra/compensator/src/gyro_compensator/gyro_compensator.cpp +++ b/extra/compensator/src/gyro_compensator/gyro_compensator.cpp @@ -11,7 +11,7 @@ #include "rmvl/compensator/gyro_compensator.h" #include "rmvl/group/gyro_group.h" -#include "rmvl/rmath/transform.h" +#include "rmvl/core/transform.hpp" #include "rmvlpara/camera/camera.h" #include "rmvlpara/compensator/gyro_compensator.h" diff --git a/extra/compensator/test/test_gravity.cpp b/extra/compensator/test/test_gravity.cpp index 143e98f7..3af2f089 100644 --- a/extra/compensator/test/test_gravity.cpp +++ b/extra/compensator/test/test_gravity.cpp @@ -19,7 +19,7 @@ #undef private #undef protected -#include "rmvl/rmath/uty_math.hpp" +#include "rmvl/core/math.hpp" #include "rmvlpara/compensator/gravity_compensator.h" using namespace rm::numeric_literals; diff --git a/extra/decider/src/gyro_decider/gyro_decider.cpp b/extra/decider/src/gyro_decider/gyro_decider.cpp index 329ce926..8a1a16c7 100644 --- a/extra/decider/src/gyro_decider/gyro_decider.cpp +++ b/extra/decider/src/gyro_decider/gyro_decider.cpp @@ -11,7 +11,7 @@ #include "rmvl/decider/gyro_decider.h" #include "rmvl/group/gyro_group.h" -#include "rmvl/rmath/transform.h" +#include "rmvl/core/transform.hpp" #include "rmvl/tracker/gyro_tracker.h" #include "rmvlpara/camera/camera.h" diff --git a/extra/decider/src/rune_decider/rune_decider.cpp b/extra/decider/src/rune_decider/rune_decider.cpp index 5a0e127b..3205c1b0 100755 --- a/extra/decider/src/rune_decider/rune_decider.cpp +++ b/extra/decider/src/rune_decider/rune_decider.cpp @@ -12,8 +12,8 @@ #include "rmvl/decider/rune_decider.h" #include "rmvl/combo/rune.h" #include "rmvl/core/timer.hpp" -#include "rmvl/rmath/transform.h" -#include "rmvl/rmath/uty_math.hpp" +#include "rmvl/core/transform.hpp" +#include "rmvl/core/math.hpp" #include "rmvlpara/camera/camera.h" #include "rmvlpara/decider/rune_decider.h" diff --git a/extra/decider/src/translation_decider/translation_decider.cpp b/extra/decider/src/translation_decider/translation_decider.cpp index b99e612c..8f5557c2 100755 --- a/extra/decider/src/translation_decider/translation_decider.cpp +++ b/extra/decider/src/translation_decider/translation_decider.cpp @@ -10,7 +10,7 @@ */ #include "rmvl/decider/translation_decider.h" -#include "rmvl/rmath.hpp" +#include "rmvl/core.hpp" #include "rmvlpara/camera/camera.h" #include "rmvlpara/decider/translation_decider.h" diff --git a/extra/detector/src/gyro_detector/inference.cpp b/extra/detector/src/gyro_detector/inference.cpp index 2f80d96b..676ffa86 100644 --- a/extra/detector/src/gyro_detector/inference.cpp +++ b/extra/detector/src/gyro_detector/inference.cpp @@ -13,7 +13,7 @@ #include "rmvl/detector/gyro_detector.h" #include "rmvl/group/gyro_group.h" -#include "rmvl/rmath/ew_topsis.hpp" +#include "rmvl/core/ew_topsis.hpp" using namespace rm; using namespace std; diff --git a/extra/detector/src/gyro_detector/match.cpp b/extra/detector/src/gyro_detector/match.cpp index c3bd61e8..9284a25c 100755 --- a/extra/detector/src/gyro_detector/match.cpp +++ b/extra/detector/src/gyro_detector/match.cpp @@ -11,7 +11,7 @@ #include "rmvl/detector/gyro_detector.h" #include "rmvl/group/gyro_group.h" -#include "rmvl/rmath/union_find.hpp" +#include "rmvl/core/datastruct.hpp" #include "rmvlpara/camera/camera.h" #include "rmvlpara/detector/gyro_detector.h" diff --git a/extra/feature/CMakeLists.txt b/extra/feature/CMakeLists.txt index 1f9b10e3..c55e0e8e 100755 --- a/extra/feature/CMakeLists.txt +++ b/extra/feature/CMakeLists.txt @@ -1,6 +1,9 @@ +find_package(OpenCV COMPONENTS imgproc calib3d REQUIRED) + rmvl_add_module( feature INTERFACE DEPENDS types + EXTERNAL ${OpenCV_LIBS} ) # light_blob @@ -10,7 +13,7 @@ rmvl_generate_para( ) rmvl_add_module( light_blob - DEPENDS feature rmath + DEPENDS feature ) # pilot @@ -20,7 +23,7 @@ rmvl_generate_para( ) rmvl_add_module( pilot - DEPENDS feature rmath + DEPENDS feature ) # rune_center @@ -30,7 +33,7 @@ rmvl_generate_para( ) rmvl_add_module( rune_center - DEPENDS feature rmath + DEPENDS feature ) # rune_target @@ -40,13 +43,13 @@ rmvl_generate_para( ) rmvl_add_module( rune_target - DEPENDS feature rmath + DEPENDS feature ) # tag rmvl_add_module( tag - DEPENDS feature rmath + DEPENDS feature ) rmvl_generate_module_para(feature) diff --git a/extra/feature/src/light_blob/light_blob.cpp b/extra/feature/src/light_blob/light_blob.cpp index 975b7911..aab657d4 100644 --- a/extra/feature/src/light_blob/light_blob.cpp +++ b/extra/feature/src/light_blob/light_blob.cpp @@ -12,7 +12,7 @@ #include #include "rmvl/feature/light_blob.h" -#include "rmvl/rmath.hpp" +#include "rmvl/core.hpp" #include "rmvlpara/feature/light_blob.h" diff --git a/extra/feature/src/light_blob/para_init.cpp b/extra/feature/src/light_blob/para_init.cpp index 50f49b3c..446c7f52 100644 --- a/extra/feature/src/light_blob/para_init.cpp +++ b/extra/feature/src/light_blob/para_init.cpp @@ -11,7 +11,7 @@ #include "rmvl/feature/light_blob.h" #include "rmvl/core/util.hpp" -#include "rmvl/rmath.hpp" +#include "rmvl/core.hpp" using namespace rm; using namespace std; diff --git a/extra/feature/src/pilot/pilot.cpp b/extra/feature/src/pilot/pilot.cpp index 7d7c1da2..911eef4b 100755 --- a/extra/feature/src/pilot/pilot.cpp +++ b/extra/feature/src/pilot/pilot.cpp @@ -12,7 +12,7 @@ #include #include "rmvl/feature/pilot.h" -#include "rmvl/rmath.hpp" +#include "rmvl/core.hpp" #include "rmvlpara/feature/pilot.h" diff --git a/extra/feature/src/tag/tag.cpp b/extra/feature/src/tag/tag.cpp index 5eda7da7..4bd53894 100644 --- a/extra/feature/src/tag/tag.cpp +++ b/extra/feature/src/tag/tag.cpp @@ -12,7 +12,7 @@ #include "rmvl/feature/tag.h" #include "rmvl/core/util.hpp" -#include "rmvl/rmath/uty_math.hpp" +#include "rmvl/core/math.hpp" using namespace std; using namespace cv; diff --git a/extra/group/src/gyro_group/calc.cpp b/extra/group/src/gyro_group/calc.cpp index 643f7ce4..c1e1b97d 100644 --- a/extra/group/src/gyro_group/calc.cpp +++ b/extra/group/src/gyro_group/calc.cpp @@ -12,7 +12,7 @@ #include #include "rmvl/group/gyro_group.h" -#include "rmvl/rmath/transform.h" +#include "rmvl/core/transform.hpp" #include "rmvl/tracker/gyro_tracker.h" #include "rmvlpara/camera/camera.h" diff --git a/extra/group/src/gyro_group/init.cpp b/extra/group/src/gyro_group/init.cpp index b23e9b88..a81bd6ae 100644 --- a/extra/group/src/gyro_group/init.cpp +++ b/extra/group/src/gyro_group/init.cpp @@ -10,7 +10,7 @@ */ #include "rmvl/group/gyro_group.h" -#include "rmvl/rmath/transform.h" +#include "rmvl/core/transform.hpp" #include "rmvl/tracker/gyro_tracker.h" #include "rmvlpara/camera/camera.h" diff --git a/extra/group/src/gyro_group/sync.cpp b/extra/group/src/gyro_group/sync.cpp index 5d6f21ee..e128ead4 100644 --- a/extra/group/src/gyro_group/sync.cpp +++ b/extra/group/src/gyro_group/sync.cpp @@ -10,7 +10,7 @@ */ #include "rmvl/group/gyro_group.h" -#include "rmvl/rmath/transform.h" +#include "rmvl/core/transform.hpp" #include "rmvl/tracker/gyro_tracker.h" #include "rmvlpara/camera/camera.h" diff --git a/extra/group/test/test_gyro_group.cpp b/extra/group/test/test_gyro_group.cpp index 09484e68..cb73eb1a 100644 --- a/extra/group/test/test_gyro_group.cpp +++ b/extra/group/test/test_gyro_group.cpp @@ -14,7 +14,7 @@ #include #include "rmvl/core/timer.hpp" -#include "rmvl/rmath/transform.h" +#include "rmvl/core/transform.hpp" #include "rmvl/group/gyro_group.h" #include "rmvl/tracker/gyro_tracker.h" diff --git a/extra/predictor/CMakeLists.txt b/extra/predictor/CMakeLists.txt index 76a41bea..84308b7e 100755 --- a/extra/predictor/CMakeLists.txt +++ b/extra/predictor/CMakeLists.txt @@ -10,7 +10,7 @@ rmvl_generate_para( ) rmvl_add_module( armor_predictor - DEPENDS predictor rmath camera + DEPENDS predictor camera ) # rune_predictor @@ -20,7 +20,7 @@ rmvl_generate_para( ) rmvl_add_module( rune_predictor - DEPENDS predictor rmath camera rune_group + DEPENDS predictor camera rune_group ) # spi_rune_predictor @@ -30,7 +30,7 @@ rmvl_generate_para( ) rmvl_add_module( spi_rune_predictor - DEPENDS predictor rmath rune_group + DEPENDS predictor rune_group ) # gyro_predictor @@ -40,7 +40,7 @@ rmvl_generate_para( ) rmvl_add_module( gyro_predictor - DEPENDS predictor rmath camera + DEPENDS predictor camera ) rmvl_generate_module_para(predictor) diff --git a/extra/tracker/src/rune_tracker/vanish_process.cpp b/extra/tracker/src/rune_tracker/vanish_process.cpp index 9014d3ac..20564c0e 100644 --- a/extra/tracker/src/rune_tracker/vanish_process.cpp +++ b/extra/tracker/src/rune_tracker/vanish_process.cpp @@ -9,7 +9,7 @@ * */ -#include "rmvl/rmath/transform.h" +#include "rmvl/core/transform.hpp" #include "rmvl/tracker/rune_tracker.h" #include "rmvlpara/camera/camera.h" diff --git a/include/rmvl/rmvl.hpp b/include/rmvl/rmvl.hpp index a4b98a8f..1f3c23a0 100644 --- a/include/rmvl/rmvl.hpp +++ b/include/rmvl/rmvl.hpp @@ -34,10 +34,6 @@ #include "rmvl/imgproc.hpp" #endif // HAVE_RMVL_IMGPROC -#ifdef HAVE_RMVL_RMATH -#include "rmvl/rmath.hpp" -#endif // HAVE_RMVL_RMATH - #ifdef HAVE_RMVL_OPCUA #include "rmvl/opcua.hpp" #endif // HAVE_RMVL_OPCUA diff --git a/modules/camera/CMakeLists.txt b/modules/camera/CMakeLists.txt index d9d79803..7025d85d 100755 --- a/modules/camera/CMakeLists.txt +++ b/modules/camera/CMakeLists.txt @@ -5,7 +5,7 @@ rmvl_generate_para( rmvl_add_module( camera - DEPENDS rmath + DEPENDS core ) # -------------------------------------------------------------------------- diff --git a/modules/camera/src/camera/camutils.cpp b/modules/camera/src/camera/camutils.cpp index 24d581b5..9c0400b3 100644 --- a/modules/camera/src/camera/camutils.cpp +++ b/modules/camera/src/camera/camutils.cpp @@ -15,7 +15,7 @@ #include #include "rmvl/camera/camutils.hpp" -#include "rmvl/rmath/uty_math.hpp" +#include "rmvl/core/math.hpp" #include "rmvlpara/camera/camera.h" void rm::CameraExtrinsics::tvec(const cv::Vec3f &tvec) diff --git a/modules/core/CMakeLists.txt b/modules/core/CMakeLists.txt index 8c9a75b6..67e4dacd 100644 --- a/modules/core/CMakeLists.txt +++ b/modules/core/CMakeLists.txt @@ -1,5 +1,6 @@ find_package(Threads REQUIRED) -find_package(OpenCV REQUIRED) +find_package(OpenCV COMPONENTS core REQUIRED) +find_package(Eigen3 REQUIRED) # 生成预定义宏 rmvl_check_include_file( @@ -13,7 +14,8 @@ rmvl_generate_para(core) # 添加 core 模块 rmvl_add_module( core - EXTERNAL ${OpenCV_LIBS} ${CMAKE_THREAD_LIBS_INIT} + EXTRA_HEADER ${EIGEN3_INCLUDE_DIR} + EXTERNAL ${CMAKE_THREAD_LIBS_INIT} opencv_core ) # 添加预定义宏到 core 模块 diff --git a/modules/core/include/rmvl/core.hpp b/modules/core/include/rmvl/core.hpp index 34e9238a..74e18812 100644 --- a/modules/core/include/rmvl/core.hpp +++ b/modules/core/include/rmvl/core.hpp @@ -26,11 +26,25 @@ * @} */ +#include + +// 通用 #include "core/util.hpp" #include "core/version.hpp" - -#include "core/dataio.hpp" -#include "core/kalman.hpp" -#include "core/numcal.hpp" #include "core/serial.hpp" #include "core/timer.hpp" +#include "core/dataio.hpp" + +// 基础数学库 +#include "core/math.hpp" +#include "core/transform.hpp" + +// 数值计算 +#include "core/numcal.hpp" + +// 数据、信号处理 +#include "core/ew_topsis.hpp" +#include "core/kalman.hpp" + +// 数据结构 +#include "core/datastruct.hpp" diff --git a/modules/core/include/rmvl/core/dataio.hpp b/modules/core/include/rmvl/core/dataio.hpp index dbce4bff..22df9a1e 100644 --- a/modules/core/include/rmvl/core/dataio.hpp +++ b/modules/core/include/rmvl/core/dataio.hpp @@ -97,7 +97,6 @@ void writeCorners(std::ostream &out, const std::vector`,`` 表示对应的标号,即参数 `idx` * - 读取的文件形如以下内容 * @code{.txt} * 1.9, 2.11, diff --git a/modules/core/include/rmvl/core/datastruct.hpp b/modules/core/include/rmvl/core/datastruct.hpp new file mode 100644 index 00000000..99e26029 --- /dev/null +++ b/modules/core/include/rmvl/core/datastruct.hpp @@ -0,0 +1,321 @@ +/** + * @file datastruct.hpp + * @author zhaoxi (535394140@qq.com) + * @brief 数据结构 + * @version 1.0 + * @date 2024-04-27 + * + * @copyright Copyright 2024 (c), zhaoxi + * + */ + +#pragma once + +#include +#include +#include +#include +#include + +namespace rm +{ + +//! @addtogroup core +//! @{ +//! @defgroup core_datastruct 数据结构 +//! @{ +//! @brief 包含自定义的容器适配器以及其余数据结构 +//! @} core_datastruct +//! @} core + +//! @addtogroup core_datastruct +//! @{ + +/** + * @brief 支持随机访问的堆(与 `std::priority_queue` 具备相同的基础容器筛选条件) + * + * @tparam Tp 元素类型 + * @tparam Sequence 容器类型,默认为 `std::vector` + * @tparam Compare 比较器可调用对象,默认为 `std::less`,即默认为大根堆 + */ +template , typename Compare = std::less> +class RaHeap +{ + static_assert(std::is_same_v, + "value_type must be the same as the underlying container"); + +public: + typedef Tp value_type; + typedef Tp &reference; + typedef const Tp &const_reference; + typedef std::size_t size_type; + typedef Sequence container_type; + typedef Compare value_compare; + +private: + Sequence _c; //!< 元素数组 + Compare _comp; //!< 可调用对象 + + std::unordered_map _indexs; //!< 下标哈希表(存放数组的下标) + +public: + RaHeap() = default; + + /** + * @brief 在堆顶添加元素 + * + * @param[in] x 待添加的元素 + */ + inline void push(const Tp &x) + { + _c.push_back(x); + _indexs[x] = _c.size() - 1; + upHeapify(_c.size() - 1); + } + + /** + * @brief 在堆顶添加元素 + * + * @param[in] x 待添加的元素 + */ + inline void push(Tp &&x) + { + _c.push_back(std::move(x)); + _indexs[x] = _c.size() - 1; + upHeapify(_c.size() - 1); + } + + /** + * @brief 在堆顶添加元素 + * + * @param[in] x 待添加的元素 + */ + template + inline void emplace(ValueType &&x) + { + _c.emplace_back(std::forward(x)); + _indexs[x] = _c.size() - 1; + upHeapify(_c.size() - 1); + } + + /** + * @brief 更新元素 + * + * @param[in] prev 之前的元素 + * @param[in] value 改动后的元素 + */ + inline void update(const Tp &prev, const Tp &value) + { + if (_indexs.find(prev) == _indexs.end()) + return; + std::size_t idx = _indexs[prev]; + _indexs[value] = idx; + _indexs.erase(prev); + _c[idx] = value; + (_comp(prev, value)) ? upHeapify(idx) : downHeapify(idx); + } + + /** + * @brief 删除指定元素 + * + * @param[in] value 待删除的元素 + */ + inline void erase(const Tp &value) + { + if (_indexs.find(value) == _indexs.end()) + return; + std::size_t idx = _indexs[value]; + swapNode(idx, _c.size() - 1); + _indexs.erase(_c.back()); + _c.pop_back(); + downHeapify(idx); + } + + //! 弹出堆顶 + inline void pop() + { + swapNode(0, _c.size() - 1); + _indexs.erase(_c.back()); + _c.pop_back(); + downHeapify(0); + } + + //! 堆是否为空 + inline bool empty() { return _c.empty(); } + //! 堆的大小 + inline std::size_t size() { return _c.size(); } + //! 获取堆顶元素 + inline const Tp &top() const { return _c.front(); } + //! 导出容器 + inline const Sequence &c() const { return _c; } + +private: + //! 交换 `_c` 数组中指定的两个下标的元素 + void swapNode(std::size_t idx1, std::size_t idx2) + { + _indexs[_c[idx1]] = idx2; + _indexs[_c[idx2]] = idx1; + std::swap(_c[idx1], _c[idx2]); + } + + //! 从给定的节点开始往上生成堆 + void upHeapify(std::size_t idx) + { + while (idx != 0 && _comp(_c[(idx - 1) >> 1], _c[idx])) + { + swapNode((idx - 1) >> 1, idx); + idx = (idx - 1) >> 1; + } + } + + //! 从给定的节点开始往下生成堆 + void downHeapify(std::size_t idx) + { + std::size_t left = (idx << 1) + 1; + while (left < _c.size()) + { + // 左节点与右节点比较出满足条件的 + auto better = left + 1 < _c.size() && _comp(_c[left], _c[left + 1]) ? left + 1 : left; + // 满足条件的子节点与自身比较 + better = _comp(_c[better], _c[idx]) ? idx : better; + if (better == idx) + break; + swapNode(idx, better); + // update + idx = better; + left = (idx << 1) + 1; + } + } +}; + +/** + * @brief 并查集 + * + * @tparam Tp 元素类型 + */ +template +class UnionFind +{ +public: + typedef Tp value_type; + typedef Tp &reference; + typedef const Tp &const_reference; + typedef std::size_t size_type; + +private: + std::unordered_set _element_set; //!< 元素集合 + std::unordered_map _parent_map; //!< 父元素哈希表 + std::unordered_map _size_map; //!< 集合大小 + int _connected_component{}; //!< 连通分量 + +public: + /** + * @brief 构造并查集 + * + * @tparam InputIterator 老式前向迭代器类型 + * @param[in] first 起始迭代器 + * @param[in] last 终止迭代器 + */ + template + UnionFind(InputIterator first, InputIterator last) + { + try + { + for (; first != last; ++first) + { + _element_set.insert(*first); + _parent_map[*first] = *first; + _size_map[*first] = 1; + _connected_component++; + } + } + catch (...) + { + _element_set.clear(); + throw; + } + } + + /** + * @brief 两个元素是否在同一个集合 + * + * @param[in] val_a 元素 A + * @param[in] val_b 元素 B + * @return 是否在同一个集合 + */ + inline bool isSameSet(const Tp &val_a, const Tp &val_b) + { + // Sign up? + if (_element_set.find(val_a) == _element_set.end() || + _element_set.find(val_b) == _element_set.end()) + return false; + // Common representation element? + return findRep(val_a) == findRep(val_b); + } + + /** + * @brief 将两个元素所在集合合并 + * + * @param[in] val_a 元素 A + * @param[in] val_b 元素 B + */ + inline void unionSet(const Tp &val_a, const Tp &val_b) + { + // Sign up? + if (_element_set.find(val_a) == _element_set.end() || + _element_set.find(val_b) == _element_set.end()) + return; + // Common representation element? + auto a_rep = findRep(val_a); + auto b_rep = findRep(val_b); + if (a_rep == b_rep) + return; + // Mount samll set to large set. + auto large_set = _size_map[a_rep] >= _size_map[b_rep] ? a_rep : b_rep; + auto small_set = large_set == a_rep ? b_rep : a_rep; + _parent_map[small_set] = large_set; + _size_map[large_set] = _size_map[a_rep] + _size_map[b_rep]; + _size_map.erase(small_set); + _connected_component--; + } + + /** + * @brief 导出数据 + * + * @return Key: 集合代表元素,Value: 集合 + */ + inline std::unordered_map> exportData() + { + std::unordered_map> datas; + for (const auto &map_pair : _size_map) + datas[map_pair.first].reserve(map_pair.second); + for (const auto &element : _element_set) + datas[findRep(element)].emplace_back(element); + return datas; + } + + //! 获取连通分量 + inline int getConnectedComponent() { return _connected_component; } + +private: + //! 寻找代表元素 + Tp findRep(Tp element) + { + std::stack path; + while (element != _parent_map[element]) + { + path.push(element); + element = _parent_map[element]; + } + while (!path.empty()) + { + _parent_map[path.top()] = element; + path.pop(); + } + return element; + } +}; + +//! @} core_datastruct + +} // namespace rm diff --git a/modules/rmath/include/rmvl/rmath/ew_topsis.hpp b/modules/core/include/rmvl/core/ew_topsis.hpp similarity index 93% rename from modules/rmath/include/rmvl/rmath/ew_topsis.hpp rename to modules/core/include/rmvl/core/ew_topsis.hpp index cec8d7c7..96011a85 100644 --- a/modules/rmath/include/rmvl/rmath/ew_topsis.hpp +++ b/modules/core/include/rmvl/core/ew_topsis.hpp @@ -19,11 +19,11 @@ namespace rm { -//! @addtogroup rmath +//! @addtogroup core //! @{ /** - * @brief 熵权法 + * @brief 熵权 TOPSIS 算法 * * @tparam Tp 元素类型 */ @@ -32,7 +32,6 @@ class EwTopsis { public: typedef Tp value_type; - typedef Tp *pointer; typedef Tp &reference; typedef const Tp &const_reference; typedef std::size_t size_type; @@ -53,16 +52,13 @@ class EwTopsis EwTopsis(EwTopsis &&) = delete; /** - * @brief 构造熵权法包装器 + * @brief 构造熵权 TOPSIS 算法类 * - * @param samples 样本指标 + * @param[in] samples 样本指标 */ - EwTopsis(const mat_type &samples) - : R_(samples), _sample_size(samples.size()), _index_size(samples[0].size()) {} + EwTopsis(const mat_type &samples) : R_(samples), _sample_size(samples.size()), _index_size(samples[0].size()) {} - /** - * @brief 权熵法推理出最终的指标 - */ + //! 基于权熵 TOPSIS 推理出最终的指标 void inference() { mat_type R; diff --git a/modules/rmath/include/rmvl/rmath/uty_math.hpp b/modules/core/include/rmvl/core/math.hpp similarity index 99% rename from modules/rmath/include/rmvl/rmath/uty_math.hpp rename to modules/core/include/rmvl/core/math.hpp index a6c07c68..696aa5db 100644 --- a/modules/rmath/include/rmvl/rmath/uty_math.hpp +++ b/modules/core/include/rmvl/core/math.hpp @@ -1,7 +1,7 @@ /** - * @file uty_math.hpp + * @file math.hpp * @author RoboMaster Vision Community - * @brief + * @brief 基础数学库 * @version 1.0 * @date 2023-01-12 * @@ -20,12 +20,12 @@ #include -#include "rmvl/core/util.hpp" +#include "util.hpp" namespace rm { -//! @addtogroup rmath +//! @addtogroup core //! @{ // --------------------【结构、类型、常量定义】-------------------- @@ -421,6 +421,6 @@ typename ForwardIterator::value_type calculateModeNum(ForwardIterator first, For ->first; } -//! @} rmath +//! @} core } // namespace rm diff --git a/modules/rmath/include/rmvl/rmath/transform.h b/modules/core/include/rmvl/core/transform.hpp similarity index 96% rename from modules/rmath/include/rmvl/rmath/transform.h rename to modules/core/include/rmvl/core/transform.hpp index 61acda19..74c8d27e 100644 --- a/modules/rmath/include/rmvl/rmath/transform.h +++ b/modules/core/include/rmvl/core/transform.hpp @@ -1,7 +1,7 @@ /** - * @file transform.h + * @file transform.hpp * @author RoboMaster Vision Community - * @brief + * @brief 坐标变换 * @version 1.0 * @date 2023-01-12 * @@ -13,13 +13,13 @@ #include -#include "rmvl/core/util.hpp" -#include "uty_math.hpp" +#include "util.hpp" +#include "math.hpp" namespace rm { -//! @addtogroup rmath +//! @addtogroup core //! @{ //! 欧拉角转轴枚举 @@ -106,6 +106,6 @@ inline cv::Matx euler2Mat(Tp val, EulerAxis axis) } } -//! @} rmath +//! @} core } // namespace rm diff --git a/modules/rmath/src/transform.cpp b/modules/core/src/transform.cpp similarity index 97% rename from modules/rmath/src/transform.cpp rename to modules/core/src/transform.cpp index 84bf80b2..17634b8b 100755 --- a/modules/rmath/src/transform.cpp +++ b/modules/core/src/transform.cpp @@ -11,7 +11,7 @@ #include -#include "rmvl/rmath/transform.h" +#include "rmvl/core/transform.hpp" cv::Point2f rm::calculateRelativeAngle(const cv::Matx33f &cameraMatrix, cv::Point2f center) { diff --git a/modules/rmath/test/test_ew_topsis.cpp b/modules/core/test/test_ew_topsis.cpp similarity index 97% rename from modules/rmath/test/test_ew_topsis.cpp rename to modules/core/test/test_ew_topsis.cpp index ef4b9f69..f609c1d6 100644 --- a/modules/rmath/test/test_ew_topsis.cpp +++ b/modules/core/test/test_ew_topsis.cpp @@ -15,8 +15,8 @@ #include -#include "rmvl/rmath/ew_topsis.hpp" -#include "rmvl/rmath/uty_math.hpp" +#include "rmvl/core/ew_topsis.hpp" +#include "rmvl/core/math.hpp" using namespace rm; using namespace std; diff --git a/modules/rmath/test/test_ra_heap.cpp b/modules/core/test/test_ra_heap.cpp similarity index 98% rename from modules/rmath/test/test_ra_heap.cpp rename to modules/core/test/test_ra_heap.cpp index ae06c05c..dfa2fc22 100644 --- a/modules/rmath/test/test_ra_heap.cpp +++ b/modules/core/test/test_ra_heap.cpp @@ -15,7 +15,7 @@ #include -#include "rmvl/rmath/ra_heap.hpp" +#include "rmvl/core/datastruct.hpp" using namespace rm; using namespace std; diff --git a/modules/rmath/test/test_union_find.cpp b/modules/core/test/test_union_find.cpp similarity index 98% rename from modules/rmath/test/test_union_find.cpp rename to modules/core/test/test_union_find.cpp index 2b53f727..a80508bd 100644 --- a/modules/rmath/test/test_union_find.cpp +++ b/modules/core/test/test_union_find.cpp @@ -16,7 +16,7 @@ #define private public -#include "rmvl/rmath/union_find.hpp" +#include "rmvl/core/datastruct.hpp" #undef private diff --git a/modules/rmath/CMakeLists.txt b/modules/rmath/CMakeLists.txt deleted file mode 100755 index a5ab9e06..00000000 --- a/modules/rmath/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -find_package(Eigen3 REQUIRED) - -rmvl_add_module( - rmath - DEPENDS core - EXTRA_HEADER ${EIGEN3_INCLUDE_DIR} - EXTERNAL -) - -# build the test program -if(BUILD_TESTS) - rmvl_add_test( - rmath Unit - DEPENDS rmath - DEPEND_TESTS GTest::gtest_main - ) -endif(BUILD_TESTS) diff --git a/modules/rmath/include/rmvl/rmath.hpp b/modules/rmath/include/rmvl/rmath.hpp deleted file mode 100755 index f0014b6f..00000000 --- a/modules/rmath/include/rmvl/rmath.hpp +++ /dev/null @@ -1,32 +0,0 @@ -/** - * @file rmath.hpp - * @author RoboMaster Vision Community - * @brief 额外数据函数库 - * @version 1.0 - * @date 2021-06-14 - * - * @copyright Copyright 2021 (c), RoboMaster Vision Community - * - */ - -#pragma once - -/** - * @defgroup rmath 数据结构与算法及实用数学库 - * @{ - * @defgroup union_find 并查集 - * @defgroup ra_heap 支持随机访问的堆结构 - * @} - */ - -#include - -#ifdef HAVE_RMVL_RMATH -#include "rmath/uty_math.hpp" - -#include "rmath/transform.h" -#include "rmath/ew_topsis.hpp" - -#include "rmath/union_find.hpp" -#include "rmath/ra_heap.hpp" -#endif // HAVE_RMVL_RMATH diff --git a/modules/rmath/include/rmvl/rmath/ra_heap.hpp b/modules/rmath/include/rmvl/rmath/ra_heap.hpp deleted file mode 100644 index 36b4c51a..00000000 --- a/modules/rmath/include/rmvl/rmath/ra_heap.hpp +++ /dev/null @@ -1,203 +0,0 @@ -/** - * @file ra_heap.hpp - * @author RoboMaster Vision Community - * @brief 支持随机访问的堆 - * @version 1.0 - * @date 2023-01-12 - * - * @copyright Copyright 2023 (c), RoboMaster Vision Community - * - */ - -#pragma once - -#include -#include -#include - -namespace rm -{ - -//! @addtogroup ra_heap -//! @{ - -/** - * @brief 支持随机访问的堆 - * - * @tparam Tp 元素类型 - * @tparam Sequence 容器类型,默认为 std::vector - * @tparam Compare 比较器可调用对象,默认为 std::less,即默认为大根堆 - */ -template , typename Compare = std::less> -class RaHeap -{ -#if __cplusplus >= 201703L - static_assert(std::is_same_v, - "value_type must be the same as the underlying container"); -#endif // C++17 - -public: - typedef typename Sequence::value_type value_type; - typedef typename Sequence::reference reference; - typedef typename Sequence::const_reference const_reference; - typedef typename Sequence::size_type size_type; - typedef Sequence container_type; - typedef Compare value_compare; - -private: - Sequence _c; //!< 元素数组 - Compare _comp; //!< 可调用对象 - - std::unordered_map _indexs; //!< 下标哈希表(存放数组的下标) - -public: - RaHeap() = default; - - /** - * @brief 在堆顶添加元素 - * - * @param x 待添加的元素 - */ - void push(const_reference x) - { - _c.push_back(x); - _indexs[x] = _c.size() - 1; - upHeapify(_c.size() - 1); - } - - /** - * @brief 在堆顶添加元素 - * - * @param x 待添加的元素 - */ - void push(value_type &&x) - { - _c.push_back(std::move(x)); - _indexs[x] = _c.size() - 1; - upHeapify(_c.size() - 1); - } - - /** - * @brief 在堆顶添加元素 - * - * @param x 待添加的元素 - */ - template - void emplace(ValueType &&x) - { - _c.emplace_back(std::forward(x)); - _indexs[x] = _c.size() - 1; - upHeapify(_c.size() - 1); - } - - /** - * @brief 更新元素 - * - * @param prev 之前的元素 - * @param value 改动后的元素 - */ - void update(const_reference prev, const_reference value) - { - if (_indexs.find(prev) == _indexs.end()) - return; - size_type idx = _indexs[prev]; - _indexs[value] = idx; - _indexs.erase(prev); - _c[idx] = value; - if (_comp(prev, value)) - upHeapify(idx); - else - downHeapify(idx); - } - - /** - * @brief 删除指定元素 - * - * @param value 待删除的元素 - */ - void erase(const_reference value) - { - if (_indexs.find(value) == _indexs.end()) - return; - size_type idx = _indexs[value]; - swapNode(idx, _c.size() - 1); - _indexs.erase(_c.back()); - _c.pop_back(); - downHeapify(idx); - } - - /** - * @brief 弹出堆顶 - */ - void pop() - { - swapNode(0, _c.size() - 1); - _indexs.erase(_c.back()); - _c.pop_back(); - downHeapify(0); - } - - //! 堆是否为空 - inline bool empty() { return size() == 0; } - //! 堆的大小 - inline size_type size() { return _c.size(); } - //! 获取堆顶元素 - inline const_reference top() const { return _c.front(); } - //! 导出容器 - inline const container_type &c() const { return _c; } - -private: - /** - * @brief 交换 _c 数组中指定的两个下标的元素 - * - * @param idx1 下标 1 - * @param idx2 小标 2 - */ - void swapNode(size_t idx1, size_t idx2) - { - _indexs[_c[idx1]] = idx2; - _indexs[_c[idx2]] = idx1; - std::swap(_c[idx1], _c[idx2]); - } - - /** - * @brief 从给定的节点开始往上生成堆 - * - * @param idx 节点下标 - */ - void upHeapify(size_type idx) - { - while (idx != 0 && _comp(_c[(idx - 1) >> 1], _c[idx])) - { - swapNode((idx - 1) >> 1, idx); - idx = (idx - 1) >> 1; - } - } - - /** - * @brief 从给定的节点开始往下生成堆 - * - * @param idx 节点下标 - */ - void downHeapify(size_type idx) - { - size_type left = (idx << 1) + 1; - while (left < _c.size()) - { - // 左节点与右节点比较出满足条件的 - size_type better = left + 1 < _c.size() && _comp(_c[left], _c[left + 1]) ? left + 1 : left; - // 满足条件的子节点与自身比较 - better = _comp(_c[better], _c[idx]) ? idx : better; - if (better == idx) - break; - swapNode(idx, better); - // update - idx = better; - left = (idx << 1) + 1; - } - } -}; - -//! @} ra_heap - -} // namespace rm diff --git a/modules/rmath/include/rmvl/rmath/union_find.hpp b/modules/rmath/include/rmvl/rmath/union_find.hpp deleted file mode 100644 index 27a6565c..00000000 --- a/modules/rmath/include/rmvl/rmath/union_find.hpp +++ /dev/null @@ -1,165 +0,0 @@ -/** - * @file union_find.hpp - * @author RoboMaster Vision Community - * @brief 并查集 - * @version 1.0 - * @date 2023-01-11 - * - * @copyright Copyright 2023 (c), RoboMaster Vision Community - * - */ - -#pragma once - -#include -#include -#include -#include - -namespace rm -{ - -//! @addtogroup union_find -//! @{ - -/** - * @brief 并查集 - * - * @tparam Tp 元素类型 - */ -template -class UnionFind -{ -public: - typedef Tp value_type; - typedef Tp *pointer; - typedef Tp &reference; - typedef const Tp *const_pointer; - typedef const Tp &const_reference; - typedef std::size_t size_type; - -private: - std::unordered_set _element_set; //!< 元素集合 - std::unordered_map _parent_map; //!< 父元素哈希表 - std::unordered_map _size_map; //!< 集合大小 - int _connected_component = 0; //!< 连通分量 - -public: - UnionFind(const UnionFind &) = delete; - UnionFind(UnionFind &&) = delete; - - /** - * @brief Construct a new Union Find Set object - * - * @tparam _InputIterator 迭代器类型 - * @param[in] first 起始迭代器 - * @param[in] last 终止迭代器 - */ - template - UnionFind(_InputIterator first, _InputIterator last) - { - try - { - for (; first != last; ++first) - { - _element_set.insert(*first); - _parent_map[*first] = *first; - _size_map[*first] = 1; - _connected_component++; - } - } - catch (...) - { - _element_set.clear(); - throw; - } - } - - /** - * @brief 两个元素是否在同一个集合 - * - * @param[in] val_a 元素 A - * @param[in] val_b 元素 B - * @return 是否在同一个集合 - */ - inline bool isSameSet(const_reference val_a, const_reference val_b) - { - // Sign up? - if (_element_set.find(val_a) == _element_set.end() || - _element_set.find(val_b) == _element_set.end()) - return false; - // Common representation element? - return findRep(val_a) == findRep(val_b); - } - - /** - * @brief 将两个元素所在集合合并 - * - * @param[in] val_a 元素 A - * @param[in] val_b 元素 B - */ - inline void unionSet(const_reference val_a, const_reference val_b) - { - // Sign up? - if (_element_set.find(val_a) == _element_set.end() || - _element_set.find(val_b) == _element_set.end()) - return; - // Common representation element? - auto a_rep = findRep(val_a); - auto b_rep = findRep(val_b); - if (a_rep == b_rep) - return; - // Mount samll set to large set. - auto large_set = _size_map[a_rep] >= _size_map[b_rep] ? a_rep : b_rep; - auto small_set = large_set == a_rep ? b_rep : a_rep; - _parent_map[small_set] = large_set; - _size_map[large_set] = _size_map[a_rep] + _size_map[b_rep]; - _size_map.erase(small_set); - _connected_component--; - } - - /** - * @brief 导出数据 - * - * @return Key: 集合代表元素,Value: 集合 - */ - inline std::unordered_map> exportData() - { - std::unordered_map> datas; - for (const auto &map_pair : _size_map) - datas[map_pair.first].reserve(map_pair.second); - for (const auto &element : _element_set) - datas[findRep(element)].emplace_back(element); - return datas; - } - - //! 获取连通分量 - inline int getConnectedComponent() { return _connected_component; } - -private: - /** - * @brief 寻找代表元素 - * - * @param[in] element 指定的元素 - * @return 集合的代表元素 - */ - value_type findRep(value_type element) - { - std::stack path; - while (element != _parent_map[element]) - { - path.push(element); - element = _parent_map[element]; - } - while (!path.empty()) - { - _parent_map[path.top()] = element; - path.pop(); - } - return element; - } -}; - -//! @} union_find - -} // namespace rm diff --git a/samples/camera/hik/CMakeLists.txt b/samples/camera/hik/CMakeLists.txt index 0c5b5b0c..4329c475 100644 --- a/samples/camera/hik/CMakeLists.txt +++ b/samples/camera/hik/CMakeLists.txt @@ -2,6 +2,8 @@ if(NOT BUILD_rmvl_hik_camera) return() endif() +find_package(OpenCV COMPONENTS highgui calib3d REQUIRED) + rmvl_add_exe( rmvl_hik_mono SOURCES sample_hik_mono.cpp @@ -27,4 +29,5 @@ rmvl_add_exe( rmvl_hik_manual_calib SOURCES sample_hik_manual_calib.cpp DEPENDS hik_camera + EXTERNAL ${OpenCV_LIBS} ) diff --git a/samples/camera/mv/CMakeLists.txt b/samples/camera/mv/CMakeLists.txt index b0c9a370..c4cfa3f8 100644 --- a/samples/camera/mv/CMakeLists.txt +++ b/samples/camera/mv/CMakeLists.txt @@ -2,6 +2,8 @@ if(NOT BUILD_rmvl_mv_camera) return() endif() +find_package(OpenCV COMPONENTS highgui calib3d REQUIRED) + rmvl_add_exe( rmvl_mv_mono SOURCES sample_mv_mono.cpp @@ -13,22 +15,26 @@ rmvl_add_exe( rmvl_mv_multi SOURCES sample_mv_multi.cpp DEPENDS mv_camera + EXTERNAL ${OpenCV_LIBS} ) rmvl_add_exe( rmvl_mv_writer SOURCES sample_mv_writer.cpp DEPENDS mv_camera + EXTERNAL ${OpenCV_LIBS} ) rmvl_add_exe( rmvl_mv_auto_calib SOURCES sample_mv_auto_calib.cpp DEPENDS mv_camera + EXTERNAL ${OpenCV_LIBS} ) rmvl_add_exe( rmvl_mv_manual_calib SOURCES sample_mv_manual_calib.cpp DEPENDS mv_camera + EXTERNAL ${OpenCV_LIBS} ) diff --git a/samples/detector/hik/CMakeLists.txt b/samples/detector/hik/CMakeLists.txt index cb012e7b..f2b3c308 100644 --- a/samples/detector/hik/CMakeLists.txt +++ b/samples/detector/hik/CMakeLists.txt @@ -2,11 +2,14 @@ if(NOT BUILD_rmvl_hik_camera OR NOT BUILD_rmvl_armor_detector) return() endif() +find_package(OpenCV COMPONENTS highgui REQUIRED) + if(HAVE_FILESYSTEM) rmvl_add_exe( rmvl_hik_armor_collection SOURCES sample_hik_armor_collection.cpp DEPENDS hik_camera armor_detector + EXTERNAL ${OpenCV_LIBS} ) endif() @@ -14,4 +17,5 @@ rmvl_add_exe( rmvl_hik_armor_size_classify SOURCES sample_hik_armor_size_classify.cpp DEPENDS hik_camera armor_detector + EXTERNAL ${OpenCV_LIBS} ) diff --git a/samples/detector/mv/CMakeLists.txt b/samples/detector/mv/CMakeLists.txt index c256edfb..89d69eaa 100644 --- a/samples/detector/mv/CMakeLists.txt +++ b/samples/detector/mv/CMakeLists.txt @@ -2,11 +2,14 @@ if(NOT BUILD_rmvl_mv_camera OR NOT BUILD_rmvl_armor_detector) return() endif() +find_package(OpenCV COMPONENTS highgui REQUIRED) + if(HAVE_FILESYSTEM) rmvl_add_exe( rmvl_mv_armor_collection SOURCES sample_mv_armor_collection.cpp DEPENDS mv_camera armor_detector + EXTERNAL ${OpenCV_LIBS} ) endif() @@ -14,4 +17,5 @@ rmvl_add_exe( rmvl_mv_armor_size_classify SOURCES sample_mv_armor_size_classify.cpp DEPENDS mv_camera armor_detector + EXTERNAL ${OpenCV_LIBS} )