* core/component_info.hh (is_valid): Check the bounding box
validity.
* core/macros.hh: Add a new macro.
* debug/decision_image.hh: Remove deprecated preconditions and add
missing includes.
* debug/save_linked_bboxes_image.hh: Add the anchor type as
argument.
* draw/bounding_box_links.hh: Add the anchor type as argument and
make use of component information.
* draw/bounding_boxes.hh: Check the component validity.
* filter/object_links_non_aligned_simple.hh: Update doc.
* filter/objects_with_holes.hh: Remove debug and timers. Add
missing includes.
* primitive/extract/lines_pattern.hh: Use the window template
parameter instead of an exact window type.
* primitive/link/internal/find_several_links.hh: Update code with
new interfaces.
* primitive/link/internal/link_functor_base.hh
(nanchors()): Remove this method.
(labeled_image()): Add a const version.
* primitive/link/internal/link_several_dmax_base.hh
(nanchors(), anchors()): New methods.
Introduce 'direction_' attribute.
* debug/several_links_decision_image.hh: Remove deprecated
preconditions.
* src/debug/show_links_single_left.cc: Update include.
* table/internal/align_lines.hh,
* table/rebuild.hh: Make use of component_set structure.
* debug/text_areas_image.hh,
* primitive/regroup/from_single_left_link_wrt_h_ratio.hh: Add
missing includes.
* src/contest/hdibco-2010/Makefile.am: Do not consider this tool
as a test anymore.
---
scribo/ChangeLog | 48 ++++++
scribo/core/component_info.hh | 2 +-
scribo/core/macros.hh | 3 +
scribo/debug/decision_image.hh | 21 ++-
scribo/debug/save_linked_bboxes_image.hh | 82 ++++------
scribo/debug/several_links_decision_image.hh | 3 +-
scribo/debug/text_areas_image.hh | 3 +-
scribo/draw/bounding_box_links.hh | 140 +++++------------
scribo/draw/bounding_boxes.hh | 5 +-
scribo/filter/object_links_non_aligned_simple.hh | 3 +-
scribo/filter/objects_with_holes.hh | 162 +++-----------------
scribo/primitive/extract/lines_pattern.hh | 3 +-
.../primitive/link/internal/find_several_links.hh | 6 +-
.../primitive/link/internal/link_functor_base.hh | 45 ++----
.../link/internal/link_several_dmax_base.hh | 93 +++++++----
.../regroup/from_single_left_link_wrt_h_ratio.hh | 6 +-
scribo/src/contest/hdibco-2010/Makefile.am | 4 +-
scribo/src/debug/show_links_single_left.cc | 2 +-
scribo/table/internal/align_lines.hh | 55 ++++---
scribo/table/rebuild.hh | 75 +++++-----
20 files changed, 317 insertions(+), 444 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index e0da752..2d5510a 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,53 @@
2010-08-09 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Small fixes in Scribo.
+
+ * core/component_info.hh (is_valid): Check the bounding box
+ validity.
+
+ * core/macros.hh: Add a new macro.
+
+ * debug/decision_image.hh: Remove deprecated preconditions and add
+ missing includes.
+
+ * draw/bounding_boxes.hh: Check the component validity.
+
+ * filter/object_links_non_aligned_simple.hh: Update doc.
+
+ * filter/objects_with_holes.hh: Remove debug and timers. Add
+ missing includes.
+
+ * primitive/extract/lines_pattern.hh: Use the window template
+ parameter instead of an exact window type.
+
+ * primitive/link/internal/find_several_links.hh: Update code with
+ new interfaces.
+
+ * primitive/link/internal/link_functor_base.hh
+ (nanchors()): Remove this method.
+ (labeled_image()): Add a const version.
+
+ * primitive/link/internal/link_several_dmax_base.hh
+ (nanchors(), anchors()): New methods.
+ Introduce 'direction_' attribute.
+
+ * debug/several_links_decision_image.hh: Remove deprecated
+ preconditions.
+
+ * src/debug/show_links_single_left.cc: Update include.
+
+ * table/internal/align_lines.hh,
+ * table/rebuild.hh: Make use of component_set structure.
+
+ * debug/text_areas_image.hh,
+ * primitive/regroup/from_single_left_link_wrt_h_ratio.hh: Add
+ missing includes.
+
+ * src/contest/hdibco-2010/Makefile.am: Do not consider this tool
+ as a test anymore.
+
+2010-08-09 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Add missing includes and headers in AFP's dedicated code.
* src/afp/components.hh,
diff --git a/scribo/core/component_info.hh b/scribo/core/component_info.hh
index 4ee438c..56f7799 100644
--- a/scribo/core/component_info.hh
+++ b/scribo/core/component_info.hh
@@ -176,7 +176,7 @@ namespace scribo
bool
component_info::is_valid() const
{
- return tag_ != component::Ignored;
+ return tag_ != component::Ignored && bbox_.is_valid();
}
diff --git a/scribo/core/macros.hh b/scribo/core/macros.hh
index 040220c..07a101a 100644
--- a/scribo/core/macros.hh
+++ b/scribo/core/macros.hh
@@ -58,4 +58,7 @@
# define for_all_lines_info(E, S) \
for_all_comp_data(E, S)
+# define for_all_anchors(E, S) \
+ for_all_elements(E, S)
+
#endif // ! SCRIBO_CORE_MACROS_HH
diff --git a/scribo/debug/decision_image.hh b/scribo/debug/decision_image.hh
index 7f881d3..1bf2643 100644
--- a/scribo/debug/decision_image.hh
+++ b/scribo/debug/decision_image.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -35,9 +36,12 @@
# include <mln/value/rgb8.hh>
# include <mln/literal/colors.hh>
# include <mln/util/array.hh>
+# include <mln/draw/box.hh>
+# include <mln/draw/line.hh>
+# include <scribo/core/tag/anchor.hh>
# include <scribo/core/object_groups.hh>
-# include <scribo/draw/bounding_boxes.hh>
+# include <scribo/primitive/link/internal/compute_anchor.hh>
namespace scribo
@@ -105,8 +109,6 @@ namespace scribo
mln_precondition(input.is_valid());
mln_precondition(groups.is_valid());
mln_precondition(filtered_groups.is_valid());
- mln_precondition(groups.size() == filtered_groups.size());
- mln_precondition(groups.components_id_() != filtered_groups.components_id_());
/// Fixme: check that components has been computed from input.
image2d<value::rgb8>
@@ -114,9 +116,11 @@ namespace scribo
for (unsigned i = 1; i < groups.size(); ++i)
if (groups(i) != filtered_groups(i))
- mln::draw::box(decision_image, components(i).bbox(), literal::red);
+ mln::draw::box(decision_image, components(i).bbox(),
+ literal::red);
else
- mln::draw::box(decision_image, components(i).bbox(), literal::green);
+ mln::draw::box(decision_image, components(i).bbox(),
+ literal::green);
trace::exiting("scribo::debug::decision_image");
return decision_image;
@@ -138,8 +142,6 @@ namespace scribo
mln_precondition(input.is_valid());
mln_precondition(links.is_valid());
mln_precondition(filtered_links.is_valid());
- mln_precondition(links.size() == filtered_links.size());
- mln_precondition(links.object_image_() != filtered_links.object_image_());
/// Fixme: check that components has been computed from input.
image2d<value::rgb8>
@@ -155,7 +157,8 @@ namespace scribo
{
mln_site(L)
p1 = primitive::link::internal::compute_anchor(comps, i, anchor),
- p2 = primitive::link::internal::compute_anchor(comps, links(i), anchor);
+ p2 = primitive::link::internal::compute_anchor(comps, links(i),
+ anchor);
value::rgb8 value = literal::green;
if (links(i) != filtered_links(i))
diff --git a/scribo/debug/save_linked_bboxes_image.hh
b/scribo/debug/save_linked_bboxes_image.hh
index ef70435..d4c940a 100644
--- a/scribo/debug/save_linked_bboxes_image.hh
+++ b/scribo/debug/save_linked_bboxes_image.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -38,6 +39,7 @@
# include <mln/value/rgb8.hh>
# include <mln/util/array.hh>
# include <mln/io/ppm/save.hh>
+# include <mln/literal/colors.hh>
# include <scribo/core/object_links.hh>
# include <scribo/core/component_set.hh>
@@ -57,7 +59,6 @@ namespace scribo
/// Save the line of components links image.
///
/// \param[in,out] input The binary from where the components are extracted.
- /// \param[in] components An object image.
/// \param[in] link_array Lines of components links.
/// \param[in] box_value Value used to draw line bounding boxes.
/// \param[in] link_value Value used to draw line links.
@@ -67,12 +68,11 @@ namespace scribo
template <typename I, typename L>
void
save_linked_bboxes_image(const Image<I>& input,
- const component_set<L>& components,
const object_links<L>& array,
const value::rgb8& box_value,
const value::rgb8& link_value,
- const std::string& filename,
- anchor::Type anchor);
+ anchor::Type anchor,
+ const std::string& filename);
/// \overload
/// The default anchor type is set to anchor::Center.
@@ -80,7 +80,6 @@ namespace scribo
template <typename I, typename L>
void
save_linked_bboxes_image(const Image<I>& input,
- const component_set<L>& components,
const object_links<L>& array,
const value::rgb8& box_value,
const value::rgb8& link_value,
@@ -89,7 +88,6 @@ namespace scribo
/// Save the line of components left and right links image.
///
/// \param[in,out] input The binary from where the components are extracted.
- /// \param[in] components An object image.
/// \param[in] left_link Lines of components left links.
/// \param[in] right_link Lines of components right links.
/// \param[in] box_value Value used to draw line bounding boxes.
@@ -98,18 +96,17 @@ namespace scribo
template <typename I, typename L>
void
save_linked_bboxes_image(const Image<I>& input,
- const component_set<L>& components,
const object_links<L>& left_link,
const object_links<L>& right_link,
const value::rgb8& box_value,
const value::rgb8& link_value,
+ anchor::Type anchor,
const std::string& filename);
/// Save the line of components left and right links image.
/// Draw also validated links.
///
/// \param[in,out] input The binary from where the components are extracted.
- /// \param[in] components An object image.
/// \param[in] left_link Lines of components left links.
/// \param[in] right_link Lines of components right links.
/// \param[in] box_value Value used to draw line bounding boxes.
@@ -121,20 +118,19 @@ namespace scribo
inline
void
save_linked_bboxes_image(const Image<I>& input,
- const component_set<L>& components,
const object_links<L>& left_link,
const object_links<L>& right_link,
const value::rgb8& box_value,
const value::rgb8& left_link_value,
const value::rgb8& right_link_value,
const value::rgb8& validated_link_value,
+ anchor::Type anchor,
const std::string& filename);
/// Save the line link graph image.
///
/// \param[in,out] input The binary from where the components are extracted.
- /// \param[in] components An object image.
/// \param[in] g The link graph.
/// \param[in] box_value Value used to draw line bounding boxes.
/// \param[in] link_value Value used to draw line links.
@@ -142,10 +138,10 @@ namespace scribo
template <typename I, typename L, typename G>
void
save_linked_bboxes_image(const Image<I>& input,
- const component_set<L>& components,
const Graph<G>& g,
const value::rgb8& box_value,
const value::rgb8& link_value,
+ anchor::Type anchor,
const std::string& filename);
@@ -156,20 +152,19 @@ namespace scribo
inline
void
save_linked_bboxes_image(const Image<I>& input,
- const component_set<L>& components,
- const object_links<L>& array,
+ const object_links<L>& links,
const value::rgb8& box_value,
const value::rgb8& link_value,
- const std::string& filename,
- anchor::Type anchor)
+ anchor::Type anchor,
+ const std::string& filename)
{
trace::entering("scribo::debug::save_linked_bboxes_image");
mln_precondition(exact(input).is_valid());
mln_ch_value(I,value::rgb8) tmp = data::convert(value::rgb8(), input);
- draw::bounding_boxes(tmp, components, box_value);
- draw::bounding_box_links(tmp, array, link_value, anchor);
+ draw::bounding_boxes(tmp, links.components(), box_value);
+ draw::bounding_box_links(tmp, links, link_value, anchor);
mln::io::ppm::save(tmp, filename);
@@ -181,14 +176,13 @@ namespace scribo
inline
void
save_linked_bboxes_image(const Image<I>& input,
- const component_set<L>& components,
- const object_links<L>& array,
+ const object_links<L>& links,
const value::rgb8& box_value,
const value::rgb8& link_value,
const std::string& filename)
{
- save_linked_bboxes_image(input, components, array, box_value,
- link_value, filename, anchor::Center);
+ save_linked_bboxes_image(input, links, box_value,
+ link_value, anchor::Center, filename);
}
@@ -197,26 +191,21 @@ namespace scribo
inline
void
save_linked_bboxes_image(const Image<I>& input,
- const component_set<L>& components,
const object_links<L>& left_link,
const object_links<L>& right_link,
const value::rgb8& box_value,
const value::rgb8& value,
const std::string& filename)
{
- trace::entering("scribo::debug::save_linked_bboxes_image");
- mln_precondition(exact(input).is_valid());
-
- mln_ch_value(I,value::rgb8) tmp = data::convert(value::rgb8(), input);
-
- draw::bounding_boxes(tmp, components, box_value);
- draw::bounding_box_links(tmp, components.mass_centers(),
- left_link, right_link,
- value);
-
- mln::io::ppm::save(tmp, filename);
-
- trace::exiting("scribo::debug::save_linked_bboxes_image");
+ save_linked_bboxes_image(input,
+ left_link,
+ right_link,
+ box_value,
+ literal::yellow,
+ literal::cyan,
+ value,
+ anchor::Center,
+ filename);
}
@@ -224,13 +213,13 @@ namespace scribo
inline
void
save_linked_bboxes_image(const Image<I>& input,
- const component_set<L>& components,
const object_links<L>& left_link,
const object_links<L>& right_link,
const value::rgb8& box_value,
const value::rgb8& left_link_value,
const value::rgb8& right_link_value,
const value::rgb8& validated_link_value,
+ anchor::Type anchor,
const std::string& filename)
{
trace::entering("scribo::debug::save_linked_bboxes_image");
@@ -238,16 +227,12 @@ namespace scribo
mln_ch_value(I,value::rgb8) tmp = data::convert(value::rgb8(), input);
- mln::util::array<mln_result(accu::center<mln_psite(L)>)>
- mass_center = labeling::compute(accu::meta::center(),
- components.labeled_image(),
- components.nelements());
-
- draw::bounding_boxes(tmp, components, box_value);
- draw::bounding_box_links(tmp, mass_center,
+ draw::bounding_boxes(tmp, left_link.components(), box_value);
+ draw::bounding_box_links(tmp,
left_link, right_link,
left_link_value, right_link_value,
- validated_link_value);
+ validated_link_value,
+ anchor);
mln::io::ppm::save(tmp, filename);
@@ -260,10 +245,10 @@ namespace scribo
inline
void
save_linked_bboxes_image(const Image<I>& input,
- const component_set<L>& components,
const Graph<G>& g,
const value::rgb8& box_value,
const value::rgb8& link_value,
+ anchor::Type anchor,
const std::string& filename)
{
trace::entering("scribo::debug::save_linked_bboxes_image");
@@ -272,8 +257,9 @@ namespace scribo
mln_ch_value(I,value::rgb8) tmp = data::convert(value::rgb8(), input);
- draw::bounding_boxes(tmp, components, box_value);
- draw::bounding_box_links(tmp, components, g, link_value);
+ draw::bounding_boxes(tmp, exact(g).components(), box_value);
+ draw::bounding_box_links(tmp, exact(g).components(), g, link_value,
+ anchor);
mln::io::ppm::save(tmp, filename);
diff --git a/scribo/debug/several_links_decision_image.hh
b/scribo/debug/several_links_decision_image.hh
index ca70d44..3446287 100644
--- a/scribo/debug/several_links_decision_image.hh
+++ b/scribo/debug/several_links_decision_image.hh
@@ -100,8 +100,7 @@ namespace scribo
mln_precondition(objects.is_valid());
mln_precondition(links.is_valid());
mln_precondition(filtered_links.is_valid());
- mln_precondition(links.size() == filtered_links.size());
- mln_precondition(links.object_image_() != filtered_links.object_image_());
+
/// Fixme: check that objects has been computed from input.
image2d<value::rgb8>
diff --git a/scribo/debug/text_areas_image.hh b/scribo/debug/text_areas_image.hh
index f6a2f0f..eab208d 100644
--- a/scribo/debug/text_areas_image.hh
+++ b/scribo/debug/text_areas_image.hh
@@ -45,8 +45,9 @@
# include <mln/math/max.hh>
-# include <scribo/core/component_set.hh>
+# include <mln/literal/black.hh>
+# include <scribo/core/component_set.hh>
namespace scribo
{
diff --git a/scribo/draw/bounding_box_links.hh b/scribo/draw/bounding_box_links.hh
index 2ee5173..f2c9804 100644
--- a/scribo/draw/bounding_box_links.hh
+++ b/scribo/draw/bounding_box_links.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -77,32 +78,9 @@ namespace scribo
/// Draw left, right and validated lists of bounding box links.
- /// Draw from the bounding box centers.
+ /// Draw from anchors.
///
/// \param[in,out] input_ An image where to draw.
- /// \param[in] bboxes Bounding boxes.
- /// \param[in] left_link Bounding box left links.
- /// \param[in] right_link Bounding box right links.
- /// \param[in] left_link_value Value used to draw left links.
- /// \param[in] right_link_value Value used to draw right links.
- /// \param[in] validated_link_value Value used to draw validated links.
- template <typename I, typename L>
- inline
- void
- bounding_box_links(Image<I>& input_,
- const mln::util::array< box<mln_site(I)> >& bboxes,
- const object_links<L>& left_link,
- const object_links<L>& right_link,
- const mln_value(I)& left_link_value,
- const mln_value(I)& right_link_value,
- const mln_value(I)& validated_link_value);
-
-
- /// Draw left, right and validated lists of bounding box links.
- /// Draw from the bounding box mass centers.
- ///
- /// \param[in,out] input_ An image where to draw.
- /// \param[in] mass_centers Bounding box mass centers.
/// \param[in] left_link Bounding box left links.
/// \param[in] right_link Bounding box right links.
/// \param[in] left_link_value Value used to draw left links.
@@ -112,12 +90,12 @@ namespace scribo
inline
void
bounding_box_links(Image<I>& input_,
- const mln::util::array<mln_site(I)::vec>& mass_centers,
const object_links<L>& left_link,
const object_links<L>& right_link,
const mln_value(I)& left_link_value,
const mln_value(I)& right_link_value,
- const mln_value(I)& validated_link_value);
+ const mln_value(I)& validated_link_value,
+ anchor::Type anchor);
/// Draw a graph of bounding box links.
@@ -131,7 +109,6 @@ namespace scribo
inline
void
bounding_box_links(Image<I>& input_,
- const mln::util::array< box<mln_site(I)> >& bboxes,
const Graph<G>& g_,
const mln_value(I)& link_value);
@@ -155,28 +132,28 @@ namespace scribo
/// Draw a link graph in an image.
/// Functor to be passed to depth_first_search.
- template <typename I>
+ template <typename I, typename G>
struct draw_graph_edges_functor
{
/// Constructor
///
/// \param[in,out] ima The image where to draw.
- /// \param[in] textbboxes The line of text bounding boxes.
/// \param[in] value The value used to draw the links.
draw_graph_edges_functor(I& ima,
- const mln::util::array<box<mln_site(I)> >& textbboxes,
const mln_value(I)& value)
- : ima_(ima), textbboxes_(textbboxes), value_(value)
+ : ima_(ima), value_(value)
{}
/// Initialize the functor.
///
/// \param[in] g The graph this functor will work on.
- template <typename G>
void
init(const Graph<G>& g)
- { deja_vu.resize(exact(g).v_nmax(), false); }
+ {
+ g_ = g;
+ deja_vu.resize(exact(g).v_nmax(), false);
+ }
/// All components/vertices have been treated.
void final()
@@ -196,8 +173,8 @@ namespace scribo
void added_to_queue(unsigned id)
{
deja_vu[id] = true;
- mln::draw::line(ima_, textbboxes_[current_vertex].center(),
- textbboxes_[id].center(), value_);
+ mln::draw::line(ima_, g_.components()(current_vertex).bbox().pcenter(),
+ g_.components()(id).bbox().pcenter(), value_);
}
/// Treating a new vertex.
@@ -215,9 +192,6 @@ namespace scribo
/// The image where to draw.
I& ima_;
- /// Line of text bounding boxes.
- const mln::util::array<box<mln_site(I)> >& textbboxes_;
-
/// Value to be used to draw links.
mln_value(I) value_;
@@ -226,6 +200,8 @@ namespace scribo
/// Store whether a vertex has been already seen or not.
std::vector<bool> deja_vu;
+
+ G g_;
};
} // end of namespace scribo::draw::internal
@@ -245,13 +221,13 @@ namespace scribo
mln_precondition(input.is_valid());
- const component_set<L>& comp_set = links.components();
+ const component_set<L>& comps = links.components();
for_all_links(i, links)
if (links(i) != i && links(i) != 0)
{
mln_site(L)
- p1 = primitive::link::internal::compute_anchor(comp_set, i, anchor),
- p2 = primitive::link::internal::compute_anchor(comp_set, links(i), anchor);
+ p1 = primitive::link::internal::compute_anchor(comps, i, anchor),
+ p2 = primitive::link::internal::compute_anchor(comps, links(i), anchor);
mln::draw::line(input, p1, p2, value);
}
@@ -275,12 +251,12 @@ namespace scribo
inline
void
bounding_box_links(Image<I>& input_,
- const mln::util::array<mln_site(I)::vec>& mass_centers,
const object_links<L>& left_link,
const object_links<L>& right_link,
const mln_value(I)& left_link_value,
const mln_value(I)& right_link_value,
- const mln_value(I)& validated_link_value)
+ const mln_value(I)& validated_link_value,
+ anchor::Type anchor)
{
trace::entering("scribo::draw::bounding_box_links");
@@ -289,6 +265,8 @@ namespace scribo
typedef mln_site(I) P;
+ const component_set<L>& comps = left_link.components();
+
mln_dpsite(P) dleft = literal::zero;
dleft[0] = 2;
mln_dpsite(P) dright = literal::zero;
@@ -296,19 +274,26 @@ namespace scribo
for_all_links(i, left_link)
{
mln::draw::line(input,
- internal::shift_site(input, mass_centers[i], dleft),
internal::shift_site(input,
- mass_centers[left_link(i)],
+ primitive::link::internal::compute_anchor(comps, i, anchor),
+ dleft),
+ internal::shift_site(input,
+ primitive::link::internal::compute_anchor(comps, left_link(i), anchor),
dleft),
left_link_value);
+
+
mln::draw::line(input,
- internal::shift_site(input, mass_centers[i], dright),
internal::shift_site(input,
- mass_centers[right_link(i)],
- dright),
+ primitive::link::internal::compute_anchor(comps, i, anchor),
+ dleft),
+ internal::shift_site(input,
+ primitive::link::internal::compute_anchor(comps, right_link(i), anchor),
+ dleft),
right_link_value);
+
mln::util::couple<bool, unsigned>
nbh = primitive::internal::is_link_valid(left_link,
right_link,
@@ -316,78 +301,29 @@ namespace scribo
if (nbh.first())
mln::draw::line(input,
- mass_centers[i],
- mass_centers[nbh.second()],
+ primitive::link::internal::compute_anchor(comps, right_link(i), anchor),
+ primitive::link::internal::compute_anchor(comps, nbh.second(), anchor),
validated_link_value);
- input(mass_centers[i]) = validated_link_value;
}
trace::exiting("scribo::draw::bounding_box_links");
}
- template <typename I, typename L>
- inline
- void
- bounding_box_links(Image<I>& input_,
- const mln::util::array< box<mln_site(I)> >& bboxes,
- const object_links<L>& left_link,
- const object_links<L>& right_link,
- const mln_value(I)& left_link_value,
- const mln_value(I)& right_link_value,
- const mln_value(I)& validated_link_value)
- {
- trace::entering("scribo::draw::bounding_box_links");
-
- I& input = exact(input_);
- mln_precondition(input.is_valid());
-
- typedef mln_site(I) P;
- mln_site(I)::vec dleft = literal::origin;
- dleft[0] = 2;
- mln_site(I)::vec dright = literal::origin;
- dright[0] = -2;
- for_all_links(i, left_link)
- {
- mln::draw::line(input,
- bboxes[i].center() + dleft,
- bboxes[left_link(i)].center() + dleft,
- left_link_value);
-
- mln::draw::line(input,
- bboxes[i].center() + dright,
- bboxes[right_link(i)].center() + dright,
- right_link_value);
-
- mln::util::couple<bool, unsigned>
- nbh = primitive::internal::is_link_valid(left_link,
- right_link,
- i);
-
- if (nbh.first())
- mln::draw::line(input,
- bboxes[i].center(),
- bboxes[nbh.second()].center(),
- validated_link_value);
- }
-
- trace::exiting("scribo::draw::bounding_box_links");
- }
template <typename I, typename G>
inline
void
bounding_box_links(Image<I>& input,
- const mln::util::array< box<mln_site(I)> >& bboxes,
const Graph<G>& g,
const mln_value(I)& link_value)
{
trace::entering("scribo::draw::bounding_box_links");
mln_precondition(exact(input).is_valid());
- mln_precondition(exact(g).v_nmax() == bboxes.nelements());
- internal::draw_graph_edges_functor<I> f(exact(input), bboxes, link_value);
+
+ internal::draw_graph_edges_functor<I,G> f(exact(input), link_value);
mln::canvas::browsing::depth_first_search(g, f);
trace::exiting("scribo::draw::bounding_box_links");
diff --git a/scribo/draw/bounding_boxes.hh b/scribo/draw/bounding_boxes.hh
index 93f4067..d2a6384 100644
--- a/scribo/draw/bounding_boxes.hh
+++ b/scribo/draw/bounding_boxes.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -99,7 +100,7 @@ namespace scribo
mln_precondition(input.is_valid());
for_all_comps(i, components)
- if (components(i).bbox().is_valid())
+ if (components(i).is_valid())
mln::draw::box(input, components(i).bbox(), value);
trace::exiting("scribo::draw::bounding_boxes");
diff --git a/scribo/filter/object_links_non_aligned_simple.hh
b/scribo/filter/object_links_non_aligned_simple.hh
index e9dc5f5..1f56d85 100644
--- a/scribo/filter/object_links_non_aligned_simple.hh
+++ b/scribo/filter/object_links_non_aligned_simple.hh
@@ -55,8 +55,7 @@ namespace scribo
\param[in] max_alpha Maximum angle value (degrees).
- Exemple with dim == 1 and anchor == 1 (bottom
- horizontal filter):
+ Exemple with anchor == 1 (bottom horizontal filter):
\verbatim
diff --git a/scribo/filter/objects_with_holes.hh b/scribo/filter/objects_with_holes.hh
index 9e781fa..fdad0d9 100644
--- a/scribo/filter/objects_with_holes.hh
+++ b/scribo/filter/objects_with_holes.hh
@@ -33,7 +33,7 @@
# include <sstream>
-# include <mln/core/concept/image.hh>
+# include <mln/core/image/image2d.hh>
# include <mln/core/alias/neighb2d.hh>
# include <mln/core/routine/extend.hh>
# include <mln/core/image/dmorph/extended.hh>
@@ -95,7 +95,7 @@ namespace scribo
inline
component_set<L>
components_with_two_holes(const component_set<L>& components,
- unsigned min_size);
+ unsigned min_size);
# ifndef MLN_INCLUDE_ONLY
@@ -129,8 +129,6 @@ namespace scribo
for_all_comps(i, components)
if (components(i).is_valid())
{
- std::cout << components(i).bbox() << std::endl;
- std::cout << components(i).tag() << std::endl;
mln_box(L) b = components(i).bbox();
b.enlarge(1);
@@ -183,10 +181,10 @@ namespace scribo
const L& lbl = components.labeled_image();
- std::cout << "components.nlabels = " <<
components.nelements() << std::endl;
+// std::cout << "components.nlabels = " <<
components.nelements() << std::endl;
- util::timer timer_;
- timer_.start();
+// util::timer timer_;
+// timer_.start();
// init
{
@@ -199,19 +197,19 @@ namespace scribo
// FIXME: Improve.
- util::timer t2;
- t2.start();
+// util::timer t2;
+// t2.start();
bboxes_ima = internal::compute_bboxes_image(components);
- float t2_ = t2;
- std::cout << "compute bboxes image " << t2_ << std::endl;
+// float t2_ = t2;
+// std::cout << "compute bboxes image " << t2_ <<
std::endl;
to_keep(0) = true;
}
- float t_ = timer_;
- std::cout << "init = " << t_ << std::endl;
+// float t_ = timer_;
+// std::cout << "init = " << t_ << std::endl;
// 1st pass
- timer_.restart();
+// timer_.restart();
{
util::array<int> dp = positive_offsets_wrt(lbl, nbh);
const unsigned n_nbhs = dp.nelements();
@@ -241,14 +239,14 @@ namespace scribo
} // for_all(pxl)
}
- t_ = timer_;
- std::cout << "1st pass = " << t_ << std::endl;
+// t_ = timer_;
+// std::cout << "1st pass = " << t_ << std::endl;
// FIXME: Iterate over another label when a label is marked as
// "to be kept".
// 2nd pass
- timer_.restart();
+// timer_.restart();
{
unsigned kept = 0;
mln_fwd_pixter(const L) pxl(bboxes_ima); // Forward.
@@ -293,15 +291,15 @@ namespace scribo
// }
}
- float t_ = timer_;
- std::cout << "2nd pass = " << t_ << std::endl;
+// float t_ = timer_;
+// std::cout << "2nd pass = " << t_ << std::endl;
- std::cout << "kept = " << kept << std::endl;
+// std::cout << "kept = " << kept << std::endl;
// debug::println(parent);
// std::cout << bg_comps << std::endl;
// std::cout << to_keep << std::endl;
- timer_.restart();
+// timer_.restart();
if (kept == components.nelements())
{
@@ -311,8 +309,8 @@ namespace scribo
component_set<L> output = components.duplicate();
output.update_tags(to_keep, component::Ignored);
- t_ = timer_;
- std::cout << "init output = " << t_ << std::endl;
+// t_ = timer_;
+// std::cout << "init output = " << t_ << std::endl;
trace::exiting("scribo::filter::objects_with_holes");
return output;
@@ -330,7 +328,7 @@ namespace scribo
{
trace::entering("scribo::filter::objects_with_holes");
- std::cout << components.nelements() << std::endl;
+// std::cout << components.nelements() << std::endl;
typedef component_set<L> O;
neighb2d nbh = c8();
@@ -366,7 +364,7 @@ namespace scribo
}
// 1st pass
- std::cout << "1st pass" << std::endl;
+// std::cout << "1st pass" << std::endl;
{
util::array<int> dp = positive_offsets_wrt(lbl, nbh);
const unsigned n_nbhs = dp.nelements();
@@ -398,7 +396,7 @@ namespace scribo
}
// 2nd pass
- std::cout << "2nd pass" << std::endl;
+// std::cout << "2nd pass" << std::endl;
{
unsigned kept = 0;
mln_fwd_pixter(const L) pxl(bboxes_ima); // Forward.
@@ -458,118 +456,6 @@ namespace scribo
}
-
-// template <typename L>
-// inline
-// component_set<L>
-// objects_with_holes(const component_set<L>& components,
-// unsigned min_holes_count)
-// {
-// trace::entering("scribo::filter::objects_with_holes");
-
-// mln_precondition(components.is_valid());
-
-
-// L bboxes_ima;
-// initialize(bboxes_ima, components);
-// data::fill(bboxes_ima, literal::zero);
-
-// for_all_components(i, components.bboxes())
-// mln::draw::box(bboxes_ima, components.bbox(i), i);
-
-// util::array<util::set<mln_value(L)> > first_bg_comp(
-// static_cast<unsigned>(components.nlabels()) + 1);
-
-// fun::i2v::array<bool>
-// to_keep(static_cast<unsigned>(components.nlabels()) + 1,
-// false);
-// to_keep(0) = true;
-
-// mln_value(L) nbglabels;
-// L bg_lbl = labeling::background(components, c8(), nbglabels);
-
-// unsigned kept;
-// mln_piter(L) p(bboxes_ima.domain());
-// for_all(p)
-// {
-// if (bboxes_ima(p) == literal::zero)
-// continue;
-
-// if (bg_lbl(p) != 0)
-// if (! first_bg_comp(bboxes_ima(p)).has(bg_lbl(p)))
-// if (first_bg_comp(bboxes_ima(p)).nelements() < min_holes_count - 1)
-// first_bg_comp(bboxes_ima(p)).insert(bg_lbl(p));
-// else
-// {
-// to_keep(bboxes_ima(p)) == true;
-// ++kept;
-// }
-// }
-
-// component_set<L> output;
-// if (kept == components.nlabels())
-// output = components;
-// else
-// output = internal::compute(components, to_keep);
-
-// trace::exiting("scribo::filter::objects_with_holes");
-// return output;
-// }
-
-
- template <typename L>
- inline
- component_set<L>
- objects_with_holes_slow(const component_set<L>& components,
- unsigned min_holes_count)
- {
- trace::entering("scribo::filter::objects_with_holes");
-
- mln_precondition(components.is_valid());
-
- fun::i2v::array<bool>
- to_keep(static_cast<unsigned>(components.nlabels()) + 1,
- true);
-
- bool to_remove = false;
- for_all_comps(i, components)
- if (components(i).tag() != component::Ignored)
- {
- mln_domain(L) b = components(i).bbox();
- b.enlarge(1);
-
- mln_ch_value(L, bool) tmp(b);
- data::fill(tmp, true);
- data::fill((tmp | ((components | components.bbox(i)) | (pw::value(components) ==
pw::cst(i))).domain()).rw(), false);
-
- typedef accu::math::count<mln_value(L)> accu_t;
- mln_value(L) nlabels;
- util::array<unsigned> counts
- = labeling::blobs_and_compute(tmp,
- c8(), nlabels,
- accu_t()).second();
- unsigned nholes = 0;
- for_all_comp_data(j, counts)
- if (counts(j) > 4u)
- ++nholes;
-
- if (nholes < min_holes_count)
- {
- to_keep(i) = false;
- to_remove = true;
- }
- }
-
- component_set<L> output;
- if (! to_remove)
- output = components;
- else
- output = internal::compute(components, to_keep);
-
- trace::exiting("scribo::filter::objects_with_holes");
- return output;
- }
-
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace scribo::filter
diff --git a/scribo/primitive/extract/lines_pattern.hh
b/scribo/primitive/extract/lines_pattern.hh
index bc23012..c68b577 100644
--- a/scribo/primitive/extract/lines_pattern.hh
+++ b/scribo/primitive/extract/lines_pattern.hh
@@ -58,7 +58,6 @@ namespace scribo
using namespace mln;
-
/// Extract lines with a specific pattern
///
/// \param[in] input_ A binary image.
@@ -109,7 +108,7 @@ namespace scribo
initialize(output, input);
mln_piter(I) p(input.domain());
- mln_qiter(window2d) q(win, p);
+ mln_qiter(W) q(win, p);
bool is_foreground;
for_all(p)
{
diff --git a/scribo/primitive/link/internal/find_several_links.hh
b/scribo/primitive/link/internal/find_several_links.hh
index d379021..8cca3bd 100644
--- a/scribo/primitive/link/internal/find_several_links.hh
+++ b/scribo/primitive/link/internal/find_several_links.hh
@@ -91,10 +91,10 @@ namespace scribo
functor.initialize_link(current_object); // <-- initialize_link
- for (unsigned anchor_ = 0; anchor_ < functor.nanchors(); ++anchor_) // <--
nanchor
+ for_all_anchors(a, functor.anchors()) // <-- nanchor && anchors
{
// FIXME : See fixme at the beginning of this file.
- anchor::Type anchor = static_cast<anchor::Type>(anchor_);
+ anchor::Type anchor = functor.anchors()[a];
mln_site(scribo_support_(F))
start_point = functor.start_point(current_object, anchor), // <-- start_point
@@ -102,7 +102,7 @@ namespace scribo
mln_postcondition(p == start_point);
- while (functor.objects().domain().has(p)
+ while (functor.labeled_image().domain().has(p)
&& ! functor.is_potential_link(current_object,
start_point, p) // <-- is_potential_link
&& functor.verify_link_criterion(current_object,
diff --git a/scribo/primitive/link/internal/link_functor_base.hh
b/scribo/primitive/link/internal/link_functor_base.hh
index f2641ad..ad3d71b 100644
--- a/scribo/primitive/link/internal/link_functor_base.hh
+++ b/scribo/primitive/link/internal/link_functor_base.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -72,15 +73,10 @@ namespace scribo
typedef mln_site(L) P;
typedef mln::util::couple<anchor::Type, P> couple_t;
- link_functor_base(const component_set<L>& components, unsigned nanchors);
-
/// \overload
- /// \p nanchors is set to 1.
link_functor_base(const component_set<L>& components);
- unsigned nanchors() const;
-
const object_links<L>& links() const;
unsigned link(unsigned object) const;
@@ -171,11 +167,12 @@ namespace scribo
mln_site(L) start_point_(unsigned current_object,
anchor::Type anchor);
+ const L& labeled_image() const;
+
protected:
object_links<L> links_;
const component_set<L> components_;
const L& labeled_image_;
- unsigned nanchors_;
};
@@ -186,25 +183,10 @@ namespace scribo
template <typename L, typename E>
inline
link_functor_base<L,E>::link_functor_base(
- const component_set<L>& components,
- unsigned nanchors)
- : links_(components),
- components_(components),
- labeled_image_(this->components_.labeled_image()),
- nanchors_(nanchors)
- {
- links_.init();
- }
-
-
- template <typename L, typename E>
- inline
- link_functor_base<L,E>::link_functor_base(
const component_set<L>& components)
: links_(components),
components_(components),
- labeled_image_(this->components_.labeled_image()),
- nanchors_(1)
+ labeled_image_(this->components_.labeled_image())
{
links_.init();
}
@@ -212,15 +194,6 @@ namespace scribo
template <typename L, typename E>
inline
- unsigned
- link_functor_base<L,E>::nanchors() const
- {
- return nanchors_;
- }
-
-
- template <typename L, typename E>
- inline
const object_links<L>&
link_functor_base<L,E>::links() const
{
@@ -403,6 +376,14 @@ namespace scribo
}
+ template <typename L, typename E>
+ inline
+ const L&
+ link_functor_base<L,E>::labeled_image() const
+ {
+ return labeled_image_;
+ }
+
// Default implementation for delegated methods.
diff --git a/scribo/primitive/link/internal/link_several_dmax_base.hh
b/scribo/primitive/link/internal/link_several_dmax_base.hh
index e1f42ff..3b4ec4b 100644
--- a/scribo/primitive/link/internal/link_several_dmax_base.hh
+++ b/scribo/primitive/link/internal/link_several_dmax_base.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -28,8 +29,11 @@
/// \file
///
-/// Base class for link functors using mass centers and a given max
-/// distance.
+/// Base class for link functors using several anchors and a maximum
+/// lookup distance.
+///
+/// FIXME: make it more generic to support different
+/// anchor::Direction.
# include <mln/accu/center.hh>
@@ -60,8 +64,8 @@ namespace scribo
namespace internal
{
- /// \brief Base class for link functors using mass centers and
- /// a given max distance.
+ /// \brief Base class for link functors using several anchors
+ /// and a maximum lookup distance.
//
template <typename L, typename E>
class link_several_dmax_base
@@ -74,14 +78,14 @@ namespace scribo
public:
- link_several_dmax_base(const object_image(L)& objects,
- unsigned neighb_max_distance,
- unsigned nanchors);
+ link_several_dmax_base(const component_set<L>& comps,
+ unsigned neighb_max_distance);
bool verify_link_criterion_(unsigned current_object,
- const P& start_point, const P& p) const;
+ const P& start_point,
+ const P& p) const;
void start_processing_object_(unsigned current_object);
@@ -91,13 +95,17 @@ namespace scribo
void initialize_link_(unsigned current_object);
couple_t finalize_link_(unsigned current_object);
-
+ unsigned nanchors() const;
+ const util::array<anchor::Type>& anchors() const;
protected:
- mln::util::array<ms_t> mass_centers_;
+ mln::util::array<anchor::Type> anchors_;
mln::util::array<couple_t> potential_links_;
float dmax_;
float neighb_max_distance_;
+ anchor::Direction direction_;
+
+ using super_::labeled_image_;
};
@@ -107,17 +115,17 @@ namespace scribo
template <typename L, typename E>
inline
link_several_dmax_base<L, E>::link_several_dmax_base(
- const object_image(L)& objects,
- unsigned neighb_max_distance,
- unsigned nanchors)
+ const component_set<L>& comps,
+ unsigned neighb_max_distance)
- : super_(objects, nanchors),
+ : super_(comps),
dmax_(0),
- neighb_max_distance_(neighb_max_distance)
+ neighb_max_distance_(neighb_max_distance),
+ direction_(anchor::Horizontal) // FIXME: make it an
+ // argument when this
+ // functor is generic
+ // enough..
{
-
- mass_centers_ = labeling::compute(accu::meta::center(),
- objects, objects.nlabels());
}
template <typename L, typename E>
@@ -130,7 +138,7 @@ namespace scribo
{
(void) current_object;
- float dist = math::abs(p.col() - start_point.col());
+ float dist = math::abs(p[direction_] - start_point[direction_]);
return dist <= dmax_; // Not too far
}
@@ -142,8 +150,8 @@ namespace scribo
unsigned current_object)
{
float
- midcol = (this->objects_.bbox(current_object).pmax().col()
- - this->objects_.bbox(current_object).pmin().col()) / 2;
+ midcol = (this->components_(current_object).bbox().pmax()[direction_]
+ - this->components_(current_object).bbox().pmin()[direction_]) / 2;
dmax_ = midcol + neighb_max_distance_;
}
@@ -168,7 +176,6 @@ namespace scribo
link_several_dmax_base<L, E>::initialize_link_(unsigned current_object)
{
(void) current_object;
- this->links_.clear();
this->potential_links_.clear();
}
@@ -188,8 +195,8 @@ namespace scribo
{
for(unsigned i = 0; i < this->potential_links_.nelements(); ++i)
{
- tmp = math::abs(this->objects_.bbox(current_object).pmax().col()
- - this->potential_links_(i).second().col());
+ tmp = math::abs(this->components_(current_object).bbox().pmax()[direction_]
+ - this->potential_links_(i).second()[direction_]);
dist.append(tmp);
if (tmp < min)
min = tmp;
@@ -198,6 +205,9 @@ namespace scribo
mln_assertion(min != mln_max(unsigned));
// Keep closest links and compute vertical overlap.
+ //
+ // FIXME: not using direction_ attribute. This code is not
+ // generic enough!
unsigned
nratio = 0,
id_max_ratio = 0;
@@ -207,17 +217,17 @@ namespace scribo
if (dist[i] < (1.2 * min))
{
unsigned
- other_object = this->objects_(potential_links_(i).second());
+ other_object = labeled_image_(potential_links_(i).second());
nbh_id = other_object;
float
dr
- = math::min(this->objects_.bbox(current_object).pmax().row(),
- this->objects_.bbox(other_object).pmax().row())
- - math::min(this->objects_.bbox(current_object).pmin().row(),
- this->objects_.bbox(other_object).pmin().row()),
- dh = this->objects_.bbox(other_object).pmax().row()
- - this->objects_.bbox(other_object).pmin().row(),
+ = math::min(this->components_(current_object).bbox().pmax().row(),
+ this->components_(other_object).bbox().pmax().row())
+ - math::min(this->components_(current_object).bbox().pmin().row(),
+ this->components_(other_object).bbox().pmin().row()),
+ dh = this->components_(other_object).bbox().pmax().row()
+ - this->components_(other_object).bbox().pmin().row(),
ratio = dr / dh;
overlap.append(ratio);
@@ -237,7 +247,7 @@ namespace scribo
if (nratio == 1)
{
this->links_(current_object)
- = this->objects_(potential_links_(id_max_ratio).second());
+ = labeled_image_(potential_links_(id_max_ratio).second());
return potential_links_(id_max_ratio);
}
@@ -249,6 +259,23 @@ namespace scribo
}
+ template <typename L, typename E>
+ inline
+ const util::array<anchor::Type>&
+ link_several_dmax_base<L, E>::anchors() const
+ {
+ return anchors_;
+ }
+
+ template <typename L, typename E>
+ inline
+ unsigned
+ link_several_dmax_base<L,E>::nanchors() const
+ {
+ return anchors_.nelements();
+ }
+
+
# endif // ! MLN_INCLUDE_ONLY
diff --git a/scribo/primitive/regroup/from_single_left_link_wrt_h_ratio.hh
b/scribo/primitive/regroup/from_single_left_link_wrt_h_ratio.hh
index 23adfc2..0eedbb8 100644
--- a/scribo/primitive/regroup/from_single_left_link_wrt_h_ratio.hh
+++ b/scribo/primitive/regroup/from_single_left_link_wrt_h_ratio.hh
@@ -46,12 +46,14 @@
# include <scribo/core/macros.hh>
# include <scribo/core/component_set.hh>
# include <scribo/core/object_links.hh>
+# include <scribo/core/object_groups.hh>
# include <scribo/filter/object_links_bbox_h_ratio.hh>
-# include <scribo/primitive/link/internal/find_link.hh>
-# include <scribo/primitive/link/internal/link_single_dmax_base.hh>
+# include <scribo/primitive/link/with_single_left_link.hh>
# include <scribo/primitive/link/compute.hh>
+# include <scribo/primitive/group/apply.hh>
+# include <scribo/primitive/group/from_single_link.hh>
namespace scribo
diff --git a/scribo/src/contest/hdibco-2010/Makefile.am
b/scribo/src/contest/hdibco-2010/Makefile.am
index 44add64..a59e424 100644
--- a/scribo/src/contest/hdibco-2010/Makefile.am
+++ b/scribo/src/contest/hdibco-2010/Makefile.am
@@ -19,9 +19,7 @@
include $(top_srcdir)/scribo/tests/tests.mk
-check_PROGRAMS = sauvola_ms_hdibco
+bin_PROGRAMS = sauvola_ms_hdibco
sauvola_ms_hdibco_SOURCES = sauvola_ms_hdibco.cc
-
-TESTS = $(check_PROGRAMS)
diff --git a/scribo/src/debug/show_links_single_left.cc
b/scribo/src/debug/show_links_single_left.cc
index 26f78e2..8c55afc 100644
--- a/scribo/src/debug/show_links_single_left.cc
+++ b/scribo/src/debug/show_links_single_left.cc
@@ -41,7 +41,7 @@
#include <scribo/primitive/extract/objects.hh>
#include <scribo/primitive/link/with_single_left_link.hh>
-#include <scribo/primitive/link/internal/link_ms_dmax_base.hh>
+#include <scribo/primitive/link/internal/link_single_dmax_base.hh>
#include <scribo/primitive/link/compute.hh>
#include <scribo/draw/bounding_boxes.hh>
diff --git a/scribo/table/internal/align_lines.hh b/scribo/table/internal/align_lines.hh
index 9af00fc..01f9c39 100644
--- a/scribo/table/internal/align_lines.hh
+++ b/scribo/table/internal/align_lines.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -41,6 +42,7 @@
# include <mln/math/round.hh>
# include <scribo/core/macros.hh>
+# include <scribo/core/component_set.hh>
namespace scribo
@@ -93,12 +95,13 @@ namespace scribo
** and all bboxes referenced in this set are aligned on the same row or col.
**
*/
- template <typename P>
+ template <typename L>
mln::util::array<int>
align_lines(unsigned nsites,
int min_coord,
int max_coord,
- mln::util::array<box<P> >& line_bboxes,
+ const component_set<L>& lines,
+ component_set<L>& aligned_lines,
unsigned dim,
unsigned max_alignment_diff);
@@ -107,12 +110,13 @@ namespace scribo
# ifndef MLN_INCLUDE_ONLY
- template <typename P>
+ template <typename L>
mln::util::array<int>
align_lines(unsigned nsites,
int min_coord,
int max_coord,
- mln::util::array<box<P> >& line_bboxes,
+ const component_set<L>& lines,
+ component_set<L>& aligned_lines,
unsigned dim,
unsigned max_alignment_diff)
{
@@ -120,58 +124,57 @@ namespace scribo
mln_precondition(nsites > 0);
- mln::util::array< mln::util::set<unsigned> > lines;
+ mln::util::array< mln::util::set<unsigned> > rlines;
lines.resize(nsites);
// Map components with actual lines.
- for_all_comps(i, line_bboxes)
+ for_all_comps(i, lines)
{
- int minline = line_bboxes[i].pmin()[dim] - max_alignment_diff;
+ int minline = lines(i).bbox().pmin()[dim] - max_alignment_diff;
minline = (minline < min_coord ? min_coord : minline);
- int maxline = line_bboxes[i].pmax()[dim] + max_alignment_diff;
+ int maxline = lines(i).bbox().pmax()[dim] + max_alignment_diff;
maxline = (maxline > max_coord ? max_coord : maxline);
for (int line = minline;
line <= maxline; ++line)
- lines[line].insert(i);
+ rlines[line].insert(i);
}
// Init box2line
- mln::util::array<int> box2line;
- box2line.resize(line_bboxes.nelements());
- for_all_elements(i, box2line)
- box2line[i] = -1;
+ mln::util::array<int>
+ box2line(unsigned(lines.nelements()) + 1, -1);
// Find the line with the highest element count.
unsigned max_nelts = 0;
- for_all_elements(i, lines)
- if (max_nelts < lines[i].nelements())
- max_nelts = lines[i].nelements();
+ for_all_elements(i, rlines)
+ if (max_nelts < rlines[i].nelements())
+ max_nelts = rlines[i].nelements();
// Aligning lines
// FIXME: not optimal... Make it faster!
// We may do too much iterations (while loop) and some of them may
// be done for nothing...
+ aligned_lines = duplicate(lines);
mln::util::array<int> newlines;
math::round<int> round;
while (max_nelts > 0)
{
- for_all_elements(i, lines)
- if (lines[i].nelements() == max_nelts)
+ for_all_elements(i, rlines)
+ if (rlines[i].nelements() == max_nelts)
{
accu::stat::mean<unsigned> mean;
- for_all_elements(j, lines[i])
- if (box2line[lines[i][j]] == -1)
- mean.take(line_bboxes[lines[i][j]].center()[dim]);
+ for_all_elements(j, rlines[i])
+ if (box2line[rlines[i][j]] == -1)
+ mean.take(lines(rlines[i][j]).bbox().pcenter()[dim]);
if (mean.is_valid())
{
for_all_elements(j, lines[i])
- if (box2line[lines[i][j]] == -1)
+ if (box2line[rlines[i][j]] == -1)
{
- line_bboxes[lines[i][j]].pmin()[dim] = round(mean.to_result());
- line_bboxes[lines[i][j]].pmax()[dim] = round(mean.to_result());
- box2line[lines[i][j]] = round(mean.to_result());
+ lines(rlines[i][j]).bbox().pmin()[dim] = round(mean.to_result());
+ lines(rlines[i][j]).bbox().pmax()[dim] = round(mean.to_result());
+ box2line[rlines[i][j]] = round(mean.to_result());
}
newlines.append(round(mean.to_result()));
}
diff --git a/scribo/table/rebuild.hh b/scribo/table/rebuild.hh
index c4029cf..f593153 100644
--- a/scribo/table/rebuild.hh
+++ b/scribo/table/rebuild.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -71,29 +72,29 @@ namespace scribo
** cell is labeled. The second argument are the aligned and connected
** table line bounding boxes.
*/
- template <typename I, typename V>
- mln::util::couple<mln_ch_value(I,V),
- mln::util::couple<mln::util::array<box<mln_site(I)> >,
- mln::util::array<box<mln_site(I)> > > >
+ template <typename I, typename L>
+ mln::util::couple<L,
+ mln::util::couple<component_set<L>,
+ component_set<L> > >
rebuild(const Image<I>& input_,
- const mln::util::couple<mln::util::array<box<mln_site(I)> >,
- mln::util::array<box<mln_site(I)> > >& linebboxes_,
+ const component_set<L>& vlines,
+ const component_set<L>& hlines,
unsigned max_dist_lines,
- V& ncells);
+ mln_value(L)& ncells);
# ifndef MLN_INCLUDE_ONLY
- template <typename I, typename V>
- mln::util::couple<mln_ch_value(I,V),
- mln::util::couple<mln::util::array<box<mln_site(I)> >,
- mln::util::array<box<mln_site(I)> > > >
+ template <typename I, typename L>
+ mln::util::couple<L,
+ mln::util::couple<component_set<L>,
+ component_set<L> > >
rebuild(const Image<I>& input_,
- const mln::util::couple<mln::util::array<box<mln_site(I)> >,
- mln::util::array<box<mln_site(I)> > >& linebboxes_,
+ const component_set<L>& vlines,
+ const component_set<L>& hlines,
unsigned max_dist_lines,
- V& ncells)
+ mln_value(L)& ncells)
{
trace::entering("scribo::table::rebuild");
const I& input = exact(input_);
@@ -101,34 +102,33 @@ namespace scribo
mlc_equal(mln_value(I), bool)::check();
mln_precondition(input.is_valid());
- mln::util::couple<mln::util::array<box<mln_site(I)> >,
- mln::util::array<box<mln_site(I)> > > linebboxes = linebboxes_;
-
- scribo::debug::save_table_image(input, linebboxes,
+# ifndef SCRIBO_DEBUG
+ scribo::debug::save_table_image(input, vlines, hlines,
literal::red, "table-raw.ppm");
+# endif
- mln::util::array<int> rows = align_lines_horizontaly(input,
linebboxes.second(), 5);
- mln::util::array<int> cols = align_lines_verticaly(input, linebboxes.first(),
5);
+ mln::util::array<int> rows = align_lines_horizontaly(input, vlines, 5);
+ mln::util::array<int> cols = align_lines_verticaly(input, hlines, 5);
-# ifndef SCRIBO_NDEBUG
- scribo::debug::save_table_image(input, linebboxes,
+# ifndef SCRIBO_DEBUG
+ scribo::debug::save_table_image(input, vlines, hlines,
literal::red, "table-aligned.ppm");
# endif
- repair_vertical_lines(input, linebboxes, 10);
- repair_horizontal_lines(input, linebboxes, 10);
+ repair_vertical_lines(input, vlines, 10);
+ repair_horizontal_lines(input, hlines, 10);
-# ifndef SCRIBO_NDEBUG
- scribo::debug::save_table_image(input, linebboxes,
+# ifndef SCRIBO_DEBUG
+ scribo::debug::save_table_image(input, vlines, hlines,
literal::red, "table-repaired.ppm");
# endif
// Connect vertical lines with horizontal lines.
- connect_vertical_lines(rows, linebboxes, input, max_dist_lines);
- connect_horizontal_lines(cols, linebboxes, input, max_dist_lines);
+ connect_vertical_lines(rows, vlines, hlines, input, max_dist_lines);
+ connect_horizontal_lines(cols, vlines, hlines, input, max_dist_lines);
-# ifndef SCRIBO_NDEBUG
- scribo::debug::save_table_image(input, linebboxes,
+# ifndef SCRIBO_DEBUG
+ scribo::debug::save_table_image(input, vlines, hlines,
literal::red, "table-connected.ppm");
# endif
@@ -136,15 +136,16 @@ namespace scribo
mln_ch_value(I,bool) res;
initialize(res, input);
data::fill(res, false);
- for_all_elements(i, linebboxes.first())
- mln::draw::box(res, linebboxes.first()[i], true);
- for_all_elements(i, linebboxes.second())
- mln::draw::box(res, linebboxes.second()[i], true);
+ for_all_comps(i, vlines)
+ mln::draw::box(res, vlines(i).bbox(), true);
+ for_all_comps(i, hlines)
+ mln::draw::box(res, hlines(i).bbox(), true);
- mln_ch_value(I,V) lbl = labeling::background(res, c8(), ncells);
+ L lbl = labeling::background(res, c8(), ncells);
trace::exiting("scribo::table::rebuild");
- return mln::make::couple(lbl, linebboxes);
+ return mln::make::couple(lbl,
+ mln::make::couple(vlines, hlines));
}
--
1.5.6.5