* apps/morphers/recorder.cc,
* apps/morphers/mask+recorder.cc:
Factor common parts...
* apps/morphers/recorder.hh: ...here (new file).
* apps/morphers/Makefile.am
(recorder_SOURCES, mask_recorder_SOURCES): Add recorder.hh.
---
milena/ChangeLog | 11 +++
milena/apps/morphers/Makefile.am | 4 +-
milena/apps/morphers/mask+recorder.cc | 81 +--------------------
milena/apps/morphers/recorder.cc | 79 +-------------------
milena/apps/morphers/{recorder.cc => recorder.hh} | 35 ++-------
5 files changed, 29 insertions(+), 181 deletions(-)
copy milena/apps/morphers/{recorder.cc => recorder.hh} (74%)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index c10deb8..554d827 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,14 @@
+2011-11-18 Roland Levillain <roland(a)lrde.epita.fr>
+
+ Refactor apps/morphers.
+
+ * apps/morphers/recorder.cc,
+ * apps/morphers/mask+recorder.cc:
+ Factor common parts...
+ * apps/morphers/recorder.hh: ...here (new file).
+ * apps/morphers/Makefile.am
+ (recorder_SOURCES, mask_recorder_SOURCES): Add recorder.hh.
+
2011-11-14 Roland Levillain <roland(a)lrde.epita.fr>
Add examples of morphers.
diff --git a/milena/apps/morphers/Makefile.am b/milena/apps/morphers/Makefile.am
index d7af433..d448c1d 100644
--- a/milena/apps/morphers/Makefile.am
+++ b/milena/apps/morphers/Makefile.am
@@ -28,8 +28,8 @@ noinst_PROGRAMS = \
mask+recorder
mask_channel_SOURCES = mask+channel.cc
-recorder_SOURCES = recorder.cc
-mask_recorder_SOURCES = mask+recorder.cc
+recorder_SOURCES = recorder.cc recorder.hh
+mask_recorder_SOURCES = mask+recorder.cc recorder.hh
MOSTLYCLEANFILES = \
lena-mask-channel.ppm \
diff --git a/milena/apps/morphers/mask+recorder.cc
b/milena/apps/morphers/mask+recorder.cc
index d697451..4689a99 100644
--- a/milena/apps/morphers/mask+recorder.cc
+++ b/milena/apps/morphers/mask+recorder.cc
@@ -24,7 +24,7 @@
// executable file might be covered by the GNU General Public License.
/// \file
-/// \brief Morpher recording every change in the morphed image
+/// \brief Exercise a morpher recording every change in the morphed image
/// followed by the application of a domain restriction with a mask.
///
/// To produce an AVI movie from the `lena-roi-fill*.ppm' files, use:
@@ -34,93 +34,20 @@
///
/// The output `lena-roi-fill.avi' can be embedded in a PDF file. */
-// FIXME: Factor with recorder.cc.
-
-#include <sstream>
-#include <iomanip>
-
#include <string>
#include <mln/core/image/image2d.hh>
#include <mln/core/image/dmorph/image_if.hh>
-#include <mln/core/image/imorph/decorated_image.hh>
#include <mln/value/rgb8.hh>
-
-#include <mln/core/routine/duplicate.hh>
-
#include <mln/literal/colors.hh>
#include <mln/data/fill.hh>
-#include <mln/io/ppm/all.hh>
-
-#include "apps/data.hh"
-
-
-// FIXME: mln::decorated_image lacks a proper definition of
-// properties! (see mln/core/image/imorph/decorated_image.hh
-namespace mln
-{
-
- namespace trait
- {
-
- template <typename I, typename D>
- struct image_< decorated_image<I,D> >
- : default_image_morpher< I,
- mln_value(I),
- decorated_image<I,D> >
- {
- typedef trait::image::category::identity_morpher category;
- };
-
- } // end of namespace mln::trait
+#include <mln/io/ppm/load.hh>
-} // end of namespace mln
+#include "apps/morphers/recorder.hh"
-
-// Recorder.
-template <typename I>
-struct recorder
-{
- void reading(const I&, const mln_psite(I)&) const
- {
- // N/A.
- }
-
- void writing(I& ima, const mln_psite(I)&, const mln_value(I)&)
- {
- sequence.push_back(mln::duplicate(ima));
- }
-
- std::vector<I> sequence;
-};
-
-template <typename I>
-mln::decorated_image< I, recorder<I> >
-record(mln::Image<I>& ima)
-{
- return mln::decorate(ima, recorder<I>());
-}
-
-
-// I/O.
-namespace ppm
-{
- template <typename I>
- void
- save(const mln::decorated_image< I, recorder<I> >& rec,
- const std::string& prefix)
- {
- for (size_t i = 0; i < rec.decoration().sequence.size(); ++i)
- {
- std::stringstream s;
- s << std::setfill ('0') << std::setw (6) << i;
- mln::io::ppm::save(rec.decoration().sequence[i],
- prefix + s.str() + ".ppm");
- }
- }
-}
+#include "apps/data.hh"
int main()
diff --git a/milena/apps/morphers/recorder.cc b/milena/apps/morphers/recorder.cc
index 195f24c..4a3f1ab 100644
--- a/milena/apps/morphers/recorder.cc
+++ b/milena/apps/morphers/recorder.cc
@@ -24,7 +24,7 @@
// executable file might be covered by the GNU General Public License.
/// \file
-/// \brief Morpher recording every change in the morphed image.
+/// \brief Exercise a morpher recording every change in the morphed image.
///
/// To produce an AVI movie from the `lena-fill*.ppm' files, use:
///
@@ -33,90 +33,19 @@
///
/// The output `lena-fill.avi' can be embedded in a PDF file. */
-#include <sstream>
-#include <iomanip>
-
#include <string>
#include <mln/core/image/image2d.hh>
-#include <mln/core/image/imorph/decorated_image.hh>
#include <mln/value/rgb8.hh>
-
-#include <mln/core/routine/duplicate.hh>
-
#include <mln/literal/colors.hh>
#include <mln/data/fill.hh>
-#include <mln/io/ppm/all.hh>
-
-#include "apps/data.hh"
-
-
-// FIXME: mln::decorated_image lacks a proper definition of
-// properties! (see mln/core/image/imorph/decorated_image.hh
-namespace mln
-{
-
- namespace trait
- {
-
- template <typename I, typename D>
- struct image_< decorated_image<I,D> >
- : default_image_morpher< I,
- mln_value(I),
- decorated_image<I,D> >
- {
- typedef trait::image::category::identity_morpher category;
- };
-
- } // end of namespace mln::trait
-
-} // end of namespace mln
+#include <mln/io/ppm/load.hh>
+#include "apps/morphers/recorder.hh"
-// Recorder.
-template <typename I>
-struct recorder
-{
- void reading(const I&, const mln_psite(I)&) const
- {
- // N/A.
- }
-
- void writing(I& ima, const mln_psite(I)&, const mln_value(I)&)
- {
- sequence.push_back(mln::duplicate(ima));
- }
-
- std::vector<I> sequence;
-};
-
-template <typename I>
-mln::decorated_image< I, recorder<I> >
-record(mln::Image<I>& ima)
-{
- return mln::decorate(ima, recorder<I>());
-}
-
-
-// I/O.
-namespace ppm
-{
- template <typename I>
- void
- save(const mln::decorated_image< I, recorder<I> >& rec,
- const std::string& prefix)
- {
- for (size_t i = 0; i < rec.decoration().sequence.size(); ++i)
- {
- std::stringstream s;
- s << std::setfill ('0') << std::setw (6) << i;
- mln::io::ppm::save(rec.decoration().sequence[i],
- prefix + s.str() + ".ppm");
- }
- }
-}
+#include "apps/data.hh"
int main()
diff --git a/milena/apps/morphers/recorder.cc b/milena/apps/morphers/recorder.hh
similarity index 74%
copy from milena/apps/morphers/recorder.cc
copy to milena/apps/morphers/recorder.hh
index 195f24c..98b5f70 100644
--- a/milena/apps/morphers/recorder.cc
+++ b/milena/apps/morphers/recorder.hh
@@ -23,38 +23,33 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
+#ifndef APPS_MORPHERS_RECORDER_HH
+# define APPS_MORPHERS_RECORDER_HH
+
/// \file
/// \brief Morpher recording every change in the morphed image.
///
-/// To produce an AVI movie from the `lena-fill*.ppm' files, use:
-///
-/// for f in lena-fill*ppm; convert $f -scale 2500% $(basename $f .ppm).png
-/// mencoder "mf://lena-fill*.png" -o lena-fill.avi -ovc lavc -lavcopts
vcodec=mjpeg
-///
-/// The output `lena-fill.avi' can be embedded in a PDF file. */
+/// \todo Split and move this into the library?
#include <sstream>
#include <iomanip>
#include <string>
-#include <mln/core/image/image2d.hh>
#include <mln/core/image/imorph/decorated_image.hh>
#include <mln/value/rgb8.hh>
#include <mln/core/routine/duplicate.hh>
-#include <mln/literal/colors.hh>
-#include <mln/data/fill.hh>
-
-#include <mln/io/ppm/all.hh>
+#include <mln/io/ppm/save.hh>
#include "apps/data.hh"
// FIXME: mln::decorated_image lacks a proper definition of
-// properties! (see mln/core/image/imorph/decorated_image.hh
+// properties! (see mln/core/image/imorph/decorated_image.hh). We use
+// the following (minimal) set of properties as a workaround.
namespace mln
{
@@ -118,18 +113,4 @@ namespace ppm
}
}
-
-int main()
-{
- using namespace mln;
- using mln::value::rgb8;
-
- 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);
- ppm::save(lena_rec, "lena-fill");
-}
+#endif // ! APPS_MORPHERS_RECORDER_HH
--
1.7.2.5