* scribo/primitive/internal/find_left_link.hh,
* scribo/primitive/internal/find_right_link.hh,
* scribo/primitive/internal/is_invalid_link.hh: Remove.
* scribo/primitive/link/internal/compute_anchor.hh,
* scribo/primitive/link/internal/link_ms_dmax_base.hh,
* scribo/primitive/link/internal/link_ms_dmax_ratio_base.hh,
* scribo/primitive/link/internal/link_single_dmax_base.hh,
* scribo/primitive/link/internal/link_single_dmax_ratio_base.hh,
* scribo/primitive/link/with_single_down_link.hh,
* scribo/primitive/link/with_single_left_link.hh,
* scribo/primitive/link/with_single_left_link_dmax_ratio.hh,
* scribo/primitive/link/with_single_right_link.hh,
* scribo/primitive/link/with_single_right_link_dmax_ratio.hh,
* scribo/primitive/link/with_single_up_link.hh: Introduce the
anchor concept and make use of it.
---
scribo/ChangeLog | 21 +++
scribo/primitive/internal/find_left_link.hh | 108 ---------------
scribo/primitive/internal/find_right_link.hh | 108 ---------------
scribo/primitive/internal/is_invalid_link.hh | 100 --------------
scribo/primitive/link/internal/compute_anchor.hh | 143 +++++++++++++++++---
.../primitive/link/internal/link_ms_dmax_base.hh | 27 ++--
.../link/internal/link_ms_dmax_ratio_base.hh | 18 ++-
.../link/internal/link_single_dmax_base.hh | 21 ++--
.../link/internal/link_single_dmax_ratio_base.hh | 20 ++--
...ingle_left_link.hh => with_single_down_link.hh} | 68 +++++++---
scribo/primitive/link/with_single_left_link.hh | 2 +-
.../link/with_single_left_link_dmax_ratio.hh | 10 +-
scribo/primitive/link/with_single_right_link.hh | 4 +-
.../link/with_single_right_link_dmax_ratio.hh | 8 +-
...le_right_link_top.hh => with_single_up_link.hh} | 81 +++++++----
15 files changed, 296 insertions(+), 443 deletions(-)
delete mode 100644 scribo/primitive/internal/find_left_link.hh
delete mode 100644 scribo/primitive/internal/find_right_link.hh
delete mode 100644 scribo/primitive/internal/is_invalid_link.hh
copy scribo/primitive/link/{with_single_left_link.hh => with_single_down_link.hh}
(60%)
copy scribo/primitive/link/{with_single_right_link_top.hh => with_single_up_link.hh}
(60%)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 891cd30..45faa9f 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,26 @@
2010-02-19 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Improve object linking backend.
+
+ * scribo/primitive/internal/find_left_link.hh,
+ * scribo/primitive/internal/find_right_link.hh,
+ * scribo/primitive/internal/is_invalid_link.hh: Remove.
+
+ * scribo/primitive/link/internal/compute_anchor.hh,
+ * scribo/primitive/link/internal/link_ms_dmax_base.hh,
+ * scribo/primitive/link/internal/link_ms_dmax_ratio_base.hh,
+ * scribo/primitive/link/internal/link_single_dmax_base.hh,
+ * scribo/primitive/link/internal/link_single_dmax_ratio_base.hh,
+ * scribo/primitive/link/with_single_down_link.hh,
+ * scribo/primitive/link/with_single_left_link.hh,
+ * scribo/primitive/link/with_single_left_link_dmax_ratio.hh,
+ * scribo/primitive/link/with_single_right_link.hh,
+ * scribo/primitive/link/with_single_right_link_dmax_ratio.hh,
+ * scribo/primitive/link/with_single_up_link.hh: Introduce the
+ anchor concept and make use of it.
+
+2010-02-19 Guillaume Lazzara <z(a)lrde.epita.fr>
+
* scribo/filter/objects_with_holes.hh: New component filter.
2010-02-19 Guillaume Lazzara <z(a)lrde.epita.fr>
diff --git a/scribo/primitive/internal/find_left_link.hh
b/scribo/primitive/internal/find_left_link.hh
deleted file mode 100644
index 4f30e36..0000000
--- a/scribo/primitive/internal/find_left_link.hh
+++ /dev/null
@@ -1,108 +0,0 @@
-// 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_INTERNAL_FIND_LEFT_LINK_HH
-# define SCRIBO_PRIMITIVE_INTERNAL_FIND_LEFT_LINK_HH
-
-/// \file
-///
-/// Find the left neighbor of a line of text if exists.
-///
-/// \todo To be deleted.
-
-# include <mln/core/concept/image.hh>
-
-# include <mln/math/abs.hh>
-
-# include <mln/util/array.hh>
-# include <mln/util/couple.hh>
-
-# include <scribo/core/object_image.hh>
-# include <scribo/primitive/internal/update_link_array.hh>
-# include <scribo/primitive/internal/is_invalid_link.hh>
-
-//FIXME: not generic.
-# include <mln/core/alias/dpoint2d.hh>
-
-namespace scribo
-{
-
- namespace primitive
- {
-
- namespace internal
- {
-
- /// Find the left neighbor of a line of text if exists.
- ///
- /// \param objects An image of objects.
- /// \param left_link The left neighbors.
- /// \param current_comp A text line id.
- /// \param dmax The maximum lookup distance.
- /// \param c The lookup start point.
- //
- template <typename L>
- mln::util::couple<bool, mln_site(L)>
- find_left_link(const object_image(L)& objects,
- mln::util::array<unsigned>& left_link,
- unsigned current_comp,
- float dmax,
- const mln_site(L)& c);
-
-
-# ifndef MLN_INCLUDE_ONLY
-
- template <typename L>
- mln::util::couple<bool, mln_site(L)>
- find_left_link(const object_image(L)& objects,
- mln::util::array<unsigned>& left_link,
- unsigned current_comp,
- float dmax,
- const mln_site(L)& c)
- {
- ///FIXME: the following code is not generic...
- /// First site on the right of the central site
- mln_site(L) p = c + mln::left;
-
- while (is_invalid_link(objects, left_link, p,
- current_comp, c, dmax))
- --p.col();
-
- bool
- b = update_link_array(objects, left_link, p, c, current_comp, dmax);
-
- return mln::make::couple(b, p);
- }
-
-# endif // MLN_INCLUDE_ONLY
-
- } // end of namespace scribo::primitive::internal
-
- } // end of namespace scribo::primitive
-
-} // end of namespace scribo
-
-
-#endif // ! SCRIBO_PRIMITIVE_INTERNAL_FIND_LEFT_LINK_HH
diff --git a/scribo/primitive/internal/find_right_link.hh
b/scribo/primitive/internal/find_right_link.hh
deleted file mode 100644
index 09e60f9..0000000
--- a/scribo/primitive/internal/find_right_link.hh
+++ /dev/null
@@ -1,108 +0,0 @@
-// 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_INTERNAL_FIND_RIGHT_LINK_HH
-# define SCRIBO_PRIMITIVE_INTERNAL_FIND_RIGHT_LINK_HH
-
-/// \file
-///
-/// Find the right neighbor of a line of text if exists.
-///
-/// \todo To be deleted.
-
-# include <mln/core/concept/image.hh>
-
-# include <mln/math/abs.hh>
-
-# include <mln/util/array.hh>
-# include <mln/util/couple.hh>
-
-# include <scribo/core/object_image.hh>
-# include <scribo/primitive/internal/update_link_array.hh>
-# include <scribo/primitive/internal/is_invalid_link.hh>
-
-//FIXME: not generic.
-# include <mln/core/alias/dpoint2d.hh>
-
-namespace scribo
-{
-
- namespace primitive
- {
-
- namespace internal
- {
-
- /// Find the right neighbor of a line of text if exists.
- ///
- /// \param objects An image of objects.
- /// \param right_link The right neighbors.
- /// \param current_comp A text line id.
- /// \param dmax The maximum lookup distance.
- /// \param c The lookup start point.
- //
- template <typename L>
- mln::util::couple<bool, mln_site(L)>
- find_right_link(const object_image(L)& objects,
- mln::util::array<unsigned>& right_link,
- unsigned current_comp,
- float dmax,
- const mln_site(L)& c);
-
-
-# ifndef MLN_INCLUDE_ONLY
-
- template <typename L>
- mln::util::couple<bool, mln_site(L)>
- find_right_link(const object_image(L)& objects,
- mln::util::array<unsigned>& right_link,
- unsigned current_comp,
- float dmax,
- const mln_site(L)& c)
- {
- /// FIXME: the following code is not generic...
- /// First site on the right of the central site
- mln_site(L) p = c + mln::right;
-
- while (is_invalid_link(objects, right_link, p,
- current_comp, c, dmax))
- ++p.col();
-
- bool
- b = update_link_array(objects, right_link, p, c, current_comp, dmax);
-
- return mln::make::couple(b, p);
- }
-
-# endif // MLN_INCLUDE_ONLY
-
- } // end of namespace scribo::primitive::internal
-
- } // end of namespace scribo::primitive
-
-} // end of namespace scribo
-
-
-#endif // ! SCRIBO_PRIMITIVE_INTERNAL_FIND_RIGHT_LINK_HH
diff --git a/scribo/primitive/internal/is_invalid_link.hh
b/scribo/primitive/internal/is_invalid_link.hh
deleted file mode 100644
index e6343fd..0000000
--- a/scribo/primitive/internal/is_invalid_link.hh
+++ /dev/null
@@ -1,100 +0,0 @@
-// 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_INTERNAL_IS_INVALID_LINK_HH
-# define SCRIBO_PRIMITIVE_INTERNAL_IS_INVALID_LINK_HH
-
-/// \file
-///
-/// Check whether an objects link is invalid or not.
-///
-/// \todo To be deleted.
-
-# include <mln/math/abs.hh>
-# include <mln/literal/zero.hh>
-
-# include <scribo/core/object_image.hh>
-
-namespace scribo
-{
-
- namespace primitive
- {
-
- namespace internal
- {
-
- using namespace mln;
-
-
- /// Check whether an objects link is invalid or not.
- ///
- /// \param objects An image of objects.
- /// \param left_link The left neighbors.
- /// \param p The current site.
- /// \param current_comp The current object id.
- /// \param c The left link start point.
- /// \param dmax The maximum lookup distance.
- //
- template <typename L>
- bool
- is_invalid_link(const object_image(L)& objects_,
- mln::util::array<unsigned>& link_array,
- const mln_site(L)& p,
- unsigned current_comp,
- const mln_site(L)& c,
- float dmax);
-
-# ifndef MLN_INCLUDE_ONLY
-
- template <typename L>
- inline
- bool
- is_invalid_link(const object_image(L)& objects,
- mln::util::array<unsigned>& link_array,
- const mln_site(L)& p,
- unsigned current_comp,
- const mln_site(L)& c,
- float dmax)
- {
- return (objects.domain().has(p) // Not outside image domain
- && (objects(p) == literal::zero // Is the background
- || objects(p) == current_comp // Is the current component
- || link_array[objects(p)] == current_comp) // Creates a loop
- && static_cast<float>(math::abs(p.col() - c.col())) < dmax); // Not
too far
- }
-
-# endif // ! MLN_INCLUDE_ONLY
-
- } // end of namespace scribo::primitive::internal
-
- } // end of namespace scribo::primitive
-
-} // end of namespace scribo
-
-
-#endif // ! SCRIBO_PRIMITIVE_INTERNAL_IS_INVALID_LINK_HH
-
-
diff --git a/scribo/primitive/link/internal/compute_anchor.hh
b/scribo/primitive/link/internal/compute_anchor.hh
index c7bae11..0d3b6f2 100644
--- a/scribo/primitive/link/internal/compute_anchor.hh
+++ b/scribo/primitive/link/internal/compute_anchor.hh
@@ -52,15 +52,11 @@ namespace scribo
/*! \brief Return the proper anchor used to find a neighbor.
\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:
- - anchor::MassCenter, mass center anchor.
- - anchor::Top, top anchor.
- - anchor::Bottom, bottom anchor.
- - anchor::Center, center anchor.
+ Anchor can take one of the values defined in the
+ scribo::anchor::Type enum.
Top and bottom anchors are respectively computed from the
@@ -76,64 +72,169 @@ namespace scribo
out.row = P.row - min(10, h /10)
*/
- template <typename L, typename P>
+ template <typename L>
mln_site(L)
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>
+ template <typename L>
mln_site(L)
compute_anchor(const object_image(L)& objects,
- const mln::util::array<P>& mass_centers,
unsigned current_object, anchor::Type anchor)
{
+ typedef mln_site(L) P;
+
unsigned h = objects.bbox(current_object).pmax().row()
- objects.bbox(current_object).pmin().row();
+ unsigned w = objects.bbox(current_object).pmax().col()
+ - objects.bbox(current_object).pmin().col();
mln_site(L) sp = objects.bbox(current_object).center();
- def::coord r = 0;
switch (anchor)
{
- // Masss Center
+ // Component masss center
case anchor::MassCenter:
- return mass_centers(current_object);
+ return objects.mass_center(current_object);
- // Top
+ // Bounding box top center
case anchor::Top:
if (h < 30)
- r = objects.bbox(current_object).pmin().row()
+ sp.row() = objects.bbox(current_object).pmin().row()
+ math::min(2u, (h + 1) / 2 - 1);
else
- r = objects.bbox(current_object).pmin().row()
+ sp.row() = objects.bbox(current_object).pmin().row()
+ math::min(10u, h /10);
break;
- // Bottom
+ // Bounding box bottom center
case anchor::Bottom:
if (h < 30)
- r = objects.bbox(current_object).pmax().row()
+ sp.row() = objects.bbox(current_object).pmax().row()
- math::min(2u, (h + 1) / 2 - 1);
else
- r = objects.bbox(current_object).pmax().row()
+ sp.row() = objects.bbox(current_object).pmax().row()
- math::min(10u, h /10);
break;
+
+ // Bounding box center
case anchor::Center:
return objects.bbox(current_object).center();
+
+ // Bounding box actual left center
+ case anchor::ActualLeft:
+ return P(objects.bbox(current_object).center().row(),
+ objects.bbox(current_object).pmin().col());
+
+
+ // Bounding box left center
+ case anchor::Left:
+ if (w < 30)
+ sp.col() = objects.bbox(current_object).pmin().col()
+ + math::min(2u, (w + 1) / 2 - 1);
+ else
+ sp.col() = objects.bbox(current_object).pmin().col()
+ + math::min(10u, w /10);
+ break;
+
+
+ // Bounding box actual right center
+ case anchor::ActualRight:
+ return P(objects.bbox(current_object).center().row(),
+ objects.bbox(current_object).pmax().col());
+
+
+ // Bounding box right center
+ case anchor::Right:
+ if (w < 30)
+ sp.col() = objects.bbox(current_object).pmax().col()
+ - math::min(2u, (w + 1) / 2 - 1);
+ else
+ sp.col() = objects.bbox(current_object).pmax().col()
+ - math::min(10u, w /10);
+ break;
+
+
+ // Bounding box top left
+ case anchor::TopLeft:
+ if (h < 30)
+ sp.row() = objects.bbox(current_object).pmin().row()
+ + math::min(2u, (h + 1) / 2 - 1);
+ else
+ sp.row() = objects.bbox(current_object).pmin().row()
+ + math::min(10u, h /10);
+ if (w < 30)
+ sp.col() = objects.bbox(current_object).pmin().col()
+ + math::min(2u, (w + 1) / 2 - 1);
+ else
+ sp.col() = objects.bbox(current_object).pmin().col()
+ + math::min(10u, w /10);
+ break;
+
+
+ // Bounding box top right
+ case anchor::TopRight:
+ if (h < 30)
+ sp.row() = objects.bbox(current_object).pmin().row()
+ + math::min(2u, (h + 1) / 2 - 1);
+ else
+ sp.row() = objects.bbox(current_object).pmin().row()
+ + math::min(10u, h /10);
+ if (w < 30)
+ sp.col() = objects.bbox(current_object).pmax().col()
+ - math::min(2u, (w + 1) / 2 - 1);
+ else
+ sp.col() = objects.bbox(current_object).pmax().col()
+ - math::min(10u, w /10);
+ break;
+
+
+ // Bounding box bottom left
+ case anchor::BottomLeft:
+ if (h < 30)
+ sp.row() = objects.bbox(current_object).pmax().row()
+ - math::min(2u, (h + 1) / 2 - 1);
+ else
+ sp.row() = objects.bbox(current_object).pmax().row()
+ - math::min(10u, h /10);
+ if (w < 30)
+ sp.col() = objects.bbox(current_object).pmin().col()
+ + math::min(2u, (w + 1) / 2 - 1);
+ else
+ sp.col() = objects.bbox(current_object).pmin().col()
+ + math::min(10u, w /10);
+ break;
+
+ // Bounding box bottom right
+ case anchor::BottomRight:
+ if (h < 30)
+ sp.row() = objects.bbox(current_object).pmax().row()
+ - math::min(2u, (h + 1) / 2 - 1);
+ else
+ sp.row() = objects.bbox(current_object).pmax().row()
+ - math::min(10u, h /10);
+ if (w < 30)
+ sp.col() = objects.bbox(current_object).pmax().col()
+ - math::min(2u, (w + 1) / 2 - 1);
+ else
+ sp.col() = objects.bbox(current_object).pmax().col()
+ - math::min(10u, w /10);
+ break;
+
+
+
default:
trace::warning("Non handled anchor");
- mln_assertion(anchor > 2);
+ mln_assertion(anchor < anchor::Invalid);
}
- sp.row() = r;
return sp;
}
diff --git a/scribo/primitive/link/internal/link_ms_dmax_base.hh
b/scribo/primitive/link/internal/link_ms_dmax_base.hh
index 80a9a13..edb0941 100644
--- a/scribo/primitive/link/internal/link_ms_dmax_base.hh
+++ b/scribo/primitive/link/internal/link_ms_dmax_base.hh
@@ -75,12 +75,11 @@ namespace scribo
link_ms_dmax_base(const object_image(L)& objects,
- unsigned neighb_max_distance);
-
-
+ unsigned neighb_max_distance,
+ anchor::Direction direction);
bool verify_link_criterion_(unsigned current_object,
- const P& start_point, const P& p) const;
+ const P& start_point, const P& p) const;
mln_site(L) start_point_(unsigned current_object,
unsigned anchor);
@@ -88,9 +87,9 @@ namespace scribo
void start_processing_object_(unsigned current_object);
private:
- mln::util::array<ms_t> mass_centers_;
float dmax_;
float neighb_max_distance_;
+ anchor::Direction direction_;
};
@@ -101,17 +100,17 @@ namespace scribo
inline
link_ms_dmax_base<L, E>::link_ms_dmax_base(
const object_image(L)& objects,
- unsigned neighb_max_distance)
+ unsigned neighb_max_distance,
+ anchor::Direction direction)
: super_(objects),
dmax_(0),
- neighb_max_distance_(neighb_max_distance)
+ neighb_max_distance_(neighb_max_distance),
+ direction_(direction)
{
-
- mass_centers_ = labeling::compute(accu::meta::center(),
- objects, objects.nlabels());
}
+
template <typename L, typename E>
inline
bool
@@ -121,7 +120,7 @@ namespace scribo
{
(void) current_object;
- float dist = math::abs(p.col() - start_point.col());
+ float dist = math::abs(p[direction_] - start_point[direction_]);
return dist <= dmax_; // Not too far
}
@@ -133,7 +132,7 @@ namespace scribo
unsigned anchor)
{
(void) anchor;
- return mass_centers_(current_object);
+ return this->objects_.mass_center(current_object);
}
@@ -144,8 +143,8 @@ namespace scribo
unsigned current_object)
{
float
- midcol = (this->objects_.bbox(current_object).pmax().col()
- - this->objects_.bbox(current_object).pmin().col()) / 2;
+ midcol = (this->objects_.bbox(current_object).pmax()[direction_]
+ - this->objects_.bbox(current_object).pmin()[direction_]) / 2;
dmax_ = midcol + neighb_max_distance_;
}
diff --git a/scribo/primitive/link/internal/link_ms_dmax_ratio_base.hh
b/scribo/primitive/link/internal/link_ms_dmax_ratio_base.hh
index 414e0b2..8eca53d 100644
--- a/scribo/primitive/link/internal/link_ms_dmax_ratio_base.hh
+++ b/scribo/primitive/link/internal/link_ms_dmax_ratio_base.hh
@@ -76,7 +76,8 @@ namespace scribo
link_ms_dmax_ratio_base(const object_image(L)& objects,
- float dmax_ratio);
+ float dmax_ratio,
+ anchor::Direction direction);
@@ -89,9 +90,9 @@ namespace scribo
void start_processing_object_(unsigned current_object);
private:
- mln::util::array<ms_t> mass_centers_;
float dmax_ratio_;
float dmax_;
+ anchor::Direction direction_;
};
@@ -102,14 +103,14 @@ namespace scribo
inline
link_ms_dmax_ratio_base<L, E>::link_ms_dmax_ratio_base(
const object_image(L)& objects,
- float dmax_ratio)
+ float dmax_ratio,
+ anchor::Direction direction)
: super_(objects),
dmax_ratio_(dmax_ratio),
- dmax_(0)
+ dmax_(0),
+ direction_(direction)
{
- mass_centers_ = labeling::compute(accu::meta::center(),
- objects, objects.nlabels());
}
template <typename L, typename E>
@@ -120,9 +121,10 @@ namespace scribo
const P& start_point,
const P& p) const
{
+ mln_assertion(dmax_ != 0);
(void) current_object;
- float dist = math::abs(p.col() - start_point.col());
+ float dist = math::abs(p[direction_] - start_point[direction_]);
return dist <= dmax_; // Not too far
}
@@ -134,7 +136,7 @@ namespace scribo
unsigned anchor)
{
(void) anchor;
- return mass_centers_(current_object);
+ return this->objects_.mass_center(current_object);
}
diff --git a/scribo/primitive/link/internal/link_single_dmax_base.hh
b/scribo/primitive/link/internal/link_single_dmax_base.hh
index 4f571af..8d594f5 100644
--- a/scribo/primitive/link/internal/link_single_dmax_base.hh
+++ b/scribo/primitive/link/internal/link_single_dmax_base.hh
@@ -76,7 +76,8 @@ namespace scribo
typedef mln_site(L) P;
link_single_dmax_base(const object_image(L)& objects,
- unsigned neighb_max_distance);
+ unsigned neighb_max_distance,
+ anchor::Direction direction);
bool verify_link_criterion_(unsigned current_object,
@@ -90,7 +91,7 @@ namespace scribo
private:
float dmax_;
float neighb_max_distance_;
-// mln::util::array<ms_t> mass_centers_;
+ anchor::Direction direction_;
};
@@ -101,14 +102,14 @@ namespace scribo
inline
link_single_dmax_base<L, E>::link_single_dmax_base(
const object_image(L)& objects,
- unsigned neighb_max_distance)
+ unsigned neighb_max_distance,
+ anchor::Direction direction)
: super_(objects),
dmax_(0),
- neighb_max_distance_(neighb_max_distance)
+ neighb_max_distance_(neighb_max_distance),
+ direction_(direction)
{
-// mass_centers_ = labeling::compute(accu::meta::center(),
-// objects, objects.nlabels());
}
@@ -122,7 +123,7 @@ namespace scribo
{
(void) current_object;
- float dist = math::abs(p.col() - start_point.col());
+ float dist = math::abs(p[direction_] - start_point[direction_]);
return dist <= dmax_; // Not too far
}
@@ -133,7 +134,7 @@ namespace scribo
link_single_dmax_base<L, E>::start_point_(unsigned current_object,
anchor::Type anchor)
{
- return internal::compute_anchor(this->objects_,
this->objects_.mass_centers(),//mass_centers_,
+ return internal::compute_anchor(this->objects_,
current_object, anchor);
}
@@ -145,8 +146,8 @@ namespace scribo
unsigned current_object)
{
float
- midcol = (this->objects_.bbox(current_object).pmax().col()
- - this->objects_.bbox(current_object).pmin().col()) / 2;
+ midcol = (this->objects_.bbox(current_object).pmax()[direction_]
+ - this->objects_.bbox(current_object).pmin()[direction_]) / 2;
dmax_ = midcol + neighb_max_distance_;
}
diff --git a/scribo/primitive/link/internal/link_single_dmax_ratio_base.hh
b/scribo/primitive/link/internal/link_single_dmax_ratio_base.hh
index 9eadba7..ebe0b6a 100644
--- a/scribo/primitive/link/internal/link_single_dmax_ratio_base.hh
+++ b/scribo/primitive/link/internal/link_single_dmax_ratio_base.hh
@@ -78,8 +78,8 @@ namespace scribo
link_single_dmax_ratio_base(const object_image(L)& objects,
- float dmax_ratio,
- unsigned center_type_);
+ float dmax_ratio,
+ anchor::Direction direction);
@@ -94,7 +94,7 @@ namespace scribo
private:
float dmax_ratio_;
float dmax_;
- mln::util::array<ms_t> mass_centers_;
+ anchor::Direction direction_;
};
@@ -105,14 +105,14 @@ namespace scribo
inline
link_single_dmax_ratio_base<L, E>::link_single_dmax_ratio_base(
const object_image(L)& objects,
- float dmax_ratio)
+ float dmax_ratio,
+ anchor::Direction direction)
: super_(objects),
dmax_ratio_(dmax_ratio),
- dmax_(0)
+ dmax_(0),
+ direction_(direction)
{
- mass_centers_ = labeling::compute(accu::meta::center(),
- objects, objects.nlabels());
}
template <typename L, typename E>
@@ -125,7 +125,7 @@ namespace scribo
{
(void) current_object;
- float dist = math::abs(p.col() - start_point.col());
+ float dist = math::abs(p[direction_] - start_point[direction_]);
return dist <= dmax_; // Not too far
}
@@ -137,8 +137,8 @@ namespace scribo
anchor::Type anchor)
{
(void) anchor;
- return internal::compute_anchors(this->objects_, mass_centers_,
- current_object, anchor);
+ return internal::compute_anchor(this->objects_,
+ current_object, anchor);
}
diff --git a/scribo/primitive/link/with_single_left_link.hh
b/scribo/primitive/link/with_single_down_link.hh
similarity index 60%
copy from scribo/primitive/link/with_single_left_link.hh
copy to scribo/primitive/link/with_single_down_link.hh
index 2cf0c5a..7e4e82c 100644
--- a/scribo/primitive/link/with_single_left_link.hh
+++ b/scribo/primitive/link/with_single_down_link.hh
@@ -23,12 +23,12 @@
// 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_WITH_SINGLE_LEFT_LINK_HH
-# define SCRIBO_PRIMITIVE_LINK_WITH_SINGLE_LEFT_LINK_HH
+#ifndef SCRIBO_PRIMITIVE_LINK_WITH_SINGLE_DOWN_LINK_HH
+# define SCRIBO_PRIMITIVE_LINK_WITH_SINGLE_DOWN_LINK_HH
/// \file
///
-/// Link text objects with their left neighbor.
+/// Link text objects with their down neighbor.
# include <mln/core/concept/image.hh>
# include <mln/core/concept/neighborhood.hh>
@@ -61,17 +61,29 @@ namespace scribo
namespace link
{
- /// \brief Link objects with their left neighbor if exists.
+ /// \brief Link objects with their down neighbor if exists.
///
/// \param[in] objects An object image.
- /// \param[in] The maximum distance allowed to seach a neighbor object.
+ /// \param[in] neighb_max_distance The maximum distance allowed
+ /// to seach a neighbor object.
+ /// \param[in] anchor The neighborhod lookup start point.
///
/// \return Object links data.
//
template <typename L>
inline
object_links<L>
- with_single_left_link(const object_image(L)& objects,
+ with_single_down_link(const object_image(L)& objects,
+ unsigned neighb_max_distance,
+ anchor::Type anchor);
+
+ /// \overload
+ /// Anchor type is set to anchor::MassCenter
+ //
+ template <typename L>
+ inline
+ object_links<L>
+ with_single_down_link(const object_image(L)& objects,
unsigned neighb_max_distance);
@@ -80,7 +92,7 @@ namespace scribo
template <typename L>
inline
object_links<L>
- with_single_left_link(const object_image(L)& objects);
+ with_single_down_link(const object_image(L)& objects);
# ifndef MLN_INCLUDE_ONLY
@@ -92,23 +104,23 @@ namespace scribo
// Functor
template <typename L>
- class single_left_functor
- : public internal::link_single_dmax_base<L, single_left_functor<L> >
+ class single_down_functor
+ : public internal::link_single_dmax_base<L, single_down_functor<L> >
{
typedef
- internal::link_single_dmax_base<L, single_left_functor<L> > super_;
+ internal::link_single_dmax_base<L, single_down_functor<L> > sdowner_;
public:
typedef mln_site(L) P;
- single_left_functor(const object_image(L)& objects, unsigned dmax)
- : super_(objects, dmax)
+ single_down_functor(const object_image(L)& objects, unsigned dmax)
+ : sdowner_(objects, dmax, anchor::Vertical)
{
}
void compute_next_site_(P& p)
{
- --p.col();
+ ++p.row();
}
};
@@ -122,19 +134,20 @@ namespace scribo
template <typename L>
inline
object_links<L>
- with_single_left_link(const object_image(L)& objects,
- unsigned neighb_max_distance)
+ with_single_down_link(const object_image(L)& objects,
+ unsigned neighb_max_distance,
+ anchor::Type anchor)
{
- trace::entering("scribo::primitive::link::with_single_left_link");
+ trace::entering("scribo::primitive::link::with_single_down_link");
mln_precondition(objects.is_valid());
- internal::single_left_functor<L>
+ internal::single_down_functor<L>
functor(objects, neighb_max_distance);
- object_links<L> output = compute(functor);
+ object_links<L> output = compute(functor, anchor);
- trace::exiting("scribo::primitive::link::with_single_left_link");
+ trace::exiting("scribo::primitive::link::with_single_down_link");
return output;
}
@@ -142,9 +155,20 @@ namespace scribo
template <typename L>
inline
object_links<L>
- with_single_left_link(const object_image(L)& objects)
+ with_single_down_link(const object_image(L)& objects,
+ unsigned neighb_max_distance)
+ {
+ return with_single_down_link(objects, neighb_max_distance,
+ anchor::MassCenter);
+ }
+
+
+ template <typename L>
+ inline
+ object_links<L>
+ with_single_down_link(const object_image(L)& objects)
{
- return with_single_left_link(objects, mln_max(unsigned));
+ return with_single_down_link(objects, mln_max(unsigned));
}
@@ -156,4 +180,4 @@ namespace scribo
} // end of namespace scribo
-#endif // ! SCRIBO_PRIMITIVE_LINK_WITH_SINGLE_LEFT_LINK_HH
+#endif // ! SCRIBO_PRIMITIVE_LINK_WITH_SINGLE_DOWN_LINK_HH
diff --git a/scribo/primitive/link/with_single_left_link.hh
b/scribo/primitive/link/with_single_left_link.hh
index 2cf0c5a..651f1f6 100644
--- a/scribo/primitive/link/with_single_left_link.hh
+++ b/scribo/primitive/link/with_single_left_link.hh
@@ -102,7 +102,7 @@ namespace scribo
typedef mln_site(L) P;
single_left_functor(const object_image(L)& objects, unsigned dmax)
- : super_(objects, dmax)
+ : super_(objects, dmax, anchor::Horizontal)
{
}
diff --git a/scribo/primitive/link/with_single_left_link_dmax_ratio.hh
b/scribo/primitive/link/with_single_left_link_dmax_ratio.hh
index 587fb6c..d59bbc1 100644
--- a/scribo/primitive/link/with_single_left_link_dmax_ratio.hh
+++ b/scribo/primitive/link/with_single_left_link_dmax_ratio.hh
@@ -44,7 +44,7 @@
# include <scribo/core/object_links.hh>
# include <scribo/primitive/link/internal/find_link.hh>
-# include <scribo/primitive/link/internal/link_ms_dmax_ratio_base.hh>
+# include <scribo/primitive/link/internal/link_single_dmax_ratio_base.hh>
# include <scribo/primitive/link/compute.hh>
@@ -99,18 +99,18 @@ namespace scribo
template <typename L>
class single_left_dmax_ratio_functor
- : public internal::link_ms_dmax_ratio_base<L,
- single_left_dmax_ratio_functor<L> >
+ : public internal::link_single_dmax_ratio_base<L,
+ single_left_dmax_ratio_functor<L> >
{
typedef single_left_dmax_ratio_functor<L> self_t;
- typedef internal::link_ms_dmax_ratio_base<L, self_t> super_;
+ typedef internal::link_single_dmax_ratio_base<L, self_t> super_;
public:
typedef mln_site(L) P;
single_left_dmax_ratio_functor(const object_image(L)& objects,
unsigned dmax)
- : super_(objects, dmax)
+ : super_(objects, dmax, anchor::Horizontal)
{
}
diff --git a/scribo/primitive/link/with_single_right_link.hh
b/scribo/primitive/link/with_single_right_link.hh
index f7272ee..22380ab 100644
--- a/scribo/primitive/link/with_single_right_link.hh
+++ b/scribo/primitive/link/with_single_right_link.hh
@@ -40,7 +40,7 @@
# include <mln/util/array.hh>
# include <scribo/core/macros.hh>
-# include <scribo/core/anchors.hh>
+# include <scribo/core/tag/anchor.hh>
# include <scribo/core/object_image.hh>
# include <scribo/core/object_links.hh>
@@ -102,7 +102,7 @@ namespace scribo
typedef mln_site(L) P;
single_right_functor(const object_image(L)& objects, unsigned dmax)
- : super_(objects, dmax)
+ : super_(objects, dmax, anchor::Horizontal)
{
}
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 ac6ef31..cd8360f 100644
--- a/scribo/primitive/link/with_single_right_link_dmax_ratio.hh
+++ b/scribo/primitive/link/with_single_right_link_dmax_ratio.hh
@@ -99,18 +99,18 @@ namespace scribo
template <typename L>
class single_right_dmax_ratio_functor
- : public link_ms_dmax_ratio_base<L,
- single_right_dmax_ratio_functor<L> >
+ : public link_single_dmax_ratio_base<L,
+ single_right_dmax_ratio_functor<L> >
{
typedef single_right_dmax_ratio_functor<L> self_t;
- typedef link_ms_dmax_ratio_base<L, self_t> super_;
+ typedef link_single_dmax_ratio_base<L, self_t> super_;
public:
typedef mln_site(L) P;
single_right_dmax_ratio_functor(const object_image(L)& objects,
unsigned dmax)
- : super_(objects, dmax)
+ : super_(objects, dmax, anchor::Horizontal)
{
}
diff --git a/scribo/primitive/link/with_single_right_link_top.hh
b/scribo/primitive/link/with_single_up_link.hh
similarity index 60%
copy from scribo/primitive/link/with_single_right_link_top.hh
copy to scribo/primitive/link/with_single_up_link.hh
index 1e3e0df..8781128 100644
--- a/scribo/primitive/link/with_single_right_link_top.hh
+++ b/scribo/primitive/link/with_single_up_link.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_PRIMITIVE_LINK_WITH_SINGLE_RIGHT_LINK_TOP_HH
-# define SCRIBO_PRIMITIVE_LINK_WITH_SINGLE_RIGHT_LINK_TOP_HH
+#ifndef SCRIBO_PRIMITIVE_LINK_WITH_SINGLE_UP_LINK_HH
+# define SCRIBO_PRIMITIVE_LINK_WITH_SINGLE_UP_LINK_HH
/// \file
///
-/// Link text objects with their right neighbor.
-
+/// Link text objects with their up neighbor.
# include <mln/core/concept/image.hh>
# include <mln/core/concept/neighborhood.hh>
# 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>
@@ -59,28 +61,39 @@ namespace scribo
namespace link
{
- /// \brief Link objects with their right neighbor if exists.
- /// Lookup startup point is the object top center.
+ /// \brief Link objects with their up neighbor if exists.
///
/// \param[in] objects An object image.
- /// \param[in] The maximum distance allowed to seach a neighbor object.
+ /// \param[in] neighb_max_distance The maximum distance allowed
+ /// to seach a neighbor object.
+ /// \param[in] anchor The neighborhod lookup start point.
///
/// \return Object links data.
//
template <typename L>
inline
object_links<L>
- with_single_right_link_top(const object_image(L)& objects,
- unsigned neighb_max_distance);
+ with_single_up_link(const object_image(L)& objects,
+ unsigned neighb_max_distance,
+ anchor::Type anchor);
+
+ /// \overload
+ /// Anchor type is set to anchor::Center
+ //
+ template <typename L>
+ inline
+ object_links<L>
+ with_single_up_link(const object_image(L)& objects,
+ unsigned neighb_max_distance);
/// \overload
/// Max distance is set to mln_max(unsigned).
+ //
template <typename L>
inline
object_links<L>
- with_single_right_link_top(const object_image(L)& objects);
-
+ with_single_up_link(const object_image(L)& objects);
# ifndef MLN_INCLUDE_ONLY
@@ -92,26 +105,23 @@ namespace scribo
// Functor
template <typename L>
- class single_right_top_functor
- : public link_single_dmax_base<L,
- single_right_top_functor<L> >
+ class single_up_functor
+ : public internal::link_single_dmax_base<L, single_up_functor<L> >
{
typedef
- link_single_dmax_base<L, single_right_top_functor<L> >
- super_;
+ internal::link_single_dmax_base<L, single_up_functor<L> > super_;
public:
typedef mln_site(L) P;
- single_right_top_functor(const object_image(L)& objects,
- unsigned dmax)
- : super_(objects, dmax)
+ single_up_functor(const object_image(L)& objects, unsigned dmax)
+ : super_(objects, dmax, anchor::Vertical)
{
}
void compute_next_site_(P& p)
{
- ++p.col();
+ --p.row();
}
};
@@ -125,29 +135,40 @@ namespace scribo
template <typename L>
inline
object_links<L>
- with_single_right_link_top(const object_image(L)& objects,
- unsigned neighb_max_distance)
+ with_single_up_link(const object_image(L)& objects,
+ unsigned neighb_max_distance,
+ anchor::Type anchor)
{
- trace::entering("scribo::primitive::link::with_single_right_link_top");
+ trace::entering("scribo::primitive::link::with_single_up_link");
mln_precondition(objects.is_valid());
- internal::single_right_top_functor<L>
+ internal::single_up_functor<L>
functor(objects, neighb_max_distance);
- object_links<L> output = compute(functor, anchor::Top);
+ object_links<L> output = compute(functor, anchor);
- trace::exiting("scribo::primitive::link::with_single_right_link_top");
+ trace::exiting("scribo::primitive::link::with_single_up_link");
return output;
}
+ template <typename L>
+ inline
+ object_links<L>
+ with_single_up_link(const object_image(L)& objects,
+ unsigned neighb_max_distance)
+ {
+ return with_single_up_link(objects, neighb_max_distance,
+ anchor::MassCenter);
+ }
+
template <typename L>
inline
object_links<L>
- with_single_right_link_top(const object_image(L)& objects)
+ with_single_up_link(const object_image(L)& objects)
{
- return with_single_right_link_top(objects, mln_max(unsigned));
+ return with_single_up_link(objects, mln_max(unsigned));
}
@@ -159,4 +180,4 @@ namespace scribo
} // end of namespace scribo
-#endif // ! SCRIBO_PRIMITIVE_LINK_WITH_SINGLE_RIGHT_LINK_TOP_HH
+#endif // ! SCRIBO_PRIMITIVE_LINK_WITH_SINGLE_UP_LINK_HH
--
1.5.6.5