Olena-patches
  Threads by month 
                
            - ----- 2025 -----
 - November
 - October
 - September
 - August
 - July
 - June
 - May
 - April
 - March
 - February
 - January
 - ----- 2024 -----
 - December
 - November
 - October
 - September
 - August
 - July
 - June
 - May
 - April
 - March
 - February
 - January
 - ----- 2023 -----
 - December
 - November
 - October
 - September
 - August
 - July
 - June
 - May
 - April
 - March
 - February
 - January
 - ----- 2022 -----
 - December
 - November
 - October
 - September
 - August
 - July
 - June
 - May
 - April
 - March
 - February
 - January
 - ----- 2021 -----
 - December
 - November
 - October
 - September
 - August
 - July
 - June
 - May
 - April
 - March
 - February
 - January
 - ----- 2020 -----
 - December
 - November
 - October
 - September
 - August
 - July
 - June
 - May
 - April
 - March
 - February
 - January
 - ----- 2019 -----
 - December
 - November
 - October
 - September
 - August
 - July
 - June
 - May
 - April
 - March
 - February
 - January
 - ----- 2018 -----
 - December
 - November
 - October
 - September
 - August
 - July
 - June
 - May
 - April
 - March
 - February
 - January
 - ----- 2017 -----
 - December
 - November
 - October
 - September
 - August
 - July
 - June
 - May
 - April
 - March
 - February
 - January
 - ----- 2016 -----
 - December
 - November
 - October
 - September
 - August
 - July
 - June
 - May
 - April
 - March
 - February
 - January
 - ----- 2015 -----
 - December
 - November
 - October
 - September
 - August
 - July
 - June
 - May
 - April
 - March
 - February
 - January
 - ----- 2014 -----
 - December
 - November
 - October
 - September
 - August
 - July
 - June
 - May
 - April
 - March
 - February
 - January
 - ----- 2013 -----
 - December
 - November
 - October
 - September
 - August
 - July
 - June
 - May
 - April
 - March
 - February
 - January
 - ----- 2012 -----
 - December
 - November
 - October
 - September
 - August
 - July
 - June
 - May
 - April
 - March
 - February
 - January
 - ----- 2011 -----
 - December
 - November
 - October
 - September
 - August
 - July
 - June
 - May
 - April
 - March
 - February
 - January
 - ----- 2010 -----
 - December
 - November
 - October
 - September
 - August
 - July
 - June
 - May
 - April
 - March
 - February
 - January
 - ----- 2009 -----
 - December
 - November
 - October
 - September
 - August
 - July
 - June
 - May
 - April
 - March
 - February
 - January
 - ----- 2008 -----
 - December
 - November
 - October
 - September
 - August
 - July
 - June
 - May
 - April
 - March
 - February
 - January
 - ----- 2007 -----
 - December
 - November
 - October
 - September
 - August
 - July
 - June
 - May
 - April
 - March
 - February
 - January
 - ----- 2006 -----
 - December
 - November
 - October
 - September
 - August
 - July
 - June
 - May
 - April
 - March
 - February
 - January
 - ----- 2005 -----
 - December
 - November
 - October
 - September
 - August
 - July
 - June
 - May
 - April
 - March
 - February
 - January
 - ----- 2004 -----
 - December
 - November
 - October
 - September
 - August
 - July
 - June
 - May
 - April
 - March
 
- 9625 discussions
 
                        
                            
                                
                            
                            last-svn-commit-897-g7415119	scribo/util/component_precise_outline.hh: Fix namespace ambiguity.
                        
                        
by Guillaume Lazzara 26 May '11
                    by Guillaume Lazzara 26 May '11
26 May '11
                    
                        ---
 scribo/ChangeLog                                |    5 +++++
 scribo/scribo/util/component_precise_outline.hh |    9 ++++++---
 2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 47b8473..6f44931 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,10 @@
 2011-05-26  Guillaume Lazzara  <z(a)lrde.epita.fr>
 
+	* scribo/util/component_precise_outline.hh: Fix namespace
+	ambiguity.
+
+2011-05-26  Guillaume Lazzara  <z(a)lrde.epita.fr>
+
 	Improve XML output.
 
 	* scribo/io/img/internal/debug_img_visitor.hh,
