Grangeat-based 2D/3D image registration
Loading...
Searching...
No Matches
Texture3DCUDA.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 Texture3DCUDA : public Texture<3, int64_t, double> {
19public:
20 using Base = Texture<3, int64_t, double>;
21
22 Texture3DCUDA() = default;
23
24 Texture3DCUDA(int64_t _textureHandle, SizeType _size, VectorType _spacing, VectorType _centrePosition = {})
27 }
28
29 Texture3DCUDA(std::shared_ptr<CUDATexture3D> cudaTexture, VectorType _spacing, VectorType _centrePosition = {})
30 : Base(cudaTexture->Size(), std::move(_spacing), std::move(_centrePosition)),
32 }
33
34 // yes copy
35 Texture3DCUDA(const Texture3DCUDA &) = default;
36
37 Texture3DCUDA &operator=(const Texture3DCUDA &) = default;
38
39 // yes move
41
43
52 static Texture3DCUDA FromTensor(const at::Tensor &volume, VectorType spacing,
53 VectorType centrePosition = VectorType::Full(0),
54 AddressModeType addressModes = AddressModeType::Full(TextureAddressMode::ZERO)) {
55 return {std::make_shared<CUDATexture3D>(volume, addressModes), std::move(spacing), std::move(centrePosition)};
56 }
57
59
60 [[nodiscard]] __device__ float Sample(const VectorType &texCoord) const {
62 }
63
65 const VectorType &texCoord) {
66 const float widthF = static_cast<float>(width);
67 const float x = floorf(-.5f + texCoord.X() * widthF);
68 const float x0 = (x + .5f) / widthF;
69 const float x1 = (x + 1.5f) / widthF;
71 textureHandle, x0, texCoord.Y(), texCoord.Z()));
72 }
73
75 const VectorType &texCoord) {
76 const float heightF = static_cast<float>(height);
77 const float y = floorf(-.5f + texCoord.Y() * heightF);
78 const float y0 = (y + .5f) / heightF;
79 const float y1 = (y + 1.5f) / heightF;
81 textureHandle, texCoord.X(), y0, texCoord.Z()));
82 }
83
85 const VectorType &texCoord) {
86 const float depthF = static_cast<float>(depth);
87 const float z = floorf(-.5f + texCoord.Z() * depthF);
88 const float z0 = (z + .5f) / depthF;
89 const float z1 = (z + 1.5f) / depthF;
91 textureHandle, texCoord.X(), texCoord.Y(), z0));
92 }
93
94 [[nodiscard]] __device__ static VectorType DSampleDTexCoord(const SizeType &volumeSize,
96 const VectorType &texCoord) {
97 return {DSampleDX(volumeSize.X(), textureHandle, texCoord), //
98 DSampleDY(volumeSize.Y(), textureHandle, texCoord), //
99 DSampleDZ(volumeSize.Z(), textureHandle, texCoord)};
100 }
101
102 [[nodiscard]] __device__ float DSampleDX(const VectorType &texCoord) const {
103 return DSampleDX(Size().X(), textureHandle, texCoord);
104 }
105
106 [[nodiscard]] __device__ float DSampleDY(const VectorType &texCoord) const {
107 return DSampleDY(Size().Y(), textureHandle, texCoord);
108 }
109
110 [[nodiscard]] __device__ float DSampleDZ(const VectorType &texCoord) const {
111 return DSampleDZ(Size().Z(), textureHandle, texCoord);
112 }
113
114 [[nodiscard]] __device__ VectorType DSampleDTexCoord(const VectorType &texCoord) const {
115 return DSampleDTexCoord(Size(), textureHandle, texCoord);
116 }
117
118private:
120 std::shared_ptr<CUDATexture3D> ownedTexture = nullptr;
121};
122
123} // namespace reg23
124
125#endif
#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