snark
pipeline.h
1 // This file is part of snark, a generic and flexible library
2 // for robotics research.
3 //
4 // Copyright (C) 2011 The University of Sydney
5 //
6 // snark is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 3 of the License, or (at your option) any later version.
10 //
11 // snark is distributed in the hope that it will be useful, but WITHOUT ANY
12 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14 // for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with snark. If not, see <http://www.gnu.org/licenses/>.
18 
19 #ifndef SNARK_IMAGING_APPLICATIONS_PIPELINE_H_
20 #define SNARK_IMAGING_APPLICATIONS_PIPELINE_H_
21 
22 #ifdef WIN32
23 #include <winsock2.h>
24 #endif
25 
26 #include <comma/application/signal_flag.h>
27 #include <snark/tbb/bursty_reader.h>
28 #include <snark/imaging/cv_mat/bursty_pipeline.h>
29 #include <snark/imaging/cv_mat/serialization.h>
30 #include <snark/imaging/cv_mat/filters.h>
31 
32 namespace snark {
33 
34 namespace tbb {
35 
36 template<>
37 struct bursty_reader_traits< std::pair< boost::posix_time::ptime, cv::Mat > >
38 {
39  static bool valid( const std::pair< boost::posix_time::ptime, cv::Mat >& p ) { return ( p.second.size().width > 0 ); }
40 };
41 
42 }
43 
44 namespace imaging { namespace applications {
45 
47 class pipeline
48 {
49 public:
50  typedef std::pair< boost::posix_time::ptime, cv::Mat > pair;
51  pipeline( cv_mat::serialization& output, const std::string& filters, tbb::bursty_reader< pair >& reader );
52 
53  void run();
54 
55 protected:
56  void write_( pair p );
57  void null_( pair p );
58  void setup_pipeline_( const std::string& filters );
59 
60  cv_mat::serialization& m_output;
61  ::tbb::filter_t< pair, void > m_filter;
62  std::vector< cv_mat::filter > m_filters;
65  comma::signal_flag is_shutdown_;
66 };
67 
68 
69 } } }
70 
71 #endif // SNARK_IMAGING_APPLICATIONS_PIPELINE_H_