Commit def1c9e0 authored by Nicolas Ballas's avatar Nicolas Ballas
Browse files

Add rle_class, not finish yet.

	* oln/core/rle: New.
	* oln/core/rle/rle_image.hh: New.
	* oln/core/rle/rle_psite.hh: New.
	* oln/core/rle/rle_pset.hh: New.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@862 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent cb82d5a5
2007-03-11 Nicolas Ballas <ballas@lrde.epita.fr>
Add rle_class, not finish yet.
* oln/core/rle: New.
* oln/core/rle/rle_image.hh: New.
* oln/core/rle/rle_psite.hh: New.
* oln/core/rle/rle_pset.hh: New.
2007-03-11 Nicolas Ballas <ballas@bosc-guerard.lrde.epita.fr>
Add rle_image class, not finish yet.
rle_image class depends on rle_psite class and rle_pset class.
* oln/core/rle/rle_image.hh: New
* oln/core/rle/rle_psite.hh: .
* oln/core/rle/rle_pset.hh: .
2007-03-09 Ugo Jardonnet <ugo.jardonnet@lrde.epita.fr>
Add test for neighborhood.
......
// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 EPITA
// Research and Development Laboratory
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
// of the GNU General Public License version 2 as published by the
// Free Software Foundation.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this library; see the file COPYING. If not, write to
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02111-1307, USA.
//
// As a special exception, you may use this file as part of a free
// software library without restriction. Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to
// produce an executable, this file does not by itself cause the
// resulting executable to be covered by the GNU General Public
// License. This exception does not however invalidate any other
// reasons why the executable file might be covered by the GNU General
// Public License.
#ifndef OLN_CORE_RLE_RLE_IMAGE_HH_
# define OLN_CORE_RLE_RLE_IMAGE_HH_
# include <map>
# include <utility>
# include <oln/core/internal/image_base.hh>
# include <oln/core/rle/rle_psite.hh>
# include <oln/core/rle/rle_pset.hh>
namespace oln
{
// Fwd decl.
template <typename P, typename T>
struct rle_image;
// Super type.
template <typename P, typename T>
struct super_trait_< rle_image<P, T> >
{
typedef rle_image<P, T> current;
typedef internal::primitive_image_<current> ret;
};
// Virtual types
template <typename P, typename T>
struct vtypes< rle_image<P, T> >
{
typedef T value;
typedef const T& rvalue;
typedef T& lvalue;
typedef P point;
typedef typename P::coord coord;
typedef rle_psite<P, T> psite;
typedef rle_pset<point> pset;
// typedef typename pset::box box;
typedef std::map<std::pair<point, unsigned>, value> data;
};
// Rle image class
template < typename P, typename T>
class rle_image : public internal::primitive_image_< rle_image<P, T> >
{
typedef rle_image<P, T> current;
typedef internal::primitive_image_< rle_image<P, T> > super;
public:
stc_using(pset);
stc_using(box);
stc_using(point);
stc_using(value);
stc_using(rvalue);
stc_using(lvalue);
stc_using(psite);
stc_using(data);
rle_image();
pset impl_points() const;
box impl_bbox() const;
bool impl_has(const point& p) const;
bool impl_owns_(const psite& p) const;
void insert(const point& p, unsigned len, value val);
rvalue impl_read(const psite& p) const;
lvalue impl_read_write(const psite& p);
//Internal
const data& get_data_() const;
protected:
pset pset_;
};
# ifndef OLN_INCLUDE_ONLY
template <typename P, typename T>
rle_image<P, T>::rle_image()
{
this->data_ = new typename rle_image<P, T>::data;
}
template <typename P, typename T>
typename rle_image<P, T>::pset
rle_image<P, T>::impl_points() const
{
return pset_;
}
template <typename P, typename T>
typename rle_image<P, T>::box
rle_image<P, T>::impl_bbox() const
{
return pset_.bbox();
}
template <typename P, typename T>
bool
rle_image<P, T>::impl_has(const typename rle_image<P, T>::point& p) const
{
return this->pset_.has(p.point_());
}
template <typename P, typename T>
bool
rle_image<P, T>::impl_owns_(const typename rle_image<P, T>::psite& p) const
{
//FIXME
return this->pset_.has(p.point_());
}
template <typename P, typename T>
void
rle_image<P, T>::insert(const typename rle_image<P, T>::point& p, unsigned len, rle_image<P, T>::value val)
{
pset_.insert(p, len);
((this->data_))->operator[](std::make_pair(p, len)) = val;
}
template <typename P, typename T>
typename rle_image<P, T>::rvalue
rle_image<P, T>::impl_read(const rle_image<P, T>::psite& p) const
{
precondition(p.iterator_() != this->data_->end());
return p.iterator_()->second;
}
template <typename P, typename T>
typename rle_image<P, T>::lvalue
rle_image<P, T>::impl_read_write(const rle_image<P, T>::psite& p)
{
precondition(p.iterator_() != this->data_->end());
return p.iterator_()->second;
}
template <typename P, typename T>
const typename rle_image<P, T>::data&
rle_image<P, T>::get_data_() const
{
//FIXME: another way to do that?
return *(this->data_.ptr_);
}
# endif // !OLN_INCLUDE_ONLY
} // end of namespace oln
#endif /* !OLN_CORE_RLE_RLE_IMAGE_HH_ */
// Copyright (C) 2006, 2007 EPITA Research and Development Laboratory
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
// of the GNU General Public License version 2 as published by the
// Free Software Foundation.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this library; see the file COPYING. If not, write to
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02111-1307, USA.
//
// As a special exception, you may use this file as part of a free
// software library without restriction. Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to
// produce an executable, this file does not by itself cause the
// resulting executable to be covered by the GNU General Public
// License. This exception does not however invalidate any other
// reasons why the executable file might be covered by the GNU General
// Public License.
#ifndef OLN_CORE_RLE_RLE_PSET_HH_
# define OLN_CORE_RLE_RLE_PSET_HH_
# include <set>
# include <utility>
# include <oln/core/rle/rle_psite.hh>
# include <oln/core/internal/point_set_base.hh>
# include <oln/core/concept/iterator_on_points.hh>
# include <oln/core/gen/fbbox.hh>
namespace oln
{
// Forwards declaration
template <typename P> struct rle_pset;
template <typename P> struct rle_pset_fwd_piter_;
template <typename P> struct rle_pset_bkd_piter_;
// Vtypes associated to rle_pset class
template <typename P>
struct vtypes< rle_pset<P> >
{
typedef P point;
typedef typename P::grid grid;
typedef fbbox_<point> box;
typedef rle_pset_fwd_piter_<P> fwd_piter;
typedef rle_pset_bkd_piter_<P> bkd_piter;
typedef fwd_piter piter;
};
// rle_pset class
template <typename P>
class rle_pset : public internal::point_set_base_<rle_pset <P> >
{
typedef rle_pset<P> current;
typedef internal::point_set_base_<rle_pset<P> > super;
public:
stc_using(point);
stc_using(box);
typedef std::set< std::pair<point, unsigned> > std_container;
rle_pset();
unsigned impl_npoints() const;
const box& impl_bbox() const;
void insert(const P& p, unsigned len);
bool impl_has(const P& p) const;
const std_container& con() const;
protected:
unsigned npts;
std_container con_;
fbbox_<point> fb_;
};
# ifndef OLN_INCLUDE_ONLY
template <typename P>
rle_pset<P>::rle_pset() : npts(0)
{
}
template <typename P>
unsigned
rle_pset<P>::impl_npoints() const
{
return npts;
}
template <typename P>
void
rle_pset<P>::insert(const P& p, unsigned len)
{
con_.insert(std::make_pair(p, len));
P pend;
//update bbox
fb_.take(p);
pend = p;
pend[0] += len - 1;
fb_.take(pend);
// update size
npts += len;
}
template <typename P>
const typename rle_pset<P>::box&
rle_pset<P>::impl_bbox() const
{
return fb_;
}
template <typename P>
bool
rle_pset<P>::impl_has(const P& p) const
{
point pend;
typename std_container::const_iterator iter;
for (iter = con_.begin(); iter != con_.end(); ++iter )
{
pend = iter->first;
pend[0] += iter->second - 1;
if (iter->first >= p && p <= pend)
return 1;
}
return 0;
}
// end of rle_pset class
template <typename P>
const typename rle_pset<P>::std_container&
rle_pset<P>::con() const
{
return this->con_;
}
# endif // !OLN_INCLUDE_ONLY
// -------------------- iterators on classes deriving from internal::rle_pset<P>
// Forward declaration
template <typename P>
class rle_pset_fwd_piter_;
// Virtual types
template <typename P>
struct vtypes< rle_pset_fwd_piter_<P> >
{
typedef P point;
};
// class rle_pset_fwd_iterator_
template <typename P>
class rle_pset_fwd_piter_ : public Iterator_on_Points< rle_pset_fwd_piter_<P> >
{
typedef Iterator_on_Points< rle_pset_fwd_piter_<P> > super;
typedef rle_pset_fwd_piter_<P> current;
public:
stc_using(point);
rle_pset_fwd_piter_(const rle_pset<P>& con);
void impl_start();
void impl_next();
void impl_invalidate();
bool impl_is_valid() const;
point impl_to_point() const;
const point* impl_point_adr() const;
protected:
const typename rle_pset<P>::std_container& con_;
typename rle_pset<P>::std_container::const_iterator it_;
point p_;
};
# ifndef OLN_INCLUDE_ONLY
template <typename P>
rle_pset_fwd_piter_<P>::rle_pset_fwd_piter_(const rle_pset<P>& cont) : con_(cont.con())
{
this->it_ = this->con_.end();
}
template <typename P>
void
rle_pset_fwd_piter_<P>::impl_start()
{
this->it_ = this->con_.begin();
this->p_ = this->it_->first;
}
template <typename P>
void
rle_pset_fwd_piter_<P>::impl_next()
{
point pend;
if (!this->is_valid())
return;
pend = this->it_->first;
pend[0] += this->it_->second - 1;
++p_[0];
if (p_ > pend)
{
++it_;
p_ = this->it_->first;
}
}
template <typename P>
void
rle_pset_fwd_piter_<P>::impl_invalidate()
{
this->it_ = this->con_.end();
}
template <typename P>
bool
rle_pset_fwd_piter_<P>::impl_is_valid() const
{
return this->it_ != this->con_.end();
}
template <typename P>
typename rle_pset_fwd_piter_<P>::point
rle_pset_fwd_piter_<P>::impl_to_point() const
{
return p_;
}
template <typename P>
const typename rle_pset_fwd_piter_<P>::point*
rle_pset_fwd_piter_<P>::impl_point_adr() const
{
return &p_;
}
# endif // !OLN_INCLUDE_ONLY
//end of class rle_pset_fwd_iterator_
// Forward declaration
template <typename P>
class rle_pset_bkd_piter_;
// Virtual type
template <typename P>
struct vtypes< rle_pset_bkd_piter_<P> >
{
typedef P point;
};
// class rle_pset_bkd_piter_
template <typename P>
class rle_pset_bkd_piter_ : public Iterator_on_Points< rle_pset_bkd_piter_<P> >
{
typedef Iterator_on_Points< rle_pset_bkd_piter_<P> > super;
typedef rle_pset_bkd_piter_<P> current;
public:
stc_using(point);
rle_pset_bkd_piter_(const rle_pset<P>& con);
void impl_start();
void impl_next();
void impl_invalidate();
bool impl_is_valid() const;
point impl_to_point() const;
const point* impl_point_adr() const;
protected:
const typename rle_pset<P>::std_container& con_;
typename rle_pset<P>::std_container::const_reverse_iterator it_;
point p_;
};
# ifndef OLN_INCLUDE_ONLY
template <typename P>
rle_pset_bkd_piter_<P>::rle_pset_bkd_piter_(const rle_pset<P>& cont) : con_(cont.con())
{
this->it_ = this->con_.rend();
}
template <typename P>
void
rle_pset_bkd_piter_<P>::impl_start()
{
this->it_ = this->con_.rbegin();
this->p_ = this->it_->first;
this->p_[0] += this->it_->second - 1;
}
template <typename P>
void
rle_pset_bkd_piter_<P>::impl_next()
{
point pend;
if (!this->is_valid())
return;
pend = this->it_->first;
--p_[0];
if (p_ < pend)
{
++it_;
p_ = this->it_->first;
this->p_[0] += this->it_->second - 1;
}
}
template <typename P>
void
rle_pset_bkd_piter_<P>::impl_invalidate()
{
this->it_ = this->con_.rend();
}
template <typename P>
bool
rle_pset_bkd_piter_<P>::impl_is_valid() const
{
return this->it_ != this->con_.rend();
}
template <typename P>
typename rle_pset_bkd_piter_<P>::point
rle_pset_bkd_piter_<P>::impl_to_point() const
{
return p_;
}
template <typename P>
const typename rle_pset_bkd_piter_<P>::point*
rle_pset_bkd_piter_<P>::impl_point_adr() const
{
return &p_;
}
# endif // !OLN_INCLUDE_ONLY
// end of class rle_pset_bkd_piter_
} // end of namespace oln
#endif /* !OLN_CORE_RLE_RLE_PSET_HH_ */
// Copyright (C) 2006, 2007 EPITA Research and Development Laboratory
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
// of the GNU General Public License version 2 as published by the
// Free Software Foundation.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this library; see the file COPYING. If not, write to
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02111-1307, USA.
//
// As a special exception, you may use this file as part of a free
// software library without restriction. Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to
// produce an executable, this file does not by itself cause the
// resulting executable to be covered by the GNU General Public
// License. This exception does not however invalidate any other
// reasons why the executable file might be covered by the GNU General
// Public License.
#ifndef OLN_CORE_RLE_RLE_PSITE_HH_
# define OLN_CORE_RLE_RLE_PSITE_HH_
# include <map>
# include <utility>
namespace oln
{
// Forward declaration
template <typename P, typename T> struct rle_image;
/*