* demo/viewer/common.hh,
* demo/viewer/key_widget.cc,
* demo/viewer/step_widget.cc,
* demo/viewer/viewer.cc: Handle visualization.
* scribo/toolchain/internal/content_in_doc_functor.hh,
* scribo/core/document.hh: Store separator information.
* scribo/io/xml/save.hh: Save whitespace separator data.
---
scribo/ChangeLog | 14 ++++++
scribo/demo/viewer/common.hh | 22 +++++++++-
scribo/demo/viewer/key_widget.cc | 6 ++-
scribo/demo/viewer/step_widget.cc | 1 +
scribo/demo/viewer/viewer.cc | 20 ++++++++-
scribo/scribo/core/document.hh | 47 ++++++++++++++++++++
scribo/scribo/io/xml/save.hh | 18 ++++++++
.../toolchain/internal/content_in_doc_functor.hh | 5 ++-
8 files changed, 128 insertions(+), 5 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index f3f150f..ef97bf9 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,3 +1,17 @@
+2011-02-05 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ Add support for whitespace separators visualization.
+
+ * demo/viewer/common.hh,
+ * demo/viewer/key_widget.cc,
+ * demo/viewer/step_widget.cc,
+ * demo/viewer/viewer.cc: Handle visualization.
+
+ * scribo/toolchain/internal/content_in_doc_functor.hh,
+ * scribo/core/document.hh: Store separator information.
+
+ * scribo/io/xml/save.hh: Save whitespace separator data.
+
2011-02-18 Guillaume Lazzara <z(a)lrde.epita.fr>
* src/text_in_picture.cc: Initialize ImageMagick and fix usage
diff --git a/scribo/demo/viewer/common.hh b/scribo/demo/viewer/common.hh
index 46f20c1..3b11ba5 100644
--- a/scribo/demo/viewer/common.hh
+++ b/scribo/demo/viewer/common.hh
@@ -24,14 +24,30 @@ namespace region
enum RegionId
{
+ // Text regions
+ // -------------
+
Text = 0,
+
+ // Extension
Line,
EndOfTextRegion,
+ // Separators
+ // ----------
+
+ Separator,
+
+ // Extension
+ WhitespaceSeparator,
+
+ EndOfSepsRegion,
+
+ // Misc regions.
+ // -------------
Image,
Noise,
- Separator,
Table,
LineDrawing,
Graphic,
@@ -40,6 +56,10 @@ namespace region
EndOfMiscRegion,
+ // Typographical lines
+ // -------------------
+
+ // Extension
Baseline,
Meanline,
diff --git a/scribo/demo/viewer/key_widget.cc b/scribo/demo/viewer/key_widget.cc
index cc10308..3b07617 100644
--- a/scribo/demo/viewer/key_widget.cc
+++ b/scribo/demo/viewer/key_widget.cc
@@ -22,8 +22,9 @@ KeyWidget::KeyWidget(const region::KeyMap& key_map)
: items_(new QTreeWidget())
{
item_list_.append(new QTreeWidgetItem(QStringList("Text")));
- item_list_.append(new QTreeWidgetItem(QStringList("Regions")));
- item_list_.append(new QTreeWidgetItem(QStringList("Typographical Lines")));
+ item_list_.append(new QTreeWidgetItem(QStringList("Separators")));
+ item_list_.append(new QTreeWidgetItem(QStringList("Misc. Regions")));
+ item_list_.append(new QTreeWidgetItem(QStringList("Typographical lines")));
QLabel* title = new QLabel(tr("Key"));
title->setAlignment(Qt::AlignHCenter);
@@ -38,6 +39,7 @@ KeyWidget::KeyWidget(const region::KeyMap& key_map)
base_id_.append(0);
base_id_.append(region::EndOfTextRegion + 1);
+ base_id_.append(region::EndOfSepsRegion + 1);
base_id_.append(region::EndOfMiscRegion + 1);
base_id_.append(region::EndOfTypoRegion + 1);
diff --git a/scribo/demo/viewer/step_widget.cc b/scribo/demo/viewer/step_widget.cc
index 77e9bd3..19b5d0f 100644
--- a/scribo/demo/viewer/step_widget.cc
+++ b/scribo/demo/viewer/step_widget.cc
@@ -59,6 +59,7 @@ void StepWidget::activate(QListWidgetItem* item)
key = iter.key();
value = iter.value();
+ qDebug() << "Loading " << value;
emit load_xml(value);
}
else
diff --git a/scribo/demo/viewer/viewer.cc b/scribo/demo/viewer/viewer.cc
index 1d48b1a..f34b3e7 100644
--- a/scribo/demo/viewer/viewer.cc
+++ b/scribo/demo/viewer/viewer.cc
@@ -51,8 +51,11 @@ Viewer::Viewer(int &argc, char** argv)
pdialog_(win_)
{
// Key map
+ // --------
key_map_[region::Text] = qMakePair(tr("Text Region"), QColor(0, 200, 0));
+
+ // Extension
key_map_[region::Line] = qMakePair(tr("Text line"), QColor(255, 0, 0));
key_map_[region::Image] = qMakePair(tr("Image"), QColor(255, 120, 0));
@@ -65,13 +68,23 @@ Viewer::Viewer(int &argc, char** argv)
key_map_[region::Chart] = qMakePair(tr("Chart"), QColor(0, 204, 255));
key_map_[region::Maths] = qMakePair(tr("Maths"), QColor(170, 0, 255));
+ // Extension
+ key_map_[region::WhitespaceSeparator] = qMakePair(tr("Whitespace Separator"),
QColor(0, 0, 128));
+
+ // Extension
key_map_[region::Baseline] = qMakePair(tr("Baseline"), QColor(128, 0, 255));
key_map_[region::Meanline] = qMakePair(tr("Meanline"), QColor(128, 0, 255));
+
+
// Region ids
+ // ----------
region_ids_["text_region"] = region::Text;
+
+ // Extension
region_ids_["line"] = region::Line;
+
region_ids_["image_region"] = region::Image;
region_ids_["noise_region"] = region::Noise;
region_ids_["separator_region"] = region::Separator;
@@ -81,6 +94,11 @@ Viewer::Viewer(int &argc, char** argv)
region_ids_["chart_region"] = region::Chart;
region_ids_["maths_region"] = region::Maths;
+ // Extension
+ region_ids_["whitespace_separator_region"] = region::WhitespaceSeparator;
+
+
+
win_->resize(1152, 864);
win_->statusBar();
@@ -572,7 +590,7 @@ Viewer::load_xml(QString filename)
while (!region.isNull())
{
- if
(region.toElement().tagName().contains(QRegExp("(image|graphic|chart|separator|table|text)_region")))
+ if
(region.toElement().tagName().contains(QRegExp("(whitespace_separator|image|graphic|chart|separator|table|text)_region")))
{
QString attr_id = region.toElement().attribute("id", "none");
add_region(region, attr_id);
diff --git a/scribo/scribo/core/document.hh b/scribo/scribo/core/document.hh
index b547da4..f112410 100644
--- a/scribo/scribo/core/document.hh
+++ b/scribo/scribo/core/document.hh
@@ -32,6 +32,7 @@
/// \brief Describes document content.
# include <mln/core/image/image2d.hh>
+# include <mln/core/alias/neighb2d.hh>
# include <mln/value/rgb8.hh>
# include <mln/io/magick/load.hh>
@@ -39,6 +40,8 @@
# include <scribo/core/line_set.hh>
# include <scribo/core/paragraph_set.hh>
+# include <scribo/primitive/extract/components.hh>
+
namespace scribo
{
@@ -83,6 +86,11 @@ namespace scribo
const mln::image2d<value::rgb8>& image() const;
void set_image(const mln::image2d<value::rgb8>& image);
+ bool has_whitespace_seps() const;
+ const mln::image2d<bool>& whitespace_seps() const;
+ const component_set<L>& whitespace_seps_comps() const;
+ void set_whitespace_separators(const image2d<bool>& whitespace_seps);
+
private:
const char *filename_;
mln::image2d<mln::value::rgb8> image_;
@@ -90,6 +98,9 @@ namespace scribo
line_set<L> lines_;
paragraph_set<L> parset_;
component_set<L> elements_;
+
+ mln::image2d<bool> whitespace_seps_;
+ component_set<L> whitespace_seps_comps_;
};
@@ -247,6 +258,42 @@ namespace scribo
}
+ template <typename L>
+ bool
+ document<L>::has_whitespace_seps() const
+ {
+ return whitespace_seps_.is_valid();
+ }
+
+
+ template <typename L>
+ const mln::image2d<bool>&
+ document<L>::whitespace_seps() const
+ {
+ return whitespace_seps_;
+ }
+
+
+ template <typename L>
+ const component_set<L>&
+ document<L>::whitespace_seps_comps() const
+ {
+ return whitespace_seps_comps_;
+ }
+
+
+ template <typename L>
+ void
+ document<L>::set_whitespace_separators(const image2d<bool>&
whitespace_seps)
+ {
+ whitespace_seps_ = whitespace_seps;
+
+ mln_value(L) ncomps;
+ whitespace_seps_comps_ = primitive::extract::components(whitespace_seps,
+ mln::c8(), ncomps);
+ }
+
+
# endif // ! MLN_INCLUDE_ONLY
diff --git a/scribo/scribo/io/xml/save.hh b/scribo/scribo/io/xml/save.hh
index 41d4fef..7011e87 100644
--- a/scribo/scribo/io/xml/save.hh
+++ b/scribo/scribo/io/xml/save.hh
@@ -364,6 +364,24 @@ namespace scribo
}
+ // Whitespace seraparators
+ if (doc.has_whitespace_seps())
+ {
+ const component_set<L>&
+ whitespace_seps_comps = doc.whitespace_seps_comps();
+
+ for_all_comps(c, whitespace_seps_comps)
+ {
+ file << " <whitespace_separator_region id=\"wss"
+ << whitespace_seps_comps(c).id()
+ << "\">" << std::endl;
+
+ internal::print_box_coords(file, whitespace_seps_comps(c).bbox(), "
");
+
+ file << " </whitespace_separator_region>" <<
std::endl;
+ }
+ }
+
file << " </page>" << std::endl;
file << "</pcGts>" << std::endl;
diff --git a/scribo/scribo/toolchain/internal/content_in_doc_functor.hh
b/scribo/scribo/toolchain/internal/content_in_doc_functor.hh
index fb7cd7c..b8aa56d 100644
--- a/scribo/scribo/toolchain/internal/content_in_doc_functor.hh
+++ b/scribo/scribo/toolchain/internal/content_in_doc_functor.hh
@@ -237,7 +237,10 @@ namespace scribo
if (enable_line_seps)
components.add_separators(separators);
if (enable_whitespace_seps)
+ {
components.add_separators(whitespaces);
+ doc.set_whitespace_separators(whitespaces);
+ }
if (enable_debug)
mln::io::pbm::save(components.separators(),
@@ -251,7 +254,7 @@ namespace scribo
on_progress();
- /// Linking potential objects
+ /// Linking objects
on_new_progress_label("Linking objects...");
object_links<L> left_link
--
1.5.6.5