-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor of
pairwise_linestring_distance
to use `multilinestring_ra…
…nge`, adds support to multilinestring distance (#755) Note, this is the first part of `pairwise_linestring_distance` refactoring, part 1 of PR: #753 Depends on #752 Contributes to #706, #703 Closes #745 Authors: - Michael Wang (https://github.com/isVoid) Approvers: - H. Thomson Comer (https://github.com/thomcom) - Mark Harris (https://github.com/harrism) URL: #755
- Loading branch information
Showing
15 changed files
with
1,300 additions
and
333 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
cpp/include/cuspatial/experimental/detail/geometry/linestring_ref.cuh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright (c) 2022, 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/cuda_utils.hpp> | ||
#include <cuspatial/detail/iterator.hpp> | ||
#include <cuspatial/traits.hpp> | ||
|
||
#include <thrust/iterator/zip_iterator.h> | ||
#include <thrust/tuple.h> | ||
|
||
namespace cuspatial { | ||
|
||
template <typename VecIterator> | ||
struct to_segment_functor { | ||
using element_t = iterator_vec_base_type<VecIterator>; | ||
using difference_type = typename thrust::iterator_difference<VecIterator>::type; | ||
VecIterator _point_begin; | ||
|
||
CUSPATIAL_HOST_DEVICE | ||
to_segment_functor(VecIterator point_begin) : _point_begin(point_begin) {} | ||
|
||
CUSPATIAL_HOST_DEVICE | ||
thrust::pair<vec_2d<element_t>, vec_2d<element_t>> operator()(difference_type i) | ||
{ | ||
return {_point_begin[i], _point_begin[i + 1]}; | ||
} | ||
}; | ||
|
||
template <typename VecIterator> | ||
CUSPATIAL_HOST_DEVICE linestring_ref<VecIterator>::linestring_ref(VecIterator begin, | ||
VecIterator end) | ||
: _point_begin(begin), _point_end(end) | ||
{ | ||
using T = iterator_vec_base_type<VecIterator>; | ||
static_assert(is_same<vec_2d<T>, iterator_value_type<VecIterator>>(), "must be vec2d type"); | ||
} | ||
|
||
template <typename VecIterator> | ||
CUSPATIAL_HOST_DEVICE auto linestring_ref<VecIterator>::num_segments() const | ||
{ | ||
// The number of segment equals the number of points minus 1. And the number of points | ||
// is thrust::distance(_point_begin, _point_end) - 1. | ||
return thrust::distance(_point_begin, _point_end) - 1; | ||
} | ||
|
||
template <typename VecIterator> | ||
CUSPATIAL_HOST_DEVICE auto linestring_ref<VecIterator>::segment_begin() const | ||
{ | ||
return detail::make_counting_transform_iterator(0, to_segment_functor{_point_begin}); | ||
} | ||
|
||
template <typename VecIterator> | ||
CUSPATIAL_HOST_DEVICE auto linestring_ref<VecIterator>::segment_end() const | ||
{ | ||
return segment_begin() + num_segments(); | ||
} | ||
|
||
} // namespace cuspatial |
70 changes: 70 additions & 0 deletions
70
cpp/include/cuspatial/experimental/detail/geometry_collection/multilinestring_ref.cuh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#pragma once | ||
|
||
#include "cuspatial/cuda_utils.hpp" | ||
#include <cuspatial/detail/iterator.hpp> | ||
#include <cuspatial/experimental/geometry/linestring_ref.cuh> | ||
|
||
#include <thrust/iterator/transform_iterator.h> | ||
|
||
namespace cuspatial { | ||
|
||
template <typename PartIterator, typename VecIterator> | ||
struct to_linestring_functor { | ||
using difference_type = typename thrust::iterator_difference<PartIterator>::type; | ||
PartIterator part_begin; | ||
VecIterator point_begin; | ||
|
||
CUSPATIAL_HOST_DEVICE | ||
to_linestring_functor(PartIterator part_begin, VecIterator point_begin) | ||
: part_begin(part_begin), point_begin(point_begin) | ||
{ | ||
} | ||
|
||
CUSPATIAL_HOST_DEVICE auto operator()(difference_type i) | ||
{ | ||
return linestring_ref{point_begin + part_begin[i], point_begin + part_begin[i + 1]}; | ||
} | ||
}; | ||
|
||
template <typename PartIterator, typename VecIterator> | ||
class multilinestring_ref; | ||
|
||
template <typename PartIterator, typename VecIterator> | ||
CUSPATIAL_HOST_DEVICE multilinestring_ref<PartIterator, VecIterator>::multilinestring_ref( | ||
PartIterator part_begin, PartIterator part_end, VecIterator point_begin, VecIterator point_end) | ||
: _part_begin(part_begin), _part_end(part_end), _point_begin(point_begin), _point_end(point_end) | ||
{ | ||
} | ||
|
||
template <typename PartIterator, typename VecIterator> | ||
CUSPATIAL_HOST_DEVICE auto multilinestring_ref<PartIterator, VecIterator>::num_linestrings() const | ||
{ | ||
return thrust::distance(_part_begin, _part_end) - 1; | ||
} | ||
|
||
template <typename PartIterator, typename VecIterator> | ||
CUSPATIAL_HOST_DEVICE auto multilinestring_ref<PartIterator, VecIterator>::part_begin() const | ||
{ | ||
return detail::make_counting_transform_iterator(0, | ||
to_linestring_functor{_part_begin, _point_begin}); | ||
} | ||
|
||
template <typename PartIterator, typename VecIterator> | ||
CUSPATIAL_HOST_DEVICE auto multilinestring_ref<PartIterator, VecIterator>::part_end() const | ||
{ | ||
return part_begin() + num_linestrings(); | ||
} | ||
|
||
template <typename PartIterator, typename VecIterator> | ||
CUSPATIAL_HOST_DEVICE auto multilinestring_ref<PartIterator, VecIterator>::point_begin() const | ||
{ | ||
return _point_begin; | ||
} | ||
|
||
template <typename PartIterator, typename VecIterator> | ||
CUSPATIAL_HOST_DEVICE auto multilinestring_ref<PartIterator, VecIterator>::point_end() const | ||
{ | ||
return _point_end; | ||
} | ||
|
||
} // namespace cuspatial |
Oops, something went wrong.