fifofilter.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_fifofilter_hh
22 #define __mia_fifofilter_hh
23 
24 #include <vector>
25 #include <memory>
26 #include <cstdlib>
27 #include <boost/call_traits.hpp>
28 #include <mia/core/msgstream.hh>
29 
30 #ifndef EXPORT_HANDLER
31 #ifdef WIN32
32 #define EXPORT_HANDLER __declspec(dllimport)
33 #else
34 #define EXPORT_HANDLER
35 #endif
36 #endif
37 
38 
40 
51 template <typename T>
53 public:
54 
56  typedef std::shared_ptr<TFifoFilter > Pointer;
57 
66  TFifoFilter(size_t width, size_t min_fill, size_t read_start);
67 
72  void push(typename ::boost::call_traits<T>::param_type x);
73 
77  void finalize();
78 
82  void append_filter(Pointer last);
83 protected:
85  size_t get_pos() const;
86 
88  size_t get_buffer_size() const;
89 
91  size_t get_start() const;
92 
94  size_t get_end() const;
95 
96 private:
98  Pointer next() const;
99 
104  virtual void do_initialize(typename ::boost::call_traits<T>::param_type x);
105 
111  virtual void do_push(typename ::boost::call_traits<T>::param_type x) = 0;
112 
117  virtual T do_filter();
118 
122  virtual void post_finalize();
123 
128  virtual void shift_buffer();
129 
135  virtual void evaluate(size_t slice);
136 
137 
138  size_t m_buf_size;
139  size_t m_min_fill;
140  size_t m_read_start;
141  size_t m_fill;
142  size_t m_start_slice;
143  size_t m_end_slice;
144  Pointer m_chain;
145  bool m_initialized;
146 };
147 
156 template <typename T>
158 public:
160  typedef std::vector<T> result_type;
161 
163  typedef std::shared_ptr< TFifoFilterSink<T> > Pointer;
164 
170  TFifoFilterSink();
171 
173  const result_type& result();
174 private:
175  virtual void do_push(typename ::boost::call_traits<T>::param_type x);
176  void shift_buffer();
177  result_type m_result;
178 };
179 
180 
190 template <typename T>
191 struct __copy_create_ptr {
192  static std::shared_ptr<T > apply (typename ::boost::call_traits<T>::param_type x){
193  return std::shared_ptr<T >(new T(x));
194  }
195 };
196 
198 
200 
201 #endif
std::shared_ptr< TFifoFilter > Pointer
smart pointer representing this class
Definition: fifofilter.hh:56
std::shared_ptr< TFifoFilterSink< T > > Pointer
smart pointer representing this class
Definition: fifofilter.hh:163
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
std::vector< T > result_type
The result of the processing.
Definition: fifofilter.hh:160
Helper class for testing FIFO filter chains.
Definition: fifofilter.hh:157
#define EXPORT_HANDLER
Definition: fifofilter.hh:34
Generic base class for out-of-core FIFO filters.
Definition: fifofilter.hh:52
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36