URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-12-12 Simon Nivault <simon.nivault(a)lrde.epita.fr>
.
* mln/core/internal/run_image.hh: Add `has' and `point_at'
method.
* mln/core/mono_obased_rle_image.hh,
* mln/core/mono_rle_image.hh,
* mln/core/obased_rle_image.hh,
* mln/core/p_runs.hh,
* mln/core/rle_image.hh,
* mln/core/sparse_image.hh: Use the new methods above.
* tests/core/p_runs.cc: Fix test.
---
mln/core/internal/run_image.hh | 40 ++++++++++++++++++++++++++++++++++++++
mln/core/mono_obased_rle_image.hh | 6 +----
mln/core/mono_rle_image.hh | 15 ++++++--------
mln/core/obased_rle_image.hh | 6 +----
mln/core/p_runs.hh | 13 +++++-------
mln/core/rle_image.hh | 6 +----
mln/core/sparse_image.hh | 8 +------
tests/core/p_runs.cc | 5 ++--
8 files changed, 64 insertions(+), 35 deletions(-)
Index: trunk/milena/tests/core/p_runs.cc
===================================================================
--- trunk/milena/tests/core/p_runs.cc (revision 1608)
+++ trunk/milena/tests/core/p_runs.cc (revision 1609)
@@ -58,6 +58,7 @@
// Pset test
p_runs_<point2d> ps;
+ p_runs_<point2d> ps2;
ps.insert(p_run<point2d>(p, 7));
mln_assertion(ps.npoints() == 7);
@@ -71,10 +72,10 @@
// Psite declaration
runs_psite<point2d> site(ps, 5, 0);
- runs_psite<point2d> site2(ps, 6, 1);
+ runs_psite<point2d> site2(ps, 5, 1);
mln_assertion(ps.has(site));
- mln_assertion(!ps.has(site2));
+ mln_assertion(!ps2.has(site2));
parc(ps);
Index: trunk/milena/mln/core/internal/run_image.hh
===================================================================
--- trunk/milena/mln/core/internal/run_image.hh (revision 1608)
+++ trunk/milena/mln/core/internal/run_image.hh (revision 1609)
@@ -71,6 +71,21 @@
* actually an lighter image. So it improves compression.
*/
void finalize();
+
+ /*! \brief Give the point represented by the point-site.
+ *
+ * Use the coordinate of the psite to see what point it corresponds
+ * with the domain of the image.
+ *
+ * \return The corresponding point.
+ */
+ P point_at(const runs_psite<P>& ps) const;
+
+ /*! \brief Tell if the image has the given point site.
+ *
+ * \return True if the image has the point site, else false.
+ */
+ bool has(const runs_psite<P>& ps) const;
};
# ifndef MLN_INCLUDE_ONLY
@@ -98,6 +113,31 @@
exact(this)->data_->finalize();
}
+ template <typename T, typename P, typename E>
+ inline
+ P
+ run_image_<T, P, E>::point_at(const runs_psite<P>& ps) const
+ {
+ const E* ima = exact(this);
+ mln_precondition(ps.p_of_run() < ima->data_->domain_.nruns());
+ mln_precondition(ps.p_in_run() <
ima->data_->domain_[ps.p_of_run()].length());
+ return ima->data_->domain_[ps.p_of_run()][ps.p_in_run()];
+ }
+
+ template <typename T, typename P, typename E>
+ inline
+ bool
+ run_image_<T, P, E>::has(const runs_psite<P>& ps) const
+ {
+ const E* ima = exact(this);
+ if (!ima->has_data())
+ return false;
+ else
+ return (ps.p_of_run() < ima->data_->domain_.nruns()
+ && ps.p_in_run() < ima->data_->domain_[ps.p_of_run()].length()
+ && ima->data_->domain_[ps.p_of_run()][ps.p_in_run()] == ps);
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace internal
Index: trunk/milena/mln/core/rle_image.hh
===================================================================
--- trunk/milena/mln/core/rle_image.hh (revision 1608)
+++ trunk/milena/mln/core/rle_image.hh (revision 1609)
@@ -212,8 +212,7 @@
rle_image<P, T>::operator() (const typename rle_image<P, T>::psite&
site)
const
{
- mln_precondition(this->has_data() &&
- site.p_of_run() < this->data_->values_.size());
+ mln_precondition(this->has(site));
return this->data_->values_[site.p_of_run()];
}
@@ -222,8 +221,7 @@
typename rle_image<P, T>::lvalue
rle_image<P, T>::operator() (const typename rle_image<P, T>::psite&
site)
{
- mln_precondition(this->has_data() &&
- site.p_of_run() < this->data_->values_.size());
+ mln_precondition(this->has(site));
return this->data_->values_[site.p_of_run()];
}
Index: trunk/milena/mln/core/mono_rle_image.hh
===================================================================
--- trunk/milena/mln/core/mono_rle_image.hh (revision 1608)
+++ trunk/milena/mln/core/mono_rle_image.hh (revision 1609)
@@ -211,27 +211,26 @@
template <typename P, typename T>
inline
typename mono_rle_image<P, T>::rvalue
- mono_rle_image<P, T>::operator() (const typename mono_rle_image<P,
T>::psite& site)
- const
+ mono_rle_image<P, T>::operator() (const typename mono_rle_image<P,
T>::psite& site) const
{
- mln_precondition(site.p_of_run() < this->data_->domain_.nruns());
+ mln_precondition(this->has(site));
return this->data_->value_;
}
template <typename P, typename T>
inline
- typename mono_rle_image<P, T>::rvalue
- mono_rle_image<P, T>::get_value() const
+ typename mono_rle_image<P, T>::lvalue
+ mono_rle_image<P, T>::operator() (const typename mono_rle_image<P,
T>::psite& site)
{
+ mln_precondition(this->has(site));
return this->data_->value_;
}
template <typename P, typename T>
inline
- typename mono_rle_image<P, T>::lvalue
- mono_rle_image<P, T>::operator() (const typename mono_rle_image<P,
T>::psite& site)
+ typename mono_rle_image<P, T>::rvalue
+ mono_rle_image<P, T>::get_value() const
{
- mln_precondition(site.p_of_run() < this->data_->domain_.nruns());
return this->data_->value_;
}
Index: trunk/milena/mln/core/obased_rle_image.hh
===================================================================
--- trunk/milena/mln/core/obased_rle_image.hh (revision 1608)
+++ trunk/milena/mln/core/obased_rle_image.hh (revision 1609)
@@ -240,8 +240,7 @@
obased_rle_image<P, T>::operator() (const typename obased_rle_image<P,
T>::psite& site)
const
{
- mln_precondition(this->has_data() &&
- site.p_of_run() < this->data_->domain_.nruns());
+ mln_precondition(this->has(site));
return this->data_->values_[site.p_of_run()];
}
@@ -250,8 +249,7 @@
typename obased_rle_image<P, T>::lvalue
obased_rle_image<P, T>::operator() (const typename obased_rle_image<P,
T>::psite& site)
{
- mln_precondition(this->has_data() &&
- site.p_of_run() < this->data_->domain_.nruns());
+ mln_precondition(this->has(site));
return this->data_->values_[site.p_of_run()];
}
Index: trunk/milena/mln/core/mono_obased_rle_image.hh
===================================================================
--- trunk/milena/mln/core/mono_obased_rle_image.hh (revision 1608)
+++ trunk/milena/mln/core/mono_obased_rle_image.hh (revision 1609)
@@ -228,8 +228,7 @@
mono_obased_rle_image<P, T>::operator() (const typename
mono_obased_rle_image<P, T>::psite& site)
const
{
- mln_precondition(this->has_data() &&
- site.p_of_run() < this->data_->domain_.nruns());
+ mln_precondition(this->has(site));
return this->data_->values_[site.p_of_run()];
}
@@ -238,8 +237,7 @@
typename mono_obased_rle_image<P, T>::lvalue
mono_obased_rle_image<P, T>::operator() (const typename
mono_obased_rle_image<P, T>::psite& site)
{
- mln_precondition(this->has_data() &&
- site.p_of_run() < this->data_->domain_.nruns());
+ mln_precondition(this->has(site));
return this->data_->values_[site.p_of_run()];
}
Index: trunk/milena/mln/core/sparse_image.hh
===================================================================
--- trunk/milena/mln/core/sparse_image.hh (revision 1608)
+++ trunk/milena/mln/core/sparse_image.hh (revision 1609)
@@ -212,9 +212,7 @@
sparse_image<P, T>::operator() (const typename sparse_image<P,
T>::psite& site)
const
{
- mln_precondition(this->has_data());
- mln_precondition(site.p_of_run() < this->data_->values_.size());
- mln_precondition(site.p_in_run() <
this->data_->values_[site.p_of_run()].size());
+ mln_precondition(this->has(site));
return this->data_->values_[site.p_of_run()][site.p_in_run()];
}
@@ -223,9 +221,7 @@
typename sparse_image<P, T>::lvalue
sparse_image<P, T>::operator() (const typename sparse_image<P,
T>::psite& site)
{
- mln_precondition(this->has_data() &&
- site.p_of_run() < this->data_->values_.size() &&
- site.p_in_run() < this->data_->values_[site.p_of_run()].size());
+ mln_precondition(this->has(site));
return this->data_->values_[site.p_of_run()][site.p_in_run()];
}
Index: trunk/milena/mln/core/p_runs.hh
===================================================================
--- trunk/milena/mln/core/p_runs.hh (revision 1608)
+++ trunk/milena/mln/core/p_runs.hh (revision 1609)
@@ -70,7 +70,7 @@
p_runs_();
/// Test is \p p belongs to this point set.
- bool has(const runs_psite<P>& p) const;
+ bool has(const runs_psite<P>& ps) const;
/// Give the exact bounding box.
const box_<P>& bbox() const;
@@ -123,13 +123,12 @@
template <typename P>
inline
bool
- p_runs_<P>::has(const runs_psite<P>& p) const
+ p_runs_<P>::has(const runs_psite<P>& ps) const
{
- for (unsigned i = 0; i < con_.nelements(); ++i)
- {
- if (con_[i].first() == p.range_start_() && con_[i].length() >
p.p_in_run())
- return true;
- }
+ if (ps.p_of_run() < nruns()
+ && ps.p_in_run() < con_[ps.p_of_run()].length())
+ return (ps == con_[ps.p_of_run()][ps.p_in_run()]);
+ else
return false;
}