Grangeat-based 2D/3D image registration
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
reg23::Vec< T, N > Class Template Reference

A simple vector class derived from std::array<T, N>, providing overrides for all useful operators. More...

#include <Vec.h>

Inheritance diagram for reg23::Vec< T, N >:

Public Types

using ElementType = T
 
using Base = std::array< T, N >
 

Public Member Functions

__host__ __device__ Vec ()
 Default construct all elements.
 
__host__ __device__ Vec (Base array)
 Construct from a std::array (this is the base class of Vec)
 
__host__ __device__ Vec (std::initializer_list< T > l)
 Construct from a series of values.
 
__host__ __device__ constexpr at::IntArrayRef ToIntArrayRef () const
 Convert to an at::IntArrayRef (this is the type of at::Tensor::sizes())
 
__host__ at::Tensor ToTensor (at::TensorOptions options={}, bool nonOwning=false) const
 Convert to an at::Tensor
 
__host__ __device__ constexpr Vec Flipped () const
 Construct a Vec with the same elements, but in the reverse order.
 
__host__ __device__ constexpr T Sum () const
 Compute the sum of all elements.
 
__host__ __device__ constexpr T Min () const
 Find the smallest element.
 
__host__ __device__ constexpr T Max () const
 Find the largest element.
 
__host__ __device__ constexpr std::pair< T, TMinMax () const
 Find the smallest and largest elements.
 
__host__ __device__ constexpr Vec< T, 3 > DeHomogenise () const
 Compute the 3-vector for this homogeneous vector, = (x, y, z) / w.
 
template<typename newT >
__host__ __device__ constexpr Vec< newT, NStaticCast () const
 Construct a Vec with the elements form this one cast to a new type.
 
__host__ __device__ constexpr T Length () const
 Compute the L^2 norm.
 
__host__ __device__ constexpr bool BooleanAll () const
 Compute the combination of all elements using the AND operator.
 
__host__ __device__ constexpr bool BooleanAny () const
 Compute the combination of all elements using the OR operator.
 
template<typename newT >
__host__ __device__ constexpr Vec< newT, NApply (const std::function< newT(T)> &f) const
 Map all elements with a common std::function mapping function.
 
template<typename newT >
__host__ __device__ constexpr Vec< newT, NApply (const std::function< newT(const T &)> &f) const
 Map all elements with a common std::function mapping function.
 
template<typename newT >
__host__ __device__ constexpr Vec< newT, NApply (newT(*f)(T)) const
 Map all elements with a common C-style mapping function.
 
template<typename newT >
__host__ __device__ constexpr Vec< newT, NApply (newT(*f)(const T &)) const
 Map all elements with a common C-style mapping function.
 
__host__ __device__ Vecoperator+= (const Vec &other)
 Element-wise addition of another Vec.
 
template<typename scalar_t >
__host__ __device__ Vecoperator+= (const scalar_t &scalar)
 Element-wise addition of a scalar.
 
__host__ __device__ Vecoperator-= (const Vec &other)
 Element-wise subtraction of another Vec.
 
template<typename scalar_t >
__host__ __device__ Vecoperator-= (const scalar_t &scalar)
 Element-wise subtraction of a scalar.
 
__host__ __device__ Vecoperator*= (const Vec &other)
 Element-wise multiplication by another Vec.
 
template<typename scalar_t >
__host__ __device__ Vecoperator*= (const scalar_t &scalar)
 Element-wise multiplication by a scalar.
 
__host__ __device__ Vecoperator/= (const Vec &other)
 Element-wise division by another Vec.
 
template<typename scalar_t >
__host__ __device__ Vecoperator/= (const scalar_t &scalar)
 Element-wise division by a scalar.
 
__host__ __device__ constexpr const TX () const
 Get a constant reference to the first element.
 
__host__ __device__ constexpr TX ()
 Get the first element.
 
__host__ __device__ constexpr const TY () const
 Get a constant reference to the second element.
 
__host__ __device__ constexpr TY ()
 Get the second element.
 
__host__ __device__ constexpr const TZ () const
 Get a constant reference to the third element.
 
__host__ __device__ constexpr TZ ()
 Get the third element.
 
__host__ __device__ constexpr const TW () const
 Get a constant reference to the fourth element.
 
__host__ __device__ constexpr TW ()
 Get the fourth element.
 
__host__ __device__ constexpr Vec< T, 2 > XY () const
 Construct a Vec from the first two elements.
 
__host__ __device__ constexpr Vec< T, 3 > XYZ () const
 Construct a Vec from the first three elements.
 

Static Public Member Functions

