Commit 2acea521 authored by Thierry Geraud's avatar Thierry Geraud
Browse files

Add milena neighborhood.

	* milena/test/main.cc: Update.
	* milena/core/neighb2d.hh: New.
	* milena/core/neighb.hh: New.
	* milena/core/concept/neighborhood.hh: New.
	* milena/core/dpoints_qiter.hh: Rename as...
	* milena/core/dpoints_piter.hh: ...this.
	* milena/core/internal/set_of.hh (operator<<): New;
	factor code.
	* milena/core/rectangle2d.hh: Update.
	* milena/core/window.hh: Update.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@986 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 3318bef3
2007-06-28 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Add milena neighborhood.
* milena/test/main.cc: Update.
* milena/core/neighb2d.hh: New.
* milena/core/neighb.hh: New.
* milena/core/concept/neighborhood.hh: New.
* milena/core/dpoints_qiter.hh: Rename as...
* milena/core/dpoints_piter.hh: ...this.
* milena/core/internal/set_of.hh (operator<<): New;
factor code.
* milena/core/rectangle2d.hh: Update.
* milena/core/window.hh: Update.
2007-06-28 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Update milena.
......
#ifndef MLN_CORE_CONCEPT_NEIGHBORHOOD_HH
# define MLN_CORE_CONCEPT_NEIGHBORHOOD_HH
# include <core/concept/object.hh>
namespace mln
{
template <typename E>
struct Neighborhood : public Object<E>
{
/*
typedef niter;
typedef fwd_niter;
typedef bkd_niter;
*/
protected:
Neighborhood();
};
# ifndef MLN_INCLUDE_ONLY
template <typename E>
Neighborhood<E>::Neighborhood()
{
typedef mln_niter(E) niter;
typedef mln_fwd_niter(E) fwd_niter;
typedef mln_bkd_niter(E) bkd_niter;
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
#endif // ! MLN_CORE_CONCEPT_NEIGHBORHOOD_HH
#ifndef MLN_CORE_DPOINTS_QITER_HH
# define MLN_CORE_DPOINTS_QITER_HH
#ifndef MLN_CORE_DPOINTS_PITER_HH
# define MLN_CORE_DPOINTS_PITER_HH
# include <core/concept/piter.hh>
# include <core/concept/genpoint.hh>
......@@ -9,7 +9,7 @@ namespace mln
{
template <typename D>
class dpoints_fwd_qiter : public Piter< dpoints_fwd_qiter<D> >
class dpoints_fwd_piter : public Piter< dpoints_fwd_piter<D> >
{
public:
......@@ -21,7 +21,7 @@ namespace mln
typedef mln_coord(D) coord;
template <typename Dps, typename Pref>
dpoints_fwd_qiter(const Dps& dps,
dpoints_fwd_piter(const Dps& dps,
const GenPoint<Pref>& p_ref);
operator point() const;
......@@ -48,7 +48,7 @@ namespace mln
template <typename D>
template <typename Dps, typename Pref>
dpoints_fwd_qiter<D>::dpoints_fwd_qiter(const Dps& dps,
dpoints_fwd_piter<D>::dpoints_fwd_piter(const Dps& dps,
const GenPoint<Pref>& p_ref)
: dps_(exact(dps).vec()),
p_ref_(* force_exact<Pref>(p_ref).pointer())
......@@ -57,7 +57,7 @@ namespace mln
}
template <typename D>
dpoints_fwd_qiter<D>::operator mln_point(D)() const
dpoints_fwd_piter<D>::operator mln_point(D)() const
{
assert(is_valid());
return p_;
......@@ -65,28 +65,28 @@ namespace mln
template <typename D>
const mln_point(D)*
dpoints_fwd_qiter<D>::pointer() const
dpoints_fwd_piter<D>::pointer() const
{
return & p_;
}
template <typename D>
bool
dpoints_fwd_qiter<D>::is_valid() const
dpoints_fwd_piter<D>::is_valid() const
{
return i_ != dps_.size();
}
template <typename D>
void
dpoints_fwd_qiter<D>::invalidate()
dpoints_fwd_piter<D>::invalidate()
{
i_ = dps_.size();
}
template <typename D>
void
dpoints_fwd_qiter<D>::start()
dpoints_fwd_piter<D>::start()
{
i_ = 0;
update_p_();
......@@ -94,7 +94,7 @@ namespace mln
template <typename D>
void
dpoints_fwd_qiter<D>::next_()
dpoints_fwd_piter<D>::next_()
{
++i_;
update_p_();
......@@ -102,7 +102,7 @@ namespace mln
template <typename D>
void
dpoints_fwd_qiter<D>::update_p_()
dpoints_fwd_piter<D>::update_p_()
{
if (is_valid())
p_ = p_ref_ + dps_[i_];
......@@ -110,7 +110,7 @@ namespace mln
template <typename D>
mln_coord(D)
dpoints_fwd_qiter<D>::operator[](unsigned i) const
dpoints_fwd_piter<D>::operator[](unsigned i) const
{
return p_[i];
}
......@@ -120,4 +120,4 @@ namespace mln
} // end of namespace mln
#endif // ! MLN_CORE_DPOINTS_QITER_HH
#endif // ! MLN_CORE_DPOINTS_PITER_HH
......@@ -36,6 +36,10 @@ namespace mln
};
template <typename E>
std::ostream& operator<<(std::ostream& ostr, const set_of_<E>& s);
# ifndef MLN_INCLUDE_ONLY
template <typename E>
......@@ -98,6 +102,17 @@ namespace mln
std::copy(s_.begin(), s_.end(), std::back_inserter(v_));
}
template <typename E>
std::ostream& operator<<(std::ostream& ostr,
const set_of_<E>& s)
{
ostr << '[';
for (unsigned i = 0; i < s.nelements(); ++i)
ostr << s.element(i)
<< (i == s.nelements() - 1 ? ']' : ',');
return ostr;
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::internal
......
#ifndef MLN_CORE_NEIGHB_HH
# define MLN_CORE_NEIGHB_HH
# include <core/concept/neighborhood.hh>
# include <core/internal/set_of.hh>
# include <core/dpoint.hh>
namespace mln
{
// fwd decls
template <typename D> class dpoints_fwd_piter;
template <typename D> class dpoints_bkd_piter;
template <typename D>
struct neighb_ : public Neighborhood< neighb_<D> >,
public internal::set_of_<D>
{
typedef dpoints_fwd_piter<D> fwd_niter;
typedef dpoints_bkd_piter<D> bkd_niter;
typedef fwd_niter niter;
neighb_();
void insert(const D& dp);
};
# ifndef MLN_INCLUDE_ONLY
template <typename D>
neighb_<D>::neighb_()
{
}
template <typename D>
void
neighb_<D>::insert(const D& dp)
{
typedef internal::set_of_<D> super;
this->super::insert( dp);
this->super::insert(-dp);
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
# include <core/dpoints_piter.hh>
#endif // ! MLN_CORE_NEIGHB_HH
#ifndef MLN_CORE_NEIGHB2D_HH
# define MLN_CORE_NEIGHB2D_HH
# include <cmath>
# include <core/neighb.hh>
# include <core/dpoint2d.hh>
namespace mln
{
typedef neighb_<dpoint2d> neighb2d;
const neighb2d& c4();
const neighb2d& c8();
const neighb2d& c2_row();
const neighb2d& c2_col();
# ifndef MLN_INCLUDE_ONLY
const neighb2d& c4()
{
static bool flower = true;
static neighb2d it;
if (flower)
{
it.insert(mk_dpoint2d(0, 1));
it.insert(mk_dpoint2d(1, 0));
flower = false;
}
return it;
}
const neighb2d& c8()
{
static bool flower = true;
static neighb2d it;
if (flower)
{
it.insert(mk_dpoint2d(0, 1));
it.insert(mk_dpoint2d(1,-1));
it.insert(mk_dpoint2d(1, 0));
it.insert(mk_dpoint2d(1, 1));
flower = false;
}
return it;
}
const neighb2d& c2_row()
{
static bool flower = true;
static neighb2d it;
if (flower)
{
it.insert(mk_dpoint2d(0, 1));
flower = false;
}
return it;
}
const neighb2d& c2_col()
{
static bool flower = true;
static neighb2d it;
if (flower)
{
it.insert(mk_dpoint2d(1, 0));
flower = false;
}
return it;
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
#endif // ! MLN_CORE_NEIGHB2D_HH
......@@ -4,7 +4,7 @@
# include <core/concept/window.hh>
# include <core/internal/set_of.hh>
# include <core/dpoint2d.hh>
# include <core/dpoints_qiter.hh>
# include <core/dpoints_piter.hh>
namespace mln
......@@ -13,8 +13,8 @@ namespace mln
struct rectangle2d : public Window< rectangle2d >,
public internal::set_of_<dpoint2d>
{
typedef dpoints_fwd_qiter<dpoint2d> fwd_qiter;
typedef dpoints_bkd_qiter<dpoint2d> bkd_qiter;
typedef dpoints_fwd_piter<dpoint2d> fwd_qiter;
typedef dpoints_bkd_piter<dpoint2d> bkd_qiter;
typedef fwd_qiter qiter;
rectangle2d(unsigned half_height, unsigned half_width);
......
......@@ -10,16 +10,16 @@ namespace mln
{
// fwd decls
template <typename D> class dpoints_fwd_qiter;
template <typename D> class dpoints_bkd_qiter;
template <typename D> class dpoints_fwd_piter;
template <typename D> class dpoints_bkd_piter;
template <typename D>
struct window_ : public Window< window_<D> >,
public internal::set_of_<D>
{
typedef dpoints_fwd_qiter<D> fwd_qiter;
typedef dpoints_bkd_qiter<D> bkd_qiter;
typedef dpoints_fwd_piter<D> fwd_qiter;
typedef dpoints_bkd_piter<D> bkd_qiter;
typedef fwd_qiter qiter;
window_();
......@@ -27,10 +27,6 @@ namespace mln
bool is_centered() const;
bool is_symmetric() const;
};
template <typename D>
std::ostream& operator<<(std::ostream& ostr,
const window_<D>& win);
# ifndef MLN_INCLUDE_ONLY
......@@ -54,23 +50,12 @@ namespace mln
return false;
}
template <typename D>
std::ostream& operator<<(std::ostream& ostr,
const window_<D>& win)
{
ostr << '[';
for (unsigned i = 0; i < win.nelements(); ++i)
ostr << win.element(i)
<< (i == win.nelements() - 1 ? ']' : ',');
return ostr;
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
# include <core/dpoints_qiter.hh>
# include <core/dpoints_piter.hh>
#endif // ! MLN_CORE_WINDOW_HH
......@@ -7,6 +7,8 @@
#include <core/window2d.hh>
#include <core/rectangle2d.hh>
#include <core/neighb2d.hh>
#include <morpho/erosion.hh>
......@@ -29,6 +31,8 @@ int main()
0, 1, 0,
1, 0, 0 };
window2d win = mk_window2d(w);
std::cout << win << std::endl;
std::cout << c8() << std::endl;
/*
{
......@@ -56,4 +60,5 @@ int main()
image2d<int> ima2 = morpho::erosion(ima, win);
debug::println(ima2);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment