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