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>
Add support for tags in paragraph_info.
......
......@@ -34,7 +34,7 @@
# include <mln/core/image/image2d.hh>
# include <mln/value/rgb8.hh>
# include <mln/draw/site_set.hh>
# include <mln/draw/polygon.hh>
# include <mln/subsampling/antialiased.hh>
# include <mln/morpho/elementary/gradient_external.hh>
......@@ -45,7 +45,7 @@
# include <scribo/util/component_precise_outline.hh>
# include <scribo/io/img/internal/draw_edges.hh>
# include <scribo/text/paragraphs_closing.hh>
namespace scribo
......@@ -85,9 +85,6 @@ namespace scribo
mln::image2d<value::rgb8>& output;
unsigned output_ratio;
// FIXME: we would like its type to be L.
mutable image2d<scribo::def::lbl_type> lbl_sub;
private: // Methods
box2d compute_bbox(const box2d& b) const;
};
......@@ -97,7 +94,7 @@ namespace scribo
# ifndef MLN_INCLUDE_ONLY
inline
inline
box2d
debug_img_visitor::compute_bbox(const box2d& b) const
{
......@@ -131,50 +128,11 @@ namespace scribo
// Page elements (Pictures, ...)
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())
if (doc.elements()(e).is_valid())
doc.elements()(e).accept(*this);
}
// line seraparators
if (doc.has_vline_seps())
for_all_comps(c, doc.vline_seps_comps())
......@@ -198,23 +156,28 @@ namespace scribo
scribo::def::lbl_type id = (scribo::def::lbl_type)info.id().to_equiv();
const L& lbl = info.holder().labeled_image();
p_array<point2d>
par = scribo::util::component_precise_outline(
extend((lbl | info.bbox()) | (pw::value(lbl) == pw::cst(id)), 0));
par = scribo::util::component_precise_outline(lbl | info.bbox(), id);
switch (info.type())
{
case component::HorizontalLineSeparator:
case component::VerticalLineSeparator:
{
mln::draw::site_set(output, par, literal::cyan, output_ratio);
mln::draw::polygon(output, par, literal::cyan, output_ratio);
}
break;
case component::DropCapital:
{
mln::draw::polygon(output, par, literal::violet, output_ratio);
}
break;
default:
case component::Image:
{
mln::draw::site_set(output, par, literal::orange, output_ratio);
mln::draw::polygon(output, par, literal::orange, output_ratio);
}
break;
}
......@@ -228,6 +191,9 @@ namespace scribo
{
const line_set<L>& lines = parset.lines();
// Prepare paragraph outlines.
L par_clo = text::paragraphs_closing(parset);
for_all_paragraphs(p, parset)
if (parset(p).is_valid())
{
......@@ -235,10 +201,11 @@ namespace scribo
for_all_paragraph_lines(lid, line_ids)
{
line_id_t l = line_ids(lid);
lines(l).accept(*this);
line_id_t l = line_ids(lid);
lines(l).accept(*this);
}
// Adjust bbox to output image size.
box2d b = compute_bbox(parset(p).bbox());
b.enlarge(1);
b.crop_wrt(output.domain());
......
......@@ -34,7 +34,7 @@
# include <mln/core/image/image2d.hh>
# include <mln/value/rgb8.hh>
# include <mln/draw/site_set.hh>
# include <mln/draw/polygon.hh>
# include <mln/draw/box.hh>
# include <scribo/core/internal/doc_serializer.hh>
......@@ -137,22 +137,27 @@ namespace scribo
scribo::def::lbl_type id = (scribo::def::lbl_type)info.id().to_equiv();
const L& lbl = info.holder().labeled_image();
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())
{
case component::HorizontalLineSeparator:
case component::VerticalLineSeparator:
{
mln::draw::site_set(output, par, literal::cyan);
mln::draw::polygon(output, par, literal::cyan);
}
break;
case component::DropCapital:
{
mln::draw::polygon(output, par, literal::violet);
}
break;
default:
case component::Image:
{
mln::draw::site_set(output, par, literal::orange);
mln::draw::polygon(output, par, literal::orange);
}
break;
}
......@@ -164,20 +169,18 @@ namespace scribo
void
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)
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)
{
line_id_t l = line_ids(lid);
lines(l).accept(*this);
}
mln::draw::box(output, parset(p).bbox(), literal::blue);
mln::draw::polygon(output, par, literal::blue);
}
}
......@@ -186,7 +189,15 @@ namespace scribo
void
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
......
......@@ -40,6 +40,7 @@
# include <scribo/io/xml/internal/print_box_coords.hh>
# include <scribo/io/xml/internal/print_page_preambule.hh>
# include <scribo/io/xml/internal/compute_text_colour.hh>
# include <scribo/text/paragraphs_closing.hh>
namespace scribo
......@@ -160,8 +161,7 @@ namespace scribo
scribo::def::lbl_type id = (scribo::def::lbl_type)info.id().to_equiv();
const L& lbl = info.holder().labeled_image();
p_array<point2d>
par = scribo::util::component_precise_outline(
extend((lbl | info.bbox()) | (pw::value(lbl) == pw::cst(id)), 0));
par = scribo::util::component_precise_outline(lbl | info.bbox(), id);
switch (info.type())
{
......@@ -189,6 +189,17 @@ namespace scribo
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:
case component::Image:
......@@ -216,9 +227,15 @@ namespace scribo
{
const line_set<L>& lines = parset.lines();
// Prepare paragraph outlines.
L par_clo = text::paragraphs_closing(parset);
for_all_paragraphs(p, parset)
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();
// FIXME: compute that information on the whole paragraph
......@@ -245,7 +262,7 @@ namespace scribo
// <Unicode></Unicode>
// </TextEquiv>
internal::print_box_coords(output, parset(p).bbox(), " ");
internal::print_image_coords(output, par, " ");
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