diff --git a/Algo/DetectHole/CMakeLists.txt b/Algo/DetectHole/CMakeLists.txt index 3e4c5ff..57f6d49 100644 --- a/Algo/DetectHole/CMakeLists.txt +++ b/Algo/DetectHole/CMakeLists.txt @@ -97,29 +97,45 @@ set(HOLE_DETECTION_SOURCES src/PlaneSegmentation.cpp ) -set(HOLE_DETECTION_HEADERS - src/HoleDetection.h - src/GeometricFitting.h - src/HoleDetectionParams.h - src/ErrorCodes.h - src/PlaneSegmentation.h - include/VZNL_Types.h -) +set(HOLE_DETECTION_HEADERS + include/HoleDetection.h + src/GeometricFitting.h + include/HoleDetectionParams.h + include/ErrorCodes.h + src/PlaneSegmentation.h + include/VZNL_Types.h +) + +set(HOLE_DETECTION_EXPORT_HEADERS + include/HoleDetection.h + include/HoleDetectionParams.h + include/ErrorCodes.h + include/VZNL_Types.h +) # Create library as SHARED (dynamic library) -add_library(HoleDetectionLib SHARED - ${HOLE_DETECTION_SOURCES} - ${HOLE_DETECTION_HEADERS} -) +add_library(HoleDetectionLib SHARED + ${HOLE_DETECTION_SOURCES} + ${HOLE_DETECTION_HEADERS} +) + +target_include_directories(HoleDetectionLib + PUBLIC + $ + $ + PRIVATE + ${CMAKE_SOURCE_DIR}/src + ${EIGEN3_INCLUDE_DIR} +) # Set library properties -set_target_properties(HoleDetectionLib PROPERTIES - VERSION ${PROJECT_VERSION} - SOVERSION 1 - PUBLIC_HEADER "${HOLE_DETECTION_HEADERS}" - CXX_VISIBILITY_PRESET hidden - VISIBILITY_INLINES_HIDDEN ON -) +set_target_properties(HoleDetectionLib PROPERTIES + VERSION ${PROJECT_VERSION} + SOVERSION 1 + PUBLIC_HEADER "${HOLE_DETECTION_EXPORT_HEADERS}" + CXX_VISIBILITY_PRESET hidden + VISIBILITY_INLINES_HIDDEN ON +) # Set UTF-8 encoding for MSVC if(MSVC) @@ -141,12 +157,12 @@ add_custom_command(TARGET HoleDetectionLib POST_BUILD ) # Copy each header file -foreach(header ${HOLE_DETECTION_HEADERS}) - get_filename_component(header_name ${header} NAME) - add_custom_command(TARGET HoleDetectionLib POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different - "${CMAKE_SOURCE_DIR}/${header}" - "${EXPORT_INCLUDE_DIR}/${header_name}" +foreach(header ${HOLE_DETECTION_EXPORT_HEADERS}) + get_filename_component(header_name ${header} NAME) + add_custom_command(TARGET HoleDetectionLib POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + "${CMAKE_SOURCE_DIR}/${header}" + "${EXPORT_INCLUDE_DIR}/${header_name}" COMMENT "Copying ${header_name} to Export/include" ) endforeach() @@ -221,9 +237,9 @@ install(TARGETS HoleDetectionLib PUBLIC_HEADER DESTINATION include/DetectHole ) -install(FILES ${HOLE_DETECTION_HEADERS} - DESTINATION include/DetectHole -) +install(FILES ${HOLE_DETECTION_EXPORT_HEADERS} + DESTINATION include/DetectHole +) # Enable testing enable_testing() diff --git a/Algo/DetectHole/PointCloudUtils/CMakeLists.txt b/Algo/DetectHole/PointCloudUtils/CMakeLists.txt index 06cfb2c..d503aa6 100644 --- a/Algo/DetectHole/PointCloudUtils/CMakeLists.txt +++ b/Algo/DetectHole/PointCloudUtils/CMakeLists.txt @@ -16,12 +16,11 @@ if(MSVC) target_compile_options(PointCloudUtils PRIVATE /utf-8) endif() -# Include directories -target_include_directories(PointCloudUtils PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/include - ${CMAKE_SOURCE_DIR}/include - ${CMAKE_SOURCE_DIR}/src -) +# Include directories +target_include_directories(PointCloudUtils PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${CMAKE_SOURCE_DIR}/include +) # Installation install(TARGETS PointCloudUtils diff --git a/Algo/DetectHole/PointCloudUtils/include/PointCloudLoader.h b/Algo/DetectHole/PointCloudUtils/include/PointCloudLoader.h index adfe7b4..ecb9e72 100644 --- a/Algo/DetectHole/PointCloudUtils/include/PointCloudLoader.h +++ b/Algo/DetectHole/PointCloudUtils/include/PointCloudLoader.h @@ -1,8 +1,8 @@ #ifndef POINT_CLOUD_LOADER_H #define POINT_CLOUD_LOADER_H -#include "../../include/VZNL_Types.h" -#include "../../src/ErrorCodes.h" +#include "VZNL_Types.h" +#include "ErrorCodes.h" /** * @brief Load point cloud from TXT file diff --git a/Algo/DetectHole/build.bat b/Algo/DetectHole/build.bat index 783a7c8..ce95aff 100644 --- a/Algo/DetectHole/build.bat +++ b/Algo/DetectHole/build.bat @@ -195,11 +195,10 @@ if exist build\%BUILD_TYPE%\HoleDetectionLib.pdb ( ) REM 复制头文件(仅复制库的公共 API 头文件) -copy /Y src\HoleDetection.h Export\include\ -copy /Y src\GeometricFitting.h Export\include\ -copy /Y src\HoleDetectionParams.h Export\include\ -copy /Y src\ErrorCodes.h Export\include\ -copy /Y include\VZNL_Types.h Export\include\ +if exist include\HoleDetection.h copy /Y include\HoleDetection.h Export\include\ +if exist include\HoleDetectionParams.h copy /Y include\HoleDetectionParams.h Export\include\ +if exist include\ErrorCodes.h copy /Y include\ErrorCodes.h Export\include\ +if exist include\VZNL_Types.h copy /Y include\VZNL_Types.h Export\include\ echo 已复制: 头文件 -^> Export\include\ echo. diff --git a/Algo/DetectHole/examples/visualization_demo/VisualizationDemo.cpp b/Algo/DetectHole/examples/visualization_demo/VisualizationDemo.cpp index 7f6cc58..1a3733e 100644 --- a/Algo/DetectHole/examples/visualization_demo/VisualizationDemo.cpp +++ b/Algo/DetectHole/examples/visualization_demo/VisualizationDemo.cpp @@ -597,11 +597,15 @@ int main(int argc, char* argv[]) { // Set up detection parameters (using defaults from constructor) SHoleDetectionParams detectionParams; detectionParams.minRadius = 0.5f; - detectionParams.angleThresholdPos = 50; - detectionParams.angleThresholdNeg = -50; SHoleFilterParams filterParams; std::cout << "=== Hole Detection Visualization Demo ===" << std::endl; + const char* lpszVer = GetAlgorithmVersion(); + + const char* lpszName = GetAlgorithmName(); + + std::cout << "Algorithm: " << (lpszName ? lpszName : "Unknown") << "version: " << (lpszVer? lpszVer:"Unknown") << std::endl; + // Check if batch directory mode if (batchDir) { std::cout << "Mode: Batch Directory Processing" << std::endl; diff --git a/Algo/DetectHole/src/ErrorCodes.h b/Algo/DetectHole/include/ErrorCodes.h similarity index 100% rename from Algo/DetectHole/src/ErrorCodes.h rename to Algo/DetectHole/include/ErrorCodes.h diff --git a/Algo/DetectHole/src/HoleDetection.h b/Algo/DetectHole/include/HoleDetection.h similarity index 92% rename from Algo/DetectHole/src/HoleDetection.h rename to Algo/DetectHole/include/HoleDetection.h index a294ba8..de92aa2 100644 --- a/Algo/DetectHole/src/HoleDetection.h +++ b/Algo/DetectHole/include/HoleDetection.h @@ -3,7 +3,7 @@ #include "HoleDetectionParams.h" #include "ErrorCodes.h" -#include "../include/VZNL_Types.h" +#include "VZNL_Types.h" // Export macro for shared library #ifdef _WIN32 @@ -12,13 +12,13 @@ #else #define HOLE_DETECTION_API __declspec(dllimport) #endif -#else - #ifdef HOLE_DETECTION_EXPORTS - #define HOLE_DETECTION_API __attribute__((visibility("default"))) - #else - #define HOLE_DETECTION_API - #endif -#endif +#else + #ifdef HOLE_DETECTION_EXPORTS + #define HOLE_DETECTION_API __attribute__((visibility("default"))) + #else + #define HOLE_DETECTION_API + #endif +#endif /** * @brief Boundary point with grid location (for debug callbacks) @@ -231,21 +231,33 @@ struct SHoleDetectionDebugCallbacks { * @post If return value is 0, result contains detected holes * @post Caller must free result->holes using delete[] */ -HOLE_DETECTION_API int DetectMultipleHoles( - const SVzNLPointXYZ* points, - int rows, - int cols, - const SHoleDetectionParams& detectionParams, +HOLE_DETECTION_API int DetectMultipleHoles( + const SVzNLPointXYZ* points, + int rows, + int cols, + const SHoleDetectionParams& detectionParams, const SHoleFilterParams& filterParams, - SMultiHoleResult* result, - const SHoleDetectionDebugCallbacks* debugCallbacks = nullptr -); - -/** - * @brief Print detection results to console in a formatted way - * - * @param [in] result Detection result structure - * @param [in] verbose If true, print detailed information for each hole + SMultiHoleResult* result, + const SHoleDetectionDebugCallbacks* debugCallbacks = nullptr +); + +/** + * @brief Get algorithm name and version information + * + * Returned pointers refer to internal static strings and must not be freed + * or modified by the caller. Either output parameter can be nullptr. + * + * @param [out] algorithmName Output algorithm name string + * @param [out] algorithmVersion Output algorithm version string + */ +HOLE_DETECTION_API const char* GetAlgorithmVersion(); +HOLE_DETECTION_API const char* GetAlgorithmName(); + +/** + * @brief Print detection results to console in a formatted way + * + * @param [in] result Detection result structure + * @param [in] verbose If true, print detailed information for each hole */ HOLE_DETECTION_API void PrintDetectionResults(const SMultiHoleResult& result, bool verbose = true); diff --git a/Algo/DetectHole/src/HoleDetectionParams.h b/Algo/DetectHole/include/HoleDetectionParams.h similarity index 97% rename from Algo/DetectHole/src/HoleDetectionParams.h rename to Algo/DetectHole/include/HoleDetectionParams.h index 66d674a..b5bde47 100644 --- a/Algo/DetectHole/src/HoleDetectionParams.h +++ b/Algo/DetectHole/include/HoleDetectionParams.h @@ -2,15 +2,15 @@ #define HOLE_DETECTION_PARAMS_H #include -#include "../include/VZNL_Types.h" // 使用 VZNL_Types.h 中定义的类型 +#include "VZNL_Types.h" // 使用 VZNL_Types.h 中定义的类型 /** * @brief 孔洞检测算法的检测参数 */ struct SHoleDetectionParams { // 凹坑检测参数 - float angleThresholdPos; // 正角度阈值,单位:度(默认值:30.0) - float angleThresholdNeg; // 负角度阈值,单位:度(默认值:-30.0) + float angleThresholdPos; // 正角度阈值,单位:度(默认值:50.0) + float angleThresholdNeg; // 负角度阈值,单位:度(默认值:-50.0) float angleSearchDistance; // Method1 前后搜索距离 A,单位:mm float minPitDepth; // 最小凹坑深度,单位:mm(默认值:1.0) @@ -39,8 +39,8 @@ struct SHoleDetectionParams { // 构造函数,设置默认值 SHoleDetectionParams() - : angleThresholdPos(30.0f) - , angleThresholdNeg(-30.0f) + : angleThresholdPos(50.0f) + , angleThresholdNeg(-50.0f) , angleSearchDistance(2.0f) , minPitDepth(1.0f) , minRadius(2.0f) diff --git a/Algo/DetectHole/src/HoleDetection.cpp b/Algo/DetectHole/src/HoleDetection.cpp index 221d58a..02aa27e 100644 --- a/Algo/DetectHole/src/HoleDetection.cpp +++ b/Algo/DetectHole/src/HoleDetection.cpp @@ -11,6 +11,9 @@ namespace { + const static char* g_algo_name = "DetectHole"; + const static char* g_algo_ver = "1.0.0"; + void PrintHoleResult(const SHoleResult& hole, int index) { std::cout << "\nHole #" << index << ":" << std::endl; @@ -368,6 +371,14 @@ int DetectMultipleHoles( return HD_SUCCESS; } +const char* GetAlgorithmVersion() { + return g_algo_ver; +} + +const char* GetAlgorithmName() { + return g_algo_name; +} + void PrintDetectionResults(const SMultiHoleResult& result, bool verbose) { std::cout << "\n========== Detection Results ==========" << std::endl; std::cout << "Total candidates: " << result.totalCandidates << std::endl;