* scribo/core/component_info.hh,
* scribo/core/component_set.hh,
* scribo/core/line_info.hh,
* scribo/core/line_set.hh,
* scribo/core/object_groups.hh: Add more methods and constructors.
* scribo/core/macros.hh: Add a new macro.
* scribo/core/tag/line.hh: Add more enums.
---
scribo/ChangeLog | 46 ++-----
scribo/core/component_info.hh | 9 +
scribo/core/component_set.hh | 59 +++++++-
scribo/core/line_info.hh | 338 ++++++++++++++++++++++++++++++++++++-----
scribo/core/line_set.hh | 168 +++++++++------------
scribo/core/macros.hh | 3 +
scribo/core/object_groups.hh | 3 +-
scribo/core/tag/line.hh | 142 +++++++++++++++++-
8 files changed, 591 insertions(+), 177 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 26f6201..d65a3ef 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,42 +1,16 @@
-2010-02-09 Guillaume Lazzara <z(a)lrde.epita.fr>
+2010-02-19 Guillaume Lazzara <z(a)lrde.epita.fr>
- Move Scribo demo.
+ Improve core classes.
- * demo/Makefile.am,
- * demo/demo.pro,
- * demo/demo.qrc,
- * demo/icons/document-open.png,
- * demo/icons/edit-find.png,
- * demo/icons/format-indent-more.png,
- * demo/icons/go-next.png,
- * demo/icons/image-x-generic.png,
- * demo/icons/list-add.png,
- * demo/icons/ocr.png,
- * demo/icons/text-x-generic.png,
- * demo/icons/view-refresh.png,
- * demo/icons/x-office-spreadsheet.png,
- * demo/src/main.cc,
- * demo/src/mainwindow.cc,
- * demo/src/mainwindow.hh,
- * demo/ui/mainwindow.ui: Move...
-
- * demo/review/Makefile.am,
- * demo/review/icons/document-open.png,
- * demo/review/icons/edit-find.png,
- * demo/review/icons/format-indent-more.png,
- * demo/review/icons/go-next.png,
- * demo/review/icons/image-x-generic.png,
- * demo/review/icons/list-add.png,
- * demo/review/icons/ocr.png,
- * demo/review/icons/text-x-generic.png,
- * demo/review/icons/view-refresh.png,
- * demo/review/icons/x-office-spreadsheet.png,
- * demo/review/review.pro,
- * demo/review/review.qrc,
- * demo/review/src/main.cc,
- * demo/review/src/mainwindow.cc,
- * demo/review/src/mainwindow.hh,
- * demo/review/ui/mainwindow.ui: ... here.
+ * scribo/core/component_info.hh,
+ * scribo/core/component_set.hh,
+ * scribo/core/line_info.hh,
+ * scribo/core/line_set.hh,
+ * scribo/core/object_groups.hh: Add more methods and constructors.
+
+ * scribo/core/macros.hh: Add a new macro.
+
+ * scribo/core/tag/line.hh: Add more enums.
2010-02-19 Guillaume Lazzara <z(a)lrde.epita.fr>
diff --git a/scribo/core/component_info.hh b/scribo/core/component_info.hh
index 0751fa2..1e4aaf5 100644
--- a/scribo/core/component_info.hh
+++ b/scribo/core/component_info.hh
@@ -64,6 +64,8 @@ namespace scribo
line_id_t line_id() const;
+ bool is_valid() const;
+
private:
component_id_t id_;
mln::box2d bbox_;
@@ -79,6 +81,7 @@ namespace scribo
component_info::component_info()
+ : id_(0), tag_(component::Ignored)
{
}
@@ -141,6 +144,12 @@ namespace scribo
return line_id_;
}
+ bool
+ component_info::is_valid() const
+ {
+ return tag_ != component::Ignored;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
diff --git a/scribo/core/component_set.hh b/scribo/core/component_set.hh
index 050f0ce..2f9d10e 100644
--- a/scribo/core/component_set.hh
+++ b/scribo/core/component_set.hh
@@ -62,17 +62,26 @@ namespace scribo
typedef mln::accu::shape::bbox<mln_site(L)> bbox_accu_t;
typedef mln::accu::pair<bbox_accu_t, center_accu_t> pair_accu_t;
+ typedef std::pair<mln_box(L),
+ std::pair<mln_site(L), unsigned> > pair_data_t;
+
typedef mln_result(center_accu_t) center_t;
component_set_data();
component_set_data(const L& ima, const mln_value(L)& ncomps);
component_set_data(const L& ima, const mln_value(L)& ncomps,
const mln::util::array<pair_accu_t>& attribs);
+ component_set_data(const L& ima, const mln_value(L)& ncomps,
+ const mln::util::array<pair_data_t>& attribs);
component_set_data(const L& ima, const mln_value(L)& ncomps,
const mln::util::array<scribo::component_info>& infos);
+
void fill_infos(const mln::util::array<pair_accu_t>& attribs);
+ void fill_infos(const mln::util::array<pair_data_t>& attribs);
+
+
L ima_;
mln_value(L) ncomps_;
mln::util::array<scribo::component_info> infos_;
@@ -89,6 +98,9 @@ namespace scribo
typedef mln::accu::center<mln_site(L)> center_accu_t;
typedef mln::accu::pair<bbox_accu_t, center_accu_t> pair_accu_t;
+ typedef std::pair<mln_box(L),
+ std::pair<mln_site(L), unsigned> > pair_data_t;
+
typedef mln_result(center_accu_t) center_t;
public:
@@ -105,6 +117,9 @@ namespace scribo
/// attributes values (bounding box and mass center).
component_set(const L& ima, const mln_value(L)& ncomps,
const mln::util::array<pair_accu_t>& attribs);
+
+ component_set(const L& ima, const mln_value(L)& ncomps,
+ const mln::util::array<pair_data_t>& attribs);
/// @}
/// Return the component count.
@@ -206,6 +221,16 @@ namespace scribo
inline
component_set_data<L>::component_set_data(const L& ima,
const mln_value(L)& ncomps,
+ const mln::util::array<pair_data_t>& attribs)
+ : ima_(ima), ncomps_(ncomps)
+ {
+ fill_infos(attribs);
+ }
+
+ template <typename L>
+ inline
+ component_set_data<L>::component_set_data(const L& ima,
+ const mln_value(L)& ncomps,
const mln::util::array<scribo::component_info>& infos)
: ima_(ima), ncomps_(ncomps), infos_(infos)
{
@@ -230,6 +255,25 @@ namespace scribo
}
}
+ template <typename L>
+ inline
+ void
+ component_set_data<L>::fill_infos(const
mln::util::array<pair_data_t>& attribs)
+ {
+ typedef mln_site(L) P;
+
+ infos_.reserve(static_cast<unsigned>(ncomps_) + 1);
+
+ infos_.append(component_info()); // Component 0, i.e. the background.
+ for_all_components(i, attribs)
+ {
+ component_info info(i, attribs[i].first,
+ attribs[i].second.first, attribs[i].second.second);
+ infos_.append(info);
+ }
+ }
+
+
} // end of namespace mln::internal
@@ -260,6 +304,17 @@ namespace scribo
template <typename L>
inline
+
+ component_set<L>::component_set(const L& ima, const mln_value(L)&
ncomps,
+ const mln::util::array<pair_data_t>& attribs)
+ {
+ data_ = new internal::component_set_data<L>(ima, ncomps, attribs);
+ }
+
+
+ template <typename L>
+ inline
+
mln_value(L)
component_set<L>::nelements() const
{
@@ -364,8 +419,8 @@ namespace scribo
component_set<L>::init_(const component_set<L>& set)
{
data_ = new internal::component_set_data<L>();
- data_->ima_ = set.object_image_();
- data_->ncomps_ = set.ncomps();
+ data_->ima_ = set.labeled_image();
+ data_->ncomps_ = set.nelements();
data_->infos_ = set.infos_();
}
diff --git a/scribo/core/line_info.hh b/scribo/core/line_info.hh
index 22eeea6..42438b0 100644
--- a/scribo/core/line_info.hh
+++ b/scribo/core/line_info.hh
@@ -33,16 +33,23 @@
# include <mln/core/alias/box2d.hh>
# include <mln/core/alias/point2d.hh>
+# include <mln/accu/stat/median_h.hh>
+# include <mln/accu/shape/bbox.hh>
# include <mln/util/object_id.hh>
# include <scribo/core/tag/component.hh>
# include <scribo/core/tag/line.hh>
+// # include <scribo/filter/object_links_bottom_aligned.hh>
+// # include <scribo/filter/object_links_top_aligned.hh>
+
+
namespace scribo
{
typedef mln::util::object_id<scribo::LineId, unsigned> line_id_t;
+ template <typename L>
class line_info
{
typedef mln::util::object_id<scribo::ComponentId, unsigned> component_id_t;
@@ -57,6 +64,9 @@ namespace scribo
unsigned absolute_baseline,
unsigned char_space,
unsigned char_width);
+ line_info(const object_links<L>& links,
+ const line_id_t& id,
+ const mln::util::array<component_id_t>& comps);
line_id_t id() const;
@@ -79,10 +89,43 @@ namespace scribo
unsigned word_space() const;
- void merge(const line_info& line) const;
+ line::ReadingDirection reading_direction() const;
+ line::Type type() const;
+ bool reverse_video() const;
+
+ float orientation() const;
+ float reading_orientation() const;
+
+ bool indented() const;
+
bool is_valid() const;
+
+ /// Merge related routines.
+ /// @{
+
+ /// This merge only updates the component list and the bounding box.
+ ///
+ /// After this merge, the line is tagged with
+ /// line::Needs_Precise_Stats_Update.
+ //
+ void fast_merge(line_info<L>& other);
+
+ /// This merge updates the component list and recompute from
+ /// scratch statistics, bounding box and other line attributes.
+ ///
+ /// After this merge, the line is tagged with line::None.
+ //
+ void precise_merge(line_info<L>& other);
+
+ /// @}
+
+
+ /// Force a new computation of statistics.
+ void force_stats_update();
+
+
private:
line_id_t id_;
line::Tag tag_;
@@ -105,17 +148,39 @@ namespace scribo
// Words related stats.
unsigned word_space_;
+
+ // Reading direction
+ line::ReadingDirection reading_direction_;
+
+ // Line type
+ line::Type type_;
+
+ // Is this line in reverse video?
+ bool reverse_video_;
+
+ // Text orientation
+ float orientation_;
+
+ // Text reading orientation
+ float reading_orientation_;
+
+ bool indented_;
+
+ // Related object links information.
+ const object_links<L>* links_;
};
+ template <typename L>
std::ostream&
- operator<<(std::ostream& ostr, const line_info& info);
+ operator<<(std::ostream& ostr, const line_info<L>& info);
# ifndef MLN_INCLUDE_ONLY
- line_info::line_info()
+ template <typename L>
+ line_info<L>::line_info()
: id_(0)
{
@@ -144,141 +209,324 @@ namespace scribo
All the metrics are computed relatively to the Baseline.
- The baseline is computed relatively to the top left corner of the
- line bounding box.
+ The baseline is defined as an absolute row index.
*/
- line_info::line_info(const line_id_t& id,
- const mln::box2d& bbox,
- const mln::util::array<component_id_t>& comps,
- unsigned absolute_median,
- unsigned absolute_baseline,
- unsigned char_space,
- unsigned char_width)
- : id_(id), tag_(line::None), bbox_(bbox), components_(comps),
- char_space_(char_space), char_width_(char_width)
+
+ template <typename L>
+ line_info<L>::line_info(const object_links<L>& links,
+ const line_id_t& id,
+ const mln::util::array<component_id_t>& comps)
+ : id_(id), tag_(line::None), components_(comps), links_(&links)
{
- baseline_ = absolute_baseline - bbox.pmin().row();
- median_ = absolute_median - bbox.pmin().row();
- x_height_ = absolute_baseline - absolute_median + 1;
- d_height_ = bbox.pmax().row() - absolute_baseline;
- a_height_ = absolute_baseline - bbox.pmin().row() + 1;
+ force_stats_update();
+
+
+// typedef mln_site(L) P;
+// const component_set<L>& comp_set = links_->component_set_();
+// mln::accu::shape::bbox<P> bbox;
+// for_all_elements(i, components_)
+// {
+// unsigned c = components_(i);
+// const box2d& bb = comp_set(c).bbox();
+// // Bounding box.
+// bbox.take(bb);
+// }
+// bbox_ = bbox.to_result();
+
+
+
+
+ // FIXME: set valid information for these attributes.
+ word_space_ = 0;
+ reading_direction_ = line::LeftToRight;
+ type_ = line::Paragraph;
+ reverse_video_ = false;
+
+ orientation_ = 0.;
+ reading_orientation_ = 0.;
+
+ indented_ = false;
}
- line_info::line_id_t
- line_info::id() const
+ template <typename L>
+ typename line_info<L>::line_id_t
+ line_info<L>::id() const
{
return id_;
}
+ template <typename L>
line::Tag
- line_info::tag() const
+ line_info<L>::tag() const
{
return tag_;
}
+ template <typename L>
void
- line_info::update_tag(line::Tag tag)
+ line_info<L>::update_tag(line::Tag tag)
{
tag_ = tag;
}
+
+ template <typename L>
const mln::box2d&
- line_info::bbox() const
+ line_info<L>::bbox() const
{
return bbox_;
}
- const mln::util::array<line_info::component_id_t>&
- line_info::components() const
+ template <typename L>
+ const mln::util::array<typename line_info<L>::component_id_t>&
+ line_info<L>::components() const
{
return components_;
}
+ template <typename L>
unsigned
- line_info::card() const
+ line_info<L>::card() const
{
return components_.size();
}
+ template <typename L>
unsigned
- line_info::baseline() const
+ line_info<L>::baseline() const
{
return baseline_;
}
+ template <typename L>
unsigned
- line_info::median() const
+ line_info<L>::median() const
{
return median_;
}
+ template <typename L>
int
- line_info::x_height() const
+ line_info<L>::x_height() const
{
return x_height_;
}
+ template <typename L>
int
- line_info::d_height() const
+ line_info<L>::d_height() const
{
return d_height_;
}
+ template <typename L>
int
- line_info::a_height() const
+ line_info<L>::a_height() const
{
return a_height_;
}
+ template <typename L>
unsigned
- line_info::char_space() const
+ line_info<L>::char_space() const
{
return char_space_;
}
+ template <typename L>
unsigned
- line_info::char_width() const
+ line_info<L>::char_width() const
{
return char_width_;
}
+ template <typename L>
unsigned
- line_info::word_space() const
+ line_info<L>::word_space() const
{
return word_space_;
}
- void
- line_info::merge(const line_info& line) const
+ template <typename L>
+ line::ReadingDirection
+ line_info<L>::reading_direction() const
+ {
+ return reading_direction_;
+ }
+
+ template <typename L>
+ line::Type
+ line_info<L>::type() const
{
- (void) line;
- std::cout << "merge not implemented!" << std::endl;
- abort();
+ return type_;
}
+ template <typename L>
bool
- line_info::is_valid() const
+ line_info<L>::reverse_video() const
+ {
+ return reverse_video_;
+ }
+
+
+ template <typename L>
+ float
+ line_info<L>::orientation() const
+ {
+ return orientation_;
+ }
+
+
+ template <typename L>
+ float
+ line_info<L>::reading_orientation() const
+ {
+ return reading_orientation_;
+ }
+
+
+ template <typename L>
+ bool
+ line_info<L>::indented() const
+ {
+ return indented_;
+ }
+
+
+ template <typename L>
+ bool
+ line_info<L>::is_valid() const
{
return id_ != 0u;
}
+ template <typename L>
+ void
+ line_info<L>::fast_merge(line_info<L>& other)
+ {
+ tag_ = line::Needs_Precise_Stats_Update;
+ other.update_tag(line::Merged);
+
+ bbox_.merge(other.bbox());
+ components_.append(other.components());
+ }
+
+
+ template <typename L>
+ void
+ line_info<L>::precise_merge(line_info<L>& other)
+ {
+ fast_merge(other);
+ force_stats_update();
+ }
+
+ template <typename L>
+ void
+ line_info<L>::force_stats_update()
+ {
+ typedef mln_site(L) P;
+ const component_set<L>& comp_set = links_->component_set_();
+
+ // FIXME: int_u<12> may not be enought but we can't use unsigned
+ // or any other larger types since there is no median
+ // implementation for high quantification types...
+
+ // Init.
+ typedef mln::value::int_u<12> median_data_t;
+ typedef mln::accu::stat::median_h<median_data_t> median_t;
+ median_t
+ absolute_median,
+ absolute_baseline,
+ char_space,
+ char_width;
+
+ mln::accu::shape::bbox<P> bbox;
+
+ for_all_elements(i, components_)
+ {
+ unsigned c = components_(i);
+
+ const box2d& bb = comp_set(c).bbox();
+
+ // Space between characters.
+ int space = bb.pmin().col()
+ - comp_set((*links_)[c]).bbox().pmax().col();
+ // -- Ignore overlapped characters.
+ if (space > 0)
+ char_space.take(space);
+
+ // Character width
+ // -- Ignore too large components.
+ if (bb.width() <= 1000)
+ char_width.take(bb.width());
+
+ // Median (compute an absolute value, from the top left
+ // corner of the image).
+ absolute_median.take(bb.pmin().row());
+
+ // Baseline (compute an absolute value, from the top left
+ // corner of the image).
+ absolute_baseline.take(bb.pmax().row());
+
+ // Bounding box.
+ bbox.take(bb);
+ }
+
+ // Finalization
+ {
+ tag_ = line::None;
+ bbox_ = bbox.to_result();
+
+ // Char space
+ if (card() == 1)
+ char_space_ = 0;
+ else
+ char_space_ = char_space.to_result();
+
+ // Char width
+ if (card() == 2)
+ char_width_ = (comp_set(components_[0]).bbox().width()
+ + comp_set(components_[1]).bbox().width()) / 2;
+ else
+ char_width_ = char_width.to_result();
+
+
+ baseline_ = absolute_baseline.to_result();
+ median_ = absolute_baseline - absolute_median;
+ x_height_ = absolute_baseline - absolute_median + 1;
+ d_height_ = absolute_baseline - bbox.to_result().pmax().row();
+ a_height_ = absolute_baseline - bbox.to_result().pmin().row() + 1;
+
+ //FIXME
+ //
+ //word_space_ = ...;
+ //reading_direction_ = ...;
+ //type_ = ...;
+ //reverse_video_ = ...;
+ //orientation_ = ...;
+ //reading_orientation_ = ...;
+ //indented_ = ...;
+ }
+ }
+
+ template <typename L>
std::ostream&
- operator<<(std::ostream& ostr, const line_info& info)
+ operator<<(std::ostream& ostr, const line_info<L>& info)
{
return ostr << "line_info("
<< "id=" << info.id()
@@ -293,6 +541,12 @@ namespace scribo
<< ", char_space=" << info.char_space()
<< ", char_width=" << info.char_width()
<< ", word_space=" << info.word_space()
+ << ", reading_direction=" << info.reading_direction()
+ << ", type=" << info.type()
+ << ", reverse_video=" << info.reverse_video()
+ << ", orientation=" << info.orientation()
+ << ", reading_orientation=" << info.reading_orientation()
+ << ", indented=" << info.indented()
<< ")" << std::endl;
}
diff --git a/scribo/core/line_set.hh b/scribo/core/line_set.hh
index 655f03b..2d846f0 100644
--- a/scribo/core/line_set.hh
+++ b/scribo/core/line_set.hh
@@ -63,10 +63,10 @@ namespace scribo
struct line_set_data
{
line_set_data();
- line_set_data(const mln::util::array<scribo::line_info>& infos,
+ line_set_data(const mln::util::array<scribo::line_info<L> >&
infos,
const component_set<L>& comp_set);
- mln::util::array<scribo::line_info> infos_;
+ mln::util::array<scribo::line_info<L> > infos_;
component_set<L> comp_set_;
};
@@ -89,23 +89,23 @@ namespace scribo
/// @}
/// Compute line stats and fill the underlying information.
- util::array<line_stats_extra> compute_lines(const object_links<L>&
links,
- const object_groups<L>& groups);
+ void compute_lines(const object_links<L>& links,
+ const object_groups<L>& groups);
/// Return the line count.
mln_value(L) nelements() const;
/// Return line information for a given line id \p id.
- const line_info& info(const mln_value(L)& id) const;
+ const line_info<L>& info(const mln_value(L)& id) const;
/// Return line information for a given line id \p id.
- line_info& info(const mln_value(L)& id);
+ line_info<L>& info(const mln_value(L)& id);
/// Return line information for a given line id \p id.
- line_info& operator()(const line_id_t& id);
+ line_info<L>& operator()(const line_id_t& id);
/// Return line information for a given line id \p id.
- const line_info& operator()(const line_id_t& id) const;
+ const line_info<L>& operator()(const line_id_t& id) const;
/// Update tag of lines set to 'false' in \p f with \p tag.
template <typename F>
@@ -121,7 +121,7 @@ namespace scribo
/// @{
/// Return all the line infos.
- const mln::util::array<scribo::line_info>& infos_() const;
+ const mln::util::array<scribo::line_info<L> >& infos_() const;
/// @}
@@ -165,7 +165,7 @@ namespace scribo
template <typename L>
inline
- line_set_data<L>::line_set_data(const
mln::util::array<scribo::line_info>& infos,
+ line_set_data<L>::line_set_data(const
mln::util::array<scribo::line_info<L> >& infos,
const component_set<L>& comp_set)
: infos_(infos), comp_set_(comp_set)
{
@@ -194,7 +194,8 @@ namespace scribo
// FIXME: groups should have a reference to the links data and we
// should only required groups as argument.
template <typename L>
- util::array<line_stats_extra>
+// util::array<line_stats_extra>
+ void
line_set<L>::compute_lines(const object_links<L>& links,
const object_groups<L>& groups)
{
@@ -217,51 +218,51 @@ namespace scribo
// implementation for high quantification types...
// Init.
- typedef mln::value::int_u<12> median_data_t;
- typedef mln::accu::stat::median_h<median_data_t> median_t;
- util::array<median_t>
- absolute_median(static_cast<unsigned>(n_groups) + 1),
- absolute_baseline(static_cast<unsigned>(n_groups) + 1),
- char_space(static_cast<unsigned>(n_groups) + 1),
- char_width(static_cast<unsigned>(n_groups) + 1);
+// typedef mln::value::int_u<12> median_data_t;
+// typedef mln::accu::stat::median_h<median_data_t> median_t;
+// util::array<median_t>
+// absolute_median(static_cast<unsigned>(n_groups) + 1),
+// absolute_baseline(static_cast<unsigned>(n_groups) + 1),
+// char_space(static_cast<unsigned>(n_groups) + 1),
+// char_width(static_cast<unsigned>(n_groups) + 1);
- util::array<mln::accu::shape::bbox<P> >
- bbox(static_cast<unsigned>(n_groups) + 1);
+// util::array<mln::accu::shape::bbox<P> >
+// bbox(static_cast<unsigned>(n_groups) + 1);
util::array< util::array<component_id_t> >
comps(static_cast<unsigned>(n_groups) + 1);
// 1st pass - Compute data.
for (unsigned i = 1; i < packed_groups.size(); ++i)
- if (comp_set(i).tag() != component::Ignored)
+ if (comp_set(i).is_valid())
{
unsigned group_id = packed_groups(i);
if (group_id != 0) // Is this component part of a group?
{
- const box2d& bb = comp_set(i).bbox();
+// const box2d& bb = comp_set(i).bbox();
- // Space between characters.
- int space = bb.pmin().col()
- - comp_set(links[i]).bbox().pmax().col();
- // -- Ignore overlapped characters.
- if (space > 0)
- char_space(group_id).take(space);
+// // Space between characters.
+// int space = bb.pmin().col()
+// - comp_set(links[i]).bbox().pmax().col();
+// // -- Ignore overlapped characters.
+// if (space > 0)
+// char_space(group_id).take(space);
- // Character width
- // -- Ignore too large components.
- if (bb.width() <= 1000)
- char_width(group_id).take(bb.width());
+// // Character width
+// // -- Ignore too large components.
+// if (bb.width() <= 1000)
+// char_width(group_id).take(bb.width());
- // Median (compute an absolute value, from the top left
- // corner of the image).
- absolute_median(group_id).take(bb.pmin().row());
+// // Median (compute an absolute value, from the top left
+// // corner of the image).
+// absolute_median(group_id).take(bb.pmin().row());
- // Baseline (compute an absolute value, from the top left
- // corner of the image).
- absolute_baseline(group_id).take(bb.pmax().row());
+// // Baseline (compute an absolute value, from the top left
+// // corner of the image).
+// absolute_baseline(group_id).take(bb.pmax().row());
- // Bounding box.
- bbox(group_id).take(bb);
+// // Bounding box.
+// bbox(group_id).take(bb);
// Component id.
comps(group_id).append(i);
@@ -270,57 +271,33 @@ namespace scribo
// 2nd pass - Store data.
data_->infos_.reserve(groups.nelements());
- data_->infos_.append(line_info()); // line with id 0 is invalid.
+ data_->infos_.append(line_info<L>()); // line with id 0 is invalid.
- util::array<line_stats_extra> stats_extra;
- stats_extra.reserve(static_cast<unsigned>(n_groups) + 1);
- stats_extra.append(line_stats_extra());
+// util::array<line_stats_extra> stats_extra;
+// stats_extra.reserve(static_cast<unsigned>(n_groups) + 1);
+// stats_extra.append(line_stats_extra());
for (unsigned i = 1; i <= n_groups; ++i)
{
- // FIXME: should be removable when object_group will store the
- // relation 'group -> comp'
- // Special cases for lines with 1 or 2 components.
- // {
- int
- cspace,
- cwidth;
- if (comps(i).nelements() == 1)
- cspace = 0;
- else
- cspace = char_space(i).to_result();
- if (comps(i).nelements() == 2)
- cwidth = (comp_set(comps(i)[0]).bbox().width()
- + comp_set(comps(i)[1]).bbox().width()) / 2;
- else
- cwidth = char_width(i).to_result();
- // }
-
// Add line info.
- line_info info(i,
- bbox(i).to_result(),
- comps(i),
- absolute_median(i).to_result(),
- absolute_baseline(i).to_result(),
- cspace,
- cwidth);
+ line_info<L> info(links, i, comps(i));
data_->infos_.append(info);
// Prepare extra stats to be returned.
- line_stats_extra stats(absolute_median(i) * absolute_median(i).card(),
- absolute_median(i).card(),
- absolute_baseline(i) * absolute_baseline(i).card(),
- absolute_baseline(i).card(),
- char_space(i) * char_space(i).card(),
- char_space(i).card(),
- char_width(i) * char_width(i).card(),
- char_width(i).card());
- stats_extra.append(stats);
+// line_stats_extra stats(absolute_median(i) * absolute_median(i).card(),
+// absolute_median(i).card(),
+// absolute_baseline(i) * absolute_baseline(i).card(),
+// absolute_baseline(i).card(),
+// char_space(i) * char_space(i).card(),
+// char_space(i).card(),
+// char_width(i) * char_width(i).card(),
+// char_width(i).card());
+// stats_extra.append(stats);
}
- return stats_extra;
+// return stats_extra;
}
@@ -335,7 +312,7 @@ namespace scribo
template <typename L>
inline
- const line_info&
+ const line_info<L>&
line_set<L>::info(const mln_value(L)& id) const
{
return this->data_->infos_[id];
@@ -343,7 +320,7 @@ namespace scribo
template <typename L>
inline
- line_info&
+ line_info<L>&
line_set<L>::info(const mln_value(L)& id)
{
return this->data_->infos_[id];
@@ -351,7 +328,7 @@ namespace scribo
template <typename L>
inline
- const line_info&
+ const line_info<L>&
line_set<L>::operator()(const line_id_t& id) const
{
return this->data_->infos_[id];
@@ -359,7 +336,7 @@ namespace scribo
template <typename L>
inline
- line_info&
+ line_info<L>&
line_set<L>::operator()(const line_id_t& id)
{
return this->data_->infos_[id];
@@ -401,7 +378,7 @@ namespace scribo
template <typename L>
inline
- const mln::util::array<scribo::line_info>&
+ const mln::util::array<scribo::line_info<L> >&
line_set<L>::infos_() const
{
return data_->infos_;
@@ -431,17 +408,18 @@ namespace scribo
return tmp;
}
- template <typename L>
- scribo::line_set<L>
- line_set(const object_links<L>& links,
- const object_groups<L>& groups,
- util::array<line_stats_extra>& line_stats)
- {
- mln_precondition(exact(ima).is_valid());
- scribo::line_set<L> tmp;
- line_stats = tmp.compute_lines(links, groups);
- return tmp;
- }
+
+// template <typename L>
+// scribo::line_set<L>
+// line_set(const object_links<L>& links,
+// const object_groups<L>& groups,
+// util::array<line_stats_extra>& line_stats)
+// {
+// mln_precondition(exact(ima).is_valid());
+// scribo::line_set<L> tmp;
+// line_stats = tmp.compute_lines(links, groups);
+// return tmp;
+// }
} // end of namespace scribo::make
diff --git a/scribo/core/macros.hh b/scribo/core/macros.hh
index b7c5253..bf2afde 100644
--- a/scribo/core/macros.hh
+++ b/scribo/core/macros.hh
@@ -46,4 +46,7 @@
# define for_all_lines(E, S) \
for_all_comps(E, S)
+# define for_all_groups(E, S) \
+ for_all_comp_data(E, S)
+
#endif // ! SCRIBO_CORE_MACROS_HH
diff --git a/scribo/core/object_groups.hh b/scribo/core/object_groups.hh
index 74e7043..6f49bcf 100644
--- a/scribo/core/object_groups.hh
+++ b/scribo/core/object_groups.hh
@@ -55,7 +55,8 @@ namespace scribo
public:
object_groups();
object_groups(const component_set<L>& components);
- object_groups(const component_set<L>& components, unsigned value);
+ object_groups(const component_set<L>& components,
+ unsigned value);
const component_set<L>& component_set_() const;
diff --git a/scribo/core/tag/line.hh b/scribo/core/tag/line.hh
index 085a550..383e331 100644
--- a/scribo/core/tag/line.hh
+++ b/scribo/core/tag/line.hh
@@ -44,10 +44,150 @@ namespace scribo
{
None = 0,
Separator,
- Ignored
+ Ignored,
+ Needs_Precise_Stats_Update,
+ Merged,
+ Pathological
};
+
+ // The following next enumerations are based on the page content
+ // XML format.
+ //
+ // XSD:
+ //
http://schema.primaresearch.org/PAGE/gts/pagecontent/2009-03-16/pagecontent…
+
+ enum ReadingDirection
+ {
+ BottomToTop,
+ LeftToRight,
+ RightToLeft,
+ TopToBottom
+ };
+
+
+ enum Type
+ {
+ Caption,
+ Credit,
+ DropCapital,
+ Floating,
+ Footer,
+ Header,
+ Heading,
+ PageNumber,
+ Paragraph
+ };
+
+
+ std::ostream&
+ operator<<(std::ostream& ostr, const Tag& tag);
+
+ std::ostream&
+ operator<<(std::ostream& ostr, const ReadingDirection& direction);
+
+ std::ostream&
+ operator<<(std::ostream& ostr, const Type& type);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ std::ostream&
+ operator<<(std::ostream& ostr, const Tag& tag)
+ {
+ std::string str;
+ switch(tag)
+ {
+ default:
+ case None:
+ str = "None";
+ break;
+ case Separator:
+ str = "Separator";
+ break;
+ case Ignored:
+ str = "Ignored";
+ break;
+ case Needs_Precise_Stats_Update:
+ str = "Needs_Precise_Stats_Update";
+ break;
+ case Merged:
+ str = "Merged";
+ break;
+ case Pathological:
+ str = "Pathological";
+ break;
+ }
+
+ return ostr << str;
+ }
+
+
+
+ std::ostream&
+ operator<<(std::ostream& ostr, const ReadingDirection& direction)
+ {
+ std::string str;
+ switch(direction)
+ {
+ case BottomToTop:
+ str = "bottom-to-top";
+ break;
+ default:
+ case LeftToRight:
+ str = "left-to-right";
+ break;
+ case RightToLeft:
+ str = "right-to-left";
+ break;
+ case TopToBottom:
+ str = "top-to-bottom";
+ break;
+ }
+
+ return ostr << str;
+ }
+
+
+ std::ostream&
+ operator<<(std::ostream& ostr, const Type& type)
+ {
+ std::string str;
+ switch(type)
+ {
+ case Caption:
+ str = "caption";
+ break;
+ default:
+ case Credit:
+ str = "credit";
+ break;
+ case DropCapital:
+ str = "drop-capital";
+ break;
+ case Floating:
+ str = "floating";
+ case Footer:
+ str = "footer";
+ case Header:
+ str = "header";
+ case Heading:
+ str = "heading";
+ case PageNumber:
+ str = "page-number";
+ case Paragraph:
+ str = "paragraph";
+ break;
+ }
+
+ return ostr << str;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+
} // end of namespace scribo::line
} // end of namespace scribo
--
1.5.6.5