diff --git a/scribo/scribo/util/component_precise_outline.hh b/scribo/scribo/util/component_precise_outline.hh
index 3c6e523..6637dc9 100644
--- a/scribo/scribo/util/component_precise_outline.hh
+++ b/scribo/scribo/util/component_precise_outline.hh
@@ -81,9 +81,11 @@ namespace scribo
       find_first_point(const I& input,
 		       point2d& p)
       {
-	const def::coord mid_row = geom::min_row(input) + (geom::nrows(input) >> 1);
+	const mln::def::coord
+	  mid_row = geom::min_row(input) + (geom::nrows(input) >> 1);
 
-	for (def::coord i = geom::min_col(input); i <= geom::max_col(input); ++i)
+	for (mln::def::coord i = geom::min_col(input);
+	     i <= geom::max_col(input); ++i)
 	{
 	  if (opt::at(input, mid_row, i))
 	  {
@@ -285,7 +287,8 @@ namespace scribo
 
       const std::vector<point2d>& vec_points = points.hook_std_vector_();
 
-      if (std::find(vec_points.begin(), vec_points.end(), cur_pt) == vec_points.end())
+      if (std::find(vec_points.begin(),
+		    vec_points.end(), cur_pt) == vec_points.end())
       {
 	points.append(cur_pt);
 
-- 
1.5.6.5
                    
                  
                  
                          
                            
                            1
                            
                          
                          
                            
                            0
                            
                          
                          
                            
    
                          
                        
                    26 May '11
                    
                        This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Olena, a generic and efficient image processing platform".
The branch icdar/hdlac2011 has been updated
  discards  118f203ff8c90a367f78502c3b5ecc1883180f86 (commit)
  discards  12da563c7ea1fba00e47b8cdb9adf526421218d2 (commit)
  discards  ebfb6d5d15d50abe54ce41cb88b243c7b03b1935 (commit)
       via  58b6a662ab8baecf54514930cebe761fbd9e0e32 (commit)
       via  46636f57bf3f360ae661412a50f2b2a808e14f90 (commit)
       via  3a15c0260477b4d491a594cc852f8994dd1eef1d (commit)
       via  532805f671d39082c9c62414be4c3266e03609bf (commit)
       via  9f7843c9c01df078d600f898bf0ea5d2398aebd1 (commit)
       via  0a594b3dad7545235b2997ea4ba4547363f4c1ab (commit)
       via  eb7b2bd077b0fc4256545e37e19af37ed9c4d25e (commit)
       via  e32f2ebf7a08cee79f727ac55ea902dbd58cd515 (commit)
       via  1d411c7c9dd03993cf3e45f9e2835bba1d1b6e5d (commit)
       via  e06be54cf5ffe080b2268704caf56e2962ff4d2c (commit)
       via  f28dd55983ff67c868ef37ddecfc7a29da91c61f (commit)
       via  02ab025088bb3639de1f2d934900311915267254 (commit)
       via  efa07ad7381d92b81cc58e2b0acb780f3922be6e (commit)
       via  0d80a703e96d8c16a09f592f4dfa2846eadd696e (commit)
This update added new revisions after undoing existing revisions.  That is
to say, the old revision is not a strict subset of the new revision.  This
situation occurs when you --force push a change and generate a repository
containing something like this:
 * -- * -- B -- O -- O -- O (118f203ff8c90a367f78502c3b5ecc1883180f86)
            \
             N -- N -- N (58b6a662ab8baecf54514930cebe761fbd9e0e32)
When this happens we assume that you've already had alert emails for all
of the O revisions, and so we here report only the revisions in the N
branch from the common base, B.
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
58b6a66 Improve XML output.
46636f5 Improve and cleanup Results in hdoc toolchain.
3a15c02 scribo/primitive/extract/lines_h_thick_and_thin.hh: Improve result quality.
532805f Add new hooks in toolchain functors.
9f7843c scribo/util/component_precise_outline.hh: New. Precise component outline extraction.
0a594b3 Add new element filters.
eb7b2bd Add util::box_intersection.
e32f2eb mln/draw/site_set.hh: new.
1d411c7 Various small fixes in Scribo.
e06be54 Introduce paragraph_id_t type.
f28dd55 Share document structure data.
02ab025 Deep modifications and clean correction of the previous bug.
efa07ad Further correction of the component outlining bug.
0d80a70 Correct a bug in the compononent outlining algorithm.
-----------------------------------------------------------------------
Summary of changes:
 milena/ChangeLog                                   |    4 +
 milena/mln/draw/site_set.hh                        |   88 ++++++
 scribo/ChangeLog                                   |  104 +++++++
 scribo/scribo/core/document.hh                     |  171 +++++++----
 scribo/scribo/core/paragraph_info.hh               |   15 +-
 scribo/scribo/core/paragraph_set.hh                |   49 +++-
 scribo/scribo/core/tag/line.hh                     |    2 +-
 scribo/scribo/core/tag/paragraph.hh                |   43 +++
 scribo/scribo/debug/line_info_image.hh             |    5 +-
 scribo/scribo/filter/images_in_paragraph.hh        |  119 ++++++++
 scribo/scribo/filter/object_links_bbox_overlap.hh  |   25 +--
 scribo/scribo/filter/paragraphs_bbox_overlap.hh    |  176 +++++++++++
 scribo/scribo/filter/paragraphs_in_image.hh        |  129 ++++++++
 scribo/scribo/filter/separators_in_element.hh      |  151 ++++++++++
 scribo/scribo/filter/separators_in_paragraph.hh    |  151 ++++++++++
 scribo/scribo/io/img/internal/debug_img_visitor.hh |  130 +++++----
 scribo/scribo/io/img/internal/full_img_visitor.hh  |   42 ++--
 .../io/xml/internal/extended_page_xml_visitor.hh   |   81 +++---
 scribo/scribo/io/xml/internal/full_xml_visitor.hh  |   79 +++---
 scribo/scribo/io/xml/internal/page_xml_visitor.hh  |   58 ++--
 scribo/scribo/primitive/extract/alignments.hh      |   12 +-
 .../primitive/extract/lines_h_thick_and_thin.hh    |   16 +-
 scribo/scribo/primitive/extract/lines_pattern.hh   |    2 +-
 scribo/scribo/primitive/extract/non_text_hdoc.hh   |   34 ++-
 .../primitive/extract/separators_nonvisible.hh     |    6 +-
 .../scribo/primitive/group/from_double_link_any.hh |    7 +-
 scribo/scribo/text/link_lines.hh                   |    2 +-
 scribo/scribo/text/merging.hh                      |   37 ++-
 scribo/scribo/text/paragraphs.hh                   |   18 +-
 .../toolchain/internal/content_in_doc_functor.hh   |    4 +
 .../toolchain/internal/content_in_hdoc_functor.hh  |  201 +++++++-------
 .../toolchain/internal/text_in_doc_functor.hh      |    4 +
 .../internal/text_in_doc_preprocess_functor.hh     |   53 ++++-
 .../scribo/toolchain/internal/toolchain_functor.hh |   28 ++-
 scribo/scribo/util/box_intersection.hh             |   85 ++++++
 scribo/scribo/util/component_precise_outline.hh    |  309 ++++++++++++++++++++
 .../primitive/extract/lines_h_thick_and_thin.cc    |    1 +
 scribo/tests/primitive/extract/Makefile.am         |    2 +-
 38 files changed, 2007 insertions(+), 436 deletions(-)
 create mode 100644 milena/mln/draw/site_set.hh
 create mode 100644 scribo/scribo/core/tag/paragraph.hh
 create mode 100644 scribo/scribo/filter/images_in_paragraph.hh
 create mode 100644 scribo/scribo/filter/paragraphs_bbox_overlap.hh
 create mode 100644 scribo/scribo/filter/paragraphs_in_image.hh
 create mode 100644 scribo/scribo/filter/separators_in_element.hh
 create mode 100644 scribo/scribo/filter/separators_in_paragraph.hh
 create mode 100644 scribo/scribo/util/box_intersection.hh
 create mode 100644 scribo/scribo/util/component_precise_outline.hh
hooks/post-receive
-- 
Olena, a generic and efficient image processing platform
                    
                  
                  
                          
                            
                            1
                            
                          
                          
                            
                            0
                            
                          
                          
                            
    
                          
                        
                    
                    
                        	* scribo/io/img/internal/debug_img_visitor.hh,
	* scribo/io/img/internal/full_img_visitor.hh,
	* scribo/io/xml/internal/page_xml_visitor.hh: Save element
	outlines and do not save invalid elements.
---
 scribo/ChangeLog                                   |    9 ++
 scribo/scribo/io/img/internal/debug_img_visitor.hh |  130 ++++++++++----------
 scribo/scribo/io/img/internal/full_img_visitor.hh  |   42 ++++---
 scribo/scribo/io/xml/internal/page_xml_visitor.hh  |    7 +-
 4 files changed, 103 insertions(+), 85 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index ecece77..47b8473 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,14 @@
 2011-05-26  Guillaume Lazzara  <z(a)lrde.epita.fr>
 
+	Improve XML output.
+
+	* scribo/io/img/internal/debug_img_visitor.hh,
+	* scribo/io/img/internal/full_img_visitor.hh,
+	* scribo/io/xml/internal/page_xml_visitor.hh: Save element
+	outlines and do not save invalid elements.
+
+2011-05-26  Guillaume Lazzara  <z(a)lrde.epita.fr>
+
 	Improve and cleanup Results in hdoc toolchain.
 
 	* scribo/primitive/extract/non_text_hdoc.hh: Make parameters
diff --git a/scribo/scribo/io/img/internal/debug_img_visitor.hh b/scribo/scribo/io/img/internal/debug_img_visitor.hh
index 7d1d3d7..a4715f5 100644
--- a/scribo/scribo/io/img/internal/debug_img_visitor.hh
+++ b/scribo/scribo/io/img/internal/debug_img_visitor.hh
@@ -34,7 +34,7 @@
 
 # include <mln/core/image/image2d.hh>
 # include <mln/value/rgb8.hh>
-# include <mln/draw/box.hh>
+# include <mln/draw/site_set.hh>
 # include <mln/subsampling/antialiased.hh>
 # include <mln/morpho/elementary/gradient_external.hh>
 
@@ -43,8 +43,11 @@
 # include <scribo/core/paragraph_set.hh>
 # include <scribo/core/line_info.hh>
 
+# include <scribo/util/component_precise_outline.hh>
 # include <scribo/io/img/internal/draw_edges.hh>
 
+
+
 namespace scribo
 {
 
@@ -82,8 +85,8 @@ namespace scribo
 	  mln::image2d<value::rgb8>& output;
 	  unsigned output_ratio;
 
-	  mutable image2d<scribo::def::lbl_type> elt_edge;
-
+	  // FIXME: we would like its type to be L.
+	  mutable image2d<scribo::def::lbl_type> lbl_sub;
 
 	private: // Methods
 	  box2d compute_bbox(const box2d& b) const;
@@ -130,51 +133,57 @@ namespace scribo
 	  {
 	    // Prepare element edges
 
-	    L lbl = duplicate(doc.elements().labeled_image());
-	    for_all_comps(c, doc.elements())
-	      if (! doc.elements()(c).is_valid())
-		data::fill(((lbl | doc.elements()(c).bbox()).rw()
-			    | (pw::value(lbl) == pw::cst(c))).rw(), 0);
+	    // L lbl = duplicate(doc.elements().labeled_image());
+	    // for_all_comps(c, doc.elements())
+	    //   if (! doc.elements()(c).is_valid())
+	    // 	data::fill(((lbl | doc.elements()(c).bbox()).rw()
+	    // 		    | (pw::value(lbl) == pw::cst(c))).rw(), 0);
 
-	    // FIXME: UGLY! Too slow!
-	    scribo::def::lbl_type nlabels;
-	    component_set<L> elts = primitive::extract::components(
-	      data::convert(bool(), mln::subsampling::antialiased(lbl, output_ratio)),
-	      c8(),
-	      nlabels);
+	    // const L& lbl = doc.lines().components().labeled_image();
+	    // lbl_sub = mln::subsampling::antialiased(lbl, output_ratio);
 
-	    // Preserving elements tags
-	    if (doc.elements().nelements() != elts.nelements())
-	    {
-	      std::cerr << "Warnig: could not preserve element type in "
-			<< "img debug output." << std::endl;
-	      std::cerr << "The number of non text element has changed while "
-			<< "subsampling images : "
-			<< doc.elements().nelements() << " vs "
-			<< elts.nelements() << std::endl;
-	    }
-	    else
-	      for_all_comps(c, doc.elements())
-	      {
-		elts(c).update_type(doc.elements()(c).type());
-		elts(c).update_tag(doc.elements()(c).tag());
-	      }
+	    // mln::io::pgm::save(data::wrap(value::int_u8(), lbl), "lbl.pgm");
+	    // mln::io::pgm::save(data::wrap(value::int_u8(), lbl_sub), "lbl_sub.pgm");
 
-	    elt_edge = morpho::elementary::gradient_external(elts.labeled_image(), c8());
+	    // // FIXME: UGLY! Too slow!
+	    // scribo::def::lbl_type nlabels;
+	    // component_set<L> elts = primitive::extract::components(
+	    //   data::convert(bool(), lbl_sub),
+	    //   c8(),
+	    //   nlabels);
 
-	    for_all_comps(e, elts)
-	      if (elts(e).is_valid())
-		elts(e).accept(*this);
+	    // Preserving elements tags
+	    // if (doc.elements().nelements() != elts.nelements())
+	    // {
+	    //   std::cerr << "Warnig: could not preserve element type in "
+	    // 		<< "img debug output." << std::endl;
+	    //   std::cerr << "The number of non text element has changed while "
+	    // 		<< "subsampling images : "
+	    // 		<< doc.elements().nelements() << " vs "
+	    // 		<< elts.nelements() << std::endl;
+	    // }
+	    // else
+	    //   for_all_comps(c, doc.elements())
+	    //   {
+	    // 	elts(c).update_type(doc.elements()(c).type());
+	    // 	elts(c).update_tag(doc.elements()(c).tag());
+	    //   }
+
+	    for_all_comps(e, doc.elements())
+	      if (doc.elements()(e).is_valid())
+		doc.elements()(e).accept(*this);
 	  }
 
 
 	  // line seraparators
 	  if (doc.has_vline_seps())
 	    for_all_comps(c, doc.vline_seps_comps())
-	      doc.vline_seps_comps()(c).accept(*this);
+	      if (doc.vline_seps_comps()(c).is_valid())
+		doc.vline_seps_comps()(c).accept(*this);
 	  if (doc.has_hline_seps())
 	    for_all_comps(c, doc.hline_seps_comps())
-	      doc.hline_seps_comps()(c).accept(*this);
+	      if (doc.hline_seps_comps()(c).is_valid())
+		doc.hline_seps_comps()(c).accept(*this);
 
 	}
 
@@ -185,13 +194,19 @@ namespace scribo
 	void
 	debug_img_visitor::visit(const component_info<L>& info) const
 	{
+	  // Getting component outline
+	  scribo::def::lbl_type id = (scribo::def::lbl_type)info.id().to_equiv();
+	  const L& lbl = info.holder().labeled_image();
+	  p_array<point2d>
+	    par = scribo::util::component_precise_outline(
+	      extend((lbl | info.bbox()) | (pw::value(lbl) == pw::cst(id)), 0));
+
 	  switch (info.type())
 	  {
 	    case component::HorizontalLineSeparator:
 	    case component::VerticalLineSeparator:
 	    {
-	      mln::draw::box(output, compute_bbox(info.bbox()),
-			     literal::cyan);
+	      mln::draw::site_set(output, par, literal::cyan, output_ratio);
 	    }
 	    break;
 
@@ -199,19 +214,7 @@ namespace scribo
 	    default:
 	    case component::Image:
 	    {
-	      // The bbox does not need to be reajusted to the
-	      // subsampled domain since it has been recomputed while
-	      // computing the edge image.
-	      //
-	      // However, the bbox must be enlarged since only the
-	      // _external_ edge is computed.
-	      box2d b = info.bbox();
-	      b.enlarge(1);
-	      b.crop_wrt(output.domain());
-	      data::fill(((output | b).rw()
-			  | (pw::value(elt_edge)
-			     == pw::cst((scribo::def::lbl_type)info.id().to_equiv()))).rw(),
-			 literal::orange);
+	      mln::draw::site_set(output, par, literal::orange, output_ratio);
 	    }
 	    break;
 	  }
@@ -226,20 +229,21 @@ namespace scribo
 	  const line_set<L>& lines = parset.lines();
 
 	  for_all_paragraphs(p, parset)
-	  {
-	    const mln::util::array<line_id_t>& line_ids = parset(p).line_ids();
-
-	    for_all_paragraph_lines(lid, line_ids)
+	    if (parset(p).is_valid())
 	    {
-	      line_id_t l = line_ids(lid);
-	      lines(l).accept(*this);
-	    }
+	      const mln::util::array<line_id_t>& line_ids = parset(p).line_ids();
 
-	    box2d b = compute_bbox(parset(p).bbox());
-	    b.enlarge(1);
-	    b.crop_wrt(output.domain());
-	    mln::draw::box(output, b, literal::blue);
-	  }
+	      for_all_paragraph_lines(lid, line_ids)
+	      {
+		line_id_t l = line_ids(lid);
+		lines(l).accept(*this);
+	      }
+
+	      box2d b = compute_bbox(parset(p).bbox());
+	      b.enlarge(1);
+	      b.crop_wrt(output.domain());
+	      mln::draw::box(output, b, literal::blue);
+	    }
 	}
 
 
diff --git a/scribo/scribo/io/img/internal/full_img_visitor.hh b/scribo/scribo/io/img/internal/full_img_visitor.hh
index 662d8d1..f2c0f5c 100644
--- a/scribo/scribo/io/img/internal/full_img_visitor.hh
+++ b/scribo/scribo/io/img/internal/full_img_visitor.hh
@@ -34,6 +34,7 @@
 
 # include <mln/core/image/image2d.hh>
 # include <mln/value/rgb8.hh>
+# include <mln/draw/site_set.hh>
 # include <mln/draw/box.hh>
 
 # include <scribo/core/internal/doc_serializer.hh>
@@ -42,6 +43,7 @@
 # include <scribo/core/line_info.hh>
 
 # include <scribo/io/img/internal/draw_edges.hh>
+# include <scribo/util/component_precise_outline.hh>
 
 namespace scribo
 {
@@ -77,8 +79,6 @@ namespace scribo
 
 	private: // Attributes
 	  mln::image2d<value::rgb8>& output;
-
-	  mutable image2d<scribo::def::lbl_type> elt_edge;
 	};
 
 
@@ -107,9 +107,6 @@ namespace scribo
 	  // Page elements (Pictures, ...)
 	  if (doc.has_elements())
 	  {
-	    // Prepare element edges
-	    elt_edge = morpho::elementary::gradient_external(doc.elements().labeled_image(), c8());
-
 	    const component_set<L>& elts = doc.elements();
 	    for_all_comps(e, elts)
 	      if (elts(e).is_valid())
@@ -120,10 +117,12 @@ namespace scribo
 	  // line seraparators
 	  if (doc.has_vline_seps())
 	    for_all_comps(c, doc.vline_seps_comps())
-	      doc.vline_seps_comps()(c).accept(*this);
+	      if (doc.vline_seps_comps()(c).is_valid())
+		doc.vline_seps_comps()(c).accept(*this);
 	  if (doc.has_hline_seps())
 	    for_all_comps(c, doc.hline_seps_comps())
-	      doc.hline_seps_comps()(c).accept(*this);
+	      if (doc.hline_seps_comps()(c).is_valid())
+		doc.hline_seps_comps()(c).accept(*this);
 
 	}
 
@@ -134,12 +133,18 @@ namespace scribo
 	void
 	full_img_visitor::visit(const component_info<L>& info) const
 	{
+	  // Getting component outline
+	  scribo::def::lbl_type id = (scribo::def::lbl_type)info.id().to_equiv();
+	  const L& lbl = info.holder().labeled_image();
+	  p_array<point2d>
+	    par = scribo::util::component_precise_outline((lbl | info.bbox()) | (pw::value(lbl) == pw::cst(id)));
+
 	  switch (info.type())
 	  {
 	    case component::HorizontalLineSeparator:
 	    case component::VerticalLineSeparator:
 	    {
-	      mln::draw::box(output, info.bbox(), literal::cyan);
+	      mln::draw::site_set(output, par, literal::cyan);
 	    }
 	    break;
 
@@ -147,7 +152,7 @@ namespace scribo
 	    default:
 	    case component::Image:
 	    {
-	      draw_edges(info, output, literal::orange, elt_edge);
+	      mln::draw::site_set(output, par, literal::orange);
 	    }
 	    break;
 	  }
@@ -162,17 +167,18 @@ namespace scribo
 	  const line_set<L>& lines = parset.lines();
 
 	  for_all_paragraphs(p, parset)
-	  {
-	    const mln::util::array<line_id_t>& line_ids = parset(p).line_ids();
-
-	    for_all_paragraph_lines(lid, line_ids)
+	    if (parset(p).is_valid())
 	    {
-	      line_id_t l = line_ids(lid);
-	      lines(l).accept(*this);
-	    }
+	      const mln::util::array<line_id_t>& line_ids = parset(p).line_ids();
 
-	    mln::draw::box(output, parset(p).bbox(), literal::blue);
-	  }
+	      for_all_paragraph_lines(lid, line_ids)
+	      {
+		line_id_t l = line_ids(lid);
+		lines(l).accept(*this);
+	      }
+
+	      mln::draw::box(output, parset(p).bbox(), literal::blue);
+	    }
 	}
 
 
diff --git a/scribo/scribo/io/xml/internal/page_xml_visitor.hh b/scribo/scribo/io/xml/internal/page_xml_visitor.hh
index 66ba21f..1659a85 100644
--- a/scribo/scribo/io/xml/internal/page_xml_visitor.hh
+++ b/scribo/scribo/io/xml/internal/page_xml_visitor.hh
@@ -35,7 +35,7 @@
 # include <scribo/core/internal/doc_serializer.hh>
 # include <scribo/convert/to_base64.hh>
 
-# include <scribo/util/component_outline.hh>
+# include <scribo/util/component_precise_outline.hh>
 
 # include <scribo/io/xml/internal/print_box_coords.hh>
 # include <scribo/io/xml/internal/print_page_preambule.hh>
@@ -160,9 +160,8 @@ namespace scribo
 	  scribo::def::lbl_type id = (scribo::def::lbl_type)info.id().to_equiv();
 	  const L& lbl = info.holder().labeled_image();
 	  p_array<point2d>
-	    par = util::component_outline(((lbl | info.bbox())
-					   | (pw::value(lbl) == pw::cst(id))),
-					  1);
+	    par = scribo::util::component_precise_outline(
+	      extend((lbl | info.bbox()) | (pw::value(lbl) == pw::cst(id)), 0));
 
 	  switch (info.type())
 	  {
-- 
1.5.6.5
                    
                  
                  
                          
                            
                            1
                            
                          
                          
                            
                            0
                            
                          
                          
                            
    
                          
                        
                    
                        
                            
                                
                            
                            last-svn-commit-895-g46636f5 Improve and cleanup	Results in hdoc toolchain.
                        
                        
by Guillaume Lazzara 26 May '11
                    by Guillaume Lazzara 26 May '11
26 May '11
                    
                        	* scribo/primitive/extract/non_text_hdoc.hh: Make parameters
	depend on the image size.
	* scribo/toolchain/internal/content_in_hdoc_functor.hh: Add new
	filters.
---
 scribo/ChangeLog                                   |   10 ++
 scribo/scribo/primitive/extract/non_text_hdoc.hh   |   34 ++++-
 .../toolchain/internal/content_in_hdoc_functor.hh  |  148 +++++++-------------
 3 files changed, 86 insertions(+), 106 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index b1be73d..ecece77 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,15 @@
 2011-05-26  Guillaume Lazzara  <z(a)lrde.epita.fr>
 
+	Improve and cleanup Results in hdoc toolchain.
+
+	* scribo/primitive/extract/non_text_hdoc.hh: Make parameters
+	depend on the image size.
+
+	* scribo/toolchain/internal/content_in_hdoc_functor.hh: Add new
+	filters.
+
+2011-05-26  Guillaume Lazzara  <z(a)lrde.epita.fr>
+
 	* scribo/primitive/extract/lines_h_thick_and_thin.hh: Improve
 	result quality.
 
diff --git a/scribo/scribo/primitive/extract/non_text_hdoc.hh b/scribo/scribo/primitive/extract/non_text_hdoc.hh
index 97e1f0e..b851bde 100644
--- a/scribo/scribo/primitive/extract/non_text_hdoc.hh
+++ b/scribo/scribo/primitive/extract/non_text_hdoc.hh
@@ -98,27 +98,47 @@ namespace scribo
 	mln_ch_value(L,bool)
 	  element_image = duplicate(doc.binary_image_wo_seps());
 
-	for_all_lines(l, doc.lines())
-	  if (doc.lines()(l).is_textline())
-	    mln::draw::box_plain(element_image, doc.lines()(l).bbox(), false);
+	// Mask text areas.
+	const paragraph_set<L>& parset = doc.paragraphs();
+	for_all_paragraphs(p, parset)
+	  if (parset(p).is_valid())
+	    for_all_paragraph_lines(l, parset(p).line_ids())
+	    {
+	      line_id_t lid = parset(p).line_ids()(l);
+	      mln::draw::box_plain(element_image, doc.lines()(lid).bbox(), false);
+	    }
 
 	element_image = morpho::closing::structural(element_image,
 						    win::rectangle2d(closing_size,
 								     closing_size));
+	// Debug
+	{
+	  debug::logger().log_image(debug::AuxiliaryResults,
+				    element_image,
+				    "non_text_hdoc_element_image");
+	}
+
 
 	mln_value(L) ncomps;
+
+	// FIXME: we should not tag elements as image here since we
+	// just don't know!
 	component_set<L>
 	  elements = primitive::extract::components(element_image,
-						    c8(), ncomps);
+						    c8(), ncomps,
+						    component::Image);
 
 	elements = scribo::filter::components_small(elements, 200);
 	elements = scribo::filter::components_on_border(elements);
-	elements = scribo::filter::objects_v_thin(elements, 100);
-	elements = scribo::filter::objects_h_thin(elements, 100);
+
+	elements = scribo::filter::objects_v_thin(elements,
+						  0.03 * doc.image().domain().height());
+	elements = scribo::filter::objects_h_thin(elements,
+						  0.03 * doc.image().domain().width());
 
 	// Debug
 	{
-	  debug::logger().log_image(debug::Special,
+	  debug::logger().log_image(debug::Results,
 				    elements.labeled_image(),
 				    "non_text_hdoc_components");
 	}
diff --git a/scribo/scribo/toolchain/internal/content_in_hdoc_functor.hh b/scribo/scribo/toolchain/internal/content_in_hdoc_functor.hh
index ef33b31..e0c5b50 100644
--- a/scribo/scribo/toolchain/internal/content_in_hdoc_functor.hh
+++ b/scribo/scribo/toolchain/internal/content_in_hdoc_functor.hh
@@ -27,6 +27,10 @@
 #ifndef SCRIBO_TOOLCHAIN_INTERNAL_CONTENT_IN_HDOC_FUNCTOR_HH
 # define SCRIBO_TOOLCHAIN_INTERNAL_CONTENT_IN_HDOC_FUNCTOR_HH
 
+#  ifndef SCRIBO_NDEBUG
+#  include <mln/util/timer.hh>
+#  endif // ! SCRIBO_NDEBUG
+
 # include <scribo/core/def/lbl_type.hh>
 # include <scribo/core/document.hh>
 # include <scribo/core/line_set.hh>
@@ -34,9 +38,6 @@
 
 # include <scribo/primitive/extract/non_text_hdoc.hh>
 # include <scribo/primitive/extract/components.hh>
-// # include <scribo/primitive/extract/separators.hh>
-// # include <scribo/primitive/extract/vertical_separators.hh>
-// # include <scribo/primitive/extract/horizontal_separators.hh>
 # include <scribo/primitive/extract/lines_h_thick_and_thin.hh>
 
 # include <scribo/primitive/extract/alignments.hh>
@@ -50,6 +51,11 @@
 # include <scribo/filter/line_links_x_height.hh>
 # include <scribo/filter/object_links_bbox_h_ratio.hh>
 # include <scribo/filter/objects_small.hh>
+# include <scribo/filter/paragraphs_bbox_overlap.hh>
+# include <scribo/filter/paragraphs_in_image.hh>
+# include <scribo/filter/separators_in_element.hh>
+# include <scribo/filter/separators_in_paragraph.hh>
+# include <scribo/filter/images_in_paragraph.hh>
 
 # include <scribo/primitive/group/from_single_link.hh>
 
@@ -198,7 +204,7 @@ namespace scribo
 	    mln_ch_value(I,bool)
 	      vseparators = preprocessing::rotate_90(
 	       	primitive::extract::lines_h_thick_and_thin(
-		  preprocessing::rotate_90(processed_image), 101, 3, 0.2, 0.6, 1), false),
+		  preprocessing::rotate_90(processed_image), 101, 3, 0.2, 0.6, 10), false),
 	      hseparators = primitive::extract::lines_h_thick_and_thin(
 		processed_image, 101, 3);
 
@@ -226,27 +232,31 @@ namespace scribo
 	// Debug
 	if (enable_line_seps)
 	{
-	  debug::logger().log_image(debug::Special,
+	  debug::logger().log_image(debug::AuxiliaryResults,
 				    doc.vline_seps(),
 				    "vseparators");
 
-	  debug::logger().log_image(debug::Special,
+	  debug::logger().log_image(debug::AuxiliaryResults,
 				    doc.hline_seps(),
 				    "hseparators");
 
-	  debug::logger().log_image(debug::Special,
+	  debug::logger().log_image(debug::AuxiliaryResults,
 				    input_cleaned,
 				    "input_wo_separators");
 	}
 #  endif // ! SCRIBO_NDEBUG
 
+	unsigned min_area = std::min(0.005 * doc.image().domain().width(),
+				     0.005 * doc.image().domain().height());
 
 	// Denoise
 	if (enable_denoising)
 	{
 	  on_new_progress_label("Denoise...");
 
-	  input_cleaned = preprocessing::denoise_fg(input_cleaned, c8(), 10);
+	  std::cout << ">> min_area = " << min_area << std::endl;
+
+	  input_cleaned = preprocessing::denoise_fg(input_cleaned, c8(), min_area);
 
 	  // Debug
 #  ifndef SCRIBO_NDEBUG
@@ -286,7 +296,7 @@ namespace scribo
 
 	on_new_progress_label("Filtering components");
 
-	components = scribo::filter::components_small(components, 10);
+	components = scribo::filter::components_small(components, min_area);
 
 	on_progress();
 
@@ -297,6 +307,7 @@ namespace scribo
 	object_links<L> left_link
 	  = primitive::link::with_single_left_link_dmax_ratio(
 	    components,
+//	    primitive::link::internal::dmax_width_and_height(1),
 	    primitive::link::internal::dmax_default(1),
 	    anchor::MassCenter);
 
@@ -304,6 +315,7 @@ namespace scribo
 	object_links<L> right_link
 	  = primitive::link::with_single_right_link_dmax_ratio(
 	    components,
+//	    primitive::link::internal::dmax_width_and_height(1),
 	    primitive::link::internal::dmax_default(1),
 	    anchor::MassCenter);
 
@@ -398,7 +410,7 @@ namespace scribo
 	if (debug::logger().is_enabled())
 	{
 	  if (enable_whitespace_seps)
-	    debug::logger().log_image(debug::Special,
+	    debug::logger().log_image(debug::AuxiliaryResults,
 				      whitespaces, "whitespaces");
 
 	  // Bboxes image.
@@ -428,7 +440,7 @@ namespace scribo
 #  endif // ! SCRIBO_NDEBUG
 	//===== END OF DEBUG =====
 
-
+	on_new_progress_label("Merging segmented lines");
 
 	lines = scribo::text::merging(lines);
 
@@ -488,96 +500,17 @@ namespace scribo
 	  on_progress();
 	}
 
-// 	// Link text lines
-// 	on_new_progress_label("Linking text lines");
-// 	line_links<L> llinks = scribo::text::link_lines(lines);
-
-
-// 	//===== DEBUG =====
-// #  ifndef SCRIBO_NDEBUG
-// 	if (debug::logger().is_enabled())
-// 	{
-// 	  image2d<value::rgb8>
-// 	    debug = data::convert(value::rgb8(), original_image);
-// 	  for_all_lines(l, lines)
-// 	  {
-// 	    if (! lines(l).is_textline())
-// 	      continue;
-
-// 	    mln::draw::box(debug, lines(l).bbox(), literal::blue);
-// 	    mln::draw::line(debug, lines(l).bbox().pcenter(),
-// 			    lines(llinks(l)).bbox().pcenter(), literal::green);
-// 	  }
-
-// 	  debug::logger().log_image(debug::AuxiliaryResults,
-// 					      debug, "links_raw");
-// 	}
-// #  endif // ! SCRIBO_NDEBUG
-// 	//===== END OF DEBUG =====
-
-// 	on_progress();
-
-
-// 	// Filter line links.
-// 	on_new_progress_label("Filter line links");
-// 	llinks = scribo::filter::line_links_x_height(llinks);
-
-// 	//===== DEBUG =====
-// #  ifndef SCRIBO_NDEBUG
-// 	if (debug::logger().is_enabled())
-// 	{
-// 	  image2d<value::rgb8>
-// 	    debug = data::convert(value::rgb8(), original_image);
-// 	  for_all_links(i, llinks)
-// 	    if (llinks(i) && llinks(i) != i)
-// 	      mln::draw::line(debug, lines(i).bbox().pcenter(),
-// 			      lines(llinks(i)).bbox().pcenter(), literal::red);
-
-// 	  debug::logger().log_image(debug::AuxiliaryResults,
-// 					      debug, "links");
-
-// 	  for (unsigned i = 1; i < llinks.nelements(); ++i)
-// 	    llinks(i) = scribo::make::internal::find_root(llinks, i);
-
-// 	  debug = data::convert(value::rgb8(), original_image);
-// 	  mln::util::array<accu::shape::bbox<point2d> >
-// 	    nbbox(llinks.nelements());
-
-// 	  for_all_lines(i, lines)
-// 	  {
-// 	    if (! lines(i).is_textline())
-// 	      continue;
-
-// 	    mln::draw::box(debug, lines(i).bbox(), literal::red);
-// 	    nbbox(llinks(i)).take(lines(i).bbox());
-// 	  }
-
-// 	  for (unsigned i = 1; i < nbbox.nelements(); ++i)
-// 	    if (nbbox(i).is_valid())
-// 	    {
-// 	      box2d b = nbbox(i).to_result();
-// 	      mln::draw::box(debug, b, literal::green);
-// 	      b.enlarge(1);
-// 	      mln::draw::box(debug, b, literal::green);
-// 	      b.enlarge(1);
-// 	      mln::draw::box(debug, b, literal::green);
-// 	    }
-
-// 	  debug::logger().log_image(debug::AuxiliaryResults,
-// 					      debug, "par");
-// 	}
-// #  endif // ! SCRIBO_NDEBUG
-// 	//===== END OF DEBUG =====
-
-// 	on_progress();
-
-
-// 	// Construct paragraphs
-// 	on_new_progress_label("Constructing paragraphs");
-// 	scribo::paragraph_set<L> parset = scribo::make::paragraph(llinks);
+	on_new_progress_label("Extracting paragraphs");
 
 	scribo::paragraph_set<L>
 	  parset = extract_paragraphs(lines, doc.binary_image());
+
+	on_progress();
+
+	on_new_progress_label("Filtering paragraphs");
+
+	parset = filter::paragraphs_bbox_overlap(parset);
+
 	doc.set_paragraphs(parset);
 
 	on_progress();
@@ -585,8 +518,16 @@ namespace scribo
 
 	// Extract other Elements
 	on_new_progress_label("Extracting Elements");
+
+	unsigned closing_size = std::min(0.01 * doc.image().domain().width(),
+					 0.01 * doc.image().domain().height());
+	if (!(closing_size % 2))
+	  closing_size += 1;
+
+	std::cout << ">> CLosing size = " << closing_size << std::endl;
+
 	component_set<L>
-	  elements = scribo::primitive::extract::non_text_hdoc(doc, 31);
+	  elements = scribo::primitive::extract::non_text_hdoc(doc, closing_size);
 
 	on_progress();
 
@@ -599,6 +540,15 @@ namespace scribo
 
 	on_progress();
 
+	on_new_progress_label("Cleanup miscellaneous false positive");
+
+	filter::separators_in_element(doc);
+	filter::separators_in_paragraph(doc);
+	filter::paragraphs_in_image(doc);
+	filter::images_in_paragraph(doc);
+
+	on_progress();
+
 
 
 	// Saving results
-- 
1.5.6.5
                    
                  
                  
                          
                            
                            1
                            
                          
                          
                            
                            0
                            
                          
                          
                            
    
                          
                        
                    
                        
                            
                                
                            
                            last-svn-commit-894-g3a15c02	scribo/primitive/extract/lines_h_thick_and_thin.hh: Improve	result quality.
                        
                        
by Guillaume Lazzara 26 May '11
                    by Guillaume Lazzara 26 May '11
26 May '11
                    
                        ---
 scribo/ChangeLog                                   |    5 +++++
 .../primitive/extract/lines_h_thick_and_thin.hh    |   16 ++++++++++++----
 2 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 87364fc..b1be73d 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,10 @@
 2011-05-26  Guillaume Lazzara  <z(a)lrde.epita.fr>
 
+	* scribo/primitive/extract/lines_h_thick_and_thin.hh: Improve
+	result quality.
+
+2011-05-26  Guillaume Lazzara  <z(a)lrde.epita.fr>
+
 	Add new hooks in toolchain functors.
 
 	* toolchain/internal/toolchain_functor.hh: Here.
diff --git a/scribo/scribo/primitive/extract/lines_h_thick_and_thin.hh b/scribo/scribo/primitive/extract/lines_h_thick_and_thin.hh
index 511da9f..53a5c32 100644
--- a/scribo/scribo/primitive/extract/lines_h_thick_and_thin.hh
+++ b/scribo/scribo/primitive/extract/lines_h_thick_and_thin.hh
@@ -83,7 +83,7 @@ namespace scribo
 			     unsigned length, unsigned delta,
 			     float p_few = 0.2,     // very tolerant  (v. severe is 0.05)
 			     float p_enough = 0.6, // very tolerant  (v. severe is 0.80)
-			     unsigned filter_factor = 1);
+			     float ratio = 8);
 
 
 # ifndef MLN_INCLUDE_ONLY
@@ -469,7 +469,7 @@ namespace scribo
       lines_h_thick_and_thin(const Image<I>& binary_image_,
 			     unsigned length, unsigned delta,
 			     float p_few, float p_enough,
-			     unsigned filter_factor)
+			     float ratio)
       {
 	trace::entering("scribo::primitive::extract::lines_h_thick_and_thin");
 
@@ -504,9 +504,17 @@ namespace scribo
 	mln::util::array<box2d>
 	  bbox = labeling::compute(accu::shape::bbox<point2d>(), lbl, nlabels);
 
+	image2d<value::int_u8> debug;
+	initialize(debug, binary_image);
+	data::fill(debug, 0);
 	for_all_ncomponents(e, nlabels)
-	  if (bbox(e).width() < filter_factor * length || bbox(e).width() / bbox(e).height() < 3)
-	    data::fill(((output | bbox(e)).rw() | (pw::value(lbl) == pw::cst(e))).rw(), false);
+	{
+	  if (bbox(e).width() < length ||
+	      (std::max(bbox(e).width(), bbox(e).height()) /
+	       std::min(bbox(e).width(), bbox(e).height()) + 0.49999) < ratio)
+	    data::fill(((output | bbox(e)).rw()
+			| (pw::value(lbl) == pw::cst(e))).rw(), false);
+	}
 
 	debug::logger().log_image(debug::Results,
 				  output, "lines_h_thick_and_thin_output");
-- 
1.5.6.5
                    
                  
                  
                          
                            
                            1
                            
                          
                          
                            
                            0
                            
                          
                          
                            
    
                          
                        
                    26 May '11
                    
                        	* toolchain/internal/toolchain_functor.hh: Here.
	* toolchain/internal/content_in_doc_functor.hh,
	* toolchain/internal/content_in_hdoc_functor.hh,
	* toolchain/internal/text_in_doc_functor.hh,
	* toolchain/internal/text_in_doc_preprocess_functor.hh: Make use
	of them.
---
 scribo/ChangeLog                                   |   12 +++++
 .../toolchain/internal/content_in_doc_functor.hh   |    4 ++
 .../toolchain/internal/content_in_hdoc_functor.hh  |   53 ++++++++++++++++++++
 .../toolchain/internal/text_in_doc_functor.hh      |    4 ++
 .../internal/text_in_doc_preprocess_functor.hh     |   53 ++++++++++++++++++-
 .../scribo/toolchain/internal/toolchain_functor.hh |   28 ++++++++++-
 6 files changed, 149 insertions(+), 5 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 13b8e95..87364fc 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,17 @@
 2011-05-26  Guillaume Lazzara  <z(a)lrde.epita.fr>
 
+	Add new hooks in toolchain functors.
+
+	* toolchain/internal/toolchain_functor.hh: Here.
+
+	* toolchain/internal/content_in_doc_functor.hh,
+	* toolchain/internal/content_in_hdoc_functor.hh,
+	* toolchain/internal/text_in_doc_functor.hh,
+	* toolchain/internal/text_in_doc_preprocess_functor.hh: Make use
+	of them.
+
+2011-05-26  Guillaume Lazzara  <z(a)lrde.epita.fr>
+
 	* scribo/util/component_precise_outline.hh: New. Precise component
 	outline extraction.
 
diff --git a/scribo/scribo/toolchain/internal/content_in_doc_functor.hh b/scribo/scribo/toolchain/internal/content_in_doc_functor.hh
index d60f3cc..4308056 100644
--- a/scribo/scribo/toolchain/internal/content_in_doc_functor.hh
+++ b/scribo/scribo/toolchain/internal/content_in_doc_functor.hh
@@ -162,6 +162,8 @@ namespace scribo
 	mln_precondition(exact(original_image).is_valid());
 	mln_precondition(exact(processed_image).is_valid());
 
+	on_start();
+
 	doc.set_image(exact(original_image));
 	doc.set_binary_image(exact(processed_image));
 
@@ -568,6 +570,8 @@ namespace scribo
 	  on_progress();
 	}
 
+	on_end();
+
 	return doc;
       }
 
diff --git a/scribo/scribo/toolchain/internal/content_in_hdoc_functor.hh b/scribo/scribo/toolchain/internal/content_in_hdoc_functor.hh
index e7d14ff..ef33b31 100644
--- a/scribo/scribo/toolchain/internal/content_in_hdoc_functor.hh
+++ b/scribo/scribo/toolchain/internal/content_in_hdoc_functor.hh
@@ -132,6 +132,20 @@ namespace scribo
 	// Results
 	//=========
 	document<L> doc;
+
+
+
+#  ifndef SCRIBO_NDEBUG
+	//=============
+	// DEBUG TOOLS
+	//=============
+	virtual void on_start();
+	virtual void on_end();
+	virtual void on_progress();
+
+	mln::util::timer t;
+	mln::util::timer gt;
+#  endif // ! SCRIBO_NDEBUG
       };
 
 
@@ -165,6 +179,8 @@ namespace scribo
 	mln_precondition(exact(original_image).is_valid());
 	mln_precondition(exact(processed_image).is_valid());
 
+	on_start();
+
 	doc.set_image(exact(original_image));
 	doc.set_binary_image(exact(processed_image));
 
@@ -353,6 +369,8 @@ namespace scribo
 	line_set<L>
 	  lines = scribo::make::line_set(groups);
 
+	on_progress();
+
 
 	// Extract whitespace to improve text merging results afterwards.
 	mln_ch_value(L,bool) whitespaces;
@@ -594,6 +612,8 @@ namespace scribo
 	  on_progress();
 	}
 
