aimsalgo  5.1.2
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( "notnullmajority", NotNullMajorityFilter<T>() );
75  registerFilter( "dif", ExtremaDifferenceFilter<T>() );
76  registerFilter( "difference", ExtremaDifferenceFilter<T>() );
77  registerFilter( "sum", SumFilter<T>() );
78  registerFilter( "var", VarFilter<T>() );
79  registerFilter( "variance", VarFilter<T>() );
80  registerFilter( "sd", StDevFilter<T>() );
81  }
82  }
83 
84  template <typename T>
85  std::map<std::string,carto::rc_ptr<ElementFilteringImageAlgorithm<T> > > & ElementFilterFactory<T>::_map()
86  {
87  static std::map<std::string,carto::rc_ptr<ElementFilteringImageAlgorithm<T> > > m;
88  return m;
89  }
90 
91  template <typename T>
92  void ElementFilterFactory<T>::registerFilter(
93  const std::string & name,
94  const ElementFilteringImageAlgorithm<T> & func
95  )
96  {
97  init();
98  _map()[ name ] = carto::rc_ptr<ElementFilteringImageAlgorithm<T> >( func.clone() );
99  }
100 
101  template <typename T>
102  std::set<std::string> ElementFilterFactory<T>::names()
103  {
104  init();
105  std::set<std::string> s;
106  typename std::map<std::string,carto::rc_ptr<ElementFilteringImageAlgorithm<T> > >::const_iterator i, e = _map().end();
107  for( i=_map().begin(); i!=e; ++i )
108  s.insert( i->first );
109  return( s );
110  }
111 
112  template <typename T>
113  ElementFilteringImageAlgorithm<T>* ElementFilterFactory<T>::create(
114  const std::string & name,
115  const StructuringElement & strel,
116  carto::Object options
117  )
118  {
119  init();
120  typename std::map<std::string,carto::rc_ptr<ElementFilteringImageAlgorithm<T> > >::const_iterator i;
121  i = _map().find( name );
122  if( i == _map().end() )
123  return( 0 );
124  ElementFilteringImageAlgorithm<T> * new_func = i->second->clone();
125  new_func->setOptions( options );
126  new_func->setStructuringElement( strel );
127  return new_func;
128  }
129 
130  template <typename T>
131  ElementFilteringImageAlgorithm<T>* ElementFilterFactory<T>::create(
132  const std::string & name,
133  carto::Object options
134  )
135  {
136  return create( name, strel::Cube(1.0), options );
137  }
138 
139 
140 } // namespace aims
141 
142 #endif
const T * const_iterator