$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
non_text_img_visitor.hh
1 // Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #ifndef SCRIBO_IO_IMG_INTERNAL_NON_TEXT_IMG_VISITOR_HH
27 # define SCRIBO_IO_IMG_INTERNAL_NON_TEXT_IMG_VISITOR_HH
28 
32 
33 # include <fstream>
34 
35 
36 # include <mln/core/image/image2d.hh>
37 # include <mln/value/rgb8.hh>
38 # include <mln/draw/box.hh>
39 
40 # include <scribo/core/internal/doc_serializer.hh>
41 # include <scribo/io/img/internal/draw_edges.hh>
42 
43 namespace scribo
44 {
45 
46  namespace io
47  {
48 
49  namespace img
50  {
51 
52  namespace internal
53  {
54 
57  class non_text_img_visitor : public doc_serializer<non_text_img_visitor>
58  {
59  public:
60  // Constructor
62 
63  // Visit overloads
64  template <typename L>
65  void visit(const document<L>& doc) const;
66 
67  template <typename L>
68  void visit(const component_set<L>& comp_set) const;
69 
70  template <typename L>
71  void visit(const component_info<L>& info) const;
72 
73  private: // Attributes
75 
76  mutable image2d<scribo::def::lbl_type> elt_edge;
77  };
78 
79 
80 
81 # ifndef MLN_INCLUDE_ONLY
82 
83 
84  inline
85  non_text_img_visitor::non_text_img_visitor(mln::image2d<value::rgb8>& out)
86  : output(out)
87  {
88  mln_assertion(output.is_valid());
89  }
90 
91 
92 
94  //
95  template <typename L>
96  void
97  non_text_img_visitor::visit(const document<L>& doc) const
98  {
99  // Page elements (Pictures, ...)
100  if (doc.has_elements())
101  {
102  // Prepare element edges
103  elt_edge = morpho::elementary::gradient_external(doc.elements().labeled_image(), c8());
104 
105  doc.elements().accept(*this);
106  }
107 
108  // line seraparators
109  if (doc.has_hline_seps())
110  doc.hline_seps_comps().accept(*this);
111  if (doc.has_vline_seps())
112  doc.vline_seps_comps().accept(*this);
113  }
114 
115 
117  //
118  template <typename L>
119  void
120  non_text_img_visitor::visit(const component_set<L>& comp_set) const
121  {
122  for_all_comps(c, comp_set)
123  if (comp_set(c).is_valid())
124  comp_set(c).accept(*this);
125  }
126 
127 
129  //
130  template <typename L>
131  void
132  non_text_img_visitor::visit(const component_info<L>& info) const
133  {
134  switch (info.type())
135  {
138  {
139  mln::draw::box(output, info.bbox(), literal::cyan);
140  }
141  break;
142 
143 
144  default:
145  case component::Image:
146  {
147  draw_edges(info, output, literal::orange, elt_edge);
148  }
149  break;
150  }
151  }
152 
153 
154 #endif // MLN_INCLUDE_ONLY
155 
156  } // end of namespace scribo::io::img::internal
157 
158  } // end of namespace scribo::io::img
159 
160  } // end of namespace scribo::io
161 
162 } // end of namespace scribo
163 
164 #endif // SCRIBO_IO_IMG_INTERNAL_NON_TEXT_IMG_VISITOR_HH