
Index: olena/ChangeLog from Simon Odou <simon@lrde.epita.fr> * oln/morpher/piece_morpher.hh: To use a piece of image like a real one. * oln/core/abstract/image_with_impl.hh: * oln/core/point2d.hh: Able to construct a point2d from a point1d. * oln/core/point2d.hxx: Likewise. * oln/core/point3d.hh: Able to construct a point3d from a point2d. * oln/core/point3d.hxx: Likewise. * oln/core/abstract/image_with_dim.hh: Fix a bug. * oln/core/abstract/image_with_impl.hh: Fix (same). Index: olena/oln/core/point2d.hh --- olena/oln/core/point2d.hh Fri, 12 Mar 2004 20:17:58 +0100 thivol_d (oln/c/30_point2d.hh 1.13 600) +++ olena/oln/core/point2d.hh Mon, 29 Mar 2004 05:38:52 +0200 odou_s (oln/c/30_point2d.hh 1.13 600) @@ -75,6 +75,10 @@ point2d(coord row, coord col); + /// The coordinates of the point2d are set to \a p and \a col. + + point2d(const point1d& p, coord col); + /// Return Give the value of the point2d row coordinate. coord Index: olena/oln/core/point2d.hxx --- olena/oln/core/point2d.hxx Mon, 19 Jan 2004 18:35:23 +0100 astrid (oln/c/29_point2d.hx 1.6 640) +++ olena/oln/core/point2d.hxx Mon, 29 Mar 2004 05:39:17 +0200 odou_s (oln/c/29_point2d.hx 1.6 640) @@ -1,4 +1,4 @@ -// Copyright (C) 2001, 2002 EPITA Research and Development Laboratory +// Copyright (C) 2001, 2002, 2004 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 @@ -48,6 +48,13 @@ nth(1) = col; } + inline + point2d::point2d(const point1d& p, coord row) + { + nth(0) = row; + nth(1) = p.col(); + } + inline coord point2d::row() const { Index: olena/oln/core/point3d.hh --- olena/oln/core/point3d.hh Fri, 12 Mar 2004 20:17:58 +0100 thivol_d (oln/c/28_point3d.hh 1.15 600) +++ olena/oln/core/point3d.hh Mon, 29 Mar 2004 05:40:21 +0200 odou_s (oln/c/28_point3d.hh 1.15 600) @@ -80,6 +80,10 @@ point3d(coord slice, coord row, coord col); + /// The coordinates of the point3d are set to \a p, and \a slice. + + point3d(const point2d& p, coord slice); + /// Return the value of the point3d slice coordinate. coord Index: olena/oln/core/point3d.hxx --- olena/oln/core/point3d.hxx Mon, 28 Jul 2003 14:14:03 +0200 david (oln/c/27_point3d.hx 1.5 640) +++ olena/oln/core/point3d.hxx Mon, 29 Mar 2004 05:39:24 +0200 odou_s (oln/c/27_point3d.hx 1.5 640) @@ -1,4 +1,4 @@ -// Copyright (C) 2001, 2002 EPITA Research and Development Laboratory +// Copyright (C) 2001, 2002, 2004 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 @@ -51,6 +51,14 @@ nth(2) = col; } + inline + point3d::point3d(const point2d& p, coord slice) + { + nth(0) = slice; + nth(1) = p.row(); + nth(2) = p.col(); + } + inline coord point3d::slice() const { Index: olena/oln/core/abstract/image_with_dim.hh --- olena/oln/core/abstract/image_with_dim.hh Sun, 14 Mar 2004 19:03:34 +0100 van-vl_n (oln/t/26_image_with 1.21 600) +++ olena/oln/core/abstract/image_with_dim.hh Mon, 29 Mar 2004 00:47:04 +0200 odou_s (oln/t/26_image_with 1.21 600) @@ -325,7 +325,7 @@ coord nrows() const { - return this->size().nrows(); + return this->exact().size().nrows(); } @@ -334,7 +334,7 @@ coord ncols() const { - return this->size().ncols(); + return this->exact().size().ncols(); } /*! \brief Return the value stored at \a row, \a col Index: olena/oln/core/abstract/image_with_impl.hh --- olena/oln/core/abstract/image_with_impl.hh Fri, 26 Mar 2004 12:53:24 +0100 thivol_d (oln/t/27_image_with 1.14.1.10 640) +++ olena/oln/core/abstract/image_with_impl.hh Mon, 29 Mar 2004 00:51:00 +0200 odou_s (oln/t/27_image_with 1.14.1.10 640) @@ -145,6 +145,17 @@ return impl_; } + /*! + ** \brief Get the size of the image. + ** \return The size. + */ + const size_type& + size() const + { + assertion(has_impl()); + return this->exact().impl()->size(); + } + /// Return the core data of the image. impl_type* Index: olena/oln/morpher/piece_morpher.hh --- olena/oln/morpher/piece_morpher.hh Mon, 29 Mar 2004 09:25:14 +0200 odou_s () +++ olena/oln/morpher/piece_morpher.hh Mon, 29 Mar 2004 09:15:56 +0200 odou_s (oln/m/40_piece_morp 644) @@ -0,0 +1,314 @@ +// Copyright (C) 2004 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, 59 Temple Place - Suite 330, 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 PIECE_MORPHER_HH +# define PIECE_MORPHER_HH + +# include <oln/morpher/generic_morpher.hh> + +namespace oln { + + namespace morpher { + + template <class I, class Exact = mlc::final> + struct 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> + {}; + + /// 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> + {}; + + /// 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> > > + {}; + + + namespace morpher { + + /// Abstract piece morpher class used for code factorization. + template <class SrcType, class Exact> + class super_piece_morpher : public abstract::generic_morpher<SrcType, 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; + + protected: + + /*! + ** \brief Default constructor. + ** \arg ima will be the image. + ** \arg p The reference point. + ** \arg s The size of the piece of image. + ** + ** One can not use this constructor to instantiate this class + ** since it is protected. + */ + super_piece_morpher(const SrcType &ima, const dpoint_type& p, + const size_type& s) + : super_type(ima), size_(s), p_(p) + {} + + const size_type size_; ///< The size 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_) {} + + public: + + /// Return the size (different from the original picture). + const size_type size() const + { + return size_; + } + + /// Return the reference point. + const dpoint_type ref_point() const + { + return p_; + } + + /// Useful to debug. + static std::string name() + { + return "super_piece_morpher<" + super_type::name() + ">"; + } + + }; + + /*! + ** \brief The default piece morpher class. + ** + ** Using this class, a piece of picture is a picture. + ** + ** \see oln::morpher::abstract::generic_morpher + ** \see oln::morpher::piece_morph + */ + template <class SrcType, class Exact> + struct piece_morpher + : public super_piece_morpher<SrcType, piece_morpher<SrcType, Exact> > + { + /// 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 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; + + /// Construct the piece morpher with an image \a ima. + piece_morpher(const SrcType &ima, const dpoint_type p, + const size_type s) + : super_type(ima, p, s) + {} + + /// Construct the piece morpher with another piece morpher. + piece_morpher(const self_type& r) + : super_type(r.get_ima(), r.ref_point(), r.size()) + {} + + /*! + ** \brief Empty constructor. + ** + ** Needed by mlc_hierarchy::any_with_diamond. + */ + piece_morpher() + {} + + /*! + ** \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 &>(this->ima_)[p + 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 + p_]; + } + + /*! 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(); + } + + /*! + ** \brief This operator= assigns rhs to the current image. + */ + self_type& + operator=(SrcType& rhs) + { + return this->exact().assign(rhs); + } + + /// Useful to debug. + static std::string name() + { + return "piece_morpher<" + super_type::name() + ">"; + } + + }; + + /// The specialized version for `const' declared images. + template <class SrcType, class Exact> + struct piece_morpher<const SrcType, Exact> + : public super_piece_morpher< SrcType, piece_morpher<const SrcType, Exact> > + { + /// 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 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; + + /*! + ** \brief Construct a piece morpher. + ** \arg ima The image. + ** \arg p The reference point. + ** \arg s The size. + */ + piece_morpher(const SrcType &ima, const dpoint_type p, + const size_type s) + : super_type(ima, p, s) + {} + + /// Construct a piece morpher from another one. + piece_morpher(const self_type& r) + : super_type(r.get_ima(), r.ref_point(), r.size()) + {} + + /*! + ** \brief Empty constructor. + ** + ** Needed by mlc_hierarchy::any_with_diamond. + */ + piece_morpher() {} + + /*! + ** \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 + p_]; + } + + /// Useful to debug. + static std::string name() + { + return "piece_morpher<" + super_type::name() + ">"; + } + + }; + + + /*! + ** \brief Instantiate a temporary read-only piece morpher. + ** \arg ima The image. + ** \arg p The reference's point. + ** \arg s The size of the window. + ** + ** A piece of the image will be viewed. + ** + ** \code + ** #include <oln/morpher/piece_morpher.hh> + ** #include <oln/basics2d.hh> + ** #include <ntg/all.hh> + ** int main() + ** { + ** 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())), + ** IMG_OUT "oln_morpher_piece_morpher.pgm"); + ** } + ** \endcode + ** \image html lena_ppm.png + ** \image latex lena_ppm.png + ** => + ** \image html oln_morpher_piece_morpher.png + ** \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) + { + return piece_morpher<I>(ima, p, s); + } + + + } // end namespace morpher + +} // end namespace oln + +#endif // !PIECE_MORPHER -- Simon Odou simon@lrde.epita.fr

Simon Odou <simon@lrde.epita.fr> writes:
* oln/core/point2d.hh: Able to construct a point2d from a point1d. * oln/core/point2d.hxx: Likewise. * oln/core/point3d.hh: Able to construct a point3d from a point2d. * oln/core/point3d.hxx: Likewise.
En fait, ce n'est pas utile pour le iter morpher mais pour le slicing morpher... Et je ne sais pas comment faire ça "proprement". Peut-être que j'aurais dû le laisser dans le fichier du morpher pour ne pas polluer le reste ? Ou si quelqu'un voit comment créer un point N-1 dimensions à partir d'un point N dimensions sans avoir à écrire chaque cas ? -- Simon Odou simon@lrde.epita.fr
participants (1)
-
Simon Odou