+	on_end();
+
 	return doc;
       }
 
@@ -615,6 +635,39 @@ namespace scribo
 	// Nothing
       }
 
+#  ifndef SCRIBO_NDEBUG
+
+      template <typename I>
+      void
+      content_in_hdoc_functor<I>::on_start()
+      {
+	gt.start();
+	t.start();
+      }
+
+      template <typename I>
+      void
+      content_in_hdoc_functor<I>::on_end()
+      {
+	gt.stop();
+	if (verbose)
+	  std::cout << "Total time: " << gt << std::endl;
+      }
+
+      template <typename I>
+      void
+      content_in_hdoc_functor<I>::on_progress()
+      {
+	t.stop();
+	if (verbose)
+	  std::cout << t << std::endl;
+	t.restart();
+      }
+
+
+#  endif // ! SCRIBO_NDEBUG
+
+
 # endif // ! MLN_INCLUDE_ONLY
 
 
diff --git a/scribo/scribo/toolchain/internal/text_in_doc_functor.hh b/scribo/scribo/toolchain/internal/text_in_doc_functor.hh
index 62074f0..f5b94cf 100644
--- a/scribo/scribo/toolchain/internal/text_in_doc_functor.hh
+++ b/scribo/scribo/toolchain/internal/text_in_doc_functor.hh
@@ -130,6 +130,8 @@ namespace scribo
       line_set<typename text_in_doc_functor<I>::L>
       text_in_doc_functor<I>::operator()(const Image<I>& input)
       {
+	on_start();
+
 	// Remove separators
 	mln_ch_value(I,bool)
 	  separators,
@@ -387,6 +389,8 @@ namespace scribo
 
 	on_progress();
 
+	on_end();
+
 	output = lines;
 	return output;
       }
