convert.hh
Go to the documentation of this file.
1 /* -*- mia-c++ -*-
2  *
3  * This file is part of MIA - a toolbox for medical image analysis
4  * Copyright (c) Leipzig, Madrid 1999-2017 Gert Wollny
5  *
6  * MIA is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with MIA; if not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 #ifndef __mia_internal_convert_hh
22 #define __mia_internal_convert_hh
23 
24 #include <mia/core/filter.hh>
25 
26 
28 
30 /*
31 
32  \ingroup templates
33  \brief Generic pixel conversion for images
34 
35  This class implements the image pixel type conversion.
36  Various mappings are supported and defined as EPixelConversion.
37  \tparam Image the image type that must provide STL-like iterators.
38  */
39 template <class Image>
40 class TConvert: public TDataFilter<Image> {
41 public:
43 
51  TConvert(mia::EPixelType pt, EPixelConversion ct, float a, float b);
52 
60  template <template <typename> class Data, typename T>
61  typename TConvert<Image>::result_type operator () (const Data<T>& data) const;
62 
63 private:
64  template <template <typename> class Data, typename S, typename T>
65  typename TConvert<Image>::result_type convert(const Data<S>& src) const;
66  typename TConvert::result_type do_filter(const Image& image) const;
67 
68  EPixelType m_pt;
69  EPixelConversion m_ct;
70  float m_a;
71  float m_b;
72 };
73 
74 /*
75  \ingroup templates
76  \brief Generic plug-in for pixel conversion image filters
77 */
78 template <class Image>
79 class TConvertFilterPlugin: public TDataFilterPlugin<Image> {
80 public:
81  TConvertFilterPlugin();
82 private:
83  virtual TDataFilter<Image> *do_create()const;
84  virtual const std::string do_get_descr()const;
85 
86  EPixelType m_pixeltype;
87  EPixelConversion m_convert;
88  float m_a;
89  float m_b;
90 
91 };
92 
94 
100 template <typename T, bool is_float>
101 struct __mia_round {
102  static T apply(T x) {
103  return x;
104  }
105 };
106 
107 template <typename T>
108 struct __mia_round<T, false> {
109  static T apply(long double x) {
110  return static_cast<T>(floor(x + 0.5));
111  }
112 };
113 
114 template <typename T, bool is_float>
115 struct __dispatch_minmax {
116  static std::pair<T, T> apply() {
117  return std::pair<T, T>(std::numeric_limits<T>::min(),std::numeric_limits<T>::max());
118  }
119 };
120 
121 template <typename T>
122 struct __dispatch_minmax<T, true> {
123  static std::pair<T, T> apply() {
124  return std::pair<T, T>(-1.0f, 1.0f);
125  }
126 };
127 
128 template <typename T>
129 struct get_minmax {
130  static std::pair<T, T> apply() {
131  return __dispatch_minmax<T, std::is_floating_point<T>::value >::apply();
132  }
133 };
134 
136 
138 
139 #endif
EPixelType
Definition: pixeltype.hh:32
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
Generic image filter plugin base.
Definition: core/filter.hh:178
TFilter< std::shared_ptr< D > >::result_type result_type
result type of this filter
Definition: core/filter.hh:101
Generic interface class to data filters.
Definition: core/filter.hh:86
EPixelConversion
Definition: pixeltype.hh:50
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36