---
scribo/ChangeLog | 5 +
...> with_single_right_link_dmax_ratio_aligned.hh} | 165 +++++++++++++-------
2 files changed, 114 insertions(+), 56 deletions(-)
copy scribo/scribo/primitive/link/{with_single_right_link_dmax_ratio.hh =>
with_single_right_link_dmax_ratio_aligned.hh} (52%)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 8895733..d04b792 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,10 @@
2010-11-16 Guillaume Lazzara <z(a)lrde.epita.fr>
+ * scribo/primitive/link/with_single_right_link_dmax_ratio_aligned.hh:
+ New.
+
+2010-11-16 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Improve text_in_picture_neg.
* scribo/toolchain/text_in_picture.hh: Remove useless argument.
diff --git a/scribo/scribo/primitive/link/with_single_right_link_dmax_ratio.hh
b/scribo/scribo/primitive/link/with_single_right_link_dmax_ratio_aligned.hh
similarity index 52%
copy from scribo/scribo/primitive/link/with_single_right_link_dmax_ratio.hh
copy to scribo/scribo/primitive/link/with_single_right_link_dmax_ratio_aligned.hh
index 03e2840..feba5f2 100644
--- a/scribo/scribo/primitive/link/with_single_right_link_dmax_ratio.hh
+++ b/scribo/scribo/primitive/link/with_single_right_link_dmax_ratio_aligned.hh
@@ -24,8 +24,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_WITH_SINGLE_RIGHT_LINK_DMAX_RATIO_HH
-# define SCRIBO_PRIMITIVE_LINK_WITH_SINGLE_RIGHT_LINK_DMAX_RATIO_HH
+#ifndef SCRIBO_PRIMITIVE_LINK_WITH_SINGLE_RIGHT_LINK_DMAX_RATIO_ALIGNED_HH
+# define SCRIBO_PRIMITIVE_LINK_WITH_SINGLE_RIGHT_LINK_DMAX_RATIO_ALIGNED_HH
/// \file
///
@@ -44,11 +44,13 @@
# include <scribo/core/component_set.hh>
# include <scribo/core/object_links.hh>
+# include <scribo/primitive/link/internal/dmax_default.hh>
# include <scribo/primitive/link/internal/find_link.hh>
# include <scribo/primitive/link/internal/link_single_dmax_ratio_base.hh>
# include <scribo/primitive/link/compute.hh>
-# include <scribo/primitive/link/internal/dmax_default.hh>
+
+# include <scribo/filter/internal/component_aligned.hh>
namespace scribo
@@ -63,40 +65,38 @@ 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 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);
+ Look for a neighbor until a maximum distance defined by :
+ dmax = w / 2 + dmax_ratio * max(h, w)
- /// \overload
- /// \p dmax_f is set to internal::dmax_default.
+ where w is the bounding box width and h the bounding box height.
+
+ */
template <typename L>
inline
object_links<L>
- with_single_right_link_dmax_ratio(const component_set<L>& components,
- float dmax_ratio,
- anchor::Type anchor);
+ with_single_right_link_dmax_ratio_aligned(
+ const component_set<L>& components,
+ float dmax_ratio,
+ float min_angle, float max_angle,
+ anchor::Type anchor);
/// \overload
/// anchor is set to MassCenter.
template <typename L>
inline
object_links<L>
- with_single_right_link_dmax_ratio(const component_set<L>& components,
- float dmax_ratio);
+ with_single_right_link_dmax_ratio_aligned(
+ const component_set<L>& components,
+ float dmax_ratio,
+ float min_angle, float max_angle);
/// \overload
@@ -105,7 +105,8 @@ namespace scribo
template <typename L>
inline
object_links<L>
- with_single_right_link_dmax_ratio(const component_set<L>& components);
+ with_single_right_link_dmax_ratio_aligned(
+ const component_set<L>& components);
@@ -118,20 +119,33 @@ namespace scribo
// Functor
template <typename L, typename F>
- class single_right_dmax_ratio_functor
+ class single_right_dmax_ratio_aligned_functor
: public link_single_dmax_ratio_base<L, F,
- single_right_dmax_ratio_functor<L,F> >
+ single_right_dmax_ratio_aligned_functor<L,F> >
{
- typedef single_right_dmax_ratio_functor<L, F> self_t;
+ typedef single_right_dmax_ratio_aligned_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,
- const DMax_Functor<F>& dmax_f)
- : super_(components, anchor::Horizontal, exact(dmax_f))
+ single_right_dmax_ratio_aligned_functor(
+ const component_set<L>& components,
+ const DMax_Functor<F>& dmax_f,
+ float min_angle,
+ float max_angle,
+ anchor::Type anchor_)
+ : super_(components, exact(dmax_f), anchor::Horizontal),
+ anchor(anchor_)
{
+ std::cout << "min_angle = " << min_angle
+ << " - max_angle = " << max_angle
+ << std::endl;
+ std::cout << "min_angle_rad = " << min_alpha_rad
+ << " - max_angle_rad = " << max_alpha_rad
+ << std::endl;
+ min_alpha_rad = (min_angle / 180.0f) * math::pi;
+ max_alpha_rad = (max_angle / 180.0f) * math::pi;
}
void compute_next_site_(P& p)
@@ -139,6 +153,49 @@ namespace scribo
++p.col();
}
+
+ inline
+ bool
+ valid_link_(unsigned current_object,
+ const P& start_point,
+ const P& p)
+ {
+ bool super_b = super_::valid_link_(current_object,
+ start_point, p);
+
+ // Distance between the two components.
+ float dist = math::abs(p[this->direction_] - start_point[this->direction_]);
+
+
+ unsigned ldist = this->components_(current_object).bbox().width() / 2;
+
+
+ // Components are really close, so the angle is more permissive.
+ if (dist < (ldist + ldist * 0.2))
+ {
+ return super_b
+ &&
+ filter::internal::component_aligned_rad(this->components_,
+ current_object,
+ this->labeled_image_(p),
+ anchor,
+ max_alpha_rad);
+ }
+
+
+ // Components are really far, so the angle is less permissive.
+ return super_b
+ && filter::internal::component_aligned_rad(this->components_,
+ current_object,
+ this->labeled_image_(p),
+ anchor,
+ min_alpha_rad);
+ }
+
+ float min_alpha_rad;
+ float max_alpha_rad;
+ anchor::Type anchor;
+
};
} // end of namespace scribo::primitive::link::internal
@@ -151,56 +208,52 @@ namespace scribo
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)
+ with_single_right_link_dmax_ratio_aligned(
+ const component_set<L>& components,
+ const DMax_Functor<F>& dmax_f,
+ float min_angle, float max_angle,
+ anchor::Type anchor)
{
- trace::entering("scribo::primitive::link::with_single_right_link_dmax_ratio");
+ trace::entering("scribo::primitive::link::with_single_right_link_dmax_ratio_aligned");
mln_precondition(components.is_valid());
- internal::single_right_dmax_ratio_functor<L, F>
- functor(components, dmax_f);
+ internal::single_right_dmax_ratio_aligned_functor<L,F>
+ functor(components, dmax_f, min_angle, max_angle, anchor);
object_links<L> output = compute(functor, anchor);
- trace::exiting("scribo::primitive::link::with_single_right_link_dmax_ratio");
+ trace::exiting("scribo::primitive::link::with_single_right_link_dmax_ratio_aligned");
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>
inline
object_links<L>
- with_single_right_link_dmax_ratio(const component_set<L>& components,
- float dmax_ratio)
+ with_single_right_link_dmax_ratio_aligned(
+ const component_set<L>& components,
+ float dmax_ratio,
+ float min_angle, float max_angle)
{
- return with_single_right_link_dmax_ratio(components,
- dmax_ratio,
- anchor::MassCenter);
+ return
+ with_single_right_link_dmax_ratio_aligned(components,
+ internal::dmax_default(dmax_ratio),
+ min_angle,
+ max_angle,
+ anchor::MassCenter);
}
template <typename L>
inline
object_links<L>
- with_single_right_link_dmax_ratio(const component_set<L>& components)
+ with_single_right_link_dmax_ratio_aligned(
+ const component_set<L>& components)
{
- return with_single_right_link_dmax_ratio(components, 3);
+ return
+ with_single_right_link_dmax_ratio_aligned(components, 3, 3, 10);
}
@@ -212,4 +265,4 @@ namespace scribo
} // end of namespace scribo
-#endif // ! SCRIBO_PRIMITIVE_LINK_WITH_SINGLE_RIGHT_LINK_DMAX_RATIO_HH
+#endif // ! SCRIBO_PRIMITIVE_LINK_WITH_SINGLE_RIGHT_LINK_DMAX_RATIO_ALIGNED_HH
--
1.5.6.5