$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
full_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_FULL_IMG_VISITOR_HH
27 # define SCRIBO_IO_IMG_INTERNAL_FULL_IMG_VISITOR_HH
28 
32 
33 # include <fstream>
34 
35 # include <mln/core/image/image2d.hh>
36 # include <mln/value/rgb8.hh>
37 # include <mln/draw/polygon.hh>
38 # include <mln/draw/box.hh>
39 
40 # include <scribo/core/internal/doc_serializer.hh>
41 # include <scribo/core/document.hh>
42 # include <scribo/core/paragraph_set.hh>
43 # include <scribo/core/line_info.hh>
44 
45 # include <scribo/text/paragraphs_closing.hh>
46 # include <scribo/io/img/internal/draw_edges.hh>
47 # include <scribo/util/component_precise_outline.hh>
48 
49 namespace scribo
50 {
51 
52  namespace io
53  {
54 
55  namespace img
56  {
57 
58  namespace internal
59  {
60 
61 
62  template <typename L>
63  class full_img_visitor : public doc_serializer<full_img_visitor<L> >
64  {
65  public:
66  // Constructor
68 
69  // Visit overloads
70  void visit(const document<L>& doc) const;
71 
72  void visit(const component_info<L>& info) const;
73 
74  void visit(const paragraph_set<L>& parset) const;
75 
76  void visit(const line_info<L>& line) const;
77 
78  private: // Attributes
80 
81  mutable L lbl_;
82  };
83 
84 
85 
86 # ifndef MLN_INCLUDE_ONLY
87 
88 
89  template <typename L>
91  : output(out)
92  {
93  mln_assertion(output.is_valid());
94  }
95 
96 
98  //
99  template <typename L>
100  void
101  full_img_visitor<L>::visit(const document<L>& doc) const
102  {
103  // Text
104  if (doc.has_text())
105  doc.paragraphs().accept(*this);
106 
107  // Page elements (Pictures, ...)
108  if (doc.has_elements())
109  {
110  const component_set<L>& elts = doc.elements();
111  for_all_comps(e, elts)
112  {
113  lbl_ = elts.labeled_image();
114  if (elts(e).is_valid())
115  elts(e).accept(*this);
116  }
117  }
118 
119 
120  // line seraparators
121  if (doc.has_vline_seps())
122  {
123  lbl_ = doc.vline_seps_comps().labeled_image();
124  for_all_comps(c, doc.vline_seps_comps())
125  if (doc.vline_seps_comps()(c).is_valid())
126  doc.vline_seps_comps()(c).accept(*this);
127  }
128  if (doc.has_hline_seps())
129  {
130  lbl_ = doc.hline_seps_comps().labeled_image();
131  for_all_comps(c, doc.hline_seps_comps())
132  if (doc.hline_seps_comps()(c).is_valid())
133  doc.hline_seps_comps()(c).accept(*this);
134  }
135 
136  }
137 
138 
140  //
141  template <typename L>
142  void
143  full_img_visitor<L>::visit(const component_info<L>& info) const
144  {
145  // Getting component outline
147  //const L& lbl = info.holder().labeled_image();
149  par = scribo::util::component_precise_outline(lbl_ | info.bbox(), id);
150 
151  switch (info.type())
152  {
155  {
156  mln::draw::polygon(output, par, literal::cyan);
157  }
158  break;
159 
161  {
162  mln::draw::polygon(output, par, literal::violet);
163  }
164  break;
165 
166  default:
167  case component::Image:
168  {
169  mln::draw::polygon(output, par, literal::orange);
170  }
171  break;
172  }
173  }
174 
176  //
177  template <typename L>
178  void
179  full_img_visitor<L>::visit(const paragraph_set<L>& parset) const
180  {
181  // const line_set<L>& lines = parset.lines();
182 
183  // Prepare paragraph outlines.
184  L par_clo = text::paragraphs_closing(parset);
185 
186  for_all_paragraphs(p, parset)
187  if (parset(p).is_valid())
188  {
189  p_array<point2d> par = scribo::util::component_precise_outline(par_clo
190  | parset(p).bbox(), p);
191 
192  mln::draw::polygon(output, par, literal::blue);
193  }
194  }
195 
196 
197  template <typename L>
198  void
199  full_img_visitor<L>::visit(const line_info<L>& line) const
200  {
201 // mln::draw::box(output, line.bbox(), literal::red);
202 
203  point2d
204  pmin = line.bbox().pmin(),
205  pmax = line.bbox().pmax();
206  pmax.row() = line.baseline();
207  pmin.row() = line.baseline();
208 
209  mln::draw::line(output, pmin, pmax, literal::red);
210  }
211 
212 #endif // MLN_INCLUDE_ONLY
213 
214  } // end of namespace scribo::io::img::internal
215 
216  } // end of namespace scribo::io::img
217 
218  } // end of namespace scribo::io
219 
220 } // end of namespace scribo
221 
222 #endif // SCRIBO_IO_IMG_INTERNAL_FULL_IMG_VISITOR_HH