From: Luca Heltai Date: Tue, 24 Jul 2018 21:41:33 +0000 (+0200) Subject: Some rtree tests with Points. X-Git-Tag: v9.1.0-rc1~881^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=598e34f9ace4335a0fc43b489a6be23358714fb1;p=dealii.git Some rtree tests with Points. --- diff --git a/tests/boost/rtree_01.cc b/tests/boost/rtree_01.cc new file mode 100644 index 0000000000..56b2711fe8 --- /dev/null +++ b/tests/boost/rtree_01.cc @@ -0,0 +1,102 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2018 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + +// Check that we can construct a tree with dealii::Point + +#include + +#include + +#include + +#include "../tests.h" + +using Patterns::Tools::to_string; + +namespace bg = boost::geometry; +namespace bgi = boost::geometry::index; + +template +using LinearPointRtree = bgi::rtree, bgi::linear>; + +template +using QuadraticPointRtree = bgi::rtree, bgi::quadratic>; + +template +using RstarPointRtree = bgi::rtree, bgi::rstar>; + +int +main(int argc, char **argv) +{ + initlog(); + + // N random points in the box. + const unsigned int N = 100; + std::vector> points(N); + std::generate(points.begin(), points.end(), []() { + return random_point<2>(); + }); + + LinearPointRtree<2> linear_tree; + linear_tree.insert(points.begin(), points.end()); + + QuadraticPointRtree<2> quadratic_tree; + quadratic_tree.insert(points.begin(), points.end()); + + RstarPointRtree<2> rstar_tree; + rstar_tree.insert(points.begin(), points.end()); + + AssertDimension(linear_tree.size(), N); + AssertDimension(quadratic_tree.size(), N); + AssertDimension(rstar_tree.size(), N); + + // Now take the middle point, and ask for the k nearest neighbors + Point<2> p(.5, .5); + // Return only the first two points, so that the order is unique + const unsigned int k = 2; + std::vector> nearest_linear; + std::vector> nearest_quadratic; + std::vector> nearest_rstar; + + linear_tree.query(bgi::nearest(p, k), std::back_inserter(nearest_linear)); + quadratic_tree.query(bgi::nearest(p, k), + std::back_inserter(nearest_quadratic)); + rstar_tree.query(bgi::nearest(p, k), std::back_inserter(nearest_rstar)); + + AssertDimension(nearest_linear.size(), k); + AssertDimension(nearest_quadratic.size(), k); + AssertDimension(nearest_rstar.size(), k); + + if (std::equal(nearest_linear.begin(), + nearest_linear.end(), + nearest_quadratic.begin())) + deallog << "OK"; + else + { + deallog << "Not OK: check " << std::endl + << to_string(nearest_linear) << std::endl + << to_string(nearest_quadratic) << std::endl; + } + if (std::equal(nearest_linear.begin(), + nearest_linear.end(), + nearest_rstar.begin())) + deallog << "OK"; + else + { + deallog << "Not OK: check " << std::endl + << to_string(nearest_linear) << std::endl + << to_string(nearest_rstar) << std::endl; + } +} diff --git a/tests/boost/rtree_01.output b/tests/boost/rtree_01.output new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/tests/boost/rtree_01.output @@ -0,0 +1 @@ +