Commit 19d46af7 authored by Matthieu Garrigues's avatar Matthieu Garrigues
Browse files

Add 1d handling

	* mln/convert/to_image.hh: .
	* mln/core/box1d.hh: New.
	* mln/core/dpoint1d.hh: New.
	* mln/core/image1d_b.hh: New.
	* mln/core/internal/box_impl.hh: .
	* mln/core/neighb1d.hh: New.
	* mln/core/pixter1d_b.hh: New.
	* mln/core/point1d.hh: New.
	* mln/core/w_window1d_float.hh: New.
	* mln/core/w_window1d_int.hh: New.
	* mln/core/win/segment1d.hh: New.
	* mln/core/window1d.hh: New.
	* mln/geom/max_ind.hh: New.
	* mln/geom/min_ind.hh: New.
	* mln/geom/ninds.hh: New.
	* mln/geom/size1d.hh: New.
	* mln/make/box1d.hh: New.
	* mln/make/dpoint1d.hh: New.
	* mln/make/point1d.hh: New.
	* mln/make/w_window1d.hh: New.
	* mln/make/w_window1d_int.hh: New.
	* mln/make/window1d.hh: New.
	* sandbox/garrigues/TODO: New.
	* tests/box1d.cc: New.
	* tests/dpoint1d.cc: New.
	* tests/image1d_b.cc: New.
	* tests/pixter1d_b.cc: New.
	* tests/point1d.cc: New.
	* tests/w_window1d_int.cc: New.
	* tests/window1d.cc: New.

