last-svn-commit-24-gc7f2301 Improve linking routines.

* core/anchors.hh: New. Add anchor types. * filter/objects_thin.hh: Use filter::internal::compute. * primitive/link/internal/find_several_links.hh, * primitive/link/internal/find_link.hh, * primitive/link/compute.hh: Update functor interface in order to specify anchors. * primitive/link/compute_several.hh: Fix an invalid namespace. * primitive/link/internal/anchors_3.hh: Move... * primitive/link/internal/compute_anchor.hh: ... here. * primitive/link/internal/link_functor_base.hh: Use anchor type. * primitive/link/internal/link_several_dmax_base.hh: New. * primitive/link/internal/link_center_dmax_base.hh, * primitive/link/internal/link_center_dmax_ratio_base.hh: Removed. * primitive/link/with_several_right_links_overlap.hh: Fix includes. * primitive/link/with_single_right_link_bottom.hh, * primitive/link/with_single_right_link_top.hh, * primitive/link/with_single_left_link.hh, * primitive/link/with_single_right_link.hh: Use link_single_dmax_base functor. * src/debug/show_links_several_right_overlap.cc, * src/debug/show_links_single_left.cc, * src/debug/show_links_single_left_dmax_ratio.cc, * src/debug/show_links_single_right.cc, * src/debug/show_links_single_right_dmax_ratio.cc: Update functor interface. --- scribo/ChangeLog | 41 +++ scribo/{util/all.hh => core/anchors.hh} | 26 +- scribo/filter/objects_thin.hh | 7 +- scribo/primitive/link/compute.hh | 39 ++- scribo/primitive/link/compute_several.hh | 2 +- .../internal/{anchors_3.hh => compute_anchor.hh} | 56 +++-- scribo/primitive/link/internal/find_link.hh | 14 +- .../primitive/link/internal/find_several_links.hh | 102 +++++---- .../primitive/link/internal/link_functor_base.hh | 56 +++-- .../link/internal/link_several_dmax_base.hh | 265 ++++++++++++++++++++ ...enter_dmax_base.hh => link_single_dmax_base.hh} | 57 ++--- ...atio_base.hh => link_single_dmax_ratio_base.hh} | 43 ++-- .../link/with_several_right_links_overlap.hh | 10 +- scribo/primitive/link/with_single_left_link.hh | 6 +- scribo/primitive/link/with_single_right_link.hh | 9 +- .../link/with_single_right_link_bottom.hh | 13 +- .../primitive/link/with_single_right_link_top.hh | 17 +- .../src/debug/show_links_several_right_overlap.cc | 51 ++-- scribo/src/debug/show_links_single_left.cc | 4 +- .../src/debug/show_links_single_left_dmax_ratio.cc | 4 +- scribo/src/debug/show_links_single_right.cc | 4 +- .../debug/show_links_single_right_dmax_ratio.cc | 4 +- 22 files changed, 586 insertions(+), 244 deletions(-) copy scribo/{util/all.hh => core/anchors.hh} (82%) rename scribo/primitive/link/internal/{anchors_3.hh => compute_anchor.hh} (75%) create mode 100644 scribo/primitive/link/internal/link_several_dmax_base.hh rename scribo/primitive/link/internal/{link_center_dmax_base.hh => link_single_dmax_base.hh} (73%) rename scribo/primitive/link/internal/{link_center_dmax_ratio_base.hh => link_single_dmax_ratio_base.hh} (79%) diff --git a/scribo/ChangeLog b/scribo/ChangeLog index 0fcd35f..2897a58 100644 --- a/scribo/ChangeLog +++ b/scribo/ChangeLog @@ -1,3 +1,44 @@ +2009-12-14 Guillaume Lazzara <z@lrde.epita.fr> + + Improve linking routines. + + * core/anchors.hh: New. Add anchor types. + + * filter/objects_thin.hh: Use filter::internal::compute. + + * primitive/link/internal/find_several_links.hh, + * primitive/link/internal/find_link.hh, + * primitive/link/compute.hh: Update functor interface in order to + specify anchors. + + * primitive/link/compute_several.hh: Fix an invalid namespace. + + * primitive/link/internal/anchors_3.hh: Move... + + * primitive/link/internal/compute_anchor.hh: ... here. + + * primitive/link/internal/link_functor_base.hh: Use anchor type. + + * primitive/link/internal/link_several_dmax_base.hh: New. + + * primitive/link/internal/link_center_dmax_base.hh, + * primitive/link/internal/link_center_dmax_ratio_base.hh: Removed. + + * primitive/link/with_several_right_links_overlap.hh: Fix includes. + + * primitive/link/with_single_right_link_bottom.hh, + * primitive/link/with_single_right_link_top.hh, + * primitive/link/with_single_left_link.hh, + * primitive/link/with_single_right_link.hh: Use + link_single_dmax_base functor. + + * src/debug/show_links_several_right_overlap.cc, + * src/debug/show_links_single_left.cc, + * src/debug/show_links_single_left_dmax_ratio.cc, + * src/debug/show_links_single_right.cc, + * src/debug/show_links_single_right_dmax_ratio.cc: Update functor + interface. + 2009-12-11 Guillaume Lazzara <z@lrde.epita.fr> Improve Sauvola Multi-scale. diff --git a/scribo/util/all.hh b/scribo/core/anchors.hh similarity index 82% copy from scribo/util/all.hh copy to scribo/core/anchors.hh index 3eef9ff..a2994b1 100644 --- a/scribo/util/all.hh +++ b/scribo/core/anchors.hh @@ -23,24 +23,26 @@ // exception does not however invalidate any other reasons why the // executable file might be covered by the GNU General Public License. -#ifndef SCRIBO_UTIL_ALL_HH -# define SCRIBO_UTIL_ALL_HH - -/// \file -/// -/// Include all headers located in scribo/util. +#ifndef SCRIBO_CORE_ANCHORS_HH +# define SCRIBO_CORE_ANCHORS_HH namespace scribo { - /// Namespace of useful classes and routines. - namespace util + namespace anchor { - } // end of namespace scribo::util + enum Type + { + MassCenter = 0, + Top, + Bottom, + Center, + Invalid + }; -} // end of namespace scribo + } -# include <scribo/util/text.hh> +} // end of namespace scribo -#endif // ! SCRIBO_UTIL_ALL_HH +#endif // ! SCRIBO_CORE_ANCHORS_HH diff --git a/scribo/filter/objects_thin.hh b/scribo/filter/objects_thin.hh index e9c869b..ea8a5af 100644 --- a/scribo/filter/objects_thin.hh +++ b/scribo/filter/objects_thin.hh @@ -39,6 +39,7 @@ # include <scribo/core/object_image.hh> # include <scribo/primitive/extract/objects.hh> +# include <scribo/filter/internal/compute.hh> namespace scribo { @@ -91,8 +92,6 @@ namespace scribo struct objects_thin_filter : Function_v2b< objects_thin_filter<L> > { - typedef accu::shape::bbox<mln_psite(L)> box_accu_t; - /// Constructor /// /// \param[in] objects object bounding boxes. @@ -175,9 +174,7 @@ namespace scribo typedef internal::objects_thin_filter<L> func_t; func_t is_not_too_thin(objects, min_thickness); - object_image(L) output; - output.init_from_(objects); - output.relabel(is_not_too_thin); + object_image(L) output = internal::compute(objects, is_not_too_thin); trace::exiting("scribo::filter::objects_thin"); return output; diff --git a/scribo/primitive/link/compute.hh b/scribo/primitive/link/compute.hh index bf94787..349721c 100644 --- a/scribo/primitive/link/compute.hh +++ b/scribo/primitive/link/compute.hh @@ -55,39 +55,44 @@ namespace scribo Functors must implement the following interface : - bool is_potential_link(unsigned current_object, + bool is_potential_link_(unsigned current_object, const P& start_point, const P& p) const - bool valid_link(unsigned current_object, + bool valid_link_(unsigned current_object, const P& start_point, const P& p) - bool verify_link_criterion(unsigned current_object, + bool verify_link_criterion_(unsigned current_object, const P& start_point, const P& p) - void validate_link(unsigned current_object, - const P& start_point, const P& p) + void validate_link_(unsigned current_object, + const P& start_point, const P& p, unsigned anchor) - void invalidate_link(unsigned current_object, - const P& start_point, const P& p) + void invalidate_link_(unsigned current_object, + const P& start_point, const P& p, unsigned anchor) - void compute_next_site(P& p) + void compute_next_site_(P& p) - const mln_site(L)& start_point(unsigned current_object) + const mln_site(L)& start_point_(unsigned current_object, unsigned anchor) - void start_processing_object(unsigned current_object) + void start_processing_object_(unsigned current_object) */ template <typename F> object_links<scribo_support(F)> - compute(Link_Functor<F>& functor); + compute(Link_Functor<F>& functor, anchor::Type anchor); + /// \overload + /// The default anchor is set to 0, the mass center. + template <typename F> + object_links<scribo_support(F)> + compute(Link_Functor<F>& functor); # ifndef MLN_INCLUDE_ONLY template <typename F> object_links<scribo_support(F)> - compute(Link_Functor<F>& functor_) + compute(Link_Functor<F>& functor_, anchor::Type anchor) { trace::entering("scribo::primitive::link::compute"); @@ -96,7 +101,7 @@ namespace scribo for_all_ncomponents(current_object, functor.objects().nlabels()) { functor.start_processing_object(current_object); //<-- start_processing_object - primitive::internal::find_link(functor, current_object); + primitive::internal::find_link(functor, current_object, anchor); } trace::exiting("scribo::primitive::link::compute"); @@ -104,6 +109,14 @@ namespace scribo } + template <typename F> + object_links<scribo_support(F)> + compute(Link_Functor<F>& functor) + { + return compute(functor, anchor::MassCenter); + } + + # endif // ! MLN_INCLUDE_ONLY } // end of namespace scribo::primitive::link diff --git a/scribo/primitive/link/compute_several.hh b/scribo/primitive/link/compute_several.hh index 0597d99..929a7cb 100644 --- a/scribo/primitive/link/compute_several.hh +++ b/scribo/primitive/link/compute_several.hh @@ -98,7 +98,7 @@ namespace scribo for_all_ncomponents(current_object, functor.objects().nlabels()) { functor.start_processing_object(current_object); //<-- start_processing_object - primitive::internal::find_several_links(functor, current_object); + internal::find_several_links(functor, current_object); } trace::exiting("scribo::primitive::link::compute_several"); diff --git a/scribo/primitive/link/internal/anchors_3.hh b/scribo/primitive/link/internal/compute_anchor.hh similarity index 75% rename from scribo/primitive/link/internal/anchors_3.hh rename to scribo/primitive/link/internal/compute_anchor.hh index 85fa80b..c7bae11 100644 --- a/scribo/primitive/link/internal/anchors_3.hh +++ b/scribo/primitive/link/internal/compute_anchor.hh @@ -23,14 +23,15 @@ // exception does not however invalidate any other reasons why the // executable file might be covered by the GNU General Public License. -#ifndef SCRIBO_PRIMITIVE_LINK_INTERNAL_ANCHORS_3_HH -# define SCRIBO_PRIMITIVE_LINK_INTERNAL_ANCHORS_3_HH +#ifndef SCRIBO_PRIMITIVE_LINK_INTERNAL_COMPUTE_ANCHOR_HH +# define SCRIBO_PRIMITIVE_LINK_INTERNAL_COMPUTE_ANCHOR_HH /// \file /// -/// Routine providing 3 anchors for neighbor seeking. +/// Routine providing anchors for neighbor seeking. # include <mln/math/min.hh> +# include <mln/util/array.hh> # include <scribo/core/object_image.hh> @@ -46,20 +47,20 @@ namespace scribo namespace internal { + using namespace mln; /*! \brief Return the proper anchor used to find a neighbor. - This routine provides up to 3 different anchors. - \param[in] objects An object image. \param[in] mass_centers Object mass centers. \param[in] current_object An object id. \param[in] anchor The expected anchor. Anchor can take one of the following values: - - 0, top anchor. - - 1, center anchor. It is the mass center. - - 2, bottom anchor. + - anchor::MassCenter, mass center anchor. + - anchor::Top, top anchor. + - anchor::Bottom, bottom anchor. + - anchor::Center, center anchor. Top and bottom anchors are respectively computed from the @@ -77,53 +78,56 @@ namespace scribo */ template <typename L, typename P> mln_site(L) - anchors_3(const object_image(L)& objects, - const mln::util::array<P>& mass_centers, - unsigned current_object, unsigned anchor); + compute_anchor(const object_image(L)& objects, + const mln::util::array<P>& mass_centers, + unsigned current_object, anchor::Type anchor); # ifndef MLN_INCLUDE_ONLY template <typename L, typename P> mln_site(L) - anchors_3(const object_image(L)& objects, - const mln::util::array<P>& mass_centers, - unsigned current_object, unsigned anchor) + compute_anchor(const object_image(L)& objects, + const mln::util::array<P>& mass_centers, + unsigned current_object, anchor::Type anchor) { unsigned h = objects.bbox(current_object).pmax().row() - objects.bbox(current_object).pmin().row(); mln_site(L) sp = objects.bbox(current_object).center(); - def::coord r; + def::coord r = 0; switch (anchor) { + // Masss Center + case anchor::MassCenter: + return mass_centers(current_object); + + // Top - case 0: + case anchor::Top: if (h < 30) r = objects.bbox(current_object).pmin().row() + math::min(2u, (h + 1) / 2 - 1); else r = objects.bbox(current_object).pmin().row() - - math::min(10u, h /10); + + math::min(10u, h /10); break; - // Center - case 1: - return mass_centers(current_object); - - - // Bottom - case 2: + // Bottom + case anchor::Bottom: if (h < 30) r = objects.bbox(current_object).pmax().row() - + math::min(2u, (h + 1) / 2 - 1); + - math::min(2u, (h + 1) / 2 - 1); else r = objects.bbox(current_object).pmax().row() - math::min(10u, h /10); break; + case anchor::Center: + return objects.bbox(current_object).center(); + default: trace::warning("Non handled anchor"); mln_assertion(anchor > 2); @@ -143,4 +147,4 @@ namespace scribo } // end of namespace scribo -#endif // ! SCRIBO_PRIMITIVE_LINK_INTERNAL_ANCHORS_3_HH +#endif // ! SCRIBO_PRIMITIVE_LINK_INTERNAL_COMPUTE_ANCHOR_HH diff --git a/scribo/primitive/link/internal/find_link.hh b/scribo/primitive/link/internal/find_link.hh index 8a2544e..b950280 100644 --- a/scribo/primitive/link/internal/find_link.hh +++ b/scribo/primitive/link/internal/find_link.hh @@ -38,6 +38,7 @@ # include <mln/util/couple.hh> # include <scribo/core/concept/link_functor.hh> +# include <scribo/core/anchors.hh> # include <scribo/core/object_image.hh> # include <scribo/core/object_links.hh> # include <scribo/primitive/internal/update_link_array.hh> @@ -59,27 +60,30 @@ namespace scribo \param[in,out] functor Functor used to compute the links. Stores the results. \param[in] current_object Current object id. + \param[in] anchor The lookup anchor. \return A couple. The first argument tells whether a valid link has been found, the second one is link anchor if exists. */ template <typename F> mln::util::couple<bool, mln_site(scribo_support_(F))> - find_link(Link_Functor<F>& functor, unsigned current_object); + find_link(Link_Functor<F>& functor, unsigned current_object, + anchor::Type anchor); # ifndef MLN_INCLUDE_ONLY template <typename F> mln::util::couple<bool, mln_site(scribo_support_(F))> - find_link(Link_Functor<F>& functor_, unsigned current_object) + find_link(Link_Functor<F>& functor_, unsigned current_object, + anchor::Type anchor) { F& functor = exact(functor_); functor.initialize_link(current_object); // <-- initialize_link mln_site(scribo_support_(F)) - start_point = functor.start_point(current_object), + start_point = functor.start_point(current_object, anchor), // <-- start_point p = start_point; mln_postcondition(p == start_point); @@ -93,9 +97,9 @@ namespace scribo functor.compute_next_site(p); // <-- compute_next_site if (functor.valid_link(current_object, start_point, p)) // <-- valid_link - functor.validate_link(current_object, start_point, p); // <-- validate_link + functor.validate_link(current_object, start_point, p, anchor); // <-- validate_link else - functor.invalidate_link(current_object, start_point, p); // <-- invalidate_link + functor.invalidate_link(current_object, start_point, p, anchor); // <-- invalidate_link functor.finalize_link(current_object); // <-- finalize_link diff --git a/scribo/primitive/link/internal/find_several_links.hh b/scribo/primitive/link/internal/find_several_links.hh index a07ee70..a690f10 100644 --- a/scribo/primitive/link/internal/find_several_links.hh +++ b/scribo/primitive/link/internal/find_several_links.hh @@ -29,6 +29,9 @@ /// \file /// /// Find the neighbor of a line of text if exists. +/// +/// \fixme do not iterate over the number of anchor types but use a +/// set of anchors specified in the functor. # include <mln/core/concept/image.hh> @@ -38,6 +41,7 @@ # include <mln/util/couple.hh> # include <scribo/core/concept/link_functor.hh> +# include <scribo/core/anchors.hh> # include <scribo/core/object_image.hh> # include <scribo/core/object_links.hh> # include <scribo/primitive/internal/update_link_array.hh> @@ -51,70 +55,82 @@ namespace scribo namespace primitive { - namespace internal + namespace link { - /*! Find the neighbor of a line of text if exists. + namespace internal + { + + /*! Find the neighbor of a line of text if exists. - \param[in,out] functor Functor used to compute the - links. Stores the results. - \param current_object Current object id. + \param[in,out] functor Functor used to compute the + links. Stores the results. + \param current_object Current object id. - \return A couple. The first argument tells whether a valid - link has been found, the second one is link anchor if exists. - */ - template <typename F> - mln::util::couple<bool, mln_site(scribo_support_(F))> - find_several_links(Link_Functor<F>& functor, - unsigned current_object); + \return A couple. The first argument tells whether a valid + link has been found, the second one is link anchor if exists. + */ + template <typename F> + mln::util::couple<bool, + mln::util::couple<anchor::Type, + mln_site(scribo_support_(F))> > + find_several_links(Link_Functor<F>& functor, + unsigned current_object); # ifndef MLN_INCLUDE_ONLY - template <typename F> - mln::util::couple<bool, mln_site(scribo_support_(F))> - find_several_links(Link_Functor<F>& functor_, - unsigned current_object) - { - F& functor = exact(functor_); + template <typename F> + mln::util::couple<bool, + mln::util::couple<anchor::Type, + mln_site(scribo_support_(F))> > + find_several_links(Link_Functor<F>& functor_, + unsigned current_object) + { + F& functor = exact(functor_); - typedef mln_site(scribo_support_(F)) P; - typedef mln::util::couple<unsigned, P> link_t; + typedef mln_site(scribo_support_(F)) P; + typedef mln::util::couple<anchor::Type, P> link_t; - P lp = functor.initialize_link(current_object); // <-- initialize_link + functor.initialize_link(current_object); // <-- initialize_link - for (unsigned anchor = 0; anchor < functor.nanchors(); ++anchor) // <-- nanchor - { - mln_site(scribo_support_(F)) - start_point = functor.start_point(current_object, anchor), // <-- start_point - p = start_point; + for (unsigned anchor_ = 0; anchor_ < functor.nanchors(); ++anchor_) // <-- nanchor + { + // FIXME : See fixme at the beginning of this file. + anchor::Type anchor = static_cast<anchor::Type>(anchor_); - mln_postcondition(p == start_point); + mln_site(scribo_support_(F)) + start_point = functor.start_point(current_object, anchor), // <-- start_point + p = start_point; - while (functor.objects().domain().has(p) - && ! functor.is_potential_link(current_object, - start_point, p) // <-- is_potential_link - && functor.verify_link_criterion(current_object, - start_point, p)) // <-- verify_link_criterion - functor.compute_next_site(p); // <-- compute_next_site + mln_postcondition(p == start_point); - if (functor.valid_link(current_object, start_point, p)) // <-- valid_link - functor.validate_link(current_object, start_point, p, anchor); // <-- validate_link - else - functor.invalidate_link(current_object, start_point, p, anchor); // <-- invalidate_link + while (functor.objects().domain().has(p) + && ! functor.is_potential_link(current_object, + start_point, p) // <-- is_potential_link + && functor.verify_link_criterion(current_object, + start_point, p)) // <-- verify_link_criterion + functor.compute_next_site(p); // <-- compute_next_site - } + if (functor.valid_link(current_object, start_point, p)) // <-- valid_link + functor.validate_link(current_object, start_point, p, anchor); // <-- validate_link + else + functor.invalidate_link(current_object, start_point, p, anchor); // <-- invalidate_link - P lp = functor.finalize_link(current_object); + } - bool b = (functor.link(current_object) != current_object); // <-- link - return mln::make::couple(b, lp); - } + link_t l = functor.finalize_link(current_object); + + bool b = (functor.link(current_object) != current_object); // <-- link + return mln::make::couple(b, l); + } # endif // MLN_INCLUDE_ONLY - } // end of namespace scribo::primitive::internal + } // end of namespace scribo::primitive::link::internal + + } // end of namespace scribo::primitive::link } // end of namespace scribo::primitive diff --git a/scribo/primitive/link/internal/link_functor_base.hh b/scribo/primitive/link/internal/link_functor_base.hh index e35f52d..dcc43d4 100644 --- a/scribo/primitive/link/internal/link_functor_base.hh +++ b/scribo/primitive/link/internal/link_functor_base.hh @@ -37,14 +37,18 @@ # include <mln/util/array.hh> # include <mln/util/couple.hh> +# include <mln/labeling/compute.hh> +# include <mln/accu/center.hh> + +# include <scribo/core/anchors.hh> # include <scribo/core/object_image.hh> # include <scribo/core/object_links.hh> # include <scribo/core/concept/link_functor.hh> +# include <scribo/primitive/link/internal/compute_anchor.hh> # include <scribo/primitive/internal/update_link_array.hh> # include <scribo/primitive/internal/init_link_array.hh> # include <scribo/primitive/internal/is_invalid_link.hh> - # define scribo_support(T) typename T::support # define scribo_support_(T) T::support @@ -68,6 +72,7 @@ namespace scribo typedef L support; typedef mln_site(L) P; + typedef mln::util::couple<anchor::Type, P> couple_t; link_functor_base(const object_image(L)& objects, unsigned nanchors); @@ -85,7 +90,7 @@ namespace scribo void initialize_link(unsigned current_object); - mln_site(L) finalize_link(unsigned current_object); + couple_t finalize_link(unsigned current_object); bool verify_link_criterion(unsigned current_object, @@ -106,7 +111,7 @@ namespace scribo void validate_link(unsigned current_object, const P& start_point, const P& p, - unsigned anchor); + anchor::Type anchor); /// \overload /// \p anchor is set to 0. @@ -115,7 +120,7 @@ namespace scribo void invalidate_link(unsigned current_object, const P& start_point, const P& p, - unsigned anchor); + anchor::Type anchor); /// \overload /// \p anchor is set to 0 @@ -130,7 +135,7 @@ namespace scribo void compute_next_site(P& p); - mln_site(L) start_point(unsigned current_object, unsigned anchor); + mln_site(L) start_point(unsigned current_object, anchor::Type anchor); /// \overload /// \p anchor is set to 0. @@ -146,7 +151,7 @@ namespace scribo // methods. void initialize_link_(unsigned current_object); - mln_site(L) finalize_link_(unsigned current_object); + couple_t finalize_link_(unsigned current_object); bool is_potential_link_(unsigned current_object, const P& start_point, const P& p) const; @@ -159,21 +164,24 @@ namespace scribo void validate_link_(unsigned current_object, const P& start_point, const P& p, - unsigned anchor); + anchor::Type anchor); void invalidate_link_(unsigned current_object, const P& start_point, const P& p, - unsigned anchor); + anchor::Type anchor); void compute_next_site_(P& p); void start_processing_object_(unsigned current_object); + mln_site(L) start_point_(unsigned current_object, + anchor::Type anchor); protected: object_links<L> links_; const object_image(L) objects_; unsigned nanchors_; + util::array<mln_result(accu::center<mln_site(L)>)> mass_centers_; }; @@ -191,6 +199,9 @@ namespace scribo nanchors_(nanchors) { primitive::internal::init_link_array(links_); + + mass_centers_ = labeling::compute(accu::meta::center(), + objects, objects.nlabels()); } @@ -203,6 +214,9 @@ namespace scribo nanchors_(1) { primitive::internal::init_link_array(links_); + + mass_centers_ = labeling::compute(accu::meta::center(), + objects, objects.nlabels()); } @@ -266,7 +280,7 @@ namespace scribo template <typename L, typename E> inline - mln_site(L) + mln::util::couple<anchor::Type, mln_site(L)> link_functor_base<L,E>::finalize_link(unsigned current_object) { return exact(this)->finalize_link_(current_object); @@ -303,7 +317,7 @@ namespace scribo link_functor_base<L,E>::validate_link(unsigned current_object, const P& start_point, const P& p, - unsigned anchor) + anchor::Type anchor) { exact(this)->validate_link_(current_object, start_point, p, anchor); } @@ -327,7 +341,7 @@ namespace scribo link_functor_base<L,E>::invalidate_link(unsigned current_object, const P& start_point, const P& p, - unsigned anchor) + anchor::Type anchor) { exact(this)->invalidate_link_(current_object, start_point, p, anchor); } @@ -361,7 +375,7 @@ namespace scribo inline mln_site(L) link_functor_base<L,E>::start_point(unsigned current_object, - unsigned anchor) + anchor::Type anchor) { return exact(this)->start_point_(current_object, anchor); } @@ -404,12 +418,12 @@ namespace scribo template <typename L, typename E> inline - mln_site(L) + mln::util::couple<anchor::Type, mln_site(L)> link_functor_base<L,E>::finalize_link_(unsigned current_object) { (void) current_object; // No-Op - return P(); + return mln::make::couple(anchor::Invalid, P()); } @@ -460,7 +474,7 @@ namespace scribo link_functor_base<L,E>::validate_link_(unsigned current_object, const P& start_point, const P& p, - unsigned anchor) + anchor::Type anchor) { (void) start_point; (void) anchor; @@ -474,7 +488,7 @@ namespace scribo link_functor_base<L,E>::invalidate_link_(unsigned current_object, const P& start_point, const P& p, - unsigned anchor) + anchor::Type anchor) { (void) current_object; (void) start_point; @@ -486,11 +500,13 @@ namespace scribo template <typename L, typename E> inline - void - link_functor_base<L,E>::compute_next_site_(P& p) + mln_site(L) + link_functor_base<L,E>::start_point_(unsigned current_object, + anchor::Type anchor) { - (void) p; - // No-Op + (void) anchor; + return internal::compute_anchor(this->objects_, mass_centers_, + current_object, anchor); } template <typename L, typename E> diff --git a/scribo/primitive/link/internal/link_several_dmax_base.hh b/scribo/primitive/link/internal/link_several_dmax_base.hh new file mode 100644 index 0000000..3d4fbae --- /dev/null +++ b/scribo/primitive/link/internal/link_several_dmax_base.hh @@ -0,0 +1,265 @@ +// Copyright (C) 2009 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_PRIMITIVE_LINK_INTERNAL_LINK_SEVERAL_DMAX_HH_ +# define SCRIBO_PRIMITIVE_LINK_INTERNAL_LINK_SEVERAL_DMAX_HH_ + +/// \file +/// +/// Base class for link functors using mass centers and a given max +/// distance. + + +# include <mln/accu/center.hh> +# include <mln/labeling/compute.hh> +# include <mln/math/abs.hh> +# include <mln/util/array.hh> + +# include <scribo/core/macros.hh> +# include <scribo/core/anchors.hh> +# include <scribo/core/object_image.hh> +# include <scribo/core/object_links.hh> + +# include <scribo/primitive/link/internal/find_link.hh> +# include <scribo/primitive/link/internal/link_functor_base.hh> + +# include <scribo/primitive/link/compute.hh> + + +namespace scribo +{ + + namespace primitive + { + + namespace link + { + + namespace internal + { + + /// \brief Base class for link functors using mass centers and + /// a given max distance. + // + template <typename L, typename E> + class link_several_dmax_base + : public link_functor_base<L, E> + { + typedef mln_site(L) P; + typedef link_functor_base<L,E> super_; + typedef mln_result(accu::center<mln_psite(L)>) ms_t; + typedef mln::util::couple<anchor::Type, P> couple_t; + + public: + + link_several_dmax_base(const object_image(L)& objects, + unsigned neighb_max_distance, + unsigned nanchors); + + + + bool verify_link_criterion_(unsigned current_object, + const P& start_point, const P& p) const; + + void start_processing_object_(unsigned current_object); + + void validate_link_(unsigned current_object, const P& start_point, + const P& p, anchor::Type anchor); + + void initialize_link_(unsigned current_object); + couple_t finalize_link_(unsigned current_object); + + + + protected: + mln::util::array<ms_t> mass_centers_; + mln::util::array<couple_t> potential_links_; + float dmax_; + float neighb_max_distance_; + }; + + +# ifndef MLN_INCLUDE_ONLY + + + 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) + + : super_(objects, nanchors), + dmax_(0), + neighb_max_distance_(neighb_max_distance) + { + + mass_centers_ = labeling::compute(accu::meta::center(), + objects, objects.nlabels()); + } + + template <typename L, typename E> + inline + bool + link_several_dmax_base<L, E>::verify_link_criterion_( + unsigned current_object, + const P& start_point, + const P& p) const + { + (void) current_object; + + float dist = math::abs(p.col() - start_point.col()); + return dist <= dmax_; // Not too far + } + + + template <typename L, typename E> + inline + void + link_several_dmax_base<L, E>::start_processing_object_( + unsigned current_object) + { + float + midcol = (this->objects_.bbox(current_object).pmax().col() + - this->objects_.bbox(current_object).pmin().col()) / 2; + dmax_ = midcol + neighb_max_distance_; + } + + + template <typename L, typename E> + inline + void + link_several_dmax_base<L, E>::validate_link_(unsigned current_object, + const P& start_point, + const P& p, + anchor::Type anchor) + { + (void) current_object; + (void) start_point; + this->potential_links_.append(mln::make::couple(anchor, p)); + } + + + template <typename L, typename E> + inline + void + link_several_dmax_base<L, E>::initialize_link_(unsigned current_object) + { + (void) current_object; + this->links_.clear(); + this->potential_links_.clear(); + } + + + template <typename L, typename E> + inline + mln::util::couple<anchor::Type, mln_site(L)> + link_several_dmax_base<L, E>::finalize_link_(unsigned current_object) + { + //TODO + mln::util::array<unsigned> dist; + unsigned + min = mln_max(unsigned), + tmp; + + if (this->potential_links_.nelements() > 0) + { + 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()); + dist.append(tmp); + if (tmp < min) + min = tmp; + } + + mln_assertion(min != mln_max(unsigned)); + + // Keep closest links and compute vertical overlap. + unsigned + nratio = 0, + id_max_ratio = 0; + mln_value(L) nbh_id; + mln::util::array<float> overlap; + for(unsigned i = 0; i < this->potential_links_.nelements(); ++i) + if (dist[i] < (1.2 * min)) + { + unsigned + other_object = this->objects_(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(), + ratio = dr / dh; + + overlap.append(ratio); + if (ratio > overlap(id_max_ratio) || nratio == 0) + { + id_max_ratio = i; + nratio = 1; + nbh_id = other_object; + } + else if (ratio == overlap(id_max_ratio) + && other_object != nbh_id) + ++nratio; + } + else + overlap.append(0); + + if (nratio == 1) + { + this->links_(current_object) + = this->objects_(potential_links_(id_max_ratio).second()); + + return potential_links_(id_max_ratio); + } + + } + + this->links_(current_object) = current_object; + return mln::make::couple(anchor::Invalid, P()); + } + + + +# endif // ! MLN_INCLUDE_ONLY + + + } // end of namespace scribo::primitive::link::internal + + } // end of namespace scribo::primitive::link + + } // end of namespace scribo::primitive + +} // end of namespace scribo + + +#endif // SCRIBO_PRIMITIVE_LINK_INTERNAL_LINK_SEVERAL_DMAX_HH_ diff --git a/scribo/primitive/link/internal/link_center_dmax_base.hh b/scribo/primitive/link/internal/link_single_dmax_base.hh similarity index 73% rename from scribo/primitive/link/internal/link_center_dmax_base.hh rename to scribo/primitive/link/internal/link_single_dmax_base.hh index 1a7a48d..4f571af 100644 --- a/scribo/primitive/link/internal/link_center_dmax_base.hh +++ b/scribo/primitive/link/internal/link_single_dmax_base.hh @@ -23,8 +23,8 @@ // exception does not however invalidate any other reasons why the // executable file might be covered by the GNU General Public License. -#ifndef SCRIBO_PRIMITIVE_LINK_INTERNAL_LINK_CENTER_DMAX_HH_ -# define SCRIBO_PRIMITIVE_LINK_INTERNAL_LINK_CENTER_DMAX_HH_ +#ifndef SCRIBO_PRIMITIVE_LINK_INTERNAL_LINK_SINGLE_DMAX_BASE_HH_ +# define SCRIBO_PRIMITIVE_LINK_INTERNAL_LINK_SINGLE_DMAX_BASE_HH_ /// \file /// @@ -38,10 +38,12 @@ # include <mln/util/array.hh> # include <scribo/core/macros.hh> +# include <scribo/core/anchors.hh> # include <scribo/core/object_image.hh> # include <scribo/core/object_links.hh> # include <scribo/primitive/link/internal/find_link.hh> +# include <scribo/primitive/link/internal/compute_anchor.hh> # include <scribo/primitive/link/internal/link_functor_base.hh> # include <scribo/primitive/link/compute.hh> @@ -63,41 +65,32 @@ namespace scribo /// a given max distance. // template <typename L, typename E> - class link_center_dmax_base + class link_single_dmax_base : public link_functor_base<L, E> { typedef link_functor_base<L,E> super_; + typedef mln_result(accu::center<mln_psite(L)>) ms_t; public: typedef mln_site(L) P; - - /*! - - center_type can have the following values: - 0 - top bounding box center - 1 - bounding box center - 2 - bottom bounding box center - - */ - link_center_dmax_base(const object_image(L)& objects, - unsigned neighb_max_distance, - unsigned center_type); + link_single_dmax_base(const object_image(L)& objects, + unsigned neighb_max_distance); bool verify_link_criterion_(unsigned current_object, const P& start_point, const P& p) const; mln_site(L) start_point_(unsigned current_object, - unsigned anchor); + anchor::Type anchor); void start_processing_object_(unsigned current_object); private: float dmax_; float neighb_max_distance_; - unsigned center_type_; +// mln::util::array<ms_t> mass_centers_; }; @@ -106,23 +99,23 @@ namespace scribo template <typename L, typename E> inline - link_center_dmax_base<L, E>::link_center_dmax_base( + link_single_dmax_base<L, E>::link_single_dmax_base( const object_image(L)& objects, - unsigned neighb_max_distance, - unsigned center_type) + unsigned neighb_max_distance) : super_(objects), dmax_(0), - neighb_max_distance_(neighb_max_distance), - center_type_(center_type) + neighb_max_distance_(neighb_max_distance) { +// mass_centers_ = labeling::compute(accu::meta::center(), +// objects, objects.nlabels()); } template <typename L, typename E> inline bool - link_center_dmax_base<L, E>::verify_link_criterion_( + link_single_dmax_base<L, E>::verify_link_criterion_( unsigned current_object, const P& start_point, const P& p) const @@ -137,24 +130,18 @@ namespace scribo template <typename L, typename E> inline mln_site(L) - link_center_dmax_base<L, E>::start_point_(unsigned current_object, - unsigned anchor) + link_single_dmax_base<L, E>::start_point_(unsigned current_object, + anchor::Type anchor) { - (void) anchor; - mln_site(L) sp = this->objects_.bbox(current_object).center(); - if (center_type_ == 0) - sp.row() = this->objects_.bbox(current_object).pmin().row(); - else if (center_type_ == 2) - sp.row() = this->objects_.bbox(current_object).pmax().row(); - - return sp; + return internal::compute_anchor(this->objects_, this->objects_.mass_centers(),//mass_centers_, + current_object, anchor); } template <typename L, typename E> inline void - link_center_dmax_base<L, E>::start_processing_object_( + link_single_dmax_base<L, E>::start_processing_object_( unsigned current_object) { float @@ -176,4 +163,4 @@ namespace scribo } // end of namespace scribo -#endif // SCRIBO_PRIMITIVE_LINK_INTERNAL_LINK_CENTER_DMAX_HH_ +#endif // SCRIBO_PRIMITIVE_LINK_INTERNAL_LINK_SINGLE_DMAX_BASE_HH_ diff --git a/scribo/primitive/link/internal/link_center_dmax_ratio_base.hh b/scribo/primitive/link/internal/link_single_dmax_ratio_base.hh similarity index 79% rename from scribo/primitive/link/internal/link_center_dmax_ratio_base.hh rename to scribo/primitive/link/internal/link_single_dmax_ratio_base.hh index 0740ec9..9eadba7 100644 --- a/scribo/primitive/link/internal/link_center_dmax_ratio_base.hh +++ b/scribo/primitive/link/internal/link_single_dmax_ratio_base.hh @@ -23,8 +23,8 @@ // exception does not however invalidate any other reasons why the // executable file might be covered by the GNU General Public License. -#ifndef SCRIBO_PRIMITIVE_LINK_INTERNAL_LINK_CENTER_DMAX_RATIO_BASE_HH_ -# define SCRIBO_PRIMITIVE_LINK_INTERNAL_LINK_CENTER_DMAX_RATIO_BASE_HH_ +#ifndef SCRIBO_PRIMITIVE_LINK_INTERNAL_LINK_SINGLE_DMAX_RATIO_BASE_HH_ +# define SCRIBO_PRIMITIVE_LINK_INTERNAL_LINK_SINGLE_DMAX_RATIO_BASE_HH_ /// \file /// @@ -39,9 +39,11 @@ # include <mln/util/array.hh> # include <scribo/core/macros.hh> +# include <scribo/core/anchors.hh> # include <scribo/core/object_image.hh> # include <scribo/core/object_links.hh> +# include <scribo/primitive/link/internal/compute_anchor.hh> # include <scribo/primitive/link/internal/find_link.hh> # include <scribo/primitive/link/internal/link_functor_base.hh> @@ -64,7 +66,7 @@ namespace scribo /// center and a proportional max distance. // template <typename L, typename E> - class link_center_dmax_ratio_base + class link_single_dmax_ratio_base : public link_functor_base<L, E> { typedef link_functor_base<L,E> super_; @@ -75,7 +77,7 @@ namespace scribo typedef mln_site(L) P; - link_center_dmax_ratio_base(const object_image(L)& objects, + link_single_dmax_ratio_base(const object_image(L)& objects, float dmax_ratio, unsigned center_type_); @@ -85,14 +87,14 @@ namespace scribo const P& start_point, const P& p) const; mln_site(L) start_point_(unsigned current_object, - unsigned anchor); + anchor::Type anchor); void start_processing_object_(unsigned current_object); private: float dmax_ratio_; float dmax_; - unsigned center_type_; + mln::util::array<ms_t> mass_centers_; }; @@ -101,22 +103,22 @@ namespace scribo template <typename L, typename E> inline - link_center_dmax_ratio_base<L, E>::link_center_dmax_ratio_base( + link_single_dmax_ratio_base<L, E>::link_single_dmax_ratio_base( const object_image(L)& objects, - float dmax_ratio, - unsigned center_type) + float dmax_ratio) : super_(objects), dmax_ratio_(dmax_ratio), - dmax_(0), - center_type_(center_type) + dmax_(0) { + mass_centers_ = labeling::compute(accu::meta::center(), + objects, objects.nlabels()); } template <typename L, typename E> inline bool - link_center_dmax_ratio_base<L, E>::verify_link_criterion_( + link_single_dmax_ratio_base<L, E>::verify_link_criterion_( unsigned current_object, const P& start_point, const P& p) const @@ -131,24 +133,19 @@ namespace scribo template <typename L, typename E> inline mln_site(L) - link_center_dmax_ratio_base<L, E>::start_point_(unsigned current_object, - unsigned anchor) + link_single_dmax_ratio_base<L, E>::start_point_(unsigned current_object, + anchor::Type anchor) { (void) anchor; - mln_site(L) sp = this->objects_.bbox(current_object).center(); - if (center_type_ == 0) - sp.row() = this->objects_.bbox(current_object).pmin().row(); - else if (center_type_ == 2) - sp.row() = this->objects_.bbox(current_object).pmax().row(); - - return sp; + return internal::compute_anchors(this->objects_, mass_centers_, + current_object, anchor); } template <typename L, typename E> inline void - link_center_dmax_ratio_base<L, E>::start_processing_object_( + link_single_dmax_ratio_base<L, E>::start_processing_object_( unsigned current_object) { float @@ -172,4 +169,4 @@ namespace scribo } // end of namespace scribo -#endif // SCRIBO_PRIMITIVE_LINK_INTERNAL_LINK_CENTER_DMAX_RATIO_BASE_HH_ +#endif // SCRIBO_PRIMITIVE_LINK_INTERNAL_LINK_SINGLE_DMAX_RATIO_BASE_HH_ diff --git a/scribo/primitive/link/with_several_right_links_overlap.hh b/scribo/primitive/link/with_several_right_links_overlap.hh index 27d9d49..f9fd5a4 100644 --- a/scribo/primitive/link/with_several_right_links_overlap.hh +++ b/scribo/primitive/link/with_several_right_links_overlap.hh @@ -39,7 +39,8 @@ # include <scribo/core/object_image.hh> # include <scribo/core/macros.hh> # include <scribo/primitive/internal/init_link_array.hh> -# include <scribo/primitive/internal/find_right_link.hh> +# include <scribo/primitive/link/internal/find_several_links.hh> +# include <scribo/primitive/link/internal/link_several_dmax_base.hh> # include <scribo/util/text.hh> @@ -94,8 +95,6 @@ namespace scribo { } - template <typename L, typename E> - inline mln_site(L) start_point_(unsigned current_object, unsigned anchor) { @@ -109,6 +108,8 @@ namespace scribo ++p.col(); } + }; + } // end of namespace scribo::primitive::link::internal @@ -122,7 +123,8 @@ namespace scribo mln_precondition(objects.is_valid()); - several_right_overlap_functor<L> functor(objects, neighb_max_distance); + internal::several_right_overlap_functor<L> + functor(objects, neighb_max_distance); for_all_ncomponents(current_object, objects.nlabels()) internal::find_several_links(functor, current_object); diff --git a/scribo/primitive/link/with_single_left_link.hh b/scribo/primitive/link/with_single_left_link.hh index bef9ea3..2cf0c5a 100644 --- a/scribo/primitive/link/with_single_left_link.hh +++ b/scribo/primitive/link/with_single_left_link.hh @@ -47,7 +47,7 @@ # include <scribo/core/object_links.hh> # include <scribo/primitive/link/internal/find_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> @@ -93,10 +93,10 @@ namespace scribo template <typename L> class single_left_functor - : public internal::link_ms_dmax_base<L, single_left_functor<L> > + : public internal::link_single_dmax_base<L, single_left_functor<L> > { typedef - internal::link_ms_dmax_base<L, single_left_functor<L> > super_; + internal::link_single_dmax_base<L, single_left_functor<L> > super_; public: typedef mln_site(L) P; diff --git a/scribo/primitive/link/with_single_right_link.hh b/scribo/primitive/link/with_single_right_link.hh index 236884b..f7272ee 100644 --- a/scribo/primitive/link/with_single_right_link.hh +++ b/scribo/primitive/link/with_single_right_link.hh @@ -40,11 +40,12 @@ # include <mln/util/array.hh> # include <scribo/core/macros.hh> +# include <scribo/core/anchors.hh> # include <scribo/core/object_image.hh> # include <scribo/core/object_links.hh> # include <scribo/primitive/link/internal/find_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> @@ -92,10 +93,10 @@ namespace scribo template <typename L> class single_right_functor - : public internal::link_ms_dmax_base<L, single_right_functor<L> > + : public internal::link_single_dmax_base<L, single_right_functor<L> > { typedef - internal::link_ms_dmax_base<L, single_right_functor<L> > super_; + internal::link_single_dmax_base<L, single_right_functor<L> > super_; public: typedef mln_site(L) P; @@ -131,7 +132,7 @@ namespace scribo internal::single_right_functor<L> functor(objects, neighb_max_distance); - object_links<L> output = compute(functor); + object_links<L> output = compute(functor, anchor::MassCenter); trace::exiting("scribo::primitive::link::with_single_right_link"); return output; diff --git a/scribo/primitive/link/with_single_right_link_bottom.hh b/scribo/primitive/link/with_single_right_link_bottom.hh index 5976f22..3b1f6e7 100644 --- a/scribo/primitive/link/with_single_right_link_bottom.hh +++ b/scribo/primitive/link/with_single_right_link_bottom.hh @@ -40,11 +40,12 @@ # include <mln/util/array.hh> # include <scribo/core/macros.hh> +# include <scribo/core/anchors.hh> # include <scribo/core/object_image.hh> # include <scribo/core/object_links.hh> # include <scribo/primitive/link/internal/find_link.hh> -# include <scribo/primitive/link/internal/link_center_dmax_base.hh> +# include <scribo/primitive/link/internal/link_single_dmax_base.hh> # include <scribo/primitive/link/compute.hh> @@ -70,7 +71,7 @@ namespace scribo inline object_links<L> with_single_right_link_bottom(const object_image(L)& objects, - unsigned neighb_max_distance); + unsigned neighb_max_distance); /// \overload @@ -92,11 +93,11 @@ namespace scribo template <typename L> class single_right_bottom_functor - : public link_center_dmax_base<L, + : public link_single_dmax_base<L, single_right_bottom_functor<L> > { typedef - link_center_dmax_base<L, single_right_bottom_functor<L> > + link_single_dmax_base<L, single_right_bottom_functor<L> > super_; public: @@ -104,7 +105,7 @@ namespace scribo single_right_bottom_functor(const object_image(L)& objects, unsigned dmax) - : super_(objects, dmax, 2) + : super_(objects, dmax) { } @@ -134,7 +135,7 @@ namespace scribo internal::single_right_bottom_functor<L> functor(objects, neighb_max_distance); - object_links<L> output = compute(functor); + object_links<L> output = compute(functor, anchor::Bottom); trace::exiting("scribo::primitive::link::with_single_right_link_bottom"); return output; diff --git a/scribo/primitive/link/with_single_right_link_top.hh b/scribo/primitive/link/with_single_right_link_top.hh index 13bb583..1e3e0df 100644 --- a/scribo/primitive/link/with_single_right_link_top.hh +++ b/scribo/primitive/link/with_single_right_link_top.hh @@ -40,11 +40,12 @@ # include <mln/util/array.hh> # include <scribo/core/macros.hh> +# include <scribo/core/anchors.hh> # include <scribo/core/object_image.hh> # include <scribo/core/object_links.hh> # include <scribo/primitive/link/internal/find_link.hh> -# include <scribo/primitive/link/internal/link_center_dmax_base.hh> +# include <scribo/primitive/link/internal/link_single_dmax_base.hh> # include <scribo/primitive/link/compute.hh> @@ -70,7 +71,7 @@ namespace scribo inline object_links<L> with_single_right_link_top(const object_image(L)& objects, - unsigned neighb_max_distance); + unsigned neighb_max_distance); /// \overload @@ -92,19 +93,19 @@ namespace scribo template <typename L> class single_right_top_functor - : public link_center_dmax_base<L, + : public link_single_dmax_base<L, single_right_top_functor<L> > { typedef - link_center_dmax_base<L, single_right_top_functor<L> > + link_single_dmax_base<L, single_right_top_functor<L> > super_; public: typedef mln_site(L) P; single_right_top_functor(const object_image(L)& objects, - unsigned dmax) - : super_(objects, dmax, 0) + unsigned dmax) + : super_(objects, dmax) { } @@ -125,7 +126,7 @@ namespace scribo inline object_links<L> with_single_right_link_top(const object_image(L)& objects, - unsigned neighb_max_distance) + unsigned neighb_max_distance) { trace::entering("scribo::primitive::link::with_single_right_link_top"); @@ -134,7 +135,7 @@ namespace scribo internal::single_right_top_functor<L> functor(objects, neighb_max_distance); - object_links<L> output = compute(functor); + object_links<L> output = compute(functor, anchor::Top); trace::exiting("scribo::primitive::link::with_single_right_link_top"); return output; diff --git a/scribo/src/debug/show_links_several_right_overlap.cc b/scribo/src/debug/show_links_several_right_overlap.cc index 6b2a66a..f2824f3 100644 --- a/scribo/src/debug/show_links_several_right_overlap.cc +++ b/scribo/src/debug/show_links_several_right_overlap.cc @@ -30,6 +30,8 @@ #include <mln/data/convert.hh> +#include <mln/util/couple.hh> + #include <mln/value/rgb8.hh> #include <mln/value/label_16.hh> #include <mln/literal/colors.hh> @@ -41,7 +43,7 @@ #include <scribo/primitive/extract/objects.hh> #include <scribo/primitive/link/internal/link_several_dmax_base.hh> -#include <scribo/primitive/link/internal/anchors_3.hh> +#include <scribo/primitive/link/internal/compute_anchor.hh> #include <scribo/primitive/link/compute_several.hh> #include <scribo/draw/bounding_boxes.hh> @@ -61,11 +63,7 @@ namespace scribo typedef primitive::link::internal::link_several_dmax_base<L, self_t> super_; - typedef - mln::util::array<mln::util::couple<unsigned, mln_site(L)> - potential_links_t; - - public: + public: typedef mln_site(L) P; several_right_overlap_debug_functor(const I& input, @@ -79,35 +77,32 @@ namespace scribo } - void validate_link_(unsigned current_object, - const P& start_point, - const P& p, - unsigned anchor) + mln::util::couple<anchor::Type, mln_site(L)> + finalize_link_(unsigned current_object) { - mln::draw::line(output_, start_point, p, literal::green); - - super_::validate_link_(current_object, start_point, p, anchor); - } + mln::util::couple<anchor::Type, mln_site(L)> + c = super_::finalize_link_(current_object); - - - void invalidate_link_(unsigned current_object, - const P& start_point, - const P& p, - unsigned anchor) - { - if (output_.domain().has(p)) - mln::draw::line(output_, start_point, p, literal::red); - else + if (c.first() != anchor::Invalid) { - P tmp = p; - ++tmp.col(); - mln::draw::line(output_, start_point, tmp, literal::red); + mln_site(L) + p = primitive::link::internal::compute_anchor(this->objects_, + this->mass_centers_, + current_object, + c.first()); + mln::draw::line(output_, p, c.second(), literal::green); } - super_::invalidate_link_(current_object, start_point, p, anchor); + return c; } + mln_site(L) + start_point_(unsigned current_object, anchor::Type anchor) + { + return primitive::link::internal::compute_anchor(this->objects_, + this->mass_centers_, + current_object, anchor); + } void compute_next_site_(P& p) diff --git a/scribo/src/debug/show_links_single_left.cc b/scribo/src/debug/show_links_single_left.cc index 094ca85..26f78e2 100644 --- a/scribo/src/debug/show_links_single_left.cc +++ b/scribo/src/debug/show_links_single_left.cc @@ -78,7 +78,7 @@ namespace scribo void validate_link_(unsigned current_object, const P& start_point, const P& p, - unsigned anchor) + anchor::Type anchor) { mln::draw::line(output_, start_point, p, literal::green); @@ -90,7 +90,7 @@ namespace scribo void invalidate_link_(unsigned current_object, const P& start_point, const P& p, - unsigned anchor) + anchor::Type anchor) { if (output_.domain().has(p)) mln::draw::line(output_, start_point, p, literal::red); diff --git a/scribo/src/debug/show_links_single_left_dmax_ratio.cc b/scribo/src/debug/show_links_single_left_dmax_ratio.cc index 2ba0ace..e133507 100644 --- a/scribo/src/debug/show_links_single_left_dmax_ratio.cc +++ b/scribo/src/debug/show_links_single_left_dmax_ratio.cc @@ -78,7 +78,7 @@ namespace scribo void validate_link_(unsigned current_object, const P& start_point, const P& p, - unsigned anchor) + anchor::Type anchor) { mln::draw::line(output_, start_point, p, literal::green); @@ -90,7 +90,7 @@ namespace scribo void invalidate_link_(unsigned current_object, const P& start_point, const P& p, - unsigned anchor) + anchor::Type anchor) { if (output_.domain().has(p)) mln::draw::line(output_, start_point, p, literal::red); diff --git a/scribo/src/debug/show_links_single_right.cc b/scribo/src/debug/show_links_single_right.cc index c121cce..7a25306 100644 --- a/scribo/src/debug/show_links_single_right.cc +++ b/scribo/src/debug/show_links_single_right.cc @@ -78,7 +78,7 @@ namespace scribo void validate_link_(unsigned current_object, const P& start_point, const P& p, - unsigned anchor) + anchor::Type anchor) { mln::draw::line(output_, start_point, p, literal::green); @@ -90,7 +90,7 @@ namespace scribo void invalidate_link_(unsigned current_object, const P& start_point, const P& p, - unsigned anchor) + anchor::Type anchor) { if (output_.domain().has(p)) mln::draw::line(output_, start_point, p, literal::red); diff --git a/scribo/src/debug/show_links_single_right_dmax_ratio.cc b/scribo/src/debug/show_links_single_right_dmax_ratio.cc index 81415bc..806114c 100644 --- a/scribo/src/debug/show_links_single_right_dmax_ratio.cc +++ b/scribo/src/debug/show_links_single_right_dmax_ratio.cc @@ -78,7 +78,7 @@ namespace scribo void validate_link_(unsigned current_object, const P& start_point, const P& p, - unsigned anchor) + anchor::Type anchor) { mln::draw::line(output_, start_point, p, literal::green); @@ -90,7 +90,7 @@ namespace scribo void invalidate_link_(unsigned current_object, const P& start_point, const P& p, - unsigned anchor) + anchor::Type anchor) { if (output_.domain().has(p)) mln::draw::line(output_, start_point, p, literal::red); -- 1.5.6.5
participants (1)
-
Guillaume Lazzara