Commit 98f9fcbe authored by Guillaume Lazzara's avatar Guillaume Lazzara
Browse files

Save component outlines instead of bboxes.

	* scribo/io/img/internal/debug_img_visitor.hh,
	* scribo/io/img/internal/full_img_visitor.hh,
	* scribo/io/xml/internal/page_xml_visitor.hh: Here.
parent cd6039ae
2011-06-07 Guillaume Lazzara <z@lrde.epita.fr>
Save component outlines instead of bboxes.
* scribo/io/img/internal/debug_img_visitor.hh,
* scribo/io/img/internal/full_img_visitor.hh,
* scribo/io/xml/internal/page_xml_visitor.hh: Here.
2011-06-07 Guillaume Lazzara <z@lrde.epita.fr> 2011-06-07 Guillaume Lazzara <z@lrde.epita.fr>
Add support for tags in paragraph_info. Add support for tags in paragraph_info.
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
# include <mln/core/image/image2d.hh> # include <mln/core/image/image2d.hh>
# include <mln/value/rgb8.hh> # include <mln/value/rgb8.hh>
# include <mln/draw/site_set.hh> # include <mln/draw/polygon.hh>
# include <mln/subsampling/antialiased.hh> # include <mln/subsampling/antialiased.hh>
# include <mln/morpho/elementary/gradient_external.hh> # include <mln/morpho/elementary/gradient_external.hh>
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
# include <scribo/util/component_precise_outline.hh> # include <scribo/util/component_precise_outline.hh>
# include <scribo/io/img/internal/draw_edges.hh> # include <scribo/io/img/internal/draw_edges.hh>
# include <scribo/text/paragraphs_closing.hh>
namespace scribo namespace scribo
...@@ -85,9 +85,6 @@ namespace scribo ...@@ -85,9 +85,6 @@ namespace scribo
mln::image2d<value::rgb8>& output; mln::image2d<value::rgb8>& output;
unsigned output_ratio; unsigned output_ratio;
// FIXME: we would like its type to be L.
mutable image2d<scribo::def::lbl_type> lbl_sub;
private: // Methods private: // Methods
box2d compute_bbox(const box2d& b) const; box2d compute_bbox(const box2d& b) const;
}; };
...@@ -97,7 +94,7 @@ namespace scribo ...@@ -97,7 +94,7 @@ namespace scribo
# ifndef MLN_INCLUDE_ONLY # ifndef MLN_INCLUDE_ONLY
inline inline
box2d box2d
debug_img_visitor::compute_bbox(const box2d& b) const debug_img_visitor::compute_bbox(const box2d& b) const
{ {
...@@ -131,50 +128,11 @@ namespace scribo ...@@ -131,50 +128,11 @@ namespace scribo
// Page elements (Pictures, ...) // Page elements (Pictures, ...)
if (doc.has_elements()) if (doc.has_elements())
{ {
// Prepare element edges
// L lbl = duplicate(doc.elements().labeled_image());
// for_all_comps(c, doc.elements())
// if (! doc.elements()(c).is_valid())
// data::fill(((lbl | doc.elements()(c).bbox()).rw()
// | (pw::value(lbl) == pw::cst(c))).rw(), 0);
// const L& lbl = doc.lines().components().labeled_image();
// lbl_sub = mln::subsampling::antialiased(lbl, output_ratio);
// mln::io::pgm::save(data::wrap(value::int_u8(), lbl), "lbl.pgm");
// mln::io::pgm::save(data::wrap(value::int_u8(), lbl_sub), "lbl_sub.pgm");
// // FIXME: UGLY! Too slow!
// scribo::def::lbl_type nlabels;
// component_set<L> elts = primitive::extract::components(
// data::convert(bool(), lbl_sub),
// c8(),
// nlabels);
// Preserving elements tags
// if (doc.elements().nelements() != elts.nelements())
// {
// std::cerr << "Warnig: could not preserve element type in "
// << "img debug output." << std::endl;
// std::cerr << "The number of non text element has changed while "
// << "subsampling images : "
// << doc.elements().nelements() << " vs "
// << elts.nelements() << std::endl;
// }
// else
// for_all_comps(c, doc.elements())
// {
// elts(c).update_type(doc.elements()(c).type());
// elts(c).update_tag(doc.elements()(c).tag());
// }
for_all_comps(e, doc.elements()) for_all_comps(e, doc.elements())
if (doc.elements()(e).is_valid()) if (doc.elements()(e).is_valid())
doc.elements()(e).accept(*this); doc.elements()(e).accept(*this);
} }
// line seraparators // line seraparators
if (doc.has_vline_seps()) if (doc.has_vline_seps())
for_all_comps(c, doc.vline_seps_comps()) for_all_comps(c, doc.vline_seps_comps())
...@@ -198,23 +156,28 @@ namespace scribo ...@@ -198,23 +156,28 @@ namespace scribo
scribo::def::lbl_type id = (scribo::def::lbl_type)info.id().to_equiv(); scribo::def::lbl_type id = (scribo::def::lbl_type)info.id().to_equiv();
const L& lbl = info.holder().labeled_image(); const L& lbl = info.holder().labeled_image();
p_array<point2d> p_array<point2d>
par = scribo::util::component_precise_outline( par = scribo::util::component_precise_outline(lbl | info.bbox(), id);
extend((lbl | info.bbox()) | (pw::value(lbl) == pw::cst(id)), 0));
switch (info.type()) switch (info.type())
{ {
case component::HorizontalLineSeparator: case component::HorizontalLineSeparator:
case component::VerticalLineSeparator: case component::VerticalLineSeparator:
{ {
mln::draw::site_set(output, par, literal::cyan, output_ratio); mln::draw::polygon(output, par, literal::cyan, output_ratio);
} }
break; break;
case component::DropCapital:
{
mln::draw::polygon(output, par, literal::violet, output_ratio);
}
break;
default: default:
case component::Image: case component::Image:
{ {
mln::draw::site_set(output, par, literal::orange, output_ratio); mln::draw::polygon(output, par, literal::orange, output_ratio);
} }
break; break;
} }
...@@ -228,6 +191,9 @@ namespace scribo ...@@ -228,6 +191,9 @@ namespace scribo
{ {
const line_set<L>& lines = parset.lines(); const line_set<L>& lines = parset.lines();
// Prepare paragraph outlines.
L par_clo = text::paragraphs_closing(parset);
for_all_paragraphs(p, parset) for_all_paragraphs(p, parset)
if (parset(p).is_valid()) if (parset(p).is_valid())
{ {
...@@ -235,10 +201,11 @@ namespace scribo ...@@ -235,10 +201,11 @@ namespace scribo
for_all_paragraph_lines(lid, line_ids) for_all_paragraph_lines(lid, line_ids)
{ {
line_id_t l = line_ids(lid); line_id_t l = line_ids(lid);
lines(l).accept(*this); lines(l).accept(*this);
} }
// Adjust bbox to output image size.
box2d b = compute_bbox(parset(p).bbox()); box2d b = compute_bbox(parset(p).bbox());
b.enlarge(1); b.enlarge(1);
b.crop_wrt(output.domain()); b.crop_wrt(output.domain());
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
# include <mln/core/image/image2d.hh> # include <mln/core/image/image2d.hh>
# include <mln/value/rgb8.hh> # include <mln/value/rgb8.hh>
# include <mln/draw/site_set.hh> # include <mln/draw/polygon.hh>
# include <mln/draw/box.hh> # include <mln/draw/box.hh>
# include <scribo/core/internal/doc_serializer.hh> # include <scribo/core/internal/doc_serializer.hh>
...@@ -137,22 +137,27 @@ namespace scribo ...@@ -137,22 +137,27 @@ namespace scribo
scribo::def::lbl_type id = (scribo::def::lbl_type)info.id().to_equiv(); scribo::def::lbl_type id = (scribo::def::lbl_type)info.id().to_equiv();
const L& lbl = info.holder().labeled_image(); const L& lbl = info.holder().labeled_image();
p_array<point2d> p_array<point2d>
par = scribo::util::component_precise_outline((lbl | info.bbox()) | (pw::value(lbl) == pw::cst(id))); par = scribo::util::component_precise_outline(lbl | info.bbox(), id);
switch (info.type()) switch (info.type())
{ {
case component::HorizontalLineSeparator: case component::HorizontalLineSeparator:
case component::VerticalLineSeparator: case component::VerticalLineSeparator:
{ {
mln::draw::site_set(output, par, literal::cyan); mln::draw::polygon(output, par, literal::cyan);
} }
break; break;
case component::DropCapital:
{
mln::draw::polygon(output, par, literal::violet);
}
break;
default: default:
case component::Image: case component::Image:
{ {
mln::draw::site_set(output, par, literal::orange); mln::draw::polygon(output, par, literal::orange);
} }
break; break;
} }
...@@ -164,20 +169,18 @@ namespace scribo ...@@ -164,20 +169,18 @@ namespace scribo
void void
full_img_visitor::visit(const paragraph_set<L>& parset) const full_img_visitor::visit(const paragraph_set<L>& parset) const
{ {
const line_set<L>& lines = parset.lines(); // const line_set<L>& lines = parset.lines();
// Prepare paragraph outlines.
L par_clo = text::paragraphs_closing(parset);
for_all_paragraphs(p, parset) for_all_paragraphs(p, parset)
if (parset(p).is_valid()) if (parset(p).is_valid())
{ {
const mln::util::array<line_id_t>& line_ids = parset(p).line_ids(); p_array<point2d> par = scribo::util::component_precise_outline(par_clo
| parset(p).bbox(), p);
for_all_paragraph_lines(lid, line_ids) mln::draw::polygon(output, par, literal::blue);
{
line_id_t l = line_ids(lid);
lines(l).accept(*this);
}
mln::draw::box(output, parset(p).bbox(), literal::blue);
} }
} }
...@@ -186,7 +189,15 @@ namespace scribo ...@@ -186,7 +189,15 @@ namespace scribo
void void
full_img_visitor::visit(const line_info<L>& line) const full_img_visitor::visit(const line_info<L>& line) const
{ {
mln::draw::box(output, line.bbox(), literal::red); // mln::draw::box(output, line.bbox(), literal::red);
point2d
pmin = line.bbox().pmin(),
pmax = line.bbox().pmax();
pmax.row() = line.baseline();
pmin.row() = line.baseline();
mln::draw::line(output, pmin, pmax, literal::red);
} }
#endif // MLN_INCLUDE_ONLY #endif // MLN_INCLUDE_ONLY
......
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
# include <scribo/io/xml/internal/print_box_coords.hh> # include <scribo/io/xml/internal/print_box_coords.hh>
# include <scribo/io/xml/internal/print_page_preambule.hh> # include <scribo/io/xml/internal/print_page_preambule.hh>
# include <scribo/io/xml/internal/compute_text_colour.hh> # include <scribo/io/xml/internal/compute_text_colour.hh>
# include <scribo/text/paragraphs_closing.hh>
namespace scribo namespace scribo
...@@ -160,8 +161,7 @@ namespace scribo ...@@ -160,8 +161,7 @@ namespace scribo
scribo::def::lbl_type id = (scribo::def::lbl_type)info.id().to_equiv(); scribo::def::lbl_type id = (scribo::def::lbl_type)info.id().to_equiv();
const L& lbl = info.holder().labeled_image(); const L& lbl = info.holder().labeled_image();
p_array<point2d> p_array<point2d>
par = scribo::util::component_precise_outline( par = scribo::util::component_precise_outline(lbl | info.bbox(), id);
extend((lbl | info.bbox()) | (pw::value(lbl) == pw::cst(id)), 0));
switch (info.type()) switch (info.type())
{ {
...@@ -189,6 +189,17 @@ namespace scribo ...@@ -189,6 +189,17 @@ namespace scribo
break; break;
} }
case component::DropCapital:
{
output << " <TextRegion id=\"r" << id << "\" "
<< " Type=\"Drop_Capital\">"
<< std::endl;
internal::print_image_coords(output, par, " ");
output << " </TextRegion>" << std::endl;
break;
}
default: default:
case component::Image: case component::Image:
...@@ -216,9 +227,15 @@ namespace scribo ...@@ -216,9 +227,15 @@ namespace scribo
{ {
const line_set<L>& lines = parset.lines(); const line_set<L>& lines = parset.lines();
// Prepare paragraph outlines.
L par_clo = text::paragraphs_closing(parset);
for_all_paragraphs(p, parset) for_all_paragraphs(p, parset)
if (parset(p).is_valid()) if (parset(p).is_valid())
{ {
p_array<mln_site(L)> par = scribo::util::component_precise_outline(par_clo
| parset(p).bbox(), p);
const mln::util::array<line_id_t>& line_ids = parset(p).line_ids(); const mln::util::array<line_id_t>& line_ids = parset(p).line_ids();
// FIXME: compute that information on the whole paragraph // FIXME: compute that information on the whole paragraph
...@@ -245,7 +262,7 @@ namespace scribo ...@@ -245,7 +262,7 @@ namespace scribo
// <Unicode></Unicode> // <Unicode></Unicode>
// </TextEquiv> // </TextEquiv>
internal::print_box_coords(output, parset(p).bbox(), " "); internal::print_image_coords(output, par, " ");
output << " </TextRegion>" << std::endl; output << " </TextRegion>" << std::endl;
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment