Re: [Olena-patches] milena r1509: Review display directory and add tests.

Guillaume Duhamel wrote:
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog: 2007-11-21 Guillaume Duhamel <guillaume.duhamel@lrde.epita.fr>
Review.
* mln/display/color_pretty.hh, * mln/display/remove.hh, * mln/display/save.hh, * mln/display/save_and_show.hh, * mln/display/show.hh: Fix enhancement, add doc and tracing, check typo.
* tests/display/color_pretty.cc, * tests/display/save_and_show.cc, * tests/display/show.cc: Tests for display routines.
Typo * mln/level/transform.hh: Fix typo.
--- mln/display/color_pretty.hh | 56 +++++++++++++++++++++++++++++-- mln/display/remove.hh | 15 +++++++- mln/display/save.hh | 38 ++++++++++++++------- mln/display/save_and_show.hh | 44 +++++++++++++++--------- mln/display/show.hh | 62 ++++++++++++++++++++++++++++++---- tests/display/color_pretty.cc | 73 ++++++++++++++++++++++------------------- tests/display/save_and_show.cc | 13 +++---- tests/display/show.cc | 12 +++++- 8 files changed, 229 insertions(+), 84 deletions(-)
Index: trunk/milena/tests/display/show.cc =================================================================== --- trunk/milena/tests/display/show.cc (revision 1508) +++ trunk/milena/tests/display/show.cc (revision 1509) @@ -25,7 +25,7 @@ // reasons why the executable file might be covered by the GNU General // Public License.
-/*! \file tests/show.cc +/*! \file tests/display/show.cc * * \brief Tests on mln::display::show. */ @@ -69,7 +69,15 @@ { image_if_value<image2d<unsigned> > t = inplace (tmp | i); display::save (t); - display::show (t, "xv"); + display::show (t, "xv", 1); } + +// image2d<value::rgb8> color_image (16, 16); +// for (int i = 0; i < 16; ++i) +// for (int j = 0; j < 16; ++j) +// color_image(point2d(i, j)) = value::rgb8(0,0,255); +// display::save (color_image); +// display::show (color_image, "xv"); + display::remove (); } Index: trunk/milena/tests/display/save_and_show.cc =================================================================== --- trunk/milena/tests/display/save_and_show.cc (revision 1508) +++ trunk/milena/tests/display/save_and_show.cc (revision 1509) @@ -25,9 +25,9 @@ // reasons why the executable file might be covered by the GNU General // Public License.
-/*! \file tests/save_and_show.cc +/*! \file tests/display/save_and_show.cc * - * \brief Tests on mln::display::show. + * \brief Tests on mln::display::save_and_show. */
# include <mln/core/image2d.hh> @@ -42,7 +42,7 @@ # include <mln/display/show.hh> # include <mln/io/ppm/save.hh> # include <mln/display/save_and_show.hh> - +# include <mln/level/fill.hh>
int main() { @@ -50,7 +50,6 @@
unsigned max = 51;
- image2d<bool> input = io::pbm::load("../../img/toto.pbm");
// Create a weighted windows : @@ -66,9 +65,11 @@ for (unsigned i = 2; i < 6; i += 2) { image_if_value<image2d<unsigned> > t = inplace (tmp | i); - display::save_and_show (t, "xv"); + display::save_and_show (t, "xv", 1); }
+ /// FIXME: Uncomment this ASAP // image2d<value::rgb8> ima (100, 100); -// display::save_and_show (ima, "xv"); +// level::fill(ima, value::rgb8 (0, 0, 255)); +// display::save_and_show (ima, "xv", 1); } Index: trunk/milena/tests/display/color_pretty.cc =================================================================== --- trunk/milena/tests/display/color_pretty.cc (revision 1508) +++ trunk/milena/tests/display/color_pretty.cc (revision 1509) @@ -31,56 +31,63 @@ */
# include <mln/core/image2d.hh> -# include <mln/io/pbm/load.hh> -# include <mln/make/win_chamfer.hh> -# include <mln/geom/chamfer.hh> -# include <mln/value/rgb8.hh> +# include <mln/value/int_u8.hh> +# include <mln/level/fill.hh> +# include <mln/core/p_set.hh> # include <mln/core/sub_image.hh> -# include <mln/core/image_if_value.hh> # include <mln/core/inplace.hh> -# include <mln/core/w_window2d_int.hh> +# include <mln/value/rgb8.hh> # include <mln/display/color_pretty.hh> -# include <mln/io/ppm/save.hh> -# include <mln/core/p_set.hh> +# include <mln/level/compare.hh>
int main() { using namespace mln; + using value::int_u8;
- unsigned max = 51; + /// Test on color_pretty. + { + image2d<int_u8> ima (2, 2); + level::fill (ima, 51);
+ p_set<point2d > s; + s.insert(point2d(0, 0)); + s.insert(point2d(1, 1)); + + sub_image<image2d<int_u8>, p_set<point2d > > input = inplace(ima | s); + image2d<value::rgb8> out = display::color_pretty(input); + + value::rgb8 vs[2][2] = { + {value::rgb8(51, 51, 51), value::rgb8(255, 0, 0) }, + {value::rgb8(255, 0, 0), value::rgb8(51, 51, 51)} + };
- image2d<bool> input = io::pbm::load("../../img/toto.pbm"); + image2d<value::rgb8> ref (make::image2d(vs)); + mln_assertion (ref == out); + }
- // Create a weighted windows : - // 0 2 0 - // 2 p 2 - // 0 2 0 - const w_window2d_int& w_win = make::mk_chamfer_3x3_int<2, 0> ();
- // Call chamfer for a distance image. - image2d<unsigned> tmp = geom::chamfer(input, w_win, max); + /// Test on color_pretty_rgb. + { + image2d<value::rgb8> ima (2, 2);
p_set<point2d > s1; p_set<point2d > s2; p_set<point2d > s3;
- for (int i = 200; i < 300; ++i) - for (int j = 0; j < 100; ++j) - s2.insert(point2d(i, j)); + s1.insert(point2d(0, 0)); + s2.insert(point2d(0, 1)); + s3.insert(point2d(1, 0)); + + image2d<value::rgb8> out = display::color_pretty_rgb(ima, s1, s2, s3); + + value::rgb8 vs[2][2] = { + {value::rgb8(255, 0, 0), value::rgb8(0, 255, 0) }, + {value::rgb8(0, 0, 255), value::rgb8(0, 0, 0)} + };
- for (int i = 0; i < 100; ++i) - for (int j = 200; j < 300; ++j) - s3.insert(point2d(i, j)); - - - -// // Call color_pretty for sub_image. -// image2d<value::rgb8> out = display::color_pretty_rgb(tmp, s1, s2, s3); - -// // Save output image from color in out.ppm. -// io::ppm::save(out, "out.ppm"); - -// std::cout << "out.ppm generate" << std::endl; + image2d<value::rgb8> ref (make::image2d(vs)); + mln_assertion (ref == out); + } } Index: trunk/milena/mln/level/transform.hh =================================================================== Index: trunk/milena/mln/display/color_pretty.hh =================================================================== --- trunk/milena/mln/display/color_pretty.hh (revision 1508) +++ trunk/milena/mln/display/color_pretty.hh (revision 1509) @@ -41,6 +41,7 @@ # include <mln/level/fill.hh> # include <mln/level/paste.hh> # include <mln/core/p_set.hh> +# include <mln/metal/is_not.hh>
namespace mln { @@ -48,10 +49,36 @@ namespace display {
+ /*! Return new image colored from an image \p input_. with the + * color red for the pixels not in the domain of \p input_. + * + * \param[in] ima The image in gray level to color. + * + * \return colored image from \p input_ in rgb8 with red for the + * color filled when the point is in bounding box of \p input_ but + * not defined. + * + * \pre \p input_ has to be initialized. + * \pre \p input_ values isn't color. + * + */ template <typename I> typename trait::image_from_mesh < mln_mesh(I), value::rgb8 >::ret color_pretty(const Image<I>& input_);
+ + /*! Return new image colored from an image \p input_. with the + * color red for the pixels not in the domain of \p input_. + * + * \param[in] ima The image whose domain let to define the domain + * of the returned image. + * \param[in] s1_ The p_set where the points will be colored in red. + * \param[in] s2_ The p_set where the points will be colored in green. + * \param[in] s3_ The p_set where the points will be colored in blue. + * + * \return colored image from \p input_ domain which be filled in rgb8. + * + */ template <typename I> typename trait::image_from_mesh < mln_mesh(I), value::rgb8 >::ret color_pretty_rgb(const Image<I>& input_, @@ -67,7 +94,6 @@ value::rgb8 color_value(V v) { - //r = v * (mln_max(V) / mln_max(value::int_u8) ); return value::rgb8(v, v, v); }
@@ -90,6 +116,8 @@ typename trait::image_from_mesh < mln_mesh(I), value::rgb8 >::ret color_pretty(const Image<I>& input_) { + trace::entering("display::impl::color_pretty"); + const I& input = exact (input_);
image2d<value::rgb8> output(input.domain().bbox()); @@ -101,6 +129,8 @@ for_all(p) output(p) = value::rgb8(color_value(input(p))); } + + trace::exiting("display::impl::color_pretty"); return output; }
@@ -142,12 +172,25 @@
} // end of namespace mln::display::impl
+ /// Facade. + template <typename I> typename trait::image_from_mesh < mln_mesh(I), value::rgb8 >::ret color_pretty(const Image<I>& input_) { - return impl::color_pretty(input_); + trace::entering("display::color_pretty"); + + const I& input = exact(input_); + mln_precondition(input.has_data()); + + mlc_is_not(mln_trait_value_kind(mln_value(I)) (), + trait::value::kind::color)::check(); + + image2d<value::rgb8> output = impl::color_pretty(input); + + trace::exiting("display::color_pretty"); + return output; }
template <typename I> @@ -157,7 +200,14 @@ const p_set<mln_point(I) >& s2_, const p_set<mln_point(I) >& s3_) { - return impl::color_pretty_rgb(input_, s1_, s2_, s3_); + trace::entering("display::color_pretty_rgb"); + + const I& input = exact(input_); + + image2d<value::rgb8> output = impl::color_pretty_rgb(input_, s1_, s2_, s3_); + + trace::exiting("display::color_pretty_rgb"); + return output; }
# endif // !MLN_INCLUDE_ONLY Index: trunk/milena/mln/display/remove.hh =================================================================== --- trunk/milena/mln/display/remove.hh (revision 1508) +++ trunk/milena/mln/display/remove.hh (revision 1509) @@ -30,7 +30,7 @@
/*! \file mln/display/remove.hh * - * \brief Remove all temporary files creat by display::save. + * \brief Remove all temporary files create by display::save. * */
@@ -47,6 +47,10 @@ namespace display {
+ /*! Remove all temporary images which are created by the routine + * save. + * + */ void remove();
@@ -58,6 +62,7 @@ void remove() { + trace::entering("display::impl::remove");
for (std::map<void*, std::string>::const_iterator it = map_saved_image_tmp_.begin (); it != map_saved_image_tmp_.end (); @@ -66,6 +71,8 @@ std::string s = "rm -f " + (*it).second; system (s.c_str ()); } + + trace::exiting("display::impl::remove"); }
} // end of namespace mln::display::impl @@ -74,7 +81,11 @@ void remove() { - return impl::remove(); + trace::entering("display::remove"); + + impl::remove(); + + trace::exiting("display::remove"); }
# endif // !MLN_INCLUDE_ONLY Index: trunk/milena/mln/display/save.hh =================================================================== --- trunk/milena/mln/display/save.hh (revision 1508) +++ trunk/milena/mln/display/save.hh (revision 1509) @@ -49,24 +49,31 @@ namespace display {
+ /*! Map which stocks the location of the saved file by the id of + * the image. + * + */ std::map<void*, std::string> map_saved_image_tmp_;
+ /*! Save an image in a temporary file in ppm format. + * + * \param[in] input_ the image to save. + * + */ template <typename I> void save(const Image<I>& input_);
- template <typename I> - void - save_color(const Image<I>& input_); - # ifndef MLN_INCLUDE_ONLY
namespace impl { template <typename I> void - save(const Image<I>& input_) + save(trait::value::kind::any, const Image<I>& input_) { + trace::entering("display::impl::save"); + const I& input = exact (input_); image2d<value::rgb8> out = display::color_pretty(input);
@@ -80,12 +87,16 @@ io::ppm::save(out, path_tmp);
map_saved_image_tmp_[(void*)input.id_ ()] = path_tmp; + + trace::exiting("display::impl::save"); }
template <typename I> void - save_color(const Image<I>& input_) + save(trait::value::kind::color, const Image<I>& input_) { + trace::entering("display::impl::save"); + const I& input = exact (input_);
/// Use of mkstemp instead tempmap. @@ -98,6 +109,8 @@ io::ppm::save(input, path_tmp);
map_saved_image_tmp_[(void*)input.id_ ()] = path_tmp; + + trace::exiting("display::impl::save"); }
} // end of namespace mln::display::impl @@ -107,14 +120,13 @@ void save(const Image<I>& input_) { - return impl::save(input_); - } + trace::entering("display::save");
- template <typename I> - void - save_color(const Image<I>& input_) - { - return impl::save_color(input_); + const I& input = exact(input_); + mln_precondition(input.has_data()); + impl::save(mln_trait_value_kind(mln_value(I)) (), input); + + trace::exiting("display::save"); }
# endif // !MLN_INCLUDE_ONLY Index: trunk/milena/mln/display/save_and_show.hh =================================================================== --- trunk/milena/mln/display/save_and_show.hh (revision 1508) +++ trunk/milena/mln/display/save_and_show.hh (revision 1509) @@ -43,9 +43,22 @@ namespace display {
+ /*! Save and show an image \p input_, which displays whith \p cmd + * viewer in \p time seconds. + * + * \param[in] input_ the image to show. + * \param[in] cmd The string which contains the programm of the + * viewer which the user want to display with. By default its + * value is "xv". + * \param[in] time The number of second of + * display, 0 display permanently. By default the value is 0. + * + * \warning This routine doesn't erase the temporary created file. + * + */ template <typename I> void - save_and_show(const Image<I>& input_, std::string cmd); + save_and_show(const Image<I>& input_, std::string cmd = "xv", int time = 0);
# ifndef MLN_INCLUDE_ONLY
@@ -53,21 +66,15 @@ { template <typename I> void - save_and_show_(trait::value::kind::color, - const Image<I>& input, std::string cmd) + save_and_show_(const Image<I>& input, + std::string cmd, int time) { - save_color(input); - show(input, cmd); - } + trace::entering("display::impl::save_and_show_");
- template <typename I> - void - save_and_show_(trait::value::kind::any, - const Image<I>& input, - std::string cmd) - { - save(input); - show(input, cmd); + display::save(input); + show(input, cmd, time); + + trace::exiting("display::impl::save_and_show_"); }
} // end of namespace mln::display::impl @@ -75,10 +82,13 @@ /// Facade. template <typename I> void - save_and_show(const Image<I>& input_, std::string cmd) + save_and_show(const Image<I>& input_, std::string cmd = "xv", int time = 0) { - impl::save_and_show_(mln_trait_value_kind(mln_value(I)) (), - input_, cmd); + trace::entering("display::save_and_show"); + + impl::save_and_show_(input_, cmd, time); + + trace::exiting("display::save_and_show"); }
# endif // !MLN_INCLUDE_ONLY Index: trunk/milena/mln/display/show.hh =================================================================== --- trunk/milena/mln/display/show.hh (revision 1508) +++ trunk/milena/mln/display/show.hh (revision 1509) @@ -47,9 +47,22 @@ namespace display {
+ /*! Show an image \p input_ previously saved by display::save, + * which displays whith \p cmd viewer in \p time seconds. + * + * \param[in] input_ the image to show. + * \param[in] cmd The string which contains the programm of the + * viewer which the user want to display with. By default its + * value is "xv". + * \param[in] time The number of second of + * display, 0 display permanently. By default the value is 0. + * + * \pre the image \p input_ is previously saved is map_saved_image_tmp_. + * + */ template <typename I> void - show(const Image<I>& input_, std::string cmd = "xv"); + show(const Image<I>& input_, std::string cmd = "xv", int time = 0);
# ifndef MLN_INCLUDE_ONLY
@@ -57,15 +70,43 @@ {
template <typename I> + bool + check_saved(const Image<I>& input_) + { + const I& input = exact(input_); + + typename std::map<void*, std::string>::iterator it = map_saved_image_tmp_.begin(); + + for (; it != map_saved_image_tmp_.end(); ++it) + if ((*it).first == input.id_()) + return true; + return false; + } + + template <typename I> void - show(const Image<I>& input_, std::string cmd) + show(const Image<I>& input_, std::string cmd, int time) { + trace::entering("display::impl::show"); + const I& input = exact (input_);
- std::string s = cmd + " " + map_saved_image_tmp_[(void*)input.id_ ()] + " &"; - system (s.c_str ()); - s = "sleep 3 && pkill " + cmd; - system (s.c_str ()); + std::stringstream st; + if (time) + { + st << cmd << " " << map_saved_image_tmp_[(void*)input.id_()] << " &"; + system(st.str().c_str()); + st.str(""); + st << "sleep " << time << " && pkill " << cmd; + system(st.str().c_str()); + } + else + { + st << cmd << " " << map_saved_image_tmp_[(void*)input.id_()]; + system(st.str().c_str()); + } + + trace::exiting("display::impl::show"); }
} // end of namespace mln::display::impl @@ -73,9 +114,14 @@ /// Facade. template <typename I> void - show(const Image<I>& input_, std::string cmd = "xv") + show(const Image<I>& input_, std::string cmd = "xv", int time = 0) { - return impl::show(input_, cmd); + trace::entering("display::show"); + + mln_precondition(impl::check_saved(input_)); + impl::show(input_, cmd, time); + + trace::entering("display::show"); }
# endif // !MLN_INCLUDE_ONLY
fix title.
participants (1)
-
Guillaume Duhamel