From bd321fa4bbb431971aac21ca263a0e9f6079261a Mon Sep 17 00:00:00 2001 From: Paul Leroy Date: Thu, 18 Sep 2025 10:26:16 +0200 Subject: [PATCH] clean CMakeLists.txt + handle duplicates --- CMakeLists.txt | 114 ++++++++++++++++++++++------------------ include/G3PointAction.h | 4 +- src/G3PointAction.cpp | 30 ++++++++--- 3 files changed, 88 insertions(+), 60 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 77f51cc..a5cb1ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,12 +8,12 @@ option( PLUGIN_G3POINT "Install example plugin" OFF ) if ( PLUGIN_G3POINT ) project( G3PointPlugin ) - + AddPlugin( NAME ${PROJECT_NAME} ) target_sources(G3PointPlugin - PRIVATE - ui/WolmanCustomPlot.ui + PRIVATE + ui/WolmanCustomPlot.ui ) set(QG3POINT_PLUGIN_VERSION "0.6") @@ -22,36 +22,50 @@ target_sources(G3PointPlugin add_subdirectory( src ) add_subdirectory( ui ) - # target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) # for mlpack + # EIGEN + set( EIGEN_ROOT_DIR "" CACHE PATH "Eigen root (contains the Eigen directory)" ) + if ( NOT EIGEN_ROOT_DIR ) + message( SEND_ERROR "No Eigen root directory specified (EIGEN_ROOT_DIR)" ) + else() + message( STATUS "EIGEN_ROOT_DIR " ${EIGEN_ROOT_DIR} ) + endif() + + # BOOST + find_package(Boost REQUIRED) + message(STATUS "Boost_VERSION: ${Boost_VERSION}") + message(STATUS "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}") + + # OPEN3D + find_package( Open3D REQUIRED ) # Find installed Open3D, which exports Open3D::Open3D + message( "Open3D_DIR ${Open3D_DIR}" ) + if(CMAKE_BUILD_TYPE STREQUAL "Debug") + set( OPENCV_DEP_DLL_FILES + ${Open3D_DIR}/../bin/Open3D.dll + ${Open3D_DIR}/../bin/tbb12_debug.dll) + elseif(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") + set( OPENCV_DEP_DLL_FILES + ${Open3D_DIR}/../bin/Open3D.dll + ${Open3D_DIR}/../bin/tbb12.dll) + endif() + copy_files( "${OPENCV_DEP_DLL_FILES}" "${CLOUDCOMPARE_DEST_FOLDER}" 1) #mind the quotes! - target_include_directories( ${PROJECT_NAME} PRIVATE - C:/opt/eigen-3.4.0 - C:/Users/PaulLeroy/miniconda3/envs/env_4_CloudCompare/include - C:/opt/open3d-devel-windows-amd64-0.19.0/include - C:/opt/GeometricTools/GTE - C:/opt/boost_1_77_0 - ) - # may be needed for debug set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj") - #============ + target_include_directories( ${PROJECT_NAME} PRIVATE + ${GEOMETRIC_TOOLS_DIR}/GTE + ${EIGEN_ROOT_DIR} + ${Boost_INCLUDE_DIRS} + ) + target_link_libraries( ${PROJECT_NAME} Open3D::Open3D ) + # QCUSTOMPLOT target_link_libraries(${PROJECT_NAME} QCustomPlot Qt5::PrintSupport ) - # Find installed Open3D, which exports Open3D::Open3D - find_package( Open3D REQUIRED ) - target_link_libraries( ${PROJECT_NAME} Open3D::Open3D ) - - message( "Open3D_DIR ${Open3D_DIR}" ) - set( OPENCV_DEP_DLL_FILES - ${Open3D_DIR}/../bin/Open3D.dll - ${Open3D_DIR}/../bin/tbb12.dll - ) - copy_files( "${OPENCV_DEP_DLL_FILES}" "${CLOUDCOMPARE_DEST_FOLDER}" 1) #mind the quotes! + # Copy OpenGL shaders copy_files( "${CMAKE_CURRENT_SOURCE_DIR}/shaders/DrawGrains.vs" "${CLOUDCOMPARE_DEST_FOLDER}/shaders/G3Point" 1) #mind the quotes! copy_files( "${CMAKE_CURRENT_SOURCE_DIR}/shaders/DrawGrains.fs" "${CLOUDCOMPARE_DEST_FOLDER}/shaders/G3Point" 1) #mind the quotes! @@ -59,38 +73,38 @@ target_sources(G3PointPlugin # git commit hash # Get the current working branch execute_process( - COMMAND git rev-parse --abbrev-ref HEAD - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - OUTPUT_VARIABLE GIT_BRANCH_G3POINT - OUTPUT_STRIP_TRAILING_WHITESPACE) + COMMAND git rev-parse --abbrev-ref HEAD + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE GIT_BRANCH_G3POINT + OUTPUT_STRIP_TRAILING_WHITESPACE) # Get the latest commit hash execute_process( - COMMAND git rev-parse --short HEAD - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - OUTPUT_VARIABLE GIT_COMMIT_HASH_G3POINT - OUTPUT_STRIP_TRAILING_WHITESPACE) + COMMAND git rev-parse --short HEAD + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE GIT_COMMIT_HASH_G3POINT + OUTPUT_STRIP_TRAILING_WHITESPACE) # Get the latest commit hash execute_process( - COMMAND git describe - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - OUTPUT_VARIABLE GIT_TAG_G3POINT - OUTPUT_STRIP_TRAILING_WHITESPACE) + COMMAND git describe + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE GIT_TAG_G3POINT + OUTPUT_STRIP_TRAILING_WHITESPACE) # Get the current working branch execute_process( - COMMAND git rev-parse --abbrev-ref HEAD - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - OUTPUT_VARIABLE GIT_BRANCH_CC - OUTPUT_STRIP_TRAILING_WHITESPACE) + COMMAND git rev-parse --abbrev-ref HEAD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_BRANCH_CC + OUTPUT_STRIP_TRAILING_WHITESPACE) # Get the latest commit hash execute_process( - COMMAND git rev-parse --short HEAD - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - OUTPUT_VARIABLE GIT_COMMIT_HASH_CC - OUTPUT_STRIP_TRAILING_WHITESPACE) + COMMAND git rev-parse --short HEAD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_COMMIT_HASH_CC + OUTPUT_STRIP_TRAILING_WHITESPACE) message(${PROJECT_NAME} " " GIT_BRANCH_G3POINT " " ${GIT_BRANCH_G3POINT}) message(${PROJECT_NAME} " " GIT_COMMIT_HASH_G3POINT " " ${GIT_COMMIT_HASH_G3POINT}) @@ -100,12 +114,12 @@ target_sources(G3PointPlugin message(${PROJECT_NAME} " " QG3POINT_VERSION " " ${QG3POINT_PLUGIN_VERSION}) target_compile_definitions(${PROJECT_NAME} PRIVATE - GIT_BRANCH_CC="${GIT_BRANCH_CC}" - GIT_COMMMIT_HASH_CC="${GIT_COMMIT_HASH_CC}" - PUBLIC GIT_BRANCH_G3POINT="${GIT_BRANCH_G3POINT}" - GIT_COMMMIT_HASH_G3POINT="${GIT_COMMIT_HASH_G3POINT}" - GIT_TAG_G3POINT="${GIT_TAG_G3POINT}" - G3POINT_VERSION="${QG3POINT_PLUGIN_VERSION}" - ) + GIT_BRANCH_CC="${GIT_BRANCH_CC}" + GIT_COMMMIT_HASH_CC="${GIT_COMMIT_HASH_CC}" + PUBLIC GIT_BRANCH_G3POINT="${GIT_BRANCH_G3POINT}" + GIT_COMMMIT_HASH_G3POINT="${GIT_COMMIT_HASH_G3POINT}" + GIT_TAG_G3POINT="${GIT_TAG_G3POINT}" + G3POINT_VERSION="${QG3POINT_PLUGIN_VERSION}" + ) endif() diff --git a/include/G3PointAction.h b/include/G3PointAction.h index 78b04bc..e96d32e 100644 --- a/include/G3PointAction.h +++ b/include/G3PointAction.h @@ -63,9 +63,9 @@ private: bool updateLocalMaximumIndexes(); bool updateLabelsAndColors(); bool checkStacks(const std::vector>& stacks, int count); - void addToStackBraunWillett(int index, const Eigen::ArrayXi& delta, const Eigen::ArrayXi &Di, std::vector& stack, int local_maximum); + void addToStackBraunWillett(int index, const Eigen::ArrayXi& delta, const Eigen::ArrayXi& Di, std::vector& stack, int local_maximum); int segmentLabelsBraunWillett(); - void getNeighborsDistancesSlopes(unsigned index); + void getNeighborsDistancesSlopes(unsigned index, std::vector& duplicates); void computeNodeSurfaces(); bool computeNormalsAndOrientThemWithCloudCompare(); void orientNormals(const Eigen::Vector3d &sensorCenter); diff --git a/src/G3PointAction.cpp b/src/G3PointAction.cpp index c9f6b83..46b1d4a 100644 --- a/src/G3PointAction.cpp +++ b/src/G3PointAction.cpp @@ -1047,7 +1047,7 @@ void G3PointAction::fit() } void G3PointAction::exportResults() -{ +{ if (m_grainsAsEllipsoids) { m_grainsAsEllipsoids->exportResultsAsCloud(); @@ -1648,7 +1648,7 @@ int G3PointAction::segmentLabelsBraunWillett() return nLabels; } -void G3PointAction::getNeighborsDistancesSlopes(unsigned index) +void G3PointAction::getNeighborsDistancesSlopes(unsigned index, std::vector& duplicates) { const CCVector3* P = m_cloud->getPoint(index); @@ -1670,7 +1670,15 @@ void G3PointAction::getNeighborsDistancesSlopes(unsigned index) float distance = (*P - *neighbor).norm(); m_neighborsDistances(index, k) = distance; // compute the slope to the neighbor - m_neighborsSlopes(index, k) = (P->z - neighbor->z) / distance; + if (distance != 0) + { + m_neighborsSlopes(index, k) = (P->z - neighbor->z) / distance; + } + else + { + m_neighborsSlopes(index, k) = 0.; // it is possible to have duplicates in the cloud + duplicates[index] = 1; + } } } } @@ -1810,7 +1818,7 @@ bool G3PointAction::computeNormalsWithOpen3D() } bool G3PointAction::queryNeighbors(ccPointCloud* cloud, ccMainAppInterface* appInterface, bool useParallelStrategy) -{ +{ QString errorStr; ccProgressDialog progressDlg(true, appInterface->getMainWindow()); @@ -1838,8 +1846,8 @@ bool G3PointAction::queryNeighbors(ccPointCloud* cloud, ccMainAppInterface* appI size_t nPoints = m_cloud->size(); CCCoreLib::DgmOctree::NearestNeighboursSearchStruct nNSS; - std::vector pointsIndexes; - pointsIndexes.resize(nPoints); + std::vector pointsIndexes(nPoints); + std::vector duplicates(nPoints, 0); if (useParallelStrategy) { @@ -1850,17 +1858,23 @@ bool G3PointAction::queryNeighbors(ccPointCloud* cloud, ccMainAppInterface* appI int threadCount = std::max(1, ccQtHelpers::GetMaxThreadCount() - 2); std::cout << "[query_neighbor] parallel strategy, thread count " << threadCount << std::endl; QThreadPool::globalInstance()->setMaxThreadCount(threadCount); - QtConcurrent::blockingMap(pointsIndexes, [=](int index){getNeighborsDistancesSlopes(index);}); + QtConcurrent::blockingMap(pointsIndexes, [&](int index){getNeighborsDistancesSlopes(index, duplicates);}); } else { //manually call the static per-point method! for (unsigned i = 0; i < nPoints; ++i) { - getNeighborsDistancesSlopes(i); + getNeighborsDistancesSlopes(i, duplicates); } } + auto trueCount = std::count(duplicates.begin(), duplicates.end(), 1); + if (trueCount) + { + ccLog::Warning("[G3Point] You have duplicates (" + QString::number(trueCount) + "), the algorithm will continue but you may think of cleaning your cloud."); + } + return true; }