Skip to content

Commit fcf04cd

Browse files
committed
review changes
1 parent a5e84b8 commit fcf04cd

File tree

2 files changed

+38
-84
lines changed

2 files changed

+38
-84
lines changed

src/geode/geometry/nn_search.cpp

Lines changed: 37 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -120,101 +120,25 @@ namespace geode
120120
return results;
121121
}
122122

123-
typename NNSearch< dimension >::ColocatedInfo colocated_index_mapping(
124-
const NNSearch< dimension >& nn_search, const double epsilon ) const
125-
{
126-
OPENGEODE_EXCEPTION( epsilon >= GLOBAL_EPSILON,
127-
"[NNSearch::colocated_index_mapping] Given epsilon too "
128-
"small, "
129-
"should be bigger than GLOBAL_EPSILON (i.e. ",
130-
GLOBAL_EPSILON, ")" );
131-
typename NNSearch< dimension >::ColocatedInfo result;
132-
const auto nb_points = nn_search.nb_points();
133-
std::vector< index_t > mapping( nb_points, NO_ID );
134-
std::mutex mutex;
135-
async::parallel_for( async::irange( index_t{ 0 }, nb_points ),
136-
[&nn_search, &epsilon, &mapping, &mutex, this](
137-
index_t point_id ) {
138-
if( mapping[point_id] != NO_ID )
139-
{
140-
return;
141-
}
142-
const auto vertices_around = nn_search.radius_neighbors(
143-
nn_search.point( point_id ), epsilon );
144-
std::lock_guard< std::mutex > lock( mutex );
145-
if( mapping[point_id] != NO_ID )
146-
{
147-
Logger::trace( point_id,
148-
" : correction 1 / mapping[p] ",
149-
mapping[point_id] );
150-
return;
151-
}
152-
for( const auto vertex_id : vertices_around )
153-
{
154-
Logger::trace( point_id, " : id ", vertex_id,
155-
" / mapping[id] ", mapping[vertex_id] );
156-
if( mapping[vertex_id] == NO_ID )
157-
{
158-
mapping[vertex_id] = point_id;
159-
}
160-
}
161-
} );
162-
result.colocated_input_points = mapping;
163-
index_t nb_unique_points{ 0 };
164-
for( const auto point_id : Range{ nb_points } )
165-
{
166-
if( mapping[point_id] == point_id )
167-
{
168-
nb_unique_points++;
169-
}
170-
}
171-
result.unique_points.resize( nb_unique_points );
172-
std::vector< index_t > old2new( nb_points, NO_ID );
173-
index_t count{ 0 };
174-
for( const auto point_id : Range{ nb_points } )
175-
{
176-
if( mapping[point_id] == point_id )
177-
{
178-
result.unique_points[count] = nn_search.point( point_id );
179-
old2new[point_id] = count;
180-
count++;
181-
}
182-
}
183-
for( const auto point_id : Range{ nb_points } )
184-
{
185-
mapping[point_id] = old2new[mapping[point_id]];
186-
}
187-
result.colocated_mapping = mapping;
188-
return result;
189-
}
190-
123+
template < typename EpsilonType >
191124
typename geode::NNSearch< dimension >::ColocatedInfo
192125
colocated_index_mapping(
193126
const geode::NNSearch< dimension >& nn_search,
194-
const Frame< dimension >& epsilons_frame ) const
127+
const EpsilonType& epsilon ) const
195128
{
196-
for( const auto d : LRange{ dimension } )
197-
{
198-
OPENGEODE_EXCEPTION(
199-
epsilons_frame.direction( d ).length() >= GLOBAL_EPSILON,
200-
"[NNSearch::colocated_index_mapping] Given epsilon too "
201-
"small, "
202-
"should be bigger than GLOBAL_EPSILON (i.e. ",
203-
GLOBAL_EPSILON, ")" );
204-
}
205129
typename NNSearch< dimension >::ColocatedInfo result;
206130
const auto nb_points = nn_search.nb_points();
207131
std::vector< index_t > mapping( nb_points, NO_ID );
208132
std::mutex mutex;
209133
async::parallel_for( async::irange( index_t{ 0 }, nb_points ),
210-
[&nn_search, &epsilons_frame, &mapping, &mutex, this](
134+
[&nn_search, &epsilon, &mapping, &mutex, this](
211135
index_t point_id ) {
212136
if( mapping[point_id] != NO_ID )
213137
{
214138
return;
215139
}
216-
const auto vertices_around = frame_neighbors(
217-
nn_search.point( point_id ), epsilons_frame );
140+
const auto neighbor_vertices =
141+
vertices_around( point( point_id ), epsilon );
218142
std::lock_guard< std::mutex > lock( mutex );
219143
if( mapping[point_id] != NO_ID )
220144
{
@@ -223,7 +147,7 @@ namespace geode
223147
mapping[point_id] );
224148
return;
225149
}
226-
for( const auto vertex_id : vertices_around )
150+
for( const auto vertex_id : neighbor_vertices )
227151
{
228152
Logger::trace( point_id, " : id ", vertex_id,
229153
" / mapping[id] ", mapping[vertex_id] );
@@ -249,7 +173,7 @@ namespace geode
249173
{
250174
if( mapping[point_id] == point_id )
251175
{
252-
result.unique_points[count] = nn_search.point( point_id );
176+
result.unique_points[count] = point( point_id );
253177
old2new[point_id] = count;
254178
count++;
255179
}
@@ -263,6 +187,22 @@ namespace geode
263187
}
264188

265189
private:
190+
template < typename EpsilonType >
191+
std::vector< index_t > vertices_around(
192+
const Point< dimension >& point, const EpsilonType& epsilon ) const;
193+
194+
std::vector< index_t > vertices_around(
195+
const Point< dimension >& point, const double& epsilon ) const
196+
{
197+
return radius_neighbors( point, epsilon );
198+
}
199+
200+
std::vector< index_t > vertices_around( const Point< dimension >& point,
201+
const Frame< dimension >& epsilon ) const
202+
{
203+
return frame_neighbors( point, epsilon );
204+
}
205+
266206
std::array< double, dimension > copy(
267207
const Point< dimension >& point ) const
268208
{
@@ -369,6 +309,11 @@ namespace geode
369309
NNSearch< dimension >::colocated_index_mapping(
370310
const double epsilon ) const
371311
{
312+
OPENGEODE_EXCEPTION( epsilon >= GLOBAL_EPSILON,
313+
"[NNSearch::colocated_index_mapping] Given epsilon too "
314+
"small, "
315+
"should be bigger than GLOBAL_EPSILON (i.e. ",
316+
GLOBAL_EPSILON, ")" );
372317
return impl_->colocated_index_mapping( *this, epsilon );
373318
}
374319

@@ -377,6 +322,15 @@ namespace geode
377322
NNSearch< dimension >::colocated_index_mapping(
378323
const Frame< dimension >& epsilons_frame ) const
379324
{
325+
for( const auto d : LRange{ dimension } )
326+
{
327+
OPENGEODE_EXCEPTION(
328+
epsilons_frame.direction( d ).length() >= GLOBAL_EPSILON,
329+
"[NNSearch::colocated_index_mapping] Given epsilon too "
330+
"small, "
331+
"should be bigger than GLOBAL_EPSILON (i.e. ",
332+
GLOBAL_EPSILON, ")" );
333+
}
380334
return impl_->colocated_index_mapping( *this, epsilons_frame );
381335
}
382336

src/geode/mesh/helpers/detail/solid_merger.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ namespace geode
9797

9898
std::unique_ptr< SolidMesh< dimension > > merge(
9999
SolidMeshMerger< dimension >& merger,
100-
const Frame3D& epsilons_frame )
100+
const Frame< dimension >& epsilons_frame )
101101
{
102102
merger.create_points( epsilons_frame );
103103
create_polyhedra( merger );

0 commit comments

Comments
 (0)