olena-2.0-14-g849c137 Work around decorated_image's lack of properties, for the recorder.

* apps/morphers/recorder.hh (trait::image_< decorated_image<I,D> >): Replace with.. (trait::image_< decorated_image<I, recorder<I> > >): ...this. Add a value_storage property. (ch_value_< decorated_image< image_<I>, data_< recorder<I> > >, V >): New trait, to handle changes of value types in images decorated with a recorder. * apps/morphers/mask+channel.cc, * apps/morphers/mask+recorder.cc, * apps/morphers/recorder.cc: Simplify these programs thanks to the preceding changes. --- milena/ChangeLog | 16 +++++++ milena/apps/morphers/mask+channel.cc | 7 +-- milena/apps/morphers/mask+recorder.cc | 6 +-- milena/apps/morphers/recorder.cc | 5 +-- milena/apps/morphers/recorder.hh | 77 ++++++++++++++++++++++++++++++--- 5 files changed, 91 insertions(+), 20 deletions(-) diff --git a/milena/ChangeLog b/milena/ChangeLog index 84c70af..4b904dc 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,21 @@ 2011-11-24 Roland Levillain <roland@lrde.epita.fr> + Work around decorated_image's lack of properties, for the recorder. + + * apps/morphers/recorder.hh + (trait::image_< decorated_image<I,D> >): Replace with.. + (trait::image_< decorated_image<I, recorder<I> > >): ...this. + Add a value_storage property. + (ch_value_< decorated_image< image_<I>, data_< recorder<I> > >, V >): + New trait, to handle changes of value types in images decorated + with a recorder. + * apps/morphers/mask+channel.cc, + * apps/morphers/mask+recorder.cc, + * apps/morphers/recorder.cc: + Simplify these programs thanks to the preceding changes. + +2011-11-24 Roland Levillain <roland@lrde.epita.fr> + Fix the initialization of mln::decorated_image. * mln/tag/init.hh (tag::data_t): New tag type. diff --git a/milena/apps/morphers/mask+channel.cc b/milena/apps/morphers/mask+channel.cc index 2e170a2..130a168 100644 --- a/milena/apps/morphers/mask+channel.cc +++ b/milena/apps/morphers/mask+channel.cc @@ -61,10 +61,7 @@ int main() image2d<rgb8> lena = io::ppm::load<rgb8>(MLN_IMG_DIR "/tiny.ppm"); fun::green green; - /* FIXME: Cheat: use generic fill as mln::decorated_image does not - define properly its properties. */ - data::impl::generic::fill_with_value((thru(green, lena).rw() | - make::box2d(5,5, 10,10)).rw(), - 255); + data::fill((thru(green, lena).rw() | make::box2d(5,5, 10,10)).rw(), + 255); io::ppm::save(lena, "lena-mask-channel.ppm"); } diff --git a/milena/apps/morphers/mask+recorder.cc b/milena/apps/morphers/mask+recorder.cc index 2693dbc..067ff6e 100644 --- a/milena/apps/morphers/mask+recorder.cc +++ b/milena/apps/morphers/mask+recorder.cc @@ -59,9 +59,7 @@ int main() typedef image2d<rgb8> I; I lena = io::ppm::load<rgb8>(MLN_IMG_DIR "/tiny.ppm"); decorated_image< I, recorder<I> > lena_rec = record(lena); - /* FIXME: Cheat: use generic fill as mln::decorated_image does not - define properly its properties. */ - data::impl::generic::fill_with_value((lena_rec | make::box2d(5,5, 10,10)).rw(), - literal::green); + data::fill((lena_rec | make::box2d(5,5, 10,10)).rw(), + literal::green); ppm::save(lena_rec, "lena-roi-fill"); } diff --git a/milena/apps/morphers/recorder.cc b/milena/apps/morphers/recorder.cc index 4a3f1ab..86af667 100644 --- a/milena/apps/morphers/recorder.cc +++ b/milena/apps/morphers/recorder.cc @@ -56,9 +56,6 @@ int main() typedef image2d<rgb8> I; I lena = io::ppm::load<rgb8>(MLN_IMG_DIR "/tiny.ppm"); decorated_image< I, recorder<I> > lena_rec = record(lena); - /* FIXME: Cheat: use generic fill as mln::decorated_image does not - define properly its properties. */ - data::impl::generic::fill_with_value(lena_rec, - literal::green); + data::fill(lena_rec, literal::green); ppm::save(lena_rec, "lena-fill"); } diff --git a/milena/apps/morphers/recorder.hh b/milena/apps/morphers/recorder.hh index 98b5f70..f8fc4f4 100644 --- a/milena/apps/morphers/recorder.hh +++ b/milena/apps/morphers/recorder.hh @@ -36,6 +36,8 @@ #include <string> +#include <mln/trait/ch_value.hh> + #include <mln/core/image/imorph/decorated_image.hh> #include <mln/value/rgb8.hh> @@ -47,22 +49,29 @@ #include "apps/data.hh" -// FIXME: mln::decorated_image lacks a proper definition of -// properties! (see mln/core/image/imorph/decorated_image.hh). We use -// the following (minimal) set of properties as a workaround. +// Forward declaration. +template <typename I> struct recorder; + +/* FIXME: mln::decorated_image lacks a proper definition of + properties! (see mln/core/image/imorph/decorated_image.hh). We use + the following (minimal) set of properties as a workaround for the + recorder decoration. */ namespace mln { - namespace trait { - template <typename I, typename D> - struct image_< decorated_image<I,D> > + template <typename I> + struct image_< decorated_image< I, recorder<I> > > : default_image_morpher< I, mln_value(I), - decorated_image<I,D> > + decorated_image< I, recorder<I> > > { typedef trait::image::category::identity_morpher category; + + // Prevent fast processing of images requiring a specific + // interface that we are unable to retrieve now. + typedef trait::image::value_storage::disrupted value_storage; }; } // end of namespace mln::trait @@ -87,6 +96,60 @@ struct recorder std::vector<I> sequence; }; +/* Skeleton of an image decorated with a recorder. + + Initialy, I (Roland) wanted to add this to mln/trait/ch_value.hh: + + template < template <class, class> class M, typename I, typename D, + typename V > + struct ch_value_< M< tag::image_<I>, tag::data_<D> >, V > + { + typedef M< mln_ch_value(I, V), D > ret; + }; + + However, this would not work in the case of the recorder since the + type D of the data attached to the image (of type I) has to be + changed as well. Indeed the initial decoration contains a sequence + of images of type I, which should be changed into a sequence of + images of type mln_ch_value(I, V). + + There are several option to improve this. One is to create a + ch_value trait for data/decorations such as `recorder<I>'. Another + one is to refine the skeleton of decorated_image<I, D> to have it + convey the type the data stored in the decoration, e.g, changing + + typedef decorated_image< tag::image_<I>, tag::data_<D> > skeleton; + + into something like + + typedef decorated_image< tag::image_<I>, tag::data_<D, V> > skeleton; + + but this seems overly complicated. + + The workaround chosen here is very local, and address the very + specific case of decorated_image< I, recorder<I> >. */ + +namespace mln +{ + namespace trait + { + namespace impl + { + template < typename I, typename V > + struct ch_value_< decorated_image< tag::image_<I>, + tag::data_< recorder<I> > >, + V > + { + typedef decorated_image< mln_ch_value(I, V), + recorder< mln_ch_value(I, V) > > ret; + }; + } // end namespace mln::trait::impl + + } // end namespace mln::trait + +} // end namespace mln + +// Helper. template <typename I> mln::decorated_image< I, recorder<I> > record(mln::Image<I>& ima) -- 1.7.2.5
participants (1)
-
Roland Levillain