]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix compatibility with nanoflann 1.3. 8030/head
authorDavid Wells <drwells@email.unc.edu>
Tue, 7 May 2019 15:49:04 +0000 (11:49 -0400)
committerDavid Wells <drwells@email.unc.edu>
Tue, 7 May 2019 15:51:18 +0000 (11:51 -0400)
It looks like nanoflann switched to doing all computations with squared
distances so all of our tests currently fail with the latest release. This PR
fixes the problem by adding nanoflann version checks (so our interface is the
same).

source/numerics/kdtree.cc
tests/numerics/kdtree_01.cc

index 27e41afe0ee69202bfe32cd06908e8202cf9c4e6..0d2bdc1658b4276535d3792765d364e92c36e42f 100644 (file)
@@ -48,7 +48,15 @@ KDTree<dim>::get_points_within_ball(const Point<dim> &center,
   params.sorted = sorted;
 
   std::vector<std::pair<unsigned int, double>> matches;
+#  if NANOFLANN_VERSION < 0x130
   kdtree->radiusSearch(center.begin_raw(), radius, matches, params);
+#  else
+  // nanoflann 1.3 performs distance comparisons with squared distances, so
+  // square the radius before we query and square root after:
+  kdtree->radiusSearch(center.begin_raw(), radius * radius, matches, params);
+  for (std::pair<unsigned int, double> &match : matches)
+    match.second = std::sqrt(match.second);
+#  endif
 
   return matches;
 }
@@ -75,7 +83,13 @@ KDTree<dim>::get_closest_points(const Point<dim> & target,
   // convert it to the format we want to return
   std::vector<std::pair<unsigned int, double>> matches(n_points);
   for (unsigned int i = 0; i < n_points; ++i)
+#  if NANOFLANN_VERSION < 0x130
     matches[i] = std::make_pair(indices[i], distances[i]);
+#  else
+    // nanoflann 1.3 performs distance comparisons with squared distances, so
+    // take a square root:
+    matches[i] = std::make_pair(indices[i], std::sqrt(distances[i]));
+#  endif
 
   return matches;
 }
index 4f05bf259d4b75846f26fa8ccfddf59fe57e3c64..a28c22e764ad2c97d8ad0128c0698b10094a8fd3 100644 (file)
@@ -50,6 +50,8 @@ main()
       auto res = kdtree.get_closest_points(p, 1)[0];
       deallog << "P: " << p << ", distance: " << res.second
               << ", index: " << res.first << std::endl;
+      AssertThrow(std::abs(points[res.first].distance(p) - res.second) < 1e-10,
+                  ExcInternalError());
     }
 
   deallog

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.