Loading...
Searching...
No Matches
coordinate_generator.cuh
1/*
2 * Copyright (c) 2023, NVIDIA CORPORATION.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <rmm/exec_policy.hpp>
20
21#include <thrust/iterator/counting_iterator.h>
22#include <thrust/iterator/transform_iterator.h>
23#include <thrust/tabulate.h>
24
25namespace cuproj_test {
26
27// Generate a grid of coordinates
28template <typename Coord>
30 Coord min_corner{};
31 Coord max_corner{};
32 Coord spacing{};
33 int num_points_x{};
34
35 grid_generator(Coord const& min_corner,
36 Coord const& max_corner,
37 int num_points_x,
38 int num_points_y)
39 : min_corner(min_corner), max_corner(max_corner), num_points_x(num_points_x)
40 {
41 spacing = Coord{(max_corner.x - min_corner.x) / num_points_x,
42 (max_corner.y - min_corner.y) / num_points_y};
43 }
44
45 __device__ Coord operator()(int i) const
46 {
47 return min_corner + Coord{(i % num_points_x) * spacing.x, (i / num_points_x) * spacing.y};
48 }
49};
50
51// Create a Vector containing a grid of coordinates between the min and max corners
52template <typename Coord, typename Vector>
53auto make_grid_array(Coord const& min_corner,
54 Coord const& max_corner,
55 int num_points_x,
56 int num_points_y)
57{
58 auto gen = grid_generator(min_corner, max_corner, num_points_x, num_points_y);
59 Vector grid(num_points_x * num_points_y);
60 thrust::tabulate(rmm::exec_policy(), grid.begin(), grid.end(), gen);
61 return grid;
62}
63
64} // namespace cuproj_test