Commit 5f36dc6d authored by Nicolas Ballas's avatar Nicolas Ballas
Browse files

Parametrize histo::data by value types, Repair image1d.

	* tests/core/other/pixter1d.cc,
	* tests/core/image/image1d.cc: Replace npoints method by nsites.
	* mln/histo/compute.spe.hh,
	* mln/histo/compute.hh,
	* tests/histo/compute.cc,
	* tests/histo/to_image1d.cc: Change the histo::data parameter
	* mln/histo/data.hh: Update data parameter.
	* mln/core/site_set/p_line_graph_piter.hh: Fix compile errors.
	* mln/core/image/image1d.hh: Repair image1d.
	* mln/core/image/image3d.hh: Fix compile errors.
	* mln/core/internal/check/image_fastest.hh: .
	* mln/core/alias/dpoint1d.hh,
	* mln/core/alias/dpoint3d.hh: Fix the dpoints coordinates type.
	* mln/core/alias/point1d.hh,
	* mln/core/alias/point3d.hh: Add specialization for subject_impl.
	* mln/core/alias/point2d.hh: delete trailing whitespaces.
	* mln/pw/image.hh,
	* mln/value/stack.hh: Remove the values method.
	* mln/convert/to_image.hh,
	* mln/morpho/erosion.hh: Adapt to the histo::data changes.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008@2209 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 1eb0adad
2008-09-10 Nicolas Ballas <ballas@lrde.epita.fr>
Parametrize histo::data by value types, Repair image1d.
* tests/core/other/pixter1d.cc,
* tests/core/image/image1d.cc: Replace npoints method by nsites.
* mln/histo/compute.spe.hh,
* mln/histo/compute.hh,
* tests/histo/compute.cc,
* tests/histo/to_image1d.cc: Change the histo::data parameter
* mln/histo/data.hh: Update data parameter.
* mln/core/site_set/p_line_graph_piter.hh: Fix compile errors.
* mln/core/image/image1d.hh: Repair image1d.
* mln/core/image/image3d.hh: Fix compile errors.
* mln/core/internal/check/image_fastest.hh: .
* mln/core/alias/dpoint1d.hh,
* mln/core/alias/dpoint3d.hh: Fix the dpoints coordinates type.
* mln/core/alias/point1d.hh,
* mln/core/alias/point3d.hh: Add specialization for subject_impl.
* mln/core/alias/point2d.hh: delete trailing whitespaces.
* mln/pw/image.hh,
* mln/value/stack.hh: Remove the values method.
* mln/convert/to_image.hh,
* mln/morpho/erosion.hh: Adapt to the histo::data changes.
2008-09-10 Ugo Jardonnet <ugo.jardonnet@lrde.epita.fr>
 
