Commit 6e097db2 authored by Thierry Geraud's avatar Thierry Geraud
Browse files

Add 3D, remove some fixmes, and make various cleanups.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@944 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 2527f0b9
2007-04-12 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Add 3D, remove some fixmes, and make various cleanups.
2007-04-12 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Add ''theoretical bounding box'' for point set types.
......
// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 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_BASICS3D_HH
# define OLN_BASICS3D_HH
# define OLN_ENV_3D
# include <oln/core/typedefs.hh>
# include <oln/core/case.hh>
# include <oln/core/traits.hh>
# include <oln/value/proxy.hh>
# include <oln/core/3d/aliases.hh>
# include <oln/core/gen/grid.hh>
# include <oln/core/3d/point3d.hh>
# include <oln/core/3d/dpoint3d.hh>
# include <oln/core/3d/topo3d.hh>
# include <oln/core/gen/fwd_piter_bbox.hh>
# include <oln/core/gen/bkd_piter_bbox.hh>
# include <oln/core/3d/window3d.hh>
# include <oln/core/gen/fwd_qiter_win.hh>
# include <oln/core/gen/bkd_qiter_win.hh>
# include <oln/core/gen/neighb.hh>
# include <oln/core/3d/neighb3d.hh>
# include <oln/core/3d/image3d.hh>
# include <oln/core/iterator_vtypes.hh>
# include <oln/core/spe/slice.hh>
# include <oln/core/spe/row.hh>
# include <oln/core/spe/col.hh>
#endif // ! OLN_BASICS3D_HH
......@@ -105,7 +105,7 @@ namespace oln
len_(len)
{
precondition(len > 0);
imax_ = imin_ + len_;
imax_ = imin_ + len_ - 1;
allocate_();
}
......@@ -192,7 +192,6 @@ namespace oln
# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
......
......@@ -28,8 +28,8 @@
#ifndef OLN_CORE_1D_BOX1D_HH
# define OLN_CORE_1D_BOX1D_HH
# include <oln/core/gen/box.hh>
# include <oln/core/1d/point1d.hh>
# include <oln/core/internal/box.hh>
namespace oln
......@@ -58,11 +58,10 @@ namespace oln
{
typedef internal::box_< box1d > super;
public:
// Note: we can't use stc_using because box1d isn't a templated class
typedef super::point point;
stc_using_(from_to_t);
box1d();
box1d(const box1d::from_to_t& dat);
box1d(const from_to_t& dat);
box1d(const point1d& pmin, const point1d& pmax);
template <typename D>
box1d(const internal::initializer_<D>& data);
......
......@@ -30,26 +30,27 @@
# define OLN_CORE_1D_DPOINT1D_HH
# include <oln/core/1d/grid1d.hh>
# include <oln/core/internal/dpoint1d.hh>
# include <oln/core/internal/dpoint_base.hh>
# include <oln/core/internal/point_impl.hh>
namespace oln
{
// Fwd decls.
struct point1d;
struct dpoint1d;
/// Super type.
// Super type.
template<>
struct super_trait_< dpoint1d >
{
typedef internal::dpoint1d_< dpoint1d > ret;
typedef internal::dpoint_base_< dpoint1d > ret;
};
/// Virtual types.
// Virtual types.
template <>
struct vtypes< dpoint1d >
{
......@@ -60,10 +61,12 @@ namespace oln
/// Usual 1D dpoint class.
class dpoint1d : public internal::dpoint1d_< dpoint1d >
class dpoint1d : public internal::dpoint_base_< dpoint1d >,
public internal::point_impl_< 1, dpoint1d >
{
typedef internal::dpoint_base_< dpoint1d > super;
public:
/// Ctors.
stc_using_(coord);
dpoint1d();
dpoint1d(int ind);
};
......@@ -81,13 +84,11 @@ namespace oln
this->ind() = ind;
}
# endif
# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
// dpoint1d goes with point1d so:
# include <oln/core/1d/point1d.hh>
......
......@@ -29,10 +29,10 @@
#ifndef OLN_CORE_1D_IMAGE1D_HH
# define OLN_CORE_1D_IMAGE1D_HH
# include <oln/core/1d/box1d.hh>
# include <oln/core/internal/image_base.hh>
# include <oln/core/internal/utils.hh>
# include <oln/core/1d/array1d.hh>
# include <oln/core/1d/box1d.hh>
namespace oln
......
......@@ -28,20 +28,15 @@
#ifndef OLN_CORE_1D_IMAGE1D_B_HH
# define OLN_CORE_1D_IMAGE1D_B_HH
# include <oln/core/1d/box1d.hh>
# include <oln/core/internal/image_base.hh>
# include <oln/core/internal/utils.hh>
# include <oln/core/1d/array1d.hh>
# include <oln/core/1d/box1d.hh>
namespace oln
{
// FIXME: Conversely to image2d_b, we use here the triplet class
// instead of the array_b_ class.
// Fwd decl.
template <typename T> class image1d_b;
......
......@@ -30,26 +30,27 @@
# define OLN_CORE_1D_POINT1D_HH
# include <oln/core/1d/grid1d.hh>
# include <oln/core/internal/point1d.hh>
# include <oln/core/internal/point_base.hh>
# include <oln/core/internal/point_impl.hh>
namespace oln
{
// Fwd decls.
class point1d;
class dpoint1d;
/// Super type.
// Super type.
template<>
struct super_trait_< point1d >
{
typedef internal::point1d_< point1d > ret;
typedef internal::point_base_< point1d > ret;
};
/// Virtual types.
// Virtual types.
template <>
struct vtypes< point1d >
{
......@@ -60,10 +61,13 @@ namespace oln
/// Usual 1D point class.
class point1d : public internal::point1d_< point1d >
class point1d : public internal::point_base_< point1d >,
public internal::point_impl_< 1, point1d >
{
typedef internal::point_base_< point1d > super;
public:
/// Ctors.
stc_using_(coord);
point1d();
point1d(int ind);
};
......@@ -81,13 +85,11 @@ namespace oln
this->ind() = ind;
}
# endif
# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
// point1d goes with dpoint1d so:
# include <oln/core/1d/dpoint1d.hh>
......
......@@ -79,11 +79,7 @@ namespace oln
const T* buffer() const;
T* buffer();
std::size_t row_pad() const
{
precondition(buffer_ != 0 and array_ != 0);
return &(array_[imin_+1][jmin_]) - &(array_[imin_][jmin_]);
}
std::size_t i_pad() const;
protected:
......@@ -105,10 +101,8 @@ namespace oln
template <typename T, typename C>
array2d_<T, C>::array2d_(C imin, C jmin, C imax, C jmax) :
imin_(imin),
jmin_(jmin),
imax_(imax),
jmax_(jmax)
imin_(imin), jmin_(jmin),
imax_(imax), jmax_(jmax)
{
precondition(imax >= imin and jmax >= jmin);
ilen_ = imax - imin + 1;
......@@ -119,15 +113,13 @@ namespace oln
template <typename T, typename C>
array2d_<T, C>::array2d_(C ilen, C jlen) :
imin_(0),
jmin_(0),
ilen_(ilen),
jlen_(jlen)
imin_(0), jmin_(0),
ilen_(ilen), jlen_(jlen)
{
precondition(ilen > 0 and jlen > 0);
// FIXME: Test that ilen_ and jlen_ are not huge!
imax_ = imin_ + ilen_;
jmax_ = jmin_ + ilen_;
imax_ = imin_ + ilen_ - 1;
jmax_ = jmin_ + ilen_ - 1;
allocate_();
}
......@@ -175,7 +167,6 @@ namespace oln
j >= jmin_ and j <= jmax_;
}
template <typename T, typename C>
C array2d_<T, C>::imin() const
{
......@@ -212,6 +203,13 @@ namespace oln
return buffer_;
}
template <typename T, typename C>
std::size_t array2d_<T, C>::i_pad() const
{
precondition(buffer_ != 0 and array_ != 0);
return jlen_;
}
template <typename T, typename C>
std::size_t array2d_<T, C>::ncells() const
{
......@@ -234,7 +232,7 @@ namespace oln
{
blen_ = std::size_t(ilen_) * std::size_t(jlen_);
buffer_ = new T[blen_];
array_ = new T*[std::size_t(ilen_)];
array_ = new T*[std::size_t(ilen_)];
T* buf = buffer_ - jmin_;
for (C i = 0; i < ilen_; ++i)
{
......@@ -255,8 +253,7 @@ namespace oln
array_ = 0; // safety
}
# endif
# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
......
......@@ -28,8 +28,8 @@
#ifndef OLN_CORE_2D_BOX2D_HH
# define OLN_CORE_2D_BOX2D_HH
# include <oln/core/concept/point_set.hh> // for internal::tag::box_t
# include <oln/core/2d/point2d.hh>
# include <oln/core/concept/point_set.hh> // for internal::tag::i_box_t
# include <oln/core/internal/box.hh>
......@@ -59,12 +59,10 @@ namespace oln
{
typedef internal::box_< box2d > super;
public:
// Note: we can't use stc_using because box2d isn't a templated class
typedef super::point point;
typedef super::from_to_t from_to_t;
stc_using_(from_to_t);
box2d();
box2d(const box2d::from_to_t& dat);
box2d(const from_to_t& dat);
box2d(const point2d& pmin, const point2d& pmax);
template <typename D>
box2d(const internal::initializer_<D>& data);
......@@ -74,11 +72,11 @@ namespace oln
{
template <typename U>
bool init__(tag::box_t, box2d& b,
bool init__(tag::i_box_t, box2d& b,
const pair< nrows_t<U>, ncols_t<U> >& data);
template <typename U>
bool init__(tag::box_t, box2d& b,
bool init__(tag::i_box_t, box2d& b,
const triplet< from_t<point2d>, nrows_t<U>, ncols_t<U> >& data);
} // end of namespace oln::internal
......@@ -103,7 +101,7 @@ namespace oln
template <typename D>
box2d::box2d(const internal::initializer_<D>& data)
{
bool box_ok = internal::init__(internal::tag::box_t(), *this, data.value());
bool box_ok = internal::init__(internal::tag::i_box_t(), *this, data.value());
postcondition(box_ok);
}
......@@ -112,7 +110,7 @@ namespace oln
{
template <typename U>
bool init__(tag::box_t, box2d& b,
bool init__(tag::i_box_t, box2d& b,
const pair< nrows_t<U>, ncols_t<U> >& data)
{
unsigned nrows = data.first.value;
......@@ -126,7 +124,7 @@ namespace oln
}
template <typename U>
bool init__(tag::box_t, box2d& b,
bool init__(tag::i_box_t, box2d& b,
const triplet< from_t<point2d>, nrows_t<U>, ncols_t<U> >& data)
{
unsigned nrows = data.second.value;
......
......@@ -30,26 +30,27 @@
# define OLN_CORE_2D_DPOINT2D_HH
# include <oln/core/2d/grid2d.hh>
# include <oln/core/internal/dpoint2d.hh>
# include <oln/core/internal/dpoint_base.hh>
# include <oln/core/internal/point_impl.hh>
namespace oln
{
// Fwd decls.
struct point2d;
struct dpoint2d;
/// Super type.
// Super type.
template<>
struct super_trait_< dpoint2d >
{
typedef internal::dpoint2d_< dpoint2d > ret;
typedef internal::dpoint_base_< dpoint2d > ret;
};
/// Virtual types.
// Virtual types.
template <>
struct vtypes< dpoint2d >
{
......@@ -60,9 +61,14 @@ namespace oln
/// Usual 2D dpoint class.
class dpoint2d : public internal::dpoint2d_< dpoint2d >
class dpoint2d : public internal::dpoint_base_< dpoint2d >,
public internal::point_impl_< 2, dpoint2d >
{
typedef internal::dpoint_base_< dpoint2d > super;
public:
stc_using_(coord);
/// Ctors.
dpoint2d();
dpoint2d(int row, int col);
......@@ -82,13 +88,11 @@ namespace oln
this->col() = col;
}
# endif
# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
// dpoint2d goes with point2d so:
# include <oln/core/2d/point2d.hh>
......
......@@ -29,10 +29,10 @@
#ifndef OLN_CORE_2D_IMAGE2D_HH
# define OLN_CORE_2D_IMAGE2D_HH
# include <oln/core/2d/box2d.hh>
# include <oln/core/internal/image_base.hh>
# include <oln/core/internal/utils.hh>
# include <oln/core/2d/array2d.hh>
# include <oln/core/2d/box2d.hh>
namespace oln
......@@ -42,7 +42,7 @@ namespace oln
template <typename T> class image2d;
/// Virtual types.
// Virtual types.
template <typename T>
struct vtypes< image2d<T> >
{
......
......@@ -29,10 +29,10 @@
#ifndef OLN_CORE_2D_IMAGE2D_B_HH
# define OLN_CORE_2D_IMAGE2D_B_HH
# include <oln/core/2d/box2d.hh>
# include <oln/core/internal/image_base.hh>
# include <oln/core/internal/utils.hh>
# include <oln/core/2d/array2d.hh>
# include <oln/core/2d/box2d.hh>
namespace oln
......@@ -43,7 +43,7 @@ namespace oln
template <typename T> class image2d_b;
/// Virtual types.
// Virtual types.
template <typename T>
struct vtypes< image2d_b<T> >
{
......@@ -68,7 +68,7 @@ namespace oln
};
/// Super type.
// Super type.
template <typename T>
struct super_trait_< image2d_b<T> >
{
......@@ -236,7 +236,7 @@ namespace oln
std::size_t image2d_b<T>::pad(const dpoint2d& dp) const
{
assert(this->has_data());
return this->data_->first.row_pad() * dp.row() + dp.col();
return this->data_->first.i_pad() * dp.row() + dp.col();
}
// template <typename T, typename D>
......@@ -269,7 +269,6 @@ namespace oln
# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
......
......@@ -96,15 +96,15 @@ namespace oln
return tmp;
}
# endif
# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln::internal
extern neighb2d c4;
extern neighb2d c8;
extern neighb2d c2r;
extern neighb2d c2c;
extern neighb2d c2_row;
extern neighb2d c2_col;
# ifndef OLN_INCLUDE_ONLY
......@@ -121,16 +121,15 @@ namespace oln
# endif // OLN_ENABLE_DEFAULT
neighb2d c4 = internal::mk_c4();
neighb2d c8 = internal::mk_c8();
neighb2d c2r = internal::mk_c2_row();
neighb2d c2c = internal::mk_c2_col();
neighb2d c4 = internal::mk_c4();
neighb2d c8 = internal::mk_c8();
# endif // OLN_INCLUDE_ONLY
neighb2d c2_row = internal::mk_c2_row();
neighb2d c2_col = internal::mk_c2_col();
# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
#endif // ! OLN_CORE_2D_NEIGHB2D_HH
......@@ -30,26 +30,27 @@
# define OLN_CORE_2D_POINT2D_HH
# include <oln/core/2d/grid2d.hh>
# include <oln/core/internal/point2d.hh>
# include <oln/core/internal/point_base.hh>
# include <oln/core/internal/point_impl.hh>
namespace oln
{
class point2d;
// Fwd decls.
class point2d;
class dpoint2d;
/// Super type.
// Super type.
template<>
struct super_trait_< point2d >
{
typedef internal::point2d_< point2d > ret;
typedef internal::point_base_< point2d > ret;
};
/// Virtual types.
// Virtual types.
template <>
struct vtypes< point2d >
{
......@@ -60,14 +61,18 @@ namespace oln
/// Usual 2D point class.
class point2d : public internal::point2d_< point2d >