OpenWalnut  1.5.0dev
WMGaussFiltering.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WMGAUSSFILTERING_H
26 #define WMGAUSSFILTERING_H
27 
28 #include <map>
29 #include <memory>
30 #include <string>
31 #include <vector>
32 
33 #include <osg/Geode>
34 #include <osg/Node>
35 #include <osg/Uniform>
36 
37 #include "core/dataHandler/WDataSetScalar.h"
38 #include "core/kernel/WModule.h"
39 #include "core/kernel/WModuleInputData.h"
40 
41 /**
42  * Gauss filtering for WDataSetScalar
43  *
44  * \problem It works only on double value sets so far.
45  * \reminder The boundary values will not be touched and considered to be zero.
46  *
47  * \ingroup modules
48  */
49 class WMGaussFiltering : public WModule
50 {
51 public:
52  /**
53  * Standard constructor.
54  */
56 
57  /**
58  * Destructor.
59  */
61 
62  /**
63  * Gives back the name of this module.
64  * \return the module's name.
65  */
66  virtual const std::string getName() const;
67 
68  /**
69  * Gives back a description of this module.
70  * \return description of module.
71  */
72  virtual const std::string getDescription() const;
73 
74  /**
75  * Due to the prototype design pattern used to build modules, this method returns a new instance of this method. NOTE: it
76  * should never be initialized or modified in some other way. A simple new instance is required.
77  *
78  * \return the prototype used to create every module in OpenWalnut.
79  */
80  virtual std::shared_ptr< WModule > factory() const;
81 
82  /**
83  * Get the icon for this module in XPM format.
84  * \return The icon.
85  */
86  virtual const char** getXPMIcon() const;
87 
88 protected:
89  /**
90  * Entry point after loading the module. Runs in separate thread.
91  */
92  virtual void moduleMain();
93 
94  /**
95  * Initialize the connectors this module is using.
96  */
97  virtual void connectors();
98 
99  /**
100  * Initialize the properties for this module.
101  */
102  virtual void properties();
103 
104 private:
105  /**
106  * A condition used to notify about changes in several properties.
107  */
108  std::shared_ptr< WCondition > m_propCondition;
109 
110  /**
111  * The number of iterations to use for filtering
112  */
113  WPropInt m_iterations;
114 
115  /**
116  * 1D or 3D filtering flag
117  */
118  WPropBool m_3DMaskMode;
119 
120  /**
121  * Simple convolution using a small gauss-like mask
122  * \param vals the valueset to work on
123  * \param nX number of positions in x direction
124  * \param nY number of positions in y direction
125  * \param nZ number of positions in z direction
126  * \param x index for x direction
127  * \param y index for x direction
128  * \param z index for x direction
129  * \param offset the offset to add to the index (useful for addressing vector/tensor elements)
130  *
131  * \return the filtered value for a given position
132  */
133  template< typename T > double filterAtPosition( std::shared_ptr< WValueSet< T > > vals,
134  size_t nX, size_t nY, size_t nZ, size_t x, size_t y, size_t z, size_t offset );
135 
136  /**
137  * Run the filter over the field.
138  * \param vals the valueset to work on
139  * \param grid the grid for the valueset
140  * \param prog the progress used for this filter iteration
141  *
142  * \return the filtered array of values.
143  */
144  template< typename T > std::vector< double > filterField( std::shared_ptr< WValueSet< T > > vals,
145  std::shared_ptr< WGridRegular3D > grid,
146  std::shared_ptr< WProgress > prog );
147 
148 
149  /**
150  * Run the 1D Gaussian filter over the field
151  * \param newVals result of the filtering
152  * \param vals the values to work on
153  * \param prog the progress used for this filter iteration
154  * \param Nx dimension along the filter
155  * \param Ny first dimension perpendicular to the filter
156  * \param Nz second dimension perpendicular to the filter
157  * \param dx element offset along the filter
158  * \param dy element offset perpendicular to the filter
159  * \param dz second element offset perpendicular to the filter
160  */
161  template< typename T >
162  void filterField1D( std::vector<T>* newVals,
163  const std::vector<T>&vals,
164  std::shared_ptr< WProgress > prog,
165  size_t Nx, size_t Ny, size_t Nz, size_t dx, size_t dy, size_t dz );
166 
167 
168  /**
169  * Run the 1D Gaussian filter over the field
170  * \param newVals result of the filtering
171  * \param vals the values to work on
172  * \param prog the progress used for this filter iteration
173  * \param Nx dimension along the filter
174  * \param Ny first dimension perpendicular to the filter
175  * \param Nz second dimension perpendicular to the filter
176  * \param dx element offset along the filter
177  * \param dy element offset perpendicular to the filter
178  * \param dz second element offset perpendicular to the filter
179  */
180  template< typename T >
181  void filterField1D( std::vector<double>* newVals,
182  std::shared_ptr< WValueSet< T > > vals,
183  std::shared_ptr< WProgress > prog,
184  size_t Nx, size_t Ny, size_t Nz, size_t dx, size_t dy, size_t dz );
185  /**
186  * Run the filter iteratively over the field. The number of iterations is determined by m_iterations.
187  *
188  * \param vals the valueset to work on
189  * \param iterations the number of iterations. If this value is <=1 then the filter gets applied exactly once.
190  *
191  * \return the filtered valueset.
192  */
193  template< typename T > std::shared_ptr< WValueSet< double > > iterativeFilterField( std::shared_ptr< WValueSet< T > > vals,
194  unsigned int iterations );
195 
196  std::shared_ptr< WModuleInputData< WDataSetScalar > > m_input; //!< Input connector required by this module.
197  std::shared_ptr< WModuleOutputData< WDataSetScalar > > m_output; //!< The only output of this filter module.
198  std::shared_ptr< WDataSetScalar > m_dataSet; //!< Pointer providing access to the treated data set in the whole module.
199 };
200 #endif // WMGAUSSFILTERING_H
Gauss filtering for WDataSetScalar.
std::shared_ptr< WDataSetScalar > m_dataSet
Pointer providing access to the treated data set in the whole module.
double filterAtPosition(std::shared_ptr< WValueSet< T > > vals, size_t nX, size_t nY, size_t nZ, size_t x, size_t y, size_t z, size_t offset)
Simple convolution using a small gauss-like mask.
virtual void moduleMain()
Entry point after loading the module.
virtual void properties()
Initialize the properties for this module.
~WMGaussFiltering()
Destructor.
virtual std::shared_ptr< WModule > factory() const
Due to the prototype design pattern used to build modules, this method returns a new instance of this...
std::shared_ptr< WModuleInputData< WDataSetScalar > > m_input
Input connector required by this module.
std::shared_ptr< WModuleOutputData< WDataSetScalar > > m_output
The only output of this filter module.
void filterField1D(std::vector< T > *newVals, const std::vector< T > &vals, std::shared_ptr< WProgress > prog, size_t Nx, size_t Ny, size_t Nz, size_t dx, size_t dy, size_t dz)
Run the 1D Gaussian filter over the field.
std::vector< double > filterField(std::shared_ptr< WValueSet< T > > vals, std::shared_ptr< WGridRegular3D > grid, std::shared_ptr< WProgress > prog)
Run the filter over the field.
std::shared_ptr< WValueSet< double > > iterativeFilterField(std::shared_ptr< WValueSet< T > > vals, unsigned int iterations)
Run the filter iteratively over the field.
virtual const std::string getDescription() const
Gives back a description of this module.
WPropBool m_3DMaskMode
1D or 3D filtering flag
virtual void connectors()
Initialize the connectors this module is using.
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
WMGaussFiltering()
Standard constructor.
std::shared_ptr< WCondition > m_propCondition
A condition used to notify about changes in several properties.
virtual const std::string getName() const
Gives back the name of this module.
WPropInt m_iterations
The number of iterations to use for filtering.
Class representing a single module of OpenWalnut.
Definition: WModule.h:72
Base Class for all value set types.
Definition: WValueSet.h:47