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

https://svn.lrde.epita.fr/svn/oln/trunk/olena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Add 3D, remove some fixmes, and make various cleanups. oln/core/1d/array1d.hh | 3 oln/core/1d/box1d.hh | 7 oln/core/1d/dpoint1d.hh | 21 - oln/core/1d/image1d.hh | 2 oln/core/1d/image1d_b.hh | 7 oln/core/1d/point1d.hh | 22 + oln/core/2d/array2d.hh | 33 +- oln/core/2d/box2d.hh | 18 - oln/core/2d/dpoint2d.hh | 22 + oln/core/2d/image2d.hh | 4 oln/core/2d/image2d_b.hh | 9 oln/core/2d/neighb2d.hh | 13 - oln/core/2d/point2d.hh | 21 + oln/core/3d/array3d.hh | 295 +++++++++++++++++++------- oln/core/3d/box3d.hh | 154 +++++++++++++ oln/core/3d/dpoint3d.hh | 115 ++-------- oln/core/3d/grid3d.hh | 95 ++++++++ oln/core/3d/image3d.hh | 223 +++++++++++-------- oln/core/3d/image3d_b.hh | 290 +++++++++++++++++++++++++ oln/core/3d/neighb3d.hh | 276 ++++++++++-------------- oln/core/3d/point3d.hh | 133 +++-------- oln/core/3d/window3d.hh | 16 - oln/core/concept/function.hh | 4 oln/core/concept/image.hh | 90 +++++++ oln/core/concept/iterator_on_points.hh | 3 oln/core/concept/neighborhood.hh | 3 oln/core/concept/operators.hh | 18 - oln/core/concept/point.hh | 24 +- oln/core/concept/point_set.hh | 2 oln/core/concept/value.hh | 6 oln/core/gen/applied_on.hh | 134 +++++++++++ oln/core/gen/box.hh | 67 ++--- oln/core/gen/dpoint.hh | 92 ++++++++ oln/core/gen/dpoints_piter.hh | 2 oln/core/gen/extended_by.hh | 60 +++++ oln/core/gen/fbbox.hh | 5 oln/core/gen/fun.hh | 193 ++++++++++------- oln/core/gen/fun_ops.hh | 58 ----- oln/core/gen/image_stack.hh | 1 oln/core/gen/literal.hh | 157 +++++++------ oln/core/gen/neighb.hh | 15 - oln/core/gen/niter_has.hh | 2 oln/core/gen/op.hh | 92 -------- oln/core/gen/over.hh | 108 +++++++++ oln/core/gen/point.hh | 93 ++++++++ oln/core/gen/restricted_to.hh | 95 ++++++++ oln/core/gen/such_as.hh | 220 +++++++++++++++++++ oln/core/gen/through.hh | 134 +++++++++++ oln/core/gen/value_cast.hh | 61 ++--- oln/core/internal/box.hh | 8 oln/core/internal/category_of.hh | 59 ++--- oln/core/internal/f_grid_to_box.hh | 16 - oln/core/internal/f_grid_to_plain_image.hh | 13 - oln/core/internal/f_point_to_box.hh | 112 +++++++++ oln/core/internal/f_pset_to_plain_image.hh | 17 + oln/core/internal/image_base.hh | 7 oln/core/internal/iterator_on_points_base.hh | 11 oln/core/internal/iterator_on_points_impl.hh | 127 +++++------ oln/core/internal/macro_extended_by.hh | 128 +++++++++++ oln/core/internal/op_fv2v_applied_on_image.hh | 4 oln/core/internal/op_image_such_as_fp2b.hh | 7 oln/core/internal/op_image_through_fv2v.hh | 2 oln/core/internal/point_base.hh | 4 oln/core/internal/point_impl.hh | 199 +++++++++++++++++ oln/core/internal/point_set_base.hh | 63 ----- oln/core/internal/point_set_std_based.hh | 2 oln/core/rle/rle_pset.hh | 2 oln/draw/bresenham.hh | 4 oln/stc/scoop.hh | 1 tests/core/iter_point1d.cc | 17 - tests/core/iter_point2d.cc | 19 - tests/core/iter_point3d.cc | 22 - tests/core/rle_image.cc | 2 tests/core/subset.cc | 1 74 files changed, 3154 insertions(+), 1211 deletions(-) Index: tests/core/iter_point1d.cc --- tests/core/iter_point1d.cc (revision 943) +++ tests/core/iter_point1d.cc (working copy) @@ -26,23 +26,20 @@ // Public License. #include <cassert> - #include <oln/core/1d/image1d.hh> -#include <oln/core/internal/iterator_on_points_base.hh> - int main() { + using namespace oln; - oln::image1d<int> ima1(40); - oln::image1d<int>::piter p (ima1.points()); - oln::point1d p1; + image1d<int> ima(10); + point1d p_; - for (p.start(); p.is_valid(); p.next()) - p1.ind() = p.ind(); + image1d<int>::piter p(ima.points()); + for_all(p) + p_.ind() = p.ind(); - assert(p1.ind() = 39); - return 0; + assert(p_.ind() = 9); } Index: tests/core/iter_point2d.cc --- tests/core/iter_point2d.cc (revision 943) +++ tests/core/iter_point2d.cc (working copy) @@ -26,25 +26,22 @@ // Public License. #include <cassert> - #include <oln/core/2d/image2d.hh> int main() { + using namespace oln; - oln::image2d<int> ima1(40, 30); - oln::image2d<int>::piter p (ima1.points()); - oln::point2d p1; + image2d<int> ima(20, 10); + point2d p_; + image2d<int>::piter p(ima.points()); - for (p.start(); p.is_valid(); p.next()) + for_all(p) { - p1.row() = p.row(); - p1.col() = p.col(); + p_.row() = p.row(); + p_.col() = p.col(); } - assert(p1.row() = 39); - assert(p1.col() = 29); - - return 0; + assert(p_.row() = 19 and p_.col() = 9); } Index: tests/core/iter_point3d.cc --- tests/core/iter_point3d.cc (revision 943) +++ tests/core/iter_point3d.cc (working copy) @@ -26,27 +26,23 @@ // Public License. #include <cassert> - #include <oln/core/3d/image3d.hh> int main() { + using namespace oln; - oln::image3d<int> ima1(40, 30, 20); - oln::image3d<int>::piter p (ima1.points()); - oln::point3d p1; + image3d<int> ima(30, 20, 10); + point3d p_; + image3d<int>::piter p(ima.points()); - for (p.start(); p.is_valid(); p.next()) + for_all(p) { - p1.row() = p.row(); - p1.col() = p.col(); - p1.slice() = p.slice(); + p_.sli() = p.sli(); + p_.row() = p.row(); + p_.col() = p.col(); } - assert(p1.row() = 39); - assert(p1.col() = 29); - assert(p1.slice() = 19); - - return 0; + assert(p_.sli() = 29 and p_.row() = 19 and p_.col() = 9); } Index: tests/core/subset.cc --- tests/core/subset.cc (revision 943) +++ tests/core/subset.cc (working copy) @@ -28,6 +28,7 @@ #include <cassert> #include <oln/core/2d/image2d.hh> #include <oln/core/2d/neighb2d.hh> +#include <oln/core/gen/restricted_to.hh> int main() Index: tests/core/rle_image.cc --- tests/core/rle_image.cc (revision 943) +++ tests/core/rle_image.cc (working copy) @@ -1,7 +1,7 @@ #include <iostream> +#include <oln/core/2d/image2d.hh> #include <oln/core/rle/rle_psite.hh> #include <oln/core/rle/rle_image.hh> -#include <oln/core/2d/image2d.hh> #include <oln/debug/print.hh> #include <oln/core/rle/rle_pset.hh> #include <oln/core/encode/rle_encode.hh> Index: oln/core/rle/rle_pset.hh --- oln/core/rle/rle_pset.hh (revision 943) +++ oln/core/rle/rle_pset.hh (working copy) @@ -59,7 +59,7 @@ { typedef P point; - typedef typename f_box_from_point_<P>::ret box; + typedef oln_f_point_to_box(P) box; typedef rle_pset_fwd_piter_<P> fwd_piter; typedef rle_pset_bkd_piter_<P> bkd_piter; }; Index: oln/core/concept/iterator_on_points.hh --- oln/core/concept/iterator_on_points.hh (revision 943) +++ oln/core/concept/iterator_on_points.hh (working copy) @@ -31,7 +31,6 @@ # include <ostream> -# include <oln/core/concept/generalized_point.hh> # include <oln/core/concept/iterator.hh> # include <oln/core/concept/point.hh> @@ -43,7 +42,7 @@ template <typename Exact> struct Iterator_on_Points : public Iterator<Exact>, - virtual public Generalized_Point<Exact> + public Generalized_Point<Exact> { stc_typename(point); Index: oln/core/concept/image.hh --- oln/core/concept/image.hh (revision 943) +++ oln/core/concept/image.hh (working copy) @@ -291,8 +291,10 @@ // final coord min_row() const; coord max_row() const; + unsigned nrows() const; coord min_col() const; coord max_col() const; + unsigned ncols() const; protected: Image_2D(); @@ -307,6 +309,17 @@ { stc_typename(coord); + // final + coord min_row() const; + coord max_row() const; + unsigned nrows() const; + coord min_col() const; + coord max_col() const; + unsigned ncols() const; + coord min_sli() const; + coord max_sli() const; + unsigned nslis() const; + protected: Image_3D(); }; @@ -635,6 +648,13 @@ } template <typename Exact> + unsigned + Image_2D<Exact>::nrows() const + { + return this->bbox().pmax().row() - this->bbox().pmin().row() + 1; + } + + template <typename Exact> typename Image_2D<Exact>::coord Image_2D<Exact>::min_col() const { @@ -648,6 +668,13 @@ return this->bbox().pmax().col(); } + template <typename Exact> + unsigned + Image_2D<Exact>::ncols() const + { + return this->bbox().pmax().col() - this->bbox().pmin().col() + 1; + } + // ----------------------------------- Image_3D<Exact> template <typename Exact> @@ -655,6 +682,69 @@ { } + template <typename Exact> + typename Image_3D<Exact>::coord + Image_3D<Exact>::min_row() const + { + return this->bbox().pmin().row(); + } + + template <typename Exact> + typename Image_3D<Exact>::coord + Image_3D<Exact>::max_row() const + { + return this->bbox().pmax().row(); + } + + template <typename Exact> + unsigned + Image_3D<Exact>::nrows() const + { + return this->bbox().pmax().row() - this->bbox().pmin().row() + 1; + } + + template <typename Exact> + typename Image_3D<Exact>::coord + Image_3D<Exact>::min_col() const + { + return this->bbox().pmin().col(); + } + + template <typename Exact> + typename Image_3D<Exact>::coord + Image_3D<Exact>::max_col() const + { + return this->bbox().pmax().col(); + } + + template <typename Exact> + unsigned + Image_3D<Exact>::ncols() const + { + return this->bbox().pmax().col() - this->bbox().pmin().col() + 1; + } + + template <typename Exact> + typename Image_3D<Exact>::coord + Image_3D<Exact>::min_sli() const + { + return this->bbox().pmin().sli(); + } + + template <typename Exact> + typename Image_3D<Exact>::coord + Image_3D<Exact>::max_sli() const + { + return this->bbox().pmax().sli(); + } + + template <typename Exact> + unsigned + Image_3D<Exact>::nslis() const + { + return this->bbox().pmax().sli() - this->bbox().pmin().sli() + 1; + } + // ----------------------------------- Point_Wise_Accessible_Image_2D<Exact> template <typename Exact> Index: oln/core/concept/function.hh --- oln/core/concept/function.hh (revision 943) +++ oln/core/concept/function.hh (working copy) @@ -62,6 +62,7 @@ template <typename Exact> struct Function_p2v : public Function<Exact> { + typedef Function_p2v<void> category; protected: Function_p2v(); }; @@ -72,6 +73,7 @@ template <typename Exact> struct Function_p2b : public Function<Exact> { + typedef Function_p2b<void> category; protected: Function_p2b(); }; @@ -82,6 +84,7 @@ template <typename Exact> struct Function_v2v : public Function<Exact> { + typedef Function_v2v<void> category; protected: Function_v2v(); }; @@ -128,6 +131,7 @@ template <typename Exact> struct Function_p2p : public Function<Exact> { + typedef Function_p2p<void> category; protected: Function_p2p(); }; Index: oln/core/concept/point.hh --- oln/core/concept/point.hh (revision 943) +++ oln/core/concept/point.hh (working copy) @@ -31,7 +31,6 @@ # include <mlc/value.hh> -# include <oln/core/concept/generalized_point.hh> # include <oln/core/concept/grid.hh> # include <oln/core/concept/operators.hh> @@ -40,8 +39,22 @@ namespace oln { - /// Instant value. - oln_decl_instant_value(point); + + /// Concept-class "Generalized_Point". + + template <typename Exact> + struct Generalized_Point : virtual public Any<Exact> + { + stc_typename(grid); + stc_typename(dim); + stc_typename(coord); + stc_typename(dpoint); + + enum { n = mlc_value(dim) }; + + protected: + Generalized_Point(); + }; /// Concept-class "Point". @@ -127,6 +140,10 @@ # ifndef OLN_INCLUDE_ONLY + template <typename Exact> + Generalized_Point<Exact>::Generalized_Point() + { + } template <typename Exact> bool Point<Exact>::op_equal_(const Exact& rhs) const @@ -193,7 +210,6 @@ # endif // ! OLN_INCLUDE_ONLY - } // end of namespace oln Index: oln/core/concept/point_set.hh --- oln/core/concept/point_set.hh (revision 943) +++ oln/core/concept/point_set.hh (working copy) @@ -36,7 +36,7 @@ { /// Instant value. - oln_decl_instant_value(box); + oln_decl_instant_value(i_box); /// Concept-class "Point_Set". Index: oln/core/concept/neighborhood.hh --- oln/core/concept/neighborhood.hh (revision 943) +++ oln/core/concept/neighborhood.hh (working copy) @@ -42,7 +42,6 @@ { stc_typename(grid); stc_typename(point); - stc_typename(category); protected: Neighborhood(); @@ -58,7 +57,7 @@ { } -# endif +# endif // ! OLN_INCLUDE_ONLY } // end of namespace oln Index: oln/core/concept/value.hh --- oln/core/concept/value.hh (revision 943) +++ oln/core/concept/value.hh (working copy) @@ -53,6 +53,12 @@ Boolean(); }; + template <> + struct vtypes< bool > // FIXME: single_vtype? or move elsewhere? + { + typedef stc::is<Boolean> category; + }; + # ifndef OLN_INCLUDE_ONLY Index: oln/core/concept/operators.hh --- oln/core/concept/operators.hh (revision 943) +++ oln/core/concept/operators.hh (working copy) @@ -81,6 +81,10 @@ /// Operator - (default version). template <typename T> + T operator- (const Any<T>& lhs, const Any<T>& rhs); + + /// Operator - (default version). + template <typename T> T operator- (const Any<T>& rhs); @@ -136,6 +140,13 @@ return tmp += exact(rhs); } + template <typename T> + T operator- (const Any<T>& lhs, const Any<T>& rhs) + { + T tmp = exact(lhs); + return tmp -= exact(rhs); + } + template <typename L, typename R> L& operator%=(Any<L>& lhs, const Any<R>& rhs) { @@ -171,13 +182,6 @@ return exact(lhs).op_plus_(exact(rhs)); } - template <typename T> - T operator- (const Any<T>& lhs, const Any<T>& rhs) - { - T tmp = exact(lhs); - return tmp -= rhs; - } - template <typename L, typename R> xtd_op_minus_trait(L, R) operator- (const Any<L>& lhs, const Any<R>& rhs) { Index: oln/core/1d/dpoint1d.hh --- oln/core/1d/dpoint1d.hh (revision 943) +++ oln/core/1d/dpoint1d.hh (working copy) @@ -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 @@ /// 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 @@ this->ind() = ind; } -# endif - +# endif // ! OLN_INCLUDE_ONLY } // end of namespace oln -// dpoint1d goes with point1d so: # include <oln/core/1d/point1d.hh> Index: oln/core/1d/array1d.hh --- oln/core/1d/array1d.hh (revision 943) +++ oln/core/1d/array1d.hh (working copy) @@ -105,7 +105,7 @@ len_(len) { precondition(len > 0); - imax_ = imin_ + len_; + imax_ = imin_ + len_ - 1; allocate_(); } @@ -192,7 +192,6 @@ # endif // ! OLN_INCLUDE_ONLY - } // end of namespace oln Index: oln/core/1d/image1d.hh --- oln/core/1d/image1d.hh (revision 943) +++ oln/core/1d/image1d.hh (working copy) @@ -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 Index: oln/core/1d/image1d_b.hh --- oln/core/1d/image1d_b.hh (revision 943) +++ oln/core/1d/image1d_b.hh (working copy) @@ -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; Index: oln/core/1d/box1d.hh --- oln/core/1d/box1d.hh (revision 943) +++ oln/core/1d/box1d.hh (working copy) @@ -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 @@ { 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); Index: oln/core/1d/point1d.hh --- oln/core/1d/point1d.hh (revision 943) +++ oln/core/1d/point1d.hh (working copy) @@ -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 @@ /// 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 @@ this->ind() = ind; } -# endif - +# endif // ! OLN_INCLUDE_ONLY } // end of namespace oln -// point1d goes with dpoint1d so: # include <oln/core/1d/dpoint1d.hh> Index: oln/core/2d/neighb2d.hh --- oln/core/2d/neighb2d.hh (revision 943) +++ oln/core/2d/neighb2d.hh (working copy) @@ -96,15 +96,15 @@ 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 @@ -123,14 +123,13 @@ neighb2d c4 = internal::mk_c4(); neighb2d c8 = internal::mk_c8(); - neighb2d c2r = internal::mk_c2_row(); - neighb2d c2c = internal::mk_c2_col(); -# 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 Index: oln/core/2d/dpoint2d.hh --- oln/core/2d/dpoint2d.hh (revision 943) +++ oln/core/2d/dpoint2d.hh (working copy) @@ -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 @@ /// 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 @@ this->col() = col; } -# endif - +# endif // ! OLN_INCLUDE_ONLY } // end of namespace oln -// dpoint2d goes with point2d so: # include <oln/core/2d/point2d.hh> Index: oln/core/2d/array2d.hh --- oln/core/2d/array2d.hh (revision 943) +++ oln/core/2d/array2d.hh (working copy) @@ -79,11 +79,7 @@ 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 @@ 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 @@ 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 @@ j >= jmin_ and j <= jmax_; } - template <typename T, typename C> C array2d_<T, C>::imin() const { @@ -213,6 +204,13 @@ } 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 { return blen_; @@ -255,8 +253,7 @@ array_ = 0; // safety } -# endif - +# endif // ! OLN_INCLUDE_ONLY } // end of namespace oln Index: oln/core/2d/image2d.hh --- oln/core/2d/image2d.hh (revision 943) +++ oln/core/2d/image2d.hh (working copy) @@ -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 @@ template <typename T> class image2d; - /// Virtual types. + // Virtual types. template <typename T> struct vtypes< image2d<T> > { Index: oln/core/2d/image2d_b.hh --- oln/core/2d/image2d_b.hh (revision 943) +++ oln/core/2d/image2d_b.hh (working copy) @@ -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 @@ template <typename T> class image2d_b; - /// Virtual types. + // Virtual types. template <typename T> struct vtypes< image2d_b<T> > { @@ -68,7 +68,7 @@ }; - /// Super type. + // Super type. template <typename T> struct super_trait_< image2d_b<T> > { @@ -236,7 +236,7 @@ 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 @@ # endif // ! OLN_INCLUDE_ONLY - } // end of namespace oln Index: oln/core/2d/box2d.hh --- oln/core/2d/box2d.hh (revision 943) +++ oln/core/2d/box2d.hh (working copy) @@ -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 @@ { 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 @@ { 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 @@ 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 @@ { 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 @@ } 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; Index: oln/core/2d/point2d.hh --- oln/core/2d/point2d.hh (revision 943) +++ oln/core/2d/point2d.hh (working copy) @@ -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 { - + // 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 @@ /// Usual 2D point class. - class point2d : public internal::point2d_< point2d > + class point2d : public internal::point_base_< point2d >, + public internal::point_impl_< 2, point2d > { typedef internal::initializer_< internal::pair< internal::row_t<int>, internal::col_t<int> > > row_col_t; + + typedef internal::point_base_< point2d > super; public: - /// Ctors. + stc_using_(coord); + point2d(); point2d(int row, int col); // FIXME: Remove! point2d(const row_col_t& dat); @@ -95,11 +100,9 @@ # endif // ! OLN_INCLUDE_ONLY - } // end of namespace oln -// point2d goes with dpoint2d so: # include <oln/core/2d/dpoint2d.hh> Index: oln/core/3d/neighb3d.hh --- oln/core/3d/neighb3d.hh (revision 943) +++ oln/core/3d/neighb3d.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2001, 2002, 2003, 2004, 2006 EPITA Research and +// Copyright (C) 2001, 2002, 2003, 2004, 2006, 2007 EPITA Research and // Development Laboratory // // This file is part of the Olena Library. This library is free @@ -36,215 +36,169 @@ namespace oln { + // FIXME: neighb3d should be an actual type, not an alias... typedef neighb_<dpoint3d> neighb3d; +# ifdef OLN_ENABLE_DEFAULT + + // Default is c6. + template <typename D> + bool init_(neighb3d* this_, const D&); + +# endif // OLN_ENABLE_DEFAULT + + namespace internal { neighb3d mk_c6(); neighb3d mk_c18(); neighb3d mk_c26(); - neighb3d mk_c4_slice(); - neighb3d mk_c8_slice(); - neighb3d mk_c4_row(); - neighb3d mk_c8_row(); - neighb3d mk_c4_col(); - neighb3d mk_c8_col(); + + neighb3d mk_c4_sli(); + neighb3d mk_c8_sli(); + + neighb3d mk_c2_sli(); + neighb3d mk_c2_row(); + neighb3d mk_c2_col(); # ifndef OLN_INCLUDE_ONLY neighb3d mk_c6() { - static bool flower = true; - static neighb3d the_; - if (flower) - { - the_ - .add(dpoint3d(0, 0, 1)) - .add(dpoint3d(0, 1, 0)) - .add(dpoint3d(1, 0, 0)); - flower = false; - } - return the_; + neighb3d tmp; + tmp + .take(dpoint3d(0, 0, 1)) + .take(dpoint3d(0, 1, 0)) + .take(dpoint3d(1, 0, 0)); + return tmp; } - neighb3d mk_c18() { - static bool flower = true; - static neighb3d the_; - if (flower) - { - the_ - .add(dpoint3d(0, 0, 1)) - .add(dpoint3d(0, 1, -1)) - .add(dpoint3d(0, 1, 0)) - .add(dpoint3d(0, 1, 1)) - .add(dpoint3d(1, -1, 0)) - .add(dpoint3d(1, 0, -1)) - .add(dpoint3d(1, 0, 0)) - .add(dpoint3d(1, 0, 1)) - .add(dpoint3d(1, 1, 0)); - flower = false; + neighb3d tmp; + tmp + .take(dpoint3d(0, 0, 1)) + .take(dpoint3d(0, 1, -1)) + .take(dpoint3d(0, 1, 0)) + .take(dpoint3d(0, 1, 1)) + .take(dpoint3d(1, -1, 0)) + .take(dpoint3d(1, 0, -1)) + .take(dpoint3d(1, 0, 0)) + .take(dpoint3d(1, 0, 1)) + .take(dpoint3d(1, 1, 0)); + return tmp; } - return the_; - } - neighb3d mk_c26() { - static bool flower = true; - static neighb3d the_; - if (flower) - { - the_ - .add(dpoint3d(0, 0, 1)) - .add(dpoint3d(0, 1, -1)) - .add(dpoint3d(0, 1, 0)) - .add(dpoint3d(0, 1, 1)) - .add(dpoint3d(1, -1, -1)) - .add(dpoint3d(1, -1, 0)) - .add(dpoint3d(1, -1, 1)) - .add(dpoint3d(1, 0, -1)) - .add(dpoint3d(1, 0, 0)) - .add(dpoint3d(1, 0, 1)) - .add(dpoint3d(1, 1, -1)) - .add(dpoint3d(1, 1, 0)) - .add(dpoint3d(1, 1, 1)); - flower = false; - } - return the_; - } - - - neighb3d mk_c4_slice() - { - static bool flower = true; - static neighb3d the_; - if (flower) - { - the_ - .add(dpoint3d(0, 0, 1)) - .add(dpoint3d(0, 1, 0)); - flower = false; - } - return the_; + neighb3d tmp; + tmp + .take(dpoint3d(0, 0, 1)) + .take(dpoint3d(0, 1, -1)) + .take(dpoint3d(0, 1, 0)) + .take(dpoint3d(0, 1, 1)) + .take(dpoint3d(1, -1, -1)) + .take(dpoint3d(1, -1, 0)) + .take(dpoint3d(1, -1, 1)) + .take(dpoint3d(1, 0, -1)) + .take(dpoint3d(1, 0, 0)) + .take(dpoint3d(1, 0, 1)) + .take(dpoint3d(1, 1, -1)) + .take(dpoint3d(1, 1, 0)) + .take(dpoint3d(1, 1, 1)); + return tmp; } - - neighb3d mk_c8_slice() - { - static bool flower = true; - static neighb3d the_; - if (flower) + neighb3d mk_c4_sli() { - the_ - .add(dpoint3d(0, 0, 1)) - .add(dpoint3d(0, 1, -1)) - .add(dpoint3d(0, 1, 0)) - .add(dpoint3d(0, 1, 1)); - flower = false; + neighb3d tmp; + tmp + .take(dpoint3d(0, 0, 1)) + .take(dpoint3d(0, 1, 0)); + return tmp; } - return the_; - } - - neighb3d mk_c4_row() - { - static bool flower = true; - static neighb3d the_; - if (flower) + neighb3d mk_c8_sli() { - the_ - .add(dpoint3d(0, 0, 1)) - .add(dpoint3d(1, 0, 0)); - flower = false; + neighb3d tmp; + tmp + .take(dpoint3d(0, 0, 1)) + .take(dpoint3d(0, 1, -1)) + .take(dpoint3d(0, 1, 0)) + .take(dpoint3d(0, 1, 1)); + return tmp; } - return the_; - } - - neighb3d mk_c8_row() + neighb3d mk_c2_sli() { - static bool flower = true; - static neighb3d the_; - if (flower) - { - the_ - .add(dpoint3d(0, 0, 1)) - .add(dpoint3d(1, 0, -1)) - .add(dpoint3d(1, 0, 0)) - .add(dpoint3d(1, 0, 1)); - flower = false; - } - return the_; + neighb3d tmp; + tmp + .take(dpoint3d(1, 0, 0)); + return tmp; } - - neighb3d mk_c4_col() + neighb3d mk_c2_row3d() { - static bool flower = true; - static neighb3d the_; - if (flower) - { - the_ - .add(dpoint3d(0, 1, 0)) - .add(dpoint3d(1, 0, 0)); - flower = false; - } - return the_; + neighb3d tmp; + tmp + .take(dpoint3d(0, 1, 0)); + return tmp; } - - neighb3d mk_c8_col() - { - static bool flower = true; - static neighb3d the_; - if (flower) + neighb3d mk_c2_col3d() { - the_ - .add(dpoint3d(0, 1, 0)) - .add(dpoint3d(1, -1, 0)) - .add(dpoint3d(1, 0, 0)) - .add(dpoint3d(1, 1, 0)); - flower = false; - } - return the_; + neighb3d tmp; + tmp + .take(dpoint3d(0, 0, 1)); + return tmp; } -# endif +# endif // ! OLN_INCLUDE_ONLY } // end of namespace oln::internal - extern const neighb3d c6; - extern const neighb3d c18; - extern const neighb3d c26; - - extern const neighb3d c4_slice; - extern const neighb3d c8_slice; - extern const neighb3d c4_row; - extern const neighb3d c8_row; - extern const neighb3d c4_col; - extern const neighb3d c8_col; + extern neighb3d c6; + extern neighb3d c18; + extern neighb3d c26; + + extern neighb3d c4_sli; + extern neighb3d c8_sli; + + extern neighb3d c2_sli; + extern neighb3d c2_row3d; + extern neighb3d c2_col3d; # ifndef OLN_INCLUDE_ONLY - const neighb3d c6 = internal::mk_c6(); - const neighb3d c18 = internal::mk_c18(); - const neighb3d c26 = internal::mk_c26(); - - const neighb3d c4_slice = internal::mk_c4_slice(); - const neighb3d c8_slice = internal::mk_c8_slice(); - const neighb3d c4_row = internal::mk_c4_row(); - const neighb3d c8_row = internal::mk_c8_row(); - const neighb3d c4_col = internal::mk_c4_col(); - const neighb3d c8_col = internal::mk_c8_col(); +# ifdef OLN_ENABLE_DEFAULT + + /// Default is c6. + template <typename D> + bool init_(neighb3d* this_, const D&) + { + *this_ = c6; + return true; + } + +# endif // OLN_ENABLE_DEFAULT + + neighb3d c6 = internal::mk_c6(); + neighb3d c18 = internal::mk_c18(); + neighb3d c26 = internal::mk_c26(); + + neighb3d c4_sli = internal::mk_c4_sli(); + neighb3d c8_sli = internal::mk_c8_sli(); + + neighb3d c2_sli = internal::mk_c2_sli(); + neighb3d c2_row3d = internal::mk_c2_row3d(); + neighb3d c2_col3d = internal::mk_c2_col3d(); -# endif +# endif // ! OLN_INCLUDE_ONLY } // end of namespace oln Index: oln/core/3d/dpoint3d.hh --- oln/core/3d/dpoint3d.hh (revision 943) +++ oln/core/3d/dpoint3d.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2001, 2002, 2003, 2004, 2006 EPITA Research and +// Copyright (C) 2001, 2002, 2003, 2004, 2006, 2007 EPITA Research and // Development Laboratory // // This file is part of the Olena Library. This library is free @@ -29,118 +29,69 @@ #ifndef OLN_CORE_3D_DPOINT3D_HH # define OLN_CORE_3D_DPOINT3D_HH -# include <mlc/int.hh> -# include <oln/core/3d/point3d.hh> -# include <oln/core/internal/dpoint_nd.hh> +# include <oln/core/3d/grid3d.hh> +# include <oln/core/internal/dpoint_base.hh> +# include <oln/core/internal/point_impl.hh> namespace oln { - typedef dpoint3d_<int> dpoint3d; + // Fwd decls. + struct point3d; + struct dpoint3d; - /// Super type. - template<typename C> - struct set_super_type< dpoint3d_<C> > + // Super type. + template<> + struct super_trait_< dpoint3d > { - typedef internal::dpoint_nd< dpoint3d_<C> > ret; + typedef internal::dpoint_base_< dpoint3d > ret; }; - /// Fwd decls. - template <unsigned D> struct grid_; - typedef grid_<3> grid3d; - template <typename C> struct point3d_; - typedef point3d_<int> point3d; - - - /// Virtual types associated to oln::dpoint3d_<C>. - template <typename C> - struct vtypes< dpoint3d_<C> > - { - typedef grid3d grid_type; - typedef point3d point_type; - typedef C coord_type; - typedef mlc::uint_<3> dim_type; - - typedef mlc::uint_<0> slice_comp_type; - typedef mlc::uint_<1> row_comp_type; - typedef mlc::uint_<2> col_comp_type; + // Virtual types. + template <> + struct vtypes< dpoint3d > + { + typedef grid3d grid; + typedef int coord; + typedef point3d point; }; - /// General 3D dpoint class. - template <typename C> - class dpoint3d_ - : public internal::dpoint_nd< dpoint3d_<C> > + /// Usual 3D dpoint class. + class dpoint3d : public internal::dpoint_base_< dpoint3d >, + public internal::point_impl_< 3, dpoint3d > { - typedef dpoint3d_<C> self_t; - typedef internal::dpoint_nd<self_t> super_t; - - using super_t::v_; - + typedef internal::dpoint_base_< dpoint3d > super; public: - - /// Ctor. - dpoint3d_(); - - /// Ctor. - dpoint3d_(const xtd::vec<3,C>& v); - - /// Ctor. - dpoint3d_(C slice, C row, C col); - - C slice() const; - C& slice(); - - C row() const; - C& row(); - - C col() const; - C& col(); + stc_using_(coord); + dpoint3d(); + dpoint3d(int sli, int row, int col); }; # ifndef OLN_INCLUDE_ONLY - template <typename C> - dpoint3d_<C>::dpoint3d_() - { - } - - template <typename C> - dpoint3d_<C>::dpoint3d_(const xtd::vec<3,C>& v) - : super_t(v) + dpoint3d::dpoint3d() { } - template <typename C> - dpoint3d_<C>::dpoint3d_(C slice, C row, C col) - : super_t(xtd::mk_vec(slice, row, col)) + dpoint3d::dpoint3d(int sli, int row, int col) { + this->sli() = sli; + this->row() = row; + this->col() = col; } - template <typename C> - C dpoint3d_<C>::slice() const { return v_[0]; } - template <typename C> - C& dpoint3d_<C>::slice() { return v_[0]; } - - template <typename C> - C dpoint3d_<C>::row() const { return v_[1]; } - template <typename C> - C& dpoint3d_<C>::row() { return v_[1]; } - - template <typename C> - C dpoint3d_<C>::col() const { return v_[2]; } - template <typename C> - C& dpoint3d_<C>::col() { return v_[2]; } +# endif // ! OLN_INCLUDE_ONLY -# endif +} // end of namespace oln -} // end of namespace oln +# include <oln/core/3d/point3d.hh> #endif // ! OLN_CORE_3D_DPOINT3D_HH Index: oln/core/3d/array3d.hh --- oln/core/3d/array3d.hh (revision 943) +++ oln/core/3d/array3d.hh (working copy) @@ -1,5 +1,5 @@ -// Copyright (C) 2001, 2003, 2004, 2006 EPITA Research and Development -// Laboratory +// Copyright (C) 2001, 2003, 2004, 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 @@ -29,43 +29,75 @@ #ifndef OLN_CORE_3D_ARRAY3D_HH # define OLN_CORE_3D_ARRAY3D_HH -# include <cstdlib> +# include <cstddef> +# include <iostream> # include <mlc/contract.hh> -# include <oln/core/abstract/array.hh> namespace oln { /// General 3D array class. - template <typename value_t, typename coord_t = int> - class array3d : public abstract::array + + template <typename T, typename C = int> + class array3d_ { public: + // Not impled. + array3d_(); + array3d_(const array3d_<T,C>& rhs); + void operator=(const array3d_<T,C>&); + // end of Not impled. + + /// Ctor. - array3d(coord_t imin, coord_t jmin, coord_t kmin, - coord_t imax, coord_t jmax, coord_t kmax); + array3d_(C imin, C jmin, C kmin, + C imax, C jmax, C kmax); + /// Ctor. - array3d(coord_t ilen, coord_t jlen, coord_t klen); + array3d_(C ilen, C jlen, C klen); /// Dtor. - ~array3d(); + ~array3d_(); + + const T& operator()(C i, C j, C k) const; + T& operator()(C i, C j, C k); + + const T& operator[](std::size_t ind) const; + T& operator[](std::size_t ind); + + bool has(C i, C j, C k) const; + + std::size_t memsize() const; + std::size_t ncells() const; - value_t operator()(coord_t i, coord_t j, coord_t k) const; - value_t& operator()(coord_t i, coord_t j, coord_t k); + C imin() const; + C jmin() const; + C kmin() const; - bool has(coord_t i, coord_t j, coord_t k) const; + C imax() const; + C jmax() const; + C kmax() const; - size_t memsize() const; + C ilen() const; + C jlen() const; + C klen() const; + + const T* buffer() const; + T* buffer(); + + std::size_t i_pad() const; + std::size_t j_pad() const; protected: - coord_t imin_, jmin_, kmin_, imax_, jmax_, kmax_; - coord_t ilen_, jlen_, klen_; - value_t* buffer_; - value_t** array_2nd_dim_; - value_t*** array_1st_dim_; + C imin_, jmin_, kmin_, imax_, jmax_, kmax_; + C ilen_, jlen_, klen_; + std::size_t blen_; + T* buffer_; + T** array_tmp_; + T*** array_; private: @@ -74,58 +106,77 @@ }; + template <typename T, typename C> + std::ostream& operator<<(std::ostream& ostr, const array3d_<T,C>& arr); + # ifndef OLN_INCLUDE_ONLY - template <typename value_t, typename coord_t> - array3d<value_t, coord_t>::array3d(coord_t imin, coord_t jmin, coord_t kmin, - coord_t imax, coord_t jmax, coord_t kmax) - : imin_(imin), jmin_(jmin), kmin_(kmin), + template <typename T, typename C> + array3d_<T, C>::array3d_(C imin, C jmin, C kmin, + C imax, C jmax, C kmax) : + imin_(imin), jmin_(jmin), kmin_(kmin), imax_(imax), jmax_(jmax), kmax_(kmax) { precondition(imax >= imin and jmax >= jmin and kmax >= kmin); ilen_ = imax - imin + 1; jlen_ = jmax - jmin + 1; klen_ = kmax - kmin + 1; + // FIXME: Test that ilen_ and jlen_ are not huge! allocate_(); } - template <typename value_t, typename coord_t> - array3d<value_t, coord_t>::array3d(coord_t ilen, coord_t jlen, coord_t klen) - : imin_(0), jmin_(0), kmin_(0), + template <typename T, typename C> + array3d_<T, C>::array3d_(C ilen, C jlen, C klen) : + imin_(0), jmin_(0), kmin_(0), ilen_(ilen), jlen_(jlen), klen_(klen) { precondition(ilen > 0 and jlen > 0 and klen > 0); - imax_ = imin_ + ilen_; - jmax_ = jmin_ + ilen_; - kmax_ = kmin_ + klen_; + // FIXME: Test that *len_ are not huge! + imax_ = imin_ + ilen_ - 1; + jmax_ = jmin_ + ilen_ - 1; + kmax_ = kmin_ + klen_ - 1; allocate_(); } - template <typename value_t, typename coord_t> - array3d<value_t, coord_t>::~array3d() + template <typename T, typename C> + array3d_<T, C>::~array3d_() { deallocate_(); } - template <typename value_t, typename coord_t> - value_t - array3d<value_t, coord_t>::operator()(coord_t i, coord_t j, coord_t k) const + template <typename T, typename C> + const T& array3d_<T, C>::operator()(C i, C j, C k) const { precondition(has(i, j, k)); - return array_1st_dim_[i][j][k]; + return array_[i][j][k]; } - template <typename value_t, typename coord_t> - value_t& - array3d<value_t, coord_t>::operator()(coord_t i, coord_t j, coord_t k) + template <typename T, typename C> + T& array3d_<T, C>::operator()(C i, C j, C k) { precondition(has(i, j, k)); - return array_1st_dim_[i][j][k]; + return array_[i][j][k]; + } + + template <typename T, typename C> + const T& array3d_<T, C>::operator[](std::size_t ind) const + { + precondition(buffer_ != 0); + precondition(ind < blen_); + return buffer_[ind]; + } + + template <typename T, typename C> + T& array3d_<T, C>::operator[](std::size_t ind) + { + precondition(buffer_ != 0); + precondition(ind < blen_); + return buffer_[ind]; } - template <typename value_t, typename coord_t> - bool array3d<value_t, coord_t>::has(coord_t i, coord_t j, coord_t k) const + template <typename T, typename C> + bool array3d_<T, C>::has(C i, C j, C k) const { return i >= imin_ and i <= imax_ and @@ -133,57 +184,157 @@ k >= kmin_ and k <= kmax_; } - template <typename value_t, typename coord_t> - size_t array3d<value_t, coord_t>::memsize() const + template <typename T, typename C> + C array3d_<T, C>::imin() const + { + return imin_; + } + + template <typename T, typename C> + C array3d_<T, C>::jmin() const + { + return jmin_; + } + + template <typename T, typename C> + C array3d_<T, C>::kmin() const + { + return kmin_; + } + + template <typename T, typename C> + C array3d_<T, C>::imax() const + { + return imax_; + } + + template <typename T, typename C> + C array3d_<T, C>::jmax() const + { + return jmax_; + } + + template <typename T, typename C> + C array3d_<T, C>::kmax() const + { + return kmax_; + } + + template <typename T, typename C> + C array3d_<T, C>::ilen() const + { + return ilen_; + } + + template <typename T, typename C> + C array3d_<T, C>::jlen() const + { + return jlen_; + } + + template <typename T, typename C> + C array3d_<T, C>::klen() const + { + return klen_; + } + + template <typename T, typename C> + const T* array3d_<T, C>::buffer() const + { + return buffer_; + } + + template <typename T, typename C> + T* array3d_<T, C>::buffer() + { + return buffer_; + } + + template <typename T, typename C> + std::size_t array3d_<T, C>::i_pad() const + { + precondition(buffer_ != 0 and array_ != 0); + return std::size_t(klen_) * std::size_t(jlen_); + } + + template <typename T, typename C> + std::size_t array3d_<T, C>::j_pad() const + { + precondition(buffer_ != 0 and array_ != 0); + return klen_; + } + + template <typename T, typename C> + std::size_t array3d_<T, C>::ncells() const + { + return blen_; + } + + template <typename T, typename C> + std::size_t array3d_<T, C>::memsize() const { return // buffer_ - size_t(ilen_) * size_t(jlen_) * size_t(klen_) * sizeof(value_t) + blen_ * sizeof(T) + - // array_2nd_dim_ - size_t(ilen_) * size_t(jlen_) * sizeof(value_t*) + // array_tmp_ + std::size_t(ilen_) * std::size_t(jlen_) * sizeof(T*) + - // array_1st_dim_ - size_t(ilen_) * sizeof(value_t*); + // array_ + std::size_t(ilen_) * sizeof(T**); } - template <typename value_t, typename coord_t> - void array3d<value_t, coord_t>::allocate_() + template <typename T, typename C> + void array3d_<T, C>::allocate_() { - buffer_ = new value_t[size_t(ilen_) * size_t(jlen_) * size_t(klen_)]; - array_2nd_dim_ = new value_t*[size_t(ilen_) * size_t(jlen_)]; - array_1st_dim_ = new value_t**[size_t(ilen_)]; - value_t* buf = buffer_ - kmin_; - for (coord_t i = 0; i < ilen_; ++i) + blen_ = std::size_t(ilen_) * std::size_t(jlen_) * std::size_t(klen_); + buffer_ = new T [blen_]; + array_tmp_ = new T* [std::size_t(ilen_) * size_t(jlen_)]; + array_ = new T**[std::size_t(ilen_)]; + T* buf = buffer_ - kmin_; + for (C i = 0; i < ilen_; ++i) { - value_t** nth_array_2nd_dim = array_2nd_dim_ + i * jlen_; - array_1st_dim_[i] = nth_array_2nd_dim - jmin_; - for (coord_t j = 0; j < jlen_; ++j) + T** arr_i_ = array_tmp_ + i * jlen_; + array_[i] = arr_i_ - jmin_; + for (C j = 0; j < jlen_; ++j) { - nth_array_2nd_dim[j] = buf; + arr_i_[j] = buf; buf += klen_; } } - array_1st_dim_ -= imin_; + array_ -= imin_; } - template <typename value_t, typename coord_t> - void array3d<value_t, coord_t>::deallocate_() + template <typename T, typename C> + void array3d_<T, C>::deallocate_() { - precondition(buffer_ != 0 and - array_2nd_dim_ != 0 and - array_1st_dim_ != 0); + precondition(buffer_ != 0 and array_ != 0 and array_tmp_ != 0); delete[] buffer_; buffer_ = 0; // safety - delete[] array_2nd_dim_; - array_2nd_dim_ = 0; // safety - array_1st_dim_ += imin_; - delete[] array_1st_dim_; - array_1st_dim_ = 0; // safety + delete[] array_tmp_; + array_tmp_ = 0; // safety + array_ += imin_; + delete[] array_; + array_ = 0; // safety + } + + template <typename T, typename C> + std::ostream& operator<<(std::ostream& ostr, const array3d_<T,C>& arr) + { + return ostr << "{" + << " imin=" << arr.imin() + << " jmin=" << arr.jmin() + << " kmin=" << arr.kmin() + << " imax=" << arr.imax() + << " jmax=" << arr.jmax() + << " kmax=" << arr.kmax() + << " ilen=" << arr.ilen() + << " jlen=" << arr.jlen() + << " klen=" << arr.klen() + << " blen=" << arr.ncells() << " }"; } -# endif - +# endif // ! OLN_INCLUDE_ONLY } // end of namespace oln Index: oln/core/3d/image3d.hh --- oln/core/3d/image3d.hh (revision 943) +++ oln/core/3d/image3d.hh (working copy) @@ -1,5 +1,5 @@ -// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 EPITA Research and -// Development Laboratory +// 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 @@ -29,171 +29,218 @@ #ifndef OLN_CORE_3D_IMAGE3D_HH # define OLN_CORE_3D_IMAGE3D_HH -# include <oln/core/image_entry.hh> -# include <oln/core/gen/grid.hh> -# include <oln/core/internal/tracked_ptr.hh> +# include <oln/core/3d/box3d.hh> +# include <oln/core/internal/image_base.hh> +# include <oln/core/internal/utils.hh> # include <oln/core/3d/array3d.hh> -# include <oln/core/3d/point3d.hh> -# include <oln/core/3d/topo3d.hh> -// For fwd_piter and bkd_piter virtual types. -# include <oln/core/iterator_vtypes.hh> namespace oln { - // Forward declaration. + // Fwd decl. template <typename T> class image3d; - /// Virtual types associated to oln::image3d<T>. + // Virtual types. template <typename T> struct vtypes< image3d<T> > { - typedef topo3d topo_type; + typedef point3d point; - typedef point3d point_type; + typedef int coord; + typedef unsigned index; - typedef mlc::false_ is_computed_type; - typedef T value_type; - typedef T& lvalue_type; + typedef T value; + typedef const T& rvalue; + typedef T& lvalue; + + typedef box3d pset; + typedef internal::pair< array3d_<value, coord>*, box3d > data; + + typedef image3d<T> plain; + typedef image3d<pl::value> skeleton; }; - /// Super type declaration. + // Super type. template <typename T> - struct set_super_type< image3d<T> > + struct super_trait_< image3d<T> > { - typedef image3d<T> self_t; - typedef image_entry<self_t> ret; + typedef image3d<T> current; + typedef internal::plain_primitive_image_<current> ret; }; /// General 3D image class. + template <typename T> - class image3d : public image_entry< image3d<T> > + class image3d : public internal::plain_primitive_image_< image3d<T> > { - typedef image3d<T> self_t; - typedef array3d<T> array_t; - + typedef image3d<T> current; + typedef internal::plain_primitive_image_<current> super; + typedef array3d_<T, int> array_t; public: + stc_using(data); - /// Ctor using sizes. - image3d(unsigned nslices, unsigned nrows, unsigned ncols, - unsigned border = 2); + image3d(); + image3d(const box3d& b); + image3d(unsigned nslis, unsigned nrows, unsigned ncols); - /// Ctor using an existing topology. - image3d(const topo3d& topo); + bool impl_owns_(const point3d& p) const; - const topo3d& impl_topo() const; + bool impl_has_at(int sli, int row, int col) const; - T impl_op_read(const point3d& p) const; - T impl_at(int slice, int row, int col) const; + const T& impl_read(const point3d& p) const; + const T& impl_index_read(unsigned i) const; + const T& impl_at(int sli, int row, int col) const; - T& impl_op_readwrite(const point3d& p); - T& impl_at(int slice, int row, int col); + T& impl_read_write(const point3d& p); + T& impl_index_read_write(unsigned i); + T& impl_at(int sli, int row, int col); - T* adr_at(int slice, int row, int col); - const T* adr_at(int slice, int row, int col) const; + void impl_write(const point3d& p, const T& v); - private: + std::size_t impl_npoints() const; - topo3d topo_; - internal::tracked_ptr<array_t> data_; + const box3d& impl_points() const; }; + template <typename T, typename D> + bool prepare(image3d<T>& target, with_t, const D& dat); + # ifndef OLN_INCLUDE_ONLY template <typename T> - image3d<T>::image3d(unsigned nslices, unsigned nrows, unsigned ncols, - unsigned border) - : topo_(bbox3d(point3d(0, 0, 0 ), - point3d(nslices - 1, nrows - 1, ncols - 1)), - border), - data_(new array_t(0 - border, - 0 - border, - 0 - border, - nslices - 1 + border, - nrows - 1 + border, - ncols - 1 + border)) + image3d<T>::image3d() + { + } + + template <typename T> + image3d<T>::image3d(const box3d& b) + { + this->data_ = new data(new array_t(b.pmin().sli(), + b.pmin().row(), + b.pmin().col(), + b.pmax().sli(), + b.pmax().row(), + b.pmax().col()), + b); + } + + template <typename T> + image3d<T>::image3d(unsigned nslis, unsigned nrows, unsigned ncols) { + precondition(nslis != 0 and nrows != 0 and ncols != 0); + this->data_ = new data(new array_t(0, 0, 0, + nslis - 1, + nrows - 1, + ncols - 1), + box3d(point3d(0, 0, 0), + point3d(nslis - 1, + nrows - 1, + ncols - 1))); } template <typename T> - image3d<T>::image3d(const topo3d& topo) - : topo_(topo), - data_(new array_t(topo.bbox().pmin().slice(), - topo.bbox().pmin().row(), - topo.bbox().pmin().col(), - topo.bbox().pmax().slice(), - topo.bbox().pmax().row(), - topo.bbox().pmax().col())) + bool image3d<T>::impl_owns_(const point3d& p) const { + assert(this->has_data()); + return this->data_->first.has(p.sli(), p.row(), p.col()); } template <typename T> - const topo3d& - image3d<T>::impl_topo() const + bool image3d<T>::impl_has_at(int sli, int row, int col) const { - return topo_; + assert(this->has_data()); + return this->data_->first.has(sli, row, col); } + template <typename T> + const T& image3d<T>::impl_read(const point3d& p) const + { + assert(this->has_data()); + return this->data_->first(p.sli(), p.row(), p.col()); + } template <typename T> - T - image3d<T>::impl_op_read(const point3d& p) const + const T& image3d<T>::impl_index_read(unsigned i) const { - precondition(data_ != 0); - precondition(topo_.has_large(p)); - return data_->operator()(p.slice(), p.row(), p.col()); + assert(this->has_data()); + assert(i < this->npoints()); + return this->data_->first[i]; } template <typename T> - T - image3d<T>::impl_at(int slice, int row, int col) const + const T& image3d<T>::impl_at(int sli, int row, int col) const { - precondition(data_->has(slice, row, col)); - return data_->operator()(slice, row, col); + assert(this->has_data()); + return this->data_->first(sli, row, col); } + template <typename T> + T& image3d<T>::impl_read_write(const point3d& p) + { + assert(this->has_data()); + return this->data_->first(p.sli(), p.row(), p.col()); + } template <typename T> - T& - image3d<T>::impl_op_readwrite(const point3d& p) + T& image3d<T>::impl_index_read_write(unsigned i) { - precondition(data_ != 0); - precondition(topo_.has_large(p)); - return data_->operator()(p.slice(), p.row(), p.col()); + assert(this->has_data()); + assert(i < this->npoints()); + return this->data_->first[i]; } template <typename T> - T& - image3d<T>::impl_at(int slice, int row, int col) + T& image3d<T>::impl_at(int sli, int row, int col) { - precondition(data_->has(slice, row, col)); - return data_->operator()(slice, row, col); + assert(this->has_data()); + return this->data_->first(sli, row, col); } + template <typename T> + void image3d<T>::impl_write(const point3d& p, const T& v) + { + assert(this->has_data()); + this->data_->first(p.sli(), p.row(), p.col()) = v; + } template <typename T> - T* image3d<T>::adr_at(int slice, int row, int col) + std::size_t image3d<T>::impl_npoints() const { - precondition(data_ != 0); - precondition(data_->has(slice, row, col)); - return &(data_->operator()(slice, row, col)); + // faster than the default code given by primitive_image_ + assert(this->has_data()); + return this->data_->first.ncells(); } template <typename T> - const T* image3d<T>::adr_at(int slice, int row, int col) const + const box3d& image3d<T>::impl_points() const { - precondition(data_ != 0); - precondition(data_->has(slice, row, col)); - return &(data_->operator()(slice, row, col)); + assert(this->has_data()); + return this->data_->second; } -# endif + template <typename T, typename D> + bool prepare(image3d<T>& target, with_t, const D& dat) + { + precondition(not target.has_data()); + box3d b; + bool box_ok = init(b, with, dat); + postcondition(box_ok); + array3d_<T,int>* ptr = new array3d_<T,int>(b.pmin().sli(), + b.pmin().row(), + b.pmin().col(), + b.pmax().sli(), + b.pmax().row(), + b.pmax().col()); + target.data__() = new typename image3d<T>::data(ptr, b); + return box_ok; + } +# endif // ! OLN_INCLUDE_ONLY } // end of namespace oln Index: oln/core/3d/image3d_b.hh --- oln/core/3d/image3d_b.hh (revision 0) +++ oln/core/3d/image3d_b.hh (revision 0) @@ -0,0 +1,290 @@ +// 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_3D_IMAGE3D_B_HH +# define OLN_CORE_3D_IMAGE3D_B_HH + +# include <oln/core/3d/box3d.hh> +# include <oln/core/internal/image_base.hh> +# include <oln/core/internal/utils.hh> +# include <oln/core/3d/array3d.hh> + + +namespace oln +{ + + + // Fwd decl. + template <typename T> class image3d_b; + + + // Virtual types. + template <typename T> + struct vtypes< image3d_b<T> > + { + typedef point3d point; + + typedef int coord; + typedef unsigned index; + + typedef T value; + typedef const T& rvalue; + typedef T& lvalue; + + typedef box3d pset; + typedef internal::triplet< array3d_<T, int>*, + unsigned, + box3d > data; + + typedef mlc::true_ vborder; + + typedef image3d_b<T> plain; + typedef image3d_b<pl::value> skeleton; + }; + + + // Super type. + template <typename T> + struct super_trait_< image3d_b<T> > + { + typedef image3d_b<T> current; + typedef internal::plain_primitive_image_<current> ret; + }; + + + /// General 3D image class. + + template <typename T> + class image3d_b : public internal::plain_primitive_image_< image3d_b<T> > + { + typedef image3d_b<T> current; + typedef internal::plain_primitive_image_<current> super; + typedef array3d_<T, int> array_t; + public: + stc_using(data); + + image3d_b(); + image3d_b(const box3d& b, + unsigned border = 2); + image3d_b(unsigned nslis, unsigned nrows, unsigned ncols, + unsigned border = 2); + + bool impl_owns_(const point3d& p) const; + + bool impl_has_at(int sli, int row, int col) const; + + const T& impl_read(const point3d& p) const; + const T& impl_index_read(unsigned i) const; + const T& impl_at(int sli, int row, int col) const; + + T& impl_read_write(const point3d& p); + T& impl_index_read_write(unsigned i); + T& impl_at(int sli, int row, int col); + + void impl_write(const point3d& p, const T& v); + + std::size_t impl_npoints() const; + + const box3d& impl_points() const; + + unsigned impl_border() const; + std::size_t pad(const dpoint3d& dp) const; + }; + +// template <typename T, typename D> +// bool init_(image3d_b<T>* this_, const D& dat); + + template <typename T, typename D> + bool prepare(image3d_b<T>& target, with_t, const D& dat); + + + +# ifndef OLN_INCLUDE_ONLY + + template <typename T> + image3d_b<T>::image3d_b() + { + } + + template <typename T> + image3d_b<T>::image3d_b(const box3d& b, + unsigned border) + { + this->data_ = new data(new array_t(b.pmin().sli() - border, + b.pmin().row() - border, + b.pmin().col() - border, + b.pmax().sli() + border, + b.pmax().row() + border, + b.pmax().col() + border), + border, + b); + } + + template <typename T> + image3d_b<T>::image3d_b(unsigned nslis, unsigned nrows, unsigned ncols, + unsigned border) + { + precondition(nslis != 0 and nrows != 0 and ncols != 0); + this->data_ = new data(new array_t(- border, + - border, + - border, + nslis - 1 + border, + nrows - 1 + border, + ncols - 1 + border), + border, + box3d(point3d(0, 0, 0), + point3d(nslis - 1, + nrows - 1, + ncols - 1))); + } + + template <typename T> + bool image3d_b<T>::impl_owns_(const point3d& p) const + { + assert(this->has_data()); + return this->data_->first.has(p.sli(), p.row(), p.col()); + } + + template <typename T> + bool image3d_b<T>::impl_has_at(int sli, int row, int col) const + { + assert(this->has_data()); + return this->data_->first.has(sli, row, col); + } + + template <typename T> + const T& image3d_b<T>::impl_read(const point3d& p) const + { + assert(this->has_data()); + return this->data_->first(p.sli(), p.row(), p.col()); + } + + template <typename T> + const T& image3d_b<T>::impl_index_read(unsigned i) const + { + assert(this->has_data()); + assert(i < this->npoints()); + return this->data_->first[i]; + } + + template <typename T> + const T& image3d_b<T>::impl_at(int sli, int row, int col) const + { + assert(this->has_data()); + return this->data_->first(sli, row, col); + } + + template <typename T> + T& image3d_b<T>::impl_read_write(const point3d& p) + { + assert(this->has_data()); + return this->data_->first(p.sli(), p.row(), p.col()); + } + + template <typename T> + T& image3d_b<T>::impl_index_read_write(unsigned i) + { + assert(this->has_data()); + assert(i < this->npoints()); + return this->data_->first[i]; + } + + template <typename T> + T& image3d_b<T>::impl_at(int sli, int row, int col) + { + assert(this->has_data()); + return this->data_->first(sli, row, col); + } + + template <typename T> + void image3d_b<T>::impl_write(const point3d& p, const T& v) + { + assert(this->has_data()); + this->data_->first(p.sli(), p.row(), p.col()) = v; + } + + template <typename T> + const box3d& image3d_b<T>::impl_points() const + { + assert(this->has_data()); + return this->data_->third; + } + + template <typename T> + unsigned image3d_b<T>::impl_border() const + { + assert(this->has_data()); + return this->data_->second; + } + + template <typename T> + std::size_t image3d_b<T>::pad(const dpoint3d& dp) const + { + assert(this->has_data()); + return + this->data_->first.i_pad() * dp.sli() + + this->data_->first.j_pad() * dp.row() + + dp.col(); + } + +// template <typename T, typename D> +// bool init_(image3d_b<T>* this_, const D& dat) +// { +// precondition(not this_->has_data()); +// box3d b; +// bool box_ok = init(b, with, dat); +// postcondition(box_ok); +// unsigned border = 2; // FIXME: Use init! +// this_->data__() = new typename image3d_b<T>::data(b.pmin(), b.pmax(), border); +// return box_ok; +// } + + template <typename T, typename D> + bool prepare(image3d_b<T>& target, with_t, const D& dat) + { + precondition(not target.has_data()); + box3d b; + bool box_ok = init(b, with, dat); + postcondition(box_ok); + unsigned border = 2; // FIXME: Use init! + array3d_<T,int>* ptr = new array3d_<T,int>(b.pmin().sli() - border, + b.pmin().row() - border, + b.pmin().col() - border, + b.pmax().sli() + border, + b.pmax().row() + border, + b.pmax().col() + border); + target.data__() = new typename image3d_b<T>::data(ptr, border, b); + return box_ok; + } + +# endif // ! OLN_INCLUDE_ONLY + +} // end of namespace oln + + +#endif // ! OLN_CORE_3D_IMAGE3D_B_HH Index: oln/core/3d/grid3d.hh --- oln/core/3d/grid3d.hh (revision 0) +++ oln/core/3d/grid3d.hh (revision 0) @@ -0,0 +1,95 @@ +// 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 OLN_CORE_3D_GRID3D_HH +# define OLN_CORE_3D_GRID3D_HH + +# include <mlc/int.hh> +# include <oln/core/2d/grid2d.hh> // So import 2d instant values. + + + +# define OLN_ENV_3D + + + +namespace oln +{ + + /// Instant values. + oln_decl_instant_value(sli); + oln_decl_instant_value(dsli); + oln_decl_instant_value(nslis); + + + /// \{ + /// Fwd decls. + + template <typename Exact> struct Grid_3D; + struct grid3d; + + /// \} + + + /// \{ + /// Grid_3D. + + template <typename Exact> + struct vtypes< Grid_3D<Exact> > + { + typedef mlc::uint_<3> dim; + }; + + template <typename Exact> + struct Grid_3D : public Grid<Exact> + { + protected: + Grid_3D() {} + }; + + /// \} + + + // Super type. + + template<> + struct super_trait_< grid3d > + { + typedef Grid_3D< grid3d > ret; + }; + + + /// Cubic grid struct. + + struct grid3d : public Grid_3D< grid3d > + { + }; + +} // end of namespace oln + + +#endif // ! OLN_CORE_3D_GRID3D_HH Index: oln/core/3d/window3d.hh --- oln/core/3d/window3d.hh (revision 943) +++ oln/core/3d/window3d.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2006 EPITA Research and Development Laboratory +// 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 @@ -28,10 +28,16 @@ #ifndef OLN_CORE_3D_WINDOW3D_HH # define OLN_CORE_3D_WINDOW3D_HH -// Headers required for the complete definition of oln::window3d -// (i.e., oln::window_<dpoint3d>). -# include <oln/core/3d/aliases.hh> -# include <oln/core/3d/dpoint3d.hh> # include <oln/core/gen/window.hh> + +namespace oln +{ + + // FIXME: window3d should be an actual type, not an alias... + typedef gen_window<dpoint3d> window3d; + +} // end of namespace oln + + #endif // ! OLN_CORE_3D_WINDOW3D_HH Index: oln/core/3d/box3d.hh --- oln/core/3d/box3d.hh (revision 0) +++ oln/core/3d/box3d.hh (revision 0) @@ -0,0 +1,154 @@ +// 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 OLN_CORE_3D_BOX3D_HH +# define OLN_CORE_3D_BOX3D_HH + +# include <oln/core/3d/point3d.hh> +# include <oln/core/concept/point_set.hh> // for internal::tag::i_box_t +# include <oln/core/internal/box.hh> + + +namespace oln +{ + + // Fwd decl. + class box3d; + + // Super type + template <> + struct super_trait_< box3d > + { + typedef internal::box_<box3d> ret; + }; + + // Virtual types + template <> + struct vtypes<box3d> + { + typedef point3d point; + typedef box3d box; + }; + + // Class box3d + class box3d : public internal::box_< box3d > + { + typedef internal::box_< box3d > super; + public: + stc_using_(from_to_t); + + box3d(); + box3d(const from_to_t& dat); + box3d(const point3d& pmin, const point3d& pmax); + template <typename D> + box3d(const internal::initializer_<D>& data); + }; + + namespace internal + { + + template <typename U> + bool init__(tag::i_box_t, box3d& b, + const triplet< nrows_t<U>, ncols_t<U>, nslis_t<U> >& data); + + template <typename U> + bool init__(tag::i_box_t, box3d& b, + const quartet< from_t<point3d>, + nrows_t<U>, ncols_t<U>, nslis_t<U> >& data); + + } // end of namespace oln::internal + + +# ifndef OLN_INCLUDE_ONLY + + box3d::box3d() + { + } + + box3d::box3d(const box3d::from_to_t& dat) : + super(dat) + { + } + + box3d::box3d(const point3d& pmin, const point3d& pmax) : + super(pmin, pmax) + { + } + + template <typename D> + box3d::box3d(const internal::initializer_<D>& data) + { + bool box_ok = internal::init__(internal::tag::i_box_t(), *this, data.value()); + postcondition(box_ok); + } + + + namespace internal + { + + template <typename U> + bool init__(tag::i_box_t, box3d& b, + const triplet< nrows_t<U>, ncols_t<U>, nslis_t<U> >& data) + { + unsigned nrows = data.first.value; + unsigned ncols = data.second.value; + unsigned nslis = data.third.value; + precondition(nrows != 0 and ncols != 0 and nslis != 0); + b.pmin().row() = 0; + b.pmin().col() = 0; + b.pmin().sli() = 0; + b.pmax().row() = nrows - 1; + b.pmax().col() = ncols - 1; + b.pmax().sli() = nslis - 1; + return true; + } + + template <typename U> + bool init__(tag::i_box_t, box3d& b, + const quartet< from_t<point3d>, + nrows_t<U>, ncols_t<U>, nslis_t<U> >& data) + { + unsigned nrows = data.second.value; + unsigned ncols = data.third.value; + unsigned nslis = data.fourth.value; + precondition(nrows != 0 and ncols != 0 and nslis != 0); + b.pmin() = data.first.value; + b.pmax().row() = b.pmin().row() + nrows - 1; + b.pmax().col() = b.pmin().col() + ncols - 1; + b.pmax().sli() = b.pmin().sli() + nslis - 1; + return true; + } + + } // end of namespace oln::internal + +# endif // ! OLN_INCLUDE_ONLY + + +} // end of namespace oln + + +#endif // ! OLN_CORE_3D_BOX3D_HH Index: oln/core/3d/point3d.hh --- oln/core/3d/point3d.hh (revision 943) +++ oln/core/3d/point3d.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2001, 2002, 2003, 2004, 2006 EPITA Research and +// Copyright (C) 2001, 2002, 2003, 2004, 2006, 2007 EPITA Research and // Development Laboratory // // This file is part of the Olena Library. This library is free @@ -29,128 +29,81 @@ #ifndef OLN_CORE_3D_POINT3D_HH # define OLN_CORE_3D_POINT3D_HH -# include <mlc/int.hh> -# include <oln/core/internal/point_nd.hh> +# include <oln/core/3d/grid3d.hh> +# include <oln/core/internal/point_base.hh> +# include <oln/core/internal/point_impl.hh> namespace oln { - /// Fwd decls. - template <unsigned D> struct grid_; - template <typename C> struct dpoint3d_; - template <typename C> struct point3d_; + // Fwd decls. + class point3d; + class dpoint3d; - typedef grid_<3> grid3d; - typedef dpoint3d_<int> dpoint3d; - typedef point3d_<int> point3d; - - - /* FIXME: Is this the right place for these functions (on types)? - In particular, the function on dpoint3d should be near the - definition of dpoint3d, not point3d's. */ - /// Specializations of functions point and dpoint : - /// \f$(n, coord) \rightarrow type\f$ for \f$n = 3\f$. - /// \{ - template <typename C> struct point_ <3, C> { typedef point3d_<C> ret; }; - template <typename C> struct dpoint_ <3, C> { typedef dpoint3d_<C> ret; }; - /// \} - - - - /// Super type. - template<typename C> - struct set_super_type< point3d_<C> > + // Super type. + template<> + struct super_trait_< point3d > { - typedef internal::point_nd< point3d_<C> > ret; + typedef internal::point_base_< point3d > ret; }; - /// Virtual types associated to oln::point3d_<C>. - template <typename C> - struct vtypes< point3d_<C> > - { - typedef grid3d grid_type; - typedef dpoint3d dpoint_type; - typedef C coord_type; - typedef mlc::uint_<3> dim_type; - - typedef mlc::uint_<0> slice_comp_type; - typedef mlc::uint_<1> row_comp_type; - typedef mlc::uint_<2> col_comp_type; + // Virtual types. + template <> + struct vtypes< point3d > + { + typedef grid3d grid; + typedef int coord; + typedef dpoint3d dpoint; }; - /// General 3D point class. - template <typename C> - class point3d_ : public internal::point_nd< point3d_<C> > - { - typedef point3d_<C> self_t; - typedef internal::point_nd<self_t> super_t; - - using super_t::v_; - + /// Usual 3D point class. + class point3d : public internal::point_base_< point3d >, + public internal::point_impl_< 3, point3d > + { + typedef internal::initializer_< + internal::triplet< internal::sli_t<int>, internal::row_t<int>, internal::col_t<int> > + > sli_row_col_t; + typedef internal::point_base_< point3d > super; public: + stc_using_(coord); - /// Ctor. - point3d_(); - - /// Ctor. - point3d_(C slice, C row, C col); - - /// Ctor. - point3d_(const xtd::vec<3,C>& v); - - C slice() const; - C& slice(); - - C row() const; - C& row(); - - C col() const; - C& col(); + point3d(); + point3d(int sli, int row, int col); // FIXME: Remove! + point3d(const sli_row_col_t& dat); }; # ifndef OLN_INCLUDE_ONLY - template <typename C> - point3d_<C>::point3d_() + point3d::point3d() { } - template <typename C> - point3d_<C>::point3d_(C slice, C row, C col) - : super_t (xtd::mk_vec(slice, row, col)) + point3d::point3d(int sli, int row, int col) // FIXME: Remove! { + this->sli() = sli; + this->row() = row; + this->col() = col; } - template <typename C> - point3d_<C>::point3d_(const xtd::vec<3,C>& v) - : super_t(v) + point3d::point3d(const point3d::sli_row_col_t& dat) { + this->sli() = dat->first.value; + this->row() = dat->second.value; + this->col() = dat->third.value; } - template <typename C> - C point3d_<C>::slice() const { return v_[0]; } - template <typename C> - C& point3d_<C>::slice() { return v_[0]; } - - template <typename C> - C point3d_<C>::row() const { return v_[1]; } - template <typename C> - C& point3d_<C>::row() { return v_[1]; } - - template <typename C> - C point3d_<C>::col() const { return v_[2]; } - template <typename C> - C& point3d_<C>::col() { return v_[2]; } - -# endif +# endif // ! OLN_INCLUDE_ONLY } // end of namespace oln +# include <oln/core/3d/dpoint3d.hh> + + #endif // ! OLN_CORE_3D_POINT3D_HH Index: oln/core/gen/dpoints_piter.hh --- oln/core/gen/dpoints_piter.hh (revision 943) +++ oln/core/gen/dpoints_piter.hh (working copy) @@ -28,7 +28,7 @@ #ifndef OLN_CORE_GEN_DPOINTS_PITER_HH # define OLN_CORE_GEN_DPOINTS_PITER_HH -# include <oln/core/concept/generalized_point.hh> +# include <oln/core/concept/point.hh> # include <oln/core/concept/window.hh> # include <oln/core/concept/neighborhood.hh> # include <oln/core/concept/image.hh> Index: oln/core/gen/box.hh --- oln/core/gen/box.hh (revision 943) +++ oln/core/gen/box.hh (working copy) @@ -29,91 +29,90 @@ #ifndef OLN_CORE_GEN_BOX_HH # define OLN_CORE_GEN_BOX_HH -# include <oln/core/concept/point.hh> -# include <oln/core/concept/iterator_on_points.hh> # include <oln/core/internal/box.hh> +# include <oln/core/gen/point.hh> namespace oln { +# define current box<G,C> + // Fwd decl. - template <typename P> class gen_box; + template <typename G, typename C> class box; // Super type. - template <typename P> - struct super_trait_< gen_box<P> > + template <typename G, typename C> + struct super_trait_< current > { - typedef gen_box<P> current__; - typedef internal::box_<current__> ret; + typedef internal::box_< current > ret; }; - /// Virtual types. - template <typename P> - struct vtypes< gen_box<P> > + // Virtual types. + template <typename G, typename C> + struct vtypes< current > { - typedef P point; - typedef gen_box<P> box; + typedef point<G, C> point; + typedef current box; }; /// Generic box class based on a point class. - template <typename P> - class gen_box : public internal::box_< gen_box<P> >, - private mlc::assert_< mlc_is_a(P, Point) > + template <typename G, typename C> + class box : public internal::box_< current > { - typedef gen_box<P> current; typedef internal::box_<current> super; public: - stc_using(point); - stc_using(box); - + stc_using(from_to_t); - public: + box(); - gen_box(); - gen_box(const P& pmin, const P& pmax); - gen_box(const typename gen_box<P>::from_to_t& data); + box(const oln::point<G,C>& pmin, const oln::point<G,C>& pmax); + box(const from_to_t& data); template <typename D> - gen_box(const internal::initializer_<D>& data); + box(const internal::initializer_<D>& data); - }; // end of class oln::gen_box<P> + }; // end of class oln::box<G,C> # ifndef OLN_INCLUDE_ONLY - template <typename P> - gen_box<P>::gen_box() + template <typename G, typename C> + current::box() { + mlc::assert_< mlc_is_a(G, Grid) >::check(); } - template <typename P> - gen_box<P>::gen_box(const P& pmin, const P& pmax) : - super(pmin, pmax) + template <typename G, typename C> + current::box(const oln::point<G,C>& pmin, + const oln::point<G,C>& pmax) + : super(pmin, pmax) { } - template <typename P> - gen_box<P>::gen_box(const typename gen_box<P>::from_to_t& data) : + template <typename G, typename C> + current::box(const typename current::from_to_t& data) : super(data) { } - template <typename P> + template <typename G, typename C> template <typename D> - gen_box<P>::gen_box(const internal::initializer_<D>& data) : + current::box(const internal::initializer_<D>& data) : super(data) { } # endif // ! OLN_INCLUDE_ONLY +# undef current + } // end of namespace oln Index: oln/core/gen/fun.hh --- oln/core/gen/fun.hh (revision 943) +++ oln/core/gen/fun.hh (working copy) @@ -42,14 +42,9 @@ -// FIXME: Separate defs and decls. - - - namespace oln { - namespace internal { @@ -87,145 +82,184 @@ - // ----------------------------- fun_p2b_<F> + // fun_p2b_<F> + // ------------- - // Fwd decl. - template <typename F> struct fun_p2b_; - - // Category. - namespace internal - { - template <typename F> - struct set_category_of_< fun_p2b_<F> > - { - typedef stc::is< Function_p2b > ret; - }; - } - - // Class. template <typename F> struct fun_p2b_ : public Function_p2b< fun_p2b_<F> > { typedef oln_arg_of_(F) argument; typedef oln_res_of_(F) result; - fun_p2b_(const F& f) : f_(f) {} - - result operator()(argument arg) const - { - return this->f_(arg); - } + fun_p2b_(const F& f); + result operator()(argument arg) const; private: F f_; }; + template <typename B, typename P> + fun_p2b_<B (*)(P)> + functorize_p2b(B (*f)(P)); + + // Specialization. + template <typename I> - struct fun_p2b_< Binary_Image<I> > : public Function_p2b< fun_p2b_< Binary_Image<I> > > + struct fun_p2b_< Binary_Image<I> > + : + public Function_p2b< fun_p2b_< Binary_Image<I> > > { typedef const oln_point(I)& argument; typedef oln_rvalue(I) result; - fun_p2b_(const Binary_Image<I>& ima) - : ima_(exact(ima)) - {} - - result operator()(argument arg) const - { - return this->ima_(arg); - } + fun_p2b_(const I& ima); + oln_rvalue(I) operator()(const oln_point(I)& arg) const; private: I ima_; }; + template <typename I> + fun_p2b_< Binary_Image<I> > + functorize_p2b(const Binary_Image<I>& ima); - // ----------------------------- fun_p2v_<F> + // fun_p2v_<F> + // ------------- - // Fwd decl. - template <typename F> struct fun_p2v_; - // Category. - namespace internal - { template <typename F> - struct set_category_of_< fun_p2v_<F> > + struct fun_p2v_ : public Function_p2v< fun_p2v_<F> > { - typedef stc::is< Function_p2v > ret; + typedef oln_arg_of_(F) argument; + typedef oln_res_of_(F) result; + + fun_p2v_(const F& f); + result operator()(argument arg) const; + + private: + F f_; }; - } - // Class. + template <typename V, typename P> + fun_p2v_<V (*)(P)> + functorize_p2v(V (*f)(P)); + + + // fun_v2v_<F> + // ------------- + + template <typename F> - struct fun_p2v_ : public Function_p2v< fun_p2v_<F> > + struct fun_v2v_ : public Function_v2v< fun_v2v_<F> > { typedef oln_arg_of_(F) argument; typedef oln_res_of_(F) result; - fun_p2v_(const F& f) : f_(f) {} - - result operator()(argument arg) const - { - return this->f_(arg); - } + fun_v2v_(const F& f); + result operator()(argument arg) const; private: F f_; }; + template <typename Vr, typename Va> + fun_v2v_<Vr (*)(Va)> + functorize_v2v(Vr (*f)(Va)); - // functorize_p2v - template <typename V, typename P> - fun_p2v_<V (*)(P)> - functorize_p2v(V (*f)(P)) + +# ifndef OLN_INCLUDE_ONLY + + // fun_p2b_<F> + + template <typename F> + fun_p2b_<F>::fun_p2b_(const F& f) + : f_(f) { - mlc::assert_< mlc_is_a(P, Point) >::check(); // FIXME: Add err msg. - fun_p2v_<V (*)(P)> tmp(f); - return tmp; } + template <typename F> + typename fun_p2b_<F>::result + fun_p2b_<F>::operator()(typename fun_p2b_<F>::argument arg) const + { + return this->f_(arg); + } - // ----------------------------- fun_v2v_<F> + template <typename B, typename P> + fun_p2b_<B (*)(P)> + functorize_p2b(B (*f)(P)) + { + typedef mlc_basic(P) P_; + mlc::assert_< mlc_is_a(P_, Point) >::check(); + // FIXME: Add static check about B being Boolean. + fun_p2b_<B (*)(P)> tmp(f); + return tmp; + } + template <typename I> + fun_p2b_< Binary_Image<I> >::fun_p2b_(const I& ima) + : ima_(ima) + { + } - // Fwd decl. - template <typename F> struct fun_v2v_; + template <typename I> + oln_rvalue(I) + fun_p2b_< Binary_Image<I> >::operator()(const oln_point(I)& arg) const + { + return this->ima_(arg); + } - // Category. - namespace internal + template <typename I> + fun_p2b_< Binary_Image<I> > + functorize_p2b(const Binary_Image<I>& ima) { + fun_p2b_< Binary_Image<I> > tmp(exact(ima)); + return tmp; + } + + // fun_p2v_<F> + template <typename F> - struct set_category_of_< fun_v2v_<F> > + fun_p2v_<F>::fun_p2v_(const F& f) + : f_(f) { - typedef stc::is< Function_v2v > ret; - }; } - // Class. template <typename F> - struct fun_v2v_ : public Function_v2v< fun_v2v_<F> > + typename fun_p2v_<F>::result + fun_p2v_<F>::operator()(typename fun_p2v_<F>::argument arg) const { - typedef oln_arg_of_(F) argument; - typedef oln_res_of_(F) result; - - fun_v2v_(const F& f) : f_(f) {} + return this->f_(arg); + } - result operator()(argument arg) const + template <typename V, typename P> + fun_p2v_<V (*)(P)> + functorize_p2v(V (*f)(P)) { - return this->f_(arg); + typedef mlc_basic(P) P_; + mlc::assert_< mlc_is_a(P_, Point) >::check(); // FIXME: Add err msg. + fun_p2v_<V (*)(P)> tmp(f); + return tmp; } - private: - F f_; - }; + // fun_v2v_<F> + template <typename F> + fun_v2v_<F>::fun_v2v_(const F& f) + : f_(f) + { + } - // functorize_v2v + template <typename F> + typename fun_v2v_<F>::result + fun_v2v_<F>::operator()(typename fun_v2v_<F>::argument arg) const + { + return this->f_(arg); + } template <typename Vr, typename Va> fun_v2v_<Vr (*)(Va)> @@ -235,6 +269,7 @@ return tmp; } +# endif // ! OLN_INCLUDE_ONLY } // end of namespace oln Index: oln/core/gen/point.hh --- oln/core/gen/point.hh (revision 0) +++ oln/core/gen/point.hh (revision 0) @@ -0,0 +1,93 @@ +// 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 OLN_CORE_GEN_POINT_HH +# define OLN_CORE_GEN_POINT_HH + +# include <oln/core/internal/point_base.hh> +# include <oln/core/internal/point_impl.hh> + + +namespace oln +{ + +# define current point<G, C> + + + // Fwd decls. + template <typename G, typename C> struct point; + template <typename G, typename C> struct dpoint; + + + // Super type. + template<typename G, typename C> + struct super_trait_< current > + { + typedef internal::point_base_< current > ret; + }; + + + // Virtual types. + template <typename G, typename C> + struct vtypes< current > + { + typedef G grid; + typedef C coord; + typedef dpoint<G,C> dpoint; + }; + + + template <typename G, typename C> + class point : public internal::point_base_< current >, + public internal::point_impl_< mlc_value(oln_dim(G)), current > + { + public: + point(); + // nothing else here + }; + + + +# ifndef OLN_INCLUDE_ONLY + + template <typename G, typename C> + current::point() + { + mlc::assert_< mlc_is_a(G, Grid) >::check(); + } + +# endif // ! OLN_INCLUDE_ONLY + +# undef current + +} // end of namespace oln + + +# include <oln/core/gen/dpoint.hh> + + +#endif // ! OLN_CORE_GEN_POINT_HH Index: oln/core/gen/extended_by.hh --- oln/core/gen/extended_by.hh (revision 0) +++ oln/core/gen/extended_by.hh (revision 0) @@ -0,0 +1,60 @@ +// 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 OLN_CORE_GEN_EXTENDED_BY_HH +# define OLN_CORE_GEN_EXTENDED_BY_HH + + +// "ima + extension" + + +namespace oln +{ + struct extended_by; +} + + +# include <oln/core/internal/op_image_extended_by_nbh.hh> +# include <oln/core/internal/macro_extended_by.hh> + + +namespace oln +{ + + oln_decl_op_image_extended_by_const(Neighborhood); + + +# ifndef OLN_INCLUDE_ONLY + + oln_def_op_image_extended_by_const(Neighborhood); + +# endif // ! OLN_INCLUDE_ONLY + +} // end of namespace oln + + +#endif // ! OLN_CORE_GEN_EXTENDED_BY_HH Index: oln/core/gen/fbbox.hh --- oln/core/gen/fbbox.hh (revision 943) +++ oln/core/gen/fbbox.hh (working copy) @@ -31,7 +31,7 @@ # include <oln/core/gen/box.hh> # include <oln/core/concept/point.hh> -# include <oln/core/internal/point_set_base.hh> +# include <oln/core/internal/f_point_to_box.hh> namespace oln @@ -49,7 +49,7 @@ public: - typedef typename f_box_from_point_<P>::ret box_t; + typedef oln_f_point_to_box(P) box_t; fbbox_(); operator box_t() const; @@ -125,7 +125,6 @@ # endif // ! OLN_INCLUDE_ONLY - } // end of namespace oln Index: oln/core/gen/restricted_to.hh --- oln/core/gen/restricted_to.hh (revision 0) +++ oln/core/gen/restricted_to.hh (revision 0) @@ -0,0 +1,95 @@ +// 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 OLN_CORE_GEN_RESTRICTED_TO_HH +# define OLN_CORE_GEN_RESTRICTED_TO_HH + + +namespace oln +{ + struct restricted_to; +} + + +# include <oln/core/internal/op_image_restricted_to_pset.hh> +# include <oln/core/gen/inplace.hh> + + +namespace oln +{ + + // Image | Point_Set + + template <typename I, typename S> + op_<const I, restricted_to, const S> + operator | (const Image<I>& ima, const Point_Set<S>& pset); + + template <typename I, typename S> + op_<I, restricted_to, const S> + operator | (Mutable_Image<I>& ima, const Point_Set<S>& pset); + + template <typename I, typename S> + inplace_< op_<I, restricted_to, const S> > + operator | (inplace_<I> ima, const Point_Set<S>& pset); + + + +# ifndef OLN_INCLUDE_ONLY + + template <typename I, typename S> + op_<const I, restricted_to, const S> + operator | (const Image<I>& ima, const Point_Set<S>& pset) + { + mlc::assert_equal_< oln_point(S), oln_point(I) >::check(); + precondition(pset < ima.points()); + op_<const I, restricted_to, const S> tmp(exact(ima), exact(pset)); + return tmp; + } + + template <typename I, typename S> + op_<I, restricted_to, const S> + operator | (Mutable_Image<I>& ima, const Point_Set<S>& pset) + { + mlc::assert_equal_< oln_point(S), oln_point(I) >::check(); + precondition(pset < ima.points()); + op_<I, restricted_to, const S> tmp(exact(ima), exact(pset)); + return tmp; + } + + template <typename I, typename S> + inplace_< op_<I, restricted_to, const S> > + operator | (inplace_<I> ima, const Point_Set<S>& pset) + { + return (ima.unwrap() | pset).inplace(); + } + +# endif // ! OLN_INCLUDE_ONLY + +} // end of namespace oln + + +#endif // ! OLN_CORE_GEN_RESTRICTED_TO_HH Index: oln/core/gen/applied_on.hh --- oln/core/gen/applied_on.hh (revision 0) +++ oln/core/gen/applied_on.hh (revision 0) @@ -0,0 +1,134 @@ +// 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 OLN_CORE_GEN_APPLIED_ON_HH +# define OLN_CORE_GEN_APPLIED_ON_HH + + +// "f << ima" is "for all p, (f << ima)(p) = f(ima(p))" + + +namespace oln +{ + struct applied_on; +} + + +# include <oln/core/internal/op_fv2v_applied_on_image.hh> +# include <oln/core/gen/fun.hh> +# include <oln/core/gen/inplace.hh> + + +namespace oln +{ + + // Function_v2v << Image + + template <typename F, typename I> + op_<const F, applied_on, const I> + operator << (const Function_v2v<F>& f, const Image<I>& ima); + + template <typename F, typename I> + op_<const F, applied_on, I> + operator << (const Function_v2v<F>& f, Mutable_Image<I>& ima); + + template <typename F, typename I> + inplace_< op_<const F, applied_on, I> > + operator << (const Function_v2v<F>& f, inplace_<I> ima); + + // V -> V << Image + + template <typename W, typename V, typename I> + op_<const fun_v2v_<W (*)(V)>, applied_on, const I> + operator << (W (*f)(V), const Image<I>& ima); + + template <typename W, typename V, typename I> + op_<const fun_v2v_<W (*)(V)>, applied_on, I> + operator << (W (*f)(V), Mutable_Image<I>& ima); + + template <typename W, typename V, typename I> + inplace_< op_<const fun_v2v_<W (*)(V)>, applied_on, I> > + operator << (W (*f)(V), inplace_<I> ima); + + + +# ifndef OLN_INCLUDE_ONLY + + // Function_v2v << Image + + template <typename F, typename I> + op_<const F, applied_on, const I> + operator << (const Function_v2v<F>& f, const Image<I>& ima) + { + op_<const F, applied_on, const I> tmp(exact(f), exact(ima)); + return tmp; + } + + template <typename F, typename I> + op_<const F, applied_on, I> + operator << (const Function_v2v<F>& f, Mutable_Image<I>& ima) + { + op_<const F, applied_on, I> tmp(exact(f), exact(ima)); + return tmp; + } + + template <typename F, typename I> + inplace_< op_<const F, applied_on, I> > + operator << (const Function_v2v<F>& f, inplace_<I> ima) + { + return (f << ima.unwrap()).inplace(); + } + + // V -> V << Image + + template <typename W, typename V, typename I> + op_<const fun_v2v_<W (*)(V)>, applied_on, const I> + operator << (W (*f)(V), const Image<I>& ima) + { + return functorize_v2v(f) << ima; + } + + template <typename W, typename V, typename I> + op_<const fun_v2v_<W (*)(V)>, applied_on, I> + operator << (W (*f)(V), Mutable_Image<I>& ima) + { + return functorize_v2v(f) << ima; + } + + template <typename W, typename V, typename I> + inplace_< op_<const fun_v2v_<W (*)(V)>, applied_on, I> > + operator << (W (*f)(V), inplace_<I> ima) + { + return (f << ima.unwrap()).inplace(); + } + +# endif // ! OLN_INCLUDE_ONLY + +} // end of namespace oln + + +#endif // ! OLN_CORE_GEN_APPLIED_ON_HH Index: oln/core/gen/niter_has.hh --- oln/core/gen/niter_has.hh (revision 943) +++ oln/core/gen/niter_has.hh (working copy) @@ -28,7 +28,7 @@ #ifndef OLN_CORE_GEN_NITER_HAS_HH # define OLN_CORE_GEN_NITER_HAS_HH -# include <oln/core/concept/generalized_point.hh> +# include <oln/core/concept/point.hh> # include <oln/core/internal/piter_adaptor.hh> # include <oln/core/gen/dpoints_piter.hh> Index: oln/core/gen/op.hh --- oln/core/gen/op.hh (revision 943) +++ oln/core/gen/op.hh (working copy) @@ -30,111 +30,23 @@ # include <oln/core/internal/special_op.hh> # include <oln/core/internal/category_of.hh> -# include <oln/core/concept/function.hh> -# include <oln/core/concept/value.hh> -# include <oln/core/gen/inplace.hh> - - - -// Macro. - -# define oln_decl_op_(OpName, Lconcept, OpSym, Rconcept) \ - \ - template <typename L, typename R> \ - op_<L, OpName, R> \ - operator OpSym (Lconcept<L>& lhs, Rconcept<R>& rhs) \ - { \ - op_<L, OpName, R> tmp(exact(lhs), exact(rhs)); \ - return tmp; \ - } \ - \ - template <typename L, typename R> \ - op_<L, OpName, const R> \ - operator OpSym (Lconcept<L>& lhs, const Rconcept<R>& rhs) \ - { \ - op_<L, OpName, const R> tmp(exact(lhs), exact(rhs)); \ - return tmp; \ - } \ - \ - template <typename L, typename R> \ - op_<const L, OpName, R> \ - operator OpSym (const Lconcept<L>& lhs, Rconcept<R>& rhs) \ - { \ - op_<const L, OpName, R> tmp(exact(lhs), exact(rhs)); \ - return tmp; \ - } \ - \ - template <typename L, typename R> \ - op_<const L, OpName, const R> \ - operator OpSym (const Lconcept<L>& lhs, const Rconcept<R>& rhs) \ - { \ - op_<const L, OpName, const R> tmp(exact(lhs), exact(rhs)); \ - return tmp; \ - } \ - \ - struct e_n_d___w_i_t_h___a___s_e_m_i___c_o_l_u_m_n - - - -# define oln_decl_inplace_image_op(OpName, OpSym, Rconcept) \ - \ - template <typename L, typename R> \ - inplace_< op_<L, OpName, R> > \ - operator OpSym (inplace_<L> lhs, Rconcept<R>& rhs) \ - { \ - mlc::assert_< mlc_is_a(L, Mutable_Image) >::check(); \ - op_<L, OpName, R> tmp(lhs.unwrap(), exact(rhs)); \ - return inplace(tmp); \ - } \ - \ - struct e_n_d___w_i_t_h___a___s_e_m_i___c_o_l_u_m_n - - - -// FIXME: Split into different files so that the client can explicitly include -// what is really needed... - -# define oln_decl_op_extended_by(Lconcept, Rconcept) oln_decl_op_( extended_by, Lconcept, +, Rconcept) -# define oln_decl_op_such_as(Lconcept, Rconcept) oln_decl_op_( such_as, Lconcept, |, Rconcept) -# define oln_decl_op_restricted_to(Lconcept, Rconcept) oln_decl_op_( restricted_to, Lconcept, |, Rconcept) -# define oln_decl_op_over(Lconcept, Rconcept) oln_decl_op_( over, Lconcept, /, Rconcept) -# define oln_decl_op_applied_on(Lconcept, Rconcept) oln_decl_op_( applied_on, Lconcept, <<, Rconcept) -# define oln_decl_op_through(Lconcept, Rconcept) oln_decl_op_( through, Lconcept, >>, Rconcept) -// ... - namespace oln { - - /// \{ - /// Operator Names. - - struct extended_by; - struct such_as; - struct restricted_to; - struct over; - struct applied_on; - struct through; - - /// \} - - - - // Fwd decl. template <typename L, typename OpName, typename R> class op_; - /// Virtual types. + // Virtual types. template <typename L, typename OpName, typename R> struct vtypes< op_<L, OpName, R> > { }; - /// Super type. + // Super type. # define super \ internal::special_op_< oln_category_of_(L), L, OpName, oln_category_of_(R), R > Index: oln/core/gen/through.hh --- oln/core/gen/through.hh (revision 0) +++ oln/core/gen/through.hh (revision 0) @@ -0,0 +1,134 @@ +// 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 OLN_CORE_GEN_THROUGH_HH +# define OLN_CORE_GEN_THROUGH_HH + + +// "ima >> ima" is "for all p, (ima >> f)(p) = f(ima(p))" + + +namespace oln +{ + struct through; +} + + +# include <oln/core/internal/op_image_through_fv2v.hh> +# include <oln/core/gen/fun.hh> +# include <oln/core/gen/inplace.hh> + + +namespace oln +{ + + // Image >> Function_v2v + + template <typename I, typename F> + op_<const I, through, const F> + operator >> (const Image<I>& ima, const Function_v2v<F>& f); + + template <typename I, typename F> + op_<I, through, const F> + operator >> (Mutable_Image<I>& ima, const Function_v2v<F>& f); + + template <typename I, typename F> + inplace_< op_<I, through, const F> > + operator >> (inplace_<I> ima, const Function_v2v<F>& f); + + // Image >> V -> V + + template <typename I, typename W, typename V> + op_<const I, through, const fun_v2v_<W (*)(V)> > + operator >> (const Image<I>& ima, W (*f)(V)); + + template <typename I, typename W, typename V> + op_<I, through, const fun_v2v_<W (*)(V)> > + operator >> (Mutable_Image<I>& ima, W (*f)(V)); + + template <typename I, typename W, typename V> + inplace_< op_<I, through, const fun_v2v_<W (*)(V)> > > + operator >> (inplace_<I> ima, W (*f)(V)); + + + +# ifndef OLN_INCLUDE_ONLY + + // Image >> Function_v2v + + template <typename I, typename F> + op_<const I, through, const F> + operator >> (const Image<I>& ima, const Function_v2v<F>& f) + { + op_<const I, through, const F> tmp(exact(ima), exact(f)); + return tmp; + } + + template <typename I, typename F> + op_<I, through, const F> + operator >> (Mutable_Image<I>& ima, const Function_v2v<F>& f) + { + op_<I, through, const F> tmp(exact(ima), exact(f)); + return tmp; + } + + template <typename I, typename F> + inplace_< op_<I, through, const F> > + operator >> (inplace_<I> ima, const Function_v2v<F>& f) + { + return (ima.unwrap() >> f).inplace(); + } + + // Image >> V -> V + + template <typename I, typename W, typename V> + op_<const I, through, const fun_v2v_<W (*)(V)> > + operator >> (const Image<I>& ima, W (*f)(V)) + { + return ima >> functorize_v2v(f); + } + + template <typename I, typename W, typename V> + op_<I, through, const fun_v2v_<W (*)(V)> > + operator >> (Mutable_Image<I>& ima, W (*f)(V)) + { + return ima >> functorize_v2v(f); + } + + template <typename W, typename V, typename I> + inplace_< op_<I, through, const fun_v2v_<W (*)(V)> > > + operator >> (inplace_<I> ima, W (*f)(V)) + { + return (ima.unwrap() >> f).inplace(); + } + +# endif // ! OLN_INCLUDE_ONLY + +} // end of namespace oln + + +#endif // ! OLN_CORE_GEN_THROUGH_HH Index: oln/core/gen/such_as.hh --- oln/core/gen/such_as.hh (revision 0) +++ oln/core/gen/such_as.hh (revision 0) @@ -0,0 +1,220 @@ +// 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 OLN_CORE_GEN_SUCH_AS_HH +# define OLN_CORE_GEN_SUCH_AS_HH + + +namespace oln +{ + struct such_as; +} + + +# include <oln/core/internal/op_pset_such_as_fp2b.hh> +# include <oln/core/internal/op_image_such_as_fp2b.hh> +# include <oln/core/gen/fun.hh> +# include <oln/core/gen/inplace.hh> + + +namespace oln +{ + + // Point_Set | Function_p2b + + template <typename S, typename F> + op_<const S, such_as, const F> + operator | (const Point_Set<S>& pset, const Function_p2b<F>& f); + + + // Point_Set | P -> B + + template <typename S, typename B, typename P> + op_<const S, such_as, const fun_p2b_<B (*)(P)> > + operator | (const Point_Set<S>& lhs, B (*f)(P)); + + + // Image | Function_p2b + + template <typename I, typename F> + op_<const I, such_as, const F> + operator | (const Image<I>& ima, const Function_p2b<F>& f); + + template <typename I, typename F> + op_<I, such_as, const F> + operator | (Mutable_Image<I>& ima, const Function_p2b<F>& f); + + template <typename I, typename F> + inplace_< op_<I, such_as, const F> > + operator | (inplace_<I> ima, const Function_p2b<F>& f); + + + // Image | P -> B + + template <typename I, typename B, typename P> + op_<const I, such_as, const fun_p2b_<B (*)(P)> > + operator | (const Image<I>& ima, B (*f)(P)); + + template <typename I, typename B, typename P> + op_<I, such_as, const fun_p2b_<B (*)(P)> > + operator | (Mutable_Image<I>& ima, B (*f)(P)); + + template <typename I, typename B, typename P> + inplace_< op_<I, such_as, const fun_p2b_<B (*)(P)> > > + operator | (inplace_<I> ima, B (*f)(P)); + + + // Image | Binary_Image + + template <typename I, typename J> + op_<const I, such_as, const fun_p2b_< Binary_Image<J> > > + operator | (const Image<I>& ima, const Binary_Image<J>& f_ima_b); + + template <typename I, typename J> + op_<I, such_as, const fun_p2b_< Binary_Image<J> > > + operator | (Mutable_Image<I>& ima, const Binary_Image<J>& f_ima_b); + + template <typename I, typename J> + inplace_< op_<I, such_as, const fun_p2b_< Binary_Image<J> > > > + operator | (inplace_<I> ima, const Binary_Image<J>& f_ima_b); + + + + +# ifndef OLN_INCLUDE_ONLY + + // Point_Set | Function_p2b + + template <typename S, typename F> + op_<const S, such_as, const F> + operator | (const Point_Set<S>& pset, const Function_p2b<F>& f) + { + typedef mlc_basic(oln_argument(F)) P_; + mlc::assert_< mlc_is_a(P_, Point) >::check(); // FIXME: Add err msg. + mlc::assert_equal_< P_, oln_point(S) >::check(); + op_<const S, such_as, const F> tmp(exact(pset), exact(f)); + return tmp; + } + + // Point_Set | P -> B + + template <typename S, typename B, typename P> + op_<const S, such_as, const fun_p2b_<B (*)(P)> > + operator | (const Point_Set<S>& pset, B (*f)(P)) + { + return pset | functorize_p2b(f); + } + + // Image | Function_p2b + + template <typename I, typename F> + op_<const I, such_as, const F> + operator | (const Image<I>& ima, const Function_p2b<F>& f) + { + typedef mlc_basic(oln_argument(F)) P_; + mlc::assert_< mlc_is_a(P_, Point) >::check(); // FIXME: Add err msg. + mlc::assert_equal_< P_, oln_point(I) >::check(); + op_<const I, such_as, const F> tmp(exact(ima), exact(f)); + return tmp; + } + + template <typename I, typename F> + op_<I, such_as, const F> + operator | (Mutable_Image<I>& ima, const Function_p2b<F>& f) + { + typedef mlc_basic(oln_argument(F)) P_; + mlc::assert_< mlc_is_a(P_, Point) >::check(); // FIXME: Add err msg. + mlc::assert_equal_< P_, oln_point(I) >::check(); + op_<I, such_as, const F> tmp(exact(ima), exact(f)); + return tmp; + } + + template <typename I, typename F> + inplace_< op_<I, such_as, const F> > + operator | (inplace_<I> ima, const Function_p2b<F>& f) + { + return (ima.unwrap() | f).inplace(); + } + + // Image | P -> B + + template <typename I, typename B, typename P> + op_<const I, such_as, const fun_p2b_<B (*)(P)> > + operator | (const Image<I>& ima, B (*f)(P)) + { + return ima | functorize_p2b(f); + } + + template <typename I, typename B, typename P> + op_<I, such_as, const fun_p2b_<B (*)(P)> > + operator | (Mutable_Image<I>& ima, B (*f)(P)) + { + return ima | functorize_p2b(f); + } + + template <typename I, typename B, typename P> + inplace_< op_<I, such_as, const fun_p2b_<B (*)(P)> > > + operator | (inplace_<I> ima, B (*f)(P)) + { + return (ima.unwrap() | f).inplace(); + } + + // Image | Binary_Image + + template <typename I, typename J> + op_<const I, such_as, const fun_p2b_< Binary_Image<J> > > + operator | (const Image<I>& ima, const Binary_Image<J>& f) + { + precondition(f.points() >= ima.points()); + mlc::assert_equal_< oln_point(I), oln_point(J) >::check(); + op_<const I, such_as, const fun_p2b_< Binary_Image<J> > > tmp(exact(ima), exact(f)); + return tmp; + } + + template <typename I, typename J> + op_<I, such_as, const fun_p2b_< Binary_Image<J> > > + operator | (Mutable_Image<I>& ima, const Binary_Image<J>& f) + { + precondition(f.points() >= ima.points()); + mlc::assert_equal_< oln_point(I), oln_point(J) >::check(); + op_<I, such_as, const fun_p2b_< Binary_Image<J> > > tmp(exact(ima), exact(f)); + return tmp; + } + + template <typename I, typename J> + inplace_< op_<I, such_as, const fun_p2b_< Binary_Image<J> > > > + operator | (inplace_<I> ima, const Binary_Image<J>& f) + { + return (ima.unwrap() | f).inplace(); + } + +# endif // ! OLN_INCLUDE_ONLY + +} // end of namespace oln + + +#endif // ! OLN_CORE_GEN_SUCH_AS_HH Index: oln/core/gen/value_cast.hh --- oln/core/gen/value_cast.hh (revision 943) +++ oln/core/gen/value_cast.hh (working copy) @@ -31,45 +31,23 @@ # include <oln/core/gen/fun.hh> -// FIXME: Separate defs and decls. - - - namespace oln { + // casted_fun_<F, V> - // ----------------------------- casted_fp2v_<F, V> - - - // Fwd decl. - template <typename F, typename V> struct casted_fp2v_; - - // Category. - namespace internal - { - template <typename F, typename V> - struct set_category_of_< casted_fp2v_<F, V> > - { - typedef stc::is< Function_p2v > ret; - }; - } - - - // Class. template <typename F, typename V> - struct casted_fp2v_ : public Function_p2v< casted_fp2v_<F, V> > + struct casted_fun_ + : + public oln::internal::category_base_type_from_< F, casted_fun_<F, V> >::ret { typedef oln_arg_of_(F) argument; typedef oln_res_of_(F) f_result; typedef V result; - casted_fp2v_(const F& f) : f_(f) {} + casted_fun_(const Function<F>& f); - result operator()(argument arg) const - { - return static_cast<V>(this->f_(arg)); - } + result operator()(argument arg) const; private: F f_; @@ -79,16 +57,33 @@ // value_cast template <typename V, typename F> - casted_fp2v_<F, V> value_cast(const Function_p2v<F>& f) + casted_fun_<F, V> value_cast(const Function<F>& f); + + +# ifndef OLN_INCLUDE_ONLY + + template <typename F, typename V> + casted_fun_<F, V>::casted_fun_(const Function<F>& f) + : f_(exact(f)) { - // FIXME: Check that the cast "F::result -> V" is OK. - casted_fp2v_<F, V> tmp(exact(f)); - return tmp; } + template <typename F, typename V> + typename casted_fun_<F, V>::result + casted_fun_<F, V>::operator()(typename casted_fun_<F, V>::argument arg) const + { + return static_cast<V>(this->f_(arg)); + } - // FIXME: Add casted_fv2v_<F,V>? + template <typename V, typename F> + casted_fun_<F, V> value_cast(const Function<F>& f) + { + // FIXME: Check that the cast "F::result -> V" is OK. + casted_fun_<F, V> tmp(f); + return tmp; + } +# endif // ! OLN_INCLUDE_ONLY } // end of namespace oln Index: oln/core/gen/neighb.hh --- oln/core/gen/neighb.hh (revision 943) +++ oln/core/gen/neighb.hh (working copy) @@ -31,19 +31,11 @@ # include <oln/core/internal/dpoints_impl.hh> # include <oln/core/internal/neighborhood_base.hh> -# include <oln/core/internal/op_image_extended_by_nbh.hh> namespace oln { - - // Op. - oln_decl_op_extended_by(Image, Neighborhood); - oln_decl_inplace_image_op(extended_by, +, Neighborhood); - - - // Fwd decl. template <typename Dp> class neighb_; @@ -96,10 +88,13 @@ return *this; } -# endif - +# endif // ! OLN_INCLUDE_ONLY } // end of namespace oln +// FIXME: Bad! +# include <oln/core/gen/extended_by.hh> + + #endif // ! OLN_CORE_GEN_NEIGHB_HH Index: oln/core/gen/literal.hh --- oln/core/gen/literal.hh (revision 943) +++ oln/core/gen/literal.hh (working copy) @@ -33,13 +33,9 @@ # include <oln/core/concept/value.hh> - - namespace oln { - - // ----------------------------- literal_<T> @@ -48,120 +44,143 @@ { typedef const T& result; - literal_(const T& val) : val_(val) {} + literal_(const T& val); - result operator()() const - { - return this->val_; - } + const T& operator()() const; - operator T() const - { - return this->val_; - } + operator T() const; template <typename U> - operator literal_<U>() const - { - literal_<U> tmp(this->val_); - return tmp; - } + operator literal_<U>() const; - result value() const - { - return this->val_; - } + const T& value() const; private: T val_; }; - // literal template <typename T> - literal_<T> - literal(const T& val) - { - literal_<T> tmp(val); - return tmp; - } + literal_<T> literal(const T& val); // ----------------------------- lit_p2v_<P,T> - // Fwd decl. - template <typename P, typename T> struct lit_p2v_; - - // Category. - namespace internal + template <typename P, typename V> + struct lit_p2v_ : public Function_p2v< lit_p2v_<P,V> > { - template <typename P, typename T> - struct set_category_of_< lit_p2v_<P,T> > - { - typedef stc::is< Function_p2v > ret; + typedef P argument; + typedef const V& result; + + lit_p2v_(const V& val); + + const V& operator()(const P&) const; + + private: + V val_; }; - } - // Class. - template <typename P, typename T> - struct lit_p2v_ : public Function_p2v< lit_p2v_<P,T> > + + // ----------------------------- lit_p2b_<P,B> + + + template <typename P, typename B> + struct lit_p2b_ : public Function_p2b< lit_p2b_<P,B> > { typedef P argument; - typedef T result; + typedef const B& result; + + lit_p2b_(const B& val); + + const B& operator()(const P&) const; + + private: + B val_; + }; + + + + +# ifndef OLN_INCLUDE_ONLY - lit_p2v_(const T& val) + // literal_<T> + + template <typename T> + literal_<T>::literal_(const T& val) : val_(val) { } - result operator()(argument) const + template <typename T> + const T& + literal_<T>::operator()() const { return this->val_; } - private: - T val_; - }; + template <typename T> + literal_<T>::operator T() const + { + return this->val_; + } + template <typename T> + template <typename U> + literal_<T>::operator literal_<U>() const + { + literal_<U> tmp(this->val_); + return tmp; + } - // ----------------------------- lit_p2b_<P,B> + template <typename T> + const T& + literal_<T>::value() const + { + return this->val_; + } + + template <typename T> + literal_<T> + literal(const T& val) + { + literal_<T> tmp(val); + return tmp; + } - // Fwd decl. - template <typename P, typename B> struct lit_p2b_; + // lit_p2v_<P,V> - // Category. - namespace internal - { - template <typename P, typename B> - struct set_category_of_< lit_p2b_<P,B> > + template <typename P, typename V> + lit_p2v_<P,V>::lit_p2v_(const V& val) + : val_(val) { - typedef stc::is< Function_p2b > ret; - }; } - // Class. - template <typename P, typename B> - struct lit_p2b_ : public Function_p2b< lit_p2b_<P,B> > + template <typename P, typename V> + const V& + lit_p2v_<P,V>::operator()(const P&) const { - typedef P argument; - typedef B result; + return this->val_; + } - lit_p2b_(const B& val) + + //lit_p2b_<P,B> + + template <typename P, typename B> + lit_p2b_<P,B>::lit_p2b_(const B& val) : val_(val) { } - result operator()(argument) const + template <typename P, typename B> + const B& + lit_p2b_<P,B>::operator()(const P&) const { return this->val_; } - private: - B val_; - }; - +# endif // ! OLN_INCLUDE_ONLY } // end of namespace oln Index: oln/core/gen/dpoint.hh --- oln/core/gen/dpoint.hh (revision 0) +++ oln/core/gen/dpoint.hh (revision 0) @@ -0,0 +1,92 @@ +// 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 OLN_CORE_GEN_DPOINT_HH +# define OLN_CORE_GEN_DPOINT_HH + +# include <oln/core/internal/dpoint_base.hh> +# include <oln/core/internal/point_impl.hh> + + +namespace oln +{ + +# define current dpoint<G, C> + + // Fwd decls. + template <typename G, typename C> struct dpoint; + template <typename G, typename C> struct point; + + + // Super type. + template<typename G, typename C> + struct super_trait_< current > + { + typedef internal::dpoint_base_< current > ret; + }; + + + // Virtual types. + template <typename G, typename C> + struct vtypes< current > + { + typedef G grid; + typedef C coord; + typedef point<G,C> point; + }; + + + template <typename G, typename C> + class dpoint : public internal::dpoint_base_< current >, + public internal::point_impl_< mlc_value(oln_dim(G)), current > + { + public: + dpoint(); + // nothing else here + }; + + + +# ifndef OLN_INCLUDE_ONLY + + template <typename G, typename C> + current::dpoint() + { + mlc::assert_< mlc_is_a(G, Grid) >::check(); + } + +# endif // ! OLN_INCLUDE_ONLY + +# undef current + +} // end of namespace oln + + +# include <oln/core/gen/point.hh> + + +#endif // ! OLN_CORE_GEN_DPOINT_HH Index: oln/core/gen/image_stack.hh --- oln/core/gen/image_stack.hh (revision 943) +++ oln/core/gen/image_stack.hh (working copy) @@ -30,6 +30,7 @@ # include <oln/core/internal/image_base.hh> # include <oln/core/internal/value_proxy.hh> +# include <oln/core/internal/f_ch_value.hh> # include <mlc/int.hh> # include <xtd/vec.hh> Index: oln/core/gen/fun_ops.hh --- oln/core/gen/fun_ops.hh (revision 943) +++ oln/core/gen/fun_ops.hh (working copy) @@ -28,25 +28,13 @@ #ifndef OLN_CORE_GEN_FUN_OPS_HH # define OLN_CORE_GEN_FUN_OPS_HH -# include <oln/core/concept/function.hh> -# include <oln/core/concept/point.hh> +# include <oln/core/gen/fun.hh> # include <oln/core/gen/literal.hh> # define oln_decl_p2v_cmp_(Name, Sym) \ \ - template <typename L, typename R> struct p2v_##Name##_; \ - \ - namespace internal \ - { \ - template <typename L, typename R> \ - struct set_category_of_< p2v_##Name##_<L,R> > \ - { \ - typedef stc::is< Function_p2b > ret; \ - }; \ - } \ - \ template <typename L, typename R> \ struct p2v_##Name##_ : public Function_p2b< p2v_##Name##_<L,R> > \ { \ @@ -94,17 +82,6 @@ # define oln_decl_p2v_arith_(Name, Sym) \ \ - template <typename L, typename R> struct p2v_##Name##_; \ - \ - namespace internal \ - { \ - template <typename L, typename R> \ - struct set_category_of_< p2v_##Name##_<L,R> > \ - { \ - typedef stc::is< Function_p2v > ret; \ - }; \ - } \ - \ template <typename L, typename R> \ struct p2v_##Name##_ : public Function_p2v< p2v_##Name##_<L,R> > \ { \ @@ -151,17 +128,6 @@ # define oln_decl_p2v_un_(Name, Sym) \ \ - template <typename T> struct p2v_##Name##_; \ - \ - namespace internal \ - { \ - template <typename T> \ - struct set_category_of_< p2v_##Name##_<T> > \ - { \ - typedef stc::is< Function_p2v > ret; \ - }; \ - } \ - \ template <typename T> \ struct p2v_##Name##_ : public Function_p2v< p2v_##Name##_<T> > \ { \ @@ -194,17 +160,6 @@ # define oln_decl_p2b_bin_(Name, Sym) \ \ - template <typename L, typename R> struct p2b_##Name##_; \ - \ - namespace internal \ - { \ - template <typename L, typename R> \ - struct set_category_of_< p2b_##Name##_<L,R> > \ - { \ - typedef stc::is< Function_p2b > ret; \ - }; \ - } \ - \ template <typename L, typename R> \ struct p2b_##Name##_ : public Function_p2b< p2b_##Name##_<L,R> > \ { \ @@ -252,17 +207,6 @@ # define oln_decl_p2b_un_(Name, Sym) \ \ - template <typename T> struct p2b_##Name##_; \ - \ - namespace internal \ - { \ - template <typename T> \ - struct set_category_of_< p2b_##Name##_<T> > \ - { \ - typedef stc::is< Function_p2b > ret; \ - }; \ - } \ - \ template <typename T> \ struct p2b_##Name##_ : public Function_p2b< p2b_##Name##_<T> > \ { \ Index: oln/core/gen/over.hh --- oln/core/gen/over.hh (revision 0) +++ oln/core/gen/over.hh (revision 0) @@ -0,0 +1,108 @@ +// 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 OLN_CORE_GEN_OVER_HH +# define OLN_CORE_GEN_OVER_HH + + +namespace oln +{ + struct over; +} + + +# include <oln/core/internal/op_fp2v_over_pset.hh> +# include <oln/core/gen/fun.hh> +# include <oln/core/gen/literal.hh> + + +namespace oln +{ + + // Function_p2v / Point_Set + + template <typename F, typename S> + op_<const F, over, const S> + operator / (const Function_p2v<F>& f, const Point_Set<S>& pset); + + + // (P -> V) / Point_Set + + template <typename V, typename P, typename S> + op_<const fun_p2v_<V (*)(P)>, over, const S> + operator / (V (*f)(P), const Point_Set<S>& pset); + + + // V / Point_Set + + template <typename V, typename S> + op_<const lit_p2v_<oln_point(S), V>, over, const S> + operator / (const literal_<V>& value, const Point_Set<S>& pset); + + + +# ifndef OLN_INCLUDE_ONLY + + // Function_p2v / Point_Set + + template <typename F, typename S> + op_<const F, over, const S> + operator / (const Function_p2v<F>& f, const Point_Set<S>& pset) + { + typedef mlc_basic(oln_argument(F)) P_; + mlc::assert_< mlc_is_a(P_, Point) >::check(); // FIXME: Add err msg. + mlc::assert_equal_< P_, oln_point(S) >::check(); + op_<const F, over, const S> tmp(exact(f), exact(pset)); + return tmp; + } + + // P -> V / Point_Set + + template <typename V, typename P, typename S> + op_<const fun_p2v_<V (*)(P)>, over, const S> + operator / (V (*f)(P), const Point_Set<S>& pset) + { + return functorize_p2v(f) / pset; + } + + // V / Point_Set + + template <typename V, typename S> + op_<const lit_p2v_<oln_point(S), V>, over, const S> + operator / (const literal_<V>& value, const Point_Set<S>& pset) + { + lit_p2v_<oln_point(S), V> lit(value); + op_<const lit_p2v_<oln_point(S), V>, over, const S> tmp(lit, exact(pset)); + return tmp; + } + +# endif // ! OLN_INCLUDE_ONLY + +} // end of namespace oln + + +#endif // ! OLN_CORE_GEN_OVER_HH Index: oln/core/internal/f_grid_to_plain_image.hh --- oln/core/internal/f_grid_to_plain_image.hh (revision 943) +++ oln/core/internal/f_grid_to_plain_image.hh (working copy) @@ -48,12 +48,15 @@ struct grid2d_hex; struct grid2d_tri; - // FIXME: 3D... + struct grid3d; + + // FIXME: ... // Image types. template <typename T> class image1d; template <typename T> class image2d; + template <typename T> class image3d; /// \} @@ -85,7 +88,13 @@ typedef image2d<T> ret; // FIXME: or image2d_b<T>? }; - // FIXME: 2D hex/tri, 3D... + template <typename T> + struct grid_to_plain_image__< grid3d, T > + { + typedef image3d<T> ret; // FIXME: or image3d_b<T>? + }; + + // FIXME: 2D hex/tri... /// \} Index: oln/core/internal/op_image_through_fv2v.hh --- oln/core/internal/op_image_through_fv2v.hh (revision 943) +++ oln/core/internal/op_image_through_fv2v.hh (working copy) @@ -84,7 +84,7 @@ namespace internal { - /// Implementation class for the result of "Function_v2v F << Image I". + /// Implementation class for the result of "Image I >> Function_v2v F". template <typename I, typename F> class current : public super Index: oln/core/internal/box.hh --- oln/core/internal/box.hh (revision 943) +++ oln/core/internal/box.hh (working copy) @@ -49,7 +49,7 @@ }; - /// Virtual types associated to oln::box_<P>. + // Virtual types associated to oln::box_<P>. template <typename Exact> struct vtypes< internal::box_<Exact> > { @@ -111,7 +111,7 @@ - /// Super types. + // Super types. template <typename B> struct super_trait_< box_fwd_piter_<B> > @@ -128,7 +128,7 @@ }; - /// Virtual types. + // Virtual types. template <typename B> struct vtypes< box_fwd_piter_<B> > @@ -233,7 +233,7 @@ template <typename D> box_<Exact>::box_(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); } Index: oln/core/internal/point_set_base.hh --- oln/core/internal/point_set_base.hh (revision 943) +++ oln/core/internal/point_set_base.hh (working copy) @@ -34,29 +34,6 @@ namespace oln { - // function : point -> box - - template <typename P> class gen_box; - - template <typename P> - struct f_box_from_point_ { typedef gen_box<P> ret; }; - - class point1d; - class box1d; - - template <> - struct f_box_from_point_< point1d > { typedef box1d ret; }; - - class point2d; - class box2d; - - template <> - struct f_box_from_point_< point2d > { typedef box2d ret; }; - - // FIXME: Move the code above elsewhere. - - - namespace internal { @@ -75,9 +52,8 @@ // point_set_base_ class - // Fwd decls. + // Fwd decl. namespace internal { template <typename Exact> struct point_set_base_; } - template <typename P> class gen_box; // Super type. @@ -102,6 +78,7 @@ typedef stc::final< stc::is<Point_Set> > category; typedef stc::final< oln_grid(point__) > grid; + // typedef stc::final< oln_coord(point__) > coord; typedef stc::final< fwd_piter__ > piter; }; @@ -126,45 +103,11 @@ { } -# endif +# endif // ! OLN_INCLUDE_ONLY } // end of namespace oln::internal } // end of namespace oln - -/// \{ -/// FIXME: Bad! - -# include <oln/core/gen/fun.hh> -# include <oln/core/internal/op_pset_such_as_fp2b.hh> - -namespace oln -{ - - // Point_Set | Function. - - oln_decl_op_such_as(Point_Set, Function_p2b); - - - // Specialization. - - template <typename S, typename B, typename P> - op_<const S, such_as, const fun_p2b_<B (*)(P)> > - operator | (const Point_Set<S>& lhs, B (*f)(P)) - { - typedef mlc_basic(P) P_; - mlc::assert_< mlc_is_a(P_, Point) >::check(); // FIXME: Add err msg. - mlc::assert_equal_< P_, oln_point(S) >::check(); - op_<const S, such_as, const fun_p2b_<B (*)(P)> > tmp(exact(lhs), f); - return tmp; - } - - -} // end of namespace oln - -/// \} - - #endif // ! OLN_CORE_INTERNAL_POINT_SET_BASE_HH Index: oln/core/internal/op_image_such_as_fp2b.hh --- oln/core/internal/op_image_such_as_fp2b.hh (revision 943) +++ oln/core/internal/op_image_such_as_fp2b.hh (working copy) @@ -28,10 +28,15 @@ #ifndef OLN_CORE_INTERNAL_OP_IMAGE_SUCH_AS_FP2B_HH # define OLN_CORE_INTERNAL_OP_IMAGE_SUCH_AS_FP2B_HH -# include <oln/core/internal/op_image_restricted_to_pset.hh> +# include <oln/core/gen/restricted_to.hh> # include <oln/core/internal/op_pset_such_as_fp2b.hh> +// "ima such_as f : p -> b" is "ima restricted_to (ima.points such_as f)" + +// FIXME: That's cool but too much code is involved... +// FIXME: ...So write a specialized version! + namespace oln { Index: oln/core/internal/f_grid_to_box.hh --- oln/core/internal/f_grid_to_box.hh (revision 943) +++ oln/core/internal/f_grid_to_box.hh (working copy) @@ -43,18 +43,18 @@ // Grid types. struct grid1d; - struct grid2d; struct grid2d_hex; struct grid2d_tri; - - // FIXME: 3D... + struct grid3d; + // ... // Box types. struct box1d; struct box2d; - template <typename P> class gen_box; + struct box3d; + // ... /// \} @@ -86,7 +86,13 @@ typedef box2d ret; }; - // FIXME: 2D hex/tri, 3D... + // FIXME: 2D hex/tri... + + template <> + struct grid_to_box__< grid3d > + { + typedef box3d ret; + }; /// \} Index: oln/core/internal/f_point_to_box.hh --- oln/core/internal/f_point_to_box.hh (revision 0) +++ oln/core/internal/f_point_to_box.hh (revision 0) @@ -0,0 +1,112 @@ +// 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 OLN_CORE_INTERNAL_F_POINT_TO_BOX_HH +# define OLN_CORE_INTERNAL_F_POINT_TO_BOX_HH + +# include <oln/core/concept/point.hh> + + +# define oln_f_point_to_box(P) \ +typename oln::internal::f_point_to_box_< P >::ret + + +namespace oln +{ + + /// \{ + /// Forward declarations. + + // Point types. + + struct point1d; + struct point2d; + struct point3d; + template <typename G, typename C> class point; + + // Box types. + + struct box1d; + struct box2d; + struct box3d; + template <typename G, typename C> class box; + + /// \} + + + + namespace internal + { + + template <typename P> + struct point_to_box__; + + + /// \{ + /// Definitions. + + template <typename G, typename C> + struct point_to_box__< point<G, C> > + { + typedef box<G, C> ret; + }; + + template <> + struct point_to_box__< point1d > + { + typedef box1d ret; + }; + + template <> + struct point_to_box__< point2d > + { + typedef box2d ret; + }; + + // FIXME: 2D hex/tri... + + template <> + struct point_to_box__< point3d > + { + typedef box3d ret; + }; + + /// \} + + + template <typename P> + struct f_point_to_box_ : private mlc::assert_< mlc_is_a(P, Point) >, + public point_to_box__< P > + { + }; + + } // end of namespace oln::internal + +} // end of namespace oln + + +#endif // ! OLN_CORE_INTERNAL_F_POINT_TO_BOX_HH Index: oln/core/internal/point_impl.hh --- oln/core/internal/point_impl.hh (revision 0) +++ oln/core/internal/point_impl.hh (revision 0) @@ -0,0 +1,199 @@ +// 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 OLN_CORE_INTERNAL_POINT_IMPL_HH +# define OLN_CORE_INTERNAL_POINT_IMPL_HH + +# include <oln/core/equipment.hh> + + +namespace oln +{ + + namespace internal + { + + // default + + template <unsigned dim, typename Exact> + struct point_impl_ + { + // nothing + }; + + + // dim = 1 + + template <typename Exact> + struct point_impl_< 1, Exact > + { + private: + stc_typename(coord); + public: + + coord ind() const; + coord& ind(); + }; + + + // dim = 2 + + template <typename Exact> + struct point_impl_< 2, Exact > + { + private: + stc_typename(coord); + public: + + coord row() const; + coord& row(); + + coord col() const; + coord& col(); + }; + + + // dim = 3 + + template <typename Exact> + struct point_impl_< 3, Exact > + { + private: + stc_typename(coord); + public: + + coord sli() const; + coord& sli(); + + coord row() const; + coord& row(); + + coord col() const; + coord& col(); + }; + + +# ifndef OLN_INCLUDE_ONLY + + // dim = 1 + + template <typename Exact> + typename point_impl_<1, Exact>::coord + point_impl_<1, Exact>::ind() const + { + return static_cast<const Exact&>(*this)[0]; + } + + template <typename Exact> + typename point_impl_<1, Exact>::coord & + point_impl_<1, Exact>::ind() + { + return static_cast<Exact&>(*this)[0]; + } + + // dim = 2 + + template <typename Exact> + typename point_impl_<2, Exact>::coord + point_impl_<2, Exact>::row() const + { + return static_cast<const Exact&>(*this)[0]; + } + + template <typename Exact> + typename point_impl_<2, Exact>::coord & + point_impl_<2, Exact>::row() + { + return static_cast<Exact&>(*this)[0]; + } + + template <typename Exact> + typename point_impl_<2, Exact>::coord + point_impl_<2, Exact>::col() const + { + return static_cast<const Exact&>(*this)[1]; + } + + template <typename Exact> + typename point_impl_<2, Exact>::coord & + point_impl_<2, Exact>::col() + { + return static_cast<Exact&>(*this)[1]; + } + + // dim = 3 + + template <typename Exact> + typename point_impl_<3, Exact>::coord + point_impl_<3, Exact>::sli() const + { + return static_cast<const Exact&>(*this)[0]; + } + + template <typename Exact> + typename point_impl_<3, Exact>::coord & + point_impl_<3, Exact>::sli() + { + return static_cast<Exact&>(*this)[0]; + } + + template <typename Exact> + typename point_impl_<3, Exact>::coord + point_impl_<3, Exact>::row() const + { + return static_cast<const Exact&>(*this)[1]; + } + + template <typename Exact> + typename point_impl_<3, Exact>::coord & + point_impl_<3, Exact>::row() + { + return static_cast<Exact&>(*this)[1]; + } + + template <typename Exact> + typename point_impl_<3, Exact>::coord + point_impl_<3, Exact>::col() const + { + return static_cast<const Exact&>(*this)[2]; + } + + template <typename Exact> + typename point_impl_<3, Exact>::coord & + point_impl_<3, Exact>::col() + { + return static_cast<Exact&>(*this)[2]; + } + +# endif // ! OLN_INCLUDE_ONLY + + } // end of namespace oln::internal + +} // end of namespace oln + + +#endif // ! OLN_CORE_INTERNAL_POINT_IMPL_HH Index: oln/core/internal/macro_extended_by.hh --- oln/core/internal/macro_extended_by.hh (revision 0) +++ oln/core/internal/macro_extended_by.hh (revision 0) @@ -0,0 +1,128 @@ +// 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 OLN_CORE_INTERNAL_MACRO_EXTENDED_BY_HH +# define OLN_CORE_INTERNAL_MACRO_EXTENDED_BY_HH + + +# include <oln/core/gen/inplace.hh> + + +# define oln_decl_op_image_extended_by_const(Concept) \ + \ + template <typename I, typename E> \ + op_<const I, extended_by, const E> \ + operator + (const Image<I>& ima, const Concept<E>& ext); \ + \ + template <typename I, typename E> \ + op_<I, extended_by, const E> \ + operator + (Mutable_Image<I>& ima, const Concept<E>& ext); \ + \ + template <typename I, typename E> \ + inplace_< op_<I, extended_by, const E> > \ + operator + (inplace_<I> ima, const Concept<E>& ext); \ + \ + struct e_n_d___w_i_t_h___s_e_m_i_c_o_l_u_m_n + + + +# define oln_decl_op_image_extended_by_mutable(Concept) \ + \ + template <typename I, typename E> \ + op_<const I, extended_by, E> \ + operator + (const Image<I>& ima, Concept<E>& ext); \ + \ + template <typename I, typename E> \ + op_<I, extended_by, E> \ + operator + (Mutable_Image<I>& ima, Concept<E>& ext); \ + \ + template <typename I, typename E> \ + inplace_< op_<I, extended_by, E> > \ + operator + (inplace_<I> ima, Concept<E>& ext); \ + \ + struct e_n_d___w_i_t_h___s_e_m_i_c_o_l_u_m_n + + + +# define oln_def_op_image_extended_by_const(Concept) \ + \ + template <typename I, typename E> \ + op_<const I, extended_by, const E> \ + operator + (const Image<I>& ima, const Concept<E>& ext) \ + { \ + op_<const I, extended_by, const E> tmp(exact(ima), exact(ext)); \ + return tmp; \ + } \ + \ + template <typename I, typename E> \ + op_<I, extended_by, const E> \ + operator + (Mutable_Image<I>& ima, const Concept<E>& ext) \ + { \ + op_<I, extended_by, const E> tmp(exact(ima), exact(ext)); \ + return tmp; \ + } \ + \ + template <typename I, typename E> \ + inplace_< op_<I, extended_by, const E> > \ + operator + (inplace_<I> ima, const Concept<E>& ext) \ + { \ + return (ima.unwrap() + ext).inplace(); \ + } \ + \ + struct e_n_d___w_i_t_h___s_e_m_i_c_o_l_u_m_n + + + +# define oln_def_op_image_extended_by_mutable(Concept) \ + \ + template <typename I, typename E> \ + op_<const I, extended_by, E> \ + operator + (const Image<I>& ima, Concept<E>& ext) \ + { \ + op_<const I, extended_by, E> tmp(exact(ima), exact(ext)); \ + return tmp; \ + } \ + \ + template <typename I, typename E> \ + op_<I, extended_by, E> \ + operator + (Mutable_Image<I>& ima, Concept<E>& ext) \ + { \ + op_<I, extended_by, E> tmp(exact(ima), exact(ext)); \ + return tmp; \ + } \ + \ + template <typename I, typename E> \ + inplace_< op_<I, extended_by, E> > \ + operator + (inplace_<I> ima, Concept<E>& ext) \ + { \ + return (ima.unwrap() + ext).inplace(); \ + } \ + \ + struct e_n_d___w_i_t_h___s_e_m_i_c_o_l_u_m_n + + +#endif // ! OLN_CORE_INTERNAL_MACRO_EXTENDED_BY_HH Index: oln/core/internal/image_base.hh --- oln/core/internal/image_base.hh (revision 943) +++ oln/core/internal/image_base.hh (working copy) @@ -514,14 +514,7 @@ # endif // ! OLN_INCLUDE_ONLY - } // end of namespace oln - -// FIXME: Bad! -# include <oln/core/internal/image_ops.hh> - - - #endif // ! OLN_CORE_INTERNAL_IMAGE_BASE_HH Index: oln/core/internal/point_set_std_based.hh --- oln/core/internal/point_set_std_based.hh (revision 943) +++ oln/core/internal/point_set_std_based.hh (working copy) @@ -66,7 +66,7 @@ typedef stc::final< point__ > point; typedef stc::final< pset_std_based_fwd_piter_<std_container__> > fwd_piter; typedef stc::final< pset_std_based_bkd_piter_<std_container__> > bkd_piter; - typedef stc::final< typename f_box_from_point_<point__>::ret > box; + typedef stc::final< oln_f_point_to_box(point__) > box; }; Index: oln/core/internal/op_fv2v_applied_on_image.hh --- oln/core/internal/op_fv2v_applied_on_image.hh (revision 943) +++ oln/core/internal/op_fv2v_applied_on_image.hh (working copy) @@ -64,8 +64,8 @@ typedef I delegatee; typedef internal::pair<I,F> data; - typedef oln_result(F) rvalue; - typedef mlc_basic(rvalue) value; + typedef mlc_basic(oln_result(F)) value; + typedef value rvalue; typedef typename mlc::if_< mlc::and_list_< mlc_is_not_const(I), stc_is_found_type(I, lvalue), Index: oln/core/internal/point_base.hh --- oln/core/internal/point_base.hh (revision 943) +++ oln/core/internal/point_base.hh (working copy) @@ -50,8 +50,8 @@ template <typename Exact> struct vtypes< internal::point_base_<Exact> > { - typedef stc::abstract grid; // FIXME: Could be defined and final? - typedef stc::abstract coord; // FIXME: Likewise? + typedef stc::abstract grid; + typedef stc::abstract coord; typedef stc::abstract dpoint; typedef stc_deferred(grid) grid__; Index: oln/core/internal/category_of.hh --- oln/core/internal/category_of.hh (revision 943) +++ oln/core/internal/category_of.hh (working copy) @@ -29,62 +29,69 @@ # define OLN_CORE_INTERNAL_CATEGORY_OF_HH # include <mlc/basic.hh> +# include <oln/core/internal/utils.hh> -# define oln_category_of_(Type) typename oln::internal::category_of_< Type >::ret +# define oln_category_of_(Type) \ + typename oln::internal::category_of_< Type >::ret + namespace oln { - // Fwd decls. - template <typename Exact> struct Boolean; - - - namespace internal { - // Category_of_ - + template <typename T1, typename T2> + struct get_category_of_ + : private mlc::abort_< pair<T1,T2> > // FIXME: Add error msg. + { + }; - template <typename T> - struct set_category_of_ + template <template <class> class C> + struct get_category_of_< C<void>, mlc::not_found > { - typedef stc_type(T, category) ret; + typedef stc::is<C> ret; }; - template <> - struct set_category_of_< bool > // FIXME: Move into oln/core/value/*. + template <template <class> class C> + struct get_category_of_< mlc::not_found, stc::is<C> > { - typedef stc::is< Boolean > ret; + typedef stc::is<C> ret; }; + // category_of_ + template <typename T> struct category_of_ { - typedef typename set_category_of_< mlc_basic(T) >::ret ret; + typedef mlc_basic(T) T__; + typedef mlc_typedef(T__, category) ret_1; + typedef stc_find_type(T__, category) ret_2; + typedef typename get_category_of_<ret_1, ret_2>::ret ret; }; - // ... - + template <class C, typename Exact> + struct get_category_base_type_; - // only_if_ - - template < typename Ret, - typename Check_1, - typename Check_2 = void, - typename Check_3 = void, - typename Check_4 = void > - struct only_if_ + template <template <class> class C, typename Exact> + struct get_category_base_type_< stc::is<C>, Exact > { - typedef Ret ret; + typedef C<Exact> ret; }; + // category_base_type_from_ + template <typename From, typename Exact> + struct category_base_type_from_ + { + typedef oln_category_of_(From) C; + typedef typename get_category_base_type_<C, Exact>::ret ret; + }; } // end of namespace oln::internal Index: oln/core/internal/iterator_on_points_impl.hh --- oln/core/internal/iterator_on_points_impl.hh (revision 943) +++ oln/core/internal/iterator_on_points_impl.hh (working copy) @@ -25,116 +25,109 @@ // reasons why the executable file might be covered by the GNU General // Public License. - #ifndef OLN_CORE_INTERNAL_ITERATOR_ON_POINTS_IMPL_HH # define OLN_CORE_INTERNAL_ITERATOR_ON_POINTS_IMPL_HH +# include <oln/core/equipment.hh> -namespace oln -{ - // Forward declarations - namespace impl +namespace oln { - template <unsigned n, typename Exact, typename P> - struct iterator_on_points_impl; - } - - template <unsigned n, typename Exact, typename P> - struct super_trait_< impl::iterator_on_points_impl<n, Exact, P> > + namespace internal { - typedef Any<P> ret; - }; - template <unsigned n, typename Exact, typename P> - struct vtypes< impl::iterator_on_points_impl<n, Exact, P> > + template <unsigned n, typename Exact> + struct iterator_on_points_impl_ { }; - - namespace impl - { - template <unsigned n, typename Exact, typename P> - struct iterator_on_points_impl : public virtual Any<Exact> + // 1d impl + template <typename Exact> + struct iterator_on_points_impl_< 1, Exact > { + private: + stc_typename(coord); + public: + coord ind() const; }; - /// point1d interface - template <typename Exact, typename P> - struct iterator_on_points_impl<1, Exact, P> : public virtual Any< Exact > + // 2d impl + template <typename Exact> + struct iterator_on_points_impl_< 2, Exact > { - typename P::coord ind() const; + private: + stc_typename(coord); + public: + coord row() const; + coord col() const; }; - /// point2d interface - template <typename Exact, typename P> - struct iterator_on_points_impl<2, Exact, P>: public virtual Any< Exact > + // 3d impl + template <typename Exact> + struct iterator_on_points_impl_< 3, Exact > { - typename P::coord row() const; - typename P::coord col() const; - }; - - /// point3d interface - template <typename Exact, typename P> - struct iterator_on_points_impl<3, Exact, P>: public virtual Any< Exact > - { - typename P::coord row() const; - typename P::coord col() const; - typename P::coord slice() const; + private: + stc_typename(coord); + public: + coord sli() const; + coord row() const; + coord col() const; }; # ifndef OLN_INCLUDE_ONLY - // point1d - template <typename Exact, typename P> - typename P::coord - iterator_on_points_impl<1, Exact, P>::ind() const + // 1d impl + + template <typename Exact> + typename iterator_on_points_impl_<1, Exact>::coord + iterator_on_points_impl_<1, Exact>::ind() const { - return exact(this)->to_point().ind(); + return static_cast<const Exact&>(*this).to_point().ind(); } - // point2d - template <typename Exact, typename P> - typename P::coord - iterator_on_points_impl<2, Exact, P>::row() const + // 2d impl + + template <typename Exact> + typename iterator_on_points_impl_<2, Exact>::coord + iterator_on_points_impl_<2, Exact>::row() const { - return exact(this)->to_point().row(); + return static_cast<const Exact&>(*this).to_point().row(); } - - template <typename Exact, typename P> - typename P::coord - iterator_on_points_impl<2, Exact, P>::col() const + template <typename Exact> + typename iterator_on_points_impl_<2, Exact>::coord + iterator_on_points_impl_<2, Exact>::col() const { - return exact(this)->to_point().col(); + return static_cast<const Exact&>(*this).to_point().col(); } - // point3d - template <typename Exact, typename P> - typename P::coord - iterator_on_points_impl<3, Exact, P>::row() const + // 3d impl + + template <typename Exact> + typename iterator_on_points_impl_<3, Exact>::coord + iterator_on_points_impl_<3, Exact>::sli() const { - return exact(this)->to_point().row(); + return static_cast<const Exact&>(*this).to_point().sli(); } - template <typename Exact, typename P> - typename P::coord - iterator_on_points_impl<3, Exact, P>::col() const + template <typename Exact> + typename iterator_on_points_impl_<3, Exact>::coord + iterator_on_points_impl_<3, Exact>::row() const { - return exact(this)->to_point().col(); + return static_cast<const Exact&>(*this).to_point().row(); } - template <typename Exact, typename P> - typename P::coord - iterator_on_points_impl<3, Exact, P>::slice() const + template <typename Exact> + typename iterator_on_points_impl_<3, Exact>::coord + iterator_on_points_impl_<3, Exact>::col() const { - return exact(this)->to_point().slice(); + return static_cast<const Exact&>(*this).to_point().col(); } # endif // ! OLN_INCLUDE_ONLY - } // end of namespace oln + } // end of namespace oln::internal } // end of namespace oln Index: oln/core/internal/f_pset_to_plain_image.hh --- oln/core/internal/f_pset_to_plain_image.hh (revision 943) +++ oln/core/internal/f_pset_to_plain_image.hh (working copy) @@ -32,7 +32,8 @@ # include <oln/core/internal/f_grid_to_plain_image.hh> -#define oln_f_pset_to_plain_image(Ps, T) typename oln::internal::f_pset_to_plain_image_< Ps, T >::ret +# define oln_f_pset_to_plain_image(Ps, T) \ + typename oln::internal::f_pset_to_plain_image_< Ps, T >::ret namespace oln @@ -42,7 +43,7 @@ /// Forward declarations. // point set types - template <typename P> class gen_box; + template <typename G, typename C> class box; class box1d; class box2d; // FIXME: ... @@ -95,10 +96,16 @@ // ... - template <typename P, typename T> - struct pset_to_plain_image__< gen_box<P>, T > + template <typename G, typename T> + struct pset_to_plain_image__< box<G, int>, T > { - typedef oln_f_grid_to_plain_image(oln_grid(P), T) ret; + typedef oln_f_grid_to_plain_image(G, T) ret; + }; + + template <typename G, typename C, typename T> + struct pset_to_plain_image__< box<G, C>, T > + { + // FIXME: Not impled yet (every C should be handled; not only int). }; template <typename S, typename F_p2b, typename T> Index: oln/core/internal/iterator_on_points_base.hh --- oln/core/internal/iterator_on_points_base.hh (revision 943) +++ oln/core/internal/iterator_on_points_base.hh (working copy) @@ -58,9 +58,6 @@ typedef stc::final< oln_coord(point__) > coord; typedef stc::final< oln_dim(point__) > dim; typedef stc::final< oln_dpoint(point__) > dpoint; - - // for getting point implementation - typedef stc_deferred(dim) dim__; }; @@ -68,10 +65,9 @@ { template <typename Exact> - class iterator_on_points_base_ : public Iterator_on_Points<Exact>, - public impl::iterator_on_points_impl - <mlc_value(typename vtypes< internal::iterator_on_points_base_<Exact> >::dim__), - Exact, typename vtypes< internal::iterator_on_points_base_<Exact> >::point__> + class iterator_on_points_base_ + : public Iterator_on_Points<Exact>, + public internal::iterator_on_points_impl_<mlc_value(stc_deferred(dim)), Exact> { protected: iterator_on_points_base_(); @@ -91,4 +87,5 @@ } // end of namespace oln + #endif // ! OLN_CORE_INTERNAL_ITERATOR_ON_POINTS_BASE_HH Index: oln/stc/scoop.hh --- oln/stc/scoop.hh (revision 943) +++ oln/stc/scoop.hh (working copy) @@ -136,6 +136,7 @@ // For concepts. # define stc_typename(Type) typedef stc_type(Exact, Type) Type # define stc_using(Type) typedef typename super::Type Type +# define stc_using_(Type) typedef super::Type Type # define stc_using_from(Abstraction, Type) typedef typename Abstraction<Exact>::Type Type # define stc_deduce_typename(Src, Type) typedef stc_type(Src, Type) Type Index: oln/draw/bresenham.hh --- oln/draw/bresenham.hh (revision 943) +++ oln/draw/bresenham.hh (working copy) @@ -30,9 +30,11 @@ # include <oln/core/concept/image.hh> # include <oln/core/gen/inplace.hh> -# include <oln/core/2d/line2d.hh> +# include <oln/core/gen/over.hh> # include <oln/level/paste.hh> +# include <oln/core/2d/line2d.hh> // FIXME: 2D! + namespace oln
participants (1)
-
Thierry Geraud