My Project
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 {
42 public:
44 
52  TConvert(mia::EPixelType pt, EPixelConversion ct, float a, float b);
53 
61  template <template <typename> class Data, typename T>
62  typename TConvert<Image>::result_type operator () (const Data<T>& data) const;
63 
64 private:
65  template <template <typename> class Data, typename S, typename T>
66  typename TConvert<Image>::result_type convert(const Data<S>& src) const;
67  typename TConvert::result_type do_filter(const Image& image) const;
68 
69  EPixelType m_pt;
70  EPixelConversion m_ct;
71  float m_a;
72  float m_b;
73 };
74 
75 /*
76  \ingroup templates
77  \brief Generic plug-in for pixel conversion image filters
78 */
79 template <class Image>
80 class TConvertFilterPlugin: public TDataFilterPlugin<Image>
81 {
82 public:
83  TConvertFilterPlugin();
84 private:
85  virtual TDataFilter<Image> *do_create()const;
86  virtual const std::string do_get_descr()const;
87 
88  EPixelType m_pixeltype;
89  EPixelConversion m_convert;
90  float m_a;
91  float m_b;
92 
93 };
94 
96 
102 template <typename T, bool is_float>
103 struct __mia_round {
104  static T apply(T x)
105  {
106  return x;
107  }
108 };
109 
110 template <typename T>
111 struct __mia_round<T, false> {
112  static T apply(long double x)
113  {
114  return static_cast<T>(floor(x + 0.5));
115  }
116 };
117 
118 template <typename T, bool is_float>
119 struct __dispatch_minmax {
120  static std::pair<T, T> apply()
121  {
122  return std::pair<T, T>(std::numeric_limits<T>::min(), std::numeric_limits<T>::max());
123  }
124 };
125 
126 template <typename T>
127 struct __dispatch_minmax<T, true> {
128  static std::pair<T, T> apply()
129  {
130  return std::pair<T, T>(-1.0f, 1.0f);
131  }
132 };
133 
134 template <typename T>
135 struct get_minmax {
136  static std::pair<T, T> apply()
137  {
138  return __dispatch_minmax<T, std::is_floating_point<T>::value >::apply();
139  }
140 };
141 
143 
145 
146 #endif
NS_MIA_BEGIN
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
NS_MIA_END
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36
TDataFilter
Generic interface class to data filters.
Definition: core/filter.hh:87
TDataFilter::result_type
TFilter< std::shared_ptr< D > >::result_type result_type
result type of this filter
Definition: core/filter.hh:102
EPixelConversion
EPixelConversion
Definition: pixeltype.hh:50
EPixelType
EPixelType
Definition: pixeltype.hh:32
filter.hh
TDataFilterPlugin
Generic image filter plugin base.
Definition: core/filter.hh:186