正在加载...
正在搜索...
无匹配项
projection.cuh
前往此文件的文档。
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 * https://apache.ac.cn/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
40
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_;
135 direction constructed_direction_{direction::FORWARD};
136};
137
141
142} // namespace cuproj
void projection(std::vector< operation_type > const &operations, projection_parameters< T > const &params, direction dir=direction::FORWARD)
构造一个新的 projection 对象。
void transform(InputCoordIter first, InputCoordIter last, OutputCoordIter result, direction dir, rmm::cuda_stream_view stream=rmm::cuda_stream_default) const
变换一系列坐标。
device_projection< Coordinate > get_device_projection(direction dir) const
获取一个 device_projection 对象,该对象可以传递给设备代码。
typename detail::pipeline< Coordinate > device_projection
一个可以从 __device__ 代码调用的 projection 对象,用于变换坐标。
direction
枚举变换操作的方向。
direction reverse(direction dir)
返回方向的相反方向。