__host__ static __device__ constexpr Vec Full (const T &value)
 Construct a Vec, copying the given value into every element.
 
__host__ static __device__ constexpr Vec Range (const T &start=T{0}, const T &step=T{1})
 Construct a Vec where the ith element is start + i * step
 
__host__ static __device__ constexpr Vec FromIntArrayRef (const at::IntArrayRef &v)
 Construct a Vec from an at::IntArrayRef (this is the type of at::Tensor::sizes())
 
static __host__ Vec FromTensor (const at::Tensor &t)
 Construct a Vec from a 1D PyTorch tensor.
 
static __host__ constexpr Vec Identity ()
 Construct an identity matrix.
 
static __host__ Vec FromTensor2D (const at::Tensor &t)
 Construct a matrix from a 2D PyTorch tensor.
 

Static Public Attributes

static constexpr std::size_t dimensionality = N
 

Detailed Description

template<typename T, std::size_t N>
class reg23::Vec< T, N >

A simple vector class derived from std::array<T, N>, providing overrides for all useful operators.

Template Parameters
TThe type of the vector's elements
NThe size/dimensionality of the vector; must be greater than 0

Member Typedef Documentation

◆ Base

template<typename T , std::size_t N>
using reg23::Vec< T, N >::Base = std::array<T, N>

◆ ElementType

template<typename T , std::size_t N>
using reg23::Vec< T, N >::ElementType = T

Constructor & Destructor Documentation

◆ Vec() [1/3]

template<typename T , std::size_t N>
__host__ __device__ reg23::Vec< T, N >::Vec ( )
inline

Default construct all elements.

◆ Vec() [2/3]

template<typename T , std::size_t N>
__host__ __device__ reg23::Vec< T, N >::Vec ( Base  array)
inline

Construct from a std::array (this is the base class of Vec)

◆ Vec() [3/3]

template<typename T , std::size_t N>
__host__ __device__ reg23::Vec< T, N >::Vec ( std::initializer_list< T l)
inline

Construct from a series of values.

Member Function Documentation

◆ Apply() [1/4]

template<typename T , std::size_t N>
template<typename newT >
__host__ __device__ constexpr Vec< newT, N > reg23::Vec< T, N >::Apply ( const std::function< newT(const T &)> &  f) const
inlineconstexpr

Map all elements with a common std::function mapping function.

Template Parameters
newTThe element type of the returned vector
Parameters
fA function with which to map each element of this vector
Returns
A Vec with the elements mapped from those of this vector using f

◆ Apply() [2/4]

template<typename T , std::size_t N>
template<typename newT >
__host__ __device__ constexpr Vec< newT, N > reg23::Vec< T, N >::Apply ( const std::function< newT(T)> &  f) const
inlineconstexpr

Map all elements with a common std::function mapping function.

Template Parameters
newTThe element type of the returned vector
Parameters
fA function with which to map each element of this vector
Returns
A Vec with the elements mapped from those of this vector using f

◆ Apply() [3/4]

template<typename T , std::size_t N>
template<typename newT >
__host__ __device__ constexpr Vec< newT, N > reg23::Vec< T, N >::Apply ( newT(*)(const T &)  f) const
inlineconstexpr

Map all elements with a common C-style mapping function.

Template Parameters
newTThe element type of the returned vector
Parameters
fA function with which to map each element of this vector
Returns
A Vec with the elements mapped from those of this vector using f

◆ Apply() [4/4]

