ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
TreeIsoHelper.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 // #######################################################################################
11 // # # # ACLOUDVIEWER PLUGIN: qTreeIso # # # # This
12 // program is free software; you can redistribute it and/or modify # #
13 // it under the terms of the GNU General Public License as published by # # the
14 // Free Software Foundation; version 2 or later of the License. # #
15 // # # This program is distributed in the hope that it will be useful, #
16 // # but WITHOUT ANY WARRANTY; without even the implied warranty of # #
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU
18 // General Public License for more details. # # # # Please cite the
19 // following paper if you find this tool helpful # # # # Xi, Z.;
20 // Hopkinson, C. 3D Graph-Based Individual-Tree Isolation (Treeiso) # # from
21 // Terrestrial Laser Scanning Point Clouds. Remote Sens. 2022, 14, 6116. # #
22 // https://doi.org/10.3390/rs14236116 # # # # Our work relies on
23 // the cut-pursuit algorithm, please also consider citing: # # Landrieu, L.;
24 // Obozinski, G. Cut Pursuit: Fast Algorithms to Learn Piecewise # # Constant
25 // Functions on General Weighted Graphs. SIAM J. Imaging Sci. # # 2017,
26 // 10, 1724–1766. # # # # Copyright © # #
27 // Artemis Lab, Department of Geography & Environment # #
28 // University of Lethbridge, Canada # # # # # # Zhouxin
29 // Xi and Chris Hopkinson; # #
30 // truebelief2010@gmail.com; c.hopkinson@uleth.ca # # #
31 // #######################################################################################
32 
33 // Local
34 #include "API.h"
35 #include "knncpp.h"
36 
37 // Eigen
38 #include <Eigen/Dense>
39 
40 // STL
41 #include <vector>
42 
43 class ccPointCloud;
44 
45 bool perform_cut_pursuit(const uint32_t K,
46  const float regStrength,
47  const std::vector<std::vector<float>>& pc_vec,
48  std::vector<float>& edgeWeight,
49  std::vector<uint32_t>& Eu,
50  std::vector<uint32_t>& Ev,
51  std::vector<uint32_t>& in_component,
52  std::vector<std::vector<uint32_t>>& components);
53 void perform_cut_pursuit2d(const uint32_t K,
54  const float regStrength,
55  const std::vector<std::vector<float>>& pc_vec,
56  std::vector<float>& edgeWeight,
57  std::vector<uint32_t>& Eu,
58  std::vector<uint32_t>& Ev,
59  std::vector<uint32_t>&);
60 
61 template <typename T>
62 void toTranslatedVector(const ccPointCloud* pc, std::vector<std::vector<T>>& y);
63 template <typename T>
64 size_t arg_min_col(std::vector<T>& arr);
65 template <typename T>
66 size_t arg_max_col(std::vector<T>& arr);
67 template <typename T>
68 void min_col(std::vector<std::vector<T>>& arr, std::vector<T>&);
69 template <typename T>
70 T min_col(std::vector<T>& arr);
71 template <typename T>
72 void max_col(std::vector<std::vector<T>>& arr, std::vector<T>&);
73 template <typename T>
74 void mean_col(std::vector<std::vector<T>>& arr, std::vector<T>&);
75 template <typename T>
76 T mean_col(std::vector<T>& arr);
77 template <typename T>
78 T median_col(std::vector<T>& arr);
79 template <typename T>
80 T mode_col(std::vector<T>& arr);
81 template <typename T>
82 void decimate_vec(std::vector<std::vector<T>>& arr,
83  T res,
84  std::vector<std::vector<T>>& vec_dec);
85 
86 template <typename T>
87 void unique_group(std::vector<T>& arr,
88  std::vector<std::vector<T>>& u_group,
89  std::vector<T>& arr_unq,
90  std::vector<T>& ui);
91 template <typename T>
92 void unique_group(std::vector<T>& idx, std::vector<std::vector<T>>&);
93 template <typename T>
94 void unique_group(std::vector<T>& arr,
95  std::vector<std::vector<T>>& u_group,
96  std::vector<T>& arr_unq);
97 template <typename T>
98 void unique_index_by_rows(std::vector<std::vector<T>>& arr,
99  std::vector<size_t>& ia,
100  std::vector<size_t>& ic);
101 template <typename T>
102 void sort_indexes_by_row(std::vector<std::vector<T>>& v,
103  std::vector<size_t>& idx,
104  std::vector<std::vector<T>>&);
105 template <typename ValueType, typename IndexType>
106 void sort_indexes(std::vector<ValueType>& v,
107  std::vector<IndexType>& idx,
108  std::vector<ValueType>&);
109 
110 template <typename T1, typename T2>
111 void get_subset(const std::vector<std::vector<T1>>& arr,
112  const std::vector<T2>& indices,
113  std::vector<std::vector<T1>>&);
114 template <typename T1, typename T2>
115 void get_subset(const std::vector<std::vector<T1>>& arr,
116  const std::vector<T2>& indices,
117  Eigen::MatrixXf&);
118 template <typename T1, typename T2>
119 bool get_subset(ccPointCloud* pcd,
120  std::vector<T2>& indices,
121  std::vector<std::vector<T1>>& arr_sub);
122 template <typename T1, typename T2>
123 void get_subset(std::vector<T1>& arr,
124  std::vector<T2>& indices,
125  std::vector<T1>& arr_sub);
126 
127 void knn_cpp_nearest_neighbors(const std::vector<std::vector<float>>& dataset,
128  size_t k,
129  std::vector<std::vector<uint32_t>>& res_idx,
130  std::vector<std::vector<float>>& res_dists,
131  unsigned n_thread);
132 void knn_cpp_build(
134  kdtree,
135  unsigned n_thread = 0);
138  kdtree,
139  Eigen::MatrixXf& query_points,
140  size_t k,
141  std::vector<std::vector<size_t>>& res_idx,
142  std::vector<std::vector<float>>& res_dists);
143 float knn_cpp_query_min_d(
145  kdtree,
146  Eigen::MatrixXf& query_points,
147  size_t k);
void unique_index_by_rows(std::vector< std::vector< T >> &arr, std::vector< size_t > &ia, std::vector< size_t > &ic)
Definition: TreeIso.cpp:1601
void sort_indexes(std::vector< ValueType > &v, std::vector< IndexType > &idx, std::vector< ValueType > &)
Definition: TreeIso.cpp:1576
void knn_cpp_nearest_neighbors(const std::vector< std::vector< float >> &dataset, size_t k, std::vector< std::vector< uint32_t >> &res_idx, std::vector< std::vector< float >> &res_dists, unsigned n_thread)
bool perform_cut_pursuit(const uint32_t K, const float regStrength, const std::vector< std::vector< float >> &pc_vec, std::vector< float > &edgeWeight, std::vector< uint32_t > &Eu, std::vector< uint32_t > &Ev, std::vector< uint32_t > &in_component, std::vector< std::vector< uint32_t >> &components)
void min_col(std::vector< std::vector< T >> &arr, std::vector< T > &)
Definition: TreeIso.cpp:1400
T mode_col(std::vector< T > &arr)
Definition: TreeIso.cpp:1453
void knn_cpp_query(knncpp::KDTreeMinkowskiX< float, knncpp::EuclideanDistance< float >> &kdtree, Eigen::MatrixXf &query_points, size_t k, std::vector< std::vector< size_t >> &res_idx, std::vector< std::vector< float >> &res_dists)
float knn_cpp_query_min_d(knncpp::KDTreeMinkowskiX< float, knncpp::EuclideanDistance< float >> &kdtree, Eigen::MatrixXf &query_points, size_t k)
Definition: TreeIso.cpp:983
T median_col(std::vector< T > &arr)
Definition: TreeIso.cpp:1437
void mean_col(std::vector< std::vector< T >> &arr, std::vector< T > &)
Definition: TreeIso.cpp:1480
void toTranslatedVector(const ccPointCloud *pc, std::vector< std::vector< T >> &y)
Definition: TreeIso.cpp:1218
void knn_cpp_build(knncpp::KDTreeMinkowskiX< float, knncpp::EuclideanDistance< float >> &kdtree, unsigned n_thread=0)
Definition: TreeIso.cpp:947
void max_col(std::vector< std::vector< T >> &arr, std::vector< T > &)
Definition: TreeIso.cpp:1464
size_t arg_max_col(std::vector< T > &arr)
Definition: TreeIso.cpp:1393
void sort_indexes_by_row(std::vector< std::vector< T >> &v, std::vector< size_t > &idx, std::vector< std::vector< T >> &)
Definition: TreeIso.cpp:1531
void decimate_vec(std::vector< std::vector< T >> &arr, T res, std::vector< std::vector< T >> &vec_dec)
Definition: TreeIso.cpp:1501
void perform_cut_pursuit2d(const uint32_t K, const float regStrength, const std::vector< std::vector< float >> &pc_vec, std::vector< float > &edgeWeight, std::vector< uint32_t > &Eu, std::vector< uint32_t > &Ev, std::vector< uint32_t > &)
size_t arg_min_col(std::vector< T > &arr)
Definition: TreeIso.cpp:1386
void unique_group(std::vector< T > &arr, std::vector< std::vector< T >> &u_group, std::vector< T > &arr_unq, std::vector< T > &ui)
Definition: TreeIso.cpp:1034
void get_subset(const std::vector< std::vector< T1 >> &arr, const std::vector< T2 > &indices, std::vector< std::vector< T1 >> &)
Definition: TreeIso.cpp:1185
A 3D cloud and its associated features (color, normals, scalar fields, etc.)