Commit 129baa2a authored by Guillaume Lazzara's avatar Guillaume Lazzara
Browse files

Add holder information to component_info.

	* scribo/core/component_info.hh,
	* scribo/core/component_set.hh,
	* scribo/core/internal/doc_serializer.hh,
	* scribo/io/img/internal/debug_img_visitor.hh,
	* scribo/io/img/internal/draw_edges.hh,
	* scribo/io/img/internal/full_img_visitor.hh,
	* scribo/io/img/internal/non_text_img_visitor.hh,
	* scribo/io/xml/internal/extended_page_xml_visitor.hh,
	* scribo/io/xml/internal/full_xml_visitor.hh,
	* scribo/io/xml/internal/page_xml_visitor.hh,
	* scribo/util/component_outline.hh: Add a template parameter to
	component_info structure and update its use.
parent 316f5150
2011-05-16 Guillaume Lazzara <lazzara@fidji.lrde.epita.fr>
Add holder information to component_info.
* scribo/core/component_info.hh,
* scribo/core/component_set.hh,
* scribo/core/internal/doc_serializer.hh,
* scribo/io/img/internal/debug_img_visitor.hh,
* scribo/io/img/internal/draw_edges.hh,
* scribo/io/img/internal/full_img_visitor.hh,
* scribo/io/img/internal/non_text_img_visitor.hh,
* scribo/io/xml/internal/extended_page_xml_visitor.hh,
* scribo/io/xml/internal/full_xml_visitor.hh,
* scribo/io/xml/internal/page_xml_visitor.hh,
* scribo/util/component_outline.hh: Add a template parameter to
component_info structure and update its use.
2011-05-16 Guillaume Lazzara <lazzara@fidji.lrde.epita.fr>
New specific toolchain for historical documents.
......
......@@ -44,15 +44,21 @@
namespace scribo
{
// Forward declarations.
template <typename L> class component_set;
typedef mln::util::object_id<scribo::ComponentId, unsigned> component_id_t;
class component_info : public Serializable<component_info>
template <typename L>
class component_info : public Serializable<component_info<L> >
{
typedef mln::util::object_id<scribo::ComponentId, unsigned> component_id_t;
public:
component_info();
component_info(const component_id_t& id,
component_info(const component_set<L>& holder,
const component_id_t& id,
const mln::box2d& bbox,
const mln::point2d& mass_center,
unsigned card,
......@@ -80,6 +86,8 @@ namespace scribo
bool is_valid() const;
const component_set<L>& holder() const;
protected:
component_id_t id_;
mln::box2d bbox_;
......@@ -90,36 +98,41 @@ namespace scribo
component::Tag tag_;
component::Type type_;
component_set<L> holder_;
};
template <typename L>
std::ostream&
operator<<(std::ostream& ostr, const component_info& info);
operator<<(std::ostream& ostr, const component_info<L>& info);
template <typename L>
bool
operator==(const component_info& lhs, const component_info& rhs);
operator==(const component_info<L>& lhs, const component_info<L>& rhs);
# ifndef MLN_INCLUDE_ONLY
inline
component_info::component_info()
template <typename L>
component_info<L>::component_info()
: id_(0), tag_(component::Ignored), type_(component::Undefined)
{
}
inline
component_info::component_info(const component_id_t& id,
const mln::box2d& bbox,
const mln::point2d& mass_center,
unsigned card,
component::Type type)
template <typename L>
component_info<L>::component_info(const component_set<L>& holder,
const component_id_t& id,
const mln::box2d& bbox,
const mln::point2d& mass_center,
unsigned card,
component::Type type)
: id_(id), bbox_(bbox), mass_center_(mass_center), card_(card),
type_(type)
type_(type), holder_(holder)
{
if (!bbox.is_valid())
tag_ = component::Ignored;
......@@ -128,114 +141,129 @@ namespace scribo
}
inline
component_info::component_id_t
component_info::id() const
template <typename L>
typename component_info<L>::component_id_t
component_info<L>::id() const
{
return id_;
}
inline
template <typename L>
const mln::box2d&
component_info::bbox() const
component_info<L>::bbox() const
{
return bbox_;
}
inline
template <typename L>
const mln::point2d&
component_info::mass_center() const
component_info<L>::mass_center() const
{
return mass_center_;
}
inline
template <typename L>
unsigned
component_info::card() const
component_info<L>::card() const
{
return card_;
}
inline
template <typename L>
bool
component_info::has_features() const
component_info<L>::has_features() const
{
return features_.valid;
}
inline
template <typename L>
void
component_info::update_features(const component_features_data& features)
component_info<L>::update_features(const component_features_data& features)
{
features_ = features;
}
inline
template <typename L>
const component_features_data&
component_info::features() const
component_info<L>::features() const
{
return features_;
}
inline
template <typename L>
component::Tag
component_info::tag() const
component_info<L>::tag() const
{
return tag_;
}
inline
template <typename L>
void
component_info::update_tag(component::Tag tag)
component_info<L>::update_tag(component::Tag tag)
{
tag_ = tag;
}
inline
template <typename L>
component::Type
component_info::type() const
component_info<L>::type() const
{
return type_;
}
inline
template <typename L>
void
component_info::update_type(component::Type type)
component_info<L>::update_type(component::Type type)
{
type_ = type;
}
inline
template <typename L>
bool
component_info::is_valid() const
component_info<L>::is_valid() const
{
return tag_ != component::Ignored && bbox_.is_valid();
}
inline
template <typename L>
const component_set<L>&
component_info<L>::holder() const
{
return holder_;
}
template <typename L>
std::ostream&
operator<<(std::ostream& ostr, const component_info& info)
operator<<(std::ostream& ostr, const component_info<L>& info)
{
return ostr << "component_info("
<< "id=" << info.id()
<< ", bbox=" << info.bbox()
<< ", mass_center=" << info.mass_center()
<< ", card=" << info.card()
<< ", tag=" << info.tag()
<< ", features=" << info.features()
<< ")" << std::endl;
ostr << "component_info("
<< "id=" << info.id()
<< ", bbox=" << info.bbox()
<< ", mass_center=" << info.mass_center()
<< ", card=" << info.card()
<< ", tag=" << info.tag();
if (info.features().valid)
ostr << ", features=" << info.features();
else
ostr << ", features=none";
ostr << ")" << std::endl;
return ostr;
}
inline
template <typename L>
bool
operator==(const component_info& lhs, const component_info& rhs)
operator==(const component_info<L>& lhs, const component_info<L>& rhs)
{
return
......
......@@ -98,7 +98,7 @@ namespace scribo
component::Type type = component::Undefined);
component_set_data(const L& ima, const mln_value(L)& ncomps,
const mln::util::array<scribo::component_info>& infos);
const mln::util::array<scribo::component_info<L> >& infos);
void fill_infos(const mln::util::array<pair_accu_t>& attribs,
component::Type type = component::Undefined);
......@@ -111,7 +111,7 @@ namespace scribo
L ima_;
mln_value(L) ncomps_;
mln::util::array<scribo::component_info> infos_;
mln::util::array<scribo::component_info<L> > infos_;
mln_ch_value(L, bool) separators_;
};
......@@ -162,16 +162,16 @@ namespace scribo
mln_value(L) nelements() const;
/// Return component information for a given component id \p id.
const component_info& info(const mln_value(L)& id) const;
const component_info<L>& info(const mln_value(L)& id) const;
/// Return component information for a given component id \p id.
component_info& info(const mln_value(L)& id);
component_info<L>& info(const mln_value(L)& id);
/// Return component information for a given component id \p id.
component_info& operator()(const component_id_t& id);
component_info<L>& operator()(const component_id_t& id);
/// Return component information for a given component id \p id.
const component_info& operator()(const component_id_t& id) const;
const component_info<L>& operator()(const component_id_t& id) const;
/// Update tag of components set to 'false' in \p f with \p tag.
......@@ -211,7 +211,7 @@ namespace scribo
/// @{
/// Return all the component infos.
const mln::util::array<scribo::component_info>& infos_() const;
const mln::util::array<scribo::component_info<L> >& infos_() const;
/// Unique set Id.
id_t id_() const;
......@@ -278,99 +278,6 @@ namespace scribo
const mln_value(L)& ncomps)
: ima_(ima), ncomps_(ncomps)
{
initialize(separators_, ima); // FIXME: to be removed
mln::data::fill(separators_, false);
typedef mln::accu::shape::bbox<mln_site(L)> bbox_accu_t;
typedef mln::accu::center<mln_site(L)> center_accu_t;
typedef mln::accu::pair<bbox_accu_t, center_accu_t> pair_accu_t;
mln::util::array<pair_accu_t> attribs;
mln::labeling::compute(attribs, ima_, 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<pair_accu_t>& attribs,
component::Type type)
: ima_(ima), ncomps_(ncomps)
{
initialize(separators_, ima); // FIXME: to be removed
mln::data::fill(separators_, false);
fill_infos(attribs, type);
}
template <typename L>
inline
component_set_data<L>::component_set_data(const L& ima,
const mln_value(L)& ncomps,
const mln::util::array<pair_data_t>& attribs,
component::Type type)
: ima_(ima), ncomps_(ncomps)
{
initialize(separators_, ima); // FIXME: to be removed
mln::data::fill(separators_, false);
fill_infos(attribs, type);
}
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)
{
initialize(separators_, ima); // FIXME: to be removed
mln::data::fill(separators_, false);
}
template <typename L>
inline
void
component_set_data<L>::fill_infos(const mln::util::array<pair_accu_t>& attribs,
component::Type type)
{
typedef mln_site(L) P;
infos_.reserve(mln::value::next(ncomps_));
infos_.append(component_info()); // Component 0, i.e. the background.
for_all_comp_data(i, attribs)
{
component_info info(i, attribs[i].first(),
attribs[i].second(), attribs[i].second_accu().nsites(),
type);
infos_.append(info);
}
}
template <typename L>
inline
void
component_set_data<L>::fill_infos(const mln::util::array<pair_data_t>& attribs,
component::Type type)
{
typedef mln_site(L) P;
infos_.reserve(mln::value::next(ncomps_));
infos_.append(component_info()); // Component 0, i.e. the background.
for_all_comp_data(i, attribs)
{
component_info info(i, attribs[i].first,
attribs[i].second.first, attribs[i].second.second,
type);
infos_.append(info);
}
}
......@@ -383,7 +290,7 @@ namespace scribo
ncomps_ = ncomps;
infos_.reserve(ncomps_);
infos_.append(component_info()); // Component 0, i.e. the background.
infos_.append(component_info<L>()); // Component 0, i.e. the background.
}
......@@ -410,6 +317,30 @@ namespace scribo
component_set<L>::component_set(const L& ima, const mln_value(L)& ncomps)
{
data_ = new internal::component_set_data<L>(ima, ncomps);
initialize(data_->separators_, ima); // FIXME: to be removed
mln::data::fill(data_->separators_, false);
typedef mln::accu::shape::bbox<mln_site(L)> bbox_accu_t;
typedef mln::accu::center<mln_site(L)> center_accu_t;
typedef mln::accu::pair<bbox_accu_t, center_accu_t> pair_accu_t;
mln::util::array<pair_accu_t> attribs;
mln::labeling::compute(attribs, ima, ncomps);
typedef mln_site(L) P;
data_->infos_.reserve(mln::value::next(ncomps));
data_->infos_.append(component_info<L>()); // Component 0, i.e. the background.
for_all_comp_data(i, attribs)
{
component_info<L> info(*this, i, attribs[i].first(),
attribs[i].second(), attribs[i].second_accu().nsites());
data_->infos_.append(info);
}
}
......@@ -419,7 +350,23 @@ namespace scribo
const mln::util::array<pair_accu_t>& attribs,
component::Type type)
{
data_ = new internal::component_set_data<L>(ima, ncomps, attribs, type);
data_ = new internal::component_set_data<L>(ima, ncomps);
initialize(data_->separators_, ima); // FIXME: to be removed
mln::data::fill(data_->separators_, false);
typedef mln_site(L) P;
data_->infos_.reserve(mln::value::next(ncomps));
data_->infos_.append(component_info<L>()); // Component 0, i.e. the background.
for_all_comp_data(i, attribs)
{
component_info<L> info(*this, i, attribs[i].first(),
attribs[i].second(), attribs[i].second_accu().nsites(),
type);
data_->infos_.append(info);
}
}
......@@ -430,7 +377,23 @@ namespace scribo
const mln::util::array<pair_data_t>& attribs,
component::Type type)
{
data_ = new internal::component_set_data<L>(ima, ncomps, attribs, type);
data_ = new internal::component_set_data<L>(ima, ncomps);
initialize(data_->separators_, ima); // FIXME: to be removed
mln::data::fill(data_->separators_, false);
typedef mln_site(L) P;
data_->infos_.reserve(mln::value::next(ncomps));
data_->infos_.append(component_info<L>()); // Component 0, i.e. the background.
for_all_comp_data(i, attribs)
{
component_info<L> info(*this, i, attribs[i].first,
attribs[i].second.first, attribs[i].second.second,
type);
data_->infos_.append(info);
}
}
......@@ -445,7 +408,7 @@ namespace scribo
template <typename L>
inline
const component_info&
const component_info<L>&
component_set<L>::info(const mln_value(L)& id) const
{
return data_->infos_[id];
......@@ -453,7 +416,7 @@ namespace scribo
template <typename L>
inline
component_info&
component_info<L>&
component_set<L>::info(const mln_value(L)& id)
{
return data_->infos_[id];
......@@ -461,7 +424,7 @@ namespace scribo
template <typename L>
inline
const component_info&
const component_info<L>&
component_set<L>::operator()(const component_id_t& id) const
{
return data_->infos_[id];
......@@ -469,7 +432,7 @@ namespace scribo
template <typename L>
inline
component_info&
component_info<L>&
component_set<L>::operator()(const component_id_t& id)
{
return data_->infos_[id];
......@@ -611,7 +574,7 @@ namespace scribo
template <typename L>
inline
const mln::util::array<scribo::component_info>&
const mln::util::array<scribo::component_info<L> >&
component_set<L>::infos_() const
{
return data_->infos_;
......
......@@ -65,7 +65,8 @@ namespace scribo
template <typename L>
void visit(const component_set<L>& comp_set) const;
void visit(const component_info& info) const;
template <typename L>
void visit(const component_info<L>& info) const;
template <typename L>
void visit(const paragraph_set<L>& parset) const;
......@@ -113,8 +114,9 @@ namespace scribo
}
template <typename E>
template <typename L>
void
doc_serializer<E>::visit(const component_info& info) const
doc_serializer<E>::visit(const component_info<L>& info) const
{
}
......
......@@ -69,7 +69,8 @@ namespace scribo
template <typename L>
void visit(const document<L>& doc) const;
void visit(const component_info& info) const;
template <typename L>
void visit(const component_info<L>& info) const;
template <typename L>
void visit(const paragraph_set<L>& parset) const;
......@@ -173,9 +174,9 @@ namespace scribo
/// Component_info
//
inline
template <typename L>
void
debug_img_visitor::visit(const component_info& info) const
debug_img_visitor::visit(const component_info<L>& info) const
{
switch (info.type())
{
......
......@@ -60,8 +60,9 @@ namespace scribo
/*! \brief Draw component edges.
*/
template <typename L>
void
draw_edges(const component_info& info,
draw_edges(const component_info<L>& info,
image2d<value::rgb8>& output, const value::rgb8& value,
const image2d<scribo::def::lbl_type>& edges);
......@@ -69,9 +70,9 @@ namespace scribo
# ifndef MLN_INCLUDE_ONLY