template<typename T , std::size_t N>
template<typename newT >
__host__ __device__ constexpr Vec< newT, N > reg23::Vec< T, N >::Apply ( newT(*)(T f) const
inlineconstexpr

Map all elements with a common C-style mapping function.

Template Parameters
newTThe element type of the returned vector
Parameters
fA function with which to map each element of this vector
Returns
A Vec with the elements mapped from those of this vector using f

◆ BooleanAll()

template<typename T , std::size_t N>
__host__ __device__ constexpr bool reg23::Vec< T, N >::BooleanAll ( ) const
inlineconstexpr

Compute the combination of all elements using the AND operator.

Returns
Whether all elements of the vector are true

For boolean vectors only

◆ BooleanAny()

template<typename T , std::size_t N>
__host__ __device__ constexpr bool reg23::Vec< T, N >::BooleanAny ( ) const
inlineconstexpr

Compute the combination of all elements using the OR operator.

Returns
Whether any elements of the vector are true

For boolean vectors only

◆ DeHomogenise()

template<typename T , std::size_t N>
__host__ __device__ constexpr Vec< T, 3 > reg23::Vec< T, N >::DeHomogenise ( ) const
inlineconstexpr

Compute the 3-vector for this homogeneous vector, = (x, y, z) / w.

Returns
The 3-vector corresponding to this homogeneous 4-vector, i.e. (x, y, z) / w

For floating-point 4-vectors only.

◆ Flipped()

template<typename T , std::size_t N>
__host__ __device__ constexpr Vec reg23::Vec< T, N >::Flipped ( ) const
inlineconstexpr

Construct a Vec with the same elements, but in the reverse order.

Returns
A copy of this vector, with the order of the elements reversed

◆ FromIntArrayRef()

template<typename T , std::size_t N>
__host__ static __device__ constexpr Vec reg23::Vec< T, N >::FromIntArrayRef ( const at::IntArrayRef &  v)
inlinestaticconstexpr

Construct a Vec from an at::IntArrayRef (this is the type of at::Tensor::sizes())

◆ FromTensor()

template<typename T , std::size_t N>
static __host__ Vec reg23::Vec< T, N >::FromTensor ( const at::Tensor &  t)
inlinestatic

Construct a Vec from a 1D PyTorch tensor.

Parameters
ta tensor of size (N,); the contained type must be consistent with the vector's type, i.e. for a Vec<float32_t, N>, t must contain values of type torch.float32.
Returns
A Vec filled with the values copied from the given tensor

◆ FromTensor2D()

template<typename T , std::size_t N>
static __host__ Vec reg23::Vec< T, N >::FromTensor2D ( const at::Tensor &  t)
inlinestatic

Construct a matrix from a 2D PyTorch tensor.

Parameters
ta tensor of size (N, T::dimensionality). The contained type must be consistent with the vector's type, i.e. for a Vec<Vec<float32_t, C>, R>, t must contain values of type torch.float32.
Returns
A Vec (of Vecs) filled with the values copied from the given tensor

Only valid for Vec of contained type T that is a specialisation of Vec, e.g. Vec<Vec<float, C>, R>

◆ Full()

template<typename T , std::size_t N>
__host__ static __device__ constexpr Vec reg23::Vec< T, N >::Full ( const T value)
inlinestaticconstexpr

Construct a Vec, copying the given value into every element.

◆ Identity()

template<typename T , std::size_t N>
static __host__ constexpr Vec reg23::Vec< T, N >::Identity ( )
inlinestaticconstexpr

Construct an identity matrix.

Returns
A Vec (of Vecs) filled as an identity matrix

Only valid for Vec of contained type T that is a specialisation of Vec with the same size, e.g. Vec<Vec<float, N>, N>

◆ Length()

template<typename T , std::size_t N>
__host__ __device__ constexpr T reg23::Vec< T, N >::Length ( ) const
inlineconstexpr

Compute the L^2 norm.

Returns
The L^2 norm of this vector

◆ Max()

template<typename T , std::size_t N>
__host__ __device__ constexpr T reg23::Vec< T, N >::Max ( ) const
inlineconstexpr

Find the largest element.

Returns
The largest element in the vector. No ordering is assumed; operation is O(N).

◆ Min()

template<typename T , std::size_t N>
__host__ __device__ constexpr T reg23::Vec< T, N >::Min ( ) const
inlineconstexpr

Find the smallest element.

Returns
The smallest element in the vector. No ordering is assumed; operation is O(N).

◆ MinMax()

template<typename T , std::size_t N>
__host__ __device__ constexpr std::pair< T, T > reg23::Vec< T, N >::MinMax ( ) const
inlineconstexpr

Find the smallest and largest elements.

Returns
A pair containing the smallest and largest elements in the vector. No ordering is assumed; operation is O(N).

◆ operator*=() [1/2]

template<typename T , std::size_t N>
template<typename scalar_t >
__host__ __device__ Vec & reg23::Vec< T, N >::operator*= ( const scalar_t scalar)
inline

Element-wise multiplication by a scalar.

◆ operator*=() [2/2]

template<typename T , std::size_t N>
__host__ __device__ Vec & reg23::Vec< T, N >::operator*= ( const Vec< T, N > &  other)
inline

Element-wise multiplication by another Vec.

◆ operator+=() [1/2]

template<typename T , std::size_t N>
template<typename scalar_t >
__host__ __device__ Vec & reg23::Vec< T, N >::operator+= ( const scalar_t scalar)
inline

Element-wise addition of a scalar.

◆ operator+=() [2/2]

template<typename T , std::size_t N>
__host__ __device__ Vec & reg23::Vec< T, N >::operator+= ( const Vec< T, N > &  other)
inline

Element-wise addition of another Vec.

◆ operator-=() [1/2]

template<typename T , std::size_t N>
template<typename scalar_t >
__host__ __device__ Vec & reg23::Vec< T, N >::operator-= ( const scalar_t scalar)
inline

Element-wise subtraction of a scalar.

◆ operator-=() [2/2]

template<typename T , std::size_t N>
__host__ __device__ Vec & reg23::Vec< T, N >::operator-= ( const Vec< T, N > &  other)
inline

Element-wise subtraction of another Vec.

◆ operator/=() [1/2]

template<typename T , std::size_t N>
template<typename scalar_t >
__host__ __device__ Vec & reg23::Vec< T, N >::operator/= ( const scalar_t scalar)
inline

Element-wise division by a scalar.

◆ operator/=() [2/2]

template<typename T , std::size_t N>
__host__ __device__ Vec & reg23::Vec< T, N >::operator/= ( const Vec< T, N > &  other)
inline

Element-wise division by another Vec.

◆ Range()

template<typename T , std::size_t N>
__host__ static __device__ constexpr Vec reg23::Vec< T, N >::Range ( const T start = T{0},
const T step = T{1} 
)
inlinestaticconstexpr

Construct a Vec where the ith element is start + i * step

◆ StaticCast()

template<typename T , std::size_t N>
template<typename newT >
__host__ __device__ constexpr Vec< newT, N > reg23::Vec< T, N >::StaticCast ( ) const
inlineconstexpr

Construct a Vec with the elements form this one cast to a new type.

Returns
A copy of this vector, with each element cast to the type newT

◆ Sum()

template<typename T , std::size_t N>
__host__ __device__ constexpr T reg23::Vec< T, N >::Sum ( ) const
inlineconstexpr

Compute the sum of all elements.

Returns
The sum of the elements of the vector

◆ ToIntArrayRef()

template<typename T , std::size_t N>
__host__ __device__ constexpr at::IntArrayRef reg23::Vec< T, N >::ToIntArrayRef ( ) const
inlineconstexpr

Convert to an at::IntArrayRef (this is the type of at::Tensor::sizes())

◆ ToTensor()

template<typename T , std::size_t N>
__host__ at::Tensor reg23::Vec< T, N >::ToTensor ( at::TensorOptions  options = {},
bool  nonOwning = false 
) const
inline

Convert to an at::Tensor

◆ W() [1/2]

template<typename T , std::size_t N>
__host__ __device__ constexpr T & reg23::Vec< T, N >::W ( )
inlineconstexpr

Get the fourth element.

◆ W() [2/2]

template<typename T , std::size_t N>
__host__ __device__ constexpr const T & reg23::Vec< T, N >::W ( ) const
inlineconstexpr

Get a constant reference to the fourth element.

◆ X() [1/2]

template<typename T , std::size_t N>
__host__ __device__ constexpr T & reg23::Vec< T, N >::X ( )
inlineconstexpr

Get the first element.

◆ X() [2/2]

template<typename T , std::size_t N>
__host__ __device__ constexpr const T & reg23::Vec< T, N >::X ( ) const
inlineconstexpr

Get a constant reference to the first element.

◆ XY()

template<typename T , std::size_t N>
__host__ __device__ constexpr Vec< T, 2 > reg23::Vec< T, N >::XY ( ) const
inlineconstexpr

Construct a Vec from the first two elements.

◆ XYZ()

template<typename T , std::size_t N>
__host__ __device__ constexpr Vec< T, 3 > reg23::Vec< T, N >::XYZ ( ) const
inlineconstexpr

Construct a Vec from the first three elements.

◆ Y() [1/2]

template<typename T , std::size_t N>
__host__ __device__ constexpr T & reg23::Vec< T, N >::Y ( )
inlineconstexpr

Get the second element.

◆ Y() [2/2]

template<typename T , std::size_t N>
__host__ __device__ constexpr const T & reg23::Vec< T, N >::Y ( ) const
inlineconstexpr

Get a constant reference to the second element.

◆ Z() [1/2]

template<typename T , std::size_t N>
__host__ __device__ constexpr T & reg23::Vec< T, N >::Z ( )
inlineconstexpr

Get the third element.

◆ Z() [2/2]

template<typename T , std::size_t N>
__host__ __device__ constexpr const T & reg23::Vec< T, N >::Z ( ) const
inlineconstexpr

Get a constant reference to the third element.

Member Data Documentation

◆ dimensionality

template<typename T , std::size_t N>
constexpr std::size_t reg23::Vec< T, N >::dimensionality = N
staticconstexpr

The documentation for this class was generated from the following file: