Skip to content

Commit 3709873

Browse files
Merge pull request #1084 from Geode-solutions/fix/nnsearch-log
fix(NNSearch): add trace log for future debug on CI
2 parents 1d46405 + 463e414 commit 3709873

File tree

4 files changed

+63
-61
lines changed

4 files changed

+63
-61
lines changed

bindings/python/tests/geometry/test-py-nnsearch.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,3 @@
5555
colocated_info = colocator.colocated_index_mapping(basic.GLOBAL_EPSILON)
5656
if colocated_info.nb_colocated_points() != 3:
5757
raise ValueError("[Test] Should be 3 colocated points")
58-
mapping_answer = [0, 0, 1, 0, 2, 1, 3]
59-
if colocated_info.colocated_mapping != mapping_answer:
60-
raise ValueError("[Test] Error in colocated mapping")
61-
points_answer = [p0, p1, p2, p3]
62-
for p in range(4):
63-
if colocated_info.unique_points[p] != points_answer[p]:
64-
raise ValueError("[Test] Error in unique points")

src/geode/geometry/nn_search.cpp

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,6 @@
3535
#include <geode/basic/logger.hpp>
3636
#include <geode/basic/pimpl_impl.hpp>
3737

38-
namespace
39-
{
40-
geode::index_t find_min_unmapped_element(
41-
absl::Span< const geode::index_t > elements,
42-
absl::Span< const geode::index_t > mapping )
43-
{
44-
geode::index_t min_index{ geode::NO_ID };
45-
for( const auto e : elements )
46-
{
47-
if( mapping[e] != e )
48-
{
49-
continue;
50-
}
51-
min_index = std::min( min_index, e );
52-
}
53-
return min_index;
54-
}
55-
} // namespace
56-
5738
namespace geode
5839
{
5940
template < index_t dimension >
@@ -208,34 +189,33 @@ namespace geode
208189
"should be bigger than GLOBAL_EPSILON (i.e. ",
209190
GLOBAL_EPSILON, ")" );
210191
typename NNSearch< dimension >::ColocatedInfo result;
211-
std::vector< index_t > mapping( nb_points() );
212-
absl::c_iota( mapping, 0 );
192+
std::vector< index_t > mapping( nb_points(), NO_ID );
213193
std::mutex mutex;
214194
async::parallel_for( async::irange( index_t{ 0 }, nb_points() ),
215195
[&epsilon, &mapping, &mutex, this]( index_t p ) {
216-
if( mapping[p] != p )
196+
if( mapping[p] != NO_ID )
217197
{
218198
return;
219199
}
220200
const auto vertices = radius_neighbors( point( p ), epsilon );
221-
auto min_index = find_min_unmapped_element( vertices, mapping );
222201
std::lock_guard< std::mutex > lock( mutex );
223-
if( mapping[p] != p )
202+
if( mapping[p] != NO_ID )
224203
{
204+
Logger::trace(
205+
p, " : correction 1 / mapping[p] ", mapping[p] );
225206
return;
226207
}
227-
if( min_index != mapping[min_index] )
228-
{
229-
min_index = find_min_unmapped_element( vertices, mapping );
230-
}
231208
for( const auto id : vertices )
232209
{
233-
if( id == mapping[id] )
210+
Logger::trace(
211+
p, " : id ", id, " / mapping[id] ", mapping[id] );
212+
if( mapping[id] == NO_ID )
234213
{
235-
mapping[id] = min_index;
214+
mapping[id] = p;
236215
}
237216
}
238217
} );
218+
result.colocated_input_points = mapping;
239219
index_t nb_unique_points{ 0 };
240220
for( const auto p : Range{ nb_points() } )
241221
{
@@ -244,23 +224,22 @@ namespace geode
244224
nb_unique_points++;
245225
}
246226
}
247-
result.colocated_input_points = mapping;
248-
index_t nb_colocated{ 0 };
249-
index_t count{ 0 };
250227
result.unique_points.resize( nb_unique_points );
228+
std::vector< index_t > old2new( nb_points(), NO_ID );
229+
index_t count{ 0 };
251230
for( const auto p : Range{ nb_points() } )
252231
{
253232
if( mapping[p] == p )
254233
{
255-
mapping[p] -= nb_colocated;
256-
result.unique_points[count++] = point( p );
257-
}
258-
else
259-
{
260-
nb_colocated++;
261-
mapping[p] = mapping[mapping[p]];
234+
result.unique_points[count] = point( p );
235+
old2new[p] = count;
236+
count++;
262237
}
263238
}
239+
for( const auto p : Range{ nb_points() } )
240+
{
241+
mapping[p] = old2new[mapping[p]];
242+
}
264243
result.colocated_mapping = mapping;
265244
return result;
266245
}

tests/geometry/test-nnsearch.cpp

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,46 @@ void first_test()
5757
const geode::Point3D p1{ { 2.4, 8.1, 7.6 } };
5858
const geode::Point3D p2{ { 8.1, 4.2, 3.8 } };
5959
const geode::Point3D p3{ { 3.1, 9.4, 9.7 } };
60-
const geode::NNSearch3D colocator( { p0, p0, p1, p0, p2, p1, p3 } );
60+
std::vector< geode::Point3D > points{ p0, p0, p1, p0, p2, p1, p3 };
61+
const geode::NNSearch3D colocator( points );
6162

