Commit 6181ecd5 authored by Guillaume Lazzara's avatar Guillaume Lazzara
Browse files

Revamp code related to object linking.

	* core/concept/link_functor.hh: New concept.

	* core/internal/link_functor_base.hh: New Base class for link
	functor.

	* primitive/link/compute.hh,
	* primitive/link/compute_several.hh,
	* primitive/link/internal/anchors_3.hh,
	* primitive/link/internal/find_link.hh,
	* primitive/link/internal/find_several_links.hh,
	* primitive/link/with_several_right_closest_links.hh,
	* primitive/link/with_several_right_links_overlap.hh,
	* primitive/link/with_single_left_link_dmax_ratio.hh,
	* primitive/link/with_single_right_link_bottom.hh,
	* primitive/link/with_single_right_link_dmax_ratio.hh,
	* primitive/link/with_single_right_link_top.hh: New routines.

	* primitive/link/internal/link_center_dmax_base.hh,
	* primitive/link/internal/link_center_dmax_ratio_base.hh,
	* primitive/link/internal/link_functor_base.hh,
	* primitive/link/internal/link_ms_dmax_base.hh,
	* primitive/link/internal/link_ms_dmax_ratio_base.hh: New functors.

	* primitive/link/with_several_left_links.hh,
	* primitive/link/with_several_right_links.hh: Use the new routines.

	* primitive/link/with_single_left_link.hh,
	* primitive/link/with_single_right_link.hh: Revamp and use the new
	routines.

git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@4705 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent f97abc33
2009-11-03 Guillaume Lazzara <z@lrde.epita.fr>
Revamp code related to object linking.
* core/concept/link_functor.hh: New concept.
* core/internal/link_functor_base.hh: New Base class for link
functor.
* primitive/link/compute.hh,
* primitive/link/compute_several.hh,
* primitive/link/internal/anchors_3.hh,
* primitive/link/internal/find_link.hh,
* primitive/link/internal/find_several_links.hh,
* primitive/link/with_several_right_closest_links.hh,
* primitive/link/with_several_right_links_overlap.hh,
* primitive/link/with_single_left_link_dmax_ratio.hh,
* primitive/link/with_single_right_link_bottom.hh,
* primitive/link/with_single_right_link_dmax_ratio.hh,
* primitive/link/with_single_right_link_top.hh: New routines.
* primitive/link/internal/link_center_dmax_base.hh,
* primitive/link/internal/link_center_dmax_ratio_base.hh,
* primitive/link/internal/link_functor_base.hh,
* primitive/link/internal/link_ms_dmax_base.hh,
* primitive/link/internal/link_ms_dmax_ratio_base.hh: New functors.
* primitive/link/with_several_left_links.hh,
* primitive/link/with_several_right_links.hh: Use the new routines.
* primitive/link/with_single_left_link.hh,
* primitive/link/with_single_right_link.hh: Revamp and use the new
routines.
2009-11-03 Guillaume Lazzara <z@lrde.epita.fr>
Small fixes in Scribo.
* debug/decision_image.hh: Fix precondition.
* filter/object_links_bbox_h_ratio.hh,
* filter/objects_thick.hh,
* primitive/internal/have_link_valid.hh,
* primitive/internal/is_link_valid.hh: Fix doc.
* filter/object_links_bbox_ratio.hh: Fix doc and invert ratio.
* filter/object_links_bottom_aligned.hh: Fix doc and use a float
angle value.
* filter/object_links_non_aligned.hh: Use absolute values.
* filter/object_links_non_aligned_simple.hh: Add special cases.
* filter/object_links_non_h_aligned.hh: Fix call to an underlying
routine.
* filter/objects_small.hh,
* filter/objects_thin.hh,
* filter/objects_v_thin.hh,
* primitive/extract/lines_discontinued.hh,
* primitive/extract/lines_h_single.hh,
* primitive/extract/lines_h_thick_and_single.hh,
* primitive/extract/lines_thick.hh,
* primitive/extract/lines_v_discontinued.hh,
* primitive/extract/lines_v_single.hh,
* primitive/extract/lines_v_thick_and_single.hh,
* primitive/internal/is_invalid_link.hh,
* src/multi_scale/find_lines.cc,
* src/primitive/group/group_from_rag.cc,
* src/table/rebuild_opening.cc,
* src/table/rebuild_rank.cc,
* text/clean.hh: Avoid warnings.
* primitive/internal/find_left_link.hh,
* primitive/internal/find_right_link.hh,
* primitive/internal/update_link_array.hh: Make the routine return
a value.
* src/binarization/sauvola.cc,
* src/binarization/sauvola_pgm.cc: Fix call to Sauvola's algorithm.
* src/primitive/group/group_from_graph.cc,
* src/primitive/group/group_from_several_graph.cc: Change
arguments values while calling with_several_graphes.
2009-10-22 Guillaume Lazzara <z@lrde.epita.fr>
Add new debug routines.
......
// 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_LINK_FUNCTOR_HH
# define SCRIBO_CORE_INTERNAL_LINK_FUNCTOR_HH
/// \file
///
/// Link 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.
template <typename E>
class Link_Functor : public mln::Object<E>
{
// typedef L support
};
} // end of namespace scribo
#endif // SCRIBO_CORE_INTERNAL_LINK_FUNCTOR_HH
// 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_LINK_INTERNAL_LINK_FUNCTOR_BASE_HH
# define SCRIBO_PRIMITIVE_LINK_INTERNAL_LINK_FUNCTOR_BASE_HH
/// \file
///
/// Base class for link functors.
# include <mln/core/concept/image.hh>
# include <mln/math/abs.hh>
# include <mln/util/array.hh>
# include <mln/util/couple.hh>
# include <scribo/core/concept/link_functor.hh>
# include <scribo/core/object_image.hh>
# include <scribo/core/object_links.hh>
# include <scribo/primitive/internal/init_link_array.hh>
namespace scribo
{
namespace internal
{
/// \brief Base class for link functors.
template <typename L, typename E>
class link_functor_base : public Link_Functor<E>
{
public:
typedef L support;
link_functor_base(const object_image(L)& objects);
const object_links<L>& links() const;
unsigned link(unsigned object) const;
const object_image(L)& objects() const;
protected:
object_links<L> links_;
const object_image(L) objects_;
};
# ifndef MLN_INCLUDE_ONLY
template <typename L, typename E>
inline
link_functor_base<L,E>::link_functor_base(const object_image(L)& objects)
: links_(objects, static_cast<unsigned>(objects.nlabels()) + 1),
objects_(objects)
{
primitive::internal::init_link_array(links_);
}
template <typename L, typename E>
inline
const object_links<L>&
link_functor_base<L,E>::links() const
{
return links_;
}
template <typename L, typename E>
inline
unsigned
link_functor_base<L,E>::link(unsigned object) const
{
return links_[object];
}
template <typename L, typename E>
inline
const object_image(L)&
link_functor_base<L,E>::objects() const
{
return objects_;
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace scribo::internal
} // end of namespace scribo
#endif // ! SCRIBO_PRIMITIVE_LINK_INTERNAL_LINK_FUNCTOR_BASE_HH
// 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_LINK_COMPUTE_HH
# define SCRIBO_PRIMITIVE_LINK_COMPUTE_HH
/// \file
///
/// Compute links between objects according a given functor.
# include <scribo/core/macros.hh>
# include <scribo/core/object_links.hh>
# include <scribo/core/concept/link_functor.hh>
# include <scribo/primitive/link/internal/find_link.hh>
namespace scribo
{
namespace primitive
{
namespace link
{
/*! \brief Compute links between objects according a given functor.
\param[in,out] functor Linking policy.
\return Object links.
Functors must implement the following interface :
bool is_potential_link(unsigned current_object,
const P& start_point, const P& p) const
bool valid_link(unsigned current_object,
const P& start_point, const P& p)
bool verify_link_criterion(unsigned current_object,
const P& start_point, const P& p)
void validate_link(unsigned current_object,
const P& start_point, const P& p)
void invalidate_link(unsigned current_object,
const P& start_point, const P& p)
void compute_next_site(P& p)
const mln_site(L)& start_point(unsigned current_object)
void start_processing_object(unsigned current_object)
*/
template <typename F>
object_links<scribo_support(F)>
compute(Link_Functor<F>& functor);
# ifndef MLN_INCLUDE_ONLY
template <typename F>
object_links<scribo_support(F)>
compute(Link_Functor<F>& functor_)
{
trace::entering("scribo::primitive::link::compute");
F& functor = exact(functor_);
for_all_ncomponents(current_object, functor.objects().nlabels())
{
functor.start_processing_object(current_object); //<-- start_processing_object
primitive::internal::find_link(functor, current_object);
}
trace::exiting("scribo::primitive::link::compute");
return functor.links();
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace scribo::primitive::link
} // end of namespace scribo::primitive
} // end of namespace scribo
#endif // ! SCRIBO_PRIMITIVE_LINK_COMPUTE_HH
// 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_LINK_COMPUTE_SEVERAL_HH
# define SCRIBO_PRIMITIVE_LINK_COMPUTE_SEVERAL_HH
/// \file
///
/// Compute_Several links between objects according a given functor.
# include <scribo/core/macros.hh>
# include <scribo/core/object_links.hh>
# include <scribo/core/concept/link_functor.hh>
# include <scribo/primitive/link/internal/find_several_links.hh>
namespace scribo
{
namespace primitive
{
namespace link
{
/*! \brief Compute_Several links between objects according a given functor.
\param[in,out] functor Linking policy.
\return Object links.
Functors must implement the following interface :
bool verify_link_criterion_(unsigned current_object,
const P& start_point, const P& p) const;
void start_processing_object_(unsigned current_object);
mln_site(L) start_point_(unsigned current_object, unsigned anchor);
void validate_link_(unsigned current_object, const P& start_point,
const P& p, unsigned anchor);
void invalidate_link_(unsigned current_object, const P& start_point,
const P& p, unsigned anchor);
void initialize_link_(unsigned current_object);
void finalize_link_(unsigned current_object);
bool is_potential_link(unsigned current_object,
const P& start_point, const P& p) const
void compute_next_site(P& p)
*/
template <typename F>
object_links<scribo_support(F)>
compute_several(Link_Functor<F>& functor);
# ifndef MLN_INCLUDE_ONLY
template <typename F>
object_links<scribo_support(F)>
compute_several(Link_Functor<F>& functor_)
{
trace::entering("scribo::primitive::link::compute_several");
F& functor = exact(functor_);
for_all_ncomponents(current_object, functor.objects().nlabels())
{
functor.start_processing_object(current_object); //<-- start_processing_object
primitive::internal::find_several_links(functor, current_object);
}
trace::exiting("scribo::primitive::link::compute_several");
return functor.links();
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace scribo::primitive::link
} // end of namespace scribo::primitive
} // end of namespace scribo
#endif // ! SCRIBO_PRIMITIVE_LINK_COMPUTE_SEVERAL_HH
// 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_LINK_INTERNAL_ANCHORS_3_HH
# define SCRIBO_PRIMITIVE_LINK_INTERNAL_ANCHORS_3_HH
/// \file
///
/// Routine providing 3 anchors for neighbor seeking.
# include <mln/math/min.hh>
# include <scribo/core/object_image.hh>
namespace scribo
{
namespace primitive
{
namespace link
{
namespace internal
{
/*! \brief Return the proper anchor used to find a neighbor.
This routine provides up to 3 different anchors.
\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:
- 0, top anchor.
- 1, center anchor. It is the mass center.
- 2, bottom anchor.
Top and bottom anchors are respectively computed from the
bbox pmin and the bbox pmax, P.
Then the output anchor coordinates are computed as follows:
out.col = bbox.center.col
if object height, h, is lower than 30.
out.row = P.row + min(2, (h + 1) / 2 - 1)
else
out.row = P.row - min(10, h /10)
*/
template <typename L, typename P>
mln_site(L)
anchors_3(const object_image(L)& objects,
const mln::util::array<P>& mass_centers,
unsigned current_object, unsigned anchor);
# ifndef MLN_INCLUDE_ONLY
template <typename L, typename P>
mln_site(L)
anchors_3(const object_image(L)& objects,
const mln::util::array<P>& mass_centers,
unsigned current_object, unsigned anchor)
{
unsigned h = objects.bbox(current_object).pmax().row()
- objects.bbox(current_object).pmin().row();
mln_site(L) sp = objects.bbox(current_object).center();
def::coord r;
switch (anchor)
{
// Top
case 0:
if (h < 30)
r = objects.bbox(current_object).pmin().row()
+ math::min(2u, (h + 1) / 2 - 1);
else
r = objects.bbox(current_object).pmin().row()
- math::min(10u, h /10);
break;
// Center
case 1:
return mass_centers(current_object);
// Bottom
case 2:
if (h < 30)
r = objects.bbox(current_object).pmax().row()
+ math::min(2u, (h + 1) / 2 - 1);
else
r = objects.bbox(current_object).pmax().row()
- math::min(10u, h /10);
break;
default:
trace::warning("Non handled anchor");
mln_assertion(anchor > 2);