LCOV - code coverage report
Current view: top level - elsa/generators - Ellipsoid.h (source / functions) Hit Total Coverage
Test: coverage-all.lcov Lines: 20 20 100.0 %
Date: 2024-05-16 04:22:26 Functions: 11 14 78.6 %

          Line data    Source code
       1             : #pragma once
       2             : #include "PhantomDefines.h"
       3             : #include <functional>
       4             : 
       5             : namespace elsa::phantoms
       6             : {
       7             : 
       8             :     template <typename data_t = double>
       9             :     class Ellipsoid
      10             :     {
      11             : 
      12             :     private:
      13             :         data_t _amplit;
      14             :         Vec3i _center;
      15             :         Vec3X<data_t> _halfAxis;
      16             :         Vec3X<data_t> _eulers;
      17             : 
      18             :         data_t bSqrcSqr;
      19             :         data_t aSqrcSqr;
      20             :         data_t aSqrbSqr;
      21             :         data_t aSqrbSqrcSqr;
      22             : 
      23             :         // setup euler rotation matrix
      24             :         Eigen::Matrix<data_t, 3, 3> rot = Eigen::Matrix<data_t, 3, 3>::Identity();
      25             :         bool rotated = false;
      26             : 
      27             :     public:
      28             :         Ellipsoid(data_t amplit, Vec3i center, Vec3X<data_t> halfAxis, Vec3X<data_t> eulers);
      29             :         /**
      30             :          * @brief returns true if there is any not zero euler angle
      31             :          */
      32          97 :         bool isRotated() { return rotated; };
      33             :         /**
      34             :          * @brief returns the amplitude to color the voxel
      35             :          */
      36         125 :         const data_t getAmplitude() const { return _amplit; };
      37             :         /**
      38             :          * @brief returns the center of the ellipsoid
      39             :          */
      40         125 :         const Vec3i& getCenter() const { return _center; };
      41             :         /**
      42             :          * @brief returns the half axis of the ellipsoid
      43             :          */
      44          26 :         const Vec3X<data_t>& getHalfAxis() const { return _halfAxis; };
      45             :         /**
      46             :          * @brief returns the euler angels of the ellipsoid
      47             :          */
      48          26 :         const Vec3X<data_t>& getEulerAngels() const { return _eulers; };
      49             :         /**
      50             :          * @brief get inverse rotation matrix
      51             :          */
      52       99422 :         const Eigen::Matrix<data_t, 3, 3> getInvRotationMatrix() const { return rot; };
      53             :         /**
      54             :          * @brief returns the ceil max floating point half width as a floating point of the longest
      55             :          * half axis
      56             :          */
      57             :         data_t getRoundMaxHalfWidth() const;
      58             : 
      59             :         bool isInEllipsoid(const Vec3i& idx) const;
      60             :         bool isInEllipsoid(const Vec3X<data_t>& idx) const;
      61             :     };
      62             : 
      63             :     template <typename data_t>
      64             :     using MinMaxFunction = std::function<std::array<data_t, 6>(std::array<data_t, 6>)>;
      65             : 
      66             :     /**
      67             :      * @brief Rasterizes the given ellipsoid in the given data container.
      68             :      */
      69             :     template <Blending b, typename data_t>
      70             :     void rasterize(Ellipsoid<data_t>& el, VolumeDescriptor& dd, DataContainer<data_t>& dc);
      71             : 
      72             :     template <Blending b, typename data_t>
      73             :     void rasterizeWithClipping(Ellipsoid<data_t>& el, VolumeDescriptor& dd,
      74             :                                DataContainer<data_t>& dc, MinMaxFunction<data_t> clipping);
      75             : 
      76             : } // namespace elsa::phantoms
      77             : 
      78             : /**
      79             :  * @brief Ellipsoid formatter to use the Logger.h functions
      80             :  */
      81             : template <typename data_t>
      82             : struct fmt::formatter<elsa::phantoms::Ellipsoid<data_t>> : fmt::formatter<std::string> {
      83             :     auto format(elsa::phantoms::Ellipsoid<data_t> ell, format_context& ctx) -> decltype(ctx.out())
      84          26 :     {
      85          26 :         auto _center = ell.getCenter();
      86          26 :         auto _amplit = ell.getAmplitude();
      87          26 :         auto _halfAxis = ell.getHalfAxis();
      88          26 :         auto _eulers = ell.getEulerAngels();
      89             : 
      90          26 :         return format_to(ctx.out(),
      91          26 :                          "Ellipsoid with amplitude {}, center ({},{},{}) , half axis ({},{},{}) "
      92          26 :                          "euler angels ({},{},{})",
      93          26 :                          _amplit, _center[elsa::phantoms::INDEX_X],
      94          26 :                          _center[elsa::phantoms::INDEX_Y], _center[elsa::phantoms::INDEX_Z],
      95          26 :                          _halfAxis[elsa::phantoms::INDEX_X], _halfAxis[elsa::phantoms::INDEX_Y],
      96          26 :                          _halfAxis[elsa::phantoms::INDEX_Z], _eulers[elsa::phantoms::INDEX_X],
      97          26 :                          _eulers[elsa::phantoms::INDEX_Y], _eulers[elsa::phantoms::INDEX_Z]);
      98          26 :     }
      99             : };

Generated by: LCOV version 1.14