Commit 9d7a1cca authored by Guillaume Lazzara's avatar Guillaume Lazzara
Browse files

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.
parent a184c810
2010-04-30 Guillaume Lazzara <z@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@lrde.epita.fr>
Small fixes in Scribo.
......
// 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_CORE_INTERNAL_DMAX_FUNCTOR_HH
# define SCRIBO_CORE_INTERNAL_DMAX_FUNCTOR_HH
/// \file
///
/// DMax functor concept.
# include <mln/core/concept/object.hh>
namespace scribo
{
/// \brief Dmax functor concept.
template <typename E>
class DMax_Functor : public mln::Object<E>
{
// typedef L support
};
} // end of namespace scribo
#endif // SCRIBO_CORE_INTERNAL_DMAX_FUNCTOR_HH
// Copyright (C) 2010 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_DMAX_DEFAULT_HH
# define SCRIBO_PRIMITIVE_LINK_INTERNAL_DMAX_DEFAULT_HH
/// \file
///
/// Default class for dmax functors.
# include <scribo/primitive/link/internal/dmax_functor_base.hh>
namespace scribo
{
namespace primitive
{
namespace link
{
namespace internal
{
/// \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
dmax_default::dmax_default(const float& dmax_factor)
: super_(dmax_factor)
{
}
# 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_DMAX_DEFAULT_HH
// Copyright (C) 2010 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_DMAX_FUNCTOR_BASE_HH
# define SCRIBO_PRIMITIVE_LINK_INTERNAL_DMAX_FUNCTOR_BASE_HH
/// \file
///
/// Base class for dmax functors.
# include <mln/core/alias/box2d.hh>
# include <mln/math/max.hh>
# include <scribo/core/concept/dmax_functor.hh>
namespace scribo
{
namespace primitive
{
namespace link
{
namespace internal
{
/// \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 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::link::internal
} // end of namespace scribo::primitive::link
} // end of namespace scribo::primitive
} // end of namespace scribo
#endif // ! SCRIBO_PRIMITIVE_LINK_INTERNAL_DMAX_FUNCTOR_BASE_HH
// Copyright (C) 2010 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_DMAX_WIDTH_AND_HEIGHT_HH
# define SCRIBO_PRIMITIVE_LINK_INTERNAL_DMAX_WIDTH_AND_HEIGHT_HH
/// \file
///
/// Dmax functor relying on width only.
///
/// For newspapers like ICDAR documents, use dmax_factor = 1.
# include <scribo/primitive/link/internal/dmax_functor_base.hh>
namespace scribo
{
namespace primitive
{
namespace link
{
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_;
public:
dmax_width_and_height(const float& dmax_factor);
float operator()(const box2d&) const;
protected:
using super_::dmax_factor_;
};
# ifndef MLN_INCLUDE_ONLY
dmax_width_and_height::dmax_width_and_height(const float& dmax_factor)
: super_(dmax_factor)
{
}
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_INTERNAL_DMAX_WIDTH_AND_HEIGHT_HH
// Copyright (C) 2010 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_DMAX_WIDTH_ONLY_HH
# define SCRIBO_PRIMITIVE_LINK_INTERNAL_DMAX_WIDTH_ONLY_HH
/// \file
///
/// Dmax functor relying on width only.
///
/// To use for paragraph alignment.
# include <scribo/primitive/link/internal/dmax_functor_base.hh>
namespace scribo
{
namespace primitive
{
namespace link
{
namespace internal
{
/// \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
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::link::internal
} // end of namespace scribo::primitive::link
} // end of namespace scribo::primitive
} // end of namespace scribo
#endif // ! SCRIBO_PRIMITIVE_LINK_INTERNAL_DMAX_WIDTH_ONLY_HH
// 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.
}
......
// 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.