last-svn-commit-925-g93197d7 Fix small fixes [to cleanup]

--- scribo/demo/viewer/viewer.cc | 10 ++-- scribo/demo/viewer/xml_widget.cc | 2 +- scribo/scribo/core/component_features_data.hh | 1 + scribo/scribo/core/group_info.hh | 11 ++++ .../scribo/io/xml/internal/compute_text_colour.hh | 1 + .../io/xml/internal/extended_page_xml_visitor.hh | 49 +++++++++++++------- scribo/scribo/io/xml/internal/time_info.hh | 1 + scribo/scribo/io/xml/save.hh | 2 +- .../toolchain/internal/content_in_doc_functor.hh | 12 ++--- .../internal/text_in_doc_preprocess_functor.hh | 2 + scribo/scribo/util/color_to_hex.hh | 1 + scribo/scribo/util/component_precise_outline.hh | 5 ++ 12 files changed, 65 insertions(+), 32 deletions(-) diff --git a/scribo/demo/viewer/viewer.cc b/scribo/demo/viewer/viewer.cc index 173cb3b..12270e1 100644 --- a/scribo/demo/viewer/viewer.cc +++ b/scribo/demo/viewer/viewer.cc @@ -368,7 +368,7 @@ Viewer::add_text(QDomNode line) QDomNode coords = line.firstChild(); - while (!coords.isNull() && !coords.toElement().tagName().contains("coords")) + while (!coords.isNull() && !coords.toElement().tagName().contains("Coords")) coords = coords.nextSibling(); if (coords.isNull()) @@ -416,7 +416,7 @@ Viewer::add_region(QDomNode father, QString attr_id) QString name = father.toElement().tagName(); region::RegionId id = static_cast<region::RegionId>(region_ids_[name]); - while (!coords.isNull() && !coords.toElement().tagName().contains("coords")) + while (!coords.isNull() && !coords.toElement().tagName().contains("Coords")) coords = coords.nextSibling(); if (coords.isNull()) @@ -471,7 +471,7 @@ Viewer::add_typo_lines(QDomNode father, QString attr_id) // Looking for bbox coordinates. { QDomNode coords = father.firstChild(); - while (!coords.isNull() && !coords.toElement().tagName().contains("coords")) + while (!coords.isNull() && !coords.toElement().tagName().contains("Coords")) coords = coords.nextSibling(); if (coords.isNull()) @@ -581,7 +581,7 @@ Viewer::load_xml(QString filename) QDomElement root = doc.documentElement(); QDomNode page = root.firstChild(); - while (!page.isNull() && !page.toElement().tagName().contains("page")) + while (!page.isNull() && !page.toElement().tagName().contains("Page")) page = page.nextSibling(); if (page.isNull()) @@ -611,7 +611,7 @@ Viewer::load_xml(QString filename) QDomNode coords = region.firstChild(); - while (!coords.isNull() && !coords.toElement().tagName().contains("coords")) + while (!coords.isNull() && !coords.toElement().tagName().contains("Coords")) coords = coords.nextSibling(); if (!container.isNull() && !coords.isNull()) diff --git a/scribo/demo/viewer/xml_widget.cc b/scribo/demo/viewer/xml_widget.cc index 57d171f..642cf9a 100644 --- a/scribo/demo/viewer/xml_widget.cc +++ b/scribo/demo/viewer/xml_widget.cc @@ -86,7 +86,7 @@ void XmlWidget::NFS(QDomNode node, QTreeWidgetItem* item) if (!node.isNull()) { QString append; - if (node.toElement().tagName().contains("point")) + if (node.toElement().tagName().contains("Point")) { QString x = node.toElement().attribute("x", "0"); QString y = node.toElement().attribute("y", "0"); diff --git a/scribo/scribo/core/component_features_data.hh b/scribo/scribo/core/component_features_data.hh index b0a4e47..6064a0f 100644 --- a/scribo/scribo/core/component_features_data.hh +++ b/scribo/scribo/core/component_features_data.hh @@ -75,6 +75,7 @@ namespace scribo } + inline bool operator==(const component_features_data& lhs, const component_features_data& rhs) diff --git a/scribo/scribo/core/group_info.hh b/scribo/scribo/core/group_info.hh index 19a8ecc..05d5aae 100644 --- a/scribo/scribo/core/group_info.hh +++ b/scribo/scribo/core/group_info.hh @@ -80,11 +80,13 @@ namespace scribo # ifndef MLN_INCLUDE_ONLY + inline group_info::group_info() : valid_(false) { } + inline group_info::group_info(unsigned id, const mln::util::array<component_id_t>& comps, unsigned pixel_area, const box2d& bbox) : id_(id), comps_(comps), valid_(true), @@ -92,53 +94,62 @@ namespace scribo { } + inline group_info::group_info(unsigned id, unsigned pixel_area, const box2d& bbox, bool valid) : id_(id), valid_(valid), pixel_area_(pixel_area), bbox_(bbox) { } + inline const mln::util::array<component_id_t>& group_info::component_ids() const { return comps_; } + inline mln::util::array<component_id_t>& group_info::component_ids_() { return comps_; } + inline bool group_info::is_valid() const { return valid_; } + inline void group_info::invalidate() { valid_ = false; } + inline unsigned group_info::card() const { return comps_.nelements(); } + inline unsigned group_info::id() const { return id_; } + inline unsigned group_info::pixel_area() const { return pixel_area_; } + inline const box2d& group_info::bbox() const { diff --git a/scribo/scribo/io/xml/internal/compute_text_colour.hh b/scribo/scribo/io/xml/internal/compute_text_colour.hh index 86fe454..f592c08 100644 --- a/scribo/scribo/io/xml/internal/compute_text_colour.hh +++ b/scribo/scribo/io/xml/internal/compute_text_colour.hh @@ -62,6 +62,7 @@ namespace scribo # ifndef MLN_INCLUDE_ONLY + inline const char * compute_text_colour(const value::rgb8& v) { 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 d109827..da7a582 100644 --- a/scribo/scribo/io/xml/internal/extended_page_xml_visitor.hh +++ b/scribo/scribo/io/xml/internal/extended_page_xml_visitor.hh @@ -52,8 +52,12 @@ # include <scribo/io/xml/internal/print_page_preambule.hh> # include <scribo/io/xml/internal/compute_text_colour.hh> +# include <scribo/text/paragraphs_closing.hh> + +# include <scribo/util/component_precise_outline.hh> # include <scribo/util/color_to_hex.hh> + namespace scribo { @@ -67,31 +71,29 @@ namespace scribo { - class extended_page_xml_visitor : public doc_serializer<extended_page_xml_visitor> + template <typename L> + class extended_page_xml_visitor + : public doc_serializer<extended_page_xml_visitor<L> > { public: // Constructor extended_page_xml_visitor(std::ofstream& out); // Visit overloads - template <typename L> void visit(const document<L>& doc) const; - template <typename L> void visit(const component_set<L>& comp_set) const; - template <typename L> void visit(const component_info<L>& info) const; - template <typename L> void visit(const paragraph_set<L>& parset) const; - template <typename L> void visit(const line_info<L>& line) const; private: // Attributes std::ofstream& output; mutable image2d<scribo::def::lbl_type> elt_edge; + mutable L lbl_; }; @@ -99,8 +101,8 @@ namespace scribo # ifndef MLN_INCLUDE_ONLY - inline - extended_page_xml_visitor::extended_page_xml_visitor(std::ofstream& out) + template <typename L> + extended_page_xml_visitor<L>::extended_page_xml_visitor(std::ofstream& out) : output(out) { } @@ -111,7 +113,7 @@ namespace scribo // template <typename L> void - extended_page_xml_visitor::visit(const document<L>& doc) const + extended_page_xml_visitor<L>::visit(const document<L>& doc) const { // Preambule print_PAGE_preambule(output, doc, false); @@ -150,8 +152,9 @@ namespace scribo // template <typename L> void - extended_page_xml_visitor::visit(const component_set<L>& comp_set) const + extended_page_xml_visitor<L>::visit(const component_set<L>& comp_set) const { + lbl_ = comp_set.labeled_image(); for_all_comps(c, comp_set) if (comp_set(c).is_valid()) comp_set(c).accept(*this); @@ -162,8 +165,14 @@ namespace scribo // template <typename L> void - extended_page_xml_visitor::visit(const component_info<L>& info) const + extended_page_xml_visitor<L>::visit(const component_info<L>& info) const { + // Getting component outline + 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(), id); + switch (info.type()) { case component::WhitespaceSeparator: @@ -177,7 +186,7 @@ namespace scribo << " y_max=\"" << info.bbox().pmax().row() << "\"" << ">" << std::endl; - internal::print_box_coords(output, info.bbox(), " "); + internal::print_image_coords(output, par, " "); output << " </whitespace_separator_region>" << std::endl; break; @@ -195,7 +204,7 @@ namespace scribo << " y_max=\"" << info.bbox().pmax().row() << "\"" << ">" << std::endl; - internal::print_box_coords(output, info.bbox(), " "); + internal::print_image_coords(output, par, " "); output << " </vertical_separator_region>" << std::endl; break; @@ -213,7 +222,7 @@ namespace scribo << " y_max=\"" << info.bbox().pmax().row() << "\"" << ">" << std::endl; - internal::print_box_coords(output, info.bbox(), " "); + internal::print_image_coords(output, par, " "); output << " </horizontal_separator_region>" << std::endl; break; @@ -250,13 +259,19 @@ namespace scribo // template <typename L> void - extended_page_xml_visitor::visit(const paragraph_set<L>& parset) const + extended_page_xml_visitor<L>::visit(const paragraph_set<L>& parset) const { 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 @@ -286,7 +301,7 @@ namespace scribo output << "\">" << std::endl; - internal::print_box_coords(output, parset(p).bbox(), " "); + internal::print_image_coords(output, parset(p).bbox(), " "); // EXTENSIONS - Not officially supported for_all_paragraph_lines(lid, line_ids) @@ -303,7 +318,7 @@ namespace scribo template <typename L> void - extended_page_xml_visitor::visit(const line_info<L>& line) const + extended_page_xml_visitor<L>::visit(const line_info<L>& line) const { if (line.has_text()) { diff --git a/scribo/scribo/io/xml/internal/time_info.hh b/scribo/scribo/io/xml/internal/time_info.hh index 6adc49a..760e856 100644 --- a/scribo/scribo/io/xml/internal/time_info.hh +++ b/scribo/scribo/io/xml/internal/time_info.hh @@ -48,6 +48,7 @@ namespace scribo # ifndef MLN_INCLUDE_ONLY + inline std::string time_info() { time_t cur_time = time(NULL); diff --git a/scribo/scribo/io/xml/save.hh b/scribo/scribo/io/xml/save.hh index cc6905b..cc02c03 100644 --- a/scribo/scribo/io/xml/save.hh +++ b/scribo/scribo/io/xml/save.hh @@ -103,7 +103,7 @@ namespace scribo template <typename L> void save_page_extended(const document<L>& doc, std::ofstream& output) { - scribo::io::xml::internal::extended_page_xml_visitor f(output); + scribo::io::xml::internal::extended_page_xml_visitor<L> f(output); doc.accept(f); } diff --git a/scribo/scribo/toolchain/internal/content_in_doc_functor.hh b/scribo/scribo/toolchain/internal/content_in_doc_functor.hh index 52ee5b0..dde8196 100644 --- a/scribo/scribo/toolchain/internal/content_in_doc_functor.hh +++ b/scribo/scribo/toolchain/internal/content_in_doc_functor.hh @@ -256,14 +256,6 @@ namespace scribo if (enable_line_seps) components.add_separators(separators); - // Debug -# ifndef SCRIBO_NDEBUG - debug::logger().log_image(debug::AuxiliaryResults, - components.separators(), - "all_separators"); -# endif // ! SCRIBO_NDEBUG - - on_new_progress_label("Filtering components"); components = scribo::filter::components_small(components, 3); @@ -373,6 +365,10 @@ namespace scribo //===== DEBUG ===== # ifndef SCRIBO_NDEBUG + debug::logger().log_image(debug::AuxiliaryResults, + components.separators(), + "all_separators"); + if (debug::logger().is_enabled()) { if (enable_whitespace_seps) diff --git a/scribo/scribo/toolchain/internal/text_in_doc_preprocess_functor.hh b/scribo/scribo/toolchain/internal/text_in_doc_preprocess_functor.hh index 484e28e..d58b4b2 100644 --- a/scribo/scribo/toolchain/internal/text_in_doc_preprocess_functor.hh +++ b/scribo/scribo/toolchain/internal/text_in_doc_preprocess_functor.hh @@ -33,6 +33,8 @@ #include <mln/fun/v2v/rgb_to_luma.hh> #include <mln/subsampling/antialiased.hh> +#include <mln/util/timer.hh> + #include <scribo/binarization/sauvola.hh> #include <scribo/binarization/sauvola_ms.hh> diff --git a/scribo/scribo/util/color_to_hex.hh b/scribo/scribo/util/color_to_hex.hh index e0ee33f..63dc81e 100644 --- a/scribo/scribo/util/color_to_hex.hh +++ b/scribo/scribo/util/color_to_hex.hh @@ -48,6 +48,7 @@ namespace scribo # ifndef MLN_INCLUDE_ONLY + inline std::string color_to_hex(const value::rgb8& v) { std::string result = "#"; diff --git a/scribo/scribo/util/component_precise_outline.hh b/scribo/scribo/util/component_precise_outline.hh index 175160c..5c87fb4 100644 --- a/scribo/scribo/util/component_precise_outline.hh +++ b/scribo/scribo/util/component_precise_outline.hh @@ -122,6 +122,7 @@ namespace scribo } } + inline void left_up_after(int& direction, const unsigned i) @@ -155,6 +156,7 @@ namespace scribo } } + inline void right_up_after(int& direction, const unsigned i) @@ -186,6 +188,7 @@ namespace scribo } } + inline void right_down_after(int& direction, const unsigned i) @@ -219,6 +222,7 @@ namespace scribo } } + inline void left_down_after(int& direction, const unsigned i) @@ -274,6 +278,7 @@ namespace scribo cur_pt = tmp; } + inline void filter_points(const mln::p_array<point2d>& points, mln::p_array<point2d>& waypoints) -- 1.5.6.5
participants (1)
-
Guillaume Lazzara