LCOV - code coverage report
Current view: top level - alg/viewshed - combiner.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 21 24 87.5 %
Date: 2024-11-21 22:18:42 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  * (c) 2024 info@hobu.co
       3             :  *
       4             :  * SPDX-License-Identifier: MIT
       5             :  ****************************************************************************/
       6             : 
       7             : #include "combiner.h"
       8             : #include "util.h"
       9             : 
      10             : namespace gdal
      11             : {
      12             : namespace viewshed
      13             : {
      14             : 
      15             : /// Read viewshed executor output and sum it up in our owned memory raster.
      16           3 : void Combiner::run()
      17             : {
      18           6 :     DatasetPtr pTempDataset;
      19             : 
      20         591 :     while (m_inputQueue.pop(pTempDataset))
      21             :     {
      22         588 :         if (!m_dataset)
      23           3 :             m_dataset = std::move(pTempDataset);
      24             :         else
      25         585 :             sum(std::move(pTempDataset));
      26             :     }
      27             :     // Queue remaining summed rasters.
      28           3 :     queueOutputBuffer();
      29           3 : }
      30             : 
      31             : /// Add the values of the source dataset to those of the owned dataset.
      32             : /// @param src  Source dataset.
      33         585 : void Combiner::sum(DatasetPtr src)
      34             : {
      35         585 :     if (!m_dataset)
      36             :     {
      37           0 :         m_dataset = std::move(src);
      38           0 :         return;
      39             :     }
      40         585 :     size_t size = bandSize(*m_dataset->GetRasterBand(1));
      41             : 
      42             :     uint8_t *dstP =
      43         585 :         static_cast<uint8_t *>(m_dataset->GetInternalHandle("MEMORY1"));
      44         585 :     uint8_t *srcP = static_cast<uint8_t *>(src->GetInternalHandle("MEMORY1"));
      45     8404850 :     for (size_t i = 0; i < size; ++i)
      46     8404270 :         *dstP++ += *srcP++;
      47             :     // If we've seen 255 inputs, queue our raster for output and rollup since we might overflow
      48             :     // otherwise.
      49         585 :     if (++m_count == 255)
      50           0 :         queueOutputBuffer();
      51             : }
      52             : 
      53             : /// Queue the owned buffer as for output.
      54           3 : void Combiner::queueOutputBuffer()
      55             : {
      56           3 :     if (m_dataset)
      57           3 :         m_outputQueue.push(std::move(m_dataset));
      58           3 :     m_count = 0;
      59           3 : }
      60             : 
      61             : }  // namespace viewshed
      62             : }  // namespace gdal

Generated by: LCOV version 1.14