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