diff --git a/scribo/scribo/toolchain/internal/text_in_doc_preprocess_functor.hh b/scribo/scribo/toolchain/internal/text_in_doc_preprocess_functor.hh
index 6c0dd5a..484e28e 100644
--- a/scribo/scribo/toolchain/internal/text_in_doc_preprocess_functor.hh
+++ b/scribo/scribo/toolchain/internal/text_in_doc_preprocess_functor.hh
@@ -132,6 +132,18 @@ namespace scribo
 	mln_concrete(I) bg;
 	image2d<bool> output;
 
+#  ifndef SCRIBO_NDEBUG
+	//=============
+	// DEBUG TOOLS
+	//=============
+	virtual void on_start();
+	virtual void on_end();
+	virtual void on_progress();
+
+	mln::util::timer t;
+	mln::util::timer gt;
+#  endif // ! SCRIBO_NDEBUG
+
       private: // Methods
 	unsigned find_best_scale(const Image<I>& ima_);
 
@@ -169,6 +181,8 @@ namespace scribo
 
 	mln_concrete(I) input_rgb = input;
 
+	on_start();
+
 	// Subsample
 	//----------
 	if (enable_subsample)
@@ -227,8 +241,6 @@ namespace scribo
 
 	// Binarization (always happens)
 	//------------------------------
