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