
Simon Odou <simon@lrde.epita.fr> writes:
Index: olena/ChangeLog from Simon Odou <simon@lrde.epita.fr>
* oln/core/image1d.hh: Add informations to image_id. * oln/core/image2d.hh: Likewise * oln/core/image3d.hh: Likewise * oln/core/impl/image_array1d.hh: Add empty constructor for any_with_diamond. * oln/core/impl/image_array.hh: Likewise. * oln/core/impl/image_array2d.hh: Likewise. * oln/core/impl/image_array3d.hh: Likewise. * oln/core/impl/image_impl.hh: Likewise. * oln/core/abstract/image_size.hh: Likewise. * oln/core/image1d_size.hh: Likewise. * oln/core/image2d_size.hh: Likewise. * oln/core/image3d_size.hh: Likewise. * tests/morpher/tests/piece: New.
a eviter, il est preferable d'employer des phrases a l'imperatif.
* tests/morpher/tests/iter: New. * tests/morpher/tests/slicing: New. * oln/core/abstract/image.hh: Size() returns const inside of const &. * oln/morpher/piece_morpher.hh: Adapt to new version of generic morpher. Respect 80 columns. * oln/morpher/slicing_morpher.hh: Likewise. * oln/morpher/iter_morpher.hh: Likewise. Better example for documentation. * oln/Makefile.am: Add files. * oln/morpher/generic_morpher.hh: Fix a bug.
Index: olena/oln/core/image1d.hh --- olena/oln/core/image1d.hh Fri, 02 Apr 2004 16:00:03 +0200 van-vl_n (oln/c/47_image1d.hh 1.28.1.3 600) +++ olena/oln/core/image1d.hh Sun, 04 Apr 2004 16:26:06 +0200 odou_s (oln/c/47_image1d.hh 1.28.1.4 600) @@ -57,6 +57,8 @@ typedef T value_type; typedef typename mlc::exact_vt<image1d<T, Exact>, Exact>::ret exact_type;
mlc_2_exact_vt_type(image1d, T, Exact) est ton amie.
typedef impl::image_array1d<T> impl_type; + typedef point1d point_type; + typedef image1d_size size_type; };
/*! \class image_traits<image1d<T, Exact> > Index: olena/oln/core/image1d_size.hh --- olena/oln/core/image1d_size.hh Fri, 12 Mar 2004 20:17:58 +0100 thivol_d (oln/c/46_image1d_si 1.11 600) +++ olena/oln/core/image1d_size.hh Sun, 04 Apr 2004 16:26:13 +0200 odou_s (oln/c/46_image1d_si 1.12 600) @@ -70,6 +70,9 @@ border_ = border; }
+ image1d_size() + {} + /// Return the number of columns in the image.
coord Index: olena/oln/core/image2d.hh --- olena/oln/core/image2d.hh Fri, 02 Apr 2004 16:00:03 +0200 van-vl_n (oln/c/45_image2d.hh 1.30.1.3 600) +++ olena/oln/core/image2d.hh Sun, 04 Apr 2004 16:26:21 +0200 odou_s (oln/c/45_image2d.hh 1.30.1.4 600) @@ -57,6 +57,8 @@ typedef T value_type; typedef typename mlc::exact_vt<image2d<T, Exact>, Exact>::ret exact_type;
Cf. plus haut.
typedef impl::image_array2d<T> impl_type; + typedef point2d point_type; + typedef image2d_size size_type; };
/*! \class image_traits<image2d<T, Exact> > Index: olena/oln/core/image2d_size.hh --- olena/oln/core/image2d_size.hh Fri, 12 Mar 2004 20:17:58 +0100 thivol_d (oln/c/44_image2d_si 1.11 600) +++ olena/oln/core/image2d_size.hh Sun, 04 Apr 2004 16:26:36 +0200 odou_s (oln/c/44_image2d_si 1.12 600) @@ -74,6 +74,9 @@ border_ = border; }
+ image2d_size() + {} + /// Return the number of rows in the image.
coord Index: olena/oln/core/image3d.hh --- olena/oln/core/image3d.hh Fri, 02 Apr 2004 16:00:03 +0200 van-vl_n (oln/c/43_image3d.hh 1.27.1.3 600) +++ olena/oln/core/image3d.hh Sun, 04 Apr 2004 16:26:27 +0200 odou_s (oln/c/43_image3d.hh 1.27.1.4 600) @@ -57,6 +57,8 @@ typedef T value_type; typedef typename mlc::exact_vt<image3d<T, Exact>, Exact>::ret exact_type; typedef impl::image_array3d<T> impl_type; + typedef point3d point_type; + typedef image3d_size size_type; };
/*! \class image_traits<image3d<T, Exact> > Index: olena/oln/core/image3d_size.hh --- olena/oln/core/image3d_size.hh Fri, 12 Mar 2004 20:17:58 +0100 thivol_d (oln/c/42_image3d_si 1.11 600) +++ olena/oln/core/image3d_size.hh Sun, 04 Apr 2004 16:26:31 +0200 odou_s (oln/c/42_image3d_si 1.12 600) @@ -80,6 +80,9 @@ border_ = border; }
+ image3d_size() + {} + /// Return the number of slices in the image.
coord Index: olena/oln/core/abstract/image_size.hh --- olena/oln/core/abstract/image_size.hh Thu, 11 Mar 2004 17:12:19 +0100 thivol_d (oln/c/41_image_size 1.11 600) +++ olena/oln/core/abstract/image_size.hh Sun, 04 Apr 2004 16:26:57 +0200 odou_s (oln/c/41_image_size 1.12 600) @@ -158,12 +158,11 @@ Exact::name() + ">"; }
- protected: - - image_size() {}
+ protected: + /*! border_ represents the width of the image border ** such a mecanism allow algorithm to perform operation ** on the points at the edge of the image as if they were Index: olena/oln/Makefile.am --- olena/oln/Makefile.am Sat, 03 Apr 2004 23:02:21 +0200 thivol_d (oln/q/47_Makefile.a 1.3.1.1.1.6.1.7.1.5 600) +++ olena/oln/Makefile.am Sun, 04 Apr 2004 16:27:17 +0200 odou_s (oln/q/47_Makefile.a 1.3.1.1.1.6.1.7.1.6 600) @@ -148,6 +148,9 @@ math/macros.hh \ morpher/color_morpher.hh \ morpher/generic_morpher.hh \ + morpher/iter_morpher.hh \ + morpher/piece_morpher.hh \ + morpher/slicing_morpher.hh \ morpher/subq_morpher.hh \ morpho/attribute_closing_opening.hh \ morpho/attribute_closing_opening_map.hxx \ Index: olena/oln/core/abstract/image.hh --- olena/oln/core/abstract/image.hh Fri, 26 Mar 2004 12:53:24 +0100 thivol_d (oln/t/25_image.hh 1.29 600) +++ olena/oln/core/abstract/image.hh Sun, 04 Apr 2004 16:27:23 +0200 odou_s (oln/t/25_image.hh 1.30 600) @@ -178,11 +178,11 @@
/// Return a reference to the image size.
Modifie les commentaires.
- const size_type& + const size_type size() const { assertion(has_impl()); - return this->exact().impl()->size(); + return this->exact().size(); }
/// Return the value of the border width. Index: olena/oln/core/impl/image_impl.hh --- olena/oln/core/impl/image_impl.hh Sun, 14 Mar 2004 19:03:34 +0100 van-vl_n (oln/t/29_image_impl 1.18 600) +++ olena/oln/core/impl/image_impl.hh Sun, 04 Apr 2004 16:28:17 +0200 odou_s (oln/t/29_image_impl 1.19 600) @@ -81,6 +81,7 @@
image_impl(const size_type s): refcount_(0), size_(s) {}
+ image_impl() {}
/// Notice that there is a new reference to the object.
Index: olena/oln/core/impl/image_array.hh --- olena/oln/core/impl/image_array.hh Mon, 15 Mar 2004 17:40:54 +0100 van-vl_n (oln/t/30_image_arra 1.16 600) +++ olena/oln/core/impl/image_array.hh Sun, 04 Apr 2004 16:28:29 +0200 odou_s (oln/t/30_image_arra 1.17 600) @@ -121,6 +121,9 @@ allocate_data_(buffer_, len(s)); }
+ image_array() : buffer_(0) + {} + image_array(const self_type&); // cpy ctor w/o impl
void @@ -169,6 +172,7 @@
~image_array() { + if (buffer_) desallocate_data_(buffer_); }
Index: olena/oln/core/impl/image_array3d.hh --- olena/oln/core/impl/image_array3d.hh Fri, 12 Mar 2004 20:17:58 +0100 thivol_d (oln/t/32_image_arra 1.11 600) +++ olena/oln/core/impl/image_array3d.hh Sun, 04 Apr 2004 16:28:41 +0200 odou_s (oln/t/32_image_arra 1.12 600) @@ -134,8 +134,11 @@ pretreat_3d_data_(this->buffer_, array2_, array_, s); }
+ image_array3d() : array_(0) {} + ~image_array3d() { + if (array_) desallocate_3d_data_(array2_, array_, this->size_); }
Index: olena/oln/core/impl/image_array2d.hh --- olena/oln/core/impl/image_array2d.hh Mon, 29 Mar 2004 15:45:23 +0200 palma_g (oln/t/33_image_arra 1.13 600) +++ olena/oln/core/impl/image_array2d.hh Sun, 04 Apr 2004 16:28:38 +0200 odou_s (oln/t/33_image_arra 1.14 600) @@ -122,8 +122,11 @@ pretreat_2d_data_(this->buffer_, array_, s); }
+ image_array2d() : array_(0) {} + ~image_array2d() { + if (array_) desallocate_2d_data_(array_, this->size_); }
Index: olena/oln/core/impl/image_array1d.hh --- olena/oln/core/impl/image_array1d.hh Fri, 12 Mar 2004 20:17:58 +0100 thivol_d (oln/t/34_image_arra 1.13 600) +++ olena/oln/core/impl/image_array1d.hh Sun, 04 Apr 2004 16:28:34 +0200 odou_s (oln/t/34_image_arra 1.14 600) @@ -99,6 +99,8 @@ pretreat_1d_data_(this->buffer_, buffer__, s); }
+ image_array1d() {} + ~image_array1d() {}
protected: Index: olena/oln/morpher/piece_morpher.hh --- olena/oln/morpher/piece_morpher.hh Mon, 29 Mar 2004 09:26:50 +0200 odou_s (oln/m/40_piece_morp 1.1 600) +++ olena/oln/morpher/piece_morpher.hh Sun, 04 Apr 2004 16:29:01 +0200 odou_s (oln/m/40_piece_morp 1.2 600) @@ -36,31 +36,51 @@
template <class I, class Exact = mlc::final> struct piece_morpher; + template <class I, class Exact = mlc::final> + struct super_piece_morpher;
} // end of namespace morpher
- /// Inherits identification's informations about the piece morpher. - template <class I, class Exact> - struct image_id< morpher::piece_morpher<I, Exact> > : public image_id<I> - {}; + /// Informations about the super piece morpher. + template <class SrcType, class Exact> + struct image_id< morpher::super_piece_morpher<SrcType, Exact> > + { + typedef typename mlc::exact_vt< + morpher::super_piece_morpher<SrcType, Exact>, + Exact>::ret + exact_type; + ///< Retrieve the exact type of the image. + };
- /// Inherits identification's informations about the const piece morpher. - template <class I, class Exact> - struct image_id< morpher::piece_morpher<const I, Exact> > : public image_id<I> - {}; + /// Informations about the piece morpher. + template <class SrcType, class Exact> + struct image_id< morpher::piece_morpher<SrcType, Exact> > + { + enum {dim = SrcType::dim}; ///< The Image dimension. + typedef oln_impl_type(SrcType) impl_type; + ///< Underlying implementation. + typedef oln_value_type(SrcType) value_type; + ///< The value type of the decorated image. + typedef typename mlc::exact_vt<morpher::piece_morpher<SrcType, Exact>, + Exact>::ret exact_type; + ///< Retrieve the exact type of the image. + typedef oln_point_type(SrcType) point_type; + typedef oln_dpoint_type(SrcType) dpoint_type; + typedef oln_size_type(SrcType) size_type; + typedef oln_iter_type(SrcType) iter_type; + };
/// Traits for piece morpher. - template <class I> - struct image_traits < morpher::piece_morpher<I> > : - public image_traits<abstract::image_with_impl<oln_impl_type(I), - morpher::piece_morpher<I> > > - {}; - - /// Traits for const piece morpher. - template <class I> - struct image_traits < morpher::piece_morpher<const I> > : - public image_traits<abstract::image_with_impl<oln_impl_type(I), - morpher::piece_morpher<const I> > > + template <class SrcType, class Exact> + struct image_traits < morpher::piece_morpher<SrcType, Exact> > + : public + image_traits< + morpher::abstract::generic_morpher< + SrcType, + typename image_id<morpher::piece_morpher<SrcType, + Exact> >::exact_type + > + > {};
@@ -68,13 +88,18 @@
/// Abstract piece morpher class used for code factorization. template <class SrcType, class Exact> - class super_piece_morpher : public abstract::generic_morpher<SrcType, SrcType, Exact> + class super_piece_morpher + : public abstract::generic_morpher<SrcType, Exact> { + public:
- typedef abstract::generic_morpher<SrcType, SrcType, Exact> super_type; - typedef oln_dpoint_type(SrcType) dpoint_type; - typedef oln_size_type(SrcType) size_type; + typedef super_piece_morpher<SrcType, Exact> self_type; + typedef typename image_id<self_type>::exact_type exact_type; + typedef abstract::generic_morpher<SrcType, Exact> super_type; + + typedef typename image_id<exact_type>::dpoint_type dpoint_type; + typedef typename image_id<exact_type>::size_type size_type;
les commentaires ?
protected:
@@ -93,31 +118,36 @@ {}
const size_type size_; ///< The size of the piece of picture. - const dpoint_type p_; ///< The reference point of the piece of picture. + const dpoint_type p_; + ///< The reference point of the piece of picture.
/*! ** \brief Empty constructor. ** ** Needed by mlc_hierarchy::any_with_diamond. */ - super_piece_morpher() : size_(size_) {} + super_piece_morpher() + {}
public:
/// Return the size (different from the original picture). - const size_type size() const + const size_type + size() const { return size_; }
/// Return the reference point. - const dpoint_type ref_point() const + const dpoint_type + ref_point() const { return p_; }
/// Useful to debug. - static std::string name() + static std::string + name() { return "super_piece_morpher<" + super_type::name() + ">"; } @@ -134,17 +164,19 @@ */ template <class SrcType, class Exact> struct piece_morpher - : public super_piece_morpher<SrcType, piece_morpher<SrcType, Exact> > + : public super_piece_morpher< + SrcType, + typename image_id<piece_morpher<SrcType, Exact> >::exact_type + > { - /// The type of the object instantiated. piece morpher can be derived. - typedef typename image_id<piece_morpher<SrcType, Exact> >::exact_type exact_type; typedef piece_morpher<SrcType, Exact> self_type; - typedef super_piece_morpher<SrcType, piece_morpher<SrcType, Exact> > super_type; + typedef typename image_id<self_type>::exact_type exact_type; + typedef super_piece_morpher<SrcType, exact_type> super_type;
- typedef oln_point_type(SrcType) point_type; - typedef oln_dpoint_type(SrcType) dpoint_type; - typedef oln_size_type(SrcType) size_type; - typedef oln_value_type(SrcType) value_type; + typedef typename image_id<exact_type>::point_type point_type; + typedef typename image_id<exact_type>::dpoint_type dpoint_type; + typedef typename image_id<exact_type>::size_type size_type; + typedef typename image_id<exact_type>::value_type value_type;
Pourquoi ne plus passer par les macros ?
/// Construct the piece morpher with an image \a ima. piece_morpher(const SrcType &ima, const dpoint_type p, @@ -170,9 +202,11 @@ ** \arg p The point. ** \return The stored value. */ - value_type& at(const point_type& p) + value_type& + at(const point_type& p) { - return const_cast<value_type &>(this->ima_)[p + p_]; + return const_cast<value_type &> + ( const_cast<SrcType &>(this->ima_)[p + p_] ); }
/*! @@ -180,7 +214,8 @@ ** \arg p The point. ** \return The stored value. */ - const value_type at(const point_type& p) const + const value_type + at(const point_type& p) const { return this->ima_[p + p_]; } @@ -209,27 +244,31 @@ }
/// Useful to debug. - static std::string name() + static std::string + name() { return "piece_morpher<" + super_type::name() + ">"; }
};
- /// The specialized version for `const' declared images. + /// The specialized version for `const' images. template <class SrcType, class Exact> struct piece_morpher<const SrcType, Exact> - : public super_piece_morpher< SrcType, piece_morpher<const SrcType, Exact> > + : public super_piece_morpher< + const SrcType, + typename image_id<piece_morpher<const SrcType, + Exact> >::exact_type + > { - /// The type of the object instantiated. piece morpher can be derived. - typedef typename image_id<piece_morpher<SrcType, Exact> >::exact_type exact_type; typedef piece_morpher<const SrcType, Exact> self_type; - typedef super_piece_morpher<SrcType, piece_morpher<const SrcType, Exact> > super_type; + typedef typename image_id<self_type>::exact_type exact_type; + typedef super_piece_morpher<const SrcType, exact_type> super_type;
- typedef oln_point_type(SrcType) point_type; - typedef oln_dpoint_type(SrcType) dpoint_type; - typedef oln_size_type(SrcType) size_type; - typedef oln_value_type(SrcType) value_type; + typedef typename image_id<exact_type>::point_type point_type; + typedef typename image_id<exact_type>::dpoint_type dpoint_type; + typedef typename image_id<exact_type>::size_type size_type; + typedef typename image_id<exact_type>::value_type value_type;
/*! ** \brief Construct a piece morpher. @@ -259,13 +298,15 @@ ** \arg p The point. ** \return The stored value. */ - const value_type at(const point_type &p) const + const value_type + at(const point_type &p) const { return this->ima_[p + p_]; }
/// Useful to debug. - static std::string name() + static std::string + name() { return "piece_morpher<" + super_type::name() + ">"; } @@ -290,7 +331,8 @@ ** oln::image2d<ntg::rgb_8> imc = oln::load(IMG_IN "lena.ppm"); ** oln::save(oln::morpher::piece_morph(imc, ** oln::dpoint2d(246, 244), - ** oln::image2d_size(30, 60, imc.border())), + ** oln::image2d_size(30, 60, + ** imc.border())), ** IMG_OUT "oln_morpher_piece_morpher.pgm"); ** } ** \endcode @@ -301,7 +343,8 @@ ** \image latex oln_morpher_piece_morpher.png */ template <class I, class PointType, class SizeType> - const piece_morpher<I> piece_morph(I &ima, const PointType p, const SizeType s) + const piece_morpher<I> + piece_morph(I &ima, const PointType p, const SizeType s) { return piece_morpher<I>(ima, p, s); } Index: olena/oln/morpher/iter_morpher.hh --- olena/oln/morpher/iter_morpher.hh Mon, 29 Mar 2004 09:31:34 +0200 odou_s (oln/m/41_iter_morph 1.1 600) +++ olena/oln/morpher/iter_morpher.hh Sun, 04 Apr 2004 16:29:10 +0200 odou_s (oln/m/41_iter_morph 1.2 600) @@ -25,8 +25,8 @@ // reasons why the executable file might be covered by the GNU General // Public License.
-#ifndef ITER_MORPHER_HH -# define ITER_MORPHER_HH +#ifndef OLN_MORPHER_ITER_MORPHER_HH +# define OLN_MORPHER_ITER_MORPHER_HH
# include <oln/morpher/generic_morpher.hh>
@@ -39,30 +39,38 @@
} // end of namespace morpher
- /// Inherits identification's informations about the iter morpher. + /// Informations about the iter morpher. template <class SrcType, class IterType, class Exact> - struct image_id< morpher::iter_morpher<SrcType, IterType, Exact> > : public image_id<SrcType> - {}; - - /// Inherits identification's informations about the const iter morpher. - template <class SrcType, class IterType, class Exact> - struct image_id< morpher::iter_morpher<const SrcType, IterType, Exact> > : public image_id<SrcType> - {}; - - /// Traits for iter morpher. - template <class SrcType, class IterType> - struct image_traits < morpher::iter_morpher<SrcType, IterType> > : - public image_traits<abstract::image_with_impl<oln_impl_type(SrcType), - morpher::iter_morpher<SrcType, IterType> > > + struct image_id< morpher::iter_morpher<SrcType, IterType, Exact> > { + enum {dim = SrcType::dim}; ///< The Image dimension. + typedef oln_impl_type(SrcType) impl_type; + ///< Underlying implementation. + typedef oln_value_type(SrcType) value_type; + ///< The value type of the decorated image. + typedef typename mlc::exact_vt< + morpher::iter_morpher<SrcType, IterType, Exact>, + Exact + >::ret exact_type; + ///< Retrieve the exact type of the image. + typedef oln_point_type(SrcType) point_type; + typedef oln_dpoint_type(SrcType) dpoint_type; + typedef oln_size_type(SrcType) size_type; typedef IterType iter_type; };
- /// Traits for const iter morpher. - template <class SrcType, class IterType> - struct image_traits < morpher::iter_morpher<const SrcType, IterType> > : - public image_traits<abstract::image_with_impl<oln_impl_type(SrcType), - morpher::iter_morpher<const SrcType, IterType> > > + /// Traits for iter morpher. + template <class SrcType, class IterType, class Exact> + struct image_traits < morpher::iter_morpher<SrcType, IterType, Exact> > + : public + image_traits< + morpher::abstract::generic_morpher< + SrcType, + typename image_id<morpher::iter_morpher<SrcType, + IterType, + Exact> >::exact_type + > + > { typedef IterType iter_type; }; @@ -71,13 +79,20 @@
template <class SrcType, class IterType, class Exact> struct iter_morpher - : public abstract::generic_morpher< SrcType, SrcType, iter_morpher<SrcType, IterType, Exact> > + : public abstract::generic_morpher< + SrcType, + typename image_id<iter_morpher<SrcType, + IterType, + Exact> >::exact_type + > { - /// The type of the object instantiated. iter morpher can be derived. - typedef typename image_id< iter_morpher<SrcType, IterType, Exact> >::exact_type exact_type; typedef iter_morpher<SrcType, IterType, Exact> self_type; - typedef IterType iter_type; - typedef abstract::generic_morpher< SrcType, SrcType, iter_morpher<SrcType, IterType, Exact> > super_type; + typedef typename image_id<self_type>::exact_type exact_type; + typedef abstract::generic_morpher<SrcType, exact_type> super_type; + + typedef typename image_id<exact_type>::iter_type iter_type; + typedef typename image_id<exact_type>::value_type value_type; + typedef typename image_id<exact_type>::point_type point_type;
/// Construct the iter morpher with an image \a ima. iter_morpher(const SrcType &ima) @@ -110,8 +125,32 @@ return this->exact(); }
+ /*! + ** \brief Return the stored value at the point. + ** \arg p The point. + ** \return The stored value. + */ + value_type& + at(const point_type& p) + { + return const_cast<value_type &> + ( const_cast<SrcType &>(this->ima_)[p] ); + } + + /*! + ** \brief Return the stored value at the point. + ** \arg p The point. + ** \return The stored value. + */ + const value_type + at(const point_type& p) const + { + return this->ima_[p]; + } + /// Useful to debug. - static std::string name() + static std::string + name() { return "iter_morpher<" + super_type::name() + ">"; } @@ -121,13 +160,22 @@ /// The specialized version for `const' declared images. template <class SrcType, class IterType, class Exact> struct iter_morpher<const SrcType, IterType, Exact> - : public abstract::generic_morpher< SrcType, SrcType, iter_morpher<const SrcType, IterType, Exact> > + : public + abstract::generic_morpher< + const SrcType, + typename image_id<iter_morpher<const SrcType, + IterType, + Exact> >::exact_type + > { - /// The type of the object instantiated. iter morpher can be derived. - typedef typename image_id< iter_morpher<SrcType, IterType, Exact> >::exact_type exact_type; typedef iter_morpher<const SrcType, IterType, Exact> self_type; - typedef IterType iter_type; - typedef abstract::generic_morpher<SrcType, SrcType, iter_morpher<const SrcType, IterType, Exact> > super_type; + typedef typename image_id<self_type>::exact_type exact_type; + typedef abstract::generic_morpher<const SrcType, exact_type> + super_type; + + typedef typename image_id<exact_type>::iter_type iter_type; + typedef typename image_id<exact_type>::value_type value_type; + typedef typename image_id<exact_type>::point_type point_type;
/// Construct the iter morpher with an image \a ima. iter_morpher(const SrcType &ima) @@ -135,19 +183,45 @@ {}
/// Construct the iter morpher with another iter morpher. - iter_morpher(const iter_morpher<const SrcType, IterType>& r) - : super_type(r.get_ima()) {} + iter_morpher(const self_type& r) + : super_type(r.get_ima()) + {}
/*! ** \brief Empty constructor. ** ** Needed by mlc_hierarchy::any_with_diamond. */ - iter_morpher() - {} + iter_morpher() {} + + /*! Perform a shallow copy from the decorated image of \a rhs + ** to the current decorated image. The points will be shared + ** by the two images. + */ + self_type& + assign(self_type& rhs) + { + oln_iter_type(SrcType) it(rhs); + + for_all(it) + this->at(it) = rhs[it]; + return this->exact();
return to_exact(*this);
+ } + + /*! + ** \brief Return the stored value at the point. + ** \arg p The point. + ** \return The stored value. + */ + const value_type + at(const point_type& p) const + { + return this->ima_[p];
il sert vraiment le this ?
+ }
/// Useful to debug. - static std::string name() + static std::string + name() { return "iter_morpher<" + super_type::name() + ">"; } @@ -158,33 +232,45 @@ ** \brief Instantiate a temporary read-only iter morpher. ** ** The image will be viewed according to its iterator type. - ** For example, the foo function will print the size of the picture - ** (the bkd_iter_type is used transparently). + ** So the resulting image will be reversed. ** ** \code ** #include <oln/morpher/iter_morpher.hh> ** #include <oln/basics2d.hh> ** #include <ntg/all.hh> - ** template <class E> - ** void foo(const oln::abstract::image<E>& img) + ** template <class E, class F> + ** void foo(const oln::abstract::image<E>& src, + ** oln::abstract::image<F>& dst) ** { - ** oln_iter_type(oln::abstract::image<E>) it(img); - ** for_all(it) + ** oln_iter_type(oln::abstract::image<E>) it_src(src); + ** oln_iter_type(oln::abstract::image<F>) it_dst(dst); + ** + ** it_dst = mlc::begin; + ** for_all(it_src) ** { - ** std::cout << it.row() << " " << it.col() << std::endl; - ** break; + ** dst[it_dst] = src[it_src]; + ** ++it_dst; ** } ** } ** int main() ** { - ** const oln::image2d<ntg::rgb_8> imc = oln::load(IMG_IN "lena.ppm"); - ** assert(imc.has_impl()); - ** foo(oln::morpher::iter_morph<oln_bkd_iter_type_(oln::image2d<ntg::rgb_8>)>(imc)); + ** const oln::image2d<ntg::rgb_8> im = oln::load(IMG_IN "lena.ppm"); + ** oln::image2d<ntg::rgb_8> im_out(im.size()); + ** + ** foo(oln::morpher::iter_morph< + ** oln_bkd_iter_type_(oln::image2d<ntg::rgb_8>)>(im), im_out); + ** oln::save(im_out, IMG_OUT "oln_morpher_iter.pgm"); ** } ** \endcode + ** \image html lena_ppm.png + ** \image latex lena_ppm.png + ** => + ** \image html oln_morpher_iter.png + ** \image latex oln_morpher_iter.png */ template <class IterType, class I> - const iter_morpher<I, IterType> iter_morph(I &ima) + const iter_morpher<I, IterType> + iter_morph(I &ima) { return iter_morpher<I, IterType>(ima); } Index: olena/oln/morpher/slicing_morpher.hh --- olena/oln/morpher/slicing_morpher.hh Mon, 29 Mar 2004 11:23:59 +0200 odou_s (oln/m/42_slicing_mo 1.2 600) +++ olena/oln/morpher/slicing_morpher.hh Sun, 04 Apr 2004 16:29:15 +0200 odou_s (oln/m/42_slicing_mo 1.3 600) @@ -36,107 +36,160 @@
template <class I, class Exact = mlc::final> struct slicing_morpher; + template <class I, class Exact = mlc::final> + struct super_slicing_morpher;
} // end of namespace morpher
- - template <class Image> - struct DecDimensionImage - {}; - template <class Type> - struct DecDimensionImage< oln::image2d<Type> > + /// Informations about the super slicing morpher. + template <class SrcType, class Exact> + struct image_id< morpher::super_slicing_morpher<SrcType, Exact> > { - typedef oln::image1d<Type> ret; + typedef typename mlc::exact_vt< + morpher::super_slicing_morpher<SrcType, Exact>, + Exact>::ret + exact_type; + ///< Retrieve the exact type of the image. + enum {dim = SrcType::dim - 1}; + typedef typename dim_traits<dim, + typename image_id<SrcType>::value_type, + exact_type + >::img_type img_type; + typedef typename image_traits<img_type>::size_type size_type; + typedef typename image_traits<img_type>::impl_type impl_type; }; - template <class Type> - struct DecDimensionImage< oln::image3d<Type> > + + /// Informations about the const super slicing morpher. + template <class SrcType, class Exact> + struct image_id< morpher::super_slicing_morpher<const SrcType, Exact> > { - typedef oln::image2d<Type> ret; + typedef typename mlc::exact_vt< + morpher::super_slicing_morpher<SrcType, Exact>, + Exact>::ret + exact_type; + ///< Retrieve the exact type of the image. + enum {dim = SrcType::dim - 1}; + typedef typename dim_traits<dim, + typename image_id<SrcType>::value_type, + exact_type + >::img_type img_type; + typedef typename image_traits<img_type>::size_type size_type; + typedef typename image_traits<img_type>::impl_type impl_type; };
- /// Inherits identification's informations about the slicing morpher.
Le cas possessif ne s'emploie qu'avec des noms de personne en tant que possesseur.
- template <class I, class Exact> - struct image_id< morpher::slicing_morpher<I, Exact> > - : public image_id<typename DecDimensionImage<I>::ret> - {}; - - /// Inherits identification's informations about the const slicing morpher.
idem.
- template <class I, class Exact> - struct image_id< morpher::slicing_morpher<const I, Exact> > - : public image_id<typename DecDimensionImage<I>::ret> - {}; + /// Informations about the slicing morpher. + template <class SrcType, class Exact> + struct image_id< morpher::slicing_morpher<SrcType, Exact> > + { + typedef typename mlc::exact_vt<morpher::slicing_morpher<SrcType, Exact>, + Exact>::ret exact_type; + ///< Retrieve the exact type of the image. + enum {dim = SrcType::dim - 1}; + typedef typename dim_traits<dim, + typename image_id<SrcType>::value_type, + exact_type + >::img_type img_type; + typedef typename image_id<img_type>::value_type value_type; + typedef typename image_id<img_type>::point_type point_type; + typedef typename image_id<img_type>::size_type size_type; + typedef typename image_id<img_type>::impl_type impl_type; + };
- /// Specialized version for slicing morpher. - template <class I> - struct image_traits< morpher::slicing_morpher<I> > : - public image_traits<abstract::image_with_impl<typename DecDimensionImage<I>::ret::impl_type, - morpher::slicing_morpher<I> > > - {}; + /// Informations about the const slicing morpher. + template <class SrcType, class Exact> + struct image_id< morpher::slicing_morpher<const SrcType, Exact> > + { + typedef typename mlc::exact_vt<morpher::slicing_morpher<SrcType, Exact>, + Exact>::ret exact_type; + ///< Retrieve the exact type of the image. + enum {dim = SrcType::dim - 1}; + typedef typename dim_traits<dim, + typename image_id<SrcType>::value_type, + exact_type + >::img_type img_type; + typedef typename image_id<img_type>::value_type value_type; + typedef typename image_traits<img_type>::point_type point_type; + typedef typename image_traits<img_type>::size_type size_type; + typedef typename image_traits<img_type>::impl_type impl_type; + };
- /// Specialized version for slicing morpher. - template <class I> - struct image_traits< morpher::slicing_morpher<const I> > : - public image_traits<abstract::image_with_impl<typename DecDimensionImage<I>::ret::impl_type, - morpher::slicing_morpher<const I> > > + /// Traits for slicing morpher. + template <class SrcType, class Exact> + struct image_traits< morpher::slicing_morpher<SrcType, Exact> > + : public + image_traits< + morpher::abstract::generic_morpher< + SrcType, + typename image_id<morpher::slicing_morpher<SrcType, + Exact> >::exact_type + > + > {};
namespace morpher {
/// Return a size of N-1 dimension. - oln::image1d_size* image_size_dec(const oln::image2d_size& image_size) + oln::image1d_size + image_size_dec(const oln::image2d_size& image_size) { - // We can't use typedef here because image2d_size and image3d_size don't have - // the same number of arguments. - return new oln::image1d_size(image_size.ncols(), image_size.border()); + return oln::image1d_size(image_size.ncols(), image_size.border()); }
/// Return a size of N-1 dimension. - oln::image2d_size* image_size_dec(const oln::image3d_size& image_size) + oln::image2d_size + image_size_dec(const oln::image3d_size& image_size) { - // We can't use typedef here because image2d_size and image3d_size don't have - // the same number of arguments. - return new oln::image2d_size(image_size.nrows(), image_size.ncols(), image_size.border()); + return oln::image2d_size(image_size.nrows(), + image_size.ncols(), + image_size.border()); }
- /// Abstract piece morpher class used for code factorization. - template <class DestType, class SrcType, class Exact> - class super_slicing_morpher : public abstract::generic_morpher<DestType, SrcType, Exact> + /// Abstract slicing morpher class used for code factorization. + template <class SrcType, class Exact> + class super_slicing_morpher + : public abstract::generic_morpher<SrcType, Exact> { + public:
- typedef oln_size_type(DestType) size_type; - typedef oln_impl_type(DestType) impl_type; - typedef abstract::generic_morpher<DestType, SrcType, Exact> super_type; + typedef super_slicing_morpher<SrcType, Exact> self_type; + typedef typename image_id<self_type>::exact_type exact_type; + typedef abstract::generic_morpher<SrcType, Exact> super_type; + + typedef typename image_id<exact_type>::size_type size_type; + typedef typename image_id<exact_type>::impl_type impl_type;
/// Override the size method. const size_type& size() const { - return *size_; + return size_; }
/// Override the impl method. const impl_type* impl() const { - return impl_; + return &impl_; }
/// Override the impl method. impl_type* impl() { - return impl_; + return &impl_; }
- ///< Return the last coordinate' value. - coord get_slice() const + /// Return the last coordinate' value. + coord + get_slice() const { return slice_; }
/// Useful to debug. - static std::string name() + static std::string + name() { return "super_slicing_morpher<" + super_type::name() + ">"; } @@ -152,62 +205,56 @@ ** since it is protected. */ super_slicing_morpher(const SrcType &ima, const coord slice) - : super_type(ima), impl_(0), size_(0), slice_(slice) - { - size_ = image_size_dec(ima_.size()); - impl_ = new impl_type(*size_); - } - - /// Destructor - ~super_slicing_morpher() - { - delete size_; - delete impl_; - } + : super_type(ima), slice_(slice), size_(image_size_dec(ima_.size())), impl_(size_) + {}
/*! ** \brief Empty constructor. ** ** Needed by mlc_hierarchy::any_with_diamond. + ** \todo create empty constructors for impl_, ... */ - super_slicing_morpher() : impl_(0), size_(0), slice_(0) + super_slicing_morpher() {}
- impl_type *impl_; - size_type *size_; ///< The size of the N-1 dimension image. coord slice_; ///< The last coordinate. + const size_type size_; ///< The size of the N-1 dimension image. + impl_type impl_;
};
/*! - ** \brief The default piece morpher class. + ** \brief The default slicing morpher class. ** - ** Using this class, a piece of picture is a picture. + ** Using this class, a slicing of picture is a picture. ** ** \see oln::morpher::abstract::generic_morpher - ** \see oln::morpher::piece_morph + ** \see oln::morpher::slicing_morph */ template <class SrcType, class Exact> struct slicing_morpher - : public super_slicing_morpher< typename DecDimensionImage<SrcType>::ret, SrcType, slicing_morpher<SrcType, Exact> > + : public super_slicing_morpher< + SrcType, + typename image_id<slicing_morpher<SrcType, Exact> >::exact_type + > { - typedef typename image_id< slicing_morpher<SrcType, Exact> >::exact_type exact_type; typedef slicing_morpher<SrcType, Exact> self_type; - typedef typename DecDimensionImage<SrcType>::ret DestType; - typedef super_slicing_morpher<DestType, SrcType, slicing_morpher<SrcType, Exact> > super_type; + typedef typename image_id<self_type>::exact_type exact_type; + typedef super_slicing_morpher<SrcType, exact_type> super_type;
- typedef oln_value_type(DestType) value_type; - typedef oln_point_type(DestType) point_type; + typedef typename image_id<exact_type>::point_type point_type; + typedef typename image_id<exact_type>::img_type img_type; + typedef typename image_id<exact_type>::value_type value_type;
/*! - ** \brief Construct a piece morpher. + ** \brief Construct a slicing morpher. ** \arg ima The image. ** \arg slice The slice value. */ slicing_morpher(const SrcType &ima, coord slice) : super_type(ima, slice) {}
- /// Construct a piece morpher from another one. + /// Construct a slicing morpher from another one. slicing_morpher(const self_type& r) : super_type(r.get_ima(), r.get_slice()) {}
@@ -223,7 +270,8 @@ ** \arg p The point. ** \return The stored value. */ - value_type& at(const point_type &p) + value_type& + at(const point_type &p) { typename SrcType::point_type tmp_p(p, slice_); return const_cast<value_type &>(this->ima_)[tmp_p]; @@ -254,35 +302,39 @@ ** \brief This operator= assigns rhs to the current image. */ self_type& - operator=(DestType& rhs) + operator=(self_type& rhs) { return this->exact().assign(rhs); }
/// Useful to debug. - static std::string name() + static std::string + name() { return "slicing_morpher<" + super_type::name() + ">"; }
};
- /// The specialized version for `const' declared images. + /// The specialized version for `const' images. template <class SrcType, class Exact> struct slicing_morpher<const SrcType, Exact> - : public super_slicing_morpher<typename DecDimensionImage<SrcType>::ret, SrcType, slicing_morpher<const SrcType, Exact> > + : public super_slicing_morpher< + const SrcType, + typename image_id<slicing_morpher<const SrcType, Exact> >::exact_type + > { - /// The type of the object instantiated. piece morpher can be derived. - typedef typename image_id<slicing_morpher<const SrcType, Exact> >::exact_type exact_type; - typedef slicing_morpher<SrcType, Exact> self_type; - typedef typename DecDimensionImage<SrcType>::ret DestType; - typedef super_slicing_morpher<DestType, SrcType, slicing_morpher<const SrcType, Exact> > super_type;
- typedef oln_value_type(DestType) value_type; - typedef oln_point_type(DestType) point_type; + typedef slicing_morpher<const SrcType, Exact> self_type; + typedef typename image_id<self_type>::exact_type exact_type; + typedef super_slicing_morpher<const SrcType, exact_type> super_type; + + typedef typename image_id<exact_type>::point_type point_type; + typedef typename image_id<exact_type>::value_type value_type; +
/*! - ** \brief Construct a piece morpher. + ** \brief Construct a slicing morpher. ** \arg ima The image. ** \arg slice The slice value. */ @@ -290,7 +342,7 @@ : super_type(ima, slice) {}
- /// Construct a piece morpher from another one. + /// Construct a slicing morpher from another one. slicing_morpher(const self_type& r) : super_type(r.get_ima(), r.get_slice()) {} @@ -308,14 +360,16 @@ ** \arg p The point. ** \return The stored value. */ - const value_type at(const point_type &p) const + const value_type + at(const point_type &p) const { typename SrcType::point_type tmp_p(p, slice_); return this->ima_[tmp_p]; }
/// Useful to debug. - static std::string name() + static std::string + name() { return "slicing_morpher<" + super_type::name() + ">"; } @@ -347,7 +401,8 @@ ** \image latex oln_morpher_slicing_morpher.png */ template <class I> - const slicing_morpher<I> slicing_morph(I &ima, coord slice) + const slicing_morpher<I> + slicing_morph(I &ima, coord slice) { return slicing_morpher<I>(ima, slice); } Index: olena/tests/morpher/tests/iter --- olena/tests/morpher/tests/iter Sun, 04 Apr 2004 16:50:04 +0200 odou_s () +++ olena/tests/morpher/tests/iter Sun, 04 Apr 2004 16:29:52 +0200 odou_s (oln/q/3_iter 1.1 600) @@ -0,0 +1,71 @@ +// -*- c++ -*- +#include <oln/morpher/iter_morpher.hh> +#include <oln/basics2d.hh> +#include <ntg/all.hh> + +#include <oln/utils/md5.hh> +#include "data.hh" +#include "check.hh" + +// Try to read from the morpher. +template <class E, class F> +void foo(const oln::abstract::image<E>& src, oln::abstract::image<F>& dst) +{ + oln_iter_type(oln::abstract::image<E>) it_src(src); + oln_iter_type(oln::abstract::image<F>) it_dst(dst); + + it_dst = mlc::begin; + for_all(it_src) + { + dst[it_dst] = src[it_src]; + ++it_dst; + } +} + +// Try to write inside the morpher. +template <class E, class F> +void foo(oln::abstract::image<E>& src, oln::abstract::image<F>& dst) +{ + oln_iter_type(oln::abstract::image<E>) it_src(src); + oln_iter_type(oln::abstract::image<F>) it_dst(dst); + + it_dst = mlc::begin; + for_all(it_src) + { + src[it_src] = dst[it_dst]; + ++it_dst; + } +} + +int main() +{ + bool fail (false); + + oln::utils::key::value_type data_key_inv[16] + = {0xd4, 0x2a, 0xe0, 0xc7, 0xc4, 0xea, 0xbc, 0xe4, + 0x10, 0x6, 0x52, 0x12, 0xba, 0x8d, 0xa4, 0x4c}; + + oln::image2d<ntg::rgb_8> im = oln::load(rdata("lena.ppm")); + oln::image2d<ntg::rgb_8> im_out(im.size()); + + const oln::image2d<ntg::rgb_8> im_const = oln::load(rdata("lena.ppm")); + oln::image2d<ntg::rgb_8> im_const_out(im_const.size()); + + oln::morpher::iter_morpher< oln::image2d<ntg::rgb_8>, + oln_bkd_iter_type_(oln::image2d<ntg::rgb_8>) > it_nonconst(im); + + foo(it_nonconst, im); + foo(oln::morpher::iter_morph<oln_bkd_iter_type_(oln::image2d<ntg::rgb_8>)>(im), im_out); + foo(oln::morpher::iter_morph<oln_bkd_iter_type_(oln::image2d<ntg::rgb_8>)>(im_const), im_const_out); + + fail = fail | (oln::utils::md5(im_out) != oln::utils::md5(it_nonconst)); + fail = fail | (oln::utils::md5(im_const_out) != oln::utils::key(data_key_inv)); + + if (!fail) + std::cout << "OK" << std::endl; + else + { + std::cout << "FAIL" << std::endl; + return true; + } +}
Y'a-t-il des des sans md5. Ce dernier, c'est l'arme ultime, il ne doit etre ustilise que si il est impossible de faire d'autre tests.
Index: olena/tests/morpher/tests/piece --- olena/tests/morpher/tests/piece Sun, 04 Apr 2004 16:50:04 +0200 odou_s () +++ olena/tests/morpher/tests/piece Sun, 04 Apr 2004 16:29:58 +0200 odou_s (oln/q/43_piece 1.1 600) @@ -0,0 +1,66 @@ +// -*- c++ -*- +#include <oln/morpher/piece_morpher.hh> +#include <oln/basics2d.hh> +#include <ntg/all.hh> + +#include <oln/utils/md5.hh> +#include "data.hh" +#include "check.hh" + +// Try to read from the morpher. +template <class E, class F> +void foo(const oln::abstract::image<E>& src, oln::abstract::image<F>& dst) +{ + oln_iter_type(oln::abstract::image<E>) it(src); + for_all(it) + dst[it] = src[it]; +} + +// Try to write inside the morpher. +template <class E, class F> +void foo(oln::abstract::image<E>& src, oln::abstract::image<F>& dst) +{ + oln_iter_type(oln::abstract::image<E>) it_src(src); + + for_all(it_src) + src[it_src] = dst[it_src]; +} + +int main() +{ + bool fail (false); + + oln::utils::key::value_type data_key[16] + = {0x2b, 0x8b, 0x3c, 0x8e, 0x92, 0x90, 0xc8, 0x9, + 0xba, 0xfd, 0xc5, 0x52, 0x7c, 0xde, 0xa5, 0x6c}; + + oln::image2d<ntg::rgb_8> im = oln::load(rdata("lena.ppm")); + const oln::image2d<ntg::rgb_8> im_const = oln::load(rdata("lena.ppm")); + oln::image2d<ntg::rgb_8> im_out(oln::image2d_size(30, 60, im.border())); + oln::image2d<ntg::rgb_8> im_const_out(oln::image2d_size(30, 60, im.border())); + + oln::morpher::piece_morpher< oln::image2d<ntg::rgb_8> > im_nonconst_out(im, + oln::dpoint2d(246, 244), + oln::image2d_size(30, 60, im.border())); + + foo(im_nonconst_out, im); + foo(oln::morpher::piece_morph(im, + oln::dpoint2d(246, 244), + oln::image2d_size(30, 60, im.border())), + im_out); + foo(oln::morpher::piece_morph(im_const, + oln::dpoint2d(246, 244), + oln::image2d_size(30, 60, im.border())), + im_const_out); + + fail = fail | (oln::utils::md5(im_out) != oln::utils::md5(im_nonconst_out)); + fail = fail | (oln::utils::md5(im_const_out) != oln::utils::key(data_key)); + + if (!fail) + std::cout << "OK" << std::endl; + else + { + std::cout << "FAIL" << std::endl; + return true; + } +}
idem.
Index: olena/tests/morpher/tests/slicing --- olena/tests/morpher/tests/slicing Sun, 04 Apr 2004 16:50:04 +0200 odou_s () +++ olena/tests/morpher/tests/slicing Sun, 04 Apr 2004 16:29:47 +0200 odou_s (oln/q/44_slicing 1.1 600) @@ -0,0 +1,46 @@ +#include <oln/morpher/slicing_morpher.hh> +#include <oln/basics2d.hh> +#include <ntg/all.hh> + +#include <oln/utils/md5.hh> +#include "data.hh" +#include "check.hh" + +// Try to read from the morpher. +template <class E, class F> +void foo(const oln::abstract::image<E>& src, oln::abstract::image<F>& dst) +{ + oln_iter_type(oln::abstract::image<E>) it(src); + for_all(it) + dst[it] = src[it]; +} + + +int main(int argc, char *argv[]) +{ + bool fail (false); + + oln::utils::key::value_type data_key[16] + = {0xc1, 0x3a, 0x47, 0xb, 0x6f, 0xff, 0xac, 0x97, + 0xab, 0xa0, 0xf, 0x6c, 0x2a, 0x4a, 0xcb, 0x1}; + + oln::image2d<ntg::rgb_8> im = oln::load(rdata("lena.ppm")); + const oln::image2d<ntg::rgb_8> im_const = oln::load(rdata("lena.ppm")); + oln::image1d<ntg::rgb_8> im_out(im.ncols()); + oln::image1d<ntg::rgb_8> im_const_out(im_const.ncols()); + + foo(oln::morpher::slicing_morph(im, 5), im_out); + foo(oln::morpher::slicing_morph(im_const, 5), im_const_out); + + std::cout << oln::utils::md5(im_const_out) << std::endl; + fail = fail | (oln::utils::md5(im_out) != oln::utils::md5(im_const_out)); + fail = fail | (oln::utils::md5(im_const_out) != oln::utils::key(data_key)); + + if (!fail) + std::cout << "OK" << std::endl; + else + { + std::cout << "FAIL" << std::endl; + return true; + } +}
idem. -- Giovanni Palma EPITA - promo 2005 - membre d'EpX - LRDE Mob. : +33 (0)6 60 97 31 74