4 #ifndef TRIGTOOLS_TRIG_VSI_DBSCAN
5 #define TRIGTOOLS_TRIG_VSI_DBSCAN
17 #include <unordered_set>
18 #include <unordered_map>
42 template<
typename po
intType>
45 using RegionFunc = std::function<std::vector<pointType>(
const pointType&,
double)>;
82 template<
typename po
intType>
84 m_regionQuery(regionQuery)
87 for (
const auto& point :
set) {
96 template<
typename po
intType>
106 template<
typename po
intType>
109 auto tmp = m_clusters;
110 const auto& tmp_noise = m_noisesCluster;
111 tmp.insert(
tmp.end(), tmp_noise.begin(), tmp_noise.end() );
127 template<
typename po
intType>
130 const Cluster<pointType>& cls_tmp = ( icls < m_clusters.size() )? m_clusters[icls] : m_noisesCluster[icls-m_clusters.size()];
141 template<
typename po
intType>
145 m_noisesCluster.clear();
146 for (
auto& pair : m_pointsVisited) {
147 const pointType& point = pair.first;
149 if ( pair.second )
continue;
151 std::vector<pointType> neighbor_points = m_regionQuery(point, eps);
152 if ( neighbor_points.size() < minN ) {
153 m_noises.emplace(point);
157 m_clusters.emplace_back( std::vector<pointType>{point} );
160 for (
size_t i = 0;
i < neighbor_points.size();
i++) {
161 const auto&
q = neighbor_points[
i];
165 auto q_itr_noise = m_noises.find(
q);
166 if ( q_itr_noise != m_noises.end() ) {
167 m_noises.erase(q_itr_noise);
168 cls.Points().emplace_back(
q);
174 auto q_itr = m_pointsVisited.find(
q);
175 if ( q_itr == m_pointsVisited.end() )
continue;
176 if ( q_itr->second )
continue;
177 q_itr->second =
true;
178 cls.Points().emplace_back(
q);
180 std::vector<pointType> q_neighbor_points = m_regionQuery(
q, eps);
181 if ( q_neighbor_points.size() >= minN ) neighbor_points.insert( neighbor_points.end(), q_neighbor_points.begin(), q_neighbor_points.end() );
187 for (
const auto&
q : m_noises) {
188 m_noisesCluster.emplace_back( std::vector<pointType>{
q} );