Line data Source code
1 : #include "DetectorDescriptor.h" 2 : #include "TypeCasts.hpp" 3 : 4 : namespace elsa 5 : { 6 0 : DetectorDescriptor::DetectorDescriptor(const IndexVector_t& numOfCoeffsPerDim, 7 0 : const std::vector<Geometry>& geometryList) 8 0 : : DataDescriptor(numOfCoeffsPerDim), _geometry(geometryList) 9 : { 10 : // TODO Clarify: What about empty geometryList? Do we want to support it, or throw an 11 : // exception? 12 0 : } 13 : 14 0 : DetectorDescriptor::DetectorDescriptor(const IndexVector_t& numOfCoeffsPerDim, 15 : const RealVector_t& spacingPerDim, 16 0 : const std::vector<Geometry>& geometryList) 17 0 : : DataDescriptor(numOfCoeffsPerDim, spacingPerDim), _geometry(geometryList) 18 : { 19 0 : } 20 : 21 0 : RealRay_t DetectorDescriptor::computeRayFromDetectorCoord(const index_t detectorIndex) const 22 : { 23 : 24 : // Return empty, if access out of bounds 25 0 : assert(detectorIndex < getNumberOfCoefficients() 26 : && "PlanarDetectorDescriptor::computeRayToDetector(index_t): Assumption " 27 : "detectorIndex smaller than number of coeffs, broken"); 28 : 29 0 : auto coord = getCoordinateFromIndex(detectorIndex); 30 0 : return computeRayFromDetectorCoord(coord); 31 0 : } 32 : 33 0 : RealRay_t DetectorDescriptor::computeRayFromDetectorCoord(const IndexVector_t coord) const 34 : { 35 : // Assume all of the coordinates are inside of the volume 36 : // auto tmp = (coord.array() < getNumberOfCoefficientsPerDimension().array()); 37 : // assert(tmp.all() 38 : // && "DetectorDescriptor::computeRayToDetector(IndexVector_t): Assumption coord " 39 : // "in bound wrong"); 40 : 41 0 : auto dim = getNumberOfDimensions(); 42 : 43 : // Assume dimension of coord is equal to dimension of descriptor 44 0 : assert(dim == coord.size()); 45 : 46 : // Cast to real_t and shift to center of pixel 47 0 : auto detectorCoord = coord.head(dim - 1).template cast<real_t>().array() + 0.5; 48 : 49 : // Last dimension is always the pose index 50 0 : auto poseIndex = coord[dim - 1]; 51 : 52 0 : return computeRayFromDetectorCoord(detectorCoord, poseIndex); 53 : } 54 : 55 0 : std::vector<Geometry> DetectorDescriptor::getGeometry() const { return _geometry; } 56 : 57 0 : index_t DetectorDescriptor::getNumberOfGeometryPoses() const 58 : { 59 0 : return static_cast<index_t>(_geometry.size()); 60 : } 61 : 62 0 : std::optional<Geometry> DetectorDescriptor::getGeometryAt(const index_t index) const 63 : { 64 : // Cast to size_t to silence warnings 65 0 : auto i = asUnsigned(index); 66 : 67 0 : if (_geometry.size() <= i) 68 0 : return {}; 69 : 70 0 : return _geometry[i]; 71 : } 72 : 73 0 : bool DetectorDescriptor::isEqual(const DataDescriptor& other) const 74 : { 75 0 : if (!DataDescriptor::isEqual(other)) 76 0 : return false; 77 : 78 : // static cast as type checked in base comparison 79 0 : auto otherBlock = static_cast<const DetectorDescriptor*>(&other); 80 : 81 0 : if (getNumberOfGeometryPoses() != otherBlock->getNumberOfGeometryPoses()) 82 0 : return false; 83 : 84 0 : return std::equal(std::cbegin(_geometry), std::cend(_geometry), 85 0 : std::cbegin(otherBlock->_geometry)); 86 : } 87 : } // namespace elsa