Loading...
Searching...
No Matches
projection.cuh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023-2024, 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 <cuproj/detail/pipeline.cuh>
20#include <cuproj/ellipsoid.hpp>
23
24#include <rmm/cuda_stream_view.hpp>
25#include <rmm/exec_policy.hpp>
26
27#include <thrust/device_vector.h>
28#include <thrust/transform.h>
29
30#include <iterator>
31#include <type_traits>
32
33namespace cuproj {
34
46template <typename Coordinate>
47using device_projection = typename detail::pipeline<Coordinate>;
48
58template <typename Coordinate, typename T = typename Coordinate::value_type>
60 public:
68 projection(std::vector<operation_type> const& operations,
69 projection_parameters<T> const& params,
70 direction dir = direction::FORWARD)
71 : params_(params), constructed_direction_(dir)
72 {
73 setup(operations);
74 }
75
87 {
88 dir = (constructed_direction_ == direction::FORWARD) ? dir : reverse(dir);
90 params_, operations_.data().get(), operations_.size(), dir};
91 }
92
104 template <class InputCoordIter, class OutputCoordIter>
105 void transform(InputCoordIter first,
106 InputCoordIter last,
107 OutputCoordIter result,
108 direction dir,
109 rmm::cuda_stream_view stream = rmm::cuda_stream_default) const
110 {
111 thrust::transform(rmm::exec_policy(stream), first, last, result, get_device_projection(dir));
112 }
113
114 private:
115 void setup(std::vector<operation_type> const& operations)
116 {
117 std::for_each(operations.begin(), operations.end(), [&](auto const& op) {
118 switch (op) {
119 case operation_type::TRANSVERSE_MERCATOR: {
120 auto op = transverse_mercator<Coordinate>{params_};
121 params_ = op.setup(params_);
122 break;
123 }
124 // TODO: some ops don't have setup. Should we make them all have setup?
125 default: break;
126 }
127 });
128
129 operations_.resize(operations.size());
130 thrust::copy(operations.begin(), operations.end(), operations_.begin());
131 }
132
133 thrust::device_vector<operation_type> operations_;
134 projection_parameters<T> params_;
135 direction constructed_direction_{direction::FORWARD};
136};
137
142} // namespace cuproj
A projection transforms coordinates between coordinate reference systems.
projection(std::vector< operation_type > const &operations, projection_parameters< T > const &params, direction dir=direction::FORWARD)
Construct a new projection object.
void transform(InputCoordIter first, InputCoordIter last, OutputCoordIter result, direction dir, rmm::cuda_stream_view stream=rmm::cuda_stream_default) const
Transform a range of coordinates.
device_projection< Coordinate > get_device_projection(direction dir) const
Get a device_projection object that can be passed to device code.
typename detail::pipeline< Coordinate > device_projection
A projection object that can be invoked from __device__ code to transform coordinates.
direction
Enumerates the direction of a transform operation.
Definition operation.cuh:44
direction reverse(direction dir)
Returns the opposite of a direction.
Definition operation.cuh:47