Commit 8283ce59 authored by Guillaume Lazzara's avatar Guillaume Lazzara
Browse files

Small fixes in Scribo.

	* core/component_info.hh (is_valid): Check the bounding box
	validity.

	* core/macros.hh: Add a new macro.

	* debug/decision_image.hh: Remove deprecated preconditions and add
	missing includes.

	* debug/save_linked_bboxes_image.hh: Add the anchor type as
	argument.

	* draw/bounding_box_links.hh: Add the anchor type as argument and
	make use of component information.

	* draw/bounding_boxes.hh: Check the component validity.

	* filter/object_links_non_aligned_simple.hh: Update doc.

	* filter/objects_with_holes.hh: Remove debug and timers. Add
	missing includes.

	* primitive/extract/lines_pattern.hh: Use the window template
	parameter instead of an exact window type.

	* primitive/link/internal/find_several_links.hh: Update code with
	new interfaces.

	* primitive/link/internal/link_functor_base.hh
	(nanchors()): Remove this method.
	(labeled_image()): Add a const version.

	* primitive/link/internal/link_several_dmax_base.hh
	(nanchors(), anchors()): New methods.
	Introduce 'direction_' attribute.

	* debug/several_links_decision_image.hh: Remove deprecated
	preconditions.

	* src/debug/show_links_single_left.cc: Update include.

	* table/internal/align_lines.hh,
	* table/rebuild.hh: Make use of component_set structure.

	* debug/text_areas_image.hh,
	* primitive/regroup/from_single_left_link_wrt_h_ratio.hh: Add
	missing includes.

	* src/contest/hdibco-2010/Makefile.am: Do not consider this tool
	as a test anymore.
