* core/concept/dmax_functor.hh,
* primitive/link/internal/dmax_default.hh,
* primitive/link/internal/dmax_functor_base.hh,
* primitive/link/internal/dmax_width_and_height.hh,
* primitive/link/internal/dmax_width_only.hh: New.
* primitive/link/internal/link_single_dmax_ratio_base.hh,
* primitive/link/with_single_left_link_dmax_ratio.hh,
* primitive/link/with_single_right_link_dmax_ratio.hh: Make use of
the new functors.
---
scribo/ChangeLog | 15 +++
.../concept/{link_functor.hh => dmax_functor.hh} | 15 +--
.../find_root.hh => link/internal/dmax_default.hh} | 54 ++++++-----
.../internal/dmax_functor_base.hh} | 69 ++++++++++----
.../dmax_width_and_height.hh} | 79 ++++++++--------
.../internal/dmax_width_only.hh} | 66 +++++++++-----
.../link/internal/link_single_dmax_ratio_base.hh | 69 +++++++++-----
.../link/with_single_left_link_dmax_ratio.hh | 100 +++++++++++++++-----
.../link/with_single_right_link_dmax_ratio.hh | 65 +++++++++----
9 files changed, 348 insertions(+), 184 deletions(-)
copy scribo/core/concept/{link_functor.hh => dmax_functor.hh} (80%)
copy scribo/primitive/{internal/find_root.hh => link/internal/dmax_default.hh} (61%)
copy scribo/primitive/{internal/find_root.hh => link/internal/dmax_functor_base.hh}
(54%)
copy scribo/primitive/link/{with_rag.hh => internal/dmax_width_and_height.hh} (53%)
copy scribo/primitive/{internal/find_root.hh => link/internal/dmax_width_only.hh}
(56%)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 0408bf3..6acc319 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,20 @@
2010-04-30 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Introduce dmax_functor concept.
+
+ * core/concept/dmax_functor.hh,
+ * primitive/link/internal/dmax_default.hh,
+ * primitive/link/internal/dmax_functor_base.hh,
+ * primitive/link/internal/dmax_width_and_height.hh,
+ * primitive/link/internal/dmax_width_only.hh: New.
+
+ * primitive/link/internal/link_single_dmax_ratio_base.hh,
+ * primitive/link/with_single_left_link_dmax_ratio.hh,
+ * primitive/link/with_single_right_link_dmax_ratio.hh: Make use of
+ the new functors.
+
+2010-04-30 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Small fixes in Scribo.
* binarization/sauvola_ms.hh,
diff --git a/scribo/core/concept/link_functor.hh b/scribo/core/concept/dmax_functor.hh
similarity index 80%
copy from scribo/core/concept/link_functor.hh
copy to scribo/core/concept/dmax_functor.hh
index f51843a..755913c 100644
--- a/scribo/core/concept/link_functor.hh
+++ b/scribo/core/concept/dmax_functor.hh
@@ -23,24 +23,21 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef SCRIBO_CORE_INTERNAL_LINK_FUNCTOR_HH
-# define SCRIBO_CORE_INTERNAL_LINK_FUNCTOR_HH
+#ifndef SCRIBO_CORE_INTERNAL_DMAX_FUNCTOR_HH
+# define SCRIBO_CORE_INTERNAL_DMAX_FUNCTOR_HH
/// \file
///
-/// Link functor concept.
+/// DMax functor concept.
# include <mln/core/concept/object.hh>
-# define scribo_support(T) typename T::support
-# define scribo_support_(T) T::support
-
namespace scribo
{
- /// \brief Link functor concept.
+ /// \brief Dmax functor concept.
template <typename E>
- class Link_Functor : public mln::Object<E>
+ class DMax_Functor : public mln::Object<E>
{
// typedef L support
@@ -50,4 +47,4 @@ namespace scribo
} // end of namespace scribo
-#endif // SCRIBO_CORE_INTERNAL_LINK_FUNCTOR_HH
+#endif // SCRIBO_CORE_INTERNAL_DMAX_FUNCTOR_HH
diff --git a/scribo/primitive/internal/find_root.hh
b/scribo/primitive/link/internal/dmax_default.hh
similarity index 61%
copy from scribo/primitive/internal/find_root.hh
copy to scribo/primitive/link/internal/dmax_default.hh
index 4fa6d20..1444dfe 100644
--- a/scribo/primitive/internal/find_root.hh
+++ b/scribo/primitive/link/internal/dmax_default.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -23,15 +23,14 @@
// 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_ROOT_LINK_ARRAY_HH
-# define SCRIBO_PRIMITIVE_INTERNAL_FIND_ROOT_LINK_ARRAY_HH
+#ifndef SCRIBO_PRIMITIVE_LINK_INTERNAL_DMAX_DEFAULT_HH
+# define SCRIBO_PRIMITIVE_LINK_INTERNAL_DMAX_DEFAULT_HH
/// \file
///
-/// Find root in a parent array arrays.
+/// Default class for dmax functors.
-
-# include <scribo/core/object_groups.hh>
+# include <scribo/primitive/link/internal/dmax_functor_base.hh>
namespace scribo
@@ -40,34 +39,45 @@ namespace scribo
namespace primitive
{
+ namespace link
+ {
+
namespace internal
{
- /// Find root in a parent array arrays.
- template <typename L>
- unsigned
- find_root(object_groups<L>& parent, unsigned x);
+
+ /// \brief Base class for dmax functors.
+ class dmax_default : public dmax_functor_base<dmax_default>
+ {
+ typedef dmax_functor_base<dmax_default> super_;
+
+ public:
+ dmax_default(const float& dmax_factor);
+
+ protected:
+ using super_::dmax_factor_;
+ };
+
# ifndef MLN_INCLUDE_ONLY
- template <typename L>
- inline
- unsigned
- find_root(object_groups<L>& parent, unsigned x)
- {
- if (parent(x) == x)
- return x;
- else
- return parent(x) = find_root(parent, parent(x));
+
+ dmax_default::dmax_default(const float& dmax_factor)
+ : super_(dmax_factor)
+ {
}
+
# endif // ! MLN_INCLUDE_ONLY
- } // end of namespace scribo::primitive::internal
- } // end of namespace scribo::text
+ } // 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_INTERNAL_FIND_ROOT_LINK_ARRAY_HH
+#endif // ! SCRIBO_PRIMITIVE_LINK_INTERNAL_DMAX_DEFAULT_HH
diff --git a/scribo/primitive/internal/find_root.hh
b/scribo/primitive/link/internal/dmax_functor_base.hh
similarity index 54%
copy from scribo/primitive/internal/find_root.hh
copy to scribo/primitive/link/internal/dmax_functor_base.hh
index 4fa6d20..8ff3f10 100644
--- a/scribo/primitive/internal/find_root.hh
+++ b/scribo/primitive/link/internal/dmax_functor_base.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -23,16 +23,18 @@
// 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_ROOT_LINK_ARRAY_HH
-# define SCRIBO_PRIMITIVE_INTERNAL_FIND_ROOT_LINK_ARRAY_HH
+#ifndef SCRIBO_PRIMITIVE_LINK_INTERNAL_DMAX_FUNCTOR_BASE_HH
+# define SCRIBO_PRIMITIVE_LINK_INTERNAL_DMAX_FUNCTOR_BASE_HH
/// \file
///
-/// Find root in a parent array arrays.
+/// Base class for dmax functors.
+# include <mln/core/alias/box2d.hh>
-# include <scribo/core/object_groups.hh>
+# include <mln/math/max.hh>
+# include <scribo/core/concept/dmax_functor.hh>
namespace scribo
{
@@ -40,34 +42,59 @@ namespace scribo
namespace primitive
{
+ namespace link
+ {
+
namespace internal
{
- /// Find root in a parent array arrays.
- template <typename L>
- unsigned
- find_root(object_groups<L>& parent, unsigned x);
+
+ /// \brief Base class for dmax functors.
+ template <typename E>
+ class dmax_functor_base : public DMax_Functor<E>
+ {
+
+ public:
+ dmax_functor_base(const float& dmax_factor);
+ float operator()(const box2d& b) const;
+
+ protected:
+ float dmax_factor_;
+ };
+
# ifndef MLN_INCLUDE_ONLY
- template <typename L>
- inline
- unsigned
- find_root(object_groups<L>& parent, unsigned x)
- {
- if (parent(x) == x)
- return x;
- else
- return parent(x) = find_root(parent, parent(x));
+
+ template <typename E>
+ dmax_functor_base<E>::dmax_functor_base(const float& dmax_factor)
+ : dmax_factor_(dmax_factor)
+ {
}
+
+ template <typename E>
+ float
+ dmax_functor_base<E>::operator()(const box2d& b) const
+ {
+ float
+ w = b.width(),
+ h = b.height();
+
+ return (w / 2.0f) + (dmax_factor_ * math::max(w, h));
+ }
+
+
# endif // ! MLN_INCLUDE_ONLY
- } // end of namespace scribo::primitive::internal
- } // end of namespace scribo::text
+ } // 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_INTERNAL_FIND_ROOT_LINK_ARRAY_HH
+#endif // ! SCRIBO_PRIMITIVE_LINK_INTERNAL_DMAX_FUNCTOR_BASE_HH
diff --git a/scribo/primitive/link/with_rag.hh
b/scribo/primitive/link/internal/dmax_width_and_height.hh
similarity index 53%
copy from scribo/primitive/link/with_rag.hh
copy to scribo/primitive/link/internal/dmax_width_and_height.hh
index 3638ec7..3f19f1f 100644
--- a/scribo/primitive/link/with_rag.hh
+++ b/scribo/primitive/link/internal/dmax_width_and_height.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -23,26 +23,16 @@
// 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_RAG_HH
-# define SCRIBO_PRIMITIVE_LINK_WITH_RAG_HH
-
+#ifndef SCRIBO_PRIMITIVE_LINK_INTERNAL_DMAX_WIDTH_AND_HEIGHT_HH
+# define SCRIBO_PRIMITIVE_LINK_INTERNAL_DMAX_WIDTH_AND_HEIGHT_HH
/// \file
///
-/// Link objects with a region adjacency graph.
-
-# include <mln/core/concept/neighborhood.hh>
-
-# include <mln/util/graph.hh>
-# include <mln/util/couple.hh>
-
-# include <mln/transform/influence_zone_geodesic.hh>
-
-# include <mln/make/influence_zone_adjacency_graph.hh>
-
+/// Dmax functor relying on width only.
+///
+/// For newspapers like ICDAR documents, use dmax_factor = 1.
-# include <scribo/core/macros.hh>
-# include <scribo/core/object_image.hh>
+# include <scribo/primitive/link/internal/dmax_functor_base.hh>
namespace scribo
@@ -54,46 +44,55 @@ namespace scribo
namespace link
{
- using namespace mln;
+ namespace internal
+ {
+
+ /// \brief Base class for dmax functors.
+ class dmax_width_and_height : public dmax_functor_base<dmax_width_and_height>
+ {
+ typedef dmax_functor_base<dmax_width_and_height> super_;
- template <typename L, typename N>
- util::couple<mln::util::graph, mln_concrete(L)>
- with_rag(const object_image(L)& objects,
- const Neighborhood<N>& nbh);
+ public:
+ dmax_width_and_height(const float& dmax_factor);
+ float operator()(const box2d&) const;
-# ifndef MLN_INCLUDE_ONLY
+ protected:
+ using super_::dmax_factor_;
+ };
- template <typename L, typename N>
- util::couple<mln::util::graph, mln_concrete(L)>
- with_rag(const object_image(L)& objects,
- const Neighborhood<N>& nbh)
- {
- trace::entering("scribo::primitive::link::with_rag");
+# ifndef MLN_INCLUDE_ONLY
- mln_precondition(objects.is_valid());
- mln_concrete(L)
- iz = transform::influence_zone_geodesic(objects, nbh);
+ dmax_width_and_height::dmax_width_and_height(const float& dmax_factor)
+ : super_(dmax_factor)
+ {
+ }
- mln::util::graph
- g = mln::make::influence_zone_adjacency_graph(iz,
- nbh,
- objects.nlabels());
- trace::exiting("scribo::primitive::link::with_rag");
- return make::couple(g, iz);
- }
+ float
+ dmax_width_and_height::operator()(const box2d& b) const
+ {
+ float
+ w = b.width(),
+ h = b.height();
+
+ return (w / 2.0f) + dmax_factor_ * (h + w);
+ }
# 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_WITH_RAG_HH
+
+#endif // ! SCRIBO_PRIMITIVE_LINK_INTERNAL_DMAX_WIDTH_AND_HEIGHT_HH
diff --git a/scribo/primitive/internal/find_root.hh
b/scribo/primitive/link/internal/dmax_width_only.hh
similarity index 56%
copy from scribo/primitive/internal/find_root.hh
copy to scribo/primitive/link/internal/dmax_width_only.hh
index 4fa6d20..034d40b 100644
--- a/scribo/primitive/internal/find_root.hh
+++ b/scribo/primitive/link/internal/dmax_width_only.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -23,15 +23,16 @@
// 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_ROOT_LINK_ARRAY_HH
-# define SCRIBO_PRIMITIVE_INTERNAL_FIND_ROOT_LINK_ARRAY_HH
+#ifndef SCRIBO_PRIMITIVE_LINK_INTERNAL_DMAX_WIDTH_ONLY_HH
+# define SCRIBO_PRIMITIVE_LINK_INTERNAL_DMAX_WIDTH_ONLY_HH
/// \file
///
-/// Find root in a parent array arrays.
-
+/// Dmax functor relying on width only.
+///
+/// To use for paragraph alignment.
-# include <scribo/core/object_groups.hh>
+# include <scribo/primitive/link/internal/dmax_functor_base.hh>
namespace scribo
@@ -40,34 +41,55 @@ namespace scribo
namespace primitive
{
+ namespace link
+ {
+
namespace internal
{
- /// Find root in a parent array arrays.
- template <typename L>
- unsigned
- find_root(object_groups<L>& parent, unsigned x);
+
+ /// \brief Base class for dmax functors.
+ class dmax_width_only : public dmax_functor_base<dmax_width_only>
+ {
+ typedef dmax_functor_base<dmax_width_only> super_;
+
+
+ public:
+ dmax_width_only();
+ float operator()(const box2d&) const;
+
+ protected:
+ using super_::dmax_factor_;
+ };
+
# ifndef MLN_INCLUDE_ONLY
- template <typename L>
- inline
- unsigned
- find_root(object_groups<L>& parent, unsigned x)
- {
- if (parent(x) == x)
- return x;
- else
- return parent(x) = find_root(parent, parent(x));
+
+ dmax_width_only::dmax_width_only()
+ : super_(0)
+ {
+ }
+
+
+ float
+ dmax_width_only::operator()(const box2d& b) const
+ {
+ float w = b.width();
+ return (w / 2.0f) + (dmax_factor_ * w);
}
+
# endif // ! MLN_INCLUDE_ONLY
- } // end of namespace scribo::primitive::internal
- } // end of namespace scribo::text
+ } // 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_INTERNAL_FIND_ROOT_LINK_ARRAY_HH
+#endif // ! SCRIBO_PRIMITIVE_LINK_INTERNAL_DMAX_WIDTH_ONLY_HH
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 1a4cb73..d3aba42 100644
--- a/scribo/primitive/link/internal/link_single_dmax_ratio_base.hh
+++ b/scribo/primitive/link/internal/link_single_dmax_ratio_base.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -43,6 +44,8 @@
# include <scribo/core/component_set.hh>
# include <scribo/core/object_links.hh>
+# include <scribo/core/concept/dmax_functor.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>
@@ -65,9 +68,9 @@ namespace scribo
/// \brief Base class for link functors using bounding box
/// center and a proportional max distance.
//
- template <typename L, typename E>
+ template <typename L, typename F, typename E>
class link_single_dmax_ratio_base
- : public link_functor_base<L, E>
+ : public link_functor_base<L,E>
{
typedef link_functor_base<L,E> super_;
typedef mln_result(accu::center<mln_psite(L)>) ms_t;
@@ -76,10 +79,9 @@ namespace scribo
typedef mln_site(L) P;
-
link_single_dmax_ratio_base(const component_set<L>& components,
- float dmax_ratio,
- anchor::Direction direction);
+ anchor::Direction direction,
+ const DMax_Functor<F>& dmax_f);
@@ -91,8 +93,8 @@ namespace scribo
void start_processing_object_(unsigned current_object);
- private:
- float dmax_ratio_;
+ protected:
+ const F dmax_f_;
float dmax_;
anchor::Direction direction_;
};
@@ -101,24 +103,24 @@ namespace scribo
# ifndef MLN_INCLUDE_ONLY
- template <typename L, typename E>
+ template <typename L, typename F, typename E>
inline
- link_single_dmax_ratio_base<L, E>::link_single_dmax_ratio_base(
+ link_single_dmax_ratio_base<L, F, E>::link_single_dmax_ratio_base(
const component_set<L>& components,
- float dmax_ratio,
- anchor::Direction direction)
+ anchor::Direction direction,
+ const DMax_Functor<F>& dmax_f)
- : super_(components),
- dmax_ratio_(dmax_ratio),
+ : super_(components),
+ dmax_f_(exact(dmax_f)),
dmax_(0),
direction_(direction)
{
}
- template <typename L, typename E>
+ template <typename L, typename F, typename E>
inline
bool
- link_single_dmax_ratio_base<L, E>::verify_link_criterion_(
+ link_single_dmax_ratio_base<L, F, E>::verify_link_criterion_(
unsigned current_object,
const P& start_point,
const P& p) const
@@ -130,10 +132,10 @@ namespace scribo
}
- template <typename L, typename E>
+ template <typename L, typename F, typename E>
inline
mln_site(L)
- link_single_dmax_ratio_base<L, E>::start_point_(unsigned current_object,
+ link_single_dmax_ratio_base<L, F, E>::start_point_(unsigned current_object,
anchor::Type anchor)
{
(void) anchor;
@@ -142,18 +144,33 @@ namespace scribo
}
- template <typename L, typename E>
+ template <typename L, typename F, typename E>
inline
void
- link_single_dmax_ratio_base<L, E>::start_processing_object_(
+ link_single_dmax_ratio_base<L, F, E>::start_processing_object_(
unsigned current_object)
{
- float
- w = this->components_.info(current_object).bbox().width(),
- h = this->components_.info(current_object).bbox().height();
-// dmax_ = (w / 2.0f) + (dmax_ratio_ * math::max(w, h));
-// dmax_ = (w / 2.0f) + (dmax_ratio_ * w);
- dmax_ = (w / 2.0f) + (h + w);
+ dmax_ = dmax_f_(this->components_.info(current_object).bbox());
+
+
+// float
+// w = this->components_.info(current_object).bbox().width();
+// // h = this->components_.info(current_object).bbox().height();
+
+// // FIXME: default case
+// // dmax_ = (w / 2.0f) + (dmax_ratio_ * math::max(w, h));
+
+// // FIXME: to use for paragraph alignment
+// dmax_ = (w / 2.0f) + (dmax_ratio_ * w);
+
+ // FIXME: to use for newspapers like ICDAR documents!
+// dmax_ = (w / 2.0f) + (h + w);
+
+ // FIXME: more general use case for newspapers
+// dmax_ = (w / 2.0f) + dmax_ratio_ * (h + w);
+
+
+ // FIXME: WE WANT TO PROVIDE A DMAX RULE THROUGH A FUNCTOR.
}
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 8be4ae2..dc99728 100644
--- a/scribo/primitive/link/with_single_left_link_dmax_ratio.hh
+++ b/scribo/primitive/link/with_single_left_link_dmax_ratio.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -40,10 +41,12 @@
# include <mln/util/array.hh>
# include <scribo/core/macros.hh>
+# include <scribo/core/concept/dmax_functor.hh>
# include <scribo/core/component_set.hh>
# include <scribo/core/object_links.hh>
# include <scribo/primitive/link/internal/find_link.hh>
+# include <scribo/primitive/link/internal/dmax_default.hh>
# include <scribo/primitive/link/internal/link_single_dmax_ratio_base.hh>
# include <scribo/primitive/link/compute.hh>
@@ -60,19 +63,38 @@ namespace scribo
/*! \brief Link components with their left neighbor if exists.
- \param[in] components An component image.
- \param[in] dmax_ratio
+ \param[in] components A component set.
+ \param[in] anchor Starting point for the neighbor lookup.
+ \param[in] dmax_f DMax functor defining the maximum lookup
+ distance.
\return Object links data.
+ Look for a neighbor until a maximum distance is reached. The
+ maximum distance is defined thanks to a functor \p dmax_f.
+ */
+ template <typename L, typename F>
+ inline
+ object_links<L>
+ with_single_left_link_dmax_ratio(const component_set<L>& components,
+ const DMax_Functor<F>& dmax_f,
+ anchor::Type anchor);
- Look for a neighbor until a maximum distance defined by :
-
- dmax = w / 2 + dmax_ratio * max(h, w)
+ /// \overload
+ ///
+ /// The default dmax functor is used (internal::dmax_default).
+ //
+ template <typename L, typename F>
+ inline
+ object_links<L>
+ with_single_left_link_dmax_ratio(const component_set<L>& components,
+ float dmax_ratio,
+ anchor::Type anchor);
- where w is the bounding box width and h the bounding box height.
- */
+ /// \overload
+ /// anchor is set to anchor::MassCenter.
+ //
template <typename L>
inline
object_links<L>
@@ -81,14 +103,18 @@ namespace scribo
/// \overload
- /// dmax_ratio is set to 3.
- template <typename L>
+ ///
+ /// The default dmax functor is used (internal::dmax_default)
+ /// with dmax_ratio set to 3.
+ ///
+ /// anchor is set to anchor::MassCenter.
+ //
+ template <typename L, typename F>
inline
object_links<L>
with_single_left_link_dmax_ratio(const component_set<L>& components);
-
# ifndef MLN_INCLUDE_ONLY
@@ -97,20 +123,20 @@ namespace scribo
// Functor
- template <typename L>
+ template <typename L, typename F>
class single_left_dmax_ratio_functor
- : public internal::link_single_dmax_ratio_base<L,
- single_left_dmax_ratio_functor<L> >
+ : public internal::link_single_dmax_ratio_base<L, F,
+ single_left_dmax_ratio_functor<L, F> >
{
- typedef single_left_dmax_ratio_functor<L> self_t;
- typedef internal::link_single_dmax_ratio_base<L, self_t> super_;
+ typedef single_left_dmax_ratio_functor<L, F> self_t;
+ typedef internal::link_single_dmax_ratio_base<L, F, self_t> super_;
public:
typedef mln_site(L) P;
single_left_dmax_ratio_functor(const component_set<L>& components,
- unsigned dmax)
- : super_(components, dmax, anchor::Horizontal)
+ const DMax_Functor<F>& dmax_f)
+ : super_(components, anchor::Horizontal, exact(dmax_f))
{
}
@@ -127,26 +153,54 @@ namespace scribo
// Facades
- template <typename L>
+ template <typename L, typename F>
inline
object_links<L>
with_single_left_link_dmax_ratio(const component_set<L>& components,
- float dmax_ratio)
+ const DMax_Functor<F>& dmax_f,
+ anchor::Type anchor)
{
trace::entering("scribo::primitive::link::with_single_left_link_dmax_ratio");
mln_precondition(components.is_valid());
- internal::single_left_dmax_ratio_functor<L>
- functor(components, dmax_ratio);
+ internal::single_left_dmax_ratio_functor<L, F>
+ functor(components, dmax_f);
- object_links<L> output = compute(functor);
+ object_links<L> output = compute(functor, anchor);
trace::exiting("scribo::primitive::link::with_single_left_link_dmax_ratio");
return output;
}
+ template <typename L, typename F>
+ inline
+ object_links<L>
+ with_single_left_link_dmax_ratio(const component_set<L>& components,
+ float dmax_ratio,
+ anchor::Type anchor)
+ {
+ return
+ with_single_left_link_dmax_ratio(components,
+ internal::dmax_default(dmax_ratio),
+ anchor);
+ }
+
+
+ template <typename L>
+ inline
+ object_links<L>
+ with_single_left_link_dmax_ratio(const component_set<L>& components,
+ float dmax_ratio)
+ {
+ return
+ with_single_left_link_dmax_ratio(components,
+ internal::dmax_default(dmax_ratio),
+ anchor::MassCenter);
+ }
+
+
template <typename L>
inline
object_links<L>
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 d3637ef..dea51d1 100644
--- a/scribo/primitive/link/with_single_right_link_dmax_ratio.hh
+++ b/scribo/primitive/link/with_single_right_link_dmax_ratio.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -61,25 +62,32 @@ namespace scribo
/*! \brief Link objects with their right neighbor if exists.
\param[in] components A component set.
- \param[in] dmax_ratio Size ratio defining the maximum lookup
- distance.
\param[in] anchor Starting point for the neighbor lookup.
+ \param[in] dmax_f DMax functor defining the maximum lookup
+ distance.
\return Object links data.
- Look for a neighbor until a maximum distance defined by :
-
- dmax = w / 2 + dmax_ratio * max(h, w)
+ Look for a neighbor until a maximum distance is reached. The
+ maximum distance is defined thanks to a functor \p dmax_f.
+ */
+ template <typename L, typename F>
+ inline
+ object_links<L>
+ with_single_right_link_dmax_ratio(const component_set<L>& components,
+ const DMax_Functor<F>& dmax_f,
+ anchor::Type anchor);
- where w is the bounding box width and h the bounding box height.
- */
+ /// \overload
+ /// \p dmax_f is set to internal::dmax_default.
template <typename L>
inline
object_links<L>
with_single_right_link_dmax_ratio(const component_set<L>& components,
- float dmax_ratio, anchor::Type anchor);
+ float dmax_ratio,
+ anchor::Type anchor);
/// \overload
/// anchor is set to MassCenter.
@@ -108,20 +116,20 @@ namespace scribo
// Functor
- template <typename L>
+ template <typename L, typename F>
class single_right_dmax_ratio_functor
- : public link_single_dmax_ratio_base<L,
- single_right_dmax_ratio_functor<L> >
+ : public link_single_dmax_ratio_base<L, F,
+ single_right_dmax_ratio_functor<L,F> >
{
- typedef single_right_dmax_ratio_functor<L> self_t;
- typedef link_single_dmax_ratio_base<L, self_t> super_;
+ typedef single_right_dmax_ratio_functor<L, F> self_t;
+ typedef link_single_dmax_ratio_base<L, F, self_t> super_;
public:
typedef mln_site(L) P;
single_right_dmax_ratio_functor(const component_set<L>& components,
- unsigned dmax)
- : super_(components, dmax, anchor::Horizontal)
+ const DMax_Functor<F>& dmax_f)
+ : super_(components, anchor::Horizontal, exact(dmax_f))
{
}
@@ -139,18 +147,19 @@ namespace scribo
// Facades
- template <typename L>
+ template <typename L, typename F>
inline
object_links<L>
with_single_right_link_dmax_ratio(const component_set<L>& components,
- float dmax_ratio, anchor::Type anchor)
+ const DMax_Functor<F>& dmax_f,
+ anchor::Type anchor)
{
trace::entering("scribo::primitive::link::with_single_right_link_dmax_ratio");
mln_precondition(components.is_valid());
- internal::single_right_dmax_ratio_functor<L>
- functor(components, dmax_ratio);
+ internal::single_right_dmax_ratio_functor<L, F>
+ functor(components, dmax_f);
object_links<L> output = compute(functor, anchor);
@@ -158,6 +167,19 @@ namespace scribo
return output;
}
+ template <typename L>
+ inline
+ object_links<L>
+ with_single_right_link_dmax_ratio(const component_set<L>& components,
+ float dmax_ratio,
+ anchor::Type anchor)
+ {
+ return
+ with_single_right_link_dmax_ratio(components,
+ internal::dmax_default(dmax_ratio),
+ anchor);
+ }
+
template <typename L>
@@ -166,7 +188,8 @@ namespace scribo
with_single_right_link_dmax_ratio(const component_set<L>& components,
float dmax_ratio)
{
- return with_single_right_link_dmax_ratio(components, dmax_ratio,
+ return with_single_right_link_dmax_ratio(components,
+ dmax_ratio,
anchor::MassCenter);
}
--
1.5.6.5