Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Header-only quadtree_point_to_nearest_linestring #1005

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
3450ecb
Improve parameter documentation in point_quadtree
harrism Mar 8, 2023
1d60510
copyright
harrism Mar 8, 2023
85bc49d
Initial prototype of quadtree_point_in_polygon
harrism Mar 8, 2023
d00773d
Remove TODO since this PR is finishing it.
harrism Mar 9, 2023
76bbc8e
Templatize
harrism Mar 9, 2023
b59467a
Initial header-only implementation (untested)
harrism Mar 9, 2023
e61f33b
Fix stream/mr parameter order
harrism Mar 15, 2023
42ca6de
Working header-only refactor
harrism Mar 15, 2023
411cc35
Merge branch 'branch-23.04' into fea-header-only-quadtree-pip
harrism Mar 15, 2023
8785316
Merge branch 'branch-23.04' into fea-header-only-quadtree-pip
harrism Mar 21, 2023
a37eefc
Fix include path.
harrism Mar 21, 2023
f31fe78
stream, mr
harrism Mar 21, 2023
dd61ed8
stream, mr
harrism Mar 21, 2023
4c7aede
Port small test to header-only API.
harrism Mar 21, 2023
6659278
Port large test to header-only API
harrism Mar 21, 2023
3465ada
Add `point_quadtree_ref` class and use to simplify APIs
harrism Mar 21, 2023
8e2b426
style
harrism Mar 21, 2023
a2e2dfb
Replace separate x_min/y_min with vec_2d
harrism Mar 21, 2023
7bb397d
Use c++17 for building tests!
harrism Mar 21, 2023
987c56d
Use multipolygon_range
harrism Mar 22, 2023
1c605d3
Style
harrism Mar 22, 2023
d49366d
Merge branch 'branch-23.04' into fea-header-only-quadtree-pip
harrism Mar 22, 2023
61c330e
Fix CUSPATIAL_EXPECTS call
harrism Mar 22, 2023
d5455f3
Add missing includes.
harrism Mar 22, 2023
d1bc4a8
Merge branch 'branch-23.04' into fea-header-only-quadtree-pip
harrism Mar 22, 2023
17e6223
style
harrism Mar 22, 2023
69381ad
Fix benchmarks build
harrism Mar 22, 2023
c819ac0
Review feedback.
harrism Mar 22, 2023
c2369be
style
harrism Mar 22, 2023
4531c9c
Passing C++, failing Pytest
harrism Mar 23, 2023
63a39b2
Merge branch 'fea-header-only-quadtree-pip' into fea-header-only-quad…
harrism Mar 23, 2023
f02de59
style
harrism Mar 23, 2023
f8df520
Make is_vec_2d more generic and update usage.
harrism Mar 28, 2023
cab59f3
Use thrust::raw_reference_cast
harrism Mar 28, 2023
57417bf
Refactor test
harrism Mar 28, 2023
71ba3c0
Add and use linestring sizes validation macro(s).
harrism Mar 28, 2023
a14586c
[part|ring]_begin --> [part|ring]_offset_begin etc.
harrism Mar 28, 2023
db0a3d3
Fix error reason
harrism Mar 28, 2023
17ae8ae
Error tests
harrism Mar 28, 2023
89f02ac
Merge branch 'fea-header-only-quadtree-pip' into fea-header-only-quad…
harrism Mar 28, 2023
281de32
Fix validation
harrism Mar 28, 2023
78445af
Remove old test, add error (column-based) test
harrism Mar 28, 2023
6e89da4
style
harrism Mar 28, 2023
baaf578
Spelling
harrism Mar 28, 2023
c1467d1
Merge branch 'fea-header-only-quadtree-pip' into fea-header-only-quad…
harrism Mar 28, 2023
9e2e43e
Spelling
harrism Mar 28, 2023
934d841
Merge branch 'branch-23.04' into fea-header-only-quadtree-pip
harrism Mar 28, 2023
7d226ca
Merge branch 'fea-header-only-quadtree-pip' into fea-header-only-quad…
harrism Mar 28, 2023
72be747
Fix polygon/linestring data in pytests
harrism Mar 28, 2023
acdd9ab
Re-add protected
harrism Mar 29, 2023
71d69e2
Merge branch 'branch-23.04' of github.com:rapidsai/cuspatial into fea…
harrism Mar 29, 2023
39a0c48
Feedback from @isVoid
harrism Mar 29, 2023
1885ded
"" -> <>
harrism Mar 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cpp/benchmarks/points_in_range.cu
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

#include <memory>

using namespace cuspatial;
using cuspatial::vec_2d;

