Grangeat-based 2D/3D image registration
Loading...
Searching...
No Matches
Texture2DCUDA.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef __CUDACC__
4
5#include "Texture.h"
6#include "CUDATexture.h"
7
8namespace reg23 {
9
18class Texture2DCUDA : public Texture<2, int64_t, double> {
19public:
20 using Base = Texture<2, int64_t, double>;
21
22 Texture2DCUDA() = default;
23
24 Texture2DCUDA(int64_t _textureHandle, SizeType _size, VectorType _spacing, VectorType _centrePosition = {})
26 }
27
28 Texture2DCUDA(std::shared_ptr<CUDATexture2D> cudaTexture, VectorType _spacing, VectorType _centrePosition = {})
29 : Base(cudaTexture->Size(), std::move(_spacing), std::move(_centrePosition)),
31 }
32
33 // yes copy
34 Texture2DCUDA(const Texture2DCUDA &) = default;
35
36 Texture2DCUDA &operator=(const Texture2DCUDA &) = default;
37
38 // yes move
40
42
51 static Texture2DCUDA FromTensor(const at::Tensor &image, VectorType spacing,
52 VectorType centrePosition = VectorType::Full(0),
53 AddressModeType addressModes = AddressModeType::Full(TextureAddressMode::ZERO)) {
54 return {std::make_shared<CUDATexture2D>(image, addressModes), std::move(spacing), std::move(centrePosition)};
55 }
56
58
59 [[nodiscard]] __device__ float Sample(const VectorType &texCoord) const {
61 }
62
63 [[nodiscard]] __device__ float DSampleDX(const VectorType &texCoord) const {
64 const float widthF = static_cast<float>(Size().X());
65 const float x = floorf(-.5f + texCoord.X() * widthF);
66 const float x0 = (x + .5f) / widthF;
67 const float x1 = (x + 1.5f) / widthF;
69 }
70
71 [[nodiscard]] __device__ float DSampleDY(const VectorType &texCoord) const {
72 const float heightF = static_cast<float>(Size().Y());
73 const float y = floorf(-.5f + texCoord.Y() * heightF);
74 const float y0 = (y + .5f) / heightF;
75 const float y1 = (y + 1.5f) / heightF;
77 float>(textureHandle, texCoord.X(), y0));
78 }
79
80 [[nodiscard]] __device__ VectorType DSampleDTexCoord(const VectorType &texCoord) const {
81 return {DSampleDX(texCoord), DSampleDY(texCoord)};
82 }
83
84private:
86 std::shared_ptr<CUDATexture2D> ownedTexture = nullptr;
87};
88
89} // namespace reg23
90
91#endif
#define __host__
Definition Global.h:17
#define __device__
Definition Global.h:22
Vec< TextureAddressMode, DIMENSIONALITY > StringsToAddressModes(const std::array< std::string_view, DIMENSIONALITY > &strings)
Definition Texture.h:44
TextureAddressMode
Definition Texture.h:18
@ ZERO
Sampling locations outside texture coordinate range will be read as 0.
Definition GridSample3DCPU.cpp:6