parent 8559cd77
2010-08-09 Guillaume Lazzara <z@lrde.epita.fr>
Small fixes in Scribo.
* core/component_info.hh (is_valid): Check the bounding box
validity.
* core/macros.hh: Add a new macro.
* debug/decision_image.hh: Remove deprecated preconditions and add
missing includes.
* draw/bounding_boxes.hh: Check the component validity.
* filter/object_links_non_aligned_simple.hh: Update doc.
* filter/objects_with_holes.hh: Remove debug and timers. Add
missing includes.
* primitive/extract/lines_pattern.hh: Use the window template
parameter instead of an exact window type.
* primitive/link/internal/find_several_links.hh: Update code with
new interfaces.
* primitive/link/internal/link_functor_base.hh
(nanchors()): Remove this method.
(labeled_image()): Add a const version.
* primitive/link/internal/link_several_dmax_base.hh
(nanchors(), anchors()): New methods.
Introduce 'direction_' attribute.
* debug/several_links_decision_image.hh: Remove deprecated
preconditions.
* src/debug/show_links_single_left.cc: Update include.
* table/internal/align_lines.hh,
* table/rebuild.hh: Make use of component_set structure.
* debug/text_areas_image.hh,
* primitive/regroup/from_single_left_link_wrt_h_ratio.hh: Add
missing includes.
* src/contest/hdibco-2010/Makefile.am: Do not consider this tool
as a test anymore.
2010-08-09 Guillaume Lazzara <z@lrde.epita.fr>
Add missing includes and headers in AFP's dedicated code.
......
......@@ -176,7 +176,7 @@ namespace scribo
bool
component_info::is_valid() const
{
return tag_ != component::Ignored;
return tag_ != component::Ignored && bbox_.is_valid();
}
......
......@@ -58,4 +58,7 @@
# define for_all_lines_info(E, S) \
for_all_comp_data(E, S)
# define for_all_anchors(E, S) \
for_all_elements(E, S)
#endif // ! SCRIBO_CORE_MACROS_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.
//
......@@ -35,9 +36,12 @@
# include <mln/value/rgb8.hh>
# include <mln/literal/colors.hh>
# include <mln/util/array.hh>
# include <mln/draw/box.hh>
# include <mln/draw/line.hh>
# include <scribo/core/tag/anchor.hh>
# include <scribo/core/object_groups.hh>
# include <scribo/draw/bounding_boxes.hh>
# include <scribo/primitive/link/internal/compute_anchor.hh>
namespace scribo
......@@ -105,8 +109,6 @@ namespace scribo
mln_precondition(input.is_valid());
mln_precondition(groups.is_valid());
mln_precondition(filtered_groups.is_valid());
mln_precondition(groups.size() == filtered_groups.size());
mln_precondition(groups.components_id_() != filtered_groups.components_id_());
/// Fixme: check that components has been computed from input.
image2d<value::rgb8>
......@@ -114,9 +116,11 @@ namespace scribo
for (unsigned i = 1; i < groups.size(); ++i)
if (groups(i) != filtered_groups(i))
mln::draw::box(decision_image, components(i).bbox(), literal::red);
mln::draw::box(decision_image, components(i).bbox(),
literal::red);
else
mln::draw::box(decision_image, components(i).bbox(), literal::green);
mln::draw::box(decision_image, components(i).bbox(),
literal::green);
trace::exiting("scribo::debug::decision_image");
return decision_image;
......@@ -138,8 +142,6 @@ namespace scribo
mln_precondition(input.is_valid());
mln_precondition(links.is_valid());
mln_precondition(filtered_links.is_valid());
mln_precondition(links.size() == filtered_links.size());
mln_precondition(links.object_image_() != filtered_links.object_image_());
/// Fixme: check that components has been computed from input.
image2d<value::rgb8>
......@@ -155,7 +157,8 @@ namespace scribo
{
mln_site(L)
p1 = primitive::link::internal::compute_anchor(comps, i, anchor),
p2 = primitive::link::internal::compute_anchor(comps, links(i), anchor);
p2 = primitive::link::internal::compute_anchor(comps, links(i),
anchor);
value::rgb8 value = literal::green;
if (links(i) != filtered_links(i))
......
// 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.
//
......@@ -38,6 +39,7 @@
# include <mln/value/rgb8.hh>
# include <mln/util/array.hh>
# include <mln/io/ppm/save.hh>
# include <mln/literal/colors.hh>
# include <scribo/core/object_links.hh>
# include <scribo/core/component_set.hh>
......@@ -57,7 +59,6 @@ namespace scribo
/// Save the line of components links image.
///
/// \param[in,out] input The binary from where the components are extracted.
/// \param[in] components An object image.
/// \param[in] link_array Lines of components links.
/// \param[in] box_value Value used to draw line bounding boxes.
/// \param[in] link_value Value used to draw line links.
......@@ -67,12 +68,11 @@ namespace scribo
template <typename I, typename L>
void
save_linked_bboxes_image(const Image<I>& input,
const component_set<L>& components,
const object_links<L>& array,
const value::rgb8& box_value,
const value::rgb8& link_value,
const std::string& filename,
anchor::Type anchor);
anchor::Type anchor,
const std::string& filename);
/// \overload
/// The default anchor type is set to anchor::Center.
......@@ -80,7 +80,6 @@ namespace scribo
template <typename I, typename L>
void
save_linked_bboxes_image(const Image<I>& input,
const component_set<L>& components,
const object_links<L>& array,
const value::rgb8& box_value,
const value::rgb8& link_value,
......@@ -89,7 +88,6 @@ namespace scribo
/// Save the line of components left and right links image.
///
/// \param[in,out] input The binary from where the components are extracted.
/// \param[in] components An object image.
/// \param[in] left_link Lines of components left links.
/// \param[in] right_link Lines of components right links.
/// \param[in] box_value Value used to draw line bounding boxes.
......@@ -98,18 +96,17 @@ namespace scribo
template <typename I, typename L>
void
save_linked_bboxes_image(const Image<I>& input,
const component_set<L>& components,
const object_links<L>& left_link,
const object_links<L>& right_link,
const value::rgb8& box_value,
const value::rgb8& link_value,
anchor::Type anchor,
const std::string& filename);
/// Save the line of components left and right links image.
/// Draw also validated links.
///
/// \param[in,out] input The binary from where the components are extracted.
/// \param[in] components An object image.
/// \param[in] left_link Lines of components left links.
/// \param[in] right_link Lines of components right links.
/// \param[in] box_value Value used to draw line bounding boxes.
......@@ -121,20 +118,19 @@ namespace scribo
inline
void
save_linked_bboxes_image(const Image<I>& input,
const component_set<L>& components,
const object_links<L>& left_link,
const object_links<L>& right_link,
const value::rgb8& box_value,
const value::rgb8& left_link_value,
const value::rgb8& right_link_value,
const value::rgb8& validated_link_value,
anchor::Type anchor,
const std::string& filename);
/// Save the line link graph image.
///
/// \param[in,out] input The binary from where the components are extracted.
/// \param[in] components An object image.
/// \param[in] g The link graph.
/// \param[in] box_value Value used to draw line bounding boxes.
/// \param[in] link_value Value used to draw line links.
......@@ -142,10 +138,10 @@ namespace scribo
template <typename I, typename L, typename G>
void
save_linked_bboxes_image(const Image<I>& input,
const component_set<L>& components,
const Graph<G>& g,
const value::rgb8& box_value,
const value::rgb8& link_value,
anchor::Type anchor,
const std::string& filename);
......@@ -156,20 +152,19 @@ namespace scribo
inline
void
save_linked_bboxes_image(const Image<I>& input,
const component_set<L>& components,
const object_links<L>& array,
const object_links<L>& links,
const value::rgb8& box_value,
const value::rgb8& link_value,
const std::string& filename,
anchor::Type anchor)
anchor::Type anchor,
const std::string& filename)
{
trace::entering("scribo::debug::save_linked_bboxes_image");
mln_precondition(exact(input).is_valid());
mln_ch_value(I,value::rgb8) tmp = data::convert(value::rgb8(), input);
draw::bounding_boxes(tmp, components, box_value);
draw::bounding_box_links(tmp, array, link_value, anchor);
draw::bounding_boxes(tmp, links.components(), box_value);
draw::bounding_box_links(tmp, links, link_value, anchor);
mln::io::ppm::save(tmp, filename);
......@@ -181,14 +176,13 @@ namespace scribo
inline
void
save_linked_bboxes_image(const Image<I>& input,
const component_set<L>& components,
const object_links<L>& array,
const object_links<L>& links,
const value::rgb8& box_value,
const value::rgb8& link_value,
const std::string& filename)
{
save_linked_bboxes_image(input, components, array, box_value,
link_value, filename, anchor::Center);
save_linked_bboxes_image(input, links, box_value,
link_value, anchor::Center, filename);
}
......@@ -197,26 +191,21 @@ namespace scribo
inline
void
save_linked_bboxes_image(const Image<I>& input,
const component_set<L>& components,
const object_links<L>& left_link,
const object_links<L>& right_link,
const value::rgb8& box_value,
const value::rgb8& value,
const std::string& filename)
{
trace::entering("scribo::debug::save_linked_bboxes_image");
mln_precondition(exact(input).is_valid());
mln_ch_value(I,value::rgb8) tmp = data::convert(value::rgb8(), input);
draw::bounding_boxes(tmp, components, box_value);
draw::bounding_box_links(tmp, components.mass_centers(),
left_link, right_link,
value);
mln::io::ppm::save(tmp, filename);
trace::exiting("scribo::debug::save_linked_bboxes_image");
save_linked_bboxes_image(input,
left_link,
right_link,
box_value,
literal::yellow,
literal::cyan,
value,
anchor::Center,
filename);
}
......@@ -224,13 +213,13 @@ namespace scribo
inline
void
save_linked_bboxes_image(const Image<I>& input,
const component_set<L>& components,
const object_links<L>& left_link,
const object_links<L>& right_link,
const value::rgb8& box_value,
const value::rgb8& left_link_value,
const value::rgb8& right_link_value,
const value::rgb8& validated_link_value,
anchor::Type anchor,
const std::string& filename)
{
trace::entering("scribo::debug::save_linked_bboxes_image");
......@@ -238,16 +227,12 @@ namespace scribo
mln_ch_value(I,value::rgb8) tmp = data::convert(value::rgb8(), input);
mln::util::array<mln_result(accu::center<mln_psite(L)>)>
mass_center = labeling::compute(accu::meta::center(),
components.labeled_image(),
components.nelements());
draw::bounding_boxes(tmp, components, box_value);
draw::bounding_box_links(tmp, mass_center,
draw::bounding_boxes(tmp, left_link.components(), box_value);
draw::bounding_box_links(tmp,
left_link, right_link,
left_link_value, right_link_value,
validated_link_value);
validated_link_value,
anchor);
mln::io::ppm::save(tmp, filename);
......@@ -260,10 +245,10 @@ namespace scribo
inline
void
save_linked_bboxes_image(const Image<I>& input,
const component_set<L>& components,
const Graph<G>& g,
const value::rgb8& box_value,
const value::rgb8& link_value,
anchor::Type anchor,
const std::string& filename)
{
trace::entering("scribo::debug::save_linked_bboxes_image");
......@@ -272,8 +257,9 @@ namespace scribo
mln_ch_value(I,value::rgb8) tmp = data::convert(value::rgb8(), input);
draw::bounding_boxes(tmp, components, box_value);
draw::bounding_box_links(tmp, components, g, link_value);
draw::bounding_boxes(tmp, exact(g).components(), box_value);
draw::bounding_box_links(tmp, exact(g).components(), g, link_value,
anchor);
mln::io::ppm::save(tmp, filename);
......
......@@ -100,8 +100,7 @@ namespace scribo
mln_precondition(objects.is_valid());
mln_precondition(links.is_valid());
mln_precondition(filtered_links.is_valid());
mln_precondition(links.size() == filtered_links.size());
mln_precondition(links.object_image_() != filtered_links.object_image_());
/// Fixme: check that objects has been computed from input.
image2d<value::rgb8>
......
......@@ -45,8 +45,9 @@
# include <mln/math/max.hh>
# include <scribo/core/component_set.hh>
# include <mln/literal/black.hh>
# include <scribo/core/component_set.hh>
namespace scribo
{
......
// 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.
//
......@@ -77,32 +78,9 @@ namespace scribo
/// Draw left, right and validated lists of bounding box links.
/// Draw from the bounding box centers.
/// Draw from anchors.
///
/// \param[in,out] input_ An image where to draw.
/// \param[in] bboxes Bounding boxes.
/// \param[in] left_link Bounding box left links.
/// \param[in] right_link Bounding box right links.
/// \param[in] left_link_value Value used to draw left links.
/// \param[in] right_link_value Value used to draw right links.
/// \param[in] validated_link_value Value used to draw validated links.
template <typename I, typename L>
inline
void
bounding_box_links(Image<I>& input_,
const mln::util::array< box<mln_site(I)> >& bboxes,
const object_links<L>& left_link,
const object_links<L>& right_link,
const mln_value(I)& left_link_value,
const mln_value(I)& right_link_value,
const mln_value(I)& validated_link_value);
/// Draw left, right and validated lists of bounding box links.
/// Draw from the bounding box mass centers.
///
/// \param[in,out] input_ An image where to draw.
/// \param[in] mass_centers Bounding box mass centers.
/// \param[in] left_link Bounding box left links.
/// \param[in] right_link Bounding box right links.
/// \param[in] left_link_value Value used to draw left links.
......@@ -112,12 +90,12 @@ namespace scribo
inline
void
bounding_box_links(Image<I>& input_,
const mln::util::array<mln_site(I)::vec>& mass_centers,
const object_links<L>& left_link,
const object_links<L>& right_link,
const mln_value(I)& left_link_value,
const mln_value(I)& right_link_value,
const mln_value(I)& validated_link_value);
const mln_value(I)& validated_link_value,
anchor::Type anchor);
/// Draw a graph of bounding box links.
......@@ -131,7 +109,6 @@ namespace scribo
inline
void
bounding_box_links(Image<I>& input_,
const mln::util::array< box<mln_site(I)> >& bboxes,
const Graph<G>& g_,
const mln_value(I)& link_value);
......@@ -155,28 +132,28 @@ namespace scribo
/// Draw a link graph in an image.
/// Functor to be passed to depth_first_search.
template <typename I>
template <typename I, typename G>
struct draw_graph_edges_functor
{
/// Constructor
///
/// \param[in,out] ima The image where to draw.
/// \param[in] textbboxes The line of text bounding boxes.
/// \param[in] value The value used to draw the links.
draw_graph_edges_functor(I& ima,
const mln::util::array<box<mln_site(I)> >& textbboxes,
const mln_value(I)& value)
: ima_(ima), textbboxes_(textbboxes), value_(value)
: ima_(ima), value_(value)
{}
/// Initialize the functor.
///
/// \param[in] g The graph this functor will work on.
template <typename G>
void
init(const Graph<G>& g)
{ deja_vu.resize(exact(g).v_nmax(), false); }
{
g_ = g;
deja_vu.resize(exact(g).v_nmax(), false);
}
/// All components/vertices have been treated.
void final()
......@@ -196,8 +173,8 @@ namespace scribo
void added_to_queue(unsigned id)
{
deja_vu[id] = true;
mln::draw::line(ima_, textbboxes_[current_vertex].center(),
textbboxes_[id].center(), value_);
mln::draw::line(ima_, g_.components()(current_vertex).bbox().pcenter(),
g_.components()(id).bbox().pcenter(), value_);
}
/// Treating a new vertex.
......@@ -215,9 +192,6 @@ namespace scribo
/// The image where to draw.
I& ima_;
/// Line of text bounding boxes.
const mln::util::array<box<mln_site(I)> >& textbboxes_;
/// Value to be used to draw links.
mln_value(I) value_;
......@@ -226,6 +200,8 @@ namespace scribo
/// Store whether a vertex has been already seen or not.
std::vector<bool> deja_vu;
G g_;
};
} // end of namespace scribo::draw::internal
......@@ -245,13 +221,13 @@ namespace scribo
mln_precondition(input.is_valid());
const component_set<L>& comp_set = links.components();
const component_set<L>& comps = links.components();
for_all_links(i, links)
if (links(i) != i && links(i) != 0)
{
mln_site(L)
p1 = primitive::link::internal::compute_anchor(comp_set, i, anchor),
p2 = primitive::link::internal::compute_anchor(comp_set, links(i), anchor);
p1 = primitive::link::internal::compute_anchor(comps, i, anchor),
p2 = primitive::link::internal::compute_anchor(comps, links(i), anchor);
mln::draw::line(input, p1, p2, value);
}
......@@ -275,12 +251,12 @@ namespace scribo
inline
void
bounding_box_links(Image<I>& input_,
const mln::util::array<mln_site(I)::vec>& mass_centers,
const object_links<L>& left_link,
const object_links<L>& right_link,
const mln_value(I)& left_link_value,
const mln_value(I)& right_link_value,
const mln_value(I)& validated_link_value)
const mln_value(I)& validated_link_value,
anchor::Type anchor)
{
trace::entering("scribo::draw::bounding_box_links");
......@@ -289,6 +265,8 @@ namespace scribo
typedef mln_site(I) P;
const component_set<L>& comps = left_link.components();
mln_dpsite(P) dleft = literal::zero;
dleft[0] = 2;
mln_dpsite(P) dright = literal::zero;
......@@ -296,19 +274,26 @@ namespace scribo
for_all_links(i, left_link)
{
mln::draw::line(input,
internal::shift_site(input, mass_centers[i], dleft),
internal::shift_site(input,
mass_centers[left_link(i)],
primitive::link::internal::compute_anchor(comps, i, anchor),
dleft),
internal::shift_site(input,
primitive::link::internal::compute_anchor(comps, left_link(i), anchor),
dleft),
left_link_value);
mln::draw::line(input,
internal::shift_site(input, mass_centers[i], dright),
internal::shift_site(input,
mass_centers[right_link(i)],
dright),
primitive::link::internal::compute_anchor(comps, i, anchor),
dleft),
internal::shift_site(input,
primitive::link::internal::compute_anchor(comps, right_link(i), anchor),
dleft),
right_link_value);
mln::util::couple<bool, unsigned>
nbh = primitive::internal::is_link_valid(left_link,
right_link,
......@@ -316,78 +301,29 @@ namespace scribo
if (nbh.first())
mln::draw::line(input,
mass_centers[i],
mass_centers[nbh.second()],
primitive::link::internal::compute_anchor(comps, right_link(i), anchor),
primitive::link::internal::compute_anchor(comps, nbh.second(), anchor),
validated_link_value);
input(mass_centers[i]) = validated_link_value;
}
trace::exiting("scribo::draw::bounding_box_links");
}
template <typename I, typename L>
inline
void
bounding_box_links(Image<I>& input_,
const mln::util::array< box<mln_site(I)> >& bboxes,
const object_links<L>& left_link,
const object_links<L>& right_link,
const mln_value(I)& left_link_v