last-svn-commit-806-g1e9c3e5 Save image edge coordinates in XML output.

* scribo/io/xml/internal/extended_page_xml_visitor.hh: Here. * scribo/io/xml/internal/print_image_coords.hh: New. --- scribo/ChangeLog | 8 ++++ .../io/xml/internal/extended_page_xml_visitor.hh | 22 ++++++++- .../{print_box_coords.hh => print_image_coords.hh} | 45 ++++++++++---------- 3 files changed, 49 insertions(+), 26 deletions(-) copy scribo/scribo/io/xml/internal/{print_box_coords.hh => print_image_coords.hh} (66%) diff --git a/scribo/ChangeLog b/scribo/ChangeLog index 1644058..5b96508 100644 --- a/scribo/ChangeLog +++ b/scribo/ChangeLog @@ -1,5 +1,13 @@ 2011-03-14 Guillaume Lazzara <z@lrde.epita.fr> + Save image edge coordinates in XML output. + + * scribo/io/xml/internal/extended_page_xml_visitor.hh: Here. + + * scribo/io/xml/internal/print_image_coords.hh: New. + +2011-03-14 Guillaume Lazzara <z@lrde.epita.fr> + * scribo/filter/object_links_aligned.hh: New. 2011-03-14 Guillaume Lazzara <z@lrde.epita.fr> diff --git a/scribo/scribo/io/xml/internal/extended_page_xml_visitor.hh b/scribo/scribo/io/xml/internal/extended_page_xml_visitor.hh index e8c7689..44d8342 100644 --- a/scribo/scribo/io/xml/internal/extended_page_xml_visitor.hh +++ b/scribo/scribo/io/xml/internal/extended_page_xml_visitor.hh @@ -31,7 +31,13 @@ /// Extended XML PAGE format serializer Visitor. # include <fstream> -# include <scribo/core/internal/doc_xml_serializer.hh> + +# include <mln/morpho/elementary/gradient_external.hh> +# include <mln/pw/all.hh> +# include <mln/core/image/dmorph/image_if.hh> + +# include <scribo/core/def/lbl_type.hh> + # include <scribo/core/internal/doc_serializer.hh> # include <scribo/core/document.hh> # include <scribo/core/component_set.hh> @@ -42,6 +48,7 @@ # include <scribo/core/line_info.hh> # include <scribo/io/xml/internal/print_box_coords.hh> +# include <scribo/io/xml/internal/print_image_coords.hh> # include <scribo/io/xml/internal/print_page_preambule.hh> @@ -81,6 +88,7 @@ namespace scribo private: // Attributes std::ofstream& output; + mutable image2d<scribo::def::lbl_type> elt_edge; }; @@ -112,7 +120,12 @@ namespace scribo // Page elements (Pictures, ...) if (doc.has_elements()) + { + // Prepare element edges + elt_edge = morpho::elementary::gradient_external(doc.elements().labeled_image(), c4()); + doc.elements().accept(*this); + } // line seraparators if (doc.has_vline_seps()) @@ -184,7 +197,10 @@ namespace scribo << " img_emb_text=\"No\" " << " img_bgcolour=\"White\">" << std::endl; - internal::print_box_coords(output, info.bbox(), " "); + internal::print_image_coords(output, + ((elt_edge | info.bbox()) + | (pw::value(elt_edge) == pw::cst((scribo::def::lbl_type)info.id().to_equiv()))).domain(), + " "); output << " </image_region>" << std::endl; break; @@ -252,7 +268,7 @@ namespace scribo output << " <line text=\"" << line.html_text() << "\" "; } else - output << " <line " << std::endl; + output << " <line "; output << "id=\"" << line.id() << "\" txt_orientation=\"" << line.orientation() diff --git a/scribo/scribo/io/xml/internal/print_box_coords.hh b/scribo/scribo/io/xml/internal/print_image_coords.hh similarity index 66% copy from scribo/scribo/io/xml/internal/print_box_coords.hh copy to scribo/scribo/io/xml/internal/print_image_coords.hh index ad84709..ebfe402 100644 --- a/scribo/scribo/io/xml/internal/print_box_coords.hh +++ b/scribo/scribo/io/xml/internal/print_image_coords.hh @@ -23,15 +23,15 @@ // exception does not however invalidate any other reasons why the // executable file might be covered by the GNU General Public License. -#ifndef SCRIBO_IO_XML_INTERNAL_PRINT_BOX_COORDS_HH -# define SCRIBO_IO_XML_INTERNAL_PRINT_BOX_COORDS_HH +#ifndef SCRIBO_IO_XML_INTERNAL_PRINT_IMAGE_COORDS_HH +# define SCRIBO_IO_XML_INTERNAL_PRINT_IMAGE_COORDS_HH /// \file /// /// \brief Prints box2d coordinates to XML data. # include <fstream> -# include <mln/core/alias/box2d.hh> +# include <mln/core/concept/site_set.hh> namespace scribo { @@ -49,36 +49,35 @@ namespace scribo /*! \brief Prints box2d coordinates to XML data. */ + template <typename S> void - print_box_coords(std::ofstream& ostr, const box2d& b, - const char *space); + print_image_coords(std::ofstream& ostr, const mln::Site_Set<S>& b, + const char *space); # ifndef MLN_INCLUDE_ONLY - inline + template <typename S> void - print_box_coords(std::ofstream& ostr, const box2d& b, - const char *space) + print_image_coords(std::ofstream& ostr, const mln::Site_Set<S>& b_, + const char *space) { std::string sc = space; std::string sp = sc + " "; - ostr << sc << "<coords>" << std::endl - << sp << "<point x=\"" << b.pmin().col() - << "\" y=\"" << b.pmin().row() << "\"/>" - << std::endl - << sp << "<point x=\"" << b.pmax().col() - << "\" y=\"" << b.pmin().row() << "\"/>" - << std::endl - << sp << "<point x=\"" << b.pmax().col() - << "\" y=\"" << b.pmax().row() << "\"/>" - << std::endl - << sp << "<point x=\"" << b.pmin().col() - << "\" y=\"" << b.pmax().row() << "\"/>" - << std::endl - << sc << "</coords>" << std::endl; + const S& b = exact(b_); + mln_precondition(b.is_valid()); + + ostr << sc << "<coords>" << std::endl; + + mln_piter(S) p(b); + for_all(p) + ostr << sp << "<point x=\"" << p.col() + << "\" y=\"" << p.row() << "\"/>" + << std::endl; + + ostr << sc << "</coords>" << std::endl; } @@ -92,4 +91,4 @@ namespace scribo } // end of namespace scribo -#endif // ! SCRIBO_IO_XML_INTERNAL_PRINT_BOX_COORDS_HH +#endif // ! SCRIBO_IO_XML_INTERNAL_PRINT_IMAGE_COORDS_HH -- 1.5.6.5
participants (1)
-
Guillaume Lazzara