Loading...
Searching...
No Matches
multipoint_range.cuh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022, 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 <cuspatial/cuda_utils.hpp>
20#include <cuspatial/traits.hpp>
21#include <cuspatial/types.hpp>
22
23#include <thrust/iterator/counting_iterator.h>
24
25namespace cuspatial {
26
52template <typename GeometryIterator, typename VecIterator>
54 public:
55 using geometry_it_t = GeometryIterator;
56 using point_it_t = VecIterator;
57 using index_t = iterator_value_type<geometry_it_t>;
58 using point_t = iterator_value_type<point_it_t>;
59 using element_t = iterator_vec_base_type<point_it_t>;
60
64 CUSPATIAL_HOST_DEVICE multipoint_range(GeometryIterator geometry_begin,
65 GeometryIterator geometry_end,
66 VecIterator points_begin,
67 VecIterator points_end);
68
72 CUSPATIAL_HOST_DEVICE auto num_multipoints();
73
77 CUSPATIAL_HOST_DEVICE auto num_points();
78
82 CUSPATIAL_HOST_DEVICE auto size() { return num_multipoints(); }
83
87 CUSPATIAL_HOST_DEVICE auto multipoint_begin();
88
92 CUSPATIAL_HOST_DEVICE auto multipoint_end();
93
97 CUSPATIAL_HOST_DEVICE auto begin() { return multipoint_begin(); }
98
102 CUSPATIAL_HOST_DEVICE auto end() { return multipoint_end(); }
103
107 CUSPATIAL_HOST_DEVICE auto point_begin();
108
112 CUSPATIAL_HOST_DEVICE auto point_end();
113
117 CUSPATIAL_HOST_DEVICE auto offsets_begin();
118
122 CUSPATIAL_HOST_DEVICE auto offsets_end();
123
127 template <typename IndexType>
128 CUSPATIAL_HOST_DEVICE auto geometry_idx_from_point_idx(IndexType point_idx) const;
129
137 template <typename IndexType>
138 CUSPATIAL_HOST_DEVICE auto operator[](IndexType idx);
139
147 template <typename IndexType>
148 CUSPATIAL_HOST_DEVICE auto point(IndexType idx);
149
154 CUSPATIAL_HOST_DEVICE bool is_single_point_range();
155
156 protected:
158 GeometryIterator _geometry_begin;
160 GeometryIterator _geometry_end;
162 VecIterator _points_begin;
164 VecIterator _points_end;
165};
166
188template <typename GeometryIteratorDiffType,
189 typename VecIteratorDiffType,
190 typename GeometryIterator,
191 typename VecIterator>
192multipoint_range<GeometryIterator, VecIterator> make_multipoint_range(
193 GeometryIteratorDiffType num_multipoints,
194 GeometryIterator geometry_begin,
195 VecIteratorDiffType num_points,
196 VecIterator point_begin)
197{
198 return multipoint_range<GeometryIterator, VecIterator>{
199 geometry_begin, geometry_begin + num_multipoints + 1, point_begin, point_begin + num_points};
200}
201
212template <typename IntegerRange, typename PointRange>
213auto make_multipoint_range(IntegerRange geometry_offsets, PointRange points)
214{
215 return multipoint_range(
216 geometry_offsets.begin(), geometry_offsets.end(), points.begin(), points.end());
217}
218
225template <collection_type_id Type,
226 typename T,
227 typename IndexType,
228 CUSPATIAL_ENABLE_IF(Type == collection_type_id::SINGLE),
229 typename GeometryColumnView>
230auto make_multipoint_range(GeometryColumnView const& points_column)
231{
232 CUSPATIAL_EXPECTS(points_column.geometry_type() == geometry_type_id::POINT,
233 "Must be POINT geometry type.");
234 auto geometry_iter = thrust::make_counting_iterator(0);
235 auto const& points_xy = points_column.child(); // Ignores x-y offset {0, 2, 4...}
236
237 auto points_it = make_vec_2d_iterator(points_xy.template begin<T>());
238
239 return multipoint_range(geometry_iter,
240 thrust::next(geometry_iter, points_column.size() + 1),
241 points_it,
242 points_it + points_xy.size() / 2);
243}
244
251template <collection_type_id Type,
252 typename T,
253 typename IndexType,
254 CUSPATIAL_ENABLE_IF(Type == collection_type_id::MULTI),
255 typename GeometryColumnView>
256auto make_multipoint_range(GeometryColumnView const& points_column)
257{
258 CUSPATIAL_EXPECTS(points_column.geometry_type() == geometry_type_id::POINT,
259 "Must be POINT geometry type.");
260 auto const& geometry_offsets = points_column.offsets();
261 auto const& points_xy = points_column.child().child(1); // Ignores x-y offset {0, 2, 4...}
262
263 auto points_it = make_vec_2d_iterator(points_xy.template begin<T>());
264
265 return multipoint_range(geometry_offsets.template begin<IndexType>(),
266 geometry_offsets.template end<IndexType>(),
267 points_it,
268 points_it + points_xy.size() / 2);
269};
270
275} // namespace cuspatial
276
277#include <cuspatial/detail/range/multipoint_range.cuh>
Non-owning range-based interface to multipoint data.
CUSPATIAL_HOST_DEVICE auto point(IndexType idx)
Returns the idxth point in the array.
CUSPATIAL_HOST_DEVICE auto multipoint_end()
Returns the iterator past the last multipoint in the multipoint array.
CUSPATIAL_HOST_DEVICE auto num_multipoints()
Returns the number of multipoints in the array.
CUSPATIAL_HOST_DEVICE auto size()
Returns the number of multipoints in the array.
CUSPATIAL_HOST_DEVICE auto end()
Returns the iterator past the last multipoint in the multipoint array.
GeometryIterator _geometry_begin
Iterator to the start of the index array of start positions to each multipoint.
CUSPATIAL_HOST_DEVICE auto multipoint_begin()
Returns the iterator to the first multipoint in the multipoint array.
CUSPATIAL_HOST_DEVICE auto point_end()
Returns the iterator to the end of the underlying point array.
CUSPATIAL_HOST_DEVICE auto point_begin()
Returns the iterator to the start of the underlying point array.
CUSPATIAL_HOST_DEVICE auto begin()
Returns the iterator to the start of the multipoint array.
VecIterator _points_end
Iterator to the past-the-end position of the point array.
CUSPATIAL_HOST_DEVICE auto geometry_idx_from_point_idx(IndexType point_idx) const
Returns the geometry index of the given point index.
VecIterator _points_begin
Iterator to the start of the point array.
CUSPATIAL_HOST_DEVICE multipoint_range(GeometryIterator geometry_begin, GeometryIterator geometry_end, VecIterator points_begin, VecIterator points_end)
Construct a new multipoint array object.
CUSPATIAL_HOST_DEVICE auto offsets_begin()
Returns the iterator to the start of the underlying offsets array.
CUSPATIAL_HOST_DEVICE bool is_single_point_range()
Returns true if the range contains only single points Undefined behavior if the range is an empty ran...
CUSPATIAL_HOST_DEVICE auto offsets_end()
Returns the iterator to the end of the underlying offsets array.
CUSPATIAL_HOST_DEVICE auto num_points()
Returns the number of points in the array.
GeometryIterator _geometry_end
Iterator to the past-the-end of the index array of start positions to each multipoint.
CUSPATIAL_HOST_DEVICE auto operator[](IndexType idx)
Returns the idxth multipoint in the array.
#define CUSPATIAL_EXPECTS(cond, reason)
Macro for checking (pre-)conditions that throws an exception when a condition is violated.
Definition error.hpp:76
multipoint_range< GeometryIterator, VecIterator > make_multipoint_range(GeometryIteratorDiffType num_multipoints, GeometryIterator geometry_begin, VecIteratorDiffType num_points, VecIterator point_begin)
Create a multipoint_range object of from size and start iterators.
auto make_vec_2d_iterator(FirstIter first, SecondIter second)
Create an iterator to vec_2d data from two input iterators.