git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@1071 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent eaa7486c
2007-09-05 Matthieu Garrigues <garrigues.matthieu@lrde.epita.fr>
Add 1d handling
* mln/convert/to_image.hh: .
* mln/core/box1d.hh: New.
* mln/core/dpoint1d.hh: New.
* mln/core/image1d_b.hh: New.
* mln/core/internal/box_impl.hh: .
* mln/core/neighb1d.hh: New.
* mln/core/pixter1d_b.hh: New.
* mln/core/point1d.hh: New.
* mln/core/w_window1d_float.hh: New.
* mln/core/w_window1d_int.hh: New.
* mln/core/win/segment1d.hh: New.
* mln/core/window1d.hh: New.
* mln/geom/max_ind.hh: New.
* mln/geom/min_ind.hh: New.
* mln/geom/ninds.hh: New.
* mln/geom/size1d.hh: New.
* mln/make/box1d.hh: New.
* mln/make/dpoint1d.hh: New.
* mln/make/point1d.hh: New.
* mln/make/w_window1d.hh: New.
* mln/make/w_window1d_int.hh: New.
* mln/make/window1d.hh: New.
* sandbox/garrigues/TODO: New.
* tests/box1d.cc: New.
* tests/dpoint1d.cc: New.
* tests/image1d_b.cc: New.
* tests/pixter1d_b.cc: New.
* tests/point1d.cc: New.
* tests/w_window1d_int.cc: New.
* tests/window1d.cc: New.
2007-09-05 Simon Nivault <simon.nivault@lrde.epita.fr>
Fast gaussian works on 2d images
......
......@@ -55,26 +55,32 @@ namespace mln
// FIXME: Move elsewhere.
namespace internal
{
template <typename T>
struct helper_dim_
{
typedef mln_point(T) P;
enum { value = P::dim };
};
template <unsigned dim, typename V> struct helper_image_from_;
template <typename V>
struct helper_image_from_< 2, V >
{
typedef image2d_b<V> ret;
};
template <typename V>
struct helper_image_from_< 1, V >
{
typedef image1d_b<V> ret;
};
} // end of namespace mln::internal
// FIXME: Doc + move elsewhere!
// FIXME: Doc + move elsewhere!
template <typename T, typename V>
struct image_from_
{
......
// Copyright (C) 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 MLN_CORE_BOX1D_HH
# define MLN_CORE_BOX1D_HH
/*! \file mln/core/box1d.hh
*
* \brief Definition of the mln::box1d alias and of construction
* routines.
*/
# include <mln/core/box.hh>
# include <mln/core/point1d.hh>
namespace mln
{
/*! \brief Type alias for a box defined on the 1D square grid with
* integer coordinates.
*
* \see mln::win::rectangle1d.
*/
typedef box_<point1d> box1d;
} // end of namespace mln
# include <mln/make/box1d.hh>
#endif // ! MLN_CORE_BOX1D_HH
// Copyright (C) 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 MLN_CORE_DPOINT1D_HH
# define MLN_CORE_DPOINT1D_HH
/*! \file mln/core/dpoint1d.hh
*
* \brief Definition of the mln::dpoint1d alias and of its
* construction routine.
*/
# include <mln/core/dpoint.hh>
namespace mln
{
/*! \brief Type alias for a delta-point defined on the 1D square
* grid with integer coordinates.
*/
typedef dpoint_<1,int> dpoint1d;
} // end of namespace mln
# include <mln/make/dpoint1d.hh>
# include <mln/core/point1d.hh>
namespace mln
{
// FIXME: Doc!
const dpoint1d prev = make::dpoint1d( -1 );
const dpoint1d next = make::dpoint1d( +1 );
} // end of namespace mln
#endif // ! MLN_CORE_DPOINT1D_HH
// Copyright (C) 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 MLN_CORE_IMAGE1D_B_HH
# define MLN_CORE_IMAGE1D_B_HH
/*! \file mln/core/image1d_b.hh
*
* \brief Definition of the basic mln::image1d_b class.
*/
# include <mln/core/internal/image_base.hh>
# include <mln/core/box1d.hh>
# include <mln/border/thickness.hh>
# include <mln/value/set.hh>
# include <mln/fun/i2v/all.hh>
// FIXME:
// # include <mln/core/pixter1d_b.hh>
// # include <mln/core/dpoints_pixter.hh>
namespace mln
{
// Fwd decl.
template <typename T> struct image1d_b;
namespace trait
{
template <typename T>
struct is_fast< image1d_b<T> >
{
typedef metal::true_ ret;
};
} // end of mln::trait
/*! \brief Basic 1D image class.
*
* The parameter \c T is the type of pixel values. This image class
* stores data in memory and has a virtual border with constant
* thickness around data.
*/
template <typename T>
struct image1d_b : public internal::image_base_< box1d, image1d_b<T> >
{
// Warning: just to make effective types appear in Doxygen:
typedef box1d pset;
typedef point1d psite;
typedef point1d point;
typedef dpoint1d dpoint;
typedef mln_fwd_piter(box1d) fwd_piter;
typedef mln_bkd_piter(box1d) bkd_piter;
// End of warning.
/// Value associated type.
typedef T value;
/// Return type of read-only access.
typedef const T& rvalue;
/// Return type of read-write access.
typedef T& lvalue;
/// Change value type.
template <typename U>
struct change_value
{
typedef image1d_b<U> ret;
};
/// Value_Set associated type.
typedef mln::value::set<T> vset;
/// Constructor without argument.
image1d_b();
/// Constructor with the numbers of indexes and the
/// border thickness.
image1d_b(int ninds, unsigned bdr = border::thickness);
/// Constructor with a box and the border thickness (default is
/// 3).
image1d_b(const box1d& b, unsigned bdr = border::thickness);
/// Copy constructor.
image1d_b(const image1d_b<T>& rhs);
/// Assignment operator.
image1d_b& operator=(const image1d_b<T>& rhs);
/// Destructor.
~image1d_b();
/// Initialize an empty image.
void init_with(int ninds, unsigned bdr = border::thickness);
/// Initialize an empty image.
void init_with(const box1d& b, unsigned bdr = border::thickness);
/// Test if \p p is valid.
bool owns_(const point1d& p) const;
/// Test if this image has been initialized.
bool has_data() const;
/// Give the set of values of the image.
const vset& values() const;
/// Give the definition domain.
const box1d& domain() const;
/// Give the border thickness.
unsigned border() const;
/// Give the number of cells (points including border ones).
std::size_t ncells() const;
/// Read-only access to the image value located at point \p p.
const T& operator()(const point1d& p) const;
/// Read-write access to the image value located at point \p p.
T& operator()(const point1d& p);
/// Read-only access to the image value located at offset \p o.
const T& operator[](unsigned o) const;
/// Read-write access to the image value located at offset \p o.
T& operator[](unsigned o);
/// Read-only access to the image value located at (\p ind).
const T& at(int ind) const;
/// Read-write access to the image value located at (\p ind).
T& at(int ind);
/// Fast Image method
/// Give the offset corresponding to the delta-point \p dp.
int offset(const dpoint1d& dp) const;
/// Give the point corresponding to the offset \p o.
point1d point_at_offset(unsigned o) const;
/// Give a hook to the value buffer.
const T* buffer() const;
/// Give a hook to the value buffer.
T* buffer();
private:
T* buffer_;
box1d b_; // theoretical box
unsigned bdr_;
box1d vb_; // virtual box, i.e., box including the virtual border
void update_vb_();
void allocate_();
void deallocate_();
typedef internal::image_base_< box1d, image1d_b<T> > super;
};
# ifndef MLN_INCLUDE_ONLY
// ctors
template <typename T>
image1d_b<T>::image1d_b()
: buffer_(0)
{
bdr_ = border::thickness; // default value in ctors.
}
template <typename T>
image1d_b<T>::image1d_b(int ninds, unsigned bdr)
: buffer_(0)
{
init_with(ninds, bdr);
}
template <typename T>
void
image1d_b<T>::init_with(int ninds, unsigned bdr)
{
mln_precondition(! this->has_data());
b_ = make::box1d(ninds);
bdr_ = bdr;
allocate_();
}
template <typename T>
image1d_b<T>::image1d_b(const box1d& b, unsigned bdr)
: buffer_(0)
{
init_with(b, bdr);
}
template <typename T>
void
image1d_b<T>::init_with(const box1d& b, unsigned bdr)
{
mln_precondition(! this->has_data());
b_ = b;
bdr_ = bdr;
allocate_();
}
template <typename T>
image1d_b<T>::image1d_b(const image1d_b<T>& rhs)
: super(rhs),
b_(rhs.domain()),
bdr_(rhs.border())
{
allocate_();
std::memcpy(this->buffer_,
rhs.buffer_,
ncells() * sizeof(T));
}
// assignment
template <typename T>
image1d_b<T>&
image1d_b<T>::operator=(const image1d_b<T>& rhs)
{
mln_precondition(rhs.has_data());
if (& rhs == this)
return *this;
if (this->has_data())
this->deallocate_();
this->b_ = rhs.domain();
this->bdr_ = rhs.border();
allocate_();
std::memcpy(this->buffer_,
rhs.buffer_,
ncells() * sizeof(T));
return *this;
}
// methods
template <typename T>
bool
image1d_b<T>::has_data() const
{
return buffer_ != 0;
}
template <typename T>
const typename image1d_b<T>::vset&
image1d_b<T>::values() const
{
return vset::the();
}
template <typename T>
const box1d&
image1d_b<T>::domain() const
{
mln_precondition(this->has_data());
return b_;
}
template <typename T>
unsigned
image1d_b<T>::border() const
{
mln_precondition(this->has_data());
return bdr_;
}
template <typename T>
std::size_t
image1d_b<T>::ncells() const
{
mln_precondition(this->has_data());
return vb_.npoints();
}
template <typename T>
bool
image1d_b<T>::owns_(const point1d& p) const
{
mln_precondition(this->has_data());
return vb_.has(p);
}
template <typename T>
const T&
image1d_b<T>::operator()(const point1d& p) const
{
mln_precondition(this->owns_(p));
return buffer_[p.ind()];
}
template <typename T>
T&
image1d_b<T>::operator()(const point1d& p)
{
mln_precondition(this->owns_(p));
return buffer_[p.ind()];
}
template <typename T>
const T&
image1d_b<T>::operator[](unsigned o) const
{
mln_precondition(o < ncells());
return *(buffer_ + o);
}
template <typename T>
T&
image1d_b<T>::operator[](unsigned o)
{
mln_precondition(o < ncells());
return *(buffer_ + o);
}
template <typename T>
const T&
image1d_b<T>::at(int ind) const
{
mln_precondition(this->owns_(make::point1d(ind)));
return buffer_[ind];
}
template <typename T>
T&
image1d_b<T>::at(int ind)
{
mln_precondition(this->owns_(make::point1d(ind)));
return buffer_[ind];
}
template <typename T>
image1d_b<T>::~image1d_b()
{
deallocate_();
}
template <typename T>
const T*
image1d_b<T>::buffer() const
{
mln_precondition(this->has_data());
return buffer_;
}
template <typename T>
T*
image1d_b<T>::buffer()
{
mln_precondition(this->has_data());
return buffer_;
}
template <typename T>
int
image1d_b<T>::offset(const dpoint1d& dp) const
{
mln_precondition(this->has_data());
int o = dp[0];
return o;
}
template <typename T>
point1d
image1d_b<T>::point_at_offset(unsigned o) const
{
mln_precondition(o < ncells());
point1d p = make::point1d(o);
mln_postcondition(& this->operator()(p) == this->buffer_ + o);
return p;
}
// private
template <typename T>
void
image1d_b<T>::update_vb_()
{
vb_.pmin() = b_.pmin() - dpoint1d(all(bdr_));
vb_.pmax() = b_.