aimsalgo  5.0.5
Neuroimaging image processing
diffusionSmoother.h
Go to the documentation of this file.
1 /* This software and supporting documentation are distributed by
2  * Institut Federatif de Recherche 49
3  * CEA/NeuroSpin, Batiment 145,
4  * 91191 Gif-sur-Yvette cedex
5  * France
6  *
7  * This software is governed by the CeCILL-B license under
8  * French law and abiding by the rules of distribution of free software.
9  * You can use, modify and/or redistribute the software under the
10  * terms of the CeCILL-B license as circulated by CEA, CNRS
11  * and INRIA at the following URL "http://www.cecill.info".
12  *
13  * As a counterpart to the access to the source code and rights to copy,
14  * modify and redistribute granted by the license, users are provided only
15  * with a limited warranty and the software's author, the holder of the
16  * economic rights, and the successive licensors have only limited
17  * liability.
18  *
19  * In this respect, the user's attention is drawn to the risks associated
20  * with loading, using, modifying and/or developing or reproducing the
21  * software by the user in light of its specific status of free software,
22  * that may mean that it is complicated to manipulate, and that also
23  * therefore means that it is reserved for developers and experienced
24  * professionals having in-depth computer knowledge. Users are therefore
25  * encouraged to load and test the software's suitability as regards their
26  * requirements in conditions enabling the security of their systems and/or
27  * data to be ensured and, more generally, to use and operate it in the
28  * same conditions as regards security.
29  *
30  * The fact that you are presently reading this means that you have had
31  * knowledge of the CeCILL-B license and that you accept its terms.
32  */
33 
34 
35 #ifndef AIMS_PRIMALSKETCH_DIFFUSIONSMOOTHER_H
36 #define AIMS_PRIMALSKETCH_DIFFUSIONSMOOTHER_H
37 
38 #include <cstdlib>
40 
41 namespace aims
42 {
43 
45 template<typename T>
46 class BaseDiffusionSmoother : public Smoother<AimsData<T>, AimsData<T> >
47 {
48 public:
49  BaseDiffusionSmoother(float delta_t) {this->SetDt(delta_t);}
51 public:
52  void check(int maxiter);
53  bool optimal() {return true;}
54  void SetDt(float Delta_t) {
55  if (Delta_t<=0.25) _dt=Delta_t;
56  else {
57  std::cerr << "Diffusion Smoother : dt must be <= 0.25"
58  << std::endl; exit(EXIT_FAILURE);
59  }
60  }
61  virtual AimsData<T> doSmoothing(const AimsData<T> & ima,
62  int maxiter, bool verbose=false) = 0;
63 
64  float dt() {return _dt;}
65 
66 public:
67  static AimsData<float> init_laplacian(void);
69 
70 protected:
71  float _dt;
72 };
73 
74 
77 template<typename T>
79 {
80 public:
81  DiffusionSmoother(float delta_t) : BaseDiffusionSmoother<T>(delta_t),
82  _hasConstantSources( false ) {}
84 
85 public:
86  virtual AimsData<T> doSmoothing(const AimsData<T> & ima,
87  int maxiter, bool verbose=false);
88  void setConstantSources( const AimsData<T> &, const T & background );
89  void removeConstantSources();
90 
91 private:
92  AimsData<T> _constantSources;
93  bool _hasConstantSources;
94  T _constantSourcesBackground;
95 };
96 
97 
98 template<typename T>
100 {
101 public:
102  BaseMaskedDiffusionSmoother(float delta_t, bool safe=true) :
103  BaseDiffusionSmoother<T>(delta_t), _mask(NULL), _safe(safe) {}
105 
106 public:
107  virtual AimsData<T> doSmoothing(const AimsData<T> & ima,
108  int maxiter, bool verbose=false) = 0;
109  void setMask( AimsData<short> *const mask, short background=0)
110  {
111  _mask = mask;
112  _background = background;
113  }
114 
115 protected:
117  bool _safe;
118  short _background;
119 };
120 
121 
122 
123 template<typename T, typename N=std::vector<Point3df> >
125 {
126 public:
127  MaskedDiffusionSmoother(float delta_t, bool safe=true) :
128  BaseMaskedDiffusionSmoother<T>(delta_t, safe) {}
130 
131 public:
132  AimsData<T> doSmoothing(const AimsData<T> & ima,
133  int maxiter, bool verbose=false);
134 };
135 
145 template<typename T>
146 class MaskedDiffusionSmoother<T, std::vector<Point3df> > :
148 {
149 public:
150  MaskedDiffusionSmoother(float delta_t, bool safe=true) :
151  BaseMaskedDiffusionSmoother<T>(delta_t, safe),
152  _has_neumann_condition(false) {}
154 
155 public:
156  virtual AimsData<T> doSmoothing(const AimsData<T> & ima,
157  int maxiter, bool verbose=false);
158  void add_neumann_condition(const Point3df &p);
159 
160 private :
161  void update_neumann_conditions(AimsData<float> &ima);
162 
163 private :
164  bool _has_neumann_condition;
165  std::vector<Point3df> _neumann_conditions;
166 };
167 
168 
169 
178 template<typename T>
181 {
182 public:
183  MaskedDiffusionSmoother(float delta_t, bool safe=true) :
184  BaseMaskedDiffusionSmoother<T>(delta_t, safe),
185  _neumann_value(1) {}
187 
188 public:
189  virtual AimsData<T> doSmoothing(const AimsData<T> & ima,
190  int maxiter, bool verbose=false);
191  void set_neumann_value(short value) {
192  _neumann_value = value;
193  }
194 
195  void convolution(const AimsData<float> &ima1,
196  AimsData<float> &ima2) const;
197 private:
198  short _neumann_value;
199 };
200 
201 }
202 
203 #endif
static AimsData< float > laplacian
DiffusionSmoother(float delta_t)
BucketMap< Void > * mask(const BucketMap< Void > &src, const BucketMap< Void > &m, bool intersect=true)
static AimsData< float > init_laplacian(void)
Heat diffusion with a volume of given datasource (Dirichlet conditions)
virtual AimsData< T > doSmoothing(const AimsData< T > &ima, int maxiter, bool verbose=false)=0
STL namespace.
BaseDiffusionSmoother(float delta_t)
BaseMaskedDiffusionSmoother(float delta_t, bool safe=true)
int verbose
Base class for Heat diffusion.
MaskedDiffusionSmoother(float delta_t, bool safe=true)
void setMask(AimsData< short > *const mask, short background=0)