Grangeat-based 2D/3D image registration
Loading...
Searching...
No Matches
Texture.h
Go to the documentation of this file.
1#pragma once
2
3#include "Common.h"
4#include "Vec.h"
5
6namespace reg23 {
7
19 ZERO,
20 WRAP
23};
24
25#ifdef __CUDACC__
27 switch (tam) {
32 default:
34 }
35}
36#endif
37
45 const std::array<std::string_view, DIMENSIONALITY> &strings) {
46 using AddressModeType = Vec<TextureAddressMode, DIMENSIONALITY>;
47 AddressModeType ret = AddressModeType::Full(TextureAddressMode::ZERO);
48 int dim = 0;
49 for (const std::string_view &str : strings) {
50 if (str == "wrap") {
52 } else if (str != "zero") {
54 "Invalid address mode string given. Valid values are: 'zero', 'wrap'. Using default value: 'zero'.")
55 }
56 ++dim;
57 }
58 return ret;
59}
60
71template <std::size_t dimensionality, typename intType = int, typename floatType = float> class Texture {
72public:
73 static constexpr std::size_t DIMENSIONALITY = dimensionality;
79
82 [[nodiscard]] __host__ __device__ const SizeType &Size() const { return size; }
84 [[nodiscard]] __host__ __device__ const VectorType &Spacing() const { return spacing; }
86 [[nodiscard]] __host__ __device__ const VectorType &CentrePosition() const { return centrePosition; }
87
92 return size.template StaticCast<FloatType>() * spacing;
93 }
94
99 [[nodiscard]] __host__ __device__ bool In(const SizeType &index) const {
100 return (index >= SizeType{}).BooleanAll() && (index < size).BooleanAll();
101 }
102
112
113protected:
114 Texture() = default;
115
117 : size(_size), spacing(_spacing), centrePosition(_centrePosition) {
118 }
119
120 // yes copy
121 Texture(const Texture &) = default;
122
123 Texture &operator=(const Texture &) = default;
124
125 // yes move
127
129
130private:
133 SizeType size{};
134 VectorType spacing{};
135 VectorType centrePosition{};
136};
137
142} // namespace reg23
General tools and structs.
#define __host__
Definition Global.h:17
#define __device__
Definition Global.h:22
A parent texture class containing template data and functionality.
Definition Texture.h:71
__host__ __device__ const SizeType & Size() const
Definition Texture.h:82
static constexpr std::size_t DIMENSIONALITY
Definition Texture.h:73
floatType FloatType
Definition Texture.h:75
Texture(const Texture &)=default
__host__ __device__ const VectorType & Spacing() const
Get the spacing of the texture's values in world coordinates as (X, Y, Z)
Definition Texture.h:84
Vec< floatType, dimensionality > VectorType
Definition Texture.h:77
__host__ __device__ const VectorType & CentrePosition() const
Get the position of the centre of the texture in world coordinates as (X, Y, Z)
Definition Texture.h:86
__host__ __device__ Linear< VectorType > MappingWorldToTexCoord() const
Definition Texture.h:107
Texture & operator=(const Texture &)=default
__host__ __device__ VectorType SizeWorld() const
Definition Texture.h:91
Texture(SizeType _size, VectorType _spacing, VectorType _centrePosition={})
Definition Texture.h:116
intType IntType
Definition Texture.h:74
Texture(Texture &&) noexcept=default
__host__ __device__ bool In(const SizeType &index) const
Definition Texture.h:99
Texture()=default
A simple vector class derived from std::array<T, N>, providing overrides for all useful operators.
Definition Vec.h:21
__host__ static __device__ constexpr Vec Full(const T &value)
Construct a Vec, copying the given value into every element.
Definition Vec.h:64
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
A functor class that represents a linear transformation: intercept + gradient * x.
Definition Common.h:27