aimsalgo  5.0.5
Neuroimaging image processing
elementfilterfactory_d.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 #ifndef AIMS_SIGNALFILTER_ELEMENTFILTERFACTORY_D_H
35 #define AIMS_SIGNALFILTER_ELEMENTFILTERFACTORY_D_H
36 
37 //--- aims -------------------------------------------------------------------
39 //--- registered algo --------------------------------------------------------
49 //----------------------------------------------------------------------------
50 
51 namespace aims {
52 
53  //==========================================================================
54  // NON LINEAR FILTERING ALGORITHM: FACTORY
55  //==========================================================================
56 
57  template <typename T>
58  void ElementFilterFactory<T>::init()
59  {
60  static bool initialized = false;
61  if( !initialized )
62  {
63  initialized = true;
64  registerFilter( "min", MinFilter<T>() );
65  registerFilter( "max", MaxFilter<T>() );
66  registerFilter( "med", MedianFilter<T>() );
67  registerFilter( "median", MedianFilter<T>() );
68  registerFilter( "notnullmedian", NotNullMedianFilter<T>() );
69  registerFilter( "mea", MeanFilter<T>() );
70  registerFilter( "mean", MeanFilter<T>() );
71  registerFilter( "notnullmean", NotNullMeanFilter<T>() );
72  registerFilter( "maj", MajorityFilter<T>() );
73  registerFilter( "majority", MajorityFilter<T>() );
74  registerFilter( "dif", ExtremaDifferenceFilter<T>() );
75  registerFilter( "difference", ExtremaDifferenceFilter<T>() );
76  registerFilter( "sum", SumFilter<T>() );
77  registerFilter( "var", VarFilter<T>() );
78  registerFilter( "variance", VarFilter<T>() );
79  registerFilter( "sd", StDevFilter<T>() );
80  }
81  }
82 
83  template <typename T>
84  std::map<std::string,carto::rc_ptr<ElementFilteringImageAlgorithm<T> > > & ElementFilterFactory<T>::_map()
85  {
86  static std::map<std::string,carto::rc_ptr<ElementFilteringImageAlgorithm<T> > > m;
87  return m;
88  }
89 
90  template <typename T>
91  void ElementFilterFactory<T>::registerFilter(
92  const std::string & name,
93  const ElementFilteringImageAlgorithm<T> & func
94  )
95  {
96  init();
97  _map()[ name ] = carto::rc_ptr<ElementFilteringImageAlgorithm<T> >( func.clone() );
98  }
99 
100  template <typename T>
101  std::set<std::string> ElementFilterFactory<T>::names()
102  {
103  init();
104  std::set<std::string> s;
105  typename std::map<std::string,carto::rc_ptr<ElementFilteringImageAlgorithm<T> > >::const_iterator i, e = _map().end();
106  for( i=_map().begin(); i!=e; ++i )
107  s.insert( i->first );
108  return( s );
109  }
110 
111  template <typename T>
112  ElementFilteringImageAlgorithm<T>* ElementFilterFactory<T>::create(
113  const std::string & name,
114  const StructuringElement & strel,
115  carto::Object options
116  )
117  {
118  init();
119  typename std::map<std::string,carto::rc_ptr<ElementFilteringImageAlgorithm<T> > >::const_iterator i;
120  i = _map().find( name );
121  if( i == _map().end() )
122  return( 0 );
123  ElementFilteringImageAlgorithm<T> * new_func = i->second->clone();
124  new_func->setOptions( options );
125  new_func->setStructuringElement( strel );
126  return new_func;
127  }
128 
129  template <typename T>
130  ElementFilteringImageAlgorithm<T>* ElementFilterFactory<T>::create(
131  const std::string & name,
132  carto::Object options
133  )
134  {
135  return create( name, strel::Cube(1.0), options );
136  }
137 
138 
139 } // namespace aims
140 
141 #endif
const T * const_iterator