ug4
raster_kernels.h
Go to the documentation of this file.
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 
42 
56 template <class T, int TDIM>
57 class Count {
58 public:
59  typedef size_t result_t;
60 
61  Count () :
62  m_count (0)
63  {}
64 
65  inline void operator () (Raster<T, TDIM>& raster,
66  const typename Raster<T, TDIM>::MultiIndex& cur)
67  {
68  if(raster.node_value(cur) != raster.no_data_value())
69  ++m_count;
70  }
71 
72  inline size_t result() const
73  {return m_count;}
74 
75 private:
76  size_t m_count;
77 };
78 
79 
81 
95 template <class T, int TDIM>
96 class Sum {
97 public:
98  typedef T result_t;
99 
100  Sum () :
101  m_sum (0)
102  {}
103 
104  inline void operator () (Raster<T, TDIM>& raster,
105  const typename Raster<T, TDIM>::MultiIndex& cur)
106  {
107  if(raster.node_value(cur) != raster.no_data_value())
108  m_sum += raster.node_value(cur);
109  }
110 
111  inline T result() const
112  {return m_sum;}
113 
114 private:
115  T m_sum;
116 };
117 
118 
120 
133 template <class T, int TDIM>
134 class Blur {
135 public:
136  Blur (T alpha) :
137  m_alpha (alpha)
138  {}
139 
141  const typename Raster<T, TDIM>::MultiIndex& cur)
142  {
143  if(raster.node_value(cur) != raster.no_data_value()) {
144  T numNbrs = (T)raster.template run_on_nbrs<Count<T, TDIM> >(cur);
145  if(numNbrs) {
146  T nbrVal = raster.template run_on_nbrs<Sum<T, TDIM> >(cur);
147 
148  raster.node_value(cur) = raster.node_value(cur) * (1. - m_alpha)
149  + (nbrVal * m_alpha / numNbrs);
150  }
151  }
152  }
153 
154 private:
156 };
157 
158 }// end of namespace
159 }// end of namespace
160 
161 #endif //__H__UG_raster_kernels
Definition: raster.h:75
Generic raster for arbitrary dimensions.
Definition: raster.h:73
T & node_value(const MultiIndex &mi)
returns the value at the given multi-index (read/write)
Definition: raster_impl.hpp:353
T no_data_value() const
returns the value that shall be considered 'no-data-value'
Definition: raster_impl.hpp:482
Kernel which blurs all values of a raster it was called on.
Definition: raster_kernels.h:134
void operator()(Raster< T, TDIM > &raster, const typename Raster< T, TDIM >::MultiIndex &cur)
Definition: raster_kernels.h:140
Blur(T alpha)
Definition: raster_kernels.h:136
T m_alpha
Definition: raster_kernels.h:155
Kernel which counts the number of times it was run on valid data values.
Definition: raster_kernels.h:57
size_t m_count
Definition: raster_kernels.h:76
size_t result_t
Definition: raster_kernels.h:59
Count()
Definition: raster_kernels.h:61
size_t result() const
Definition: raster_kernels.h:72
void operator()(Raster< T, TDIM > &raster, const typename Raster< T, TDIM >::MultiIndex &cur)
Definition: raster_kernels.h:65
Kernel which sums the values for all entries it was called on.
Definition: raster_kernels.h:96
T result() const
Definition: raster_kernels.h:111
void operator()(Raster< T, TDIM > &raster, const typename Raster< T, TDIM >::MultiIndex &cur)
Definition: raster_kernels.h:104
T result_t
Definition: raster_kernels.h:98
T m_sum
Definition: raster_kernels.h:115
Sum()
Definition: raster_kernels.h:100
number alpha
the ug namespace