-	on_new_progress_label("Binarization");
-
 	if (binarization_algo == Sauvola)
 	{
 	  on_new_progress_label("Binarization (Sauvola)");
@@ -242,7 +254,7 @@ namespace scribo
 	}
 	else // binarization_algo == Convert
 	{
-	  on_new_progress_label("Binary conversion");
+	  on_new_progress_label("Binarization (Binary conversion)");
 	  output = mln::data::convert(bool(), intensity_ima);
 	}
 
@@ -260,6 +272,8 @@ namespace scribo
 	  on_progress();
 	}
 
+	on_end();
+
 	return output;
       }
 
@@ -293,6 +307,39 @@ namespace scribo
       }
 
 
+#  ifndef SCRIBO_NDEBUG
+
+      template <typename I>
+      void
+      text_in_doc_preprocess_functor<I>::on_start()
+      {
+	gt.start();
+	t.start();
+      }
+
+      template <typename I>
+      void
+      text_in_doc_preprocess_functor<I>::on_end()
+      {
+	gt.stop();
+	if (verbose)
+	  std::cout << "Total time: " << gt << std::endl;
+      }
+
+      template <typename I>
+      void
+      text_in_doc_preprocess_functor<I>::on_progress()
+      {
+	t.stop();
+	if (verbose)
+	  std::cout << t << std::endl;
+	t.restart();
+      }
+
+
+#  endif // ! SCRIBO_NDEBUG
+
+
 # endif // ! MLN_INCLUDE_ONLY
 
 
diff --git a/scribo/scribo/toolchain/internal/toolchain_functor.hh b/scribo/scribo/toolchain/internal/toolchain_functor.hh
index a29dafa..5621c7c 100644
--- a/scribo/scribo/toolchain/internal/toolchain_functor.hh
+++ b/scribo/scribo/toolchain/internal/toolchain_functor.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory
+// (LRDE)
 //
 // This file is part of Olena.
 //
@@ -26,6 +27,7 @@
 #ifndef SCRIBO_TOOLCHAIN_INTERNAL_TOOLCHAIN_FUNCTOR_HH
 # define SCRIBO_TOOLCHAIN_INTERNAL_TOOLCHAIN_FUNCTOR_HH
 
+# include <unistd.h>
 # include <iostream>
 
 namespace scribo
@@ -50,6 +52,8 @@ namespace scribo
 	// Triggers
 	//==========
 
+	virtual void on_start();
+	virtual void on_end();
 	virtual void on_progress();
 	virtual void on_new_progress_label(const char *label);
 
@@ -71,17 +75,37 @@ namespace scribo
       // Triggers
       //==========
 
+
+      inline
+      void Toolchain_Functor::on_start()
+      {
+	// Nothing
+      }
+
+      inline
+      void Toolchain_Functor::on_end()
+      {
+	// Nothing
+      }
+
       inline
       void Toolchain_Functor::on_progress()
       {
 	// Nothing
+	if (verbose)
+	  std::cout << std::endl;
       }
 
       inline
       void Toolchain_Functor::on_new_progress_label(const char *label)
       {
 	if (verbose)
-	  std::cout << label << std::endl;
+	{
+	  if (isatty(1))
+	    std::cout << "> \e[0;32m " << label << " \e[m - ";
+	  else
+	    std::cout << "> " << label << " - ";
+	}
       }
 
 # endif // ! MLN_INCLUDE_ONLY
-- 
1.5.6.5
                    
                  
                  
                          
                            
                            1
                            
                          
                          
                            
                            0
                            
                          
                          
                            
    
                          
                        
                    
                        
                            
                                
                            
                            last-svn-commit-892-g9f7843c	scribo/util/component_precise_outline.hh: New. Precise	component outline extraction.
                        
                        
by Guillaume Lazzara 26 May '11
                    by Guillaume Lazzara 26 May '11
26 May '11
                    
                        ---
 scribo/ChangeLog                                |    5 +
 scribo/scribo/util/component_precise_outline.hh |  309 +++++++++++++++++++++++
 2 files changed, 314 insertions(+), 0 deletions(-)
 create mode 100644 scribo/scribo/util/component_precise_outline.hh
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 16762ae..13b8e95 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,10 @@
 2011-05-26  Guillaume Lazzara  <z(a)lrde.epita.fr>
 
+	* scribo/util/component_precise_outline.hh: New. Precise component
+	outline extraction.
+
+2011-05-26  Guillaume Lazzara  <z(a)lrde.epita.fr>
+
 	Add new element filters.
 
 	* scribo/filter/images_in_paragraph.hh,