Update rotation.
......
......@@ -187,11 +187,11 @@ namespace mln
return ima;
}
template <typename S>
template <typename T>
inline
image1d<std::size_t> to_image(const histo::data<S>& h)
image1d<std::size_t> to_image(const histo::data<T>& h)
{
mln_value(S)
mln_value(histo::data<T>)
v_min = h.vset()[0],
v_max = h.vset()[h.vset().nvalues() - 1];
image1d<std::size_t> ima(make::box1d(v_min, v_max));
......
......@@ -36,6 +36,7 @@
# include <mln/core/dpoint.hh>
# include <mln/core/grids.hh>
# include <mln/core/def/coord.hh>
namespace mln
......@@ -44,7 +45,7 @@ namespace mln
/*! \brief Type alias for a delta-point defined on the 1D square
* grid with integer coordinates.
*/
typedef dpoint<mln::grid::tick, int> dpoint1d;
typedef dpoint<mln::grid::tick, def::coord> dpoint1d;
} // end of namespace mln
......
......@@ -36,7 +36,7 @@
# include <mln/core/dpoint.hh>
# include <mln/core/grids.hh>
# include <mln/core/def/coord.hh>
namespace mln
{
......@@ -44,7 +44,7 @@ namespace mln
/*! \brief Type alias for a delta-point defined on the 3D square
* grid with integer coordinates.
*/
typedef dpoint<mln::grid::cube, int> dpoint3d;
typedef dpoint<mln::grid::cube, def::coord> dpoint3d;
} // end of namespace mln
......
......@@ -35,7 +35,9 @@
*/
# include <mln/core/point.hh>
// For site_const_impl and site_mutable_impl.
# include <mln/core/concept/site_proxy.hh>
# include <mln/core/internal/force_exact.hh>
namespace mln
{
......@@ -45,6 +47,97 @@ namespace mln
*/
typedef point<grid::tick, def::coord> point1d;
namespace internal
{
// Specialization.
template <typename C, typename E>
struct subject_impl< const point<grid::tick, C>, E >
{
typedef C coord;
enum { dim = 1 };
typedef const C& row_t;
const C& row() const;
const C& operator[](unsigned i) const;
const C& last_coord() const;
private:
const E& exact_() const;
};
// Specialization for point<M,C>.
template <typename C, typename E>
struct subject_impl< point<grid::tick, C>, E > :
subject_impl< const point<grid::tick, C>, E >
{
private:
typedef subject_impl< const point<grid::tick, C>, E > super_;
E& exact_();
public:
using super_::row;
C& row();
using super_::operator[];
C& operator[](unsigned i);
};
# ifndef MLN_INCLUDE_ONLY
// subject_impl
template <typename C, typename E>
inline
const C&
subject_impl< const point<grid::tick, C>, E >::row() const
{
return exact_().get_subject().row();
}
template <typename C, typename E>
inline
const C&
subject_impl< const point<grid::tick, C>, E >::operator[](unsigned i) const
{
mln_precondition(i < 1);
return exact_().get_subject()[i];
}
template <typename C, typename E>
inline
const E&
subject_impl< const point<grid::tick, C>, E >::exact_() const
{
return internal::force_exact<const E>(*this);
}
// subject_impl
template <typename C, typename E>
inline
C&
subject_impl< point<grid::tick, C>, E >::row()
{
return exact_().get_subject().row();
}
template <typename C, typename E>
inline
C&
subject_impl< point<grid::tick, C>, E >::operator[](unsigned i)
{
mln_precondition(i < 2);
return exact_().get_subject()[i];
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::internal
} // end of namespace mln
......
......@@ -163,7 +163,7 @@ namespace mln
mln_precondition(i < 2);
return exact_().get_subject()[i];
}
template <typename C, typename E>
inline
E&
......@@ -175,7 +175,7 @@ namespace mln
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::internal
} // end of namespace mln
......
......@@ -35,7 +35,9 @@
*/
# include <mln/core/point.hh>
// For site_const_impl and site_mutable_impl:
# include <mln/core/concept/site_proxy.hh>
# include <mln/core/internal/force_exact.hh>
namespace mln
{
......@@ -45,6 +47,159 @@ namespace mln
*/
typedef point<grid::cube, def::coord> point3d;
namespace internal
{
// Specialization.
template <typename C, typename E>
struct subject_impl< const point<grid::cube, C>, E >
{
typedef C coord;
enum { dim = 3 };
typedef const C& row_t;
const C& row() const;
typedef const C& col_t;
const C& col() const;
typedef const C& sli_t;
const C& sli() const;
const C& operator[](unsigned i) const;
const C& last_coord() const;
private:
const E& exact_() const;
};
// Specialization for point<M,C>.
template <typename C, typename E>
struct subject_impl< point<grid::cube, C>, E > :
subject_impl< const point<grid::cube, C>, E >
{
private:
typedef subject_impl< const point<grid::cube, C>, E > super_;
E& exact_();
public:
using super_::row;
C& row();
using super_::col;
C& col();
using super_::sli;
C& sli();
using super_::operator[];
C& operator[](unsigned i);
};
# ifndef MLN_INCLUDE_ONLY
// subject_impl
template <typename C, typename E>
inline
const C&
subject_impl< const point<grid::cube, C>, E >::row() const
{
return exact_().get_subject().row();
}
template <typename C, typename E>
inline
const C&
subject_impl< const point<grid::cube, C>, E >::col() const
{
return exact_().get_subject().col();
}
template <typename C, typename E>
inline
const C&
subject_impl< const point<grid::cube, C>, E >::sli() const
{
return exact_().get_subject().sli();
}
template <typename C, typename E>
inline
const C&
subject_impl< const point<grid::cube, C>, E >::operator[](unsigned i) const
{
mln_precondition(i < 3);
return exact_().get_subject()[i];
}
template <typename C, typename E>
inline
const C&
subject_impl< const point<grid::cube, C>, E >::last_coord() const
{
return this->col();
}
template <typename C, typename E>
inline
const E&
subject_impl< const point<grid::cube, C>, E >::exact_() const
{
return internal::force_exact<const E>(*this);
}
// subject_impl
template <typename C, typename E>
inline
C&
subject_impl< point<grid::cube, C>, E >::row()
{
return exact_().get_subject().row();
}
template <typename C, typename E>
inline
C&
subject_impl< point<grid::cube, C>, E >::col()
{
return exact_().get_subject().col();
}
template <typename C, typename E>
inline
C&
subject_impl< point<grid::cube, C>, E >::sli()
{
return exact_().get_subject().sli();
}
template <typename C, typename E>
inline
C&
subject_impl< point<grid::cube, C>, E >::operator[](unsigned i)
{
mln_precondition(i < 3);
return exact_().get_subject()[i];
}
template <typename C, typename E>
inline
E&
subject_impl< point<grid::cube, C>, E >::exact_()
{
return internal::force_exact<E>(*this);
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::internal
} // end of namespace mln
......
......@@ -124,10 +124,10 @@ namespace mln
public internal::image_primary< T, box1d, image1d<T> >
{
typedef internal::image_primary< T, mln::box1d, image1d<T> > super_;
/// Coordinate associated type.
typedef int coord;
/// Value associated type.
typedef T value;
......@@ -169,9 +169,6 @@ namespace mln
/// 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;
......@@ -179,16 +176,10 @@ namespace mln
T& operator()(const point1d& p);
/// Read-only access to the image value located at offset \p o.
const T& operator[](unsigned o) const;
const T& operator[](unsigned i) 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);
T& operator[](unsigned i);
/// Fast Image method
......@@ -197,10 +188,10 @@ namespace mln
using super_::index_of_point;
/// Give the offset corresponding to the delta-point \p dp.
int offset(const dpoint1d& dp) const;
int delta_index(const dpoint1d& dp) const;
/// Give the point corresponding to the offset \p o.
point1d point_at_offset(unsigned o) const;
point1d point_at_index(unsigned i) const;
/// Give a hook to the value buffer.
const T* buffer() const;
......@@ -208,6 +199,16 @@ namespace mln
/// Give a hook to the value buffer.
T* buffer();
/// Read-only access to the image value located at (\p ind).
const T& element(unsigned ind) const;
/// Read-write access to the image value located at (\p ind).
T& element(unsigned ind);
/// Give the number of cells (points including border ones).
std::size_t nelements() const;
/// Resize image border with new_border.
void resize_(unsigned new_border);
......@@ -358,7 +359,7 @@ namespace mln
image1d<T>::domain() const
{
mln_precondition(this->has_data());
return this->data->b_;
return this->data_->b_;
}
template <typename T>
......@@ -367,7 +368,7 @@ namespace mln
image1d<T>::bbox() const
{
mln_precondition(this->has_data());
return this->data->b_;
return this->data_->b_;
}
template <typename T>
......@@ -376,16 +377,16 @@ namespace mln
image1d<T>::border() const
{
mln_precondition(this->has_data());
return this->data->bdr_;
return this->data_->bdr_;
}
template <typename T>
inline
std::size_t
image1d<T>::ncells() const
image1d<T>::nelements() const
{
mln_precondition(this->has_data());
return this->data->vb_.npoints();
return this->data_->vb_.nsites();
}
template <typename T>
......@@ -394,7 +395,7 @@ namespace mln
image1d<T>::has(const point1d& p) const
{
mln_precondition(this->has_data());
return this->data->vb_.has(p);
return this->data_->vb_.has(p);
}
template <typename T>
......@@ -403,7 +404,7 @@ namespace mln
image1d<T>::operator()(const point1d& p) const
{
mln_precondition(this->has(p));
return this->data->array_[p.ind()];
return this->data_->array_[p.ind()];
}
template <typename T>
......@@ -412,7 +413,7 @@ namespace mln
image1d<T>::operator()(const point1d& p)
{
mln_precondition(this->has(p));
return this->data->array_[p.ind()];
return this->data_->array_[p.ind()];
}
template <typename T>
......@@ -420,8 +421,8 @@ namespace mln
const T&
image1d<T>::operator[](unsigned o) const
{
mln_precondition(o < ncells());
return *(this->data->buffer_ + o);
mln_precondition(o < nelements());
return *(this->data_->buffer_ + o);
}
template <typename T>
......@@ -429,26 +430,26 @@ namespace mln
T&
image1d<T>::operator[](unsigned o)
{
mln_precondition(o < ncells());
return *(this->data->buffer_ + o);
mln_precondition(o < nelements());
return *(this->data_->buffer_ + o);
}
template <typename T>
inline
const T&
image1d<T>::at(int ind) const
image1d<T>::element(unsigned ind) const
{
mln_precondition(this->has(make::point1d(ind)));
return this->data->array_[ind];
return this->data_->array_[ind];
}
template <typename T>
inline
T&
image1d<T>::at(int ind)
image1d<T>::element(unsigned ind)
{
mln_precondition(this->has(make::point1d(ind)));
return this->data->array_[ind];
return this->data_->array_[ind];
}
template <typename T>
......@@ -457,7 +458,7 @@ namespace mln
image1d<T>::buffer() const
{
mln_precondition(this->has_data());
return this->data->buffer_;
return this->data_->buffer_;
}
template <typename T>
......@@ -466,13 +467,13 @@ namespace mln
image1d<T>::buffer()
{
mln_precondition(this->has_data());
return this->data->buffer_;
return this->data_->buffer_;
}
template <typename T>
inline
int
image1d<T>::offset(const dpoint1d& dp) const
image1d<T>::delta_index(const dpoint1d& dp) const
{
mln_precondition(this->has_data());
int o = dp[0];
......@@ -482,11 +483,11 @@ namespace mln
template <typename T>
inline
point1d
image1d<T>::point_at_offset(unsigned o) const
image1d<T>::point_at_index(unsigned i) const
{
mln_precondition(o < ncells());
point1d p = make::point1d(o + this->data->vb_.min_ind());
mln_postcondition(& this->operator()(p) == this->data->buffer_ + o);
mln_precondition(i < nelements());
point1d p = make::point1d(i + this->data_->vb_.min_ind());
mln_postcondition(& this->operator()(p) == this->data_->buffer_ + i);
return p;
}
......@@ -495,7 +496,7 @@ namespace mln
void
image1d<T>::resize_(unsigned new_border)
{
this->data->reallocate_(new_border);
this->data_->reallocate_(new_border);
}
# endif // ! MLN_INCLUDE_ONLY
......
......@@ -89,17 +89,25 @@ namespace mln
template <typename T>
struct image_< image3d<T> > : default_image_< T, image3d<T> >
{
// misc
typedef trait::image::category::primary category;
typedef trait::image::access::random access;
typedef trait::image::space::three_d space;
typedef trait::image::size::regular size;
typedef trait::image::support::aligned support;
typedef trait::image::border::stored border;
typedef trait::image::data::raw data;
typedef trait::image::io::read_write io;
typedef trait::image::speed::fastest speed;