Skip to content

Commit

Permalink
fix(NNSearch): add more info about colocalized points
Browse files Browse the repository at this point in the history
  • Loading branch information
panquez committed Oct 17, 2024
1 parent 71363b3 commit 219a57e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
11 changes: 9 additions & 2 deletions include/geode/geometry/nn_search.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ namespace geode
public:
struct ColocatedInfo
{
ColocatedInfo() = default;
[[nodiscard]] index_t nb_unique_points() const
{
return unique_points.size();
Expand All @@ -52,13 +53,19 @@ namespace geode
return colocated_mapping.size() - nb_unique_points();
}

std::vector< Point< dimension > > unique_points;
/*!
* This list has the size of the number of points in the tree.
* Each index is pointing to its old point index as given in input
* vector.
*/
std::vector< index_t > colocated_mapping;
/*!
* This list has the size of the number of points in the tree.
* Each index is pointing to its new unique point stored in the
* unique_points vector.
*/
std::vector< index_t > colocated_mapping;
std::vector< Point< dimension > > unique_points;
std::vector< index_t > colocated_input_points;
};

public:
Expand Down
9 changes: 6 additions & 3 deletions src/geode/geometry/nn_search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ namespace geode
"[NNSearch::colocated_index_mapping] Given epsilon too small, "
"should be bigger than GLOBAL_EPSILON (i.e. ",
GLOBAL_EPSILON, ")" );
typename NNSearch< dimension >::ColocatedInfo result;
std::vector< index_t > mapping( nb_points() );
absl::c_iota( mapping, 0 );
async::parallel_for( async::irange( index_t{ 0 }, nb_points() ),
Expand All @@ -210,23 +211,25 @@ namespace geode
nb_unique_points++;
}
}
result.colocated_input_points = mapping;
index_t nb_colocated{ 0 };
index_t count{ 0 };
std::vector< Point< dimension > > unique_points( nb_unique_points );
result.unique_points.resize( nb_unique_points );
for( const auto p : Range{ nb_points() } )
{
if( mapping[p] == p )
{
mapping[p] -= nb_colocated;
unique_points[count++] = point( p );
result.unique_points[count++] = point( p );
}
else
{
nb_colocated++;
mapping[p] = mapping[mapping[p]];
}
}
return { std::move( mapping ), std::move( unique_points ) };
result.colocated_mapping = mapping;
return result;
}

template class opengeode_geometry_api NNSearch< 2 >;
Expand Down

0 comments on commit 219a57e

Please sign in to comment.