OpenWalnut  1.5.0dev
WMAnisotropicFiltering.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 WMANISOTROPICFILTERING_H
26 #define WMANISOTROPICFILTERING_H
27 
28 #include <memory>
29 #include <string>
30 #include <vector>
31 
32 #include "core/dataHandler/WDataSetSingle.h"
33 #include "core/dataHandler/WValueSet.h"
34 #include "core/kernel/WModule.h"
35 #include "core/kernel/WModuleInputData.h"
36 #include "core/kernel/WModuleOutputData.h"
37 
38 /**
39  * This module smoothes images of a dataset while preserving edges.
40  *
41  * \ingroup modules
42  */
44 {
45 public:
46  /**
47  * Standard constructor.
48  */
50 
51  /**
52  * Destructor.
53  */
54  virtual ~WMAnisotropicFiltering();
55 
56  /**
57  * Gives back the name of this module.
58  * \return the module's name.
59  */
60  virtual const std::string getName() const;
61 
62  /**
63  * Gives back a description of this module.
64  * \return description to module.
65  */
66  virtual const std::string getDescription() const;
67 
68  /**
69  * Due to the prototype design pattern used to build modules, this method returns a new instance of this method. NOTE: it
70  * should never be initialized or modified in some other way. A simple new instance is required.
71  *
72  * \return the prototype used to create every module in OpenWalnut.
73  */
74  virtual std::shared_ptr< WModule > factory() const;
75 
76  /**
77  * Return an icon for this module.
78  *
79  * \return the icon
80  */
81  virtual const char** getXPMIcon() const;
82 
83 protected:
84  /**
85  * Entry point after loading the module. Runs in separate thread.
86  */
87  virtual void moduleMain();
88 
89  /**
90  * Initialize the connectors this module is using.
91  */
92  virtual void connectors();
93 
94  /**
95  * Initialize the properties for this module.
96  */
97  virtual void properties();
98 
99  /**
100  * Callback for m_active.
101  */
102  virtual void activate();
103 
104 private:
105  /**
106  * Calculates the resulting smoothed image.
107  *
108  * \param iterations The number of diffusion time steps.
109  */
110  void calcSmoothedImages( int iterations );
111 
112  /**
113  * Calculates grid indices from voxel coords.
114  *
115  * \param grid The grid.
116  * \param x The x-coord.
117  * \param y The y-coord.
118  * \param z The z-coord.
119  *
120  * \return The voxel index.
121  */
122  std::size_t coordsToIndex( std::shared_ptr< WGridRegular3D > const& grid,
123  std::size_t x, std::size_t y, std::size_t z );
124 
125  /**
126  * Copy the datasets image data to a temp array.
127  *
128  * \param smoothed The temp array to copy to.
129  * \param grid The grid, which is not used in this function.
130  */
131  void copyData( std::shared_ptr< std::vector< double > >& smoothed, // NOLINT non-const ref
132  std::shared_ptr< WGridRegular3D > const& grid );
133 
134  /**
135  * Calculates an array containing the derivatives in x, y and z directions of the image
136  * intensity (i.e. contains the intensity gradient).
137  *
138  * \param deriv The memory used for the gradient values.
139  * \param smoothed The intensity data.
140  * \param grid The grid.
141  * \param image The index of the image to calc the gradient from.
142  * \param numImages The number of images in this dataset.
143  */
144  void calcDeriv( std::vector< double >& deriv, std::shared_ptr< std::vector< double > > const& smoothed, // NOLINT non-const ref
145  std::shared_ptr< WGridRegular3D > const& grid, std::size_t image, std::size_t numImages );
146 
147  /**
148  * Calculates the diffusion coeff for every voxel.
149  *
150  * \param coeff The memory used for the coeff data.
151  * \param deriv The gradient data.
152  * \param grid The grid.
153  */
154  void calcCoeff( std::vector< double >& coeff, std::vector< double > const& deriv, // NOLINT non-const ref
155  std::shared_ptr< WGridRegular3D > const& grid );
156 
157  /**
158  * Do the diffusion.
159  *
160  * \param deriv The intensity gradient data.
161  * \param coeff The diffusion coeffs.
162  * \param smoothed The new smoothed image.
163  * \param grid The grid.
164  * \param image The index of the image to calc the gradient from.
165  * \param numImages The number of images in this dataset.
166  */
167  void diffusion( std::vector< double > const& deriv, std::vector< double > const& coeff,
168  std::shared_ptr< std::vector< double > >& smoothed, // NOLINT non-const ref
169  std::shared_ptr< WGridRegular3D > const& grid, std::size_t image, std::size_t numImages );
170 
171  /**
172  * An input connector that accepts multi image datasets.
173  */
174  std::shared_ptr< WModuleInputData< WDataSetSingle > > m_input;
175 
176  /**
177  * An output connector for the output dataset.
178  */
179  std::shared_ptr< WModuleOutputData< WDataSetSingle > > m_output;
180 
181  /**
182  * This is a pointer to the dataset the module is currently working on.
183  */
184  std::shared_ptr< WDataSetSingle > m_dataSet;
185 
186  /**
187  * A condition used to notify about changes in several properties.
188  */
189  std::shared_ptr< WCondition > m_propCondition;
190 
191  //! The edge preservation parameter used for diffusion coeff calculation.
192  double m_k;
193 
194  //! The size of the time steps.
195  double m_d;
196 
197  //! A property for the number of iterations.
198  WPropInt m_iterations;
199 
200  //! A property for the edge preservation parameter.
201  WPropDouble m_Kcoeff;
202 
203  //! A property for the time step size.
204  WPropDouble m_delta;
205 };
206 
207 #endif // WMANISOTROPICFILTERING_H
This module smoothes images of a dataset while preserving edges.
std::shared_ptr< WDataSetSingle > m_dataSet
This is a pointer to the dataset the module is currently working on.
virtual void moduleMain()
Entry point after loading the module.
std::shared_ptr< WCondition > m_propCondition
A condition used to notify about changes in several properties.
double m_d
The size of the time steps.
WPropDouble m_Kcoeff
A property for the edge preservation parameter.
void calcDeriv(std::vector< double > &deriv, std::shared_ptr< std::vector< double > > const &smoothed, std::shared_ptr< WGridRegular3D > const &grid, std::size_t image, std::size_t numImages)
Calculates an array containing the derivatives in x, y and z directions of the image intensity (i....
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...
virtual const std::string getName() const
Gives back the name of this module.
WPropDouble m_delta
A property for the time step size.
virtual const char ** getXPMIcon() const
Return an icon for this module.
void calcCoeff(std::vector< double > &coeff, std::vector< double > const &deriv, std::shared_ptr< WGridRegular3D > const &grid)
Calculates the diffusion coeff for every voxel.
virtual ~WMAnisotropicFiltering()
Destructor.
std::shared_ptr< WModuleOutputData< WDataSetSingle > > m_output
An output connector for the output dataset.
void copyData(std::shared_ptr< std::vector< double > > &smoothed, std::shared_ptr< WGridRegular3D > const &grid)
Copy the datasets image data to a temp array.
void diffusion(std::vector< double > const &deriv, std::vector< double > const &coeff, std::shared_ptr< std::vector< double > > &smoothed, std::shared_ptr< WGridRegular3D > const &grid, std::size_t image, std::size_t numImages)
Do the diffusion.
virtual const std::string getDescription() const
Gives back a description of this module.
virtual void properties()
Initialize the properties for this module.
std::shared_ptr< WModuleInputData< WDataSetSingle > > m_input
An input connector that accepts multi image datasets.
WMAnisotropicFiltering()
Standard constructor.
void calcSmoothedImages(int iterations)
Calculates the resulting smoothed image.
virtual void connectors()
Initialize the connectors this module is using.
std::size_t coordsToIndex(std::shared_ptr< WGridRegular3D > const &grid, std::size_t x, std::size_t y, std::size_t z)
Calculates grid indices from voxel coords.
double m_k
The edge preservation parameter used for diffusion coeff calculation.
WPropInt m_iterations
A property for the number of iterations.
virtual void activate()
Callback for m_active.
Class representing a single module of OpenWalnut.
Definition: WModule.h:72