LRE
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2025
January
2024
December
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008
December
November
October
September
August
July
June
May
April
March
February
January
2007
December
November
October
September
August
July
June
May
April
March
February
January
2006
December
November
October
September
August
July
June
May
April
March
February
January
2005
December
November
October
September
August
July
June
May
April
March
February
January
2004
December
November
October
September
August
July
June
May
April
March
List overview
Download
Olena-patches
----- 2025 -----
January 2025
----- 2024 -----
December 2024
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
----- 2008 -----
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
----- 2007 -----
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
----- 2006 -----
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006
----- 2005 -----
December 2005
November 2005
October 2005
September 2005
August 2005
July 2005
June 2005
May 2005
April 2005
March 2005
February 2005
January 2005
----- 2004 -----
December 2004
November 2004
October 2004
September 2004
August 2004
July 2004
June 2004
May 2004
April 2004
March 2004
olena-patches@lrde.epita.fr
9625 discussions
Start a n
N
ew thread
proto-1.0 159: Repair geodesic erosion and dilation (cont.)
by Roland Levillain
https://svn.lrde.epita.fr/svn/oln/prototypes/proto-1.0
ChangeLog | 15 +++++++++++++++ oln/morpho/geodesic_dilation.hh | 13 ++++++++----- oln/morpho/geodesic_erosion.hh | 13 ++++++++----- tests/morpho/tests/closing | 15 +++++++++------ tests/morpho/tests/erosion | 35 ++++++++++++++++++----------------- tests/morpho/tests/geodesic_dilation | 4 +--- tests/morpho/tests/geodesic_erosion | 4 +--- tests/morpho/tests/opening | 15 +++++++++------ 8 files changed, 69 insertions(+), 45 deletions(-) Index: olena/ChangeLog from Roland Levillain <roland(a)lrde.epita.fr> Repair geodesic erosion and dilation (cont.). * oln/morpho/geodesic_dilation.hh (morpho::proc::geodesic_dilation) * oln/morpho/geodesic_erosion.hh (morpho::proc::geodesic_erosion): Fix iterator definition, as well as min/max operation. * olena/tests/morpho/tests/closing * olena/tests/morpho/tests/erosion * olena/tests/morpho/tests/geodesic_dilation, * olena/tests/morpho/tests/geodesic_erosion, * olena/tests/morpho/tests/opening: Aesthetic changes. 2005-04-15 Roland Levillain <roland(a)lrde.epita.fr> Index: olena/tests/morpho/tests/opening --- olena/tests/morpho/tests/opening (revision 158) +++ olena/tests/morpho/tests/opening (working copy) @@ -8,19 +8,22 @@ #include <oln/level/compare.hh> #include <ntg/all.hh> +using namespace oln; + bool check() { - // MD5 sum of object.pbm's geodesic dilation result. - oln::utils::key::value_type data_key[16] = + // MD5 sum of object.pbm's opening result. + // FIXME: Replace this fake with the actual result. + utils::key::value_type data_key[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - oln::utils::key key(data_key); + utils::key key(data_key); - typedef oln::image2d<ntg::bin> im_type; + typedef image2d<ntg::bin> im_type; im_type ima; - ima = oln::io::read(rdata("16x16.pbm")); + ima = io::read(rdata("16x16.pbm")); - if (oln::utils::md5(oln::morpho::opening(ima, oln::win_c8p())) != key) + if (utils::md5(morpho::opening(ima, win_c8p())) != key) return true; return false; Index: olena/tests/morpho/tests/geodesic_erosion --- olena/tests/morpho/tests/geodesic_erosion (revision 158) +++ olena/tests/morpho/tests/geodesic_erosion (working copy) @@ -14,6 +14,7 @@ bool check() { // MD5 sum of object.pbm's geodesic erosion result. + // FIXME: Replace this fake with the actual result. utils::key::value_type data_key[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; @@ -30,12 +31,9 @@ marker = morpho::closing(mask, win_c4p()).exact(); // Classical procedure. - // FIXME: Re-enable when proc::geodesic_erosion is fixed. -#if 0 if (utils::md5(morpho::proc::geodesic_erosion(join(marker, nbh), mask).exact()) != key) return true; -#endif // Facade to object-algorithm. if (utils::md5(morpho::geodesic_erosion(join(marker, nbh), Index: olena/tests/morpho/tests/geodesic_dilation --- olena/tests/morpho/tests/geodesic_dilation (revision 158) +++ olena/tests/morpho/tests/geodesic_dilation (working copy) @@ -14,6 +14,7 @@ bool check() { // MD5 sum of object.pbm's geodesic dilation result. + // FIXME: Replace this fake with the actual result. utils::key::value_type data_key[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; @@ -30,12 +31,9 @@ marker = morpho::opening(mask, win_c4p()).exact(); // Classical procedure. - // FIXME: Re-enable when proc::geodesic_dilation is fixed. -#if 0 if (utils::md5(morpho::proc::geodesic_dilation(join(marker, nbh), mask).exact()) != key) return true; -#endif // Facade to object-algorithm. if (utils::md5(morpho::geodesic_dilation(join(marker, nbh), Index: olena/tests/morpho/tests/erosion --- olena/tests/morpho/tests/erosion (revision 158) +++ olena/tests/morpho/tests/erosion (working copy) @@ -8,27 +8,28 @@ #include <oln/level/compare.hh> #include <ntg/all.hh> +using namespace oln; + bool check() { - oln::utils::key::value_type data_key[16] = - {0x7c, 0x4f, 0xf, 0xc7, 0x27, 0x1, 0x98, 0x81, - 0xfd, 0xb, 0x2e, 0xf6, 0x1c, 0x84, 0xc9, 0x1e}; - - oln::utils::key key(data_key); + // MD5 sum of object.pbm's erosion result. + // FIXME: Replace this fake with the actual result. + utils::key::value_type data_key[16] = + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + utils::key key(data_key); - typedef oln::image2d<ntg::bin> im_type; + typedef image2d<ntg::bin> im_type; im_type ima; - ima = oln::io::read(rdata("16x16.pbm")); + ima = io::read(rdata("16x16.pbm")); - std::cout << oln::utils::md5(oln::morpho::erosion(ima, oln::win_c8p())) << std::endl; - if (oln::utils::md5(oln::morpho::erosion(ima, oln::win_c8p())) == key) - { - std::cout << "OK" << std::endl; - return false; - } - else - { - std::cout << "FAIL" << std::endl; + // Classical procedure. + if (utils::md5(morpho::proc::erosion(ima, win_c8p())) != key) return true; - } + + // Facade to object-algorithm. + if (utils::md5(morpho::erosion(ima, win_c8p())) != key) + return true; + + return false; } Index: olena/tests/morpho/tests/closing --- olena/tests/morpho/tests/closing (revision 158) +++ olena/tests/morpho/tests/closing (working copy) @@ -8,19 +8,22 @@ #include <oln/level/compare.hh> #include <ntg/all.hh> +using namespace oln; + bool check() { - // MD5 sum of object.pbm's geodesic dilation result. - oln::utils::key::value_type data_key[16] = + // MD5 sum of object.pbm's closing result. + // FIXME: Replace this fake with the actual result. + utils::key::value_type data_key[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - oln::utils::key key(data_key); + utils::key key(data_key); - typedef oln::image2d<ntg::bin> im_type; + typedef image2d<ntg::bin> im_type; im_type ima; - ima = oln::io::read(rdata("16x16.pbm")); + ima = io::read(rdata("16x16.pbm")); - if (oln::utils::md5(oln::morpho::closing(ima, oln::win_c8p())) != key) + if (utils::md5(morpho::closing(ima, win_c8p())) != key) return true; return false; Index: olena/oln/morpho/geodesic_dilation.hh --- olena/oln/morpho/geodesic_dilation.hh (revision 158) +++ olena/oln/morpho/geodesic_dilation.hh (working copy) @@ -33,7 +33,6 @@ # include <oln/core/abstract/image_operator.hh> # include <oln/morpho/stat.hh> # include <oln/level/compare.hh> -# include <oln/convert/nbh_to_se.hh> # include <oln/arith/min.hh> # include <oln/core/abstract/neighborhood.hh> @@ -59,11 +58,15 @@ oln_type_of(I1, concrete) output(marker.size()); // FIXME: Useless? // marker.border_adapt_copy(marker.nbh_get().delta()); - oln_type_of(I1, piter) p(marker); + oln_type_of(I1, piter) p(marker.size()); for_all_p (p) - output[p] = - arith::min(morpho::max(marker, p, marker.nbh_get().get_win()), - mask[p]); + { + oln_type_of(I1, value) a = + morpho::max(marker, p, marker.nbh_get().get_win()); + oln_type_of(I2, value) b = mask[p]; + // Min. + output[p] = a < b ? a : b; + } return output; } Index: olena/oln/morpho/geodesic_erosion.hh --- olena/oln/morpho/geodesic_erosion.hh (revision 158) +++ olena/oln/morpho/geodesic_erosion.hh (working copy) @@ -33,7 +33,6 @@ # include <oln/core/abstract/image_operator.hh> # include <oln/morpho/stat.hh> # include <oln/level/compare.hh> -# include <oln/convert/nbh_to_se.hh> # include <oln/arith/max.hh> # include <oln/core/abstract/neighborhood.hh> @@ -59,11 +58,15 @@ oln_type_of(I1, concrete) output(marker.size()); // FIXME: Useless? // marker.border_adapt_copy(marker.nbh_get().delta()); - oln_type_of(I1, piter) p(marker); + oln_type_of(I1, piter) p(marker.size()); for_all_p (p) - output[p] = - arith::max(morpho::min(marker, p, marker.nbh_get().get_win()), - mask[p]); + { + oln_type_of(I1, value) a = + morpho::min(marker, p, marker.nbh_get().get_win()); + oln_type_of(I2, value) b = mask[p]; + // Max. + output[p] = a > b ? a : b; + } return output; }
19Â years, 8Â months
1
0
0
0
proto-1.0 158: Add generic morphological opening and closing, repair geodesic erosion and dilation
by Roland Levillain
https://svn.lrde.epita.fr/svn/oln/prototypes/proto-1.0
ChangeLog | 24 ++++ oln/core/abstract/image_with_extension.hh | 2 oln/core/gen/image_with_nbh.hh | 6 - oln/makefile.src | 2 oln/morpho/closing.hh | 166 ++++++++++++++++++++++++++++++ oln/morpho/geodesic_dilation.hh | 11 + oln/morpho/geodesic_erosion.hh | 13 +- oln/morpho/opening.hh | 166 ++++++++++++++++++++++++++++++ tests/core/tests/readwrite_image | 1 tests/core/tests/setget | 11 + tests/morpho/tests/closing | 27 ++++ tests/morpho/tests/dilation | 1 tests/morpho/tests/erosion | 1 tests/morpho/tests/geodesic_dilation | 76 +++++++------ tests/morpho/tests/geodesic_erosion | 75 ++++++------- tests/morpho/tests/opening | 27 ++++ 16 files changed, 519 insertions(+), 90 deletions(-) Index: olena/ChangeLog from Roland Levillain <roland(a)lrde.epita.fr> Add generic morphological opening and closing. Repair geodesic erosion and dilation. * oln/morpho/closing.hh, oln/morpho/opening.hh: New files. * oln/makefile.src (OLN_DEP): Add morpho/closing.hh and morpho/opening.hh. * tests/morpho/tests/closing, tests/morpho/tests/opening: New tests. * tests/core/tests/readwrite_image, tests/core/tests/setget: Update tests. * oln/morpho/geodesic_dilation.hh (impl_run): Fix access to window. * oln/morpho/geodesic_erosion.hh (impl_run): Likewise. Fix precondition. * oln/core/abstract/image_with_extension.hh (image_with_extension::image_with_extension): Remove const before reference of the first argument. * oln/core/gen/image_with_nbh.hh (image_with_nbh::image_with_nbh, join): Likewise. (nbh_): Make it non const. Index: olena/tests/morpho/tests/opening --- olena/tests/morpho/tests/opening (revision 0) +++ olena/tests/morpho/tests/opening (revision 0) @@ -0,0 +1,27 @@ + // -*- C++ -*- +#include "data.hh" +#include <oln/utils/md5.hh> + +#include <oln/io/read_image.hh> +#include <oln/basics2d.hh> +#include <oln/morpho/opening.hh> +#include <oln/level/compare.hh> +#include <ntg/all.hh> + +bool check() +{ + // MD5 sum of object.pbm's geodesic dilation result. + oln::utils::key::value_type data_key[16] = + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + oln::utils::key key(data_key); + + typedef oln::image2d<ntg::bin> im_type; + im_type ima; + ima = oln::io::read(rdata("16x16.pbm")); + + if (oln::utils::md5(oln::morpho::opening(ima, oln::win_c8p())) != key) + return true; + + return false; +} Index: olena/tests/morpho/tests/geodesic_erosion --- olena/tests/morpho/tests/geodesic_erosion (revision 157) +++ olena/tests/morpho/tests/geodesic_erosion (working copy) @@ -1,45 +1,46 @@ + // -*- C++ -*- #include "data.hh" -//#include <oln/utils/md5.hh> +#include <oln/utils/md5.hh> #include <iostream> -//#include <oln/io/read_image.hh> -//#include <oln/basics2d.hh> -//#include <oln/core/abstract/image_with_nbh.hh> -//#include <oln/morpho/opening.hh> -//#include <oln/morpho/geodesic_erosion.hh> -//#include <ntg/all.hh> +#include <oln/io/read_image.hh> +#include <oln/basics2d.hh> +#include <oln/core/gen/image_with_nbh.hh> +#include <oln/morpho/closing.hh> +#include <oln/morpho/geodesic_erosion.hh> +#include <ntg/all.hh> +using namespace oln; bool check() { - // FIXME : really test this algorithm - // FAKE test below - std::cout << "FIXME : md5 does not math with olena-0.10 reference" << std::endl; - return false; - // FIXME : end fake test + // MD5 sum of object.pbm's geodesic erosion result. + utils::key::value_type data_key[16] = + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + utils::key key(data_key); + + typedef image2d<ntg::bin> im_type; + + neighborhood2d nbh(neighb_c4()); + + im_type marker; + im_type mask; + + mask = io::read(rdata("object.pbm")); + marker = morpho::closing(mask, win_c4p()).exact(); + + // Classical procedure. + // FIXME: Re-enable when proc::geodesic_erosion is fixed. +#if 0 + if (utils::md5(morpho::proc::geodesic_erosion(join(marker, nbh), + mask).exact()) != key) + return true; +#endif + + // Facade to object-algorithm. + if (utils::md5(morpho::geodesic_erosion(join(marker, nbh), + mask).exact()) != key) + return true; -// oln::utils::key::value_type data_key[16] = -// {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; // md5 of object.pbm's geodesic_erosion result -// oln::utils::key key(data_key); - -// typedef oln::image2d<ntg::bin> im_type; - -// oln::neighborhood2d nbh(oln::neighb_c4()); - -// im_type marker; -// im_type mask; - -// marker = oln::io::read(rdata("object.pbm")); -// mask = oln::morpho::opening(mask, oln::win_c4p()).exact(); - -// if (oln::utils::md5(oln::morpho::geodesic_erosion(join(marker, nbh), mask).exact()) == key) -// { -// std::cout << "OK" << std::endl; -// return false; -// } -// else -// { -// std::cout << "FAIL" << std::endl; -// return true; -// } + return false; } Index: olena/tests/morpho/tests/dilation --- olena/tests/morpho/tests/dilation (revision 157) +++ olena/tests/morpho/tests/dilation (working copy) @@ -1,3 +1,4 @@ + // -*- C++ -*- #include "data.hh" #include <oln/utils/md5.hh> Index: olena/tests/morpho/tests/geodesic_dilation --- olena/tests/morpho/tests/geodesic_dilation (revision 157) +++ olena/tests/morpho/tests/geodesic_dilation (working copy) @@ -1,44 +1,46 @@ + // -*- C++ -*- #include "data.hh" -//#include <oln/utils/md5.hh> +#include <oln/utils/md5.hh> #include <iostream> -//#include <oln/io/read_image.hh> -//#include <oln/basics2d.hh> -//#include <oln/core/abstract/image_with_nbh.hh> -//#include <oln/morpho/opening.hh> -//#include <oln/morpho/geodesic_erosion.hh> -//#include <ntg/all.hh> +#include <oln/io/read_image.hh> +#include <oln/basics2d.hh> +#include <oln/core/gen/image_with_nbh.hh> +#include <oln/morpho/opening.hh> +#include <oln/morpho/geodesic_dilation.hh> +#include <ntg/all.hh> + +using namespace oln; bool check() { - // FIXME : really test this algorithm - // FAKE test below - std::cout << "FIXME : md5 does not math with olena-0.10 reference" << std::endl; - return false; - // FIXME : end fake test + // MD5 sum of object.pbm's geodesic dilation result. + utils::key::value_type data_key[16] = + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + utils::key key(data_key); + + typedef image2d<ntg::bin> im_type; + + neighborhood2d nbh(neighb_c4()); + + im_type marker; + im_type mask; + + mask = io::read(rdata("object.pbm")); + marker = morpho::opening(mask, win_c4p()).exact(); + + // Classical procedure. + // FIXME: Re-enable when proc::geodesic_dilation is fixed. +#if 0 + if (utils::md5(morpho::proc::geodesic_dilation(join(marker, nbh), + mask).exact()) != key) + return true; +#endif + + // Facade to object-algorithm. + if (utils::md5(morpho::geodesic_dilation(join(marker, nbh), + mask).exact()) != key) + return true; -// oln::utils::key::value_type data_key[16] = -// {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; // md5 of object.pbm's geodesic_dilation result -// oln::utils::key key(data_key); - -// typedef oln::image2d<ntg::bin> im_type; - -// oln::neighborhood2d nbh(oln::neighb_c4()); - -// im_type marker; -// im_type mask; - -// mask = oln::io::read(rdata("object.pbm")); -// marker = oln::morpho::opening(mask, oln::win_c4p()).exact(); - -// if (oln::utils::md5(oln::morpho::geodesic_dilation(join(marker, nbh), mask).exact()) == key) -// { -// std::cout << "OK" << std::endl; -// return false; -// } -// else -// { -// std::cout << "FAIL" << std::endl; -// return true; -// } + return false; } Index: olena/tests/morpho/tests/erosion --- olena/tests/morpho/tests/erosion (revision 157) +++ olena/tests/morpho/tests/erosion (working copy) @@ -1,3 +1,4 @@ + // -*- C++ -*- #include "data.hh" #include <oln/utils/md5.hh> Index: olena/tests/morpho/tests/closing --- olena/tests/morpho/tests/closing (revision 0) +++ olena/tests/morpho/tests/closing (revision 0) @@ -0,0 +1,27 @@ + // -*- C++ -*- +#include "data.hh" +#include <oln/utils/md5.hh> + +#include <oln/io/read_image.hh> +#include <oln/basics2d.hh> +#include <oln/morpho/closing.hh> +#include <oln/level/compare.hh> +#include <ntg/all.hh> + +bool check() +{ + // MD5 sum of object.pbm's geodesic dilation result. + oln::utils::key::value_type data_key[16] = + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + oln::utils::key key(data_key); + + typedef oln::image2d<ntg::bin> im_type; + im_type ima; + ima = oln::io::read(rdata("16x16.pbm")); + + if (oln::utils::md5(oln::morpho::closing(ima, oln::win_c8p())) != key) + return true; + + return false; +} Index: olena/tests/core/tests/readwrite_image --- olena/tests/core/tests/readwrite_image (revision 157) +++ olena/tests/core/tests/readwrite_image (working copy) @@ -22,6 +22,7 @@ template <> struct set_props <category::image, dummy_image> { + typedef grid2d grid_type; typedef is_a<abstract::readwrite_image> image_constness; typedef is_a<abstract::image2d> image_dimension_type; Index: olena/tests/core/tests/setget --- olena/tests/core/tests/setget (revision 157) +++ olena/tests/core/tests/setget (working copy) @@ -15,17 +15,18 @@ template <> struct set_props < category::image, dummy_image > { - typedef int concrete_type; - typedef int image_dimension_type; + typedef mlc::no_type grid_type; + typedef mlc::no_type concrete_type; + typedef mlc::no_type image_dimension_type; typedef int size_type; typedef int point_type; typedef int value_type; typedef mlc::no_type delegated_type; - typedef fwd_piter2d piter_type; - typedef fwd_piter2d fwd_piter_type; - typedef bkd_piter2d bkd_piter_type; + typedef mlc::no_type piter_type; + typedef mlc::no_type fwd_piter_type; + typedef mlc::no_type bkd_piter_type; }; struct dummy_image : public abstract::readwrite_image< dummy_image > Index: olena/oln/core/abstract/image_with_extension.hh --- olena/oln/core/abstract/image_with_extension.hh (revision 157) +++ olena/oln/core/abstract/image_with_extension.hh (working copy) @@ -68,7 +68,7 @@ { } - image_with_extension(const abstract::image<I>& image) : + image_with_extension(abstract::image<I>& image) : super_type(image) { } Index: olena/oln/core/gen/image_with_nbh.hh --- olena/oln/core/gen/image_with_nbh.hh (revision 157) +++ olena/oln/core/gen/image_with_nbh.hh (working copy) @@ -58,7 +58,7 @@ public: - image_with_nbh(const abstract::image<I>& image, + image_with_nbh(abstract::image<I>& image, const abstract::neighborhood<N>& nbh) : super_type(image), nbh_(nbh.exact()) @@ -72,7 +72,7 @@ protected: - N& nbh_; + const N& nbh_; }; @@ -80,7 +80,7 @@ template <typename I, typename N> image_with_nbh<I, N> - join(const abstract::image<I>& image, + join(abstract::image<I>& image, const abstract::neighborhood<N>& nbh) { image_with_nbh<I, N> tmp(image, nbh); Index: olena/oln/makefile.src --- olena/oln/makefile.src (revision 157) +++ olena/oln/makefile.src (working copy) @@ -137,8 +137,10 @@ level/fill.hh \ \ morpho/cc_tarjan.hh \ + morpho/closing.hh \ morpho/dilation.hh \ morpho/erosion.hh \ + morpho/opening.hh \ morpho/reconstruction.hh \ morpho/splitse.hh \ morpho/stat.hh \ Index: olena/oln/morpho/geodesic_dilation.hh --- olena/oln/morpho/geodesic_dilation.hh (revision 157) +++ olena/oln/morpho/geodesic_dilation.hh (working copy) @@ -57,10 +57,12 @@ precondition(marker.size() == mask.size()); precondition(level::is_greater_or_equal(mask, marker)); oln_type_of(I1, concrete) output(marker.size()); - marker.border_adapt_copy(marker.nbh_get().delta()); + // FIXME: Useless? + // marker.border_adapt_copy(marker.nbh_get().delta()); oln_type_of(I1, piter) p(marker); for_all_p (p) - output[p] = arith::min(morpho::max(marker, p, convert::nbh_to_cse(marker.nbh_get())), + output[p] = + arith::min(morpho::max(marker, p, marker.nbh_get().get_win()), mask[p]); return output; } @@ -110,7 +112,10 @@ mlc::eq<oln_type_of(I1, size), oln_type_of(I2, size)>::ensure(); precondition((this->input1).size() == (this->input2).size()); precondition(level::is_greater_or_equal(this->input2, this->input1)); - this->output = arith::min(dilation(this->input1.unbox(), this->input1.unbox().nbh_get()).output.unbox(), this->input2.unbox()).output; + this->output = + arith::min(dilation(this->input1.unbox(), + this->input1.unbox().nbh_get().get_win()).output.unbox(), + this->input2.unbox()).output; } }; Index: olena/oln/morpho/closing.hh --- olena/oln/morpho/closing.hh (revision 0) +++ olena/oln/morpho/closing.hh (revision 0) @@ -0,0 +1,166 @@ +// Copyright (C) 2001, 2002, 2003, 2004, 2005 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 OLENA_MORPHO_CLOSING_HH +# define OLENA_MORPHO_CLOSING_HH + +# include <mlc/cmp.hh> +# include <mlc/to_string.hh> + +# include <oln/core/abstract/images.hh> +# include <oln/core/abstract/image_operator.hh> + +# include <oln/morpho/dilation.hh> +# include <oln/morpho/erosion.hh> +# include <oln/core/2d/window2d.hh> + + +namespace oln { + + + // fwd decl + + namespace morpho { + template <typename I> struct closing_ret; + } + + // super_type + + template <typename I> + struct set_super_type< morpho::closing_ret<I> > + { + typedef oln_type_of(I, concrete) output_type; + + typedef morpho::closing_ret<I> self_type; + typedef abstract::image_unary_operator<output_type, I, self_type > ret; + }; + + + + + namespace morpho { + + + + // Closing as a 'classical' procedure returning an image (do not + // use it; prefer morpho::closing). + + namespace proc { + + template<typename I, typename W> + oln_type_of(I, concrete) closing(const abstract::image<I>& input, + const abstract::window<W>& win) + { + mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure(); + oln_type_of(I, concrete) output(input.size()); + output = morpho::erosion(morpho::dilation(input, win), win); + return output; + } + + } // end of namespace oln::morpho::proc + + + + /// Closing return type. + + template <typename I> + struct closing_ret : public oln_super_of_(closing_ret<I>) + { + typedef oln_super_of(closing_ret<I>) super_type; + + closing_ret(const abstract::image<I>& input) : + super_type(input) + { + } + + }; + + + // Various implementation. + + namespace impl { + + + /// Generic implementation of closing (type). + + template <typename I, typename W> + struct generic_closing : public closing_ret<I> + { + typedef closing_ret<I> super_type; + // FIXME: typedef oln_type_of(super_type, output) output_type; + + const W& win; + + generic_closing(const abstract::image<I>& input, + const abstract::window<W>& win) : + super_type(input), + win(win.exact()) + { + } + + void impl_run() + { + oln_type_of(super_type, output) tmp(input.size()); + tmp = morpho::erosion(morpho::dilation(input, win), win); + output = tmp; + } + }; + + // Generic implementation of closing (routine). + + template<typename I, typename W> + closing_ret<I> closing(const abstract::image<I>& input, + const abstract::window<W>& win) + { + impl::generic_closing<I,W> tmp(input, win); + tmp.run(); + return tmp; + } + + // FIXME: Add specialized implementations. + + } // end of namespace oln::morpho::impl + + + /// Generic closing (facade). + + template<typename I, typename W> + closing_ret<I> closing(const abstract::image<I>& input, + const abstract::window<W>& win) + { + mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure(); + return impl::closing(input.exact(), win.exact()); + } + + + } // end of namespace oln::morpho + + +} // end of namespace oln + + +#endif // ! OLENA_MORPHO_CLOSING_HH Index: olena/oln/morpho/opening.hh --- olena/oln/morpho/opening.hh (revision 0) +++ olena/oln/morpho/opening.hh (revision 0) @@ -0,0 +1,166 @@ +// Copyright (C) 2001, 2002, 2003, 2004, 2005 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 OLENA_MORPHO_OPENING_HH +# define OLENA_MORPHO_OPENING_HH + +# include <mlc/cmp.hh> +# include <mlc/to_string.hh> + +# include <oln/core/abstract/images.hh> +# include <oln/core/abstract/image_operator.hh> + +# include <oln/morpho/dilation.hh> +# include <oln/morpho/erosion.hh> +# include <oln/core/2d/window2d.hh> + + +namespace oln { + + + // fwd decl + + namespace morpho { + template <typename I> struct opening_ret; + } + + // super_type + + template <typename I> + struct set_super_type< morpho::opening_ret<I> > + { + typedef oln_type_of(I, concrete) output_type; + + typedef morpho::opening_ret<I> self_type; + typedef abstract::image_unary_operator<output_type, I, self_type > ret; + }; + + + + + namespace morpho { + + + + // Opening as a 'classical' procedure returning an image (do not + // use it; prefer morpho::opening). + + namespace proc { + + template<typename I, typename W> + oln_type_of(I, concrete) opening(const abstract::image<I>& input, + const abstract::window<W>& win) + { + mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure(); + oln_type_of(I, concrete) output(input.size()); + output = morpho::dilation(morpho::erosion(input, win), win); + return output; + } + + } // end of namespace oln::morpho::proc + + + + /// Opening return type. + + template <typename I> + struct opening_ret : public oln_super_of_(opening_ret<I>) + { + typedef oln_super_of(opening_ret<I>) super_type; + + opening_ret(const abstract::image<I>& input) : + super_type(input) + { + } + + }; + + + // Various implementation. + + namespace impl { + + + /// Generic implementation of opening (type). + + template <typename I, typename W> + struct generic_opening : public opening_ret<I> + { + typedef opening_ret<I> super_type; + // FIXME: typedef oln_type_of(super_type, output) output_type; + + const W& win; + + generic_opening(const abstract::image<I>& input, + const abstract::window<W>& win) : + super_type(input), + win(win.exact()) + { + } + + void impl_run() + { + oln_type_of(super_type, output) tmp(input.size()); + tmp = morpho::dilation(morpho::erosion(input, win), win); + output = tmp; + } + }; + + // Generic implementation of opening (routine). + + template<typename I, typename W> + opening_ret<I> opening(const abstract::image<I>& input, + const abstract::window<W>& win) + { + impl::generic_opening<I,W> tmp(input, win); + tmp.run(); + return tmp; + } + + // FIXME: Add specialized implementations. + + } // end of namespace oln::morpho::impl + + + /// Generic opening (facade). + + template<typename I, typename W> + opening_ret<I> opening(const abstract::image<I>& input, + const abstract::window<W>& win) + { + mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure(); + return impl::opening(input.exact(), win.exact()); + } + + + } // end of namespace oln::morpho + + +} // end of namespace oln + + +#endif // ! OLENA_MORPHO_OPENING_HH Index: olena/oln/morpho/geodesic_erosion.hh --- olena/oln/morpho/geodesic_erosion.hh (revision 157) +++ olena/oln/morpho/geodesic_erosion.hh (working copy) @@ -57,10 +57,12 @@ precondition(marker.size() == mask.size()); precondition(level::is_greater_or_equal(marker, mask)); oln_type_of(I1, concrete) output(marker.size()); - marker.border_adapt_copy(marker.nbh_get().delta()); + // FIXME: Useless? + // marker.border_adapt_copy(marker.nbh_get().delta()); oln_type_of(I1, piter) p(marker); for_all_p (p) - output[p] = arith::max(morpho::min(marker, p, convert::nbh_to_cse(marker.nbh_get())), + output[p] = + arith::max(morpho::min(marker, p, marker.nbh_get().get_win()), mask[p]); return output; } @@ -108,8 +110,11 @@ { mlc::eq<oln_type_of(I1, size), oln_type_of(I2, size)>::ensure(); precondition((this->input1).size() == (this->input2).size()); - precondition(level::is_greater_or_equal(this->input2, this->input1)); - this->output = arith::max(erosion(this->input1.unbox(), this->input1.unbox().nbh_get()).output.unbox(), this->input2.unbox()).output; + precondition(level::is_greater_or_equal(this->input1, this->input2)); + this->output = + arith::max(erosion(this->input1.unbox(), + this->input1.unbox().nbh_get().get_win()).output.unbox(), + this->input2.unbox()).output; } };
19Â years, 8Â months
1
0
0
0
proto-1.0 156: Fix bugs
by Thierry GERAUD
2005-04-14 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr> * oln/core/accum.hh: Rewrite and move... * oln/funobj/accum.hh: ...here. * tests/morpho/tests/geodesic_erosion: Add include. * tests/morpho/tests/geodesic_dilation: Likewise. * tests/morpho/tests/erosion: Fix bug. * oln/core/typedefs.hh: Add decls for iterators. * oln/core/abstract/image.hh (grid_type): New property. * oln/core/1d/image1d.hh: Update. * oln/core/2d/image2d.hh: Likewise. * oln/core/3d/image3d.hh: Likewise. * oln/core/abstract/qiter.hh: Fix bug. * oln/core/abstract/image_like_.hh (real const): Remove 'const' in return since an image-like behaves as a mutable. (real): Remove. (box<I>): Add operator= for image_like_. * oln/core/2d/window2d.hh (win_hline2d, win_vline2d): New types. * oln/core/box.hh: Clean up and add new methods. * oln/core/gen/regular_fwd_qiter.hh: Fix ctor signature. * oln/core/gen/regular_bkd_qiter.hh: Likewise. * oln/core/gen/regular_qiter.hh: Likewise. * oln/core/gen/regular_window.hh: Add includes. * oln/makefile.src: Update. * oln/morpho/stat.hh: Update. * oln/morpho/erosion.hh: Index: tests/morpho/tests/geodesic_erosion =================================================================== --- tests/morpho/tests/geodesic_erosion (revision 155) +++ tests/morpho/tests/geodesic_erosion (working copy) @@ -1,6 +1,6 @@ #include "data.hh" //#include <oln/utils/md5.hh> - +#include <iostream> //#include <oln/io/read_image.hh> //#include <oln/basics2d.hh> //#include <oln/core/abstract/image_with_nbh.hh> Index: tests/morpho/tests/geodesic_dilation =================================================================== --- tests/morpho/tests/geodesic_dilation (revision 155) +++ tests/morpho/tests/geodesic_dilation (working copy) @@ -1,6 +1,6 @@ #include "data.hh" //#include <oln/utils/md5.hh> - +#include <iostream> //#include <oln/io/read_image.hh> //#include <oln/basics2d.hh> //#include <oln/core/abstract/image_with_nbh.hh> Index: tests/morpho/tests/erosion =================================================================== --- tests/morpho/tests/erosion (revision 155) +++ tests/morpho/tests/erosion (working copy) @@ -19,7 +19,7 @@ im_type ima; ima = oln::io::read(rdata("16x16.pbm")); - std::cout << oln::utils::md5(oln::morpho::dilation(ima, oln::win_c8p())) << std::endl; + std::cout << oln::utils::md5(oln::morpho::erosion(ima, oln::win_c8p())) << std::endl; if (oln::utils::md5(oln::morpho::erosion(ima, oln::win_c8p())) == key) { std::cout << "OK" << std::endl; Index: oln/funobj/accum.hh =================================================================== --- oln/funobj/accum.hh (revision 0) +++ oln/funobj/accum.hh (working copy) @@ -25,45 +25,93 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef OLENA_CORE_ACCUM_HH -# define OLENA_CORE_ACCUM_HH +#ifndef OLENA_CORE_FUNOBJ_ACCUM_HH +# define OLENA_CORE_FUNOBJ_ACCUM_HH +# include <mlc/contract.hh> -/*! \class max_accumulator -** -** This is a \a functor. It saves the maximum T value -** that has been passed as an argument of its operator() -** method. To retrieve the value saved, just use the -** max_accumulator as a T instance. -*/ +namespace oln +{ -// FIXME: no namespace !!! -// FIXME: move this file !!! + namespace funobj + { -template <class T> -struct max_accumulator -{ - - max_accumulator (T t) : acc_(t) - {} + /// Max accumulator. - void - operator()(T t) - { - if (t > acc_) - acc_ = t; - } + template <class T> + struct max_accumulator + { - operator T() const - { - return acc_; - } + max_accumulator() : + ok_(false) + {} + + void operator()(const T& t) + { + if (not ok_) + { + ok_ = true; + acc_ = t; + return; + } + if (t > acc_) + acc_ = t; + } + + operator T() const + { + precondition(ok_); + return acc_; + } + + private: + + bool ok_; + T acc_; -private: + }; + + + /// Min accumulator. + + template <class T> + struct min_accumulator + { - T acc_; - -}; + min_accumulator() : + ok_(false) + {} + + void operator()(const T& t) + { + if (not ok_) + { + ok_ = true; + acc_ = t; + return; + } + if (t < acc_) + acc_ = t; + } + + operator T() const + { + precondition(ok_); + return acc_; + } + + private: + + bool ok_; + T acc_; -#endif // OLENA_CORE_ACCUM_HH + }; + + + } // end of namespace oln::funobj + +} // end of namespace oln + + +#endif // ! OLENA_CORE_FUNOBJ_ACCUM_HH Index: oln/core/typedefs.hh =================================================================== --- oln/core/typedefs.hh (revision 155) +++ oln/core/typedefs.hh (working copy) @@ -55,10 +55,24 @@ mlc_decl_typedef(grid_type); + // iterators + mlc_decl_typedef(iter_type); mlc_decl_typedef(fwd_iter_type); mlc_decl_typedef(bkd_iter_type); + mlc_decl_typedef(piter_type); + mlc_decl_typedef(fwd_piter_type); + mlc_decl_typedef(bkd_piter_type); + + mlc_decl_typedef(qiter_type); + mlc_decl_typedef(fwd_qiter_type); + mlc_decl_typedef(bkd_qiter_type); + + mlc_decl_typedef(niter_type); + mlc_decl_typedef(fwd_niter_type); + mlc_decl_typedef(bkd_niter_type); + // category::image mlc_decl_typedef(data_type); @@ -71,11 +85,6 @@ mlc_decl_typedef(image_type); mlc_decl_typedef(concrete_type); - mlc_decl_typedef(piter_type); - mlc_decl_typedef(fwd_piter_type); - mlc_decl_typedef(bkd_piter_type); - mlc_decl_typedef(fwd_niter_type); - mlc_decl_typedef(delegated_type); mlc_decl_typedef(size_type); mlc_decl_typedef(window_type); @@ -92,10 +101,7 @@ mlc_decl_typedef(input1_type); mlc_decl_typedef(input2_type); - // category::window - mlc_decl_typedef(fwd_qiter_type); - mlc_decl_typedef(bkd_qiter_type); // category::grid Index: oln/core/abstract/image.hh =================================================================== --- oln/core/abstract/image.hh (revision 155) +++ oln/core/abstract/image.hh (working copy) @@ -62,10 +62,13 @@ template <> struct set_default_props < category::image > { + typedef mlc::undefined_type grid_type; + typedef mlc::undefined_type concrete_type; typedef mlc::undefined_type value_type; typedef mlc::undefined_type point_type; typedef mlc::undefined_type size_type; + typedef mlc::undefined_type piter_type; typedef mlc::undefined_type fwd_piter_type; typedef mlc::undefined_type bkd_piter_type; @@ -90,6 +93,8 @@ template <typename I> struct get_props < category::image, I > { + typedef oln_type_of(I, grid) grid_type; + typedef oln_type_of(I, concrete) concrete_type; typedef oln_type_of(I, value) value_type; typedef oln_type_of(I, point) point_type; @@ -116,6 +121,8 @@ ostr << "props_of( oln::category::image, " << mlc_to_string(I) << " ) =" << std::endl << "{" << std::endl + << "\t grid_type = " << mlc_to_string(grid_type) << std::endl + << "\t concrete_type = " << mlc_to_string(concrete_type) << std::endl << "\t value_type = " << mlc_to_string(value_type) << std::endl << "\t point_type = " << mlc_to_string(point_type) << std::endl @@ -139,6 +146,7 @@ static void ensure() { + mlc::is_ok< grid_type >::ensure(); mlc::is_ok< concrete_type >::ensure(); mlc::is_ok< value_type >::ensure(); mlc::is_ok< point_type >::ensure(); Index: oln/core/abstract/qiter.hh =================================================================== --- oln/core/abstract/qiter.hh (revision 155) +++ oln/core/abstract/qiter.hh (working copy) @@ -38,7 +38,7 @@ for(q.ensure_is_qiter(), q.start_at_p(p); q.is_valid(); q.next()) # define for_all_remaining_q( q ) \ - for(q.ensure_is_piter(); q.is_valid(); q.next()) + for(q.ensure_is_qiter(); q.is_valid(); q.next()) # define oln_qit_type_of(QiterType, Alias) \ Index: oln/core/abstract/image_like_.hh =================================================================== --- oln/core/abstract/image_like_.hh (revision 155) +++ oln/core/abstract/image_like_.hh (working copy) @@ -74,23 +74,37 @@ { } - const I& real() const + I& real() const { return this->image_.unbox(); } - I& real() - { - return this->image_.unbox(); - } - }; } // end of namespace oln::abstract +} // end of namespace oln + +# include <oln/core/box.hh> + + +namespace oln +{ + + + template <typename I> + template <typename E> + box<I>& box<I>::operator=(const abstract::image_like_<I, E>& rhs) + { + this->image_ = rhs.real(); + return *this; + } + + } // end of namespace oln + #endif // ! OLENA_CORE_ABSTRACT_IMAGE_LIKE__HH Index: oln/core/1d/image1d.hh =================================================================== --- oln/core/1d/image1d.hh (revision 155) +++ oln/core/1d/image1d.hh (working copy) @@ -52,6 +52,8 @@ template <typename T> struct set_props < category::image, image1d<T> > { + typedef grid1d grid_type; + // intrusive property: typedef is_a<abstract::image1d> image_dimension_type; // FIXME: should be generalized Index: oln/core/2d/image2d.hh =================================================================== --- oln/core/2d/image2d.hh (revision 155) +++ oln/core/2d/image2d.hh (working copy) @@ -62,6 +62,8 @@ template <typename T> struct set_props < category::image, image2d<T> > { + typedef grid2d grid_type; + // intrusive property: typedef is_a<abstract::image2d> image_dimension_type; // FIXME: should be generalized Index: oln/core/2d/window2d.hh =================================================================== --- oln/core/2d/window2d.hh (revision 155) +++ oln/core/2d/window2d.hh (working copy) @@ -37,6 +37,9 @@ namespace oln { + + //------------------------------------------- window2d + // fwd decl struct window2d; @@ -65,6 +68,9 @@ }; + //------------------------------------ win_rectangle2d + + // fwd decl struct win_rectangle2d; @@ -100,9 +106,78 @@ }; + //------------------------------------ win_hline2d - // classical 2d windows + // fwd decl + struct win_hline2d; + + // super type + template <> + struct set_super_type< win_hline2d > { typedef abstract::regular_window< grid2d, win_hline2d > ret; }; + + + /// Class win_hline2d. + struct win_hline2d : public oln_super_of_(win_hline2d) + { + typedef oln_super_of_(win_hline2d) super_type; + + win_hline2d(unsigned length) : + length(length) + { + int + min_dcol = (1 - int(length)) / 2, + max_dcol = int(length) / 2; + for (int dcol = min_dcol; dcol <= max_dcol; ++dcol) + { + dpoint2d dp(0, dcol); + this->add_(dp); + } + } + + const unsigned length; + }; + + + + //------------------------------------ win_vline2d + + + // fwd decl + struct win_vline2d; + + // super type + template <> + struct set_super_type< win_vline2d > { typedef abstract::regular_window< grid2d, win_vline2d > ret; }; + + + /// Class win_vline2d. + struct win_vline2d : public oln_super_of_(win_vline2d) + { + typedef oln_super_of_(win_vline2d) super_type; + + win_vline2d(unsigned length) : + length(length) + { + int + min_drow = (1 - int(length)) / 2, + max_drow = int(length) / 2; + for (int drow = min_drow; drow <= max_drow; ++drow) + { + dpoint2d dp(drow, 0); + this->add_(dp); + } + } + + const unsigned length; + }; + + + + + //------------------------------- classical 2d windows + + /*! ** \brief Create a window (2 dimensions) of 4 elements. ** \return The new window. Index: oln/core/box.hh =================================================================== --- oln/core/box.hh (revision 155) +++ oln/core/box.hh (working copy) @@ -28,13 +28,19 @@ #ifndef OLENA_CORE_BOX_HH # define OLENA_CORE_BOX_HH +# include <mlc/bool.hh> # include <oln/core/abstract/image_entry.hh> + + namespace oln { - // fwd decl + // fwd decls template <typename I> struct box; + namespace abstract { + template <typename I, typename E> struct image_like_; + } // category @@ -65,7 +71,7 @@ }; - /// Class oln::box... + /// Class oln::box<I> encapsulating a mutable image. template <typename I> struct box : public abstract::image_entry< box<I> > @@ -84,24 +90,49 @@ this->exact_ptr = this; } + box(const box<I>& rhs) : + image_(const_cast<I&>(rhs.image_)) + { + this->exact_ptr = this; + } + + // operator= that are ok + box<I>& operator=(abstract::image<I>& rhs) { this->image_ = rhs.exact(); return *this; } - box(const box<I>& rhs) : - image_(const_cast<I&>(rhs.image_)) + box<I>& operator=(const box<I>& rhs) { - this->exact_ptr = this; + this->image_ = const_cast<I&>(rhs.image_); + return *this; } - box<I> operator=(const box<I>& rhs) + template <typename E> + box<I>& operator=(const abstract::image_like_<I, E>& rhs); // impl in image_like_.hh + + // operator= that are not ok + + template <typename II> + void operator=(const box<II>& rhs) { - this->image_ = const_cast<I&>(rhs.image_); - return *this; + mlc::false_type::ensure(); } + template <typename II, typename E> + void operator=(const abstract::image_like_<II, E>& rhs) + { + mlc::false_type::ensure(); + } + + template <typename II> + void operator=(const abstract::image<II>& rhs) + { + mlc::false_type::ensure(); + } + // FIXME: add versions for I2 (neq I) to produce explicit errors I& impl_delegate() @@ -116,15 +147,15 @@ /// Hooks. - I& unbox() + I& unbox() const { - return this->image_; + return const_cast<I&>(this->image_); } - const I& unbox() const - { - return this->image_; - } +// const I& unbox() const +// { +// return this->image_; +// } private: @@ -134,6 +165,8 @@ }; + /// Class oln::box<const I> encapsulating a constant image. + template <typename I> struct box<const I> : public abstract::image_entry< box<const I> > { Index: oln/core/accum.hh =================================================================== --- oln/core/accum.hh (revision 155) +++ oln/core/accum.hh (working copy) @@ -1,69 +0,0 @@ -// Copyright (C) 2001, 2004, 2005 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 OLENA_CORE_ACCUM_HH -# define OLENA_CORE_ACCUM_HH - - -/*! \class max_accumulator -** -** This is a \a functor. It saves the maximum T value -** that has been passed as an argument of its operator() -** method. To retrieve the value saved, just use the -** max_accumulator as a T instance. -*/ - - -// FIXME: no namespace !!! -// FIXME: move this file !!! - -template <class T> -struct max_accumulator -{ - - max_accumulator (T t) : acc_(t) - {} - - void - operator()(T t) - { - if (t > acc_) - acc_ = t; - } - - operator T() const - { - return acc_; - } - -private: - - T acc_; - -}; - -#endif // OLENA_CORE_ACCUM_HH Index: oln/core/3d/image3d.hh =================================================================== --- oln/core/3d/image3d.hh (revision 155) +++ oln/core/3d/image3d.hh (working copy) @@ -55,6 +55,8 @@ template <typename T> struct set_props < category::image, image3d<T> > { + typedef grid3d grid_type; + // intrusive property: typedef is_a<abstract::image3d> image_dimension_type; // FIXME: should be generalized Index: oln/core/gen/regular_fwd_qiter.hh =================================================================== --- oln/core/gen/regular_fwd_qiter.hh (revision 155) +++ oln/core/gen/regular_fwd_qiter.hh (working copy) @@ -54,7 +54,7 @@ typedef regular_fwd_qiter<G,W> self_type; typedef abstract::regular_qiter<G, self_type> super_type; - regular_fwd_qiter(const abstract::regular_window<G,W>& win) : + regular_fwd_qiter(const abstract::window<W>& win) : super_type(win) { this->invalidate(); Index: oln/core/gen/regular_bkd_qiter.hh =================================================================== --- oln/core/gen/regular_bkd_qiter.hh (revision 155) +++ oln/core/gen/regular_bkd_qiter.hh (working copy) @@ -54,7 +54,7 @@ typedef regular_bkd_qiter<G,W> self_type; typedef abstract::regular_qiter<G, self_type> super_type; - regular_bkd_qiter(const abstract::regular_window<G,W>& win) : + regular_bkd_qiter(const abstract::window<W>& win) : super_type(win) { this->invalidate(); Index: oln/core/gen/regular_qiter.hh =================================================================== --- oln/core/gen/regular_qiter.hh (revision 155) +++ oln/core/gen/regular_qiter.hh (working copy) @@ -30,7 +30,7 @@ # include <oln/core/abstract/grid.hh> # include <oln/core/abstract/qiter.hh> -# include <oln/core/gen/regular_window.hh> +# include <oln/core/abstract/window.hh> namespace oln { @@ -67,7 +67,7 @@ typedef oln_grd_type_of(G, dimvalue) dimvalue_type; static const unsigned dim = dimvalue_type::val; - regular_qiter(const regular_window<G, oln_qit_type_of(E, window)>& win) : + regular_qiter(const abstract::window<oln_qit_type_of(E, window)>& win) : super_type(win.exact()) { } Index: oln/core/gen/regular_window.hh =================================================================== --- oln/core/gen/regular_window.hh (revision 155) +++ oln/core/gen/regular_window.hh (working copy) @@ -178,5 +178,8 @@ return ostr; } +# include <oln/core/gen/regular_fwd_qiter.hh> +# include <oln/core/gen/regular_bkd_qiter.hh> + #endif // ! OLENA_CORE_GEN_REGULAR_WINDOW_HH Index: oln/makefile.src =================================================================== --- oln/makefile.src (revision 155) +++ oln/makefile.src (working copy) @@ -81,8 +81,6 @@ core/abstract/size.hh \ core/abstract/window.hh \ \ - core/accum.hh \ - \ core/any/all.hh \ core/any/dpoint.hh \ core/any/grid.hh \ @@ -126,6 +124,8 @@ fancy/iota.hh \ fancy/print.hh \ \ + funobj/accum.hh \ + \ io/gz_stream.hh \ io/read_image.hh \ io/read_image_2d_pnm.hh \ Index: oln/morpho/stat.hh =================================================================== --- oln/morpho/stat.hh (revision 155) +++ oln/morpho/stat.hh (working copy) @@ -32,6 +32,7 @@ # include <ntg/bin.hh> # include <oln/core/abstract/images.hh> # include <oln/core/abstract/window.hh> +# include <oln/funobj/accum.hh> namespace oln { @@ -49,16 +50,13 @@ mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure(); oln_wn_type_of(W, fwd_iter) q(win); - oln_type_of(I, value) val; - - q.start_at_p(p); - val = input[q]; + funobj::min_accumulator<oln_type_of(I, value)> minval; - for_all_remaining_q (q) - if (input.hold(q) and input[q].value() < val) - val = input[q].value(); + for_all_q_of_p (q, p) + if (input.hold(q)) + minval(input[q]); - return val; + return minval; } @@ -89,16 +87,13 @@ mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure(); oln_wn_type_of(W, fwd_iter) q(win); - oln_type_of(I, value) val; + funobj::max_accumulator<oln_type_of(I, value)> maxval; + + for_all_q_of_p (q, p) + if (input.hold(q)) + maxval(input[q]); - q.start_at_p(p); - val = input[q]; - - for_all_remaining_q (q) - if (input.hold(q) and input[q].value() > val) - val = input[q].value(); - - return val; + return maxval; } Index: oln/morpho/erosion.hh =================================================================== --- oln/morpho/erosion.hh (revision 155) +++ oln/morpho/erosion.hh (working copy) @@ -29,6 +29,7 @@ # define OLENA_MORPHO_EROSION_HH # include <mlc/cmp.hh> +# include <mlc/to_string.hh> # include <oln/core/abstract/images.hh> # include <oln/core/abstract/image_operator.hh> @@ -164,13 +165,13 @@ void impl_run() { - oln_type_of(super_type, output) temp(input.size()); // FIXME: trick + oln_type_of(super_type, output) temp; - win_rectangle2d hline(1, win.width); - win_rectangle2d vline(win.height, 1); + win_hline2d hline(win.width); + win_vline2d vline(win.height); temp = morpho::erosion(input, hline); - output = morpho::erosion(temp, vline); + output = morpho::erosion(temp, vline); } };
19Â years, 8Â months
1
0
0
0
proto-1.0 155: Add unary point-wise function (PWF) and use it to simplify unary apply on PWF.
by Roland Levillain
https://svn.lrde.epita.fr/svn/oln/prototypes/proto-1.0
ChangeLog | 18 +++++ oln/core/pw/abstract/unary_function.hh | 108 +++++++++++++++++++++++++++++++++ oln/core/pw/apply.hh | 45 ++++--------- oln/makefile.src | 1 4 files changed, 141 insertions(+), 31 deletions(-) Index: olena/ChangeLog from Roland Levillain <roland(a)lrde.epita.fr> Add unary point-wise function (PWF). Use it to simplify unary apply on PWF. * oln/core/pw/abstract/unary_function.hh: New file. * oln/core/pw/apply.hh: Use it to rewrite pw::apply. (apply): Inherit from pw::abstract::unary_function. Rename as ... (apply1): ...this. (apply1::input_): Remove attribute. (apply1::apply1): Adjust ctor. (apply1::impl_get): Adjust method. (apply1::impl_size, apply1::impl_hold, apply1::impl_hold_large): Remove methods. * oln/makefile.src (OLN_DEP): Add core/pw/abstract/unary_function.hh. Index: olena/oln/core/pw/abstract/unary_function.hh --- olena/oln/core/pw/abstract/unary_function.hh (revision 0) +++ olena/oln/core/pw/abstract/unary_function.hh (revision 0) @@ -0,0 +1,108 @@ +// Copyright (C) 2005 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 OLENA_CORE_PW_ABSTRACT_UNARY_FUNCTION_HH +# define OLENA_CORE_PW_ABSTRACT_UNARY_FUNCTION_HH + +# include <oln/core/pw/abstract/function.hh> +# include <oln/core/abstract/point.hh> +# include <oln/core/abstract/size.hh> + + + +namespace oln { + + + // fwd decl + namespace pw { + namespace abstract { + template <typename T, typename E> struct unary_function; + } + } + + // super type + template <typename T, typename E> + struct set_super_type < pw::abstract::unary_function<T, E> > { typedef pw::abstract::function<E> ret; }; + + // props + template <typename T, typename E> + struct set_props < category::pw, pw::abstract::unary_function<T, E> > + { + typedef oln_pw_type_of(T, point) point_type; + typedef oln_pw_type_of(T, size) size_type; + }; + + + namespace pw { + + namespace abstract { + + template <typename T, typename E> + struct unary_function : public function<E> + { + typedef T input_type; + + T input; + + unary_function(const abstract::function<T>& input) : + input(input.exact()) + { + } + + typedef oln_pw_type_of(E, point) point_type; + typedef oln_pw_type_of(E, size) size_type; + + const size_type& impl_size() const + { + return input.size(); + } + + bool impl_hold(const point_type& p) const + { + return input.hold(p); + } + + bool impl_hold_large(const point_type& p) const + { + return input.hold_large(p); + } + + protected: + unary_function() {} + + }; + + + } // end of namespace oln::pw::abstract + + } // end of namespace oln::pw + +} // end of namespace oln + + + +#endif // ! OLENA_CORE_PW_ABSTRACT_UNARY_FUNCTION_HH Index: olena/oln/core/pw/apply.hh --- olena/oln/core/pw/apply.hh (revision 154) +++ olena/oln/core/pw/apply.hh (working copy) @@ -29,7 +29,7 @@ # define OLENA_CORE_PW_APPLY_HH # include <mlc/fun.hh> -# include <oln/core/pw/abstract/function.hh> +# include <oln/core/pw/abstract/unary_function.hh> # include <oln/core/pw/abstract/binary_function.hh> # include <oln/core/pw/macros.hh> @@ -42,19 +42,19 @@ // fwd decl namespace pw { - template <typename F, typename T> struct apply; + template <typename F, typename T> struct apply1; } // super type template <typename F, typename T> - struct set_super_type < pw::apply<F, T> > + struct set_super_type < pw::apply1<F, T> > { - typedef pw::abstract::function< pw::apply<F, T> > ret; + typedef pw::abstract::unary_function< T, pw::apply1<F, T> > ret; }; // props template <typename F, typename T> - struct set_props < category::pw, pw::apply<F, T> > + struct set_props < category::pw, pw::apply1<F, T> > { typedef oln_pw_type_of(T, point) point_type; typedef typename F::result_type value_type; @@ -65,45 +65,28 @@ namespace pw { template <typename F, typename T> - struct apply : public abstract::function < apply<F, T> > + struct apply1 : public abstract::unary_function < T, apply1<F, T> > { - typedef apply<F, T> self_type; + typedef apply1<F, T> self_type; typedef oln_pw_type_of(self_type, point) point_type; typedef oln_pw_type_of(self_type, value) value_type; typedef oln_pw_type_of(self_type, size) size_type; - typedef abstract::function<self_type> super_type; + typedef abstract::unary_function<T, self_type> super_type; F f_; - T input_; - apply(const mlc::abstract::unary_function<F>& f, + apply1(const mlc::abstract::unary_function<F>& f, const abstract::function<T>& input) : - super_type(), - f_(f.exact()), - input_(input.exact()) - { - } - - const size_type& impl_size() const + super_type(input), + f_(f.exact()) { - return input_.size(); } const value_type impl_get(const point_type& p) const { - return f_(input_(p)); - } - - bool impl_hold(const point_type& p) const - { - return input_.hold(p); - } - - bool impl_hold_large(const point_type& p) const - { - return input_.hold_large(p); + return f_(this->input(p)); } }; @@ -173,11 +156,11 @@ /// apply function on pwf template <typename F, typename T> -oln::pw::apply<F, T> +oln::pw::apply1<F, T> p_apply (const mlc::abstract::unary_function<F>& f, const oln::pw::abstract::function<T>& x) { - oln::pw::apply<F, T> tmp(f, x); + oln::pw::apply1<F, T> tmp(f, x); return tmp; } Index: olena/oln/makefile.src --- olena/oln/makefile.src (revision 154) +++ olena/oln/makefile.src (working copy) @@ -109,6 +109,7 @@ \ core/pw/abstract/binary_function.hh \ core/pw/abstract/function.hh \ + core/pw/abstract/unary_function.hh \ core/pw/apply.hh \ core/pw/all.hh \ core/pw/cmp.hh \
19Â years, 8Â months
1
0
0
0
proto-1.0 154: Change in windows.
by Thierry GERAUD
2005-04-14 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr> * oln/core/typedefs.hh (oln_super_of): New macro. * oln/core/abstract/image_operator.hh (set_props): Declare output_type. * oln/core/1d/qiter1d.hh: Remove typedefs. * oln/core/2d/qiter2d.hh: Likewise. * oln/core/3d/qiter3d.hh: Likewise. * oln/core/1d/window1d.hh: Use inheritance. * oln/core/2d/window2d.hh: Likewise. (win_rectangle2d): New class. * oln/core/3d/window3d.hh: Likewise. * oln/core/any/dpoint.hh (operator+): Move to... * oln/core/any/point.hh: ...here. * oln/core/gen/regular_fwd_qiter.hh: Add parameter W. * oln/core/gen/regular_bkd_qiter.hh: Likewise. * oln/core/gen/regular_qiter.hh: Update. * oln/core/gen/regular_window.hh: Update. * oln/core/gen/regular_neighborhood.hh: Update. * oln/morpho/stat.hh (stat_): Remove. * oln/morpho/erosion.hh: Rewrite. Index: oln/core/typedefs.hh =================================================================== --- oln/core/typedefs.hh (revision 153) +++ oln/core/typedefs.hh (working copy) @@ -38,8 +38,14 @@ # include <mlc/to_string.hh> +# define oln_super_of_(Type) \ +oln::internal::get_super_type<Type>::ret +# define oln_super_of(Type) \ +typename oln_super_of_(Type) + + namespace oln { Index: oln/core/abstract/image.hh =================================================================== --- oln/core/abstract/image.hh (revision 153) +++ oln/core/abstract/image.hh (working copy) @@ -39,6 +39,7 @@ + namespace oln { Index: oln/core/abstract/image_operator.hh =================================================================== --- oln/core/abstract/image_operator.hh (revision 153) +++ oln/core/abstract/image_operator.hh (working copy) @@ -48,8 +48,18 @@ template <typename O, typename I1, typename I2, typename E> struct set_super_type< abstract::image_binary_operator<O, I1, I2, E> > { typedef abstract::image_operator<O, E> ret; }; + // props + template <typename O, typename E> + struct set_props < category::image, abstract::image_operator<O, E> > + { + typedef O output_type; + }; + + + + namespace abstract { Index: oln/core/1d/qiter1d.hh =================================================================== --- oln/core/1d/qiter1d.hh (revision 153) +++ oln/core/1d/qiter1d.hh (working copy) @@ -31,18 +31,11 @@ # include <oln/core/1d/grid1d.hh> # include <oln/core/1d/point1d.hh> # include <oln/core/1d/dpoint1d.hh> + # include <oln/core/1d/window1d.hh> # include <oln/core/gen/regular_fwd_qiter.hh> # include <oln/core/gen/regular_bkd_qiter.hh> -namespace oln { - - typedef regular_fwd_qiter<grid1d> fwd_qiter1d; - typedef regular_bkd_qiter<grid1d> bkd_qiter1d; - -} - - #endif // ! OLENA_CORE_1D_QITER1D_HH Index: oln/core/1d/window1d.hh =================================================================== --- oln/core/1d/window1d.hh (revision 153) +++ oln/core/1d/window1d.hh (working copy) @@ -36,8 +36,37 @@ namespace oln { - typedef regular_window< grid1d > window1d; + // fwd decl + struct window1d; + + // super type + template <> + struct set_super_type< window1d > { typedef abstract::regular_window< grid1d, window1d > ret; }; + + + struct window1d : public abstract::regular_window< grid1d, window1d > + { + typedef abstract::regular_window< grid1d, window1d > super_type; + + window1d() + {} + + window1d(unsigned n, const coord_t crd[]) : + super_type(n, crd) + {} + + window1d& add(const dpoint1d& dp) + { + this->add_(dp); + return *this; + } + + }; + + + + // classical 1d windows /*! Index: oln/core/2d/qiter2d.hh =================================================================== --- oln/core/2d/qiter2d.hh (revision 153) +++ oln/core/2d/qiter2d.hh (working copy) @@ -31,18 +31,11 @@ # include <oln/core/2d/grid2d.hh> # include <oln/core/2d/point2d.hh> # include <oln/core/2d/dpoint2d.hh> + # include <oln/core/2d/window2d.hh> # include <oln/core/gen/regular_fwd_qiter.hh> # include <oln/core/gen/regular_bkd_qiter.hh> -namespace oln { - - typedef regular_fwd_qiter<grid2d> fwd_qiter2d; - typedef regular_bkd_qiter<grid2d> bkd_qiter2d; - -} - - #endif // ! OLENA_CORE_2D_QITER2D_HH Index: oln/core/2d/window2d.hh =================================================================== --- oln/core/2d/window2d.hh (revision 153) +++ oln/core/2d/window2d.hh (working copy) @@ -37,8 +37,70 @@ namespace oln { - typedef regular_window< grid2d > window2d; + // fwd decl + struct window2d; + // super type + template <> + struct set_super_type< window2d > { typedef abstract::regular_window< grid2d, window2d > ret; }; + + + struct window2d : public oln_super_of_(window2d) + { + typedef oln_super_of_(window2d) super_type; + + window2d() + {} + + window2d(unsigned n, const coord_t crd[]) : + super_type(n, crd) + {} + + window2d& add(const dpoint2d& dp) + { + this->add_(dp); + return *this; + } + + }; + + + // fwd decl + struct win_rectangle2d; + + // super type + template <> + struct set_super_type< win_rectangle2d > { typedef abstract::regular_window< grid2d, win_rectangle2d > ret; }; + + + /// Class win_rectangle2d. + struct win_rectangle2d : public oln_super_of_(win_rectangle2d) + { + typedef oln_super_of_(win_rectangle2d) super_type; + + win_rectangle2d(unsigned height, unsigned width) : + height(height), + width(width) + { + int + min_drow = (1 - int(height)) / 2, + max_drow = int(height) / 2, + min_dcol = (1 - int(width)) / 2, + max_dcol = int(width) / 2; + for (int drow = min_drow; drow <= max_drow; ++drow) + for (int dcol = min_dcol; dcol <= max_dcol; ++dcol) + { + dpoint2d dp(drow, dcol); + this->add_(dp); + } + } + + const unsigned height; + const unsigned width; + }; + + + // classical 2d windows /*! Index: oln/core/3d/qiter3d.hh =================================================================== --- oln/core/3d/qiter3d.hh (revision 153) +++ oln/core/3d/qiter3d.hh (working copy) @@ -31,18 +31,11 @@ # include <oln/core/3d/grid3d.hh> # include <oln/core/3d/point3d.hh> # include <oln/core/3d/dpoint3d.hh> + # include <oln/core/3d/window3d.hh> # include <oln/core/gen/regular_fwd_qiter.hh> # include <oln/core/gen/regular_bkd_qiter.hh> -namespace oln { - - typedef regular_fwd_qiter<grid3d> fwd_qiter3d; - typedef regular_bkd_qiter<grid3d> bkd_qiter3d; - -} - - #endif // ! OLENA_CORE_3D_QITER3D_HH Index: oln/core/3d/window3d.hh =================================================================== --- oln/core/3d/window3d.hh (revision 153) +++ oln/core/3d/window3d.hh (working copy) @@ -36,8 +36,37 @@ namespace oln { - typedef regular_window< grid3d > window3d; + // fwd decl + struct window3d; + + // super type + template <> + struct set_super_type< window3d > { typedef abstract::regular_window< grid3d, window3d > ret; }; + + + struct window3d : public abstract::regular_window< grid3d, window3d > + { + typedef abstract::regular_window< grid3d, window3d > super_type; + + window3d() + {} + + window3d(unsigned n, const coord_t crd[]) : + super_type(n, crd) + {} + + window3d& add(const dpoint3d& dp) + { + this->add_(dp); + return *this; + } + + }; + + + + // classical 3d windows /*! Index: oln/core/any/point.hh =================================================================== --- oln/core/any/point.hh (revision 153) +++ oln/core/any/point.hh (working copy) @@ -127,8 +127,15 @@ # include <oln/core/any/dpoint.hh> + namespace oln { + template <typename P> + const any_point any_dpoint::operator+(const abstract::point<P>& rhs) const + { + return any_point(); + } + const any_dpoint any_point::impl_minus(const any_point& rhs) const { precondition(false); Index: oln/core/any/dpoint.hh =================================================================== --- oln/core/any/dpoint.hh (revision 153) +++ oln/core/any/dpoint.hh (working copy) @@ -31,7 +31,6 @@ # include <iostream> # include <mlc/contract.hh> # include <oln/core/abstract/dpoint.hh> -# include <oln/core/any/point.hh> namespace oln { @@ -124,14 +123,5 @@ # include <oln/core/any/point.hh> -namespace oln { - template <typename P> - const any_point any_dpoint::operator+(const abstract::point<P>& rhs) const - { - return any_point(); - } - -} - #endif // ! OLENA_CORE_ANY_DPOINT_HH Index: oln/core/gen/regular_fwd_qiter.hh =================================================================== --- oln/core/gen/regular_fwd_qiter.hh (revision 153) +++ oln/core/gen/regular_fwd_qiter.hh (working copy) @@ -34,20 +34,27 @@ namespace oln { // fwd decl - template <typename G> struct regular_fwd_qiter; + template <typename G, typename W> struct regular_fwd_qiter; // category - template <typename G> - struct set_super_type< regular_fwd_qiter<G> > { typedef abstract::regular_qiter< G, regular_fwd_qiter<G> > ret; }; + template <typename G, typename W> + struct set_super_type< regular_fwd_qiter<G,W> > { typedef abstract::regular_qiter< G, regular_fwd_qiter<G,W> > ret; }; + // props + template <typename G, typename W> + struct set_props < category::qiter, regular_fwd_qiter<G,W> > + { + typedef W window_type; + }; - template <typename G> - struct regular_fwd_qiter : public abstract::regular_qiter< G, regular_fwd_qiter<G> > + + template <typename G, typename W> + struct regular_fwd_qiter : public abstract::regular_qiter< G, regular_fwd_qiter<G,W> > { - typedef regular_fwd_qiter<G> self_type; + typedef regular_fwd_qiter<G,W> self_type; typedef abstract::regular_qiter<G, self_type> super_type; - regular_fwd_qiter(const regular_window<G>& win) : + regular_fwd_qiter(const abstract::regular_window<G,W>& win) : super_type(win) { this->invalidate(); Index: oln/core/gen/regular_bkd_qiter.hh =================================================================== --- oln/core/gen/regular_bkd_qiter.hh (revision 153) +++ oln/core/gen/regular_bkd_qiter.hh (working copy) @@ -34,21 +34,27 @@ namespace oln { // bkd decl - template <typename G> - struct regular_bkd_qiter; + template <typename G, typename W> struct regular_bkd_qiter; // category - template <typename G> - struct set_super_type< regular_bkd_qiter<G> > { typedef abstract::regular_qiter< G, regular_bkd_qiter<G> > ret; }; + template <typename G, typename W> + struct set_super_type< regular_bkd_qiter<G,W> > { typedef abstract::regular_qiter< G, regular_bkd_qiter<G,W> > ret; }; + // props + template <typename G, typename W> + struct set_props < category::qiter, regular_bkd_qiter<G,W> > + { + typedef W window_type; + }; - template <typename G> - struct regular_bkd_qiter : public abstract::regular_qiter< G, regular_bkd_qiter<G> > + + template <typename G, typename W> + struct regular_bkd_qiter : public abstract::regular_qiter< G, regular_bkd_qiter<G,W> > { - typedef regular_bkd_qiter<G> self_type; + typedef regular_bkd_qiter<G,W> self_type; typedef abstract::regular_qiter<G, self_type> super_type; - regular_bkd_qiter(const regular_window<G>& win) : + regular_bkd_qiter(const abstract::regular_window<G,W>& win) : super_type(win) { this->invalidate(); Index: oln/core/gen/regular_qiter.hh =================================================================== --- oln/core/gen/regular_qiter.hh (revision 153) +++ oln/core/gen/regular_qiter.hh (working copy) @@ -48,8 +48,7 @@ template <typename G, typename E> struct set_props < category::qiter, abstract::regular_qiter<G,E> > { - typedef G grid_type; - typedef regular_window<G> window_type; + typedef G grid_type; }; @@ -68,8 +67,8 @@ typedef oln_grd_type_of(G, dimvalue) dimvalue_type; static const unsigned dim = dimvalue_type::val; - regular_qiter(const regular_window<G>& win) : - super_type(win) + regular_qiter(const regular_window<G, oln_qit_type_of(E, window)>& win) : + super_type(win.exact()) { } Index: oln/core/gen/regular_window.hh =================================================================== --- oln/core/gen/regular_window.hh (revision 153) +++ oln/core/gen/regular_window.hh (working copy) @@ -43,124 +43,133 @@ namespace oln { // fwd decls - template <typename G> class regular_window; - template <typename G> class regular_fwd_qiter; + template <typename G, typename W> class regular_fwd_qiter; + namespace abstract { + template <typename G, typename E> class regular_window; + } // super_type - template <typename G> struct set_super_type< regular_window<G> > { typedef abstract::window< regular_window<G> > ret; }; + template <typename G, typename E> struct set_super_type< abstract::regular_window<G, E> > { typedef abstract::window<E> ret; }; // props - template <typename G> - struct set_props< category::window, regular_window<G> > + template <typename G, typename E> + struct set_props< category::window, abstract::regular_window<G, E> > { typedef G grid_type; typedef oln_grd_type_of(G, dpoint) dpoint_type; typedef oln_grd_type_of(G, size) size_type; - typedef regular_fwd_qiter<G> fwd_iter_type; -// typedef regular_fwd_dpiter<G> fwd_dpiter_type; // FIXME: later... + typedef regular_fwd_qiter<G,E> fwd_iter_type; + // typedef regular_fwd_dpiter<G> fwd_dpiter_type; // FIXME: later... }; - template <typename G> - class regular_window : public abstract::window< regular_window<G> > + + + namespace abstract { - public: + template <typename G, typename E> + class regular_window : public window<E> + { + + public: - typedef regular_window<G> self_type; + typedef regular_window<G, E> self_type; - typedef oln_grd_type_of(G, coord) coord_type; - typedef oln_grd_type_of(G, dpoint) dpoint_type; - typedef oln_grd_type_of(G, dimvalue) dimvalue_type; + typedef oln_grd_type_of(G, coord) coord_type; + typedef oln_grd_type_of(G, dpoint) dpoint_type; + typedef oln_grd_type_of(G, dimvalue) dimvalue_type; - static const unsigned dim = dimvalue_type::val; + static const unsigned dim = dimvalue_type::val; - regular_window() : - dp_(), - delta_(0) - { - } + coord_type delta() const + { + return this->delta_; + } - regular_window(unsigned n, const coord_type crd[]) : - dp_(), - delta_(0) - { - precondition(n != 0); - // FIXME: size of crd wrt n - for (unsigned i = 0; i < n; ++i) - { - dpoint_type dp; - for (unsigned c = 0; c < dim; ++c) - dp.nth(c) = crd[i * dim + c]; - this->add(dp); - } - } + unsigned card() const + { + return this->dp_.size(); + } - self_type& add(const dpoint_type& dp) - { - this->dpset_.insert(dp); - this->dp_.clear(); - std::copy(this->dpset_.begin(), this->dpset_.end(), - std::back_inserter(this->dp_)); - this->delta_update_(dp); - return *this; - } + const dpoint_type dp(unsigned i) const + { + precondition(i < this->card()); + return this->dp_[i]; + } - coord_type delta() const - { - return this->delta_; - } + const self_type operator-() const + { + self_type tmp; + for (unsigned i = 0; i < this->card(); ++i) + tmp.add_(- this->dp_[i]); + return tmp; + } - unsigned card() const - { - return this->dp_.size(); - } + void sym() + { + *this = - *this; + } - const dpoint_type dp(unsigned i) const - { - precondition(i < this->card()); - return this->dp_[i]; - } + const std::vector<dpoint_type>& get_dp() const + { + return this->dp_; + } - const self_type operator-() const - { - self_type tmp; - for (unsigned i = 0; i < this->card(); ++i) - tmp.add(- this->dp_[i]); - return tmp; - } + protected: - void sym() - { - *this = - *this; - } + regular_window() : + dp_(), + delta_(0) + { + } - const std::vector<dpoint_type>& get_dp() const - { - return this->dp_; - } + regular_window(unsigned n, const coord_type crd[]) : + dp_(), + delta_(0) + { + precondition(n != 0); + // FIXME: size of crd wrt n + for (unsigned i = 0; i < n; ++i) + { + dpoint_type dp; + for (unsigned c = 0; c < dim; ++c) + dp.nth(c) = crd[i * dim + c]; + this->add_(dp); + } + } - private: + void add_(const dpoint_type& dp) + { + this->dpset_.insert(dp); + this->dp_.clear(); + std::copy(this->dpset_.begin(), this->dpset_.end(), + std::back_inserter(this->dp_)); + this->delta_update_(dp); + } + + private: - std::set<dpoint_type, fwd_less_dpoint> dpset_; - std::vector<dpoint_type> dp_; - coord_type delta_; + std::set<dpoint_type, fwd_less_dpoint> dpset_; + std::vector<dpoint_type> dp_; + coord_type delta_; - void delta_update_(const dpoint_type& dp) - { - for (unsigned c = 0; c < dim; ++c) - if (abs(dp.nth(c)) > this->delta_) - this->delta_ = abs(dp.nth(c)); - } + void delta_update_(const dpoint_type& dp) + { + for (unsigned c = 0; c < dim; ++c) + if (abs(dp.nth(c)) > this->delta_) + this->delta_ = abs(dp.nth(c)); + } - }; + }; + } // end of namespace oln::abstract } // end of namespace oln -template<class G> -std::ostream& operator<<(std::ostream& ostr, const oln::regular_window<G>& win) +template<typename G, typename E> +std::ostream& operator<<(std::ostream& ostr, const oln::abstract::regular_window<G, E>& win) { ostr << "["; for (unsigned i = 0; i < win.card(); ++i) Index: oln/core/gen/regular_neighborhood.hh =================================================================== --- oln/core/gen/regular_neighborhood.hh (revision 153) +++ oln/core/gen/regular_neighborhood.hh (working copy) @@ -40,13 +40,27 @@ // super_type template <typename G> struct set_super_type< regular_neighborhood<G> > { typedef abstract::neighborhood< regular_neighborhood<G> > ret; }; + + // FIXME: temporary code to get a window type from a grid type + struct grid1d; struct window1d; + struct grid2d; struct window2d; + struct grid3d; struct window3d; + namespace internal { + template <typename grid_type> struct to_window; + template <> struct to_window <grid1d> { typedef window1d ret; }; + template <> struct to_window <grid2d> { typedef window2d ret; }; + template <> struct to_window <grid3d> { typedef window3d ret; }; + } + // FIXME: end of temporary code + + // props template <typename G> struct set_props< category::neighborhood, regular_neighborhood<G> > { typedef oln_grd_type_of(G, dpoint) dpoint_type; typedef oln_grd_type_of(G, size) size_type; - typedef regular_window<G> window_type; + typedef typename internal::to_window<G>::ret window_type; }; @@ -58,6 +72,7 @@ public: typedef regular_neighborhood<G> self_type; + typedef oln_nbh_type_of(self_type, window) window_type; typedef oln_grd_type_of(G, coord) coord_type; typedef oln_grd_type_of(G, dpoint) dpoint_type; @@ -69,7 +84,7 @@ { } - regular_neighborhood(const regular_window<G>& win) + regular_neighborhood(const window_type& win) { for (unsigned i = 0; i < win.card(); ++i) this->add(win.dp(i)); @@ -117,7 +132,7 @@ return this->win_.get_dp(); } - const regular_neighborhood<G>& get_win() const + const window_type& get_win() const { return this->win_; } @@ -125,7 +140,7 @@ private: /// Only attribute (to delegate to). - regular_window<G> win_; + window_type win_; }; Index: oln/morpho/stat.hh =================================================================== --- oln/morpho/stat.hh (revision 153) +++ oln/morpho/stat.hh (working copy) @@ -30,7 +30,7 @@ # include <mlc/cmp.hh> # include <ntg/bin.hh> -# include <oln/core/abstract/image.hh> +# include <oln/core/abstract/images.hh> # include <oln/core/abstract/window.hh> @@ -38,160 +38,87 @@ namespace morpho { - namespace internal { - /*! - ** \brief Min and Max on a window. - ** - ** We need to use this inner definition in order to specialize - ** max and min on binary images. - ** - ** \param I Image exact type. - ** \param W Window type. - ** \param V Associated value type. - */ - template <class I, class W, class V = oln_type_of(I, value)> - struct stat_ - { - /*! - ** \brief Maximum of a window. - ** - ** Look for the maximum in the window win disposed - ** on the image input, at the point p. - ** - ** \arg input Input image. - ** \arg p Point of the image to move the window on. - ** \arg win The window to use. - */ - static V - max(const abstract::image<I>& input, - const oln_type_of(I, point)& p, - const abstract::window<W>& win) - { - mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure(); + /// Local min on a function. - oln_wn_type_of(W, fwd_iter) q(win); - q.start_at_p(p); - V val = input[q]; - for_all_remaining_q (q) - if (input.hold(q)) - if (val < input[q].value()) - val = input[q].value(); - return val; - } + template <typename I, typename W> + oln_type_of(I, value) min(const abstract::image<I>& input, + const oln_type_of(I, point)& p, + const abstract::window<W>& win) + { + mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure(); - /*! - ** \brief Minimum of a window. - ** - ** Look for the minimum in the window win disposed - ** on the image input, at the point p. - ** - ** \arg input Input image. - ** \arg p Point of the image to move the window on. - ** \arg win The window to use. - */ - static V - min(const abstract::image<I>& input, - const oln_type_of(I, point)& p, - const abstract::window<W>& win) - { - mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure(); + oln_wn_type_of(W, fwd_iter) q(win); + oln_type_of(I, value) val; - oln_wn_type_of(W, fwd_iter) q(win); - q.start_at(p); - V val = input[q]; - for_all_remaining_q (q) - if (input.hold(q)) - if (val > input[q].value()) - val = input[q].value(); - return val; - } + q.start_at_p(p); + val = input[q]; + + for_all_remaining_q (q) + if (input.hold(q) and input[q].value() < val) + val = input[q].value(); - }; + return val; + } - /* Binary specialization. */ - template <class I, class W> - struct stat_<I, W, ntg::bin> - { - static ntg::bin - max(const abstract::image<I>& input, - const oln_type_of(I, point)& p, - const abstract::window<W>& win) - { - mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure(); - oln_wn_type_of(W, fwd_iter) q(win); - for_all_q_of_p (q, p) - if (input.hold(q)) - if (input[q] == true) - return true; - return false; - } + /// Local min on a set. - static ntg::bin - min(const abstract::image<I>& input, - const oln_type_of(I, point)& p, - const abstract::window<W>& win) - { - mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure(); - oln_wn_type_of(W, fwd_iter) q(win); - for_all_q_of_p (q, p) - if (input.hold(q)) - if (input[q] == false) - return false; - return true; - } + template <typename I, typename W> + bool min(const abstract::binary_image<I>& input, + const oln_type_of(I, point)& p, + const abstract::window<W>& win) + { + mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure(); - }; + oln_wn_type_of(W, fwd_iter) q(win); + for_all_q_of_p (q, p) + if (input.hold(q) and not input[q]) + return false; + return true; + } - } // internal - /*! - ** \brief Maximum of a window. - ** - ** Look for the maximum in the window win disposed - ** on the image input, at the point p. - ** - ** \param I Image exact type. - ** \param W Window type. - ** - ** \arg input Input image. - ** \arg p Point of the image to move the window on. - ** \arg win The window to use. - */ - template<class I, class W> - oln_type_of(I, value) - max(const abstract::image<I>& input, - const oln_type_of(I, point)& p, - const abstract::window<W>& win) + /// Local max on a function. + + template <typename I, typename W> + oln_type_of(I, value) max(const abstract::image<I>& input, + const oln_type_of(I, point)& p, + const abstract::window<W>& win) { - // FIXME: test dim I == dim W - return internal::stat_<I, W>::max(input.exact(), p, win.exact()); + mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure(); + + oln_wn_type_of(W, fwd_iter) q(win); + oln_type_of(I, value) val; + + q.start_at_p(p); + val = input[q]; + + for_all_remaining_q (q) + if (input.hold(q) and input[q].value() > val) + val = input[q].value(); + + return val; } - /*! ** \brief Minimum of a window. - ** - ** Look for the minimum in the window win disposed - ** on the image input, at the point p. - ** - ** \param I Image exact type. - ** \param W Window type. - ** - ** \arg input Input image. - ** \arg p Point of the image to move the window on. - ** \arg win The window to use. - */ - template<class I, class W> - oln_type_of(I, value) - min(const abstract::image<I>& input, - const oln_type_of(I, point)& p, - // const mlc_exact_type(I)::iter_type& p, - const abstract::window<W>& win) + + /// Local max on a set. + + template <typename I, typename W> + bool max(const abstract::binary_image<I>& input, + const oln_type_of(I, point)& p, + const abstract::window<W>& win) { - // FIXME: test dim I == dim W - return internal::stat_<I, W>::min(input.exact(), p, win.exact()); + mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure(); + + oln_wn_type_of(W, fwd_iter) q(win); + for_all_q_of_p (q, p) + if (input.hold(q) and input[q]) + return true; + return false; } + } // end of namespace morpho } // end of namespace oln Index: oln/morpho/erosion.hh =================================================================== --- oln/morpho/erosion.hh (revision 153) +++ oln/morpho/erosion.hh (working copy) @@ -30,23 +30,50 @@ # include <mlc/cmp.hh> +# include <oln/core/abstract/images.hh> # include <oln/core/abstract/image_operator.hh> # include <oln/morpho/stat.hh> +# include <oln/core/2d/window2d.hh> + namespace oln { + + // fwd decl + namespace morpho { + template <typename I> struct erosion_ret; + } + // super_type + template <typename I> + struct set_super_type< morpho::erosion_ret<I> > + { + typedef oln_type_of(I, concrete) output_type; + + typedef morpho::erosion_ret<I> self_type; + typedef abstract::image_unary_operator<output_type, I, self_type > ret; + }; + + + + + namespace morpho { + + + + // Erosion as a 'classical' procedure returning an image (do not + // use it; prefer morpho::erosion). + namespace proc { - /// Erosion as a procedure (do not use it; prefer morpho::erosion). - template<typename I, typename W> oln_type_of(I, concrete) erosion(const abstract::image<I>& input, const abstract::window<W>& win) { + mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure(); oln_type_of(I, concrete) output(input.size()); oln_type_of(I, fwd_piter) p(input.size()); for_all_p (p) @@ -58,136 +85,127 @@ - /*! - ** \brief Perform a morphological erosion. - ** - ** Compute the morphological erosion of input using win - ** as structuring element. - ** - ** On grey-scale images, each point is replaced by the minimum - ** value of its neighbors, as indicated by win. On binary - ** images, a logical and is performed between neighbors. The - ** morpho::fast version of this function use a different - ** algorithm: an histogram of the value of the neighborhood - ** indicated by win is updated while iterating over all point of - ** the image. Doing so is more efficient when the structuring - ** element is large. - ** - ** \param I Exact type of the input image. - ** \param W Exact type of the structuring element. - ** - ** - ** \arg input Input image. - ** \arg win Structuring element to use. - ** - ** \code - ** #include <oln/basics2d.hh> - ** #include <oln/morpho/erosion.hh> - ** #include <oln/level/compare.hh> - ** #include <ntg/all.hh> - ** int main() - ** { - ** typedef oln::image2d<ntg::bin> im_type; - ** - ** im_type im1(oln::load(IMG_IN "object.pbm")); - ** save(oln::morpho::erosion(im1, oln::win_c8p()), - ** IMG_OUT "oln_morpho_erosion.pbm"); - ** } - ** \endcode - ** - ** \image html object_pbm.png - ** \image latex object_pbm.png - ** => - ** \image html oln_morpho_erosion.png - ** \image latex oln_morpho_erosion.png - ** - ** \see oln::morpho::fast::erosion() - */ + /// Erosion return type. - // fwd decl - template <typename I, typename W> struct erosion_ret; - - } - - // super_type - template <typename I, typename W> - struct set_super_type< morpho::erosion_ret<I,W> > - { - typedef abstract::image_unary_operator<oln_type_of(I, concrete), I, morpho::erosion_ret<I,W> > ret; - }; - - - - - namespace morpho { - - /// Erosion return. - - template <typename I, typename W> - struct erosion_ret : public abstract::image_unary_operator<oln_type_of(I, concrete), I, erosion_ret<I,W> > + template <typename I> + struct erosion_ret : public oln_super_of_(erosion_ret<I>) { - typedef abstract::image_unary_operator<oln_type_of(I, concrete), I, erosion_ret<I,W> > super_type; - typedef typename super_type::output_type output_type; + typedef oln_super_of(erosion_ret<I>) super_type; - const W win; - - erosion_ret(const abstract::image<I>& input, - const abstract::window<W>& win) : - super_type(input), - win(win.exact()) + erosion_ret(const abstract::image<I>& input) : + super_type(input) { } }; + // Various implementation. + namespace impl { - /// Erosion generic implementation. + /// Generic implementation of erosion (type). + template <typename I, typename W> - struct generic_erosion : public erosion_ret<I,W> + struct generic_erosion : public erosion_ret<I> { - typedef erosion_ret<I,W> super_type; - typedef typename super_type::output_type output_type; + typedef erosion_ret<I> super_type; + const W& win; + generic_erosion(const abstract::image<I>& input, const abstract::window<W>& win) : - super_type(input, win) + super_type(input), + win(win.exact()) { } void impl_run() { - mlc::eq<oln_type_of(I, size), oln_wn_type_of(W, size)>::ensure(); + oln_type_of(super_type, output) tmp(input.size()); // FIXME: trick + output = tmp; - output_type tmp(this->input.size()); // FIXME: trick - this->output = tmp; - - oln_type_of(I, fwd_piter) p(this->input.size()); + oln_type_of(I, fwd_piter) p(input.size()); for_all_p (p) - this->output[p] = morpho::min(this->input, p, this->win); + output[p] = morpho::min(input, p, win); } }; + // Generic implementation of erosion (routine). + + template<typename I, typename W> + erosion_ret<I> erosion(const abstract::image<I>& input, + const abstract::window<W>& win) + { + impl::generic_erosion<I,W> tmp(input, win); + tmp.run(); + return tmp; + } + + + + + /// Rectangle2d implementation of erosion (type). + + template <typename I> + struct rectangle2d_erosion : public erosion_ret<I> + { + typedef erosion_ret<I> super_type; + + const win_rectangle2d& win; + + rectangle2d_erosion(const abstract::image<I>& input, + const win_rectangle2d& win) : + super_type(input), + win(win) + {} + + void impl_run() + { + oln_type_of(super_type, output) temp(input.size()); // FIXME: trick + + win_rectangle2d hline(1, win.width); + win_rectangle2d vline(win.height, 1); + + temp = morpho::erosion(input, hline); + output = morpho::erosion(temp, vline); + } + }; + + // Rectangle2d implementation of erosion (routine). + + template<typename I> + erosion_ret<I> erosion(const abstract::image<I>& input, + const win_rectangle2d& win) + { + impl::rectangle2d_erosion<I> tmp(input, win); + tmp.run(); + return tmp; + } + + + + } // end of namespace oln::morpho::impl - /// Erosion generic routine. + /// Generic erosion (facade). + template<typename I, typename W> - erosion_ret<I,W> erosion(const abstract::image<I>& input, - const abstract::window<W>& win) + erosion_ret<I> erosion(const abstract::image<I>& input, + const abstract::window<W>& win) { - impl::generic_erosion<I,W> tmp(input, win); - tmp.run(); - return tmp; + mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure(); + return impl::erosion(input.exact(), win.exact()); } } // end of namespace oln::morpho + } // end of namespace oln
19Â years, 8Â months
1
0
0
0
proto-1.0 153: Add binary apply on point-wise functions
by Roland Levillain
https://svn.lrde.epita.fr/svn/oln/prototypes/proto-1.0
ChangeLog | 22 +++++++++ oln/core/abstract/size.hh | 3 - oln/core/any/dpoint.hh | 6 +- oln/core/any/grid.hh | 3 - oln/core/any/point.hh | 28 ++++++++++-- oln/core/pw/abstract/binary_function.hh | 8 +++ oln/core/pw/apply.hh | 74 ++++++++++++++++++++++++++++++-- oln/makefile.src | 3 - tests/pw/tests/apply-binary | 20 ++++++++ 9 files changed, 152 insertions(+), 15 deletions(-) Index: olena/ChangeLog from Roland Levillain <roland(a)lrde.epita.fr> Add binary apply on point-wise functions. * oln/core/pw/apply.hh (apply2): New class. (p_apply): New helper for binary point-wise apply. * tests/pw/tests/apply-binary: New test. * oln/core/abstract/size.hh (oln_size_type_from_2): Adjust macro to new Metalic logic system. * oln/core/pw/abstract/binary_function.hh (binary_function_helper < any_size, any_size >): New specialization. * oln/core/any/point.hh (impl_plus, impl_minus, impl_nth): Implement (as dummies). * oln/core/any/grid.hh (any_coord): Define this type. * oln/core/any/dpoint.hh: Aesthetic changes. * oln/makefile.src (OLN_DEP): Remove core/abstract/regular_niter.hh, core/3d/fwd_niter3d.hh and core/3d/fwd_qiter3d.hh. 2005-04-14 Roland Levillain <roland(a)lrde.epita.fr> Index: olena/tests/pw/tests/apply-binary --- olena/tests/pw/tests/apply-binary (revision 0) +++ olena/tests/pw/tests/apply-binary (revision 0) @@ -0,0 +1,20 @@ + // -*- C++ -*- +#include <iostream> + +#include <cmath> +#include <oln/core/pw/apply.hh> +#include <oln/core/pw/literal.hh> +#include <oln/core/any/point.hh> + +using namespace oln; + +bool check() +{ + any_point p; + + pw::literal<int> pv1 (p_lit(1)); + pw::literal<int> pv2 (p_lit(2)); + + int res = p_apply(mlc::make_binary_fun(std::plus<int>()), pv1, pv2)(p); + return not (res == 3); +} Index: olena/oln/core/abstract/size.hh --- olena/oln/core/abstract/size.hh (revision 151) +++ olena/oln/core/abstract/size.hh (working copy) @@ -41,7 +41,8 @@ -# define oln_size_type_from_2(S1, S2) typename mlc::if_< typename mlc::eq< S2, oln::any_size >::ret, S1, S2 >::ret +# define oln_size_type_from_2(S1, S2) \ +typename mlc::if_< mlc::eq< S2, oln::any_size >, S1, S2 >::ret Index: olena/oln/core/pw/abstract/binary_function.hh --- olena/oln/core/pw/abstract/binary_function.hh (revision 151) +++ olena/oln/core/pw/abstract/binary_function.hh (working copy) @@ -100,6 +100,14 @@ } }; + template <> + struct binary_function_helper < any_size, any_size > { + template <typename L, typename R> + static const L& select(const L& l, R) { + return l; + } + }; + } // end of namespace oln::pw::abstract::internal Index: olena/oln/core/pw/apply.hh --- olena/oln/core/pw/apply.hh (revision 151) +++ olena/oln/core/pw/apply.hh (working copy) @@ -30,6 +30,7 @@ # include <mlc/fun.hh> # include <oln/core/pw/abstract/function.hh> +# include <oln/core/pw/abstract/binary_function.hh> # include <oln/core/pw/macros.hh> @@ -41,8 +42,7 @@ // fwd decl namespace pw { - template <typename F, typename T> - struct apply; + template <typename F, typename T> struct apply; } // super type @@ -110,18 +110,86 @@ } // end of namespace oln::pw + + /*---------. + | Binary. | + `---------*/ + + // fwd decl + namespace pw { + template <typename F, typename T1, typename T2> struct apply2; + } + + // super type + template <typename F, typename T1, typename T2> + struct set_super_type < pw::apply2<F, T1, T2> > + { + typedef pw::abstract::binary_function<T1, T2, pw::apply2<F, T1, T2> > ret; + }; + + // props + template <typename F, typename T1, typename T2> + struct set_props < category::pw, pw::apply2<F, T1, T2> > + { + typedef typename F::result_type value_type; + }; + + namespace pw { + + template <typename F, typename T1, typename T2> + struct apply2 : + public abstract::binary_function <T1, T2, apply2<F, T1, T2> > + { + typedef apply2<F, T1, T2> self_type; + + typedef oln_pw_type_of(self_type, point) point_type; + typedef oln_pw_type_of(self_type, value) value_type; + typedef oln_pw_type_of(self_type, size) size_type; + + typedef + abstract::binary_function <T1, T2, apply2<F, T1, T2> > super_type; + + F f_; + + apply2(const mlc::abstract::binary_function<F>& f, + const abstract::function<T1>& left, + const abstract::function<T2>& right) : + super_type(left, right), + f_(f.exact()) + { + } + + const value_type impl_get(const point_type& p) const + { + return f_(this->left(p), this->right(p)); + } + }; + + } // end of namespace oln::pw + } // end of namespace oln /// apply function on pwf template <typename F, typename T> -oln::pw::apply<F, T> p_apply (const mlc::abstract::unary_function<F>& f, +oln::pw::apply<F, T> +p_apply (const mlc::abstract::unary_function<F>& f, const oln::pw::abstract::function<T>& x) { oln::pw::apply<F, T> tmp(f, x); return tmp; } +template <typename F, typename T1, typename T2> +oln::pw::apply2<F, T1, T2> +p_apply (const mlc::abstract::binary_function<F>& f, + const oln::pw::abstract::function<T1>& x, + const oln::pw::abstract::function<T2>& y) +{ + oln::pw::apply2<F, T1, T2> tmp(f, x, y); + return tmp; +} + #endif // ! OLENA_CORE_PW_APPLY_HH Index: olena/oln/core/any/grid.hh --- olena/oln/core/any/grid.hh (revision 151) +++ olena/oln/core/any/grid.hh (working copy) @@ -39,7 +39,8 @@ struct any_point; struct any_dpoint; struct any_size; - struct any_coord; + // Dummy coord type. + struct any_coord {}; // super type template <> Index: olena/oln/core/any/point.hh --- olena/oln/core/any/point.hh (revision 151) +++ olena/oln/core/any/point.hh (working copy) @@ -63,7 +63,7 @@ bool impl_fwd_less(const any_point& rhs) const { - precondition(0); + precondition(false); return false; } @@ -72,7 +72,11 @@ return this->exact().impl_eq(rhs.exact()); } - const any_point impl_plus(const any_dpoint& rhs) const; + const any_point impl_plus(const any_dpoint& rhs) const + { + precondition(false); + return any_point(); + } template <typename D> const any_point impl_plus(const abstract::dpoint<D>& rhs) const @@ -85,9 +89,18 @@ template <typename P> const any_dpoint impl_minus(const abstract::point<P>& rhs) const; - const any_coord impl_nth(unsigned i) const; + const any_coord impl_nth(unsigned i) const + { + precondition(false); + return any_coord(); + } - any_coord& impl_nth(unsigned i); + any_coord& impl_nth(unsigned i) + { + static any_coord dummy = any_coord(); + precondition(false); + return dummy; + } }; @@ -116,9 +129,16 @@ namespace oln { + const any_dpoint any_point::impl_minus(const any_point& rhs) const + { + precondition(false); + return any_dpoint(); + } + template <typename P> const any_dpoint any_point::impl_minus(const abstract::point<P>& rhs) const { + precondition(false); return any_dpoint(); } Index: olena/oln/core/any/dpoint.hh --- olena/oln/core/any/dpoint.hh (revision 151) +++ olena/oln/core/any/dpoint.hh (working copy) @@ -69,7 +69,7 @@ bool impl_fwd_less(const any_dpoint& rhs) const { - precondition(0); + precondition(false); return false; } @@ -80,14 +80,14 @@ const coord_t impl_nth(unsigned i) const { - precondition(0); + precondition(false); return 0; } coord_t& impl_nth(unsigned i) { static coord_t dummy = coord_t(); - precondition(0); + precondition(false); return dummy; } Index: olena/oln/makefile.src --- olena/oln/makefile.src (revision 151) +++ olena/oln/makefile.src (working copy) @@ -47,9 +47,7 @@ core/3d/array3d.hh \ core/3d/bkd_piter3d.hh \ core/3d/dpoint3d.hh \ - core/3d/fwd_niter3d.hh \ core/3d/fwd_piter3d.hh \ - core/3d/fwd_qiter3d.hh \ core/3d/image3d.hh \ core/3d/neighborhood3d.hh \ core/3d/niter3d.hh \ @@ -80,7 +78,6 @@ core/abstract/piter.hh \ core/abstract/point.hh \ core/abstract/qiter.hh \ - core/abstract/regular_niter.hh \ core/abstract/size.hh \ core/abstract/window.hh \ \
19Â years, 8Â months
1
0
0
0
proto-1.0 152: Fix remaining tests in tests/core
by Roland Levillain
https://svn.lrde.epita.fr/svn/oln/prototypes/proto-1.0
ChangeLog | 8 ++++++++ tests/core/tests/readwrite_image | 4 ++++ tests/core/tests/setget | 11 +++++++++-- 3 files changed, 21 insertions(+), 2 deletions(-) Index: olena/ChangeLog from Roland Levillain <roland(a)lrde.epita.fr> Fix remaining tests in tests/core. * tests/core/tests/readwrite_image, tests/core/tests/setget (set_props <category::image, dummy_image>): Add missing properties. 2005-04-14 Roland Levillain <roland(a)lrde.epita.fr> Index: olena/tests/core/tests/readwrite_image --- olena/tests/core/tests/readwrite_image (revision 151) +++ olena/tests/core/tests/readwrite_image (working copy) @@ -29,6 +29,10 @@ typedef point2d point_type; typedef ntg::int_u8 value_type; + typedef fwd_piter2d piter_type; + typedef fwd_piter2d fwd_piter_type; + typedef bkd_piter2d bkd_piter_type; + typedef value_type value_storage_type; typedef array2d<value_storage_type> storage_type; }; Index: olena/tests/core/tests/setget --- olena/tests/core/tests/setget (revision 151) +++ olena/tests/core/tests/setget (working copy) @@ -1,4 +1,4 @@ - + // -*- C++ -*- #include <oln/basics.hh> @@ -13,12 +13,19 @@ }; template <> - struct set_props < category::image, dummy_image > : public props_of <category::image> + struct set_props < category::image, dummy_image > { + typedef int concrete_type; + typedef int image_dimension_type; + typedef int size_type; typedef int point_type; typedef int value_type; typedef mlc::no_type delegated_type; + + typedef fwd_piter2d piter_type; + typedef fwd_piter2d fwd_piter_type; + typedef bkd_piter2d bkd_piter_type; }; struct dummy_image : public abstract::readwrite_image< dummy_image >
19Â years, 8Â months
1
0
0
0
proto-1.0 151: Fix core/image_valuedness test
by Roland Levillain
https://svn.lrde.epita.fr/svn/oln/prototypes/proto-1.0
ChangeLog | 9 +++++++ tests/core/tests/image_valuedness | 41 +++++++++++++++++++++++++++-------- tests/core/tests/image_vectorialness | 26 ---------------------- 3 files changed, 41 insertions(+), 35 deletions(-) Index: olena/ChangeLog from Roland Levillain <roland(a)lrde.epita.fr> Fix core/image_valuedness test. * tests/core/tests/image_vectorialness: Rename file as... * tests/core/tests/image_valuedness: ...this. Catch up with the new oln/abstract/image_valuedness.hh, and augment the test case. 2005-04-14 Roland Levillain <roland(a)lrde.epita.fr> Index: olena/tests/core/tests/image_vectorialness --- olena/tests/core/tests/image_vectorialness (revision 150) +++ olena/tests/core/tests/image_vectorialness (working copy) @@ -1,26 +0,0 @@ - -#include <iostream> - -#include <ntg/all.hh> -#include <oln/basics2d.hh> - -#include <oln/fancy/iota.hh> -#include <oln/fancy/print.hh> - -#include "check.hh" -#include "data.hh" - - - -template <typename I> -void foo_i(const oln::abstract::integer_image<I>& input) -{} - - -bool check() -{ - // it lacks test for decimal, vectorial, ... images. - oln::image2d<ntg::int_u8> ima_i; - foo_i(ima_i); - return false; -} Index: olena/tests/core/tests/image_valuedness --- olena/tests/core/tests/image_valuedness (revision 149) +++ olena/tests/core/tests/image_valuedness (working copy) @@ -1,26 +1,49 @@ + // -*- C++ -*- +#include <string> -#include <iostream> - -#include <ntg/all.hh> +#include <ntg/bin.hh> +#include <ntg/int.hh> +#include <ntg/cplx.hh> #include <oln/basics2d.hh> -#include <oln/fancy/iota.hh> -#include <oln/fancy/print.hh> - #include "check.hh" #include "data.hh" +template <typename I> +void foo_scalar(const oln::abstract::scalar_valued_image<I>& input) +{} + +template <typename I> +void foo_vector(const oln::abstract::vector_valued_image<I>& input) +{} + +template <typename I> +void foo_label(const oln::abstract::label_valued_image<I>& input) +{} template <typename I> -void foo_i(const oln::abstract::integer_image<I>& input) +void foo_data(const oln::abstract::data_valued_image<I>& input) {} bool check() { - // it lacks test for decimal, vectorial, ... images. + // Scalar. oln::image2d<ntg::int_u8> ima_i; - foo_i(ima_i); + foo_scalar(ima_i); + + // Vector. + oln::image2d<ntg::cplx<ntg::rect, float> > ima_v; + foo_vector(ima_v); + + // Label. + oln::image2d<ntg::bin> ima_l; + foo_label(ima_l); + + // Other data. + oln::image2d<std::string> ima_d; + foo_data(ima_d); + return false; }
19Â years, 8Â months
1
0
0
0
proto-1.0 150: Fix core/fwd_qiter2d test
by Roland Levillain
https://svn.lrde.epita.fr/svn/oln/prototypes/proto-1.0
ChangeLog | 14 ++++++++++++++ oln/core/abstract/qiter.hh | 2 +- oln/core/gen/regular_fwd_qiter.hh | 5 +++-- oln/core/gen/regular_qiter.hh | 2 ++ tests/core/tests/fwd_qiter2d | 11 ++++------- tests/core/tests/fwd_witer2d | 26 -------------------------- 6 files changed, 24 insertions(+), 36 deletions(-) Index: olena/ChangeLog from Roland Levillain <roland(a)lrde.epita.fr> Fix core/fwd_qiter2d test. * tests/core/tests/fwd_witer2d: Rename file as... * tests/core/tests/fwd_qiter2d: ...this. Adjust to the new interface of q-iterators. * oln/core/gen/regular_fwd_qiter.hh (abstract::qiter<self_type>): Make it a friend. (impl_invalidate): Explicitely cast to avoid comparisons between signed and unsigned values. * oln/core/gen/regular_qiter.hh (abstract::qiter<E>): Make it a friend. 2005-04-14 Roland Levillain <roland(a)lrde.epita.fr> Index: olena/tests/core/tests/fwd_witer2d --- olena/tests/core/tests/fwd_witer2d (revision 149) +++ olena/tests/core/tests/fwd_witer2d (working copy) @@ -1,26 +0,0 @@ - // -*- C++ -*- -#include <oln/core/2d/fwd_witer2d.hh> -#include <oln/core/abstract/piter.hh> - -#include <ntg/all.hh> - -#include <cassert> - -using namespace oln; -using namespace ntg; - -template <typename E> -bool foo(const E& w) -{ - oln_type_of(E, fwd_witer) i(w); - unsigned cpt = 0; - for_all(i) - ++cpt; - return not (cpt == w.card()); -} - -int main() -{ - window2d w = win_c8p(); - return foo(w); -} Index: olena/tests/core/tests/fwd_qiter2d --- olena/tests/core/tests/fwd_qiter2d (revision 147) +++ olena/tests/core/tests/fwd_qiter2d (working copy) @@ -1,20 +1,17 @@ // -*- C++ -*- -#include <oln/core/2d/fwd_witer2d.hh> -#include <oln/core/abstract/piter.hh> - -#include <ntg/all.hh> +#include <oln/core/2d/window2d.hh> #include <cassert> using namespace oln; -using namespace ntg; template <typename E> bool foo(const E& w) { - oln_type_of(E, fwd_witer) i(w); + oln_wn_type_of(E, fwd_iter) q(w); unsigned cpt = 0; - for_all(i) + point2d p; + for_all_q_of_p(q, p) ++cpt; return not (cpt == w.card()); } Index: olena/oln/core/abstract/qiter.hh --- olena/oln/core/abstract/qiter.hh (revision 149) +++ olena/oln/core/abstract/qiter.hh (working copy) @@ -35,7 +35,7 @@ # define for_all_q_of_p(q, p) \ - for(q.ensure_is_qiter(), q.center_at(p), q.start(); q.is_valid(); q.next()) + for(q.ensure_is_qiter(), q.start_at_p(p); q.is_valid(); q.next()) # define for_all_remaining_q( q ) \ for(q.ensure_is_piter(); q.is_valid(); q.next()) Index: olena/oln/core/gen/regular_fwd_qiter.hh --- olena/oln/core/gen/regular_fwd_qiter.hh (revision 149) +++ olena/oln/core/gen/regular_fwd_qiter.hh (working copy) @@ -54,6 +54,7 @@ } friend class abstract::iter<self_type>; + friend class abstract::qiter<self_type>; protected: @@ -69,12 +70,12 @@ bool impl_is_valid() const { - return this->pos_ != this->win_.card(); + return this->pos_ != int(this->win_.card()); } void impl_invalidate() { - this->pos_ = this->win_.card(); + this->pos_ = int(this->win_.card()); } }; Index: olena/oln/core/gen/regular_qiter.hh --- olena/oln/core/gen/regular_qiter.hh (revision 149) +++ olena/oln/core/gen/regular_qiter.hh (working copy) @@ -80,6 +80,8 @@ return point_type(*this).nth(i); } + friend class abstract::qiter<E>; + protected: int pos_;
19Â years, 8Â months
1
0
0
0
proto-1.0 148: Fix some 1D and 3D classes and have more tests pass
by Roland Levillain
https://svn.lrde.epita.fr/svn/oln/prototypes/proto-1.0
ChangeLog | 37 +++++++++++++++ oln/core/1d/array1d.hh | 52 +++++++++++++++++++--- oln/core/1d/image1d.hh | 2 oln/core/2d/array2d.hh | 3 - oln/core/3d/array3d.hh | 91 ++++++++++++++++++++++++++++++--------- oln/core/3d/image3d.hh | 2 tests/core/tests/fwd_witer2d | 1 tests/core/tests/piter1d | 21 +++++++-- tests/core/tests/piter2d | 6 +- tests/core/tests/piter3d | 21 +++++++-- tests/core/tests/readwrite_image | 5 -- 11 files changed, 198 insertions(+), 43 deletions(-) Index: olena/ChangeLog from Roland Levillain <roland(a)lrde.epita.fr> Fix some 1D and 3D classes and have more tests pass. * oln/basics1d.hh (oln/core/1d/fwd_piter1d.hh) (oln/core/1d/bkd_piter1d.hh): Include them. * oln/core/1d/image1d.hh (bkd_piter_type) New typedef. * oln/core/1d/array1d.hh: Do not set exact_ptr, since this class not longer inherits from mlc::any__best_speed, but from mlc::any. * oln/core/1d/array1d.hh (alloc_and_init): New function. (resize, impl_clear_data): Handle the border. (size): Rename method as... (impl_size): ...this. (~array1d): Call clear_data() instead of impl_clear_data(). (impl_resize_border): New method. * oln/core/2d/array2d.hh (alloc_and_init): Remove useless assignment. (~array2d): Call clear_data() instead of impl_clear_data(). * oln/basics3d.hh (oln/core/3d/fwd_piter3d.hh) * oln/core/3d/image3d.hh (bkd_piter_type) New typedef. * oln/core/3d/array3d.hh: Do not set exact_ptr, since this class (oln/core/3d/bkd_piter3d.hh): Include them. not longer inherits from mlc::any__best_speed, but from mlc::any. (size): Rename method as... (impl_size): ...this. (~array3d): Call clear_data() instead of impl_clear_data(). (impl_resize): Move allocation code... (alloc_and_init): ...here (new function). (impl_resize_border): New method. * tests/core/tests/readwrite_image: Catch up with the new property system. * tests/core/tests/piter1d (check): Test bkd_piter1d too. * tests/core/tests/piter3d (check): Test bkd_piter3d too. Index: olena/tests/core/tests/fwd_witer2d --- olena/tests/core/tests/fwd_witer2d (revision 147) +++ olena/tests/core/tests/fwd_witer2d (working copy) @@ -1,3 +1,4 @@ + // -*- C++ -*- #include <oln/core/2d/fwd_witer2d.hh> #include <oln/core/abstract/piter.hh> Index: olena/tests/core/tests/readwrite_image --- olena/tests/core/tests/readwrite_image (revision 147) +++ olena/tests/core/tests/readwrite_image (working copy) @@ -1,3 +1,4 @@ + // -*- C++ -*- #include <iostream> #include <ntg/all.hh> @@ -19,12 +20,10 @@ }; template <> - struct set_props <category::image, dummy_image> : - public props_of < category::image > + struct set_props <category::image, dummy_image> { typedef is_a<abstract::readwrite_image> image_constness; typedef is_a<abstract::image2d> image_dimension_type; - typedef vectorialness_from_valuetype_(ntg::int_u8) image_vectorialness_type; typedef size2d size_type; typedef point2d point_type; Index: olena/tests/core/tests/piter1d --- olena/tests/core/tests/piter1d (revision 147) +++ olena/tests/core/tests/piter1d (working copy) @@ -1,4 +1,4 @@ - + // -*- C++ -*- #include <iostream> #include <ntg/all.hh> @@ -15,15 +15,28 @@ oln::image1d<int> ima(10); int cpt = 0; - oln::fwd_piter1d it(ima.size()); - for_all (it) + oln::fwd_piter1d fwd_it(ima.size()); + for_all_p (fwd_it) + { + ima[fwd_it] = 0; + cpt++; + } + + if (cpt != 10) + return true; + + + cpt = 0; + oln::bkd_piter1d bkd_it(ima.size()); + for_all_p (bkd_it) { - ima[it] = 0; + ima[bkd_it] = 0; cpt++; } if (cpt != 10) return true; + return false; } Index: olena/tests/core/tests/piter2d --- olena/tests/core/tests/piter2d (revision 147) +++ olena/tests/core/tests/piter2d (working copy) @@ -1,4 +1,4 @@ - + // -*- C++ -*- #include <iostream> #include <ntg/all.hh> @@ -16,7 +16,7 @@ int cpt = 0; oln::fwd_piter2d fwd_it(ima.size()); - for_all (fwd_it) + for_all_p (fwd_it) { ima[fwd_it] = 0; cpt++; @@ -28,7 +28,7 @@ cpt = 0; oln::bkd_piter2d bkd_it(ima.size()); - for_all (bkd_it) + for_all_p (bkd_it) { ima[bkd_it] = 0; cpt++; Index: olena/tests/core/tests/piter3d --- olena/tests/core/tests/piter3d (revision 147) +++ olena/tests/core/tests/piter3d (working copy) @@ -1,4 +1,4 @@ - + // -*- C++ -*- #include <iostream> #include <ntg/all.hh> @@ -15,15 +15,28 @@ oln::image3d<int> ima(10, 10, 10); int cpt = 0; - oln::fwd_piter3d it(ima.size()); - for_all (it) + oln::fwd_piter3d fwd_it(ima.size()); + for_all_p (fwd_it) + { + ima[fwd_it] = 0; + cpt++; + } + + if (cpt != 1000) + return true; + + + cpt = 0; + oln::bkd_piter3d bkd_it(ima.size()); + for_all_p (bkd_it) { - ima[it] = 0; + ima[bkd_it] = 0; cpt++; } if (cpt != 1000) return true; + return false; } Index: olena/oln/core/1d/array1d.hh --- olena/oln/core/1d/array1d.hh (revision 147) +++ olena/oln/core/1d/array1d.hh (working copy) @@ -52,6 +52,14 @@ }; + template<class T> + void alloc_and_init(T*& buffer, const size1d& s) + { + size_t nelts_eff = s.nindices() + 2 * s.border(); + buffer = new T[nelts_eff]; + buffer += s.border(); + } + template <typename T> class array1d : public abstract::data_storage< array1d<T> > @@ -63,7 +71,6 @@ buffer_(0), size_() { - this->exact_ptr = this; invariant_(); } @@ -76,13 +83,12 @@ buffer_(0), size_() { - this->exact_ptr = this; this->resize(s); } ~array1d() { - this->impl_clear_data(); + this->clear_data(); } bool impl_has_data() const @@ -97,6 +103,7 @@ if (this->has_data()) { // buffer + buffer_ -= size_.border(); delete[] buffer_; buffer_ = 0; // size @@ -105,7 +112,7 @@ invariant_(); } - const size1d& size() const + const size1d& impl_size() const { return size_; } @@ -117,8 +124,41 @@ invariant_(); this->clear_data(); size_ = s; - size_t nelts_eff = size_.nindices() + 2 * size_.border(); - buffer_ = new T[nelts_eff]; + + alloc_and_init(buffer_, s); + invariant_(); + } + + void impl_resize_border(size_t new_border, bool copy_border) + { + invariant_(); + T* new_buffer_; + size1d new_size_(this->size_.nindices(), new_border); + + alloc_and_init(new_buffer_, new_size_); + + if (buffer_ != 0) + { + size_t border = this->size_.border(); + + if (border > new_border) + border = new_border; + + coord_t indice_min = copy_border ? -border : 0; + coord_t indice_max = int(this->size_.nindices()) + + (copy_border ? border : 0); + size_t nindices = int(this->size_.nindices()) + + (copy_border ? (border * 2) : 0); + + memcpy(new_buffer_ + indice_min, this->buffer_ + indice_min, + nindices * sizeof (T)); + + this->clear_data(); + } + + buffer_ = new_buffer_; + size_ = new_size_; + invariant_(); } Index: olena/oln/core/1d/image1d.hh --- olena/oln/core/1d/image1d.hh (revision 147) +++ olena/oln/core/1d/image1d.hh (working copy) @@ -41,6 +41,7 @@ // fwd decls struct fwd_piter1d; + struct bkd_piter1d; template <typename T> class image1d; // super type @@ -63,6 +64,7 @@ typedef fwd_piter1d piter_type; typedef fwd_piter1d fwd_piter_type; + typedef bkd_piter1d bkd_piter_type; // please note that value_storage_type means data_type // since image1d is an image_with_data Index: olena/oln/core/2d/array2d.hh --- olena/oln/core/2d/array2d.hh (revision 147) +++ olena/oln/core/2d/array2d.hh (working copy) @@ -58,7 +58,6 @@ buffer = new T[nelts_eff]; array = new T*[nrows_eff]; - buffer = buffer; T* buf = buffer + s.border(); for (size_t row = 0; row < nrows_eff; ++row) { @@ -97,7 +96,7 @@ ~array2d() { - this->impl_clear_data(); + this->clear_data(); } bool impl_has_data() const Index: olena/oln/core/3d/array3d.hh --- olena/oln/core/3d/array3d.hh (revision 147) +++ olena/oln/core/3d/array3d.hh (working copy) @@ -53,6 +53,32 @@ }; + template<class T> + void alloc_and_init(T*& buffer, T***& array, T**& array2, const size3d& s) + { + size_t nslices_eff = s.nslices() + 2 * s.border(); + size_t nrows_eff = s.nrows() + 2 * s.border(); + size_t ncols_eff = s.ncols() + 2 * s.border(); + size_t nelts_eff = nslices_eff * nrows_eff * ncols_eff; + + buffer = new T[nelts_eff]; + array = new T**[nslices_eff]; + array2 = new T*[nslices_eff * nrows_eff]; + + T* buf = buffer + s.border(); + for (size_t slice = 0; slice < nslices_eff; ++slice) + { + T** a2 = array2 + slice * nrows_eff; + array[slice] = a2 + s.border(); + for (size_t row = 0; row < nrows_eff; ++row) + { + a2[row] = buf; + buf += ncols_eff; + } + } + array += s.border(); + } + template <typename T> class array3d : public abstract::data_storage< array3d<T> > { @@ -65,7 +91,6 @@ array2_(0), size_() { - this->exact_ptr = this; invariant_(); } @@ -80,13 +105,12 @@ array2_(0), size_() { - this->exact_ptr = this; this->resize(s); } ~array3d() { - this->impl_clear_data(); + this->clear_data(); } bool impl_has_data() const @@ -116,7 +140,7 @@ invariant_(); } - const size3d& size() const + const size3d& impl_size() const { return size_; } @@ -131,27 +155,52 @@ this->clear_data(); size_ = s; - size_t nslices_eff = size_.nslices() + 2 * size_.border(); - size_t nrows_eff = size_.nrows() + 2 * size_.border(); - size_t ncols_eff = size_.ncols() + 2 * size_.border(); - size_t nelts_eff = nslices_eff * nrows_eff * ncols_eff; - - buffer_ = new T[nelts_eff]; - array_ = new T**[nslices_eff]; - array2_ = new T*[nslices_eff * nrows_eff]; + alloc_and_init(buffer_, array_, array2_, s); + invariant_(); + } - T* buf = buffer_ + size_.border(); - for (size_t slice = 0; slice < nslices_eff; ++slice) + void impl_resize_border(size_t new_border, bool copy_border) { - T** a2 = array2_ + slice * nrows_eff; - array_[slice] = a2 + size_.border(); - for (size_t row = 0; row < nrows_eff; ++row) + invariant_(); + T* new_buffer_; + T*** new_array_; + T** new_array2_; + size3d new_size_(this->size_.nslices(), this->size_.nrows(), + this->size_.ncols(), new_border); + + alloc_and_init(new_buffer_, new_array_, new_array2_, new_size_); + + if (buffer_ != 0) { - a2[row] = buf; - buf += ncols_eff; - } + size_t border = this->size_.border(); + + if (border > new_border) + border = new_border; + + coord_t slice_min = copy_border ? -border : 0; + coord_t slice_max = int(this->size_.nslices()) + + (copy_border ? border : 0); + coord_t row_min = copy_border ? -border : 0; + coord_t row_max = int(this->size_.nrows()) + + (copy_border ? border : 0); + coord_t col_min = copy_border ? -border : 0; + size_t ncols = int(this->size_.ncols()) + + (copy_border ? (border * 2) : 0); + + for (coord_t slice = slice_min; slice < slice_max; ++slice) + for (coord_t row = row_min; row < row_max; ++row) + memcpy(new_array_[slice][row] + col_min, + this->array_[slice][row] + col_min, + ncols * sizeof (T)); + + this->clear_data(); } - array_ += size_.border(); + + buffer_ = new_buffer_; + array_ = new_array_; + array2_ = new_array2_; + size_ = new_size_; + invariant_(); } Index: olena/oln/core/3d/image3d.hh --- olena/oln/core/3d/image3d.hh (revision 147) +++ olena/oln/core/3d/image3d.hh (working copy) @@ -44,6 +44,7 @@ // fwd decls struct fwd_piter3d; + struct bkd_piter3d; template <typename T> class image3d; // super @@ -66,6 +67,7 @@ typedef fwd_piter3d piter_type; typedef fwd_piter3d fwd_piter_type; + typedef bkd_piter3d bkd_piter_type; // please note that value_storage_type means data_type // since image3d is an image_with_data
19Â years, 8Â months
1
0
0
0
← Newer
1
...
931
932
933
934
935
936
937
...
963
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
Results per page:
10
25
50
100
200