$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
separators_in_paragraph.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_FILTER_SEPARATORS_IN_PARAGRAPH_HH
27 # define SCRIBO_FILTER_SEPARATORS_IN_PARAGRAPH_HH
28 
33 
34 
35 # include <mln/core/concept/image.hh>
36 # include <mln/draw/box_plain.hh>
37 # include <scribo/core/component_set.hh>
38 # include <scribo/core/document.hh>
39 
40 
41 namespace scribo
42 {
43 
44  namespace filter
45  {
46 
47  using namespace mln;
48 
49 
63  //
64  template <typename L>
65  void
66  separators_in_paragraph(document<L>& doc,
67  unsigned hmin_size, unsigned vmin_size);
68 
69 
70 # ifndef MLN_INCLUDE_ONLY
71 
72  template <typename L>
73  void
74  separators_in_paragraph(document<L>& doc,
75  unsigned hmin_size, unsigned vmin_size)
76  {
77  mln_trace("scribo::filter::separators_in_paragraph");
78 
79  mln_precondition(doc.is_valid());
80  mln_precondition(doc.has_elements());
81  mln_precondition(doc.has_hline_seps() || doc.has_vline_seps());
82 
83  if ((doc.has_hline_seps() && !doc.hline_seps_comps().nelements())
84  && (doc.has_vline_seps() && !doc.vline_seps_comps().nelements()))
85  return;
86 
87  mln_ch_value(L,bool) billboard;
88  initialize(billboard, doc.image());
89  data::fill(billboard, false);
90 
91  for_all_comps(p, doc.paragraphs())
92  if (doc.paragraphs()(p).is_valid())
93  mln::draw::box_plain(billboard, doc.paragraphs()(p).bbox(), true);
94 
95  // Horizontal separators
96  if (doc.has_hline_seps())
97  {
98  component_set<L> hline = doc.hline_seps_comps().duplicate();
99  for_all_comps(c, hline)
100  if (hline(c).is_valid())
101  {
102  const mln_box(L)& b_ = hline(c).bbox();
103 
104  const bool tl = billboard(b_.pmin());
105  const bool tr = billboard.at_(b_.pmin().row(), b_.pmax().col());
106  const bool ml = billboard.at_(b_.pcenter().row(), b_.pmin().col());
107  const bool mc = billboard.at_(b_.pcenter().row(), b_.pcenter().col());
108  const bool mr = billboard.at_(b_.pcenter().row(), b_.pmax().col());
109  const bool bl = billboard.at_(b_.pmax().row(), b_.pmin().col());
110  const bool br = billboard(b_.pmax());
111 
112  // This separator is included in an element (picture, drawing...)
113  // => Ignore it.
114  if (tl && tr && ml && mc && mr && bl && br
115  && hline(c).bbox().width() < hmin_size)
116  hline(c).update_tag(component::Ignored);
117  }
118 
119  // FIXME: warning this call may produce inconsistent data
120  // Ignored components are still in the separator image...
121  doc.set_hline_separators(doc.hline_seps(), hline);
122  }
123 
124  // Vertical separators
125  if (doc.has_vline_seps())
126  {
127  component_set<L> vline = doc.vline_seps_comps().duplicate();
128  for_all_comps(c, vline)
129  if (vline(c).is_valid())
130  {
131  const mln_box(L)& b_ = vline(c).bbox();
132 
133  const bool tl = billboard(b_.pmin());
134  const bool tr = billboard.at_(b_.pmin().row(), b_.pmax().col());
135  const bool ml = billboard.at_(b_.pcenter().row(), b_.pmin().col());
136  const bool mc = billboard.at_(b_.pcenter().row(), b_.pcenter().col());
137  const bool mr = billboard.at_(b_.pcenter().row(), b_.pmax().col());
138  const bool bl = billboard.at_(b_.pmax().row(), b_.pmin().col());
139  const bool br = billboard(b_.pmax());
140 
141  // This separator is included in an element (picture, drawing...)
142  // => Ignore it.
143  if (tl && tr && ml && mc && mr && bl && br
144  && vline(c).bbox().height() < vmin_size)
145  vline(c).update_tag(component::Ignored);
146  }
147 
148  // FIXME: warning this call may produce inconsistent data
149  // Ignored components are still in the separator image...
150  doc.set_vline_separators(doc.vline_seps(), vline);
151  }
152 
153  }
154 
155 # endif // ! MLN_INCLUDE_ONLY
156 
157  } // end of namespace scribo::filter
158 
159 } // end of namespace scribo
160 
161 #endif // ! SCRIBO_FILTER_SEPARATORS_IN_PARAGRAPH_HH