LCOV - code coverage report
Current view: top level - ugbase/common/util - raster_kernels.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 21 0
Test Date: 2025-09-21 23:31:46 Functions: 0.0 % 4 0

            Line data    Source code
       1              : /*
       2              :  * Copyright (c) 2017:  G-CSC, Goethe University Frankfurt
       3              :  * Author: Sebastian Reiter
       4              :  * 
       5              :  * This file is part of UG4.
       6              :  * 
       7              :  * UG4 is free software: you can redistribute it and/or modify it under the
       8              :  * terms of the GNU Lesser General Public License version 3 (as published by the
       9              :  * Free Software Foundation) with the following additional attribution
      10              :  * requirements (according to LGPL/GPL v3 §7):
      11              :  * 
      12              :  * (1) The following notice must be displayed in the Appropriate Legal Notices
      13              :  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
      14              :  * 
      15              :  * (2) The following notice must be displayed at a prominent place in the
      16              :  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
      17              :  * 
      18              :  * (3) The following bibliography is recommended for citation and must be
      19              :  * preserved in all covered files:
      20              :  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
      21              :  *   parallel geometric multigrid solver on hierarchically distributed grids.
      22              :  *   Computing and visualization in science 16, 4 (2013), 151-164"
      23              :  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
      24              :  *   flexible software system for simulating pde based models on high performance
      25              :  *   computers. Computing and visualization in science 16, 4 (2013), 165-179"
      26              :  * 
      27              :  * This program is distributed in the hope that it will be useful,
      28              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      29              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      30              :  * GNU Lesser General Public License for more details.
      31              :  */
      32              : 
      33              : #ifndef __H__UG_raster_kernels
      34              : #define __H__UG_raster_kernels
      35              : 
      36              : #include "raster.h"
      37              : 
      38              : namespace ug {
      39              : namespace raster_kernels {
      40              : 
      41              : ///     Kernel which counts the number of times it was run on valid data values
      42              : /** For use with ug::Raster.
      43              :  * 
      44              :  * This class defines a default constructor, the type 'result_t',
      45              :  * and the method 'result_t result() const' and can thus be used like this:
      46              :  *
      47              :  * \code
      48              :  * Raster<T,TDIM> raster;
      49              :  * //...
      50              :  * size_t countAll = raster.run_on_all<Count<T,TDIM> > ();
      51              :  * size_t countNbrs = raster.run_on_nbrs<Count<T,TDIM> > (someMultiIndex);
      52              :  * \endcode
      53              :  *
      54              :  * \note        if the kernel is run on a 'no_data_value', the counter is not increased.
      55              :  */
      56              : template <class T, int TDIM>
      57              : class Count {
      58              : public:
      59              :         typedef size_t result_t;
      60              : 
      61            0 :         Count () :
      62            0 :                 m_count (0)
      63              :         {}
      64              : 
      65              :         inline void operator () (Raster<T, TDIM>& raster,
      66              :                                                          const typename Raster<T, TDIM>::MultiIndex& cur)
      67              :         {
      68            0 :                 if(raster.node_value(cur) != raster.no_data_value())
      69            0 :                         ++m_count;
      70              :         }
      71              : 
      72              :         inline size_t result() const
      73            0 :         {return m_count;}
      74              : 
      75              : private:
      76              :         size_t m_count;
      77              : };
      78              : 
      79              : 
      80              : ///     Kernel which sums the values for all entries it was called on
      81              : /** For use with ug::Raster.
      82              :  * 
      83              :  * This class defines a default constructor, the type 'result_t',
      84              :  * and the method 'result_t result() const' and can thus be used like this:
      85              :  *
      86              :  * \code
      87              :  * Raster<T,TDIM> raster;
      88              :  * //...
      89              :  * size_t sumAll = raster.run_on_all<Sum<T,TDIM> > ();
      90              :  * size_t sumNbrs = raster.run_on_nbrs<Sum<T,TDIM> > (someMultiIndex);
      91              :  * \endcode
      92              :  *
      93              :  * \note        'no_data_values' are ignored and will not be summed.
      94              :  */
      95              : template <class T, int TDIM>
      96              : class Sum {
      97              : public:
      98              :         typedef T result_t;
      99              : 
     100            0 :         Sum () :
     101            0 :                 m_sum (0)
     102              :         {}
     103              : 
     104            0 :         inline void operator () (Raster<T, TDIM>& raster,
     105              :                                                          const typename Raster<T, TDIM>::MultiIndex& cur)
     106              :         {
     107            0 :                 if(raster.node_value(cur) != raster.no_data_value())
     108            0 :                         m_sum += raster.node_value(cur);
     109            0 :         }
     110              : 
     111              :         inline T result() const
     112            0 :         {return m_sum;}
     113              : 
     114              : private:
     115              :         T m_sum;
     116              : };
     117              : 
     118              : 
     119              : ///     Kernel which blurs all values of a raster it was called on
     120              : /** \note       This class does not feature a default constructor and thus
     121              :  *                      must be constructed before being run on a raster.
     122              :  *
     123              :  * Use, e.g., like this:
     124              :  * \code
     125              :  * Raster<T,TDIM> raster;
     126              :  * //...
     127              :  * Blur<T,TDIM> blurKernel(0.1);
     128              :  * raster.run_on_all (blurKernel);
     129              :  * \endcode
     130              :  *
     131              :  * \note 'no_data_values' will not be affected by the blur operation
     132              :  */
     133              : template <class T, int TDIM>
     134              : class Blur {
     135              : public:
     136            0 :         Blur (T alpha) :
     137            0 :                 m_alpha (alpha)
     138              :         {}
     139              : 
     140            0 :         void operator () (Raster<T, TDIM>& raster,
     141              :                           const typename Raster<T, TDIM>::MultiIndex& cur)
     142              :         {
     143            0 :                 if(raster.node_value(cur) != raster.no_data_value()) {
     144            0 :                         T numNbrs = (T)raster.template run_on_nbrs<Count<T, TDIM> >(cur);
     145            0 :                         if(numNbrs) {
     146              :                                 T nbrVal = raster.template run_on_nbrs<Sum<T, TDIM> >(cur);
     147              :                                 
     148            0 :                                 raster.node_value(cur) = raster.node_value(cur) * (1. - m_alpha)
     149            0 :                                                                            + (nbrVal * m_alpha / numNbrs);
     150              :                         }
     151              :                 }
     152            0 :         }
     153              : 
     154              : private:
     155              :         T m_alpha;
     156              : };
     157              : 
     158              : }//     end of namespace
     159              : }//     end of namespace
     160              : 
     161              : #endif  //__H__UG_raster_kernels
        

Generated by: LCOV version 2.0-1