$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
text_blocks_image.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_MAKE_TEXT_BLOCKS_IMAGE_HH
27 # define SCRIBO_MAKE_TEXT_BLOCKS_IMAGE_HH
28 
32 
33 # include <mln/core/image/image2d.hh>
34 # include <mln/draw/box_plain.hh>
35 
36 # include <scribo/core/document.hh>
37 # include <scribo/core/paragraph_set.hh>
38 # include <scribo/core/line_info.hh>
39 
40 
41 namespace scribo
42 {
43 
44  namespace make
45  {
46  using namespace mln;
47 
48 
50 
53  template <typename L>
54  mln_ch_value(L,bool)
55  text_blocks_image(const document<L>& doc, unsigned min_nlines);
56 
57 
58  # ifndef MLN_INCLUDE_ONLY
59 
60  template <typename L>
61  mln_ch_value(L,bool)
62  text_blocks_image(const document<L>& doc, unsigned min_nlines)
63  {
64  mln_trace("scribo::make::text_blocks_image");
65 
66  mln_precondition(doc.is_open());
67 
68  image2d<bool> output;
69  initialize(output, doc.image());
70  data::fill(output, false);
71 
72  // image2d<value::int_u8> log;
73  // initialize(log, output);
74  // data::fill(log, 0);
75 
76  if (doc.has_text())
77  {
78  const paragraph_set<L>& parset = doc.paragraphs();
79  for_all_paragraphs(p, parset)
80  if (parset(p).nlines() >= min_nlines)
81  {
82  box2d last_box;
83 
84  // For each line in this paragraph.
85  for_all_elements(l, parset(p).line_ids())
86  {
87  const line_info<L>&
88  line = parset.lines()(parset(p).line_ids()(l));
89 
90  // Avoid invalid case:
91  //
92  // =======
93  // ======
94  if (last_box.is_valid()
95  && last_box.pmax().row() < line.bbox().pmin().row()
96  && last_box.pmin().col() < line.bbox().pmax().col())
97  {
98  point2d
99  pmin(std::min(last_box.pmax().row(),
100  line.bbox().pmin().row()),
101  std::max(last_box.pmin().col(),
102  line.bbox().pmin().col())),
103  pmax(std::max(last_box.pmax().row(),
104  line.bbox().pmin().row()),
105  std::min(last_box.pmax().col(),
106  line.bbox().pmax().col()));
107 
108  box2d new_box(pmin, pmax);
109  mln::draw::box_plain(output, new_box, true);
110  // mln::draw::box_plain(log, new_box, 1);
111 
112  // mln::io::pgm::save(log, mln::debug::filename("log.pgm", i++));
113  }
114 
115  mln::draw::box_plain(output, line.bbox(), true);
116  // mln::draw::box_plain(log, line.bbox(), 255);
117  // mln::io::pgm::save(log, mln::debug::filename("log.pgm", i++));
118  last_box = line.bbox();
119  }
120  }
121  }
122 
123 
124  return output;
125  }
126 
127 # endif // ! MLN_INCLUDE_ONLY
128 
129  } // end of namespace scribo::make
130 
131 } // end of namespace scribo
132 
133 
134 
135 #endif // ! SCRIBO_MAKE_TEXT_BLOCKS_IMAGE_HH