My Project
combiner_filter.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_template_combiner_filter_hh
22 #define mia_template_combiner_filter_hh
23 
24 
25 #include <mia/template/combiner.hh>
26 #include <mia/core/iohandler.hh>
27 
28 
29 
31 
32 template <typename Image>
33 class TImageCombinerFilter: public TDataFilter<Image>
34 {
35 public:
36  TImageCombinerFilter(std::shared_ptr<TImageCombiner<Image>> combiner,
37  const std::string& other_image_file, bool reverse);
38 
39  typename Image::Pointer do_filter(const Image& image) const;
40 
41  std::shared_ptr<TImageCombiner<Image>> m_combiner;
42  std::string m_other_image;
43  bool m_reverse;
44 
45 };
46 
47 
48 template <class Image>
50 {
51 public:
53  virtual TDataFilter<Image> *do_create()const;
54  virtual const std::string do_get_descr()const;
55 private:
56  std::shared_ptr<TImageCombiner<Image>> m_combiner;
57  std::string m_other_image;
58  bool m_reverse;
59 
60 };
61 
62 template <typename Image>
64  const std::string& other_image_file, bool reverse):
65  m_combiner(combiner),
66  m_other_image(other_image_file),
67  m_reverse(reverse)
68 {
69 }
70 
71 template <typename Image>
72 typename Image::Pointer TImageCombinerFilter<Image>::do_filter(const Image& image) const
73 {
74  auto other_image = load_image<typename Image::Pointer>(m_other_image);
75 
76  if (m_reverse)
77  return m_combiner->combine(*other_image, image);
78  else
79  return m_combiner->combine(image, *other_image);
80 }
81 
82 
83 template <typename Image>
85  TDataFilterPlugin<Image>("combiner"),
86  m_reverse(false)
87 {
88  typedef typename IOHandler_of<Image>::type IOHandler;
89  this->add_parameter("op", make_param(m_combiner, "", true, "Image combiner to be applied to the images"));
90  this->add_parameter("image", new CStringParameter(m_other_image, CCmdOptionFlags::required_input, "second image that is needed in the combiner",
91  &IOHandler::instance()));
92  this->add_parameter("reverse", new CBoolParameter(m_reverse, false, "reverse the order in which the images passed to the combiner"));
93 }
94 
95 template <typename Image>
97 {
98  return new TImageCombinerFilter<Image>(m_combiner, m_other_image, m_reverse);
99 }
100 
101 template <typename Image>
103 {
104  return "Combine two images with the given combiner operator. if 'reverse' is set to false, the first "
105  "operator is the image passed through the filter pipeline, and the second image is loaded "
106  "from the file given with the 'image' parameter the moment the filter is run.";
107 }
108 
110 
111 #endif
CParamTranslator::add_parameter
void add_parameter(const std::string &name, CParameter *param)
TImageCombinerFilter
Definition: combiner_filter.hh:34
NS_MIA_BEGIN
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
combiner.hh
TImageCombinerFilterPlugin::TImageCombinerFilterPlugin
TImageCombinerFilterPlugin()
Definition: combiner_filter.hh:84
NS_MIA_END
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36
TImageCombinerFilter::do_filter
Image::Pointer do_filter(const Image &image) const
Definition: combiner_filter.hh:72
make_param
CParameter * make_param(T &value, bool required, const char *descr)
Definition: parameter.hh:280
THandlerSingleton
the singleton that a plug-in handler really is
Definition: handler.hh:159
iohandler.hh
TImageCombinerFilterPlugin
Definition: combiner_filter.hh:50
CStringParameter
an string parameter
Definition: parameter.hh:537
TImageCombiner
Definition: template/combiner.hh:33
TImageCombinerFilter::m_other_image
std::string m_other_image
Definition: combiner_filter.hh:42
TImageCombinerFilterPlugin::do_get_descr
virtual const std::string do_get_descr() const
Definition: combiner_filter.hh:102
TDataFilter< Image >::Image
Image Image
defines the image type handled by the image filter
Definition: core/filter.hh:96
TDataFilter
Generic interface class to data filters.
Definition: core/filter.hh:87
TImageCombinerFilter::TImageCombinerFilter
TImageCombinerFilter(std::shared_ptr< TImageCombiner< Image >> combiner, const std::string &other_image_file, bool reverse)
Definition: combiner_filter.hh:63
TImageCombinerFilter::m_reverse
bool m_reverse
Definition: combiner_filter.hh:43
TImageCombinerFilter::m_combiner
std::shared_ptr< TImageCombiner< Image > > m_combiner
Definition: combiner_filter.hh:41
CBoolParameter
CTParameter< bool > CBoolParameter
boolean parameter
Definition: parameter.hh:561
TImageCombinerFilterPlugin::do_create
virtual TDataFilter< Image > * do_create() const
Definition: combiner_filter.hh:96
TDataFilterPlugin
Generic image filter plugin base.
Definition: core/filter.hh:186