$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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_TEXT_IMG_VISITOR_HH
27 # define SCRIBO_IO_IMG_INTERNAL_TEXT_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/box.hh>
38 # include <mln/literal/colors.hh>
39 
40 # include <scribo/core/internal/doc_serializer.hh>
41 # include <scribo/core/document.hh>
42 # include <scribo/core/component_set.hh>
43 # include <scribo/core/paragraph_set.hh>
44 # include <scribo/core/line_info.hh>
45 
46 namespace scribo
47 {
48 
49  namespace io
50  {
51 
52  namespace img
53  {
54 
55  namespace internal
56  {
57 
58 
59  class text_img_visitor : public doc_serializer<text_img_visitor>
60  {
61  public:
62  // Constructor
64 
65  // Visit overloads
66  template <typename L>
67  void visit(const document<L>& doc) const;
68 
69  template <typename L>
70  void visit(const component_set<L>& comp_set) const;
71 
72  template <typename L>
73  void visit(const paragraph_set<L>& parset) const;
74 
75  template <typename L>
76  void visit(const line_info<L>& line) const;
77 
78  private: // Attributes
80  };
81 
82 
83 
84 # ifndef MLN_INCLUDE_ONLY
85 
86  inline
87  text_img_visitor::text_img_visitor(mln::image2d<value::rgb8>& out)
88  : output(out)
89  {
90  mln_assertion(output.is_valid());
91  }
92 
93 
94 
96  //
97  template <typename L>
98  void
99  text_img_visitor::visit(const document<L>& doc) const
100  {
101  mln_precondition(doc.is_open());
102 
103  // Prepare output image.
104  output = duplicate(doc.image());
105 
106 
107  // Text
108  if (doc.has_text())
109  doc.paragraphs().accept(*this);
110  }
111 
113  //
114  template <typename L>
115  void
116  text_img_visitor::visit(const component_set<L>& comp_set) const
117  {
118  for_all_comps(c, comp_set)
119  if (comp_set(c).is_valid())
120  comp_set(c).accept(*this);
121  }
122 
123 
125  //
126  template <typename L>
127  void
128  text_img_visitor::visit(const paragraph_set<L>& parset) const
129  {
130  const line_set<L>& lines = parset.lines();
131 
132  for_all_paragraphs(p, parset)
133  {
134  const mln::util::array<line_id_t>& line_ids = parset(p).line_ids();
135 
136  for_all_paragraph_lines(lid, line_ids)
137  {
138  line_id_t l = line_ids(lid);
139  lines(l).accept(*this);
140  }
141 
142  mln::draw::box(output, parset(p).bbox(), literal::blue);
143  }
144  }
145 
146 
147  template <typename L>
148  void
149  text_img_visitor::visit(const line_info<L>& line) const
150  {
151  mln::draw::box(output, line.bbox(), literal::red);
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_TEXT_IMG_VISITOR_HH