$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
images_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_IMAGES_IN_PARAGRAPH_HH
27 # define SCRIBO_FILTER_IMAGES_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 
55  //
56  template <typename L>
57  void
58  images_in_paragraph(document<L>& doc);
59 
60 
61 # ifndef MLN_INCLUDE_ONLY
62 
63  template <typename L>
64  void
65  images_in_paragraph(document<L>& doc)
66  {
67  mln_trace("scribo::filter::images_in_paragraph");
68 
69  mln_precondition(doc.is_valid());
70 
71  if (! doc.has_elements())
72  return;
73 
74  mln_ch_value(L,bool) billboard;
75  initialize(billboard, doc.image());
76  data::fill(billboard, false);
77 
78  for_all_comps(p, doc.paragraphs())
79  if (doc.paragraphs()(p).is_valid())
80  mln::draw::box_plain(billboard, doc.paragraphs()(p).bbox(), true);
81 
82 
83  component_set<L> elts = doc.elements();
84  for_all_comps(c, elts)
85  if (elts(c).is_valid() && elts(c).type() == component::Image)
86  {
87  const mln_box(L)& b_ = elts(c).bbox();
88 
89  const bool tl = billboard(b_.pmin());
90  const bool tr = billboard.at_(b_.pmin().row(), b_.pmax().col());
91  const bool ml = billboard.at_(b_.pcenter().row(), b_.pmin().col());
92  const bool mc = billboard.at_(b_.pcenter().row(), b_.pcenter().col());
93  const bool mr = billboard.at_(b_.pcenter().row(), b_.pmax().col());
94  const bool bl = billboard.at_(b_.pmax().row(), b_.pmin().col());
95  const bool br = billboard(b_.pmax());
96 
97  // This separator is included in an element (picture, drawing...)
98  // => Ignore it.
99  if (tl && tr && ml && mc && mr && bl && br)
100  elts(c).update_tag(component::Ignored);
101  }
102 
103  // FIXME: warning this call may produce inconsistent data
104  // Ignored components are still in the separator image...
105  doc.set_elements(elts);
106 
107  }
108 
109 # endif // ! MLN_INCLUDE_ONLY
110 
111  } // end of namespace scribo::filter
112 
113 } // end of namespace scribo
114 
115 #endif // ! SCRIBO_FILTER_IMAGES_IN_PARAGRAPH_HH