Line data Source code
1 : #pragma once 2 : 3 : #include "elsaDefines.h" 4 : #include "Cloneable.h" 5 : 6 : #include <vector> 7 : 8 : namespace elsa 9 : { 10 : 11 : /** 12 : * @brief Base class for representing metadata for linearized n-dimensional signal stored in 13 : * memory 14 : * 15 : * @author Matthias Wieczorek - initial code 16 : * @author Tobias Lasser - modularization, modernization 17 : * @author Maximilian Hornung - various enhancements 18 : * @author David Frank - inheritance restructuring 19 : * 20 : * This class provides an interface for metadata about a signal that is stored in memory. This 21 : * base class provides other descriptor subclasses with a fundamental interface to access the 22 : * important parameters (i.e. dimensionality, size and spacing) of the metadata. 23 : * 24 : */ 25 : class DataDescriptor : public Cloneable<DataDescriptor> 26 : { 27 : public: 28 : /// delete default constructor (having no metadata is invalid) 29 : DataDescriptor() = delete; 30 : 31 : /// Pure virtual destructor 32 : virtual ~DataDescriptor() = 0; 33 : 34 : /** 35 : * @brief Constructor for DataDescriptor, accepts dimension and size 36 : * 37 : * @param[in] numberOfCoefficientsPerDimension vector containing the number of coefficients 38 : * per dimension, (dimension is set implicitly from the size of the vector) 39 : * 40 : * @throw InvalidArgumentError if any number of coefficients is non-positive 41 : */ 42 : explicit DataDescriptor(IndexVector_t numberOfCoefficientsPerDimension); 43 : 44 : /** 45 : * @brief Constructor for DataDescriptor, accepts dimension, size and spacing 46 : * 47 : * @param[in] numberOfCoefficientsPerDimension vector containing the number of coefficients 48 : * per dimension, (dimension is set implicitly from the size of the vector) 49 : * @param[in] spacingPerDimension vector containing the spacing per dimension 50 : * 51 : * @throw InvalidArgumentError if any number of coefficients is non-positive, 52 : * or sizes of numberOfCoefficientsPerDimension and spacingPerDimension do not match 53 : */ 54 : explicit DataDescriptor(IndexVector_t numberOfCoefficientsPerDimension, 55 : RealVector_t spacingPerDimension); 56 : 57 : /// return the number of dimensions 58 : index_t getNumberOfDimensions() const; 59 : 60 : /// return the total number of coefficients 61 : index_t getNumberOfCoefficients() const; 62 : 63 : /// return the number of coefficients per dimension 64 : IndexVector_t getNumberOfCoefficientsPerDimension() const; 65 : 66 : /// return the spacing per dimension 67 : RealVector_t getSpacingPerDimension() const; 68 : 69 : /// return the location of the origin (typically the center) 70 : RealVector_t getLocationOfOrigin() const; 71 : 72 : /** 73 : * @brief computes the linearized index in the data vector from local coordinates 74 : * 75 : * @param[in] coordinate vector containing the local coordinate 76 : * @return the index into the linearized data vector 77 : * 78 : * The local coordinates are integers, running from 0 to 79 : * _numberOfCoefficientsPerDimension[i]-1 for every dimension i = 0,...,_numberOfDimensions. 80 : * Linearization is assumed to be done in order of the dimensions. 81 : */ 82 : index_t getIndexFromCoordinate(const elsa::IndexVector_t& coordinate) const; 83 : 84 : /** 85 : * @brief computes the local coordinates from a linearized index 86 : * 87 : * @param[in] index into the linearized data vector 88 : * @return the local coordinate corresponding to the index 89 : * 90 : * The local coordinates are integers, running from 0 to 91 : * _numberOfCoefficientsPerDimension[i]-1 for every dimension i = 92 : * 0,...,_numberOfDimensions. Linearization is assumed to be done in order of the 93 : * dimensions. 94 : */ 95 : IndexVector_t getCoordinateFromIndex(index_t index) const; 96 : 97 : protected: 98 : /// Number of dimensions 99 : index_t _numberOfDimensions; 100 : 101 : /// vector containing the number of coefficients per dimension 102 : IndexVector_t _numberOfCoefficientsPerDimension; 103 : 104 : /// vector containing the spacing per dimension 105 : RealVector_t _spacingPerDimension; 106 : 107 : /// vector containing precomputed partial products of coefficients per dimension for index 108 : /// computations 109 : IndexVector_t _productOfCoefficientsPerDimension; 110 : 111 : /// vector containing the origin of the described volume (typically the center) 112 : RealVector_t _locationOfOrigin; 113 : 114 : /// default copy constructor, hidden from non-derived classes to prevent potential slicing 115 3439 : DataDescriptor(const DataDescriptor&) = default; 116 : 117 : /// default move constructor, hidden from non-derived classes to prevent potential slicing 118 494 : DataDescriptor(DataDescriptor&&) = default; 119 : 120 : /// implement the polymorphic comparison operation 121 : bool isEqual(const DataDescriptor& other) const override; 122 : }; 123 : 124 : } // namespace elsa