LCOV - code coverage report
Current view: top level - elsa/generators - Box.cpp (source / functions) Hit Total Coverage
Test: coverage-all.lcov Lines: 53 53 100.0 %
Date: 2024-05-16 04:22:26 Functions: 4 6 66.7 %

          Line data    Source code
       1             : #include "Box.h"
       2             : 
       3             : namespace elsa::phantoms
       4             : {
       5             : 
       6             :     template <typename data_t>
       7             :     Box<data_t>::Box(data_t amplit, elsa::phantoms::Vec3i center, Vec3X<data_t> edgeLength)
       8          42 :         : _amplit{amplit}, _center{center}, _edgeLength{edgeLength} {};
       9             : 
      10             :     template <Blending b, typename data_t>
      11             :     void rasterize(Box<data_t>& el, VolumeDescriptor& dd, DataContainer<data_t>& dc)
      12          42 :     {
      13             : 
      14          42 :         auto strides = dd.getProductOfCoefficientsPerDimension();
      15             : 
      16             :         // global offests for a fast memory reuse in the for loops
      17          42 :         index_t xOffset = 0;
      18          42 :         index_t xOffsetNeg = 0;
      19          42 :         index_t yOffset = 0;
      20          42 :         index_t yOffsetNeg = 0;
      21          42 :         index_t zOffset = 0;
      22          42 :         index_t zOffsetNeg = 0;
      23             : 
      24          42 :         Vec3i _center = el.getCenter();
      25          42 :         data_t _amplit = el.getAmplitude();
      26             : 
      27          42 :         index_t maxX = std::lround(el.getEdgeLength()[INDEX_X] / 2);
      28          42 :         index_t maxY = std::lround(el.getEdgeLength()[INDEX_Y] / 2);
      29          42 :         index_t maxZ = std::lround(el.getEdgeLength()[INDEX_Z] / 2);
      30             : 
      31          42 :         Vec3i idx(3);
      32          42 :         idx << 0, 0, 0;
      33             : 
      34         175 :         for (; idx[INDEX_Z] <= maxZ; idx[INDEX_Z]++) {
      35         133 :             zOffset = (idx[INDEX_Z] + _center[INDEX_Z]) * strides[INDEX_Z];
      36         133 :             zOffsetNeg = (-idx[INDEX_Z] + _center[INDEX_Z]) * strides[INDEX_Z];
      37             : 
      38         407 :             for (; idx[INDEX_Y] <= maxY; idx[INDEX_Y]++) {
      39         274 :                 yOffset = (idx[INDEX_Y] + _center[INDEX_Y]) * strides[INDEX_Y];
      40         274 :                 yOffsetNeg = (-idx[INDEX_Y] + _center[INDEX_Y]) * strides[INDEX_Y];
      41             : 
      42        1144 :                 for (; idx[INDEX_X] <= maxX; idx[INDEX_X]++) {
      43         870 :                     xOffset = (idx[INDEX_X] + _center[INDEX_X]) * strides[INDEX_X];
      44         870 :                     xOffsetNeg = (-idx[INDEX_X] + _center[INDEX_X]) * strides[INDEX_X];
      45             : 
      46         870 :                     blend<b>(dc, xOffset + yOffset + zOffset, _amplit);
      47             : 
      48             :                     // mirror the voxel at most 8 times
      49             : 
      50         870 :                     if (idx[INDEX_X] != 0) {
      51         596 :                         blend<b>(dc, xOffsetNeg + yOffset + zOffset, _amplit);
      52         596 :                     }
      53         870 :                     if (idx[INDEX_Y] != 0) {
      54         443 :                         blend<b>(dc, xOffset + yOffsetNeg + zOffset, _amplit);
      55         443 :                     }
      56         870 :                     if (idx[INDEX_Z] != 0) {
      57         592 :                         blend<b>(dc, xOffset + yOffset + zOffsetNeg, _amplit);
      58         592 :                     }
      59             : 
      60         870 :                     if (idx[INDEX_X] != 0 && idx[INDEX_Y] != 0) {
      61         302 :                         blend<b>(dc, xOffsetNeg + yOffsetNeg + zOffset, _amplit);
      62         302 :                     }
      63             : 
      64         870 :                     if (idx[INDEX_X] != 0 && idx[INDEX_Z] != 0) {
      65         404 :                         blend<b>(dc, xOffsetNeg + yOffset + zOffsetNeg, _amplit);
      66         404 :                     }
      67             : 
      68         870 :                     if (idx[INDEX_Y] != 0 && idx[INDEX_Z] != 0) {
      69         302 :                         blend<b>(dc, xOffset + yOffsetNeg + zOffsetNeg, _amplit);
      70         302 :                     }
      71             : 
      72         870 :                     if (idx[INDEX_X] != 0 && idx[INDEX_Y] != 0 && idx[INDEX_Z] != 0) {
      73         205 :                         blend<b>(dc, xOffsetNeg + yOffsetNeg + zOffsetNeg, _amplit);
      74         205 :                     }
      75         870 :                 };
      76         274 :                 idx[INDEX_X] = 0;
      77         274 :             }
      78         133 :             idx[INDEX_Y] = 0;
      79         133 :         }
      80          42 :     };
      81             : 
      82             :     // ------------------------------------------
      83             :     // explicit template instantiation
      84             :     template class Box<float>;
      85             :     template class Box<double>;
      86             : 
      87             :     template void rasterize<Blending::ADDITION, float>(Box<float>& el, VolumeDescriptor& dd,
      88             :                                                        DataContainer<float>& dc);
      89             :     template void rasterize<Blending::ADDITION, double>(Box<double>& el, VolumeDescriptor& dd,
      90             :                                                         DataContainer<double>& dc);
      91             : 
      92             :     template void rasterize<Blending::OVERWRITE, float>(Box<float>& el, VolumeDescriptor& dd,
      93             :                                                         DataContainer<float>& dc);
      94             :     template void rasterize<Blending::OVERWRITE, double>(Box<double>& el, VolumeDescriptor& dd,
      95             :                                                          DataContainer<double>& dc);
      96             : 
      97             : } // namespace elsa::phantoms

Generated by: LCOV version 1.14