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
26#include <mia/core/iohandler.hh>
27
28
29
31
32template <typename Image>
34{
35public:
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;
44
45};
46
47
48template <class Image>
50{
51public:
53 virtual TDataFilter<Image> *do_create()const;
54 virtual const std::string do_get_descr()const;
55private:
56 std::shared_ptr<TImageCombiner<Image>> m_combiner;
57 std::string m_other_image;
58 bool m_reverse;
59
60};
61
62template <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
71template <typename Image>
72typename 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
83template <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
95template <typename Image>
97{
98 return new TImageCombinerFilter<Image>(m_combiner, m_other_image, m_reverse);
99}
100
101template <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
void add_parameter(const std::string &name, CParameter *param)
an string parameter
Definition parameter.hh:537
Generic image filter plugin base.
Generic interface class to data filters.
Image Image
defines the image type handled by the image filter
the singleton that a plug-in handler really is
Definition handler.hh:159
virtual const std::string do_get_descr() const
virtual TDataFilter< Image > * do_create() const
std::shared_ptr< TImageCombiner< Image > > m_combiner
TImageCombinerFilter(std::shared_ptr< TImageCombiner< Image > > combiner, const std::string &other_image_file, bool reverse)
Image::Pointer do_filter(const Image &image) const
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition defines.hh:33
#define NS_MIA_END
conveniance define to end the mia namespace
Definition defines.hh:36
CTParameter< bool > CBoolParameter
boolean parameter
Definition parameter.hh:561
CParameter * make_param(T &value, bool required, const char *descr)
Definition parameter.hh:280