last-svn-commit-57-ga8aeee1 Update code according to last changes in Scribo core classes.

* draw/bounding_box_links.hh, * primitive/internal/init_link_array.hh, * primitive/internal/is_link_valid.hh, * primitive/link/internal/link_single_dmax_base.hh, * src/afp/link.hh: Update the use of object_link class. * draw/bounding_boxes.hh, * filter/objects_with_holes.hh, * src/afp/regroup.hh: Update for_all macro. * estim/object_groups_v_thickness.hh, * filter/object_groups_small.hh, * filter/object_groups_v_thickness.hh, * text/recognition.hh: Update access to component_set. * filter/object_links_bbox_h_ratio.hh, * filter/object_links_bbox_overlap.hh, * filter/object_links_bbox_ratio.hh, * filter/object_links_bottom_aligned.hh, * filter/object_links_non_aligned_simple.hh, * filter/object_links_top_aligned.hh, * primitive/group/apply.hh, * primitive/group/from_single_link.hh, * primitive/link/merge_double_link.hh, * primitive/link/with_single_right_link_bottom.hh, * primitive/link/with_single_right_link_dmax_ratio.hh, * primitive/link/with_single_right_link_top.hh: Improve routine prototypes. * primitive/link/internal/link_functor_base.hh: Make use of separators if exist. --- scribo/ChangeLog | 36 ++++++++++++ scribo/draw/bounding_box_links.hh | 20 +++--- scribo/draw/bounding_boxes.hh | 2 +- scribo/estim/object_groups_v_thickness.hh | 2 +- scribo/filter/object_groups_small.hh | 2 +- scribo/filter/object_groups_v_thickness.hh | 2 +- scribo/filter/object_links_bbox_h_ratio.hh | 10 +-- scribo/filter/object_links_bbox_overlap.hh | 18 ++---- scribo/filter/object_links_bbox_ratio.hh | 14 ++--- scribo/filter/object_links_bottom_aligned.hh | 12 +--- scribo/filter/object_links_non_aligned_simple.hh | 60 ++++++++++---------- scribo/filter/object_links_top_aligned.hh | 13 +--- scribo/filter/objects_with_holes.hh | 4 +- scribo/primitive/group/apply.hh | 33 ++++------- scribo/primitive/group/from_single_link.hh | 27 ++++----- scribo/primitive/internal/init_link_array.hh | 6 +- scribo/primitive/internal/is_link_valid.hh | 14 +++-- .../primitive/link/internal/link_functor_base.hh | 19 +++++-- .../link/internal/link_single_dmax_base.hh | 4 +- scribo/primitive/link/merge_double_link.hh | 19 +++---- .../link/with_single_right_link_bottom.hh | 28 +++++----- .../link/with_single_right_link_dmax_ratio.hh | 30 +++++++++- .../primitive/link/with_single_right_link_top.hh | 17 +++--- scribo/src/afp/link.hh | 12 ++-- scribo/src/afp/regroup.hh | 2 +- scribo/text/recognition.hh | 2 +- 26 files changed, 218 insertions(+), 190 deletions(-) diff --git a/scribo/ChangeLog b/scribo/ChangeLog index 54d5f0d..74cef68 100644 --- a/scribo/ChangeLog +++ b/scribo/ChangeLog @@ -1,5 +1,41 @@ 2010-03-11 Guillaume Lazzara <z@lrde.epita.fr> + Update code according to last changes in Scribo core classes. + + * draw/bounding_box_links.hh, + * primitive/internal/init_link_array.hh, + * primitive/internal/is_link_valid.hh, + * primitive/link/internal/link_single_dmax_base.hh, + * src/afp/link.hh: Update the use of object_link class. + + * draw/bounding_boxes.hh, + * filter/objects_with_holes.hh, + * src/afp/regroup.hh: Update for_all macro. + + * estim/object_groups_v_thickness.hh, + * filter/object_groups_small.hh, + * filter/object_groups_v_thickness.hh, + * text/recognition.hh: Update access to component_set. + + * filter/object_links_bbox_h_ratio.hh, + * filter/object_links_bbox_overlap.hh, + * filter/object_links_bbox_ratio.hh, + * filter/object_links_bottom_aligned.hh, + * filter/object_links_non_aligned_simple.hh, + * filter/object_links_top_aligned.hh, + * primitive/group/apply.hh, + * primitive/group/from_single_link.hh, + * primitive/link/merge_double_link.hh, + * primitive/link/with_single_right_link_bottom.hh, + * primitive/link/with_single_right_link_dmax_ratio.hh, + * primitive/link/with_single_right_link_top.hh: Improve routine + prototypes. + + * primitive/link/internal/link_functor_base.hh: Make use of + separators if exist. + +2010-03-11 Guillaume Lazzara <z@lrde.epita.fr> + Improve debug routines in Scribo. * debug/bboxes_enlarged_image.hh, diff --git a/scribo/draw/bounding_box_links.hh b/scribo/draw/bounding_box_links.hh index b2c425a..2ee5173 100644 --- a/scribo/draw/bounding_box_links.hh +++ b/scribo/draw/bounding_box_links.hh @@ -245,13 +245,13 @@ namespace scribo mln_precondition(input.is_valid()); - const component_set<L>& comp_set = links.component_set_(); - for_all_components(i, links) - if (links[i] != i && links[i] != 0) + const component_set<L>& comp_set = 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); + p2 = primitive::link::internal::compute_anchor(comp_set, links(i), anchor); mln::draw::line(input, p1, p2, value); } @@ -293,19 +293,19 @@ namespace scribo dleft[0] = 2; mln_dpsite(P) dright = literal::zero; dright[0] = -2; - for_all_components(i, left_link) + 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]], + mass_centers[left_link(i)], 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]], + mass_centers[right_link(i)], dright), right_link_value); @@ -347,16 +347,16 @@ namespace scribo dleft[0] = 2; mln_site(I)::vec dright = literal::origin; dright[0] = -2; - for_all_components(i, left_link) + for_all_links(i, left_link) { mln::draw::line(input, bboxes[i].center() + dleft, - bboxes[left_link[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, + bboxes[right_link(i)].center() + dright, right_link_value); mln::util::couple<bool, unsigned> diff --git a/scribo/draw/bounding_boxes.hh b/scribo/draw/bounding_boxes.hh index 3dce077..93f4067 100644 --- a/scribo/draw/bounding_boxes.hh +++ b/scribo/draw/bounding_boxes.hh @@ -77,7 +77,7 @@ namespace scribo mln_precondition(input.is_valid()); - for_all_components(i, boxes) + for_all_comp_data(i, boxes) if (boxes[i].is_valid()) mln::draw::box(input, boxes[i], value); diff --git a/scribo/estim/object_groups_v_thickness.hh b/scribo/estim/object_groups_v_thickness.hh index 6d74f2c..b626243 100644 --- a/scribo/estim/object_groups_v_thickness.hh +++ b/scribo/estim/object_groups_v_thickness.hh @@ -69,7 +69,7 @@ namespace scribo mln_precondition(groups.is_valid()); - const component_set<L>& components = groups.component_set_(); + const component_set<L>& components = groups.components(); //FIXME: remove when object_groups will store the number of //elements per group. diff --git a/scribo/filter/object_groups_small.hh b/scribo/filter/object_groups_small.hh index b2662c0..60f8753 100644 --- a/scribo/filter/object_groups_small.hh +++ b/scribo/filter/object_groups_small.hh @@ -81,7 +81,7 @@ namespace scribo output(0) = 0; for_all_groups(i, output) if (group_size[groups(i)] < n_links - || !groups.component_set_()(i).is_valid()) + || !groups.components()(i).is_valid()) output(i) = 0; trace::exiting("scribo::filter::object_groups_small"); diff --git a/scribo/filter/object_groups_v_thickness.hh b/scribo/filter/object_groups_v_thickness.hh index a4c5277..caac765 100644 --- a/scribo/filter/object_groups_v_thickness.hh +++ b/scribo/filter/object_groups_v_thickness.hh @@ -78,7 +78,7 @@ namespace scribo object_groups<L> output(groups); output(0) = 0; for (unsigned i = 1; i < output.nelements(); ++i) - if (groups.component_set_()(i).is_valid() + if (groups.components()(i).is_valid() && group_thickness[groups(i)] < thickness) output(i) = 0; diff --git a/scribo/filter/object_links_bbox_h_ratio.hh b/scribo/filter/object_links_bbox_h_ratio.hh index 261fbcb..5573f16 100644 --- a/scribo/filter/object_links_bbox_h_ratio.hh +++ b/scribo/filter/object_links_bbox_h_ratio.hh @@ -52,7 +52,6 @@ namespace scribo /*! \brief Invalidate links between two components with too different height. - \param[in] components A component set. \param[in] links Link objects information. \param[in] max_h_ratio The maximum height ratio of two linked bounding boxes. @@ -61,8 +60,7 @@ namespace scribo */ template <typename L> object_links<L> - object_links_bbox_h_ratio(const component_set<L>& components, - const object_links<L>& links, + object_links_bbox_h_ratio(const object_links<L>& links, float max_h_ratio); @@ -71,17 +69,15 @@ namespace scribo template <typename L> object_links<L> - object_links_bbox_h_ratio(const component_set<L>& components, - const object_links<L>& links, + object_links_bbox_h_ratio(const object_links<L>& links, float max_h_ratio) { trace::entering("scribo::filter::object_links_bbox_h_ratio"); - mln_precondition(components.is_valid()); mln_precondition(links.is_valid()); object_links<L> - output = object_links_bbox_ratio(components, links, 0, max_h_ratio); + output = object_links_bbox_ratio(links, 0, max_h_ratio); trace::exiting("scribo::filter::object_links_bbox_h_ratio"); return output; diff --git a/scribo/filter/object_links_bbox_overlap.hh b/scribo/filter/object_links_bbox_overlap.hh index d2d9376..ffcbb6c 100644 --- a/scribo/filter/object_links_bbox_overlap.hh +++ b/scribo/filter/object_links_bbox_overlap.hh @@ -53,7 +53,6 @@ namespace scribo /*! \brief Invalidate links between two components having their bounding box overlapping too much. - \param[in] components A component set. \param[in] links Link components information. \param[in] max_overlap_ratio The maximum ratio of the overlapping areas. @@ -62,8 +61,7 @@ namespace scribo */ template <typename L> object_links<L> - object_links_bbox_overlap(const component_set<L>& components, - const object_links<L>& links, + object_links_bbox_overlap(const object_links<L>& links, float max_overlap_ratio); @@ -72,19 +70,17 @@ namespace scribo template <typename L> object_links<L> - object_links_bbox_overlap(const component_set<L>& components, - const object_links<L>& links, + object_links_bbox_overlap(const object_links<L>& links, float max_overlap_ratio) { trace::entering("scribo::filter::object_links_bbox_overlap"); - mln_precondition(components.is_valid()); mln_precondition(links.is_valid()); - mln_precondition(components.id_() == links.components_id_()); + const component_set<L>& components = links.components(); object_links<L> output(links); - for_all_components(i, components) + for_all_comps(i, components) if (components(i).is_valid() && links(i) != i) { bool has_intersection = true; @@ -92,9 +88,9 @@ namespace scribo 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]); + components(links(i)).bbox().pmin()[dim]); pmax[dim] = math::min(components(i).bbox().pmax()[dim], - components(links[i]).bbox().pmax()[dim]); + components(links(i)).bbox().pmax()[dim]); if (pmin[dim] > pmax[dim]) { @@ -113,7 +109,7 @@ namespace scribo if (ratio_i >= max_overlap_ratio || ratio_link_i >= max_overlap_ratio) - output[i] = i; + output(i) = i; } trace::exiting("scribo::filter::object_links_bbox_overlap"); diff --git a/scribo/filter/object_links_bbox_ratio.hh b/scribo/filter/object_links_bbox_ratio.hh index bc5523c..d1c01dd 100644 --- a/scribo/filter/object_links_bbox_ratio.hh +++ b/scribo/filter/object_links_bbox_ratio.hh @@ -49,7 +49,6 @@ namespace scribo /*! \brief Invalidate links between two components with too different height or width. - \param[in] components An object image. \param[in] links Link components information. \param[in] dim The dimension to use to compare bbox length. \param[in] max_ratio The maximum length ratio of two linked @@ -59,8 +58,7 @@ namespace scribo */ template <typename L> object_links<L> - object_links_bbox_ratio(const component_set<L>& components, - const object_links<L>& links, + object_links_bbox_ratio(const object_links<L>& links, unsigned dim, float max_ratio); @@ -70,19 +68,19 @@ namespace scribo template <typename L> object_links<L> - object_links_bbox_ratio(const component_set<L>& components, - const object_links<L>& links, + object_links_bbox_ratio(const object_links<L>& links, unsigned dim, float max_ratio) { trace::entering("scribo::filter::object_links_bbox_ratio"); - mln_precondition(components.is_valid()); mln_precondition(links.is_valid()); + const component_set<L>& components = links.components(); + object_links<L> output(links); - for (unsigned i = 1; i < links.size(); ++i) - if (links[i] != i) + for (unsigned i = 1; i < links.nelements(); ++i) + if (links(i) != i) { float lmin = components(i).bbox().pmax()[dim] diff --git a/scribo/filter/object_links_bottom_aligned.hh b/scribo/filter/object_links_bottom_aligned.hh index ce6f6af..f1816d4 100644 --- a/scribo/filter/object_links_bottom_aligned.hh +++ b/scribo/filter/object_links_bottom_aligned.hh @@ -37,7 +37,6 @@ # include <scribo/core/macros.hh> # include <scribo/core/object_links.hh> -# include <scribo/core/component_set.hh> # include <scribo/filter/object_links_non_aligned_simple.hh> @@ -52,7 +51,6 @@ namespace scribo /*! \brief Invalidate links between two components if their bottom are not aligned. - \param[in] components A component set. \param[in] links Object links information. \param[in] max_alpha Maximum angle value (degrees). @@ -82,8 +80,7 @@ namespace scribo */ template <typename L> object_links<L> - object_links_bottom_aligned(const component_set<L>& components, - const object_links<L>& links, + object_links_bottom_aligned(const object_links<L>& links, float max_alpha); @@ -92,18 +89,15 @@ namespace scribo template <typename L> object_links<L> - object_links_bottom_aligned(const component_set<L>& components, - const object_links<L>& links, + object_links_bottom_aligned(const object_links<L>& links, float max_alpha) { trace::entering("scribo::filter::object_links_bottom_aligned"); - mln_precondition(components.is_valid()); mln_precondition(links.is_valid()); object_links<L> - output = object_links_non_aligned_simple(components, links, - 2, max_alpha); + output = object_links_non_aligned_simple(links, 2, max_alpha); trace::exiting("scribo::filter::object_links_bottom_aligned"); return output; diff --git a/scribo/filter/object_links_non_aligned_simple.hh b/scribo/filter/object_links_non_aligned_simple.hh index c27bea5..5ecba0f 100644 --- a/scribo/filter/object_links_non_aligned_simple.hh +++ b/scribo/filter/object_links_non_aligned_simple.hh @@ -38,7 +38,6 @@ # include <scribo/core/macros.hh> # include <scribo/core/object_links.hh> -# include <scribo/core/object_image.hh> namespace scribo { @@ -51,7 +50,6 @@ namespace scribo /*! \brief Invalidate links between two non aligned components. Alignment is based on a given edge of object bounding boxes. - \param[in] components A component set. \param[in] links Object links information. \param[in] max_alpha Maximum angle value (degrees). @@ -91,8 +89,7 @@ namespace scribo */ template <typename L> object_links<L> - object_links_non_aligned_simple(const component_set<L>& components, - const object_links<L>& links, + object_links_non_aligned_simple(const object_links<L>& links, unsigned edge, float max_alpha); @@ -102,16 +99,17 @@ namespace scribo template <typename L> object_links<L> - object_links_non_aligned_simple(const component_set<L>& comps, - const object_links<L>& links, + object_links_non_aligned_simple(const object_links<L>& links, unsigned edge, float max_alpha) { trace::entering("scribo::filter::object_links_non_aligned_simple"); - mln_precondition(comps.is_valid()); mln_precondition(links.is_valid()); + + const component_set<L>& comps = links.components(); + object_links<L> output(links); float dr, dc; @@ -123,81 +121,81 @@ namespace scribo { for_all_comps(i, comps) { - if (links[i] != i) + if (links(i) != i) { dr = math::abs(comps(i).bbox().pcenter().row() - - comps(links[i]).bbox().pcenter().row()); + - comps(links(i)).bbox().pcenter().row()); dc = math::abs(comps(i).bbox().pcenter().col() - - comps(links[i]).bbox().pcenter().col()); + - comps(links(i)).bbox().pcenter().col()); if (std::atan(dr / dc) > max_alpha_rad) - output[i] = i; + output(i) = i; } } } // Top else if (edge == 1) { - for_all_comps(i, comps.bboxes()) - if (links[i] != i) + for_all_comps(i, comps) + if (links(i) != i) { dr = math::abs(comps(i).bbox().pmin().row() - - comps(links[i]).bbox().pmin().row()); + - comps(links(i)).bbox().pmin().row()); dc = math::abs(comps(i).bbox().pcenter().col() - - comps(links[i]).bbox().pcenter().col()); + - comps(links(i)).bbox().pcenter().col()); if (std::atan(dr / dc) > max_alpha_rad) - output[i] = i; + output(i) = i; } } // Bottom else if (edge == 2) { - for_all_comps(i, comps.bboxes()) + for_all_comps(i, comps) { - if (links[i] != i) + if (links(i) != i) { dr = math::abs(comps(i).bbox().pmax().row() - - comps(links[i]).bbox().pmax().row()); + - comps(links(i)).bbox().pmax().row()); dc = math::abs(comps(i).bbox().pcenter().col() - - comps(links[i]).bbox().pcenter().col()); + - comps(links(i)).bbox().pcenter().col()); if (std::atan(dr / dc) > max_alpha_rad) - output[i] = i; + output(i) = i; } } } // Left else if (edge == 3) { - for_all_comps(i, comps.bboxes()) + for_all_comps(i, comps) { - if (links[i] != i) + if (links(i) != i) { dr = math::abs(comps(i).bbox().pcenter().row() - - comps(links[i]).bbox().pcenter().row()); + - comps(links(i)).bbox().pcenter().row()); dc = math::abs(comps(i).bbox().pmin().col() - - comps(links[i]).bbox().pmin().col()); + - comps(links(i)).bbox().pmin().col()); if (std::atan(dc / dr) > max_alpha_rad) - output[i] = i; + output(i) = i; } } } // Right else if (edge == 4) { - for_all_comps(i, comps.bboxes()) + for_all_comps(i, comps) { - if (links[i] != i) + if (links(i) != i) { dr = math::abs(comps(i).bbox().pcenter().row() - - comps(links[i]).bbox().pcenter().row()); + - comps(links(i)).bbox().pcenter().row()); dc = math::abs(comps(i).bbox().pmax().col() - - comps(links[i]).bbox().pmax().col()); + - comps(links(i)).bbox().pmax().col()); if (std::atan(dc / dr) > max_alpha_rad) - output[i] = i; + output(i) = i; } } } diff --git a/scribo/filter/object_links_top_aligned.hh b/scribo/filter/object_links_top_aligned.hh index 4a92c96..de5ab3b 100644 --- a/scribo/filter/object_links_top_aligned.hh +++ b/scribo/filter/object_links_top_aligned.hh @@ -36,7 +36,6 @@ # include <scribo/core/macros.hh> # include <scribo/core/object_links.hh> -# include <scribo/core/object_image.hh> # include <scribo/filter/object_links_non_aligned_simple.hh> @@ -51,7 +50,6 @@ namespace scribo /*! \brief Invalidate links between two objects if their top are not aligned. - \param[in] objects An object image. \param[in] links Object links information. \param[in] max_alpha Maximum angle value (degrees). @@ -81,8 +79,7 @@ namespace scribo */ template <typename L> object_links<L> - object_links_top_aligned(const object_image(L)& objects, - const object_links<L>& links, + object_links_top_aligned(const object_links<L>& links, float max_alpha); @@ -91,19 +88,15 @@ namespace scribo template <typename L> object_links<L> - object_links_top_aligned(const object_image(L)& objects, - const object_links<L>& links, + object_links_top_aligned(const object_links<L>& links, float max_alpha) { trace::entering("scribo::filter::object_links_top_aligned"); - mln_precondition(objects.is_valid()); mln_precondition(links.is_valid()); object_links<L> - output = object_links_non_aligned_simple(objects, links, - 1, - max_alpha); + output = object_links_non_aligned_simple(links, 1, max_alpha); trace::exiting("scribo::filter::object_links_top_aligned"); return output; diff --git a/scribo/filter/objects_with_holes.hh b/scribo/filter/objects_with_holes.hh index dc72383..9e781fa 100644 --- a/scribo/filter/objects_with_holes.hh +++ b/scribo/filter/objects_with_holes.hh @@ -532,7 +532,7 @@ namespace scribo true); bool to_remove = false; - for_all_components(i, components) + for_all_comps(i, components) if (components(i).tag() != component::Ignored) { mln_domain(L) b = components(i).bbox(); @@ -549,7 +549,7 @@ namespace scribo c8(), nlabels, accu_t()).second(); unsigned nholes = 0; - for_all_components(j, counts) + for_all_comp_data(j, counts) if (counts(j) > 4u) ++nholes; diff --git a/scribo/primitive/group/apply.hh b/scribo/primitive/group/apply.hh index 26903fe..aff9a95 100644 --- a/scribo/primitive/group/apply.hh +++ b/scribo/primitive/group/apply.hh @@ -53,21 +53,18 @@ namespace scribo /*! \brief Apply grouping in an object image. - \param components A component set. \param groups An object group structure. \return A copy of \p components with grouped components. */ template <typename L> component_set<L> - apply(const component_set<L>& components, - const object_groups<L>& groups); + apply(const object_groups<L>& groups); /// \overload template <typename L> component_set<L> - apply(const component_set<L>& components, - const object_links<L>& links); + apply(const object_links<L>& links); @@ -76,16 +73,14 @@ namespace scribo template <typename L> component_set<L> - apply(const component_set<L>& components, - const object_groups<L>& groups) + apply(const object_groups<L>& groups) { trace::entering("scribo::primitive::group::apply"); - mln_precondition(components.is_valid()); - mln_precondition(groups.nelements() == components.nlabels().next()); - mln_precondition(groups.nelements() == components.bboxes().nelements()); - mln_precondition(groups.components_id_() == components.id_()); + mln_precondition(groups.is_valid()); + + const component_set<L>& components = groups.components(); L labeled_image = duplicate(components.labeled_image()); @@ -94,7 +89,7 @@ namespace scribo packed_relabel_fun = mln::make::relabelfun(groups.comp_to_group(), components.nelements(), new_nlabels); - new_nlabels = components.nelements(); + labeling::relabel_inplace(labeled_image, new_nlabels, packed_relabel_fun); @@ -107,21 +102,15 @@ namespace scribo template <typename L> component_set<L> - apply(const component_set<L>& components, - const object_links<L>& links) + apply(const object_links<L>& links) { trace::entering("scribo::primitive::group::apply"); - mln_precondition(components.is_valid()); - mln_precondition(links.nelements() == components.nlabels().next()); - mln_precondition(links.nelements() == components.bboxes().nelements()); - mln_precondition(links.components_id_() == components.id_()); - - - object_groups<L> group = group::from_single_link(components, links); + mln_precondition(links.is_valid()); - component_set<L> output = apply(components, links); + object_groups<L> group = group::from_single_link(links); + component_set<L> output = apply(group); trace::exiting("scribo::primitive::group::apply"); return output; diff --git a/scribo/primitive/group/from_single_link.hh b/scribo/primitive/group/from_single_link.hh index 128af6c..ffb2938 100644 --- a/scribo/primitive/group/from_single_link.hh +++ b/scribo/primitive/group/from_single_link.hh @@ -61,15 +61,13 @@ namespace scribo \brief Link text components with their neighbor line if they have one. - \param[in] components A component set. - \param[in] link_array The neighbor line of each line. + \param[in] links The neighbor line of each line. \return Object groups information. */ template <typename L> object_groups<L> - from_single_link(const component_set<L>& components, - const object_links<L>& link_array); + from_single_link(const object_links<L>& links); # ifndef MLN_INCLUDE_ONLY @@ -77,26 +75,23 @@ namespace scribo template <typename L> inline object_groups<L> - from_single_link(const component_set<L>& components, - const object_links<L>& link_array) + from_single_link(const object_links<L>& links) { trace::entering("scribo::primitive::group::from_single_link"); - mln_precondition(components.is_valid()); - mln_precondition(link_array.nelements() == components.nelements().next()); - mln_precondition(link_array.components_id_() == components.id_()); + mln_precondition(links.is_valid()); - object_groups<L> parent_array(components); - parent_array.init_(link_array); + object_groups<L> parent(links); + parent.init_(links); - for_all_components(i, parent_array) - if (!components(i).is_valid()) - parent_array(i) = 0; + for_all_groups(i, parent) + if (!links.components()(i).is_valid()) + parent(i) = 0; else - primitive::internal::find_root(parent_array, i); + primitive::internal::find_root(parent, i); trace::exiting("scribo::primitive::group::from_single_link"); - return parent_array; + return parent; } # endif // ! MLN_INCLUDE_ONLY diff --git a/scribo/primitive/internal/init_link_array.hh b/scribo/primitive/internal/init_link_array.hh index aa85175..2b46ad5 100644 --- a/scribo/primitive/internal/init_link_array.hh +++ b/scribo/primitive/internal/init_link_array.hh @@ -58,12 +58,12 @@ namespace scribo void init_link_array(object_links<L>& link_array) { - const component_set<L>& comp_set = link_array.component_set_(); + const component_set<L>& comp_set = link_array.components(); for (unsigned i = 0; i < link_array.nelements(); ++i) if (comp_set(i).tag() == component::Ignored) - link_array[i] = 0; + link_array(i) = 0; else - link_array[i] = i; + link_array(i) = i; } # endif // ! MLN_INCLUDE_ONLY diff --git a/scribo/primitive/internal/is_link_valid.hh b/scribo/primitive/internal/is_link_valid.hh index 34c27b8..5510699 100644 --- a/scribo/primitive/internal/is_link_valid.hh +++ b/scribo/primitive/internal/is_link_valid.hh @@ -52,20 +52,22 @@ namespace scribo /// /// \return True if the link is between the \p i-th component /// and it neighbor is validated. + template <typename L> mln::util::couple<bool,unsigned> - is_link_valid(const mln::util::array<unsigned>& left_link, - const mln::util::array<unsigned>& right_link, + is_link_valid(const object_links<L>& left_link, + const object_links<L>& right_link, unsigned i); # ifndef MLN_INCLUDE_ONLY + template <typename L> mln::util::couple<bool,unsigned> - is_link_valid(const mln::util::array<unsigned>& left_link, - const mln::util::array<unsigned>& right_link, + is_link_valid(const object_links<L>& left_link, + const object_links<L>& right_link, unsigned i) { - bool b = (right_link[left_link[i]] == i && left_link[i] != i); - return mln::make::couple(b, left_link[i]); + bool b = (right_link(left_link(i)) == i && left_link(i) != i); + return mln::make::couple(b, left_link(i)); } # endif // ! MLN_INCLUDE_ONLY diff --git a/scribo/primitive/link/internal/link_functor_base.hh b/scribo/primitive/link/internal/link_functor_base.hh index 65f897c..5e4af46 100644 --- a/scribo/primitive/link/internal/link_functor_base.hh +++ b/scribo/primitive/link/internal/link_functor_base.hh @@ -233,7 +233,7 @@ namespace scribo unsigned link_functor_base<L,E>::link(unsigned object) const { - return links_[object]; + return links_(object); } template <typename L, typename E> @@ -256,9 +256,14 @@ namespace scribo { (void) start_point; mln_value(L) v = this->labeled_image_(p); + bool is_separator = this->components_.separators()(p); + + if (is_separator) + return true; + return v != literal::zero // Not the background && v != current_object // Not the current component - && this->links_[v] != current_object // No loops + && this->links_(v) != current_object // No loops && this->components_(v).tag() != component::Ignored; // Not ignored } @@ -288,8 +293,12 @@ namespace scribo const P& start_point, const P& p) const { - return exact(this)->verify_link_criterion_(current_object, - start_point, p); + return + // Do not link with separators... + ! this->components_.separators()(p) + // ... and perform custom checks. + && exact(this)->verify_link_criterion_(current_object, + start_point, p); } template <typename L, typename E> @@ -471,7 +480,7 @@ namespace scribo { (void) start_point; (void) anchor; - this->links_[current_object] = this->labeled_image_(p); + this->links_(current_object) = this->labeled_image_(p); } diff --git a/scribo/primitive/link/internal/link_single_dmax_base.hh b/scribo/primitive/link/internal/link_single_dmax_base.hh index b94da8e..6897bd6 100644 --- a/scribo/primitive/link/internal/link_single_dmax_base.hh +++ b/scribo/primitive/link/internal/link_single_dmax_base.hh @@ -146,8 +146,8 @@ namespace scribo unsigned current_object) { float - midcol = (this->components_.bbox(current_object).pmax()[direction_] - - this->components_.bbox(current_object).pmin()[direction_]) / 2; + midcol = (this->components_(current_object).bbox().pmax()[direction_] + - this->components_(current_object).bbox().pmin()[direction_]) / 2; dmax_ = midcol + neighb_max_distance_; } diff --git a/scribo/primitive/link/merge_double_link.hh b/scribo/primitive/link/merge_double_link.hh index 0628cd6..704c103 100644 --- a/scribo/primitive/link/merge_double_link.hh +++ b/scribo/primitive/link/merge_double_link.hh @@ -64,7 +64,6 @@ namespace scribo \brief Validate and merge double link information. A link must exist in both ways to be validated. - \param[in] components The Lines of text. \param[in] left_link The left neighbor of each line of text. \param[in] right_link The right neighbor of each line of text. @@ -72,8 +71,7 @@ namespace scribo */ template <typename L> object_links<L> - merge_double_link(const component_set<L>& components, - const object_links<L>& left_link, + merge_double_link(const object_links<L>& left_link, const object_links<L>& right_link); @@ -84,31 +82,30 @@ namespace scribo template <typename L> inline object_links<L> - merge_double_link(const component_set<L>& components, - const object_links<L>& left_link, + merge_double_link(const object_links<L>& left_link, const object_links<L>& right_link) { trace::entering("scribo::primitive::link::merge_double_link"); - mln_precondition(components.is_valid()); - mln_precondition(left_link.nelements() == right_link.nelements()); - mln_precondition(left_link.components_id_() == components.id_()); - mln_precondition(right_link.components_id_() == components.id_()); + mln_precondition(left_link.is_valid()); + mln_precondition(right_link.is_valid()); + mln_precondition(left_link.components() == right_link.components()); + const component_set<L>& components = left_link.components(); object_links<L> merge(left_link); for_all_ncomponents(i, components.nelements()) { if (components(i).tag() == component::Ignored) - merge[i] = 0; + merge(i) = 0; else { mln::util::couple<bool, unsigned> nbh = primitive::internal::is_link_valid(left_link, right_link, i); if (!nbh.first()) - merge[i] = i; + merge(i) = i; } } diff --git a/scribo/primitive/link/with_single_right_link_bottom.hh b/scribo/primitive/link/with_single_right_link_bottom.hh index 747e15c..85f6b50 100644 --- a/scribo/primitive/link/with_single_right_link_bottom.hh +++ b/scribo/primitive/link/with_single_right_link_bottom.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,7 +29,7 @@ /// \file /// -/// Link text objects with their right neighbor. +/// Link text components with their right neighbor. # include <mln/core/concept/image.hh> @@ -41,7 +42,6 @@ # include <scribo/core/macros.hh> # include <scribo/core/tag/anchor.hh> -# include <scribo/core/object_image.hh> # include <scribo/core/object_links.hh> # include <scribo/primitive/link/internal/find_link.hh> @@ -59,10 +59,10 @@ namespace scribo namespace link { - /// \brief Link objects with their right neighbor if exists. + /// \brief Link components with their right neighbor if exists. /// Lookup startup point is the object bottom center. /// - /// \param[in] objects An object image. + /// \param[in] components A component set. /// \param[in] The maximum distance allowed to seach a neighbor object. /// /// \return Object links data. @@ -70,7 +70,7 @@ namespace scribo template <typename L> inline object_links<L> - with_single_right_link_bottom(const object_image(L)& objects, + with_single_right_link_bottom(const component_set<L>& components, unsigned neighb_max_distance); @@ -79,7 +79,7 @@ namespace scribo template <typename L> inline object_links<L> - with_single_right_link_bottom(const object_image(L)& objects); + with_single_right_link_bottom(const component_set<L>& components); @@ -103,9 +103,9 @@ namespace scribo public: typedef mln_site(L) P; - single_right_bottom_functor(const object_image(L)& objects, + single_right_bottom_functor(const component_set<L>& components, unsigned dmax) - : super_(objects, dmax) + : super_(components, dmax, anchor::Horizontal) { } @@ -125,15 +125,15 @@ namespace scribo template <typename L> inline object_links<L> - with_single_right_link_bottom(const object_image(L)& objects, + with_single_right_link_bottom(const component_set<L>& components, unsigned neighb_max_distance) { trace::entering("scribo::primitive::link::with_single_right_link_bottom"); - mln_precondition(objects.is_valid()); + mln_precondition(components.is_valid()); internal::single_right_bottom_functor<L> - functor(objects, neighb_max_distance); + functor(components, neighb_max_distance); object_links<L> output = compute(functor, anchor::Bottom); @@ -145,9 +145,9 @@ namespace scribo template <typename L> inline object_links<L> - with_single_right_link_bottom(const object_image(L)& objects) + with_single_right_link_bottom(const component_set<L>& components) { - return with_single_right_link_bottom(objects, mln_max(unsigned)); + return with_single_right_link_bottom(components, mln_max(unsigned)); } diff --git a/scribo/primitive/link/with_single_right_link_dmax_ratio.hh b/scribo/primitive/link/with_single_right_link_dmax_ratio.hh index 858346e..d3637ef 100644 --- a/scribo/primitive/link/with_single_right_link_dmax_ratio.hh +++ b/scribo/primitive/link/with_single_right_link_dmax_ratio.hh @@ -61,7 +61,9 @@ namespace scribo /*! \brief Link objects with their right neighbor if exists. \param[in] components A component set. - \param[in] dmax_ratio + \param[in] dmax_ratio Size ratio defining the maximum lookup + distance. + \param[in] anchor Starting point for the neighbor lookup. \return Object links data. @@ -77,11 +79,20 @@ namespace scribo inline object_links<L> with_single_right_link_dmax_ratio(const component_set<L>& components, + float dmax_ratio, anchor::Type anchor); + + /// \overload + /// anchor is set to MassCenter. + template <typename L> + inline + object_links<L> + with_single_right_link_dmax_ratio(const component_set<L>& components, float dmax_ratio); /// \overload /// dmax_ratio is set to 3. + /// anchor is set to MassCenter. template <typename L> inline object_links<L> @@ -127,11 +138,12 @@ namespace scribo // Facades + template <typename L> inline object_links<L> with_single_right_link_dmax_ratio(const component_set<L>& components, - float dmax_ratio) + float dmax_ratio, anchor::Type anchor) { trace::entering("scribo::primitive::link::with_single_right_link_dmax_ratio"); @@ -140,13 +152,25 @@ namespace scribo internal::single_right_dmax_ratio_functor<L> functor(components, dmax_ratio); - object_links<L> output = compute(functor); + object_links<L> output = compute(functor, anchor); trace::exiting("scribo::primitive::link::with_single_right_link_dmax_ratio"); return output; } + + template <typename L> + inline + object_links<L> + with_single_right_link_dmax_ratio(const component_set<L>& components, + float dmax_ratio) + { + return with_single_right_link_dmax_ratio(components, dmax_ratio, + anchor::MassCenter); + } + + template <typename L> inline object_links<L> diff --git a/scribo/primitive/link/with_single_right_link_top.hh b/scribo/primitive/link/with_single_right_link_top.hh index 14a4f37..6d26114 100644 --- a/scribo/primitive/link/with_single_right_link_top.hh +++ b/scribo/primitive/link/with_single_right_link_top.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,7 +42,7 @@ # include <scribo/core/macros.hh> # include <scribo/core/tag/anchor.hh> -# include <scribo/core/object_image.hh> +# include <scribo/core/component_set.hh> # include <scribo/core/object_links.hh> # include <scribo/primitive/link/internal/find_link.hh> @@ -70,7 +71,7 @@ namespace scribo template <typename L> inline object_links<L> - with_single_right_link_top(const object_image(L)& objects, + with_single_right_link_top(const component_set<L>& objects, unsigned neighb_max_distance); @@ -79,7 +80,7 @@ namespace scribo template <typename L> inline object_links<L> - with_single_right_link_top(const object_image(L)& objects); + with_single_right_link_top(const component_set<L>& objects); @@ -103,9 +104,9 @@ namespace scribo public: typedef mln_site(L) P; - single_right_top_functor(const object_image(L)& objects, + single_right_top_functor(const component_set<L>& objects, unsigned dmax) - : super_(objects, dmax) + : super_(objects, dmax, anchor::Horizontal) { } @@ -125,7 +126,7 @@ namespace scribo template <typename L> inline object_links<L> - with_single_right_link_top(const object_image(L)& objects, + with_single_right_link_top(const component_set<L>& objects, unsigned neighb_max_distance) { trace::entering("scribo::primitive::link::with_single_right_link_top"); @@ -145,7 +146,7 @@ namespace scribo template <typename L> inline object_links<L> - with_single_right_link_top(const object_image(L)& objects) + with_single_right_link_top(const component_set<L>& objects) { return with_single_right_link_top(objects, mln_max(unsigned)); } diff --git a/scribo/src/afp/link.hh b/scribo/src/afp/link.hh index 66115d0..b6ef1f9 100644 --- a/scribo/src/afp/link.hh +++ b/scribo/src/afp/link.hh @@ -60,9 +60,9 @@ namespace scribo { if (*p != literal::zero // Not the background && *p != i // Not the current component - && right[*p] != i) // No loops + && right(*p) != i) // No loops { - right[i] = *p; + right(i) = *p; break; } } @@ -79,9 +79,9 @@ namespace scribo { if (*p != literal::zero // Not the background && *p != i // Not the current component - && left[*p] != i) // No loops + && left(*p) != i) // No loops { - left[i] = *p; + left(i) = *p; break; } } @@ -123,9 +123,9 @@ namespace scribo { if (*p != literal::zero // Not the background && *p != i // Not the current component - && left[*p] != i) // No loops + && left(*p) != i) // No loops { - left[i] = *p; + left(i) = *p; break; } } diff --git a/scribo/src/afp/regroup.hh b/scribo/src/afp/regroup.hh index 2de36b9..3fcfcaa 100644 --- a/scribo/src/afp/regroup.hh +++ b/scribo/src/afp/regroup.hh @@ -28,7 +28,7 @@ namespace scribo new_groups(components, static_cast<unsigned>(components.nlabels()) + 1, 0); unsigned ngroups = 0; - for_all_components(i, components.bboxes()) + for_all_comps(i, components) { if (groups[i] == 0) continue; diff --git a/scribo/text/recognition.hh b/scribo/text/recognition.hh index 364e56b..5927d44 100644 --- a/scribo/text/recognition.hh +++ b/scribo/text/recognition.hh @@ -143,7 +143,7 @@ namespace scribo data::fill(text_ima, true); // Careful : background is set to 'False' - const component_set<L>& comp_set = lines.component_set_(); + const component_set<L>& comp_set = lines.components(); const L& lbl = comp_set.labeled_image(); const mln::util::array<component_id_t>& comps = lines(i).components(); -- 1.5.6.5
participants (1)
-
Guillaume Lazzara