last-svn-commit-39-gc24feb9 Add anchor support in debug routines.

* scribo/debug/alignment_decision_image.hh, * scribo/debug/links_decision_image.hh, * scribo/debug/save_linked_bboxes_image.hh, * scribo/draw/bounding_box_links.hh: Make use of anchor points to draw debug outputs. --- scribo/ChangeLog | 10 +++++ scribo/debug/alignment_decision_image.hh | 26 ++++++++++-- scribo/debug/links_decision_image.hh | 34 ++++++++++++++--- scribo/debug/save_linked_bboxes_image.hh | 48 +++++++++++++++++------ scribo/draw/bounding_box_links.hh | 61 ++++++++++++------------------ 5 files changed, 118 insertions(+), 61 deletions(-) diff --git a/scribo/ChangeLog b/scribo/ChangeLog index 01ab3a1..52a13dd 100644 --- a/scribo/ChangeLog +++ b/scribo/ChangeLog @@ -1,5 +1,15 @@ 2010-02-19 Guillaume Lazzara <z@lrde.epita.fr> + Add anchor support in debug routines. + + * scribo/debug/alignment_decision_image.hh, + * scribo/debug/links_decision_image.hh, + * scribo/debug/save_linked_bboxes_image.hh, + * scribo/draw/bounding_box_links.hh: Make use of anchor points to + draw debug outputs. + +2010-02-19 Guillaume Lazzara <z@lrde.epita.fr> + Add new link filters. * scribo/filter/object_links_non_aligned_simple.hh: Handle new diff --git a/scribo/debug/alignment_decision_image.hh b/scribo/debug/alignment_decision_image.hh index 9a4fa50..e3b6163 100644 --- a/scribo/debug/alignment_decision_image.hh +++ b/scribo/debug/alignment_decision_image.hh @@ -114,7 +114,8 @@ namespace scribo alignment_decision_image(const Image<I>& input_, const object_links<L>& links, const object_links<L>& filtered_links, - const Alignment& alignment) + const Alignment& alignment, + unsigned max_link_length) { trace::entering("scribo::debug::alignment_decision_image"); const I& input = exact(input_); @@ -147,10 +148,11 @@ namespace scribo mln::util::couple<P,P> anchors = internal::find_anchors(objects, i, links[i], alignment); - mln::draw::line(decision_image, - anchors.first(), - anchors.second(), - value); + if (norm::l1_distance(anchors.first(), anchors.second()) < max_link_length) + mln::draw::line(decision_image, + anchors.first(), + anchors.second(), + value); } } @@ -159,6 +161,20 @@ namespace scribo } + template <typename I, typename L> + mln_ch_value(I,value::rgb8) + alignment_decision_image(const Image<I>& input_, + const object_links<L>& links, + const object_links<L>& filtered_links, + const Alignment& alignment) + { + return alignment_decision_image(input_, + links, + filtered_links, + alignment, + mln_max(unsigned)); + } + # endif // ! MLN_INCLUDE_ONLY diff --git a/scribo/debug/links_decision_image.hh b/scribo/debug/links_decision_image.hh index 368d9b7..e1cf766 100644 --- a/scribo/debug/links_decision_image.hh +++ b/scribo/debug/links_decision_image.hh @@ -36,6 +36,7 @@ # include <mln/value/rgb8.hh> # include <mln/literal/colors.hh> # include <mln/util/array.hh> +# include <mln/norm/l1.hh> # include <scribo/core/object_groups.hh> # include <scribo/draw/bounding_boxes.hh> @@ -54,8 +55,15 @@ namespace scribo mln_ch_value(I,value::rgb8) links_decision_image(const Image<I>& input_, const object_links<L>& links, - const object_links<L>& filtered_links); + const object_links<L>& filtered_links, + unsigned max_link_length); + /// \overload + template <typename I, typename L> + mln_ch_value(I,value::rgb8) + links_decision_image(const Image<I>& input_, + const object_links<L>& links, + const object_links<L>& filtered_links); # ifndef MLN_INCLUDE_ONLY @@ -63,7 +71,8 @@ namespace scribo mln_ch_value(I,value::rgb8) links_decision_image(const Image<I>& input_, const object_links<L>& links, - const object_links<L>& filtered_links) + const object_links<L>& filtered_links, + unsigned max_link_length) { trace::entering("scribo::debug::links_decision_image"); const I& input = exact(input_); @@ -105,10 +114,11 @@ namespace scribo while (objects(p2) != links[i] && objects.domain().has(p2)) ++p2.col(); - mln::draw::line(links_decision_image, - p1, - p2, - value); + if (norm::l1_distance(p2.to_vec(), p1.to_vec()) < max_link_length) + mln::draw::line(links_decision_image, + p1, + p2, + value); } } @@ -117,6 +127,18 @@ namespace scribo } + template <typename I, typename L> + mln_ch_value(I,value::rgb8) + links_decision_image(const Image<I>& input_, + const object_links<L>& links, + const object_links<L>& filtered_links) + { + return links_decision_image(input_, + links, + filtered_links, + mln_max(unsigned)); + } + # endif // ! MLN_INCLUDE_ONLY } // end of namespace scribo::debug diff --git a/scribo/debug/save_linked_bboxes_image.hh b/scribo/debug/save_linked_bboxes_image.hh index 364f06e..c4e3cd1 100644 --- a/scribo/debug/save_linked_bboxes_image.hh +++ b/scribo/debug/save_linked_bboxes_image.hh @@ -62,6 +62,21 @@ namespace scribo /// \param[in] box_value Value used to draw line bounding boxes. /// \param[in] link_value Value used to draw line links. /// \param[in] filename The target file name. + /// \param[in] anchor Anchor from where the links are drawn. + // + template <typename I, typename L> + void + save_linked_bboxes_image(const Image<I>& input, + const object_image(L)& objects, + const object_links<L>& array, + const value::rgb8& box_value, + const value::rgb8& link_value, + const std::string& filename, + anchor::Type anchor); + + /// \overload + /// The default anchor type is set to anchor::Center. + // template <typename I, typename L> void save_linked_bboxes_image(const Image<I>& input, @@ -145,20 +160,16 @@ namespace scribo const object_links<L>& array, const value::rgb8& box_value, const value::rgb8& link_value, - const std::string& filename) + const std::string& filename, + anchor::Type anchor) { trace::entering("scribo::debug::save_linked_bboxes_image"); mln_precondition(exact(input).is_valid()); mln_ch_value(I,value::rgb8) tmp = data::convert(value::rgb8(), input); - mln::util::array<mln_result(accu::center<mln_psite(L)>)> - mass_center = labeling::compute(accu::meta::center(), - objects, - objects.nlabels()); - draw::bounding_boxes(tmp, objects.bboxes(), box_value); - draw::bounding_box_links(tmp, mass_center, array, link_value); + draw::bounding_box_links(tmp, array, link_value, anchor); io::ppm::save(tmp, filename); @@ -171,6 +182,22 @@ namespace scribo void save_linked_bboxes_image(const Image<I>& input, const object_image(L)& objects, + const object_links<L>& array, + const value::rgb8& box_value, + const value::rgb8& link_value, + const std::string& filename) + { + save_linked_bboxes_image(input, objects, array, box_value, + link_value, filename, anchor::Center); + } + + + + template <typename I, typename L> + inline + void + save_linked_bboxes_image(const Image<I>& input, + const object_image(L)& objects, const object_links<L>& left_link, const object_links<L>& right_link, const value::rgb8& box_value, @@ -182,13 +209,8 @@ namespace scribo mln_ch_value(I,value::rgb8) tmp = data::convert(value::rgb8(), input); - mln::util::array<mln_result(accu::center<mln_psite(L)>)> - mass_center = labeling::compute(accu::meta::center(), - objects, - objects.nlabels()); - draw::bounding_boxes(tmp, objects.bboxes(), box_value); - draw::bounding_box_links(tmp, mass_center, + draw::bounding_box_links(tmp, objects.mass_centers(), left_link, right_link, value); diff --git a/scribo/draw/bounding_box_links.hh b/scribo/draw/bounding_box_links.hh index 47a4f0a..ed6337d 100644 --- a/scribo/draw/bounding_box_links.hh +++ b/scribo/draw/bounding_box_links.hh @@ -35,9 +35,11 @@ # include <mln/util/array.hh> # include <mln/canvas/browsing/depth_first_search.hh> +# include <scribo/core/tag/anchor.hh> # include <scribo/core/macros.hh> # include <scribo/core/object_links.hh> # include <scribo/primitive/internal/is_link_valid.hh> +# include <scribo/primitive/link/internal/compute_anchor.hh> namespace scribo { @@ -54,25 +56,22 @@ namespace scribo /// \param[in] bboxes Bounding boxes. /// \param[in] links Bounding box links. /// \param[in] value Value used to draw links. + /// \param[in] anchor Anchor from where the links are drawn. + // template <typename I, typename L> void bounding_box_links(Image<I>& input_, - const mln::util::array< box<mln_site(I)> >& bboxes, const object_links<L>& link, - const mln_value(I)& value); + const mln_value(I)& value, + anchor::Type anchor); - /// Draw a list of bounding box links from their mass centers. - /// - /// \param[in,out] input_ An image where to draw. - /// \param[in] mass_centers Bounding boxes mass centers. - /// \param[in] links Bounding box links. - /// \param[in] value Value used to draw links. + /// \overload + /// The default anchor type is set to anchor::Center. + // template <typename I, typename L> - inline void bounding_box_links(Image<I>& input_, - const mln::util::array<mln_site(I)::vec>& mass_centers, const object_links<L>& link, const mln_value(I)& value); @@ -236,9 +235,9 @@ namespace scribo inline void bounding_box_links(Image<I>& input_, - const mln::util::array< box<mln_site(I)> >& bboxes, const object_links<L>& links, - const mln_value(I)& value) + const mln_value(I)& value, + anchor::Type anchor) { trace::entering("scribo::draw::bounding_box_links"); @@ -246,41 +245,29 @@ namespace scribo mln_precondition(input.is_valid()); + const object_image(L)& objects = links.object_image_(); for_all_components(i, links) - if (links[i] != i) - mln::draw::line(input, - bboxes[i].center(), - bboxes[links[i]].center(), - value); + if (links[i] != i && links[i] != 0) + { + mln_site(L) + p1 = primitive::link::internal::compute_anchor(objects, i, anchor), + p2 = primitive::link::internal::compute_anchor(objects, links[i], anchor); + + mln::draw::line(input, p1, p2, value); + } trace::exiting("scribo::draw::bounding_box_links"); } + template <typename I, typename L> inline void - bounding_box_links(Image<I>& input_, - const mln::util::array<mln_site(I)::vec>& mass_centers, + bounding_box_links(Image<I>& input, const object_links<L>& links, const mln_value(I)& value) { - trace::entering("scribo::draw::bounding_box_links"); - - I& input = exact(input_); - - mln_precondition(input.is_valid()); - - for_all_components(i, links) - { - if (links[i] != i) - mln::draw::line(input, - mass_centers[i], - mass_centers[links[i]], - value); - input(mass_centers[i]) = value; - } - - trace::exiting("scribo::draw::bounding_box_links"); + return bounding_box_links(input, links, value, anchor::Center); } @@ -401,7 +388,7 @@ namespace scribo mln_precondition(exact(g).v_nmax() == bboxes.nelements()); internal::draw_graph_edges_functor<I> f(exact(input), bboxes, link_value); - canvas::browsing::depth_first_search(g, f); + mln::canvas::browsing::depth_first_search(g, f); trace::exiting("scribo::draw::bounding_box_links"); } -- 1.5.6.5
participants (1)
-
Guillaume Lazzara