My Project
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 {
54 public:
55 
57  typedef std::shared_ptr<TFifoFilter > Pointer;
58 
67  TFifoFilter(size_t width, size_t min_fill, size_t read_start);
68 
73  void push(typename ::boost::call_traits<T>::param_type x);
74 
78  void finalize();
79 
83  void append_filter(Pointer last);
84 protected:
86  size_t get_pos() const;
87 
89  size_t get_buffer_size() const;
90 
92  size_t get_start() const;
93 
95  size_t get_end() const;
96 
97 private:
99  Pointer next() const;
100 
105  virtual void do_initialize(typename ::boost::call_traits<T>::param_type x);
106 
112  virtual void do_push(typename ::boost::call_traits<T>::param_type x) = 0;
113 
118  virtual T do_filter();
119 
123  virtual void post_finalize();
124 
129  virtual void shift_buffer();
130 
136  virtual void evaluate(size_t slice);
137 
138 
139  size_t m_buf_size;
140  size_t m_min_fill;
141  size_t m_read_start;
142  size_t m_fill;
143  size_t m_start_slice;
144  size_t m_end_slice;
145  Pointer m_chain;
146  bool m_initialized;
147 };
148 
157 template <typename T>
159 {
160 public:
162  typedef std::vector<T> result_type;
163 
165  typedef std::shared_ptr< TFifoFilterSink<T>> Pointer;
166 
173 
175  const result_type& result();
176 private:
177  virtual void do_push(typename ::boost::call_traits<T>::param_type x);
178  void shift_buffer();
179  result_type m_result;
180 };
181 
182 
192 template <typename T>
193 struct __copy_create_ptr {
194  static std::shared_ptr<T > apply (typename ::boost::call_traits<T>::param_type x)
195  {
196  return std::shared_ptr<T >(new T(x));
197  }
198 };
199 
201 
203 
204 #endif
Helper class for testing FIFO filter chains.
Definition: fifofilter.hh:159
std::shared_ptr< TFifoFilterSink< T > > Pointer
smart pointer representing this class
Definition: fifofilter.hh:165
const result_type & result()
std::vector< T > result_type
The result of the processing.
Definition: fifofilter.hh:162
Generic base class for out-of-core FIFO filters.
Definition: fifofilter.hh:53
std::shared_ptr< TFifoFilter > Pointer
smart pointer representing this class
Definition: fifofilter.hh:57
size_t get_buffer_size() const
void finalize()
size_t get_start() const
size_t get_end() const
size_t get_pos() const
TFifoFilter(size_t width, size_t min_fill, size_t read_start)
void push(typename ::boost::call_traits< T >::param_type x)
void append_filter(Pointer last)
#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
#define EXPORT_HANDLER
Definition: fifofilter.hh:34