/
example_intersection.cpp
79 lines (65 loc) · 2.95 KB
/
example_intersection.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/****************************************************************************
* Copyright (c) 2017-2022 by the ArborX authors *
* All rights reserved. *
* *
* This file is part of the ArborX library. ArborX is *
* distributed under a BSD 3-clause license. For the licensing terms see *
* the LICENSE file in the top-level directory. *
* *
* SPDX-License-Identifier: BSD-3-Clause *
****************************************************************************/
#include <ArborX.hpp>
#include <Kokkos_Core.hpp>
#include <iostream>
int main(int argc, char *argv[])
{
Kokkos::ScopeGuard guard(argc, argv);
using ExecutionSpace = Kokkos::DefaultExecutionSpace;
using MemorySpace = ExecutionSpace::memory_space;
using Box = ArborX::ExperimentalHyperGeometry::Box<2>;
using Point = ArborX::ExperimentalHyperGeometry::Point<2>;
Kokkos::View<Box *, MemorySpace> boxes("Example::boxes", 4);
auto boxes_host = Kokkos::create_mirror_view(boxes);
boxes_host[0] = {{0, 0}, {1, 1}};
boxes_host[1] = {{1, 0}, {2, 1}};
boxes_host[2] = {{0, 1}, {1, 2}};
boxes_host[3] = {{1, 1}, {2, 2}};
Kokkos::deep_copy(boxes, boxes_host);
// -----------
// | | 1 |
// | | 0 |
// |----2----|
// | | |
// | | |
// -----------
Kokkos::View<decltype(ArborX::intersects(Point{})) *, MemorySpace> queries(
"Example::queries", 3);
auto queries_host = Kokkos::create_mirror_view(queries);
queries_host[0] = ArborX::intersects(Point{1.8, 1.5});
queries_host[1] = ArborX::intersects(Point{1.3, 1.7});
queries_host[2] = ArborX::intersects(Point{1, 1});
Kokkos::deep_copy(queries, queries_host);
ExecutionSpace space;
ArborX::BVH<MemorySpace, ArborX::PairValueIndex<Box>> const tree(
space, ArborX::Experimental::attach_indices(boxes));
// The query will resize indices and offsets accordingly
Kokkos::View<int *, MemorySpace> indices("Example::indices", 0);
Kokkos::View<int *, MemorySpace> offsets("Example::offsets", 0);
tree.query(space, queries, indices, offsets);
auto offsets_host =
Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, offsets);
auto indices_host =
Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, indices);
// Expected output:
// offsets: 0 1 2 6
// indices: 3 3 0 2 1 3
// The order of the last 4 indices may vary.
std::cout << "offsets: ";
std::copy(offsets_host.data(), offsets_host.data() + offsets.size(),
std::ostream_iterator<int>(std::cout, " "));
std::cout << "\nindices: ";
std::copy(indices_host.data(), indices_host.data() + indices.size(),
std::ostream_iterator<int>(std::cout, " "));
std::cout << "\n";
return 0;
}