LCOV - code coverage report
Current view: top level - include/ad/rss/unstructured - DebugDrawing.hpp (source / functions) Hit Total Coverage
Test: ad_rss Lines: 11 16 68.8 %
Date: 2024-04-23 14:35:54 Functions: 5 6 83.3 %
Branches: 6 18 33.3 %

           Branch data     Line data    Source code
       1                 :            : // ----------------- BEGIN LICENSE BLOCK ---------------------------------
       2                 :            : //
       3                 :            : // Copyright (C) 2020-2022 Intel Corporation
       4                 :            : //
       5                 :            : // SPDX-License-Identifier: LGPL-2.1-only
       6                 :            : //
       7                 :            : // ----------------- END LICENSE BLOCK -----------------------------------
       8                 :            : /**
       9                 :            :  * @file
      10                 :            :  */
      11                 :            : #pragma once
      12                 :            : 
      13                 :            : #include "ad/rss/unstructured/Geometry.hpp"
      14                 :            : 
      15                 :            : #include <string>
      16                 :            : #include <utility>
      17                 :            : #include <vector>
      18                 :            : 
      19                 :            : #define DEBUG_DRAWING_POLYGON(polygon, color, ns) (DebugDrawing::getInstance()->drawPolygon(polygon, color, ns))
      20                 :            : #define DEBUG_DRAWING_LINE(line, color, ns) (DebugDrawing::getInstance()->drawLine(line, color, ns))
      21                 :            : #define DEBUG_DRAWING_IS_ENABLED() (DebugDrawing::getInstance()->isEnabled())
      22                 :            : 
      23                 :            : /*!
      24                 :            :  * @brief namespace ad
      25                 :            :  */
      26                 :            : namespace ad {
      27                 :            : /*!
      28                 :            :  * @brief namespace rss
      29                 :            :  */
      30                 :            : namespace rss {
      31                 :            : /*!
      32                 :            :  * @brief namespace unstructured
      33                 :            :  */
      34                 :            : namespace unstructured {
      35                 :            : 
      36                 :            : class DebugDrawing
      37                 :            : {
      38                 :            : public:
      39                 :            :   struct NullDeleter
      40                 :            :   {
      41                 :       1080 :     void operator()(const void *)
      42                 :            :     {
      43                 :       1080 :     }
      44                 :            :   };
      45                 :            :   struct DebugPoint
      46                 :            :   {
      47                 :            :     DebugPoint(double inX, double inY)
      48                 :            :       : x(inX)
      49                 :            :       , y(inY){};
      50                 :            :     double x;
      51                 :            :     double y;
      52                 :            :   };
      53                 :            : 
      54                 :            :   struct DebugLine
      55                 :            :   {
      56                 :            :     DebugLine(Line const &iLine, std::string const &iColor, std::string const &iNs)
      57                 :            :       : line(iLine)
      58                 :            :       , color(iColor)
      59                 :            :       , ns(iNs)
      60                 :            :     {
      61                 :            :     }
      62                 :            :     Line line;
      63                 :            :     std::string color{"white"};
      64                 :            :     std::string ns;
      65                 :            : 
      66                 :            :     std::vector<DebugPoint> getVector()
      67                 :            :     {
      68                 :            :       std::vector<DebugPoint> vectorLine;
      69                 :            :       for (auto const &pt : line)
      70                 :            :       {
      71                 :            :         vectorLine.push_back(DebugPoint(pt.x(), pt.y()));
      72                 :            :       }
      73                 :            :       return vectorLine;
      74                 :            :     }
      75                 :            :   };
      76                 :            : 
      77                 :            :   struct DebugPolygon
      78                 :            :   {
      79                 :          0 :     DebugPolygon(Polygon const &iPolygon, std::string const &iColor, std::string const &iNs)
      80                 :          0 :       : polygon(iPolygon)
      81                 :            :       , color(iColor)
      82   [ #  #  #  # ]:          0 :       , ns(iNs)
      83                 :            :     {
      84                 :          0 :     }
      85                 :            :     Polygon polygon;
      86                 :            :     std::string color{"white"};
      87                 :            :     std::string ns;
      88                 :            : 
      89                 :            :     std::vector<DebugPoint> getVector()
      90                 :            :     {
      91                 :            :       std::vector<DebugPoint> vectorPolygon;
      92                 :            :       for (auto const &pt : polygon.outer())
      93                 :            :       {
      94                 :            :         vectorPolygon.push_back(DebugPoint(pt.x(), pt.y()));
      95                 :            :       }
      96                 :            :       return vectorPolygon;
      97                 :            :     }
      98                 :            :   };
      99                 :            : 
     100                 :          1 :   explicit DebugDrawing() = default;
     101                 :            : 
     102                 :            :   /**
     103                 :            :    * @brief singelton instance getter
     104                 :            :    */
     105                 :       1080 :   static std::shared_ptr<DebugDrawing> getInstance()
     106                 :            :   {
     107   [ +  +  +  -  :       1080 :     static DebugDrawing *mSingleton = new DebugDrawing();
             +  -  -  - ]
     108         [ +  - ]:       2160 :     return std::shared_ptr<DebugDrawing>(mSingleton, NullDeleter());
     109                 :            :   }
     110                 :            : 
     111                 :            :   /**
     112                 :            :    * @brief clean up all geometries to draw (before a new cycle)
     113                 :            :    */
     114                 :            :   void reset()
     115                 :            :   {
     116                 :            :     if (!mEnabled)
     117                 :            :     {
     118                 :            :       return;
     119                 :            :     }
     120                 :            :     mLines.clear();
     121                 :            :     mPolygons.clear();
     122                 :            :   }
     123                 :            : 
     124                 :            :   /**
     125                 :            :    * @brief enable/disable debug drawing
     126                 :            :    */
     127                 :            :   void enable(bool value)
     128                 :            :   {
     129                 :            :     mEnabled = value;
     130                 :            :   }
     131                 :            : 
     132                 :            :   /**
     133                 :            :    * @brief enable/disable debug drawing
     134                 :            :    */
     135                 :        220 :   bool isEnabled()
     136                 :            :   {
     137                 :        220 :     return mEnabled;
     138                 :            :   }
     139                 :            : 
     140                 :            :   /**
     141                 :            :    * @brief draw a line
     142                 :            :    *
     143                 :            :    * @param[in] line line to draw
     144                 :            :    * @param[in] color line color
     145                 :            :    * @param[in] ns namespace to identify geometry
     146                 :            :    */
     147                 :            :   void drawLine(Line const &line, std::string const &color = "white", std::string const &ns = "")
     148                 :            :   {
     149                 :            :     if (!mEnabled)
     150                 :            :     {
     151                 :            :       return;
     152                 :            :     }
     153                 :            :     mLines.push_back(DebugLine(line, color, ns));
     154                 :            : 
     155                 :            :     spdlog::trace("DRAW;{};{};{};LINE", ns, color, std::to_string(line));
     156                 :            :   }
     157                 :            : 
     158                 :            :   /**
     159                 :            :    * @brief draw a polygon
     160                 :            :    *
     161                 :            :    * @param[in] polygon polygon to draw
     162                 :            :    * @param[in] color line color
     163                 :            :    * @param[in] ns namespace to identify geometry
     164                 :            :    */
     165                 :        860 :   void drawPolygon(Polygon const &polygon, std::string const &color = "white", std::string const &ns = "")
     166                 :            :   {
     167         [ +  - ]:        860 :     if (!mEnabled)
     168                 :            :     {
     169                 :        860 :       return;
     170                 :            :     }
     171         [ #  # ]:          0 :     mPolygons.push_back(DebugPolygon(polygon, color, ns));
     172                 :            :   }
     173                 :            : 
     174                 :            :   std::vector<DebugLine> mLines;
     175                 :            :   std::vector<DebugPolygon> mPolygons;
     176                 :            :   bool mEnabled{false};
     177                 :            : };
     178                 :            : 
     179                 :            : } // namespace unstructured
     180                 :            : } // namespace rss
     181                 :            : } // namespace ad

Generated by: LCOV version 1.14