Skip to content

Commit f4f76bf

Browse files
committed
robustness improved
1 parent 0bf378b commit f4f76bf

2 files changed

Lines changed: 24 additions & 20 deletions

File tree

TreeNSearch/source/TreeNSearch.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,13 @@ void tns::TreeNSearch::set_symmetric_search(const bool activate)
169169
}
170170
void tns::TreeNSearch::set_cell_size(const float cell_size)
171171
{
172+
if (this->cell_size > 0.0) {
173+
std::cout << "tns::TreeNSearch::set_cell_size error: Cell size already set. Create a new TreeNSearch instance if you need a different cell_size." << std::endl;
174+
exit(-1);
175+
}
172176
this->cell_size = cell_size;
173177
this->cell_size_inv = 1.0f / cell_size;
178+
this->are_cells_valid = false;
174179
}
175180
int tns::TreeNSearch::_get_set_pair_id(const int set_i, const int set_j) const
176181
{
@@ -414,7 +419,25 @@ void tns::TreeNSearch::_update_world_AABB()
414419
std::array<float, 3> new_bottom = { MAXf, MAXf, MAXf };
415420
std::array<float, 3> new_top = { MINf, MINf, MINf };
416421

417-
// Find points AABB
422+
// Sequentual computation if points are too few
423+
if (this->get_total_n_points() < this->number_of_too_few_particles) {
424+
for (int set_i = 0; set_i < this->n_sets; set_i++) {
425+
const float* points = this->set_points[set_i];
426+
const int n_points = this->get_n_points_in_set(set_i);
427+
428+
for (int point_i = 0; point_i < n_points; point_i++) {
429+
new_bottom[0] = std::min(new_bottom[0], points[3 * point_i]);
430+
new_bottom[1] = std::min(new_bottom[1], points[3 * point_i + 1]);
431+
new_bottom[2] = std::min(new_bottom[2], points[3 * point_i + 2]);
432+
433+
new_top[0] = std::max(new_top[0], points[3 * point_i]);
434+
new_top[1] = std::max(new_top[1], points[3 * point_i + 1]);
435+
new_top[2] = std::max(new_top[2], points[3 * point_i + 2]);
436+
}
437+
}
438+
}
439+
440+
// Parallel version
418441
// Note: Paralelized across points and sets
419442
for (int set_i = 0; set_i < this->n_sets; set_i++) {
420443
const float* points = this->set_points[set_i];

tests/tests.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -61,25 +61,6 @@ void _compare_tns_with_bruteforce(Points& points, tns::TreeNSearch& nsearch, Bru
6161
std::cout << "\tDifferent n_threads scalar... " << (threads_success ? "passed!" : "xxxxxxx FAILED! xxxxxxx") << std::endl;
6262
nsearch.set_n_threads(omp_get_max_threads());
6363

64-
// Cell size
65-
bool cell_size_success = true;
66-
for (float cell_size = points.search_radius; cell_size < 3.0f * points.search_radius; cell_size += 0.2f * points.search_radius) {
67-
nsearch.set_cell_size(cell_size);
68-
nsearch.run();
69-
cell_size_success = cell_size_success && bruteforce.compare(nsearch, report_when_a_test_fails);
70-
}
71-
std::cout << "\tDifferent cell_size SIMD... " << (cell_size_success ? "passed!" : "xxxxxxx FAILED! xxxxxxx") << std::endl;
72-
nsearch.set_cell_size(1.5f * points.search_radius);
73-
74-
cell_size_success = true;
75-
for (float cell_size = points.search_radius; cell_size < 3.0f * points.search_radius; cell_size += 0.2f * points.search_radius) {
76-
nsearch.set_cell_size(cell_size);
77-
nsearch.run_scalar();
78-
cell_size_success = cell_size_success && bruteforce.compare(nsearch, report_when_a_test_fails);
79-
}
80-
std::cout << "\tDifferent cell_size scalar... " << (cell_size_success ? "passed!" : "xxxxxxx FAILED! xxxxxxx") << std::endl;
81-
nsearch.set_cell_size(1.5f * points.search_radius);
82-
8364
// Recursion cap
8465
bool recursion_cap_success = true;
8566
for (int recursion_cap = 100; recursion_cap < 2000; recursion_cap += 100) {

0 commit comments

Comments
 (0)