
https://svn.lrde.epita.fr/svn/oln/trunk/olena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Introduce 'prepare' to initialize image structures. * oln/core/concept/image.hh (Image_2D): Add min_row, max_row, min_col, and max_col. * oln/debug/print.hh: Update. * oln/level/apply_local.hh (init): Replace by prepare. * oln/core/init.hh: Fix. * oln/core/equipment.hh (oln_box): New. * oln/core/2d/neighb2d.hh: Unconst objects. * oln/core/2d/image2d.hh (init_): Rename as... (prepare): ...this. * oln/core/2d/image2d_b.hh: Likewise. * oln/core/internal/op_image_restricted_to_pset.hh: Likewise. * oln/core/internal/op_image_plus_nbh.hh: Likewise. * oln/core/internal/image_base.hh (init_): New overload. core/2d/image2d.hh | 10 ++-- core/2d/image2d_b.hh | 24 +++++++--- core/2d/neighb2d.hh | 16 +++---- core/concept/image.hh | 34 +++++++++++++++ core/equipment.hh | 1 core/init.hh | 4 - core/internal/image_base.hh | 16 +++++-- core/internal/op_image_plus_nbh.hh | 50 +++++++++++++++------- core/internal/op_image_restricted_to_pset.hh | 61 ++++++++++++++++++--------- debug/print.hh | 8 +-- level/apply_local.hh | 2 11 files changed, 161 insertions(+), 65 deletions(-) Index: oln/debug/print.hh --- oln/debug/print.hh (revision 889) +++ oln/debug/print.hh (working copy) @@ -100,11 +100,11 @@ std::ostream& ostr) { const oln_coord(I) - min_row = input.bbox().pmin().row(), - max_row = input.bbox().pmax().row(); + min_row = input.min_row(), + max_row = input.max_row(); const oln_coord(I) - min_col = input.bbox().pmin().col(), - max_col = input.bbox().pmax().col(); + min_col = input.min_col(), + max_col = input.max_col(); for (oln_coord(I) row = min_row; row <= max_row; ++row) { for (oln_coord(I) col = min_col; col <= max_col; ++col) Index: oln/level/apply_local.hh --- oln/level/apply_local.hh (revision 889) +++ oln/level/apply_local.hh (working copy) @@ -61,7 +61,7 @@ const Image_with_Nbh<I>& input) { oln_plain_value(I, typename F::result) output; - init(output, with, input); + prepare(output, with, input); oln_piter(I) p(input.points()); for_all(p) output(p) = level::local(f, input, p); Index: oln/core/concept/image.hh --- oln/core/concept/image.hh (revision 889) +++ oln/core/concept/image.hh (working copy) @@ -269,6 +269,12 @@ { stc_typename(coord); + // final + coord min_row() const; + coord max_row() const; + coord min_col() const; + coord max_col() const; + protected: Image_2D(); }; @@ -487,6 +493,34 @@ { } + template <typename Exact> + typename Image_2D<Exact>::coord + Image_2D<Exact>::min_row() const + { + return this->bbox().pmin().row(); + } + + template <typename Exact> + typename Image_2D<Exact>::coord + Image_2D<Exact>::max_row() const + { + return this->bbox().pmax().row(); + } + + template <typename Exact> + typename Image_2D<Exact>::coord + Image_2D<Exact>::min_col() const + { + return this->bbox().pmin().col(); + } + + template <typename Exact> + typename Image_2D<Exact>::coord + Image_2D<Exact>::max_col() const + { + return this->bbox().pmax().col(); + } + // ----------------------------------- Image_3D<Exact> template <typename Exact> Index: oln/core/init.hh --- oln/core/init.hh (revision 889) +++ oln/core/init.hh (working copy) @@ -162,7 +162,7 @@ template <typename Target, typename Data> bool init(Any<Target>& target, with_t, Any<Data>& data) { - return init(target, const_cast<const Data&>(data)); + return init(target, with, const_cast<const Any<Data>&>(data)); } @@ -174,7 +174,7 @@ // Guard: we cannot have "const Target". template <typename Target, typename Data> - bool init(const Any<Target>&, with_t, const Any<Data>&) + bool init(const Any<Target>& target, with_t, const Any<Data>& data) { mlc::abort_< Target, ERROR::initialization_of_temporary_or_const_object_<Target> >::check(); return false; Index: oln/core/2d/neighb2d.hh --- oln/core/2d/neighb2d.hh (revision 889) +++ oln/core/2d/neighb2d.hh (working copy) @@ -101,10 +101,10 @@ } // end of namespace oln::internal - extern const neighb2d c4; - extern const neighb2d c8; - extern const neighb2d c2r; - extern const neighb2d c2c; + extern neighb2d c4; + extern neighb2d c8; + extern neighb2d c2r; + extern neighb2d c2c; # ifndef OLN_INCLUDE_ONLY @@ -121,10 +121,10 @@ # endif // OLN_ENABLE_DEFAULT - const neighb2d c4 = internal::mk_c4(); - const neighb2d c8 = internal::mk_c8(); - const neighb2d c2r = internal::mk_c2_row(); - const neighb2d c2c = internal::mk_c2_col(); + 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 Index: oln/core/2d/image2d.hh --- oln/core/2d/image2d.hh (revision 889) +++ oln/core/2d/image2d.hh (working copy) @@ -104,7 +104,7 @@ }; template <typename T, typename D> - bool init_(image2d<T>* this_, const D& dat); + bool prepare(image2d<T>& target, with_t, const D& dat); # ifndef OLN_INCLUDE_ONLY @@ -213,18 +213,18 @@ } template <typename T, typename D> - bool init_(image2d<T>* this_, const D& dat) + bool prepare(image2d<T>& target, with_t, const D& dat) { - precondition(not this_->has_data()); + precondition(not target.has_data()); box2d b; bool box_ok = init(b, with, dat); postcondition(box_ok); - this_->data__() = new typename image2d<T>::data(b.pmin().row(), b.pmin().col(), + target.data__() = new typename image2d<T>::data(b.pmin().row(), b.pmin().col(), b.pmax().row(), b.pmax().col()); return box_ok; } -# endif +# endif // ! OLN_INCLUDE_ONLY } // end of namespace oln Index: oln/core/2d/image2d_b.hh --- oln/core/2d/image2d_b.hh (revision 889) +++ oln/core/2d/image2d_b.hh (working copy) @@ -151,8 +151,8 @@ unsigned border() const; }; - template <typename T, typename D> - bool init_(image2d_b<T>* this_, const D& dat); +// template <typename T, typename D> +// bool init_(image2d_b<T>* this_, const D& dat); # ifndef OLN_INCLUDE_ONLY @@ -256,19 +256,31 @@ return this->data_->border; } +// template <typename T, typename D> +// bool init_(image2d_b<T>* this_, const D& dat) +// { +// precondition(not this_->has_data()); +// box2d b; +// bool box_ok = init(b, with, dat); +// postcondition(box_ok); +// unsigned border = 2; // FIXME: Use init! +// this_->data__() = new typename image2d_b<T>::data(b.pmin(), b.pmax(), border); +// return box_ok; +// } + template <typename T, typename D> - bool init_(image2d_b<T>* this_, const D& dat) + bool prepare(image2d_b<T>& target, with_t, const D& dat) { - precondition(not this_->has_data()); + precondition(not target.has_data()); box2d b; bool box_ok = init(b, with, dat); postcondition(box_ok); unsigned border = 2; // FIXME: Use init! - this_->data__() = new typename image2d_b<T>::data(b.pmin(), b.pmax(), border); + target.data__() = new typename image2d_b<T>::data(b.pmin(), b.pmax(), border); return box_ok; } -# endif +# endif // ! OLN_INCLUDE_ONLY } // end of namespace oln Index: oln/core/equipment.hh --- oln/core/equipment.hh (revision 889) +++ oln/core/equipment.hh (working copy) @@ -64,6 +64,7 @@ # define oln_bkd_niter(T) oln_typename_shortcut__(T, bkd_niter) # define oln_bkd_piter(T) oln_typename_shortcut__(T, bkd_piter) # define oln_bkd_qiter(T) oln_typename_shortcut__(T, bkd_qiter) +# define oln_box(T) oln_typename_shortcut__(T, box) // c stc_decl_associated_type( coord ); Index: oln/core/internal/op_image_restricted_to_pset.hh --- oln/core/internal/op_image_restricted_to_pset.hh (revision 889) +++ oln/core/internal/op_image_restricted_to_pset.hh (working copy) @@ -102,19 +102,23 @@ // init - template <typename I, typename S, typename D> - bool init_(internal::current* target, const D& dat); - template <typename S, typename I> - bool init(Point_Set<S>& target, - with_t, + bool init_(Point_Set<S>* this_, const internal::current& dat); template <typename I, typename S> - bool init(Image<I>& target, - with_t, + bool init_(Image<I>* this_, const internal::current& dat); + template <typename I, typename S, typename D> + bool init_(internal::current* this_, const D& dat); + + // prepare + + template <typename I, typename S, typename D> + bool prepare(internal::current& target, with_t, const D& dat); + + # ifndef OLN_INCLUDE_ONLY @@ -160,8 +164,25 @@ } // end of namespace oln::internal + // init + template <typename S, typename I> + bool init_(Point_Set<S>* this_, + const internal::current& data) + { + exact(*this_) = data.points(); + return true; + } + + template <typename I, typename S> + bool init_(Image<I>* this_, + const internal::current& data) + { + exact(*this_) = data.image(); + return true; + } + template <typename I, typename S, typename D> bool init_(internal::current* this_, const D& dat) { @@ -174,23 +195,23 @@ return image_ok and subset_ok; } - template <typename S, typename I> - bool init_(Point_Set<S>* this_, - const internal::current& data) - { - *this_ = data.points(); - return true; - } - template <typename I, typename S> - bool init(Image<I>* this_, - const internal::current& data) + // prepare + + template <typename I, typename S, typename D> + bool prepare(internal::current& target, with_t, const D& dat) { - *this_ = data.image(); - return true; + precondition(not target.has_data()); + target.data__() = new typename op_<I, restricted_to, S>::data; + bool image_ok = prepare(target.data__()->first, with, dat); + bool subset_ok = init(target.data__()->second, with, dat); + postcondition(image_ok); + postcondition(subset_ok); + return image_ok and subset_ok; } -# endif // OLN_INCLUDE_ONLY + +# endif // ! OLN_INCLUDE_ONLY # undef current Index: oln/core/internal/op_image_plus_nbh.hh --- oln/core/internal/op_image_plus_nbh.hh (revision 889) +++ oln/core/internal/op_image_plus_nbh.hh (working copy) @@ -28,6 +28,7 @@ #ifndef OLN_CORE_INTERNAL_OP_IMAGE_PLUS_NBH_HH # define OLN_CORE_INTERNAL_OP_IMAGE_PLUS_NBH_HH +# include <mlc/unconst.hh> # include <oln/core/concept/neighborhood.hh> # include <oln/core/gen/op.hh> # include <oln/core/gen/dpoints_piter.hh> @@ -107,19 +108,22 @@ } // end of namespace oln::internal + // prepare + + template <typename I, typename N, typename D> + bool prepare(internal::current& target, with_t, const D& dat); + // init template <typename I, typename N, typename D> bool init_(internal::current* target, const D& dat); template <typename N, typename I> - bool init(Neighborhood<N>& target, - with_t, + bool init_(Neighborhood<N>* this_, const internal::current& dat); template <typename I, typename N> - bool init(Image<I>& target, - with_t, + bool init_(Image<I>* this_, const internal::current& dat); @@ -169,6 +173,22 @@ // init + template <typename N, typename I> + bool init_(Neighborhood<N>* this_, + const internal::current& data) + { + exact(*this_) = data.nbhood(); + return true; + } + + template <typename I, typename N> + bool init_(Image<I>* this_, + const internal::current& data) + { + exact(*this_) = data.image(); + return true; + } + template <typename I, typename N, typename D> bool init_(internal::current* this_, const D& dat) { @@ -181,20 +201,18 @@ return ima_ok and nbh_ok; } - template <typename N, typename I> - bool init_(Neighborhood<N>* this_, - const internal::current& data) - { - *this_ = data.nbhood(); - return true; - } + // prepare - template <typename I, typename N> - bool init(Image<I>* this_, - const internal::current& data) + template <typename I, typename N, typename D> + bool prepare(internal::current& target, with_t, const D& dat) { - *this_ = data.image(); - return true; + precondition(not target.has_data()); + target.data__() = new typename op_<I, plus, N>::data; + bool ima_ok = prepare(target.data__()->first, with, dat); + bool nbh_ok = init(target.data__()->second, with, dat); + postcondition(ima_ok); + postcondition(nbh_ok); + return ima_ok and nbh_ok; } # endif // OLN_INCLUDE_ONLY Index: oln/core/internal/image_base.hh --- oln/core/internal/image_base.hh (revision 889) +++ oln/core/internal/image_base.hh (working copy) @@ -436,7 +436,10 @@ bool init_(box_<P>* this_, const internal::image_base_<I>& data); template <typename Target, typename I> - bool init_(Target* this_, const internal::single_image_morpher_<I>& data); + bool init_(Any<Target>* this_, const internal::single_image_morpher_<I>& data); + + template <typename P, typename I> // for disambiguation purpose + bool init_(box_<P>* this_, const internal::single_image_morpher_<I>& data); # ifndef OLN_INCLUDE_ONLY @@ -449,12 +452,19 @@ } template <typename Target, typename I> - bool init_(Target* this_, const internal::single_image_morpher_<I>& data) + bool init_(Any<Target>* this_, const internal::single_image_morpher_<I>& data) { return init(*this_, with, data.image()); } -# endif // OLN_INCLUDE_ONLY + template <typename P, typename I> + bool init_(box_<P>* this_, const internal::single_image_morpher_<I>& data) + { + *this_ = data.bbox(); + return true; + } + +# endif // ! OLN_INCLUDE_ONLY } // end of namespace oln