diff --git a/scribo/scribo/util/component_precise_outline.hh b/scribo/scribo/util/component_precise_outline.hh
new file mode 100644
index 0000000..3c6e523
--- /dev/null
+++ b/scribo/scribo/util/component_precise_outline.hh
@@ -0,0 +1,309 @@
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena.  If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction.  Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License.  This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#ifndef SCRIBO_UTIL_COMPONENT_PRECISE_OUTLINE_HH
+# define SCRIBO_UTIL_COMPONENT_PRECISE_OUTLINE_HH
+
+/*!
+ * \file
+ *
+ * \brief Define a function which finds a precise and isothetic
+ * outline.
+ *
+ */
+
+
+# include <mln/io/pbm/load.hh>
+# include <mln/literal/colors.hh>
+# include <mln/io/ppm/save.hh>
+# include <mln/data/convert.hh>
+# include <mln/opt/at.hh>
+
+# include <iostream>
+
+namespace scribo
+{
+
+  namespace util
+  {
+
+    using namespace mln;
+
+
+    template <typename I>
+    mln::p_array<point2d>
+    component_precise_outline(const Image<I>& input_);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+    namespace internal
+    {
+
+
+      static const int offset[4][8][2] =
+      {
+	{ { -1, 0 }, { 0, -1 }, { -1, -1 }, { 1, 0 }, { 1, -1 }, { 0, 1 }, {
+	    1, 1 }, { -1, 1 } },
+	{ { 0, -1 }, { 1, 0 }, { 1, -1 }, { 0, 1 }, { 1, 1 }, { -1, 0 }, {
+	    -1, 1 }, { -1, -1 } },
+	{ { 1, 0 }, { 0, 1 }, { 1, 1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, {
+	    -1, -1 }, { 1, -1 } },
+	{ { 0, 1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { -1, -1 }, { 1, 0 }, {
+	    1, -1 }, { 1, 1 } }
+      };
+
+
+      template <typename I>
+      void
+      find_first_point(const I& input,
+		       point2d& p)
+      {
+	const def::coord mid_row = geom::min_row(input) + (geom::nrows(input) >> 1);
+
+	for (def::coord i = geom::min_col(input); i <= geom::max_col(input); ++i)
+	{
+	  if (opt::at(input, mid_row, i))
+	  {
+	    p.row() = mid_row;
+	    p.col() = i;
+	    break;
+	  }
+	}
+      }
+
+      template <typename I>
+      void
+      left_up(int& direction,
+	      const unsigned i,
+	      const I& input,
+	      const point2d& cur_pt)
+      {
+	if (i < 3)
+	{
+	  const point2d p1(cur_pt.row() + offset[direction][0][1],
+			   cur_pt.col() + offset[direction][0][0]);
+	  const point2d p2(cur_pt.row() + offset[direction][5][1],
+			   cur_pt.col() + offset[direction][5][0]);
+	  const point2d p3(cur_pt.row() + offset[direction][7][1],
+			   cur_pt.col() + offset[direction][7][0]);
+
+	  if (input(p1) && !input(p2) && input(p3))
+	  {
+	    direction = 3;
+	    return;
+	  }
+	}
+
+	if (i == 3 || i == 4)
+	  direction = 1;
+	else if (i == 5 || i == 6)
+	  direction = 2;
+	else if (i == 7)
+	  direction = 3;
+      }
+
+
+      template <typename I>
+      void
+      right_up(int& direction,
+	       const unsigned i,
+	       const I& input,
+	       const point2d& cur_pt)
+      {
+	if (i < 3)
+	{
+	  const point2d p2(cur_pt.row() + offset[direction][5][1],
+			   cur_pt.col() + offset[direction][5][0]);
+	  const point2d p3(cur_pt.row() + offset[direction][7][1],
+			   cur_pt.col() + offset[direction][7][0]);
+
+	  if (!input(p2) && input(p3))
+	  {
+	    direction = 0;
+	    return;
+	  }
+	}
+
+	if (i == 3 || i == 4)
+	  direction = 2;
+	else if (i == 5 || i == 6)
+	  direction = 3;
+	else if (i == 7)
+	  direction = 0;
+      }
+
+
+      template <typename I>
+      void
+      right_down(int& direction,
+		 const unsigned i,
+		 const I& input,
+		 const point2d& cur_pt)
+      {
+	if (i < 3)
+	{
+	  const point2d p1(cur_pt.row() + offset[direction][0][1],
+			   cur_pt.col() + offset[direction][0][0]);
+	  const point2d p2(cur_pt.row() + offset[direction][5][1],
+			   cur_pt.col() + offset[direction][5][0]);
+	  const point2d p3(cur_pt.row() + offset[direction][7][1],
+			   cur_pt.col() + offset[direction][7][0]);
+
+	  if (input(p1) && !input(p2) && input(p3))
+	  {
+	    direction = 1;
+	    return;
+	  }
+	}
+
+	if (i == 3 || i == 4)
+	  direction = 3;
+	else if (i == 5 || i == 6)
+	  direction = 0;
+	else if (i == 7)
+	  direction = 1;
+      }
+
+
+      template <typename I>
+      void
+      left_down(int& direction,
+		const unsigned i,
+		const I& input,
+		const point2d& cur_pt)
+      {
+	if (i < 3)
+	{
+	  const point2d p2(cur_pt.row() + offset[direction][5][1],
+			   cur_pt.col() + offset[direction][5][0]);
+	  const point2d p3(cur_pt.row() + offset[direction][7][1],
+			   cur_pt.col() + offset[direction][7][0]);
+
+	  if (!input(p2) && input(p3))
+	  {
+	    direction = 2;
+	    return;
+	  }
+	}
+
+	if (i == 3 || i == 4)
+	  direction = 0;
+	else if (i == 5 || i == 6)
+	  direction = 1;
+	else if (i == 7)
+	  direction = 2;
+      }
+
+      template <typename I>
+      void
+      find_next_point(const I& input,
+		      point2d& cur_pt,
+		      int& direction)
+      {
+	unsigned i = 0;
+	point2d tmp;
+
+	for (; i < 8; ++i)
+	{
+	  tmp = point2d(cur_pt.row() + offset[direction][i][1],
+			cur_pt.col() + offset[direction][i][0]);
+
+	  if (input.domain().has(tmp) && input(tmp))
+	    break;
+	}
+
+	// Should not happen
+	if (i == 8)
+	  return;
+
+	switch (direction)
+	{
+	  case 0: left_up(direction, i, input, cur_pt); break;
+	  case 1: right_up(direction , i, input, cur_pt); break;
+	  case 2: right_down(direction, i, input, cur_pt); break;
+	  case 3: left_down(direction, i, input, cur_pt); break;
+	}
+
+	cur_pt = tmp;
+      }
+
+    } // end of namespace scribo::util::internal
+
+
+    template <typename I>
+    mln::p_array<point2d>
+    component_precise_outline(const Image<I>& input_)
+    {
+      trace::entering("scribo::util::component_precise_outline");
+
+      const I& input = exact(input_);
+      typedef mln_site(I) P;
+
+      point2d start_pt;
+      int direction = 0;
+      mln::p_array<P> points;
+      points.reserve(std::max(geom::ncols(input), geom::nrows(input)));
+
+      internal::find_first_point(input, start_pt);
+
+      P cur_pt = start_pt;
+
+      internal::find_next_point(input, cur_pt, direction);
+      points.append(cur_pt);
+
+      while (cur_pt != start_pt)
+      {
+	internal::find_next_point(input, cur_pt, direction);
+	points.append(cur_pt);
+      }
+
+
+      internal::find_next_point(input, cur_pt, direction);
+
+      const std::vector<point2d>& vec_points = points.hook_std_vector_();
+
+      if (std::find(vec_points.begin(), vec_points.end(), cur_pt) == vec_points.end())
+      {
+	points.append(cur_pt);
+
+	while (cur_pt != start_pt)
+	{
+	  internal::find_next_point(input, cur_pt, direction);
+	  points.append(cur_pt);
+	}
+      }
+
+      trace::exiting("scribo::util::component_precise_outline");
+      return points;
+    }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+  } // end of namespace scribo::util
+
+} // end of namespace scribo
+
+#endif // ! SCRIBO_UTIL_COMPONENT_PRECISE_OUTLINE_HH
-- 
1.5.6.5
                    
                  
                  
                          
                            
                            1
                            
                          
                          
                            
                            0
                            
                          
                          
                            
    
                          
                        
                    
                    
                        	* scribo/filter/images_in_paragraph.hh,
	* scribo/filter/paragraphs_bbox_overlap.hh,
	* scribo/filter/paragraphs_in_image.hh,
	* scribo/filter/separators_in_element.hh,
	* scribo/filter/separators_in_paragraph.hh: New.
---
 scribo/ChangeLog                                |   10 ++
 scribo/scribo/filter/images_in_paragraph.hh     |  119 +++++++++++++++
 scribo/scribo/filter/paragraphs_bbox_overlap.hh |  176 +++++++++++++++++++++++
 scribo/scribo/filter/paragraphs_in_image.hh     |  129 +++++++++++++++++
 scribo/scribo/filter/separators_in_element.hh   |  151 +++++++++++++++++++
 scribo/scribo/filter/separators_in_paragraph.hh |  151 +++++++++++++++++++
 6 files changed, 736 insertions(+), 0 deletions(-)
 create mode 100644 scribo/scribo/filter/images_in_paragraph.hh
 create mode 100644 scribo/scribo/filter/paragraphs_bbox_overlap.hh
 create mode 100644 scribo/scribo/filter/paragraphs_in_image.hh
 create mode 100644 scribo/scribo/filter/separators_in_element.hh
 create mode 100644 scribo/scribo/filter/separators_in_paragraph.hh
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 959746f..16762ae 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,15 @@
 2011-05-26  Guillaume Lazzara  <z(a)lrde.epita.fr>
 
+	Add new element filters.
+
+	* scribo/filter/images_in_paragraph.hh,
+	* scribo/filter/paragraphs_bbox_overlap.hh,
+	* scribo/filter/paragraphs_in_image.hh,
+	* scribo/filter/separators_in_element.hh,
+	* scribo/filter/separators_in_paragraph.hh: New.
+
+2011-05-26  Guillaume Lazzara  <z(a)lrde.epita.fr>
+
 	Add util::box_intersection.
 
 	* scribo/util/box_intersection.hh: New.
diff --git a/scribo/scribo/filter/images_in_paragraph.hh b/scribo/scribo/filter/images_in_paragraph.hh
new file mode 100644
index 0000000..e05b202
--- /dev/null
+++ b/scribo/scribo/filter/images_in_paragraph.hh
@@ -0,0 +1,119 @@
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena.  If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction.  Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License.  This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#ifndef SCRIBO_FILTER_IMAGES_IN_PARAGRAPH_HH
+# define SCRIBO_FILTER_IMAGES_IN_PARAGRAPH_HH
+
+/// \file
+///
+/// Invalidate false positive separators.
+/// \fixme Share same test canvas as text::merging.
+
+
+# include <mln/core/concept/image.hh>
+# include <scribo/core/component_set.hh>
+# include <scribo/core/document.hh>
+
+
+namespace scribo
+{
+
+  namespace filter
+  {
+
+    using namespace mln;
+
+
+    /// Invalidate false positive separators.
+    ///
+    /// \param[in] separators    A paragraph set.
+    ///
+    /// \return A doc with invalidated separators.
+    ///
+    /// Warning: it does not remove separators from separator
+    /// image. It only invalidate separator components in their
+    /// respective component_set.
+    ///
+    template <typename L>
+    void
+    images_in_paragraph(document<L>& doc);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+    template <typename L>
+    void
+    images_in_paragraph(document<L>& doc)
+    {
+      trace::entering("scribo::filter::images_in_paragraph");
+
+      mln_precondition(doc.is_valid());
+
+      if (! doc.has_elements())
+	return;
+
+      mln_ch_value(L,bool) billboard;
+      initialize(billboard, doc.image());
+      data::fill(billboard, false);
+
+      for_all_comps(p, doc.paragraphs())
+	if (doc.paragraphs()(p).is_valid())
+	  mln::draw::box_plain(billboard, doc.paragraphs()(p).bbox(), true);
+
+
+      component_set<L> elts = doc.elements();
+      for_all_comps(c, elts)
+	if (elts(c).is_valid() && elts(c).type() == component::Image)
+	{
+	  const mln_box(L)& b_ = elts(c).bbox();
+
+	  const bool tl = billboard(b_.pmin());
+	  const bool tr = billboard.at_(b_.pmin().row(), b_.pmax().col());
+	  const bool ml = billboard.at_(b_.pcenter().row(), b_.pmin().col());
+	  const bool mc = billboard.at_(b_.pcenter().row(), b_.pcenter().col());
+	  const bool mr = billboard.at_(b_.pcenter().row(), b_.pmax().col());
+	  const bool bl = billboard.at_(b_.pmax().row(), b_.pmin().col());
+	  const bool br = billboard(b_.pmax());
+
+	  // This separator is included in an element (picture, drawing...)
+	  // => Ignore it.
+	  if (tl && tr && ml && mc && mr && bl && br)
+	    elts(c).update_tag(component::Ignored);
+
+	  // FIXME: warning this call may produce inconsistent data
+	  // Ignored components are still in the separator image...
+	  doc.set_elements(elts);
+	}
+
+      trace::exiting("scribo::filter::images_in_paragraph");
+    }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+  } // end of namespace scribo::filter
+
+} // end of namespace scribo
+
+#endif // ! SCRIBO_FILTER_IMAGES_IN_PARAGRAPH_HH
diff --git a/scribo/scribo/filter/paragraphs_bbox_overlap.hh b/scribo/scribo/filter/paragraphs_bbox_overlap.hh
new file mode 100644
index 0000000..aa1c8ac
--- /dev/null
+++ b/scribo/scribo/filter/paragraphs_bbox_overlap.hh
@@ -0,0 +1,176 @@
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena.  If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction.  Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License.  This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#ifndef SCRIBO_FILTER_PARAGRAPHS_BBOX_OVERLAP_HH
+# define SCRIBO_FILTER_PARAGRAPHS_BBOX_OVERLAP_HH
+
+/// \file
+///
+/// Remove invalid paragraphs.
+/// \fixme Share same test canvas as text::merging.
+
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/neighborhood.hh>
+# include <mln/core/concept/function.hh>
+# include <mln/core/image/dmorph/image_if.hh>
+# include <mln/data/transform.hh>
+# include <mln/util/array.hh>
+
+# include <scribo/core/paragraph_set.hh>
+
+
+namespace scribo
+{
+
+  namespace filter
+  {
+
+    using namespace mln;
+
+
+    /// Remove invalid paragraphs.
+    ///
+    /// \param[in] paragraphs    A paragraph set.
+    ///
+    /// \return A paragraph set with invalid paragraphs tag set to
+    /// Paragraph::Ignored.
+    template <typename L>
+    paragraph_set<L>
+    paragraphs_bbox_overlap(const paragraph_set<L>& paragraphs);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+    namespace internal
+    {
+
+      template <typename L>
+      struct order_paragraphs_id
+      {
+	order_paragraphs_id(const scribo::paragraph_set<L>& paragraphs)
+	  : paragraphs_(paragraphs)
+	{
+	}
+
+	bool operator()(const scribo::paragraph_id_t& l1,
+			const scribo::paragraph_id_t& l2) const
+	{
+	  const unsigned l1_nsites = paragraphs_(l1).bbox().nsites();
+	  const unsigned l2_nsites = paragraphs_(l2).bbox().nsites();
+
+	  if (l1_nsites == l2_nsites)
+	    return l1 > l2;
+	  return l1_nsites > l2_nsites;
+	}
+
+	scribo::paragraph_set<L> paragraphs_;
+      };
+
+    } // end of namespace scribo::filter::internal
+
+
+    template <typename L>
+    paragraph_set<L>
+    paragraphs_bbox_overlap(const paragraph_set<L>& paragraphs)
+    {
+      trace::entering("scribo::filter::paragraphs_bbox_overlap");
+
+      mln_precondition(paragraphs.is_valid());
+
+      L billboard;
+      initialize(billboard, paragraphs.lines().components().labeled_image());
+      data::fill(billboard, 0);
+
+      mln::util::array<bool> not_to_ignore(paragraphs.nelements() + 1, true);
+      not_to_ignore(0) = false;
+
+      for_all_paragraphs(cur_id, paragraphs)
+      {
+	const box2d& b_ = paragraphs(cur_id).bbox();
+
+	if (paragraphs(cur_id).nlines() > 1)
+	{
+	  mln::draw::box_plain(billboard, b_, cur_id);
+	  continue;
+	}
+
+	const unsigned tl = billboard(b_.pmin());
+	const unsigned tr = billboard.at_(b_.pmin().row(), b_.pmax().col());
+	const unsigned ml = billboard.at_(b_.pcenter().row(), b_.pmin().col());
+	const unsigned mc = billboard.at_(b_.pcenter().row(), b_.pcenter().col());
+	const unsigned mr = billboard.at_(b_.pcenter().row(), b_.pmax().col());
+	const unsigned bl = billboard.at_(b_.pmax().row(), b_.pmin().col());
+	const unsigned br = billboard(b_.pmax());
+
+	typedef std::set<unsigned> set_t;
+	set_t labels;
+	labels.insert(tl);
+	labels.insert(tl);
+	labels.insert(tr);
+	labels.insert(ml);
+	labels.insert(mc);
+	labels.insert(mr);
+	labels.insert(bl);
+	labels.insert(br);
+
+	for (set_t::const_iterator it = labels.begin();
+	     it != labels.end();
+	     ++it)
+	  if (not_to_ignore(*it))
+	  {
+	    box2d b2 = paragraphs(*it).bbox();
+	    box2d b_i = scribo::util::box_intersection(b_, b2);
+
+	    // si b_ est inclus dans une boite donc le nombre de comp > 1 => invalid juste b_
+	    // sinon => invalid b_ et b2
+	    if ((b_i.nsites() / (float)b_.nsites() > 0.4
+		 || (b_i.nsites() / (float)b2.nsites()) > 0.9))
+	    {
+	      not_to_ignore(cur_id) = false;
+
+	      if (paragraphs(*it).nlines() < 4)
+		not_to_ignore(*it) = false;
+	    }
+	  }
+
+	mln::draw::box_plain(billboard, b_, cur_id);
+      }
+
+      paragraph_set<L> output = paragraphs.duplicate();
+      output.invalidate(not_to_ignore);
+
+      trace::exiting("scribo::filter::paragraphs_bbox_overlap");
+      return output;
+    }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+  } // end of namespace scribo::filter
+
+} // end of namespace scribo
+
+#endif // ! SCRIBO_FILTER_PARAGRAPHS_BBOX_OVERLAP_HH
diff --git a/scribo/scribo/filter/paragraphs_in_image.hh b/scribo/scribo/filter/paragraphs_in_image.hh
new file mode 100644
index 0000000..1029430
--- /dev/null
+++ b/scribo/scribo/filter/paragraphs_in_image.hh
@@ -0,0 +1,129 @@
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena.  If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction.  Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License.  This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#ifndef SCRIBO_FILTER_PARAGRAPHS_IN_IMAGE_HH
+# define SCRIBO_FILTER_PARAGRAPHS_IN_IMAGE_HH
+
+/// \file
+///
+/// Remove invalid paragraphs.
+/// \fixme Share same test canvas as text::merging.
+
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/neighborhood.hh>
+# include <mln/core/concept/function.hh>
+# include <mln/core/image/dmorph/image_if.hh>
+
+# include <mln/data/transform.hh>
+
+# include <mln/util/array.hh>
+
+# include <mln/pw/all.hh>
+
+# include <scribo/core/paragraph_set.hh>
+# include <scribo/fun/v2b/objects_small_filter.hh>
+# include <scribo/primitive/extract/components.hh>
+
+
+namespace scribo
+{
+
+  namespace filter
+  {
+
+    using namespace mln;
+
+
+    /// Remove invalid paragraphs.
+    ///
+    /// \param[in] paragraphs    A paragraph set.
+    ///
+    /// \return A paragraph set with invalid paragraphs tag set to
+    /// Paragraph::Ignored.
+    template <typename L>
+    void
+    paragraphs_in_image(document<L>& doc);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+    template <typename L>
+    void
+    paragraphs_in_image(document<L>& doc)
+    {
+      trace::entering("scribo::filter::paragraphs_in_image");
+
+      mln_precondition(doc.has_elements());
+      mln_precondition(doc.has_text());
+
+      image2d<bool> billboard;
+      initialize(billboard, doc.lines().components().labeled_image());
+      data::fill(billboard, false);
+
+      // Draw Image bboxes.
+      for_all_elements(e, doc.elements())
+	if (doc.elements()(e).is_valid()
+	    && doc.elements()(e).type() == component::Image)
+	  mln::draw::box_plain(billboard, doc.elements()(e).bbox(), true);
+
+      mln::io::pbm::save(billboard, "billboard_parimage.pbm");
+
+      const paragraph_set<L>& parset = doc.paragraphs();
+      mln::util::array<bool> not_to_ignore(parset.nelements() + 1, true);
+      not_to_ignore(0) = false;
+
+      for_all_paragraphs(cur_id, parset)
+      {
+	const box2d& b_ = parset(cur_id).bbox();
+	const bool
+	  tl = billboard(b_.pmin()),
+	  tr = billboard.at_(b_.pmin().row(), b_.pmax().col()),
+	  ml = billboard.at_(b_.pcenter().row(), b_.pmin().col()),
+	  mc = billboard.at_(b_.pcenter().row(), b_.pcenter().col()),
+	  mr = billboard.at_(b_.pcenter().row(), b_.pmax().col()),
+	  bl = billboard.at_(b_.pmax().row(), b_.pmin().col()),
+	  br = billboard(b_.pmax());
+
+	// The paragraph is fully included in an image.
+	if (tl && tr && ml && mc && mr && bl && br)
+	  not_to_ignore(cur_id) = false;
+      }
+
+      paragraph_set<L> output = parset.duplicate();
+      output.invalidate(not_to_ignore);
+      doc.set_paragraphs(output);
+
+      trace::exiting("scribo::filter::paragraphs_in_image");
+    }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+  } // end of namespace scribo::filter
+
+} // end of namespace scribo
+
+#endif // ! SCRIBO_FILTER_PARAGRAPHS_IN_IMAGE_HH
diff --git a/scribo/scribo/filter/separators_in_element.hh b/scribo/scribo/filter/separators_in_element.hh
new file mode 100644
index 0000000..228d82f
--- /dev/null
+++ b/scribo/scribo/filter/separators_in_element.hh
@@ -0,0 +1,151 @@
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena.  If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction.  Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License.  This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#ifndef SCRIBO_FILTER_SEPARATORS_IN_ELEMENT_HH
+# define SCRIBO_FILTER_SEPARATORS_IN_ELEMENT_HH
+
+/// \file
+///
+/// Invalidate false positive separators.
+/// \fixme Share same test canvas as text::merging.
+
+
+# include <mln/core/concept/image.hh>
+# include <scribo/core/component_set.hh>
+# include <scribo/core/document.hh>
+
+
+namespace scribo
+{
+
+  namespace filter
+  {
+
+    using namespace mln;
+
+
+    /// Invalidate false positive separators.
+    ///
+    /// \param[in] separators    A paragraph set.
+    ///
+    /// \return A doc with invalidated separators.
+    ///
+    /// Warning: it does not remove separators from separator
+    /// image. It only invalidate separator components in their
+    /// respective component_set.
+    ///
+    template <typename L>
+    void
+    separators_in_element(document<L>& doc);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+    template <typename L>
+    void
+    separators_in_element(document<L>& doc)
+    {
+      trace::entering("scribo::filter::separators_in_element");
+
+      mln_precondition(doc.is_valid());
+      mln_precondition(doc.has_elements());
+      mln_precondition(doc.has_hline_seps() || doc.has_vline_seps());
+
+      if ((doc.has_hline_seps() && !doc.hline_seps_comps().nelements())
+	  && (doc.has_vline_seps() && !doc.vline_seps_comps().nelements()))
+	return;
+
+      mln_ch_value(L,bool) billboard;
+      initialize(billboard, doc.image());
+      data::fill(billboard, false);
+
+      for_all_comps(e, doc.elements())
+	if (doc.elements()(e).is_valid())
+	  mln::draw::box_plain(billboard, doc.elements()(e).bbox(), true);
+
+      // Horizontal separators
+      if (doc.has_hline_seps())
+      {
+	component_set<L> hline = doc.hline_seps_comps().duplicate();
+	for_all_comps(c, hline)
+	{
+	  const mln_box(L)& b_ = hline(c).bbox();
+
+	  const bool tl = billboard(b_.pmin());
+	  const bool tr = billboard.at_(b_.pmin().row(), b_.pmax().col());
+	  const bool ml = billboard.at_(b_.pcenter().row(), b_.pmin().col());
+	  const bool mc = billboard.at_(b_.pcenter().row(), b_.pcenter().col());
+	  const bool mr = billboard.at_(b_.pcenter().row(), b_.pmax().col());
+	  const bool bl = billboard.at_(b_.pmax().row(), b_.pmin().col());
+	  const bool br = billboard(b_.pmax());
+
+	  // This separator is included in an element (picture, drawing...)
+	  // => Ignore it.
+	  if (tl && tr && ml && mc && mr && bl && br)
+	    hline(c).update_tag(component::Ignored);
+
+	  // FIXME: warning this call may produce inconsistent data
+	  // Ignored components are still in the separator image...
+	  doc.set_hline_separators(doc.hline_seps(), hline);
+	}
+      }
+
+      // Vertical separators
+      if (doc.has_vline_seps())
+      {
+	component_set<L> vline = doc.vline_seps_comps().duplicate();
+	for_all_comps(c, vline)
+	{
+	  const mln_box(L)& b_ = vline(c).bbox();
+
+	  const bool tl = billboard(b_.pmin());
+	  const bool tr = billboard.at_(b_.pmin().row(), b_.pmax().col());
+	  const bool ml = billboard.at_(b_.pcenter().row(), b_.pmin().col());
+	  const bool mc = billboard.at_(b_.pcenter().row(), b_.pcenter().col());
+	  const bool mr = billboard.at_(b_.pcenter().row(), b_.pmax().col());
+	  const bool bl = billboard.at_(b_.pmax().row(), b_.pmin().col());
+	  const bool br = billboard(b_.pmax());
+
+	  // This separator is included in an element (picture, drawing...)
+	  // => Ignore it.
+	  if (tl && tr && ml && mc && mr && bl && br)
+	    vline(c).update_tag(component::Ignored);
+
+	  // FIXME: warning this call may produce inconsistent data
+	  // Ignored components are still in the separator image...
+	  doc.set_vline_separators(doc.vline_seps(), vline);
+	}
+
+	trace::exiting("scribo::filter::separators_in_element");
+      }
+    }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+  } // end of namespace scribo::filter
+
+} // end of namespace scribo
+
+#endif // ! SCRIBO_FILTER_SEPARATORS_IN_ELEMENT_HH
diff --git a/scribo/scribo/filter/separators_in_paragraph.hh b/scribo/scribo/filter/separators_in_paragraph.hh
new file mode 100644
index 0000000..3e7a150
--- /dev/null
+++ b/scribo/scribo/filter/separators_in_paragraph.hh
@@ -0,0 +1,151 @@
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena.  If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction.  Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License.  This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#ifndef SCRIBO_FILTER_SEPARATORS_IN_PARAGRAPHS_HH
+# define SCRIBO_FILTER_SEPARATORS_IN_PARAGRAPH_HH
+
+/// \file
+///
+/// Invalidate false positive separators.
+/// \fixme Share same test canvas as text::merging.
+
+
+# include <mln/core/concept/image.hh>
+# include <scribo/core/component_set.hh>
+# include <scribo/core/document.hh>
+
+
+namespace scribo
+{
+
+  namespace filter
+  {
+
+    using namespace mln;
+
+
+    /// Invalidate false positive separators.
+    ///
+    /// \param[in] separators    A paragraph set.
+    ///
+    /// \return A doc with invalidated separators.
+    ///
+    /// Warning: it does not remove separators from separator
+    /// image. It only invalidate separator components in their
+    /// respective component_set.
+    ///
+    template <typename L>
+    void
+    separators_in_paragraph(document<L>& doc);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+    template <typename L>
+    void
+    separators_in_paragraph(document<L>& doc)
+    {
+      trace::entering("scribo::filter::separators_in_paragraph");
+
+      mln_precondition(doc.is_valid());
+      mln_precondition(doc.has_elements());
+      mln_precondition(doc.has_hline_seps() || doc.has_vline_seps());
+
+      if ((doc.has_hline_seps() && !doc.hline_seps_comps().nelements())
+	  && (doc.has_vline_seps() && !doc.vline_seps_comps().nelements()))
+	return;
+
+      mln_ch_value(L,bool) billboard;
+      initialize(billboard, doc.image());
+      data::fill(billboard, false);
+
+      for_all_comps(p, doc.paragraphs())
+	if (doc.paragraphs()(p).is_valid())
+	  mln::draw::box_plain(billboard, doc.paragraphs()(p).bbox(), true);
+
+      // Horizontal separators
+      if (doc.has_hline_seps())
+      {
+	component_set<L> hline = doc.hline_seps_comps().duplicate();
+	for_all_comps(c, hline)
+	{
+	  const mln_box(L)& b_ = hline(c).bbox();
+
+	  const bool tl = billboard(b_.pmin());
+	  const bool tr = billboard.at_(b_.pmin().row(), b_.pmax().col());
+	  const bool ml = billboard.at_(b_.pcenter().row(), b_.pmin().col());
+	  const bool mc = billboard.at_(b_.pcenter().row(), b_.pcenter().col());
+	  const bool mr = billboard.at_(b_.pcenter().row(), b_.pmax().col());
+	  const bool bl = billboard.at_(b_.pmax().row(), b_.pmin().col());
+	  const bool br = billboard(b_.pmax());
+
+	  // This separator is included in an element (picture, drawing...)
+	  // => Ignore it.
+	  if (tl && tr && ml && mc && mr && bl && br)
+	    hline(c).update_tag(component::Ignored);
+
+	  // FIXME: warning this call may produce inconsistent data
+	  // Ignored components are still in the separator image...
+	  doc.set_hline_separators(doc.hline_seps(), hline);
+	}
+      }
+
+      // Vertical separators
+      if (doc.has_vline_seps())
+      {
+	component_set<L> vline = doc.vline_seps_comps().duplicate();
+	for_all_comps(c, vline)
+	{
+	  const mln_box(L)& b_ = vline(c).bbox();
+
+	  const bool tl = billboard(b_.pmin());
+	  const bool tr = billboard.at_(b_.pmin().row(), b_.pmax().col());
+	  const bool ml = billboard.at_(b_.pcenter().row(), b_.pmin().col());
+	  const bool mc = billboard.at_(b_.pcenter().row(), b_.pcenter().col());
+	  const bool mr = billboard.at_(b_.pcenter().row(), b_.pmax().col());
+	  const bool bl = billboard.at_(b_.pmax().row(), b_.pmin().col());
+	  const bool br = billboard(b_.pmax());
+
+	  // This separator is included in an element (picture, drawing...)
+	  // => Ignore it.
+	  if (tl && tr && ml && mc && mr && bl && br)
+	    vline(c).update_tag(component::Ignored);
+
+	  // FIXME: warning this call may produce inconsistent data
+	  // Ignored components are still in the separator image...
+	  doc.set_vline_separators(doc.vline_seps(), vline);
+	}
+
+	trace::exiting("scribo::filter::separators_in_paragraph");
+      }
+    }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+  } // end of namespace scribo::filter
+
+} // end of namespace scribo
+
+#endif // ! SCRIBO_FILTER_SEPARATORS_IN_PARAGRAPH_HH
-- 
1.5.6.5
                    
                  
                  
                          
                            
                            1
                            
                          
                          
                            
                            0
                            
                          
                          
                            
    
                          
                        
                    
                    
                        	* scribo/util/box_intersection.hh: New.
	* scribo/filter/object_links_bbox_overlap.hh: Make use of this new
	routine.
---
 scribo/ChangeLog                                   |    9 +++
 scribo/scribo/filter/object_links_bbox_overlap.hh  |   25 ++--------
 .../util/{color_to_hex.hh => box_intersection.hh}  |   53 +++++++++++---------
 3 files changed, 43 insertions(+), 44 deletions(-)
 copy scribo/scribo/util/{color_to_hex.hh => box_intersection.hh} (56%)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 3c70e89..959746f 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,14 @@
 2011-05-26  Guillaume Lazzara  <z(a)lrde.epita.fr>
 
+	Add util::box_intersection.
+
+	* scribo/util/box_intersection.hh: New.
+
+	* scribo/filter/object_links_bbox_overlap.hh: Make use of this new
+	routine.
+
+2011-05-26  Guillaume Lazzara  <z(a)lrde.epita.fr>
+
 	Various small fixes in Scribo.
 
 	* scribo/core/paragraph_info.hh: Add validity information.
diff --git a/scribo/scribo/filter/object_links_bbox_overlap.hh b/scribo/scribo/filter/object_links_bbox_overlap.hh
index a93d849..29b71ba 100644
--- a/scribo/scribo/filter/object_links_bbox_overlap.hh
+++ b/scribo/scribo/filter/object_links_bbox_overlap.hh
@@ -41,6 +41,7 @@
 # include <scribo/core/object_links.hh>
 # include <scribo/core/component_set.hh>
 # include <scribo/filter/object_links_bbox_ratio.hh>
+# include <scribo/util/box_intersection.hh>
 
 namespace scribo
 {
@@ -80,32 +81,14 @@ namespace scribo
       const component_set<L>& components = links.components();
       object_links<L> output = links.duplicate();
 
-      bool has_intersection;
-      mln_site(L) pmin, pmax;
       float ratio_i, ratio_link_i;
 
       for_all_links(i, links)
 	if (links.is_linked(i))
 	{
-	  has_intersection = true;
-	  for (unsigned dim = 0; dim < mln_site_(L)::dim; ++dim)
-	  {
-	    pmin[dim] = math::max(components(i).bbox().pmin()[dim],
-				  components(links(i)).bbox().pmin()[dim]);
-	    pmax[dim] = math::min(components(i).bbox().pmax()[dim],
-				  components(links(i)).bbox().pmax()[dim]);
-
-	    if (pmin[dim] > pmax[dim])
-	    {
-	      has_intersection = false;
-	      break;
-	    }
-	  }
-
-	  if (!has_intersection)
-	    continue;
-
-	  mln_box(L) interbbox(pmin, pmax);
+	  mln_box(L)
+	    interbbox = scribo::util::box_intersection(components(i).bbox(),
+						       components(links(i)).bbox());
 
 	  ratio_i = interbbox.nsites() /(float)components(i).bbox().nsites();
 	  ratio_link_i = interbbox.nsites() /(float)components(links(i)).bbox().nsites();
diff --git a/scribo/scribo/util/color_to_hex.hh b/scribo/scribo/util/box_intersection.hh
similarity index 56%
copy from scribo/scribo/util/color_to_hex.hh
copy to scribo/scribo/util/box_intersection.hh
index e0ee33f..f090233 100644
--- a/scribo/scribo/util/color_to_hex.hh
+++ b/scribo/scribo/util/box_intersection.hh
@@ -23,18 +23,17 @@
 // exception does not however invalidate any other reasons why the
 // executable file might be covered by the GNU General Public License.
 
-#ifndef SCRIBO_UTIL_COLOR_TO_HEX_HH
-# define SCRIBO_UTIL_COLOR_TO_HEX_HH
+#ifndef SCRIBO_UTIL_BOX_INTERSECTION_HH
+# define SCRIBO_UTIL_BOX_INTERSECTION_HH
 
 /// \file
 ///
-/// Convert hexadecimal encoded colors to value::rgb8.
+/// Return the box corresponding to the intersection of two boxes.
 
 
-#include <cstdio>
-#include <iostream>
-#include <string.h>
-#include <mln/value/rgb8.hh>
+#include <mln/core/site_set/box.hh>
+#include <mln/math/min.hh>
+#include <mln/math/max.hh>
 
 namespace scribo
 {
@@ -43,30 +42,38 @@ namespace scribo
   {
     using namespace mln;
 
-    std::string color_to_hex(const value::rgb8& v);
+    /// \brief Return the box corresponding to the intersection of two
+    /// boxes.
+    ///
+    /// \return An invalid box if there is no intersection. The box
+    /// corresponding to the intersection, otherwise.
+    template <typename P>
+    box<P>
+    box_intersection(const box<P>& lhs, const box<P>& rhs);
 
 
 # ifndef MLN_INCLUDE_ONLY
 
-    std::string color_to_hex(const value::rgb8& v)
+    template <typename P>
+    box<P>
+    box_intersection(const box<P>& lhs, const box<P>& rhs)
     {
-      std::string result = "#";
+      trace::entering("scribo::util::box_intersection");
 
-      char buf[3];
+      P pmin, pmax;
+      for (unsigned dim = 0; dim < P::dim; ++dim)
+      {
+	pmin[dim] = math::max(lhs.pmin()[dim], rhs.pmin()[dim]);
+	pmax[dim] = math::min(lhs.pmax()[dim], rhs.pmax()[dim]);
 
-      int c = v.red();
-      sprintf(buf, "%.2X", c);
-      result.append(buf);
+	if (pmin[dim] > pmax[dim]) // No intersection.
+	  return box<P>();
+      }
 
-      c = v.green();
-      sprintf(buf, "%.2X", c);
-      result.append(buf);
+      box<P> output(pmin, pmax);
 
-      c = v.blue();
-      sprintf(buf, "%.2X", c);
-      result.append(buf);
-
-      return result;
+      trace::exiting("scribo::util::box_intersection");
+      return output;
     }
 
 # endif // ! MLN_INCLUDE_ONLY
@@ -75,4 +82,4 @@ namespace scribo
 
 } // end of namespace scribo
 
-#endif // ! SCRIBO_UTIL_COLOR_TO_HEX_HH
+#endif // ! SCRIBO_UTIL_BOX_INTERSECTION_HH
-- 
1.5.6.5
                    
                  
                  
                          
                            
                            1
                            
                          
                          
                            
                            0
                            
                          
                          
                            
    
                          
                        
                    
                    
                        ---
 milena/ChangeLog                              |    4 ++
 milena/mln/draw/{box_plain.hh => site_set.hh} |   58 +++++++++++-------------
 2 files changed, 31 insertions(+), 31 deletions(-)
 copy milena/mln/draw/{box_plain.hh => site_set.hh} (61%)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index e8430cd..8ea11b0 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,7 @@
+2011-05-26  Guillaume Lazzara  <z(a)lrde.epita.fr>
+
+	* mln/draw/site_set.hh: new.
+
 2011-05-17  Guillaume Lazzara  <z(a)lrde.epita.fr>
 
 	Add new sample programs.
diff --git a/milena/mln/draw/box_plain.hh b/milena/mln/draw/site_set.hh
similarity index 61%
copy from milena/mln/draw/box_plain.hh
copy to milena/mln/draw/site_set.hh
index ec5b865..1738b16 100644
--- a/milena/mln/draw/box_plain.hh
+++ b/milena/mln/draw/site_set.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
 //
 // This file is part of Olena.
 //
@@ -23,23 +23,17 @@
 // exception does not however invalidate any other reasons why the
 // executable file might be covered by the GNU General Public License.
 
-#ifndef MLN_DRAW_BOX_PLAIN_HH
-# define MLN_DRAW_BOX_PLAIN_HH
+#ifndef MLN_DRAW_SITE_SET_HH
+# define MLN_DRAW_SITE_SET_HH
 
 /*! \file
  *
- * \brief Draw a plain box in an image.
+ * \brief Draw a site set in an image.
  *
- * \fixme Rename as box.hh
  */
 
 # include <mln/core/concept/image.hh>
-# include <mln/core/alias/box2d.hh>
-# include <mln/data/fill.hh>
-# include <mln/draw/line.hh>
-# include <mln/pw/image.hh>
-# include <mln/pw/cst.hh>
-
+# include <mln/core/concept/site_set.hh>
 
 namespace mln
 {
@@ -47,39 +41,41 @@ namespace mln
   namespace draw
   {
 
-    /*! Draw a plain box at value \p v in image \p ima
+    /*! Draw a sites with value \p v in image \p ima
      *
      * \param[in,out] ima The image to be drawn.
-     * \param[in] b the box to draw.
+     * \param[in] b the site set to draw.
      * \param[in] v The value to assign to all drawn pixels.
+     * \param[in] output_ratio size ratio between output image and the
+     * image from which the bboxes were calculated.
      *
-     * \pre \p ima has to be initialized.
-     * \pre \p ima has \p beg.
-     * \pre \p ima has \p end.
+     * \pre \p s is included in \p ima domain.
      *
      */
-    template <typename I, typename B>
-    void box_plain(Image<I>& ima,
-		   const Box<B>& b,
-		   const mln_value(I)& v);
+    template <typename I, typename S>
+    void site_set(Image<I>& ima,
+		  const Site_Set<S>& s,
+		  const mln_value(I)& v,
+		  unsigned output_ratio = 1);
 
 
 # ifndef MLN_INCLUDE_ONLY
 
-    template <typename I, typename B>
-    inline
-    void box_plain(Image<I>& ima,
-		   const Box<B>& b,
-		   const mln_value(I)& v)
+    template <typename I, typename S>
+    void site_set(Image<I>& ima_,
+		  const Site_Set<S>& s_,
+		  const mln_value(I)& v,
+		  unsigned output_ratio)
     {
       mln_precondition(exact(ima).is_valid());
+      mln_precondition(exact(ima).domain() >= exact(s));
 
-      mln_psite(I) pmin = exact(b).pmin();
-      mln_psite(I) pmax = exact(b).pmax();
-
-      mln_precondition(exact(ima).has(pmin) && exact(ima).has(pmax));
+      I& ima = exact(ima_);
+      const S& s = exact(s_);
 
-      data::fill((ima | b).rw(), v);
+      mln_piter(S) p(s);
+      for_all(p)
+	ima(p / output_ratio) = v;
     }
 
 # endif // ! MLN_INCLUDE_ONLY
@@ -89,4 +85,4 @@ namespace mln
 } // end of namespace mln
 
 
-#endif // ! MLN_DRAW_BOX_PLAIN_HH
+#endif // ! MLN_DRAW_SITE_SET_HH
-- 
1.5.6.5
                    
                  
                  
                          
                            
                            1
                            
                          
                          
                            
                            0