/**
* @brief Helper to generate random points within a range
Expand Down
45 changes: 45 additions & 0 deletions cpp/include/cuspatial/detail/utility/validation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,51 @@

#include <cuspatial/error.hpp>

/**
* @brief Macro for validating the data array sizes for linestrings.
*
* Raises an exception if any of the following are false:
* - The number of linestring offsets is greater than zero.
* - There are at least two vertices per linestring offset.
*
* Linestrings follow [GeoArrow data layout][1]. Offsets arrays have one more element than the
* number of items in the array. The last offset is always the sum of the previous offset and the
* size of that element. For example the last value in the linestring offsets array is the
* last linestring offset plus one. See [Arrow Variable-Size Binary layout](2). Note that an
* empty list still has one offset: {0}.
*
* [1]: https://github.com/geoarrow/geoarrow/blob/main/format.md
* [2]: https://arrow.apache.org/docs/format/Columnar.html#variable-size-binary-layout
*/
#define CUSPATIAL_EXPECTS_VALID_LINESTRING_SIZES(num_linestring_points, num_linestring_offsets) \
CUSPATIAL_EXPECTS(num_linestring_offsets > 0, \
"Polygon offsets must contain at least one (1) value"); \
CUSPATIAL_EXPECTS(num_linestring_points >= 2 * (num_linestring_offsets - 1), \
"Each linestring must have at least two vertices");

/**
* @brief Macro for validating the data array sizes for multilinestrings.
*
* Raises an exception if any of the following are false:
* - The number of multilinestring offsets is greater than zero.
* - The number of linestring offsets is greater than zero.
* - There are at least two vertices per linestring offset.
*
* Multilinestrings follow [GeoArrow data layout][1]. Offsets arrays have one more element than the
* number of items in the array. The last offset is always the sum of the previous offset and the
* size of that element. For example the last value in the linestring offsets array is the
* last linestring offset plus one. See [Arrow Variable-Size Binary layout](2). Note that an
* empty list still has one offset: {0}.
*
* [1]: https://github.com/geoarrow/geoarrow/blob/main/format.md
* [2]: https://arrow.apache.org/docs/format/Columnar.html#variable-size-binary-layout
*/
#define CUSPATIAL_EXPECTS_VALID_MULTILINESTRING_SIZES( \
num_linestring_points, num_multilinestring_offsets, num_linestring_offsets) \
CUSPATIAL_EXPECTS(num_multilinestring_offsets > 0, \
"Multilinestring offsets must contain at least one (1) value"); \
CUSPATIAL_EXPECTS_VALID_LINESTRING_SIZES(num_linestring_points, num_linestring_offsets);

/**
* @brief Macro for validating the data array sizes for a polygon.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace cuspatial {
namespace detail {

/**
* @brief Kernel to test if a point is inside a polygon.
* @brief Test if a point is inside a polygon.
*
* Implemented based on Eric Haines's crossings-multiply algorithm:
* See "Crossings test" section of http://erich.realtimerendering.com/ptinpoly/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2023, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include <cuspatial/experimental/geometry/linestring_ref.cuh>
#include <cuspatial/experimental/geometry/segment.cuh>
#include <cuspatial/vec_2d.hpp>

namespace cuspatial {
namespace detail {

template <typename T>
__device__ T proj2(segment<T> const& s, vec_2d<T> const& v)
{
return dot(v - s.v1, s.v2 - s.v1);
}

template <typename T, typename LinestringRef>
inline __device__ T point_linestring_distance(vec_2d<T> const& point,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we can simplify point_to_segment_distance_squared in linestring.cuh with this API?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think it can be simplified, or factored in a way to maximize reuse.

LinestringRef const& linestring)
{
T distance_squared = std::numeric_limits<T>::max();

for (auto const& s : linestring) {
auto v1p = point - s.v1;
auto v2p = point - s.v2;
auto d0 = dot(v1p, v1p);
auto d1 = dot(v2p, v2p);
auto d2 = s.length2();
auto d3 = proj2(s, point);
auto const r = d3 * d3 / d2;
auto const d = (d3 <= 0 || r >= d2) ? min(d0, d1) : d0 - r;
distance_squared = min(distance_squared, d);
}

return sqrt(distance_squared);
}

} // namespace detail
} // namespace cuspatial
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ BoundingBoxIterator linestring_bounding_boxes(LinestringOffsetIterator linestrin
T expansion_radius,
rmm::cuda_stream_view stream)
{
static_assert(is_same<T, iterator_vec_base_type<VertexIterator>>(),
"expansion_radius type must match vertex floating-point type");

static_assert(is_floating_point<T>(), "Only floating point polygon vertices supported");

static_assert(is_same<vec_2d<T>, iterator_value_type<VertexIterator>>(),
static_assert(is_vec_2d<iterator_value_type<VertexIterator>>,
"Input vertices must be cuspatial::vec_2d");

static_assert(cuspatial::is_integral<iterator_value_type<LinestringOffsetIterator>>(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ BoundingBoxIterator polygon_bounding_boxes(PolygonOffsetIterator polygon_offsets
T expansion_radius,
rmm::cuda_stream_view stream)
{
static_assert(is_same<T, iterator_vec_base_type<VertexIterator>>(),
"expansion_radius type must match vertex floating-point type");

static_assert(is_floating_point<T>(), "Only floating point polygon vertices supported");

static_assert(is_same<vec_2d<T>, iterator_value_type<VertexIterator>>(),
static_assert(is_vec_2d<iterator_value_type<VertexIterator>>,
"Input vertices must be cuspatial::vec_2d");

static_assert(cuspatial::is_integral<iterator_value_type<PolygonOffsetIterator>,
Expand Down
Loading