6263
const auto colocated_info =
6364
colocator.colocated_index_mapping( geode::GLOBAL_EPSILON );
6465
OPENGEODE_EXCEPTION( colocated_info.nb_colocated_points() == 3,
65-
"[Test] Should be 3 colocated points" );
66-
const std::vector< geode::index_t > mapping_answer{ 0, 0, 1, 0, 2, 1, 3 };
67-
OPENGEODE_EXCEPTION( colocated_info.colocated_mapping == mapping_answer,
68-
"[Test] Error in colocated mapping" );
69-
const std::vector< geode::Point3D > points_answer{ p0, p1, p2, p3 };
70-
OPENGEODE_EXCEPTION( colocated_info.unique_points == points_answer,
71-
"[Test] Error in unique points" );
66+
"[Test 1] Should be 3 colocated points" );
67+
for( const auto p : geode::Indices{ points } )
68+
{
69+
OPENGEODE_EXCEPTION( colocated_info.colocated_mapping[p]
70+
< colocated_info.unique_points.size(),
71+
"[Test 1] Wrong value of colocated_mapping (bigger than unique "
72+
"points size)" );
73+
const auto& colocated_point =
74+
colocated_info.unique_points[colocated_info.colocated_mapping[p]];
75+
OPENGEODE_EXCEPTION(
76+
geode::point_point_distance( points[p], colocated_point )
77+
<= geode::GLOBAL_EPSILON,
78+
"[Test 1] Colocated point is not close enough to original point" );
79+
}
80+
for( const auto up0 : geode::Indices{ colocated_info.unique_points } )
81+
{
82+
for( const auto up1 : geode::Indices{ colocated_info.unique_points } )
83+
{
84+
if( up1 <= up0 )
85+
{
86+
continue;
87+
}
88+
OPENGEODE_EXCEPTION(
89+
geode::point_point_distance( colocated_info.unique_points[up0],
90+
colocated_info.unique_points[up1] )
91+
> geode::GLOBAL_EPSILON,
92+
"[Test 1] Colocated points are too close" );
93+
}
94+
}
7295
}
7396

7497
void second_test()
7598
{
76-
geode::Logger::set_level( geode::Logger::LEVEL::debug );
99+
geode::Logger::set_level( geode::Logger::LEVEL::trace );
77100
std::vector< geode::Point2D > points{
78101
geode::Point2D{ { 0, 0.2 } },
79102
geode::Point2D{ { 0.25, 0 } },
@@ -87,18 +110,24 @@ void second_test()
87110

88111
const auto colocated_info = colocator.colocated_index_mapping( DISTANCE );
89112
DEBUG( colocated_info.nb_unique_points() );
113+
for( const auto v : geode::Range{ 6 } )
114+
{
115+
geode::Logger::trace( v, " : ",
116+
colocated_info.colocated_input_points[v], " / ",
117+
colocated_info.colocated_mapping[v] );
118+
}
90119
for( const auto p : geode::Indices{ points } )
91120
{
92121
OPENGEODE_EXCEPTION( colocated_info.colocated_mapping[p]
93122
< colocated_info.unique_points.size(),
94-
"[Test] Wrong value of colocated_mapping (bigger than unique "
123+
"[Test 2] Wrong value of colocated_mapping (bigger than unique "
95124
"points size)" );
96125
const auto& colocated_point =
97126
colocated_info.unique_points[colocated_info.colocated_mapping[p]];
98127
OPENGEODE_EXCEPTION(
99128
geode::point_point_distance( points[p], colocated_point )
100129
<= DISTANCE,
101-
"[Test] Colocated point is not close enough to original point" );
130+
"[Test 2] Colocated point is not close enough to original point" );
102131
}
103132
for( const auto up0 : geode::Indices{ colocated_info.unique_points } )
104133
{
@@ -112,11 +141,11 @@ void second_test()
112141
geode::point_point_distance( colocated_info.unique_points[up0],
113142
colocated_info.unique_points[up1] )
114143
> DISTANCE,
115-
"[Test] Colocated points are too close" );
144+
"[Test 2] Colocated points are too close" );
116145
}
117146
}
118147
OPENGEODE_EXCEPTION( colocated_info.nb_unique_points() == 2,
119-
"[Test] Should be 2 unique points" );
148+
"[Test 2] Should be 2 unique points" );
120149
}
121150

122151
void test()

tests/mesh/test-merge-surface.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,9 @@ void test_import()
136136
}
137137
geode::NNSearch3D nns( points );
138138
const auto mappings = nns.colocated_index_mapping( geode::GLOBAL_EPSILON );
139+
DEBUG( mappings.nb_colocated_points() );
139140
OPENGEODE_EXCEPTION( mappings.nb_colocated_points() == 0,
140-
"[Test] Should be nomore colocated points" );
141+
"[Test] Should be no more colocated points" );
141142
for( const auto p : geode::Indices{ points } )
142143
{
143144
OPENGEODE_EXCEPTION(

0 commit comments

Comments
 (0)