Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bd321fa4bb |
+65
-64
@@ -8,13 +8,13 @@ option( PLUGIN_G3POINT "Install example plugin" OFF )
|
||||
|
||||
if ( PLUGIN_G3POINT )
|
||||
project( G3PointPlugin )
|
||||
|
||||
|
||||
AddPlugin( NAME ${PROJECT_NAME} )
|
||||
|
||||
target_sources(G3PointPlugin
|
||||
PRIVATE
|
||||
ui/WolmanCustomPlot.ui
|
||||
)
|
||||
target_sources(G3PointPlugin
|
||||
PRIVATE
|
||||
ui/WolmanCustomPlot.ui
|
||||
)
|
||||
|
||||
set(QG3POINT_PLUGIN_VERSION "0.6")
|
||||
|
||||
@@ -22,18 +22,6 @@ if ( PLUGIN_G3POINT )
|
||||
add_subdirectory( src )
|
||||
add_subdirectory( ui )
|
||||
|
||||
# target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) # for mlpack
|
||||
|
||||
# may be needed for debug
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj")
|
||||
|
||||
#============
|
||||
# QCUSTOMPLOT
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
QCustomPlot
|
||||
Qt5::PrintSupport
|
||||
)
|
||||
|
||||
# EIGEN
|
||||
set( EIGEN_ROOT_DIR "" CACHE PATH "Eigen root (contains the Eigen directory)" )
|
||||
if ( NOT EIGEN_ROOT_DIR )
|
||||
@@ -42,68 +30,81 @@ if ( PLUGIN_G3POINT )
|
||||
message( STATUS "EIGEN_ROOT_DIR " ${EIGEN_ROOT_DIR} )
|
||||
endif()
|
||||
|
||||
# OPEN3D
|
||||
option(USE_OPEN3D_WITH_G3POINT "Enable the use of Open3D with G3Point" OFF)
|
||||
if (USE_OPEN3D_WITH_G3POINT)
|
||||
find_package( Open3D REQUIRED ) # Find installed Open3D, which exports Open3D::Open3D
|
||||
target_link_libraries( ${PROJECT_NAME} Open3D::Open3D )
|
||||
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()
|
||||
message( "Open3D_DIR ${Open3D_DIR}" )
|
||||
copy_files( "${OPENCV_DEP_DLL_FILES}" "${CLOUDCOMPARE_DEST_FOLDER}" 1) #mind the quotes!
|
||||
endif()
|
||||
# BOOST
|
||||
find_package(Boost REQUIRED)
|
||||
message(STATUS "Boost_VERSION: ${Boost_VERSION}")
|
||||
message(STATUS "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
|
||||
|
||||
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!
|
||||
# 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!
|
||||
|
||||
# may be needed for debug
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj")
|
||||
|
||||
target_include_directories( ${PROJECT_NAME} PRIVATE
|
||||
../../../../libs/qCC_db/extern/CCCoreLib/extern/nanoflann/include
|
||||
${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
|
||||
)
|
||||
|
||||
# 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!
|
||||
|
||||
#================
|
||||
# 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})
|
||||
@@ -113,12 +114,12 @@ if ( PLUGIN_G3POINT )
|
||||
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()
|
||||
|
||||
+6
-45
@@ -1,27 +1,24 @@
|
||||
#include "Eigen/Dense"
|
||||
#include <nanoflann.hpp>
|
||||
|
||||
// qCC_db
|
||||
#include <ccOctree.h>
|
||||
#include <ccScalarField.h>
|
||||
#include <ccPointCloud.h>
|
||||
|
||||
// CCCoreLib
|
||||
#include <DgmOctree.h>
|
||||
#include <Neighbourhood.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include <G3PointDialog.h>
|
||||
|
||||
#include <GrainsAsEllipsoids.h>
|
||||
|
||||
#include <AnglesCustomPlot.h>
|
||||
|
||||
#include <G3PointPlots.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
class ccMainAppInterface;
|
||||
class ccPointCloud;
|
||||
|
||||
namespace G3Point
|
||||
{
|
||||
@@ -56,38 +53,6 @@ public:
|
||||
|
||||
template<typename T> static bool EigenArrayToFile(QString name, T array);
|
||||
|
||||
|
||||
// A small adaptor to let nanoflann access ccPointCloud data
|
||||
struct CloudAdaptor
|
||||
{
|
||||
const ccPointCloud* cloud;
|
||||
|
||||
CloudAdaptor(const ccPointCloud* c) : cloud(c) {}
|
||||
|
||||
// Must return the number of data points
|
||||
inline size_t kdtree_get_point_count() const { return cloud->size(); }
|
||||
|
||||
// Returns the dim'th component of the idx'th point
|
||||
inline float kdtree_get_pt(const size_t idx, int dim) const
|
||||
{
|
||||
if (dim == 0)
|
||||
return cloud->getPoint(static_cast<unsigned>(idx))->x;
|
||||
else if (dim == 1)
|
||||
return cloud->getPoint(static_cast<unsigned>(idx))->y;
|
||||
else
|
||||
return cloud->getPoint(static_cast<unsigned>(idx))->z;
|
||||
}
|
||||
|
||||
// Optional bounding-box computation: return false to default to a standard bbox computation loop.
|
||||
template<class BBOX>
|
||||
bool kdtree_get_bbox(BBOX&) const { return false; }
|
||||
};
|
||||
|
||||
// Typedef for a 3D KD-tree index
|
||||
using KDTree = nanoflann::KDTreeSingleIndexAdaptor<nanoflann::L2_Simple_Adaptor<float, CloudAdaptor>,
|
||||
CloudAdaptor,
|
||||
3 /* dim */>;
|
||||
|
||||
private:
|
||||
bool sfConvertToRandomRGB(const ccHObject::Container &selectedEntities, QWidget* parent);
|
||||
void addToStack(int index, const Eigen::ArrayXi& n_donors, const Eigen::ArrayXXi& donors, std::vector<int>& stack);
|
||||
@@ -98,17 +63,13 @@ private:
|
||||
bool updateLocalMaximumIndexes();
|
||||
bool updateLabelsAndColors();
|
||||
bool checkStacks(const std::vector<std::vector<int>>& stacks, int count);
|
||||
void addToStackBraunWillett(int index, const Eigen::ArrayXi& delta, const Eigen::ArrayXi &Di, std::vector<int>& stack, int local_maximum);
|
||||
void addToStackBraunWillett(int index, const Eigen::ArrayXi& delta, const Eigen::ArrayXi& Di, std::vector<int>& stack, int local_maximum);
|
||||
int segmentLabelsBraunWillett();
|
||||
void getNeighborsDistancesSlopes(unsigned index);
|
||||
void getNeighborsDistancesSlopes(unsigned index, std::vector<char>& duplicates);
|
||||
void computeNodeSurfaces();
|
||||
bool computeNormalsAndOrientThemWithCloudCompare();
|
||||
void orientNormals(const Eigen::Vector3d &sensorCenter);
|
||||
bool computeNormalsWithOpen3D();
|
||||
bool findNearestNeighborsNanoFlann(const unsigned int globalIndex, CCCoreLib::ReferenceCloud *points, const KDTree *kdTree);
|
||||
bool computeNormWithFlann(unsigned int index, NormsTableType* theNorms, const KDTree *kdTree);
|
||||
bool computeNormalsWithCloudCompare();
|
||||
bool computeNormals();
|
||||
bool queryNeighbors(ccPointCloud* cloud, ccMainAppInterface* appInterface, bool useParallelStrategy=true);
|
||||
void init();
|
||||
void showDlg();
|
||||
|
||||
@@ -15,6 +15,22 @@
|
||||
//# #
|
||||
//##########################################################################
|
||||
|
||||
// First:
|
||||
// Replace all occurrences of 'G3PointPlugin' by your own plugin class name in this file.
|
||||
// This includes the resource path to info.json in the constructor.
|
||||
|
||||
// Second:
|
||||
// Open G3PointPlugin.qrc, change the "prefix" and the icon filename for your plugin.
|
||||
// Change the name of the file to <yourPluginName>.qrc
|
||||
|
||||
// Third:
|
||||
// Open the info.json file and fill in the information about the plugin.
|
||||
// "type" should be one of: "Standard", "GL", or "I/O" (required)
|
||||
// "name" is the name of the plugin (required)
|
||||
// "icon" is the Qt resource path to the plugin's icon (from the .qrc file)
|
||||
// "description" is used as a tootip if the plugin has actions and is displayed in the plugin dialog
|
||||
// "authors", "maintainers", and "references" show up in the plugin dialog as well
|
||||
|
||||
#include <QtGui>
|
||||
|
||||
#include "G3Point.h"
|
||||
|
||||
+37
-192
@@ -1,6 +1,4 @@
|
||||
#include "G3PointAction.h"
|
||||
#include "DgmOctreeReferenceCloud.h"
|
||||
#include "Neighbourhood.h"
|
||||
|
||||
// CCPluginAPI
|
||||
#include <ccMainAppInterface.h>
|
||||
@@ -35,9 +33,7 @@
|
||||
#include <random>
|
||||
|
||||
// Open3D
|
||||
#ifdef USE_OPEN3D_WITH_G3POINT
|
||||
#include <open3d/geometry/PointCloud.h>
|
||||
#endif
|
||||
|
||||
// Eigen
|
||||
#include <Eigen/Geometry>
|
||||
@@ -373,7 +369,7 @@ Eigen::ArrayXXd G3PointAction::computeMeanAngleBetweenNormalsAtBorders()
|
||||
Eigen::ArrayXXi duplicated_labels(m_cloud->size(), m_kNN);
|
||||
for (int n = 0; n < m_kNN; n++)
|
||||
{
|
||||
duplicated_labels(Eigen::placeholders::all, n) = m_labels;
|
||||
duplicated_labels(Eigen::all, n) = m_labels;
|
||||
}
|
||||
Eigen::ArrayXXi labels_of_neighbors(m_cloud->size(), m_kNN);
|
||||
for (int index = 0; index < static_cast<int>(m_cloud->size()); index++)
|
||||
@@ -407,12 +403,12 @@ Eigen::ArrayXXd G3PointAction::computeMeanAngleBetweenNormalsAtBorders()
|
||||
|
||||
for (auto i : indborder)
|
||||
{
|
||||
auto neighbors = m_neighborsIndexes(i, Eigen::placeholders::all); // indexes of the neighbors of i
|
||||
Eigen::Vector3d N1(m_normals(i, Eigen::placeholders::all)); // normal at i
|
||||
auto neighbors = m_neighborsIndexes(i, Eigen::all); // indexes of the neighbors of i
|
||||
Eigen::Vector3d N1(m_normals(i, Eigen::all)); // normal at i
|
||||
for (auto j : neighbors)
|
||||
{
|
||||
// Take the normals vector for i and j
|
||||
Eigen::Vector3d N2(m_normals(j, Eigen::placeholders::all)); // normal at j
|
||||
Eigen::Vector3d N2(m_normals(j, Eigen::all)); // normal at j
|
||||
double angle = angleRot2VecMat(N1, N2);
|
||||
if ((m_labels(i) != -1) && (m_labels(j) != -1)) // points which belong to the discarded grains have the -1 label
|
||||
{
|
||||
@@ -1051,7 +1047,7 @@ void G3PointAction::fit()
|
||||
}
|
||||
|
||||
void G3PointAction::exportResults()
|
||||
{
|
||||
{
|
||||
if (m_grainsAsEllipsoids)
|
||||
{
|
||||
m_grainsAsEllipsoids->exportResultsAsCloud();
|
||||
@@ -1267,21 +1263,21 @@ bool G3PointAction::wolman()
|
||||
|
||||
Eigen::ArrayXXf dq(n_iter, 3);
|
||||
Eigen::ArrayXf d_sample = d[0];
|
||||
dq(0, Eigen::placeholders::all) << quant(d[0], 0.1), quant(d[0], 0.5), quant(d[0], 0.9);
|
||||
dq(0, Eigen::all) << quant(d[0], 0.1), quant(d[0], 0.5), quant(d[0], 0.9);
|
||||
for (int i = 1; i < n_iter; i++)
|
||||
{
|
||||
Eigen::ArrayXf tmp(d_sample.size() + d[i].size());
|
||||
tmp << d_sample, d[i];
|
||||
d_sample = tmp;
|
||||
dq(i, Eigen::placeholders::all) << quant(d[i], 0.1), quant(d[i], 0.5), quant(d[i], 0.9);
|
||||
dq(i, Eigen::all) << quant(d[i], 0.1), quant(d[i], 0.5), quant(d[i], 0.9);
|
||||
}
|
||||
|
||||
// std::cout << "d_sample " << d_sample << std::endl;
|
||||
|
||||
// compute standard deviation
|
||||
Eigen::Array3d edq {std_dev(dq(Eigen::placeholders::all, 0)),
|
||||
std_dev(dq(Eigen::placeholders::all, 1)),
|
||||
std_dev(dq(Eigen::placeholders::all, 2))};
|
||||
Eigen::Array3d edq {std_dev(dq(Eigen::all, 0)),
|
||||
std_dev(dq(Eigen::all, 1)),
|
||||
std_dev(dq(Eigen::all, 2))};
|
||||
Eigen::Array3d dq_final {quant(d_sample, 0.1),
|
||||
quant(d_sample, 0.5),
|
||||
quant(d_sample, 0.9)};
|
||||
@@ -1434,11 +1430,11 @@ bool G3PointAction::cleanLabels()
|
||||
Eigen::RowVector3d centroid = points.colwise().mean();
|
||||
points.rowwise() -= centroid;
|
||||
// SVD decomposition A = U S V∗
|
||||
s(k, Eigen::placeholders::all) = points.jacobiSvd().singularValues();
|
||||
s(k, Eigen::all) = points.jacobiSvd().singularValues();
|
||||
}
|
||||
// filtering condition: (l2 / l0 > min_flatness) or (l1 / l0 > 2 * min_flatness)
|
||||
Xb condition = (s(Eigen::placeholders::all, 2) / s(Eigen::placeholders::all, 0) > m_minFlatness)
|
||||
|| (s(Eigen::placeholders::all, 1) / s(Eigen::placeholders::all, 0) > 2. * m_minFlatness);
|
||||
Xb condition = (s(Eigen::all, 2) / s(Eigen::all, 0) > m_minFlatness)
|
||||
|| (s(Eigen::all, 1) / s(Eigen::all, 0) > 2. * m_minFlatness);
|
||||
size_t numberOfGrainsToKeep = condition.count();
|
||||
if (numberOfGrainsToKeep == m_stacks.size())
|
||||
{
|
||||
@@ -1652,7 +1648,7 @@ int G3PointAction::segmentLabelsBraunWillett()
|
||||
return nLabels;
|
||||
}
|
||||
|
||||
void G3PointAction::getNeighborsDistancesSlopes(unsigned index)
|
||||
void G3PointAction::getNeighborsDistancesSlopes(unsigned index, std::vector<char>& duplicates)
|
||||
{
|
||||
const CCVector3* P = m_cloud->getPoint(index);
|
||||
|
||||
@@ -1674,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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1746,7 +1750,7 @@ void G3PointAction::orientNormals(const Eigen::Vector3d& sensorCenter)
|
||||
{
|
||||
const CCVector3 *point = m_cloud->getPoint(i);
|
||||
Eigen::Vector3d P1 = sensorCenter - Eigen::Vector3d(point->x, point->y, point->z);
|
||||
Eigen::Vector3d P2 = m_normals(i, Eigen::placeholders::all);
|
||||
Eigen::Vector3d P2 = m_normals(i, Eigen::all);
|
||||
double angle = atan2(P1.cross(P2).norm(), P1.dot(P2));
|
||||
if ((angle < - M_PI / 2) || (angle > M_PI / 2))
|
||||
{
|
||||
@@ -1759,7 +1763,6 @@ void G3PointAction::orientNormals(const Eigen::Vector3d& sensorCenter)
|
||||
|
||||
bool G3PointAction::computeNormalsWithOpen3D()
|
||||
{
|
||||
#ifdef USE_OPEN3D_WITH_G3POINT
|
||||
// create an open3D point cloud from the original point cloud
|
||||
std::vector<Eigen::Vector3d> points(m_cloud->size());
|
||||
for (int index =0; index < points.size(); index++) // copy all points
|
||||
@@ -1812,174 +1815,10 @@ bool G3PointAction::computeNormalsWithOpen3D()
|
||||
}
|
||||
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool G3PointAction::findNearestNeighborsNanoFlann(const unsigned globalIndex,
|
||||
CCCoreLib::ReferenceCloud* points,
|
||||
const KDTree* kdTree)
|
||||
{
|
||||
// Prepare query
|
||||
const CCVector3* Q = m_cloud->getPoint(globalIndex);
|
||||
float query[3] = { Q->x, Q->y, Q->z };
|
||||
|
||||
std::vector<size_t> retIndexes(m_kNN);
|
||||
std::vector<float> outDistsSqr(m_kNN);
|
||||
|
||||
// Perform search
|
||||
nanoflann::KNNResultSet<float> resultSet(m_kNN);
|
||||
resultSet.init(&retIndexes[0], &outDistsSqr[0]);
|
||||
if(kdTree->findNeighbors(resultSet, &query[0]))
|
||||
{
|
||||
points->resize(m_kNN);
|
||||
for (int i = 0; i < m_kNN; ++i)
|
||||
{
|
||||
points->setPointIndex(i, retIndexes[i]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool G3PointAction::computeNormWithFlann(unsigned index,
|
||||
NormsTableType* theNorms,
|
||||
const G3PointAction::KDTree* kdTree)
|
||||
{
|
||||
CCVector3 N;
|
||||
|
||||
QScopedPointer<CCCoreLib::ReferenceCloud> points(new CCCoreLib::ReferenceCloud(m_cloud));
|
||||
if(findNearestNeighborsNanoFlann(index, points.data(), kdTree))
|
||||
{
|
||||
CCCoreLib::Neighbourhood neighbourhood(points.data());
|
||||
N = *neighbourhood.getLSPlaneNormal();
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
theNorms->setValue(index, N);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool G3PointAction::computeNormalsWithCloudCompare()
|
||||
{
|
||||
unsigned pointCount = m_cloud->size();
|
||||
|
||||
if (!m_cloud || m_cloud->size() == 0)
|
||||
{
|
||||
ccLog::Error("Invalid cloud.");
|
||||
return false;
|
||||
}
|
||||
|
||||
CloudAdaptor adaptor(m_cloud);
|
||||
|
||||
// Build KD-tree (parameter: number of leaf nodes to inspect per query)
|
||||
|
||||
size_t leaf_max_size = 10;
|
||||
nanoflann::KDTreeSingleIndexAdaptorFlags flags = nanoflann::KDTreeSingleIndexAdaptorFlags::None;
|
||||
unsigned int n_thread_build = 0; // 0 => nanoflann automatically determines the number of threads to use
|
||||
|
||||
nanoflann::KDTreeSingleIndexAdaptorParams params(leaf_max_size, flags, n_thread_build);
|
||||
QSharedPointer<KDTree> m_kdTree(new KDTree(3, adaptor, params));
|
||||
m_kdTree->buildIndex();
|
||||
|
||||
// we instantiate 3D normal vectors
|
||||
QSharedPointer<NormsTableType> theNorms(new NormsTableType);
|
||||
QScopedPointer<NormsIndexesTableType> normsIndexes(new NormsIndexesTableType);
|
||||
static const CCVector3 blankN(0, 0, 0);
|
||||
if (!theNorms->resizeSafe(pointCount, true, &blankN))
|
||||
{
|
||||
normsIndexes->resize(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
ccLog::Print("[computeNormalsWithCloudCompare]");
|
||||
#ifdef QT_DEBUG
|
||||
//manually call the static per-point method!
|
||||
for (unsigned index = 0; index < pointCount; ++index)
|
||||
{
|
||||
computeNormWithFlann(index, theNorms.data(), m_kNN, m_kdTree.data(), m_cloud);
|
||||
}
|
||||
#else
|
||||
std::vector<unsigned> pointsIndexes;
|
||||
pointsIndexes.resize(pointCount);
|
||||
for (unsigned i = 0; i < pointCount; ++i)
|
||||
{
|
||||
pointsIndexes[i] = i;
|
||||
}
|
||||
int threadCount = std::max(1, ccQtHelpers::GetMaxThreadCount() - 2);
|
||||
ccLog::Print("[computeNormalsWithCloudCompare] parallel strategy, thread count " + QString::number(threadCount));
|
||||
QThreadPool::globalInstance()->setMaxThreadCount(threadCount);
|
||||
QtConcurrent::blockingMap(pointsIndexes, [=](int index){computeNormWithFlann(index, theNorms.data(), m_kdTree.data());});
|
||||
#endif
|
||||
|
||||
if (!m_cloud->hasNormals())
|
||||
{
|
||||
if (!m_cloud->resizeTheNormsTable())
|
||||
{
|
||||
ccLog::Error(QString("Not enough memory to compute normals on cloud '%1'").arg(m_cloud->getName()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// we hide normals during process
|
||||
m_cloud->showNormals(false);
|
||||
|
||||
// compress the normals
|
||||
for (unsigned i = 0; i < theNorms->currentSize(); i++)
|
||||
{
|
||||
const CCVector3& N = theNorms->at(i);
|
||||
const CompressedNormType nCode = ccNormalVectors::GetNormIndex(N);
|
||||
m_cloud->setPointNormalIndex(i, nCode);
|
||||
}
|
||||
|
||||
// preferred orientation
|
||||
ccLog::Print("[computeNormalsWithCloudCompare] orient normals, PLUS_Z ");
|
||||
ccNormalVectors::UpdateNormalOrientations(m_cloud, *m_cloud->normals(), ccNormalVectors::PLUS_Z);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool G3PointAction::computeNormals()
|
||||
{
|
||||
// if there are normals, already, propose to keep them
|
||||
if (m_cloud->hasNormals())
|
||||
{
|
||||
QMessageBox msgBox;
|
||||
msgBox.setInformativeText("Recompute normals?");
|
||||
msgBox.setText("There are existing normals, keep them or recompute.");
|
||||
QPushButton *keepButton = msgBox.addButton(tr("Keep"), QMessageBox::ActionRole);
|
||||
msgBox.addButton(tr("Recompute"), QMessageBox::AcceptRole);
|
||||
QPushButton *cancelButton = msgBox.addButton(tr("Cancel"), QMessageBox::AcceptRole);
|
||||
|
||||
msgBox.exec();
|
||||
|
||||
if (msgBox.clickedButton() == keepButton)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (msgBox.clickedButton() == cancelButton)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_OPEN3D_WITH_G3POINT
|
||||
return computeNormalsWithOpen3D();
|
||||
#else
|
||||
return computeNormalsWithCloudCompare();
|
||||
#endif
|
||||
}
|
||||
|
||||
bool G3PointAction::queryNeighbors(ccPointCloud* cloud, ccMainAppInterface* appInterface, bool useParallelStrategy)
|
||||
{
|
||||
{
|
||||
QString errorStr;
|
||||
|
||||
ccProgressDialog progressDlg(true, appInterface->getMainWindow());
|
||||
@@ -2007,8 +1846,8 @@ bool G3PointAction::queryNeighbors(ccPointCloud* cloud, ccMainAppInterface* appI
|
||||
|
||||
size_t nPoints = m_cloud->size();
|
||||
CCCoreLib::DgmOctree::NearestNeighboursSearchStruct nNSS;
|
||||
std::vector<unsigned> pointsIndexes;
|
||||
pointsIndexes.resize(nPoints);
|
||||
std::vector<unsigned> pointsIndexes(nPoints);
|
||||
std::vector<char> duplicates(nPoints, 0);
|
||||
|
||||
if (useParallelStrategy)
|
||||
{
|
||||
@@ -2019,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;
|
||||
}
|
||||
|
||||
@@ -2048,7 +1893,7 @@ void G3PointAction::segment()
|
||||
|
||||
computeNodeSurfaces();
|
||||
|
||||
computeNormals();
|
||||
computeNormalsWithOpen3D();
|
||||
|
||||
// compute the centroid
|
||||
unsigned pointCount = m_cloud->size();
|
||||
@@ -2119,7 +1964,7 @@ void G3PointAction::getBorders()
|
||||
Eigen::ArrayXXi duplicatedLabelsInColumns(m_cloud->size(), m_kNN);
|
||||
for (int n = 0; n < m_kNN; n++)
|
||||
{
|
||||
duplicatedLabelsInColumns(Eigen::placeholders::all, n) = m_labels;
|
||||
duplicatedLabelsInColumns(Eigen::all, n) = m_labels;
|
||||
}
|
||||
Eigen::ArrayXXi labelsOfNeighbors(m_cloud->size(), m_kNN);
|
||||
for (int index = 0; index < static_cast<float>(m_cloud->size()); index++)
|
||||
|
||||
+12
-12
@@ -626,15 +626,15 @@ bool GrainsAsEllipsoids::directFit(const Eigen::ArrayX3d& xyz, Eigen::ArrayXd& p
|
||||
|
||||
Eigen::MatrixXd d(xyz.rows(), 10);
|
||||
|
||||
d << xyz(Eigen::placeholders::all, 0).pow(2).matrix()
|
||||
, xyz(Eigen::placeholders::all, 1).pow(2).matrix()
|
||||
, xyz(Eigen::placeholders::all, 2).pow(2).matrix()
|
||||
, (2 * xyz(Eigen::placeholders::all, 1) * xyz(Eigen::placeholders::all, 2)).matrix()
|
||||
, (2 * xyz(Eigen::placeholders::all, 0) * xyz(Eigen::placeholders::all, 2)).matrix()
|
||||
, (2 * xyz(Eigen::placeholders::all, 0) * xyz(Eigen::placeholders::all, 1)).matrix()
|
||||
, (2 * xyz(Eigen::placeholders::all, 0)).matrix()
|
||||
, (2 * xyz(Eigen::placeholders::all, 1)).matrix()
|
||||
, (2 * xyz(Eigen::placeholders::all, 2)).matrix()
|
||||
d << xyz(Eigen::all, 0).pow(2).matrix()
|
||||
, xyz(Eigen::all, 1).pow(2).matrix()
|
||||
, xyz(Eigen::all, 2).pow(2).matrix()
|
||||
, (2 * xyz(Eigen::all, 1) * xyz(Eigen::all, 2)).matrix()
|
||||
, (2 * xyz(Eigen::all, 0) * xyz(Eigen::all, 2)).matrix()
|
||||
, (2 * xyz(Eigen::all, 0) * xyz(Eigen::all, 1)).matrix()
|
||||
, (2 * xyz(Eigen::all, 0)).matrix()
|
||||
, (2 * xyz(Eigen::all, 1)).matrix()
|
||||
, (2 * xyz(Eigen::all, 2)).matrix()
|
||||
, Eigen::MatrixXd::Ones(xyz.rows(), 1);
|
||||
|
||||
Eigen::MatrixXd s = d.transpose() * d;
|
||||
@@ -686,7 +686,7 @@ bool GrainsAsEllipsoids::directFit(const Eigen::ArrayX3d& xyz, Eigen::ArrayXd& p
|
||||
{
|
||||
if (eigenValues(k) == eigenValue)
|
||||
{
|
||||
v = eigensolver.eigenvectors()(Eigen::placeholders::all, k).real();
|
||||
v = eigensolver.eigenvectors()(Eigen::all, k).real();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -698,7 +698,7 @@ bool GrainsAsEllipsoids::directFit(const Eigen::ArrayX3d& xyz, Eigen::ArrayXd& p
|
||||
{
|
||||
if (abs(eigenValues(k)) == eigenValue)
|
||||
{
|
||||
v = eigensolver.eigenvectors()(Eigen::placeholders::all, k).real();
|
||||
v = eigensolver.eigenvectors()(Eigen::all, k).real();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -710,7 +710,7 @@ bool GrainsAsEllipsoids::directFit(const Eigen::ArrayX3d& xyz, Eigen::ArrayXd& p
|
||||
{
|
||||
if (eigenValues(k) == eigenValue)
|
||||
{
|
||||
v = eigensolver.eigenvectors()(Eigen::placeholders::all, k).real();
|
||||
v = eigensolver.eigenvectors()(Eigen::all, k).real();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user