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
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
August 2009
----- 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
6 participants
108 discussions
Start a n
N
ew thread
4342: Integrate LRDE code writting rules in the Stats code.
by Yann Jacquelet
* green/Stats/Makefile.am : Remove Makefile. * green/Stats/Stats.cc : Remove source. * green/Stats : Remove directory. * green/stats : New directory. * green/stats/Makefile.am : New Makefile. * green/stats/stats.cc : New source. --- trunk/milena/sandbox/ChangeLog | 12 ++++++++++++ .../sandbox/green/{Stats => stats}/Makefile.am | 0 .../green/{Stats/Stats.cc => stats/stats.cc} | 0 3 files changed, 12 insertions(+), 0 deletions(-) rename trunk/milena/sandbox/green/{Stats => stats}/Makefile.am (100%) rename trunk/milena/sandbox/green/{Stats/Stats.cc => stats/stats.cc} (100%) diff --git a/trunk/milena/sandbox/ChangeLog b/trunk/milena/sandbox/ChangeLog index 399a8cd..0f1c749 100644 --- a/trunk/milena/sandbox/ChangeLog +++ b/trunk/milena/sandbox/ChangeLog @@ -1,5 +1,17 @@ 2009-08-04 Yann Jacquelet <jacquelet(a)lrde.epita.fr> + Integrate LRDE code writting rules in the Stats code. + + * green/Stats/Makefile.am : Remove Makefile. + * green/Stats/Stats.cc : Remove source. + * green/Stats : Remove directory. + + * green/stats : New directory. + * green/stats/Makefile.am : New Makefile. + * green/stats/stats.cc : New source. + +2009-08-04 Yann Jacquelet <jacquelet(a)lrde.epita.fr> + Integrate LRDE code writting rules in the HelloMilena code. * green/LearnMilena/Makefile.am : Remove Makefile. diff --git a/trunk/milena/sandbox/green/Stats/Makefile.am b/trunk/milena/sandbox/green/stats/Makefile.am similarity index 100% rename from trunk/milena/sandbox/green/Stats/Makefile.am rename to trunk/milena/sandbox/green/stats/Makefile.am diff --git a/trunk/milena/sandbox/green/Stats/Stats.cc b/trunk/milena/sandbox/green/stats/stats.cc similarity index 100% rename from trunk/milena/sandbox/green/Stats/Stats.cc rename to trunk/milena/sandbox/green/stats/stats.cc -- 1.5.6.5
15 years, 4 months
1
0
0
0
4341: Integrate LRDE code writting rules in the HelloMilena code.
by Yann Jacquelet
* green/LearnMilena/Makefile.am : Remove Makefile. * green/LearnMilena/LearnMilena.cc : Remove source. * green/LearnMilena : Remove directory. * green/learn_milena : New directory. * green/learn_milena/Makefile.am : New Makefile. * green/learn_milena/learn_milena.cc : New source. --- trunk/milena/sandbox/ChangeLog | 12 ++++++++++++ .../{LearnMilena => learn_milena}/Makefile.am | 0 .../learn_milena.cc} | 0 3 files changed, 12 insertions(+), 0 deletions(-) rename trunk/milena/sandbox/green/{LearnMilena => learn_milena}/Makefile.am (100%) rename trunk/milena/sandbox/green/{LearnMilena/LearnMilena.cc => learn_milena/learn_milena.cc} (100%) diff --git a/trunk/milena/sandbox/ChangeLog b/trunk/milena/sandbox/ChangeLog index 329e303..399a8cd 100644 --- a/trunk/milena/sandbox/ChangeLog +++ b/trunk/milena/sandbox/ChangeLog @@ -2,6 +2,18 @@ Integrate LRDE code writting rules in the HelloMilena code. + * green/LearnMilena/Makefile.am : Remove Makefile. + * green/LearnMilena/LearnMilena.cc : Remove source. + * green/LearnMilena : Remove directory. + + * green/learn_milena : New directory. + * green/learn_milena/Makefile.am : New Makefile. + * green/learn_milena/learn_milena.cc : New source. + +2009-08-04 Yann Jacquelet <jacquelet(a)lrde.epita.fr> + + Integrate LRDE code writting rules in the HelloMilena code. + * green/HelloMilena/Makefile.am : Remove Makefile. * green/HelloMilena/HelloMilena.cc : Remove source. * green/HelloMilena : Remove directory. diff --git a/trunk/milena/sandbox/green/LearnMilena/Makefile.am b/trunk/milena/sandbox/green/learn_milena/Makefile.am similarity index 100% rename from trunk/milena/sandbox/green/LearnMilena/Makefile.am rename to trunk/milena/sandbox/green/learn_milena/Makefile.am diff --git a/trunk/milena/sandbox/green/LearnMilena/LearnMilena.cc b/trunk/milena/sandbox/green/learn_milena/learn_milena.cc similarity index 100% rename from trunk/milena/sandbox/green/LearnMilena/LearnMilena.cc rename to trunk/milena/sandbox/green/learn_milena/learn_milena.cc -- 1.5.6.5
15 years, 4 months
1
0
0
0
4340: Integrate LRDE code writting rules in the HelloMilena code.
by Yann Jacquelet
* green/HelloMilena/Makefile.am : Remove Makefile. * green/HelloMilena/HelloMilena.cc : Remove source. * green/HelloMilena : Remove directory. * green/hello_milena : New directory. * green/hello_milena/Makefile.am : New Makefile. * green/hello_milena/hello_milena.cc : New source. --- trunk/milena/sandbox/ChangeLog | 28 +++++++++++++++----- .../{HelloMilena => hello_milena}/Makefile.am | 0 .../hello_milena.cc} | 21 ++++++++------- 3 files changed, 32 insertions(+), 17 deletions(-) rename trunk/milena/sandbox/green/{HelloMilena => hello_milena}/Makefile.am (100%) rename trunk/milena/sandbox/green/{HelloMilena/HelloMilena.cc => hello_milena/hello_milena.cc} (79%) diff --git a/trunk/milena/sandbox/ChangeLog b/trunk/milena/sandbox/ChangeLog index baf6b54..329e303 100644 --- a/trunk/milena/sandbox/ChangeLog +++ b/trunk/milena/sandbox/ChangeLog @@ -1,14 +1,28 @@ 2009-08-04 Yann Jacquelet <jacquelet(a)lrde.epita.fr> - Integrate LRDE code writting rules in my learning programs. + Integrate LRDE code writting rules in the HelloMilena code. - * green/Otsu/Makefile.am : Remove Makefile. - * green/Otsu/Otsu.cc : Remove source. - * green/Otsu : Remove directory. + * green/HelloMilena/Makefile.am : Remove Makefile. + * green/HelloMilena/HelloMilena.cc : Remove source. + * green/HelloMilena : Remove directory. + + * green/hello_milena : New directory. + * green/hello_milena/Makefile.am : New Makefile. + * green/hello_milena/hello_milena.cc : New source. - * green/otsu : New directory. - * green/otsu/Makefile.am : New Makefile. - * green/otsu/otsu.cc : New source (substituate float by double). +2009-08-04 Yann Jacquelet <jacquelet(a)lrde.epita.fr> + + Integrate LRDE code writting rules in the HelloWorld code. + + * green/HelloWorld/Makefile.am : Remove Makefile. + * green/HelloWorld/HelloWorld.cc : Remove source. + * green/HelloWorld/Print.cc : Remove source. + * green/HelloWorld : Remove directory. + + * green/hello_world : New directory. + * green/hello_world/Makefile.am : New Makefile. + * green/hello_world/hello_world.cc : New source. + * green/hello_world/print.cc : New source. 2009-08-04 Yann Jacquelet <jacquelet(a)lrde.epita.fr> diff --git a/trunk/milena/sandbox/green/HelloMilena/Makefile.am b/trunk/milena/sandbox/green/hello_milena/Makefile.am similarity index 100% rename from trunk/milena/sandbox/green/HelloMilena/Makefile.am rename to trunk/milena/sandbox/green/hello_milena/Makefile.am diff --git a/trunk/milena/sandbox/green/HelloMilena/HelloMilena.cc b/trunk/milena/sandbox/green/hello_milena/hello_milena.cc similarity index 79% rename from trunk/milena/sandbox/green/HelloMilena/HelloMilena.cc rename to trunk/milena/sandbox/green/hello_milena/hello_milena.cc index 0a8eb61..b319929 100644 --- a/trunk/milena/sandbox/green/HelloMilena/HelloMilena.cc +++ b/trunk/milena/sandbox/green/hello_milena/hello_milena.cc @@ -14,17 +14,17 @@ int main() // Définition de HelloWorld sous forme binaire bool vals [13][21] = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0}, + {0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0}, {0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0}, - {0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0}, + {0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0}, {0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0}, - {0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0}, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0}, - {0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0}, - {0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0}, - {0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0}, - {0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0}, + {0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0}, + {0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0}, + {0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0}, + {0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0}, + {0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; // Initialiser l'image avec sa définition @@ -33,7 +33,8 @@ int main() // Imprimer l'image en mode texte sur la console debug::println(img); - // Sauver l'image en pbm, l'afficher hors programme avec "display HelloWorld.pbm" + // Sauver l'image en pbm, + //l'afficher hors programme avec "display HelloWorld.pbm" io::pbm::save(img, "./HelloWorld.pbm"); return 0; -- 1.5.6.5
15 years, 4 months
1
0
0
0
4339: Integrate LRDE code writting rules in the HelloWorld code.
by Yann Jacquelet
* green/HelloWorld/Makefile.am : Remove Makefile. * green/HelloWorld/HelloWorld.cc : Remove source. * green/HelloWorld/Print.cc : Remove source. * green/HelloWorld : Remove directory. * green/hello_world : New directory. * green/hello_world/Makefile.am : New Makefile. * green/hello_world/hello_world.cc : New source. * green/hello_world/print.cc : New source. --- trunk/milena/sandbox/ChangeLog | 42 ++++++++++++++++++++ .../green/{HelloWorld => hello_world}/Makefile.am | 0 .../HelloWorld.cc => hello_world/hello_world.cc} | 0 .../{HelloWorld/Print.cc => hello_world/print.cc} | 0 4 files changed, 42 insertions(+), 0 deletions(-) rename trunk/milena/sandbox/green/{HelloWorld => hello_world}/Makefile.am (100%) rename trunk/milena/sandbox/green/{HelloWorld/HelloWorld.cc => hello_world/hello_world.cc} (100%) rename trunk/milena/sandbox/green/{HelloWorld/Print.cc => hello_world/print.cc} (100%) diff --git a/trunk/milena/sandbox/ChangeLog b/trunk/milena/sandbox/ChangeLog index 010a2b9..baf6b54 100644 --- a/trunk/milena/sandbox/ChangeLog +++ b/trunk/milena/sandbox/ChangeLog @@ -1,3 +1,45 @@ +2009-08-04 Yann Jacquelet <jacquelet(a)lrde.epita.fr> + + Integrate LRDE code writting rules in my learning programs. + + * green/Otsu/Makefile.am : Remove Makefile. + * green/Otsu/Otsu.cc : Remove source. + * green/Otsu : Remove directory. + + * green/otsu : New directory. + * green/otsu/Makefile.am : New Makefile. + * green/otsu/otsu.cc : New source (substituate float by double). + +2009-08-04 Yann Jacquelet <jacquelet(a)lrde.epita.fr> + + Integrate LRDE code writting rules in my own otsu code. + + * green/Otsu/Makefile.am : Remove Makefile. + * green/Otsu/Otsu.cc : Remove source. + * green/Otsu : Remove directory. + + * green/otsu : New directory. + * green/otsu/Makefile.am : New Makefile. + * green/otsu/otsu.cc : New source (substituate float by double). + + +2009-08-04 Yann Jacquelet <jacquelet(a)lrde.epita.fr> + + Integrate LRDE code writting rules in the fraction c++ type. + + * green/Fraction/Makefile.am : Remove Makefile. + * green/Fraction/main.cc : Remove source. + * green/Fraction/frac.hh : Remove source. + * green/Fraction/frac.cc : Remove source. + * green/Fraction : Remove directory. + + * green/fraction : New directory. + * green/fraction/Makefile.am : New Makefile. + * green/fraction/sign_prod.hh : New source. + * green/fraction/gcd.hh : New source. + * green/fraction/frac.hh : New source. + * green/fraction/frac.cc : New source. + 2009-08-03 Fabien Freling <fabien.freling(a)lrde.epita.fr> Implement support for 2D tiled images and other drafts. diff --git a/trunk/milena/sandbox/green/HelloWorld/Makefile.am b/trunk/milena/sandbox/green/hello_world/Makefile.am similarity index 100% rename from trunk/milena/sandbox/green/HelloWorld/Makefile.am rename to trunk/milena/sandbox/green/hello_world/Makefile.am diff --git a/trunk/milena/sandbox/green/HelloWorld/HelloWorld.cc b/trunk/milena/sandbox/green/hello_world/hello_world.cc similarity index 100% rename from trunk/milena/sandbox/green/HelloWorld/HelloWorld.cc rename to trunk/milena/sandbox/green/hello_world/hello_world.cc diff --git a/trunk/milena/sandbox/green/HelloWorld/Print.cc b/trunk/milena/sandbox/green/hello_world/print.cc similarity index 100% rename from trunk/milena/sandbox/green/HelloWorld/Print.cc rename to trunk/milena/sandbox/green/hello_world/print.cc -- 1.5.6.5
15 years, 4 months
1
0
0
0
4338: Integrate LRDE code writting rules in my own otsu code.
by Yann Jacquelet
* green/Otsu/Makefile.am : Remove Makefile. * green/Otsu/Otsu.cc : Remove source. * green/Otsu : Remove directory. * green/otsu : New directory. * green/otsu/Makefile.am : New Makefile. * green/otsu/otsu.cc : New source (substituate float by double). --- trunk/milena/sandbox/green/otsu/Makefile.am | 49 +++++++++++ .../sandbox/green/{Otsu/Otsu.cc => otsu/otsu.cc} | 84 ++++++++++++------- 2 files changed, 102 insertions(+), 31 deletions(-) create mode 100644 trunk/milena/sandbox/green/otsu/Makefile.am rename trunk/milena/sandbox/green/{Otsu/Otsu.cc => otsu/otsu.cc} (57%) diff --git a/trunk/milena/sandbox/green/otsu/Makefile.am b/trunk/milena/sandbox/green/otsu/Makefile.am new file mode 100644 index 0000000..36a83e3 --- /dev/null +++ b/trunk/milena/sandbox/green/otsu/Makefile.am @@ -0,0 +1,49 @@ +# +# Generic Makefile +# + +BIN_PATTERN= trunk/build/milena +SRC_PATTERN= trunk/milena + +CXXFLAGS= -ggdb -O0 -Wall -W -pedantic -ansi -pipe +ECHO= echo +RM= rm +MKDIR= mkdir +CP= cp + +ifeq ($(findstring $(BIN_PATTERN),$(PWD)), $(BIN_PATTERN)) +BIN_DIR= +SRC_DIR= $(subst $(BIN_PATTERN),$(SRC_PATTERN), $(PWD))/ +else +BIN_DIR= $(subst $(SRC_PATTERN),$(BIN_PATTERN), $(PWD))/ +SRC_DIR= +endif + +TARGET= $(BIN_DIR)$(notdir $(PWD)) +BIN_MAKE= $(BIN_DIR)Makefile +SRC_MAKE= $(SRC_DIR)Makefile.am + + +SRC_FILES= $(wildcard $(SRC_DIR)*.cc) +OLD_FILES= $(addsuffix ~, $(SRC_FILES)) +OBJ_FILES= $(addprefix $(BIN_DIR), $(notdir $(SRC_FILES:%.cc=%.o))) + + +all: $(BIN_DIR) $(TARGET) + @$(ECHO) "Compilation terminée" + +$(BIN_DIR): + $(MKDIR) $(BIN_DIR) + $(CP) $(SRC_MAKE) $(BIN_MAKE) + +$(TARGET):$(OBJ_FILES) + $(LINK.cc) $^ $(LOADLIBES) $(LDLIBS) -o $@ + +$(BIN_DIR)%.o:$(SRC_DIR)%.cc + $(COMPILE.cc) $(OUTPUT_OPTION) $< + +clean: + -@$(RM) $(TARGET) + -@$(RM) $(OBJ_FILES) + -@$(RM) $(OLD_FILES) + diff --git a/trunk/milena/sandbox/green/Otsu/Otsu.cc b/trunk/milena/sandbox/green/otsu/otsu.cc similarity index 57% rename from trunk/milena/sandbox/green/Otsu/Otsu.cc rename to trunk/milena/sandbox/green/otsu/otsu.cc index 138c07e..78d1594 100644 --- a/trunk/milena/sandbox/green/Otsu/Otsu.cc +++ b/trunk/milena/sandbox/green/otsu/otsu.cc @@ -14,6 +14,7 @@ #include <mln/accu/stat/mean.hh> #include <mln/accu/stat/variance.hh> #include <mln/data/compute.hh> +#include <mln/math/sqr.hh> // Pour les chargements/sauvegardes des images #include <mln/io/pgm/load.hh> @@ -41,6 +42,12 @@ // Pour la négation du mask #include <mln/logical/not.hh> +// +// En float, la variance totale n'est pas constante +// En double, cette variance ne bouge plus +// Le calcul des moments doit se faire en double +// voire de manière fractionnaire pour les ordres supérieurs +// #define MAX_THRESHOLD 255 @@ -60,12 +67,15 @@ int main() io::pgm::load(input, "/usr/local/share/olena/images/small.pgm"); -// (2) Etablir les caractéristiques globales de l'image (min, max, mean, variance) - float count = data::compute(accu::meta::math::count(), input); +// (2) Etablir les caractéristiques globales de l'image +//(min, max, mean, variance) + typedef value::int_u8 gl8; + + double count = data::compute(accu::meta::math::count(), input); value::int_u8 min = data::compute(accu::meta::stat::min(), input); value::int_u8 max = data::compute(accu::meta::stat::max(), input); - float mean = data::compute(accu::meta::stat::mean(), input); - float var = data::compute(accu::stat::variance<value::int_u8>(), input); + double mean = data::compute(accu::meta::stat::mean(), input); + double var = data::compute(accu::stat::variance<double>(), input); cout << "CARACTERISTIQUES DE L'IMAGE" << endl; cout << "COUNT = " << count << endl; @@ -82,36 +92,42 @@ int main() -// (4) Calculer les caractéristiques de chacunes des 2 classes pour chacun des seuils - float grp1_count[MAX_THRESHOLD]; - float grp1_mean[MAX_THRESHOLD]; - float grp1_var[MAX_THRESHOLD]; +// (4) Calculer les caractéristiques de chacunes des 2 classes +// pour chacun des seuils + double grp1_count[MAX_THRESHOLD]; + double grp1_mean[MAX_THRESHOLD]; + double grp1_var[MAX_THRESHOLD]; - float grp2_count[MAX_THRESHOLD]; - float grp2_mean[MAX_THRESHOLD]; - float grp2_var[MAX_THRESHOLD]; + double grp2_count[MAX_THRESHOLD]; + double grp2_mean[MAX_THRESHOLD]; + double grp2_var[MAX_THRESHOLD]; - typedef image_if< image2d<value::int_u8>, fun::eq_v2b_expr_< pw::value_< image2d<bool> >, pw::cst_<int> > > tmp_img_t; + typedef image2d<bool> mask_t; + typedef image2d<gl8> img_t; + typedef fun::eq_v2b_expr_< pw::value_< mask_t >, pw::cst_<int> > fun_t; + typedef image_if< img_t, fun_t > tmp_img_t; - for (value::int_u8 threshold = min; threshold <= max; threshold++) + for (value::int_u8 threshold = min; threshold <= max+1; threshold++) { mask = binarization::threshold(input, threshold); tmp_img_t tmp1 = (input | (pw::value(mask) == false)).rw(); grp1_count[threshold] = data::compute(accu::meta::math::count(), tmp1); grp1_mean[threshold] = data::compute(accu::meta::stat::mean(), tmp1); - grp1_var[threshold] = data::compute(accu::stat::variance<float>(), tmp1); -# grp1_var[threshold] = data::compute(accu::stat::variance<value::int_u8>(), tmp2); + grp1_var[threshold] = data::compute(accu::stat::variance<double>(), tmp1); + //grp1_var[threshold] = data::compute(accu::stat::variance<gl8>(), tmp2); tmp_img_t tmp2 = (input | (pw::value(mask) == true)).rw(); grp2_count[threshold] = data::compute(accu::meta::math::count(), tmp2); grp2_mean[threshold] = data::compute(accu::meta::stat::mean(), tmp2); - grp2_var[threshold] = data::compute(accu::stat::variance<float>(), tmp2); -# grp2_var[threshold] = data::compute(accu::stat::variance<value::int_u8>(), tmp2); + grp2_var[threshold] = data::compute(accu::stat::variance<double>(), tmp2); + //grp2_var[threshold] = data::compute(accu::stat::variance<gl8>(), tmp2); cout << "S = " << threshold << " "; - cout << "G1=[" << grp1_count[threshold] << ", " << grp1_mean[threshold] << ", " << grp1_var[threshold] << "] "; - cout << "G2=[" << grp2_count[threshold] << ", " << grp2_mean[threshold] << ", " << grp2_var[threshold] << "]" << endl; + cout << "G1=[" << grp1_count[threshold] << ", "; + cout << grp1_mean[threshold] << ", " << grp1_var[threshold] << "] "; + cout << "G2=[" << grp2_count[threshold] << ", "; + cout << grp2_mean[threshold] << ", " << grp2_var[threshold] << "]" << endl; } cout << "---------------------------" << endl; @@ -124,18 +140,24 @@ int main() // Vintra = (1/N)(N1*V1+N2*V2) // Vinter = (1/N)(N1*(M-M1)² + N2*(M-M2)²) // V = Vinter + Vintra - float min_var = var; + double min_var = var; value::int_u8 min_threshold = 0; - for (value::int_u8 threshold = min; threshold <= max; threshold++) + for (value::int_u8 threshold = min; threshold <= max+1; threshold++) { - float img_count = grp1_count[threshold] + grp2_count[threshold]; - float img_mean = (grp1_count[threshold]*grp1_mean[threshold]+grp2_count[threshold]*grp2_mean[threshold])/img_count; - float var_intra = (grp1_count[threshold]*grp1_var[threshold]+grp2_count[threshold]*grp2_var[threshold])/img_count; - float grp1_diff = img_mean-grp1_mean[threshold]; - float grp2_diff = img_mean-grp2_mean[threshold]; - float var_inter = (grp1_count[threshold]*grp1_diff*grp1_diff+grp2_count[threshold]*grp2_diff*grp2_diff)/img_count; - float img_var = var_inter + var_intra; + double img_count = grp1_count[threshold] + grp2_count[threshold]; + double grp1_mp = grp1_count[threshold] * grp1_mean[threshold]; + double grp2_mp = grp2_count[threshold] * grp2_mean[threshold]; + double img_mean = (grp1_mp + grp2_mp)/img_count; + double grp1_vp = grp1_count[threshold] * grp1_var[threshold]; + double grp2_vp = grp2_count[threshold] * grp2_var[threshold]; + double var_intra = (grp1_vp + grp2_vp)/img_count; + double grp1_diff = math::sqr(img_mean-grp1_mean[threshold]); + double grp2_diff = math::sqr(img_mean-grp2_mean[threshold]); + double grp1_inter= grp1_count[threshold] * grp1_diff; + double grp2_inter= grp2_count[threshold] * grp2_diff; + double var_inter = (grp1_inter + grp2_inter)/img_count; + double img_var = var_inter + var_intra; if (min_var > var_intra) { @@ -143,7 +165,7 @@ int main() min_threshold = threshold; } - cout << "S = " << threshold << " (" << img_count << ", " << img_mean << ", "; + cout << "S = " << threshold << " (" << img_count << ", " << img_mean <<", "; cout << img_var << "[" << var_intra << "|" << var_inter << "]) " << endl; } @@ -155,8 +177,8 @@ int main() initialize(output, input); data::paste(input, output); mask = binarization::threshold(input, min_threshold); - data::fill((output | (pw::value(mask) == false)).rw(), grp1_mean[min_threshold]); - data::fill((output | (pw::value(mask) == true)).rw(), grp2_mean[min_threshold]); + data::fill((output|(pw::value(mask) == false)).rw(),grp1_mean[min_threshold]); + data::fill((output|(pw::value(mask) == true)).rw(), grp2_mean[min_threshold]); // binarisation mask = binarization::threshold(input, min_threshold); -- 1.5.6.5
15 years, 4 months
1
0
0
0
4337: Integrate LRDE code writting rules in the fraction c++ type.
by Yann Jacquelet
* green/Fraction/Makefile.am : Remove Makefile. * green/Fraction/main.cc : Remove source. * green/Fraction/frac.hh : Remove source. * green/Fraction/frac.cc : Remove source. * green/Fraction : Remove directory. * green/fraction : New directory. * green/fraction/Makefile.am : New Makefile. * green/fraction/sign_prod.hh : New source. * green/fraction/gcd.hh : New source. * green/fraction/frac.hh : New source. * green/fraction/frac.cc : New source. --- trunk/milena/sandbox/green/Fraction/frac.cc | 271 --------- trunk/milena/sandbox/green/Fraction/main.cc | 112 ---- .../green/{Fraction => fraction}/Makefile.am | 0 trunk/milena/sandbox/green/fraction/frac.cc | 423 +++++++++++++ .../sandbox/green/{Fraction => fraction}/frac.hh | 641 ++++++++++---------- trunk/milena/sandbox/green/fraction/gcd.hh | 91 +++ trunk/milena/sandbox/green/fraction/sign_prod.hh | 74 +++ 7 files changed, 919 insertions(+), 693 deletions(-) delete mode 100644 trunk/milena/sandbox/green/Fraction/frac.cc delete mode 100644 trunk/milena/sandbox/green/Fraction/main.cc rename trunk/milena/sandbox/green/{Fraction => fraction}/Makefile.am (100%) create mode 100644 trunk/milena/sandbox/green/fraction/frac.cc rename trunk/milena/sandbox/green/{Fraction => fraction}/frac.hh (50%) create mode 100644 trunk/milena/sandbox/green/fraction/gcd.hh create mode 100644 trunk/milena/sandbox/green/fraction/sign_prod.hh diff --git a/trunk/milena/sandbox/green/Fraction/frac.cc b/trunk/milena/sandbox/green/Fraction/frac.cc deleted file mode 100644 index 4a7f452..0000000 --- a/trunk/milena/sandbox/green/Fraction/frac.cc +++ /dev/null @@ -1,271 +0,0 @@ -#include <iostream> -#include "frac.hh" - -// -// TEST INSTANTIATION -// -void test_instantiation_without_argument() -{ - const mln::algebra::frac<int> constant; - mln::algebra::frac<int> variable; - - mln_assertion(constant == variable); - std::cout << "const frac<T> f : ok" << std::endl; - std::cout << "frac<T> f : ok" << std::endl; -} - -void test_instantiation_numerator_denominator() -{ - const mln::algebra::frac<int> constant(2,5); - mln::algebra::frac<int> variable(2,5); - - mln_assertion(constant == variable); - std::cout << "const frac<T> f(n,d) : ok" << std::endl; - std::cout << "frac<T> f(n,d) : ok" << std::endl; -} - -void test_instantiation_frac() -{ - const mln::algebra::frac<int> ref_int(2,5); - const mln::algebra::frac<long> ref_long(2,5); - - const mln::algebra::frac<int> constant1 = ref_int; - const mln::algebra::frac<int> constant2 = ref_long; - mln::algebra::frac<int> variable1 = ref_int; - mln::algebra::frac<int> variable2 = ref_long; - - mln_assertion(constant1 == ref_int); - mln_assertion(constant2 == ref_long); - mln_assertion(variable1 == ref_int); - mln_assertion(variable2 == ref_long); - std::cout << "const frac<T> f = frac<T> : ok" << std::endl; - std::cout << "const frac<T> f = frac<F> : ok" << std::endl; - std::cout << "frac<T> f = frac<T> : ok" << std::endl; - std::cout << "frac<T> f = frac<F> : ok" << std::endl; -} - -void test_instantiation_zero() -{ - const mln::algebra::frac<int> zero(0,0); - const mln::algebra::frac<int> f_cst = mln::literal::zero; - mln::algebra::frac<int> f_var = mln::literal::zero; - - mln_assertion(zero == f_cst); - mln_assertion(zero == f_var); - std::cout << "const frac<T> f = zero : ok" << std::endl; - std::cout << "frac<T> f = zero : ok" << std::endl; -} - -void test_instantiation_one() -{ - const mln::algebra::frac<int> one(1,0); - const mln::algebra::frac<int> f_cst = mln::literal::one; - mln::algebra::frac<int> f_var = mln::literal::one; - - mln_assertion(one == f_cst); - mln_assertion(one == f_var); - std::cout << "const frac<T> f = one : ok" << std::endl; - std::cout << "frac<T> f = one : ok" << std::endl; -} - -void test_instantiation_integer() -{ - const mln::algebra::frac<int> ref(5,0); - const mln::algebra::frac<int> f_cst = 5; - mln::algebra::frac<int> f_var = 5; - - mln_assertion(ref == f_cst); - mln_assertion(ref == f_var); - std::cout << "const frac<T> f = integer : ok" << std::endl; - std::cout << "frac<T> f = integer : ok" << std::endl; -} - - -// -// TEST ASSIGNEMENT -// -void test_assignement_zero() -{ - const mln::algebra::frac<int> zero(0,0); - mln::algebra::frac<int> f; - - f = mln::literal::zero; - mln_assertion(zero == f); - std::cout << "frac = zero : ok" << std::endl; -} - -void test_assignement_one() -{ - const mln::algebra::frac<int> one(1,0); - mln::algebra::frac<int> f; - - f = mln::literal::one; - mln_assertion(one == f); - std::cout << "frac = one : ok" << std::endl; -} - -void test_assignement_frac() -{ - const mln::algebra::frac<int> ref(2,3); - mln::algebra::frac<int> f; - - f = ref; - mln_assertion(ref == f); - std::cout << "frac = frac : ok" << std::endl; -} - -void test_assignement_integer() -{ - const mln::algebra::frac<int> ref(5,0); - mln::algebra::frac<int> f; - - f = 5; - mln_assertion(ref == f); - std::cout << "frac = integer: ok" << std::endl; -} - -int main() -{ - using namespace std; - using namespace mln; - using namespace mln::algebra; - - trace::quiet = true; - - // Testing instanciation - frac<int> f0; - frac<int> op1a(5,10); - frac<int> op1b(op1a); - frac<int> op2a(1,2); - frac<int> op2b = op2a; - int op3a = 1; - int op3b = 1; - int op4a = 2; - int op4b = 2; - frac<int> resPlus(literal::one); - frac<int> resMinus(literal::zero); - frac<int> resTimes(1,4); - frac<int> resDiv(literal::one); - frac<int> resPlusScalar(3,2); - frac<int> resMinusScalar(-1,2); - frac<int> resTimesScalar(literal::one); - frac<int> resDivScalar(1,4); - frac<int> resUminus(-1,4); - frac<int> resZero(0,0); - frac<int> resOne(1,0); - cout << "frac<T> f : ok" << endl; - - test_instantiation_without_argument(); - test_instantiation_numerator_denominator(); - test_instantiation_frac(); - test_instantiation_zero(); - test_instantiation_one(); - test_instantiation_integer(); - - // trace::quiet = false; - - //trace::quiet = true; - - test_assignement_zero(); - test_assignement_one(); - test_assignement_frac(); - test_assignement_integer(); - - - // Test frac.eval() - mln_assertion(0.5 == op2b.eval()); - mln_assertion(op2a == op2b); - cout << "frac.eval() : ok" << endl; - - // Test - frac - mln_assertion(resUminus == (-op2b)); - cout << "- frac() : ok" << endl; - - // Test frac + frac - mln_assertion(resPlus == (op1b + op2b)); - mln_assertion(op1a == op1b); - mln_assertion(op2a == op2b); - cout << "frac + frac : ok" << endl; - - // Test frac - frac - mln_assertion(resMinus == (op1b - op2b)); - mln_assertion(op1a == op1b); - mln_assertion(op2a == op2b); - cout << "frac - frac : ok" << endl; - - // Test frac * frac - mln_assertion(resTimes == (op1b * op2b)); - mln_assertion(op1a == op1b); - mln_assertion(op2a == op2b); - cout << "frac * frac : ok" << endl; - - // Test frac / frac - mln_assertion(resDiv == (op1b / op2b)); - mln_assertion(op1a == op1b); - mln_assertion(op2a == op2b); - cout << "frac / frac : ok" << endl; - - // Test frac + scalar - mln_assertion(resPlusScalar == (op1b + op3b)); - mln_assertion(op1a == op1b); - mln_assertion(op3a == op3b); - cout << "frac + scalar : ok" << endl; - - // Test frac - scalar - mln_assertion(resMinusScalar == (op1b - op3b)); - mln_assertion(op1a == op1b); - mln_assertion(op3a == op3b); - cout << "frac - scalar : ok" << endl; - - // Test frac * scalar - mln_assertion(resTimesScalar == (op1b * op4b)); - mln_assertion(op1a == op1b); - mln_assertion(op4a == op4b); - cout << "frac * scalar : ok" << endl; - - // Test frac / scalar - mln_assertion(resDivScalar == (op1b / op4b)); - mln_assertion(op1a == op1b); - mln_assertion(op4a == op4b); - cout << "frac / scalar : ok" << endl; - - return 0; -} - -#include <mln/core/image/image2d.hh> -#include <mln/value/int_u8.hh> -#include <mln/io/pgm/load.hh> -#include <mln/data/compute.hh> -#include <mln/accu/math/sum.hh> -#include <mln/accu/stat/mean.hh> -#include <mln/accu/stat/variance.hh> - - -int main2() -{ - using namespace mln; - using namespace std; - using namespace mln::algebra; - - image2d<value::int_u8> input; - io::pgm::load(input, "/usr/local/share/olena/images/small.pgm"); - - /* - accu::math::sum< value::int_u8 > sum0; - accu::math::sum< value::int_u8, frac<long> > sum1; - - cout << data::compute(sum0, input) << endl; - cout << data::compute(sum1, input) << endl; - - accu::stat::mean< value::int_u8 > mean0; - accu::stat::mean< value::int_u8, frac<long> > mean1; - */ - // cout << data::compute(mean0, input) << endl; - //cout << data::compute(mean1, input) << endl; - - //frac<long> count = data::compute(accu::math::count< frac<long> >(), input); - //frac<long> variance = data::compute(accu::stat::variance< frac<long>, frac<long>, frac<long> >(), input); - - - return 0; -} diff --git a/trunk/milena/sandbox/green/Fraction/main.cc b/trunk/milena/sandbox/green/Fraction/main.cc deleted file mode 100644 index 0f6373c..0000000 --- a/trunk/milena/sandbox/green/Fraction/main.cc +++ /dev/null @@ -1,112 +0,0 @@ -#include <iostream> -#include "frac.hh" - -#include <mln/core/image/image2d.hh> -#include <mln/value/int_u8.hh> -#include <mln/io/pgm/load.hh> -#include <mln/accu/stat/variance.hh> -#include <mln/data/compute.hh> - -int main2() -{ - using namespace std; - using namespace mln; - using namespace mln::algebra; - - trace::quiet = true; - - // Testing instanciation - frac<int> f0; - frac<int> op1a(5,10); - frac<int> op1b(op1a); - frac<int> op2a(1,2); - frac<int> op2b = op2a; - int op3a = 1; - int op3b = 1; - int op4a = 2; - int op4b = 2; - frac<int> resPlus(literal::one); - frac<int> resMinus(literal::zero); - frac<int> resTimes(1,4); - frac<int> resDiv(literal::one); - frac<int> resPlusScalar(3,2); - frac<int> resMinusScalar(-1,2); - frac<int> resTimesScalar(literal::one); - frac<int> resDivScalar(1,4); - frac<int> resUminus(-1,4); - - // Test frac.eval() - mln_assertion(0.5 == op2b.eval()); - mln_assertion(op2a == op2b); - cout << "frac.eval() : ok" << endl; - - // Test - frac - mln_assertion(resUminus == (-op2b)); - cout << "- frac() : ok" << endl; - - // Test frac + frac - mln_assertion(resPlus == (op1b + op2b)); - mln_assertion(op1a == op1b); - mln_assertion(op2a == op2b); - cout << "frac + frac : ok" << endl; - - // Test frac - frac - mln_assertion(resMinus == (op1b - op2b)); - mln_assertion(op1a == op1b); - mln_assertion(op2a == op2b); - cout << "frac - frac : ok" << endl; - - // Test frac * frac - mln_assertion(resTimes == (op1b * op2b)); - mln_assertion(op1a == op1b); - mln_assertion(op2a == op2b); - cout << "frac * frac : ok" << endl; - - // Test frac / frac - mln_assertion(resDiv == (op1b / op2b)); - mln_assertion(op1a == op1b); - mln_assertion(op2a == op2b); - cout << "frac / frac : ok" << endl; - - // Test frac + scalar - mln_assertion(resPlusScalar == (op1b + op3b)); - mln_assertion(op1a == op1b); - mln_assertion(op3a == op3b); - cout << "frac + scalar : ok" << endl; - - // Test frac - scalar - mln_assertion(resMinusScalar == (op1b - op3b)); - mln_assertion(op1a == op1b); - mln_assertion(op3a == op3b); - cout << "frac - scalar : ok" << endl; - - // Test frac * scalar - mln_assertion(resTimesScalar == (op1b * op4b)); - mln_assertion(op1a == op1b); - mln_assertion(op4a == op4b); - cout << "frac * scalar : ok" << endl; - - // Test frac / scalar - mln_assertion(resDivScalar == (op1b / op4b)); - mln_assertion(op1a == op1b); - mln_assertion(op4a == op4b); - cout << "frac / scalar : ok" << endl; - - return 0; -} - -int main() -{ - using namespace mln; - using namespace std; - using namespace mln::algebra; - - image2d<value::int_u8> input; - io::pgm::load(input, "/usr/local/share/olena/images/small.pgm"); - - - frac<long> variance = data::compute(accu::stat::variance< frac<long>, frac<long>, frac<long> >(), input); - - - return 0; -} diff --git a/trunk/milena/sandbox/green/Fraction/Makefile.am b/trunk/milena/sandbox/green/fraction/Makefile.am similarity index 100% rename from trunk/milena/sandbox/green/Fraction/Makefile.am rename to trunk/milena/sandbox/green/fraction/Makefile.am diff --git a/trunk/milena/sandbox/green/fraction/frac.cc b/trunk/milena/sandbox/green/fraction/frac.cc new file mode 100644 index 0000000..b8e8520 --- /dev/null +++ b/trunk/milena/sandbox/green/fraction/frac.cc @@ -0,0 +1,423 @@ +#include <iostream> +#include "frac.hh" + +// +// TEST INSTANTIATION +// +void test_instantiation_without_argument() +{ + const mln::algebra::frac<int> frac; + + std::cout << "frac<T> frac : ok" << std::endl; +} + +void test_instantiation_numerator_denominator() +{ + const mln::algebra::frac<int> frac(-2,5); + + std::cout << "frac<T> frac(n,d) : ok" << std::endl; +} + +void test_instantiation_frac() +{ + const mln::algebra::frac<int> ref(-2,5); + const mln::algebra::frac<int> frac = ref; + + mln_assertion(ref == frac); + + std::cout << "frac<T> frac = frac : ok" << std::endl; +} + +void test_instantiation_zero() +{ + const mln::algebra::frac<int> ref(0,1); + const mln::algebra::frac<int> frac = mln::literal::zero; + + mln_assertion(ref == frac); + std::cout << "frac<T> frac = zero : ok" << std::endl; +} + +void test_instantiation_one() +{ + const mln::algebra::frac<int> ref(1,1); + const mln::algebra::frac<int> frac = mln::literal::one; + + mln_assertion(ref == frac); + std::cout << "frac<T> frac = one : ok" << std::endl; +} + +void test_instantiation_integer() +{ + const mln::algebra::frac<int> ref(5,1); + const mln::algebra::frac<int> frac = 5; + + mln_assertion(ref == frac); + std::cout << "frac<T> frac = integer : ok" << std::endl; +} + + +// +// TEST FRAC_BASE_ +// +void test_frac_base_accessor() +{ + const int ref1 = 1; + const int ref2 = 2; + const mln::math::sign_t ref3 = mln::math::negative; + const float ref4 = -0.5; + const mln::algebra::frac<int> frac(-1, 2); + + mln_assertion(ref1 == frac.numerator()); + mln_assertion(ref2 == frac.denominator()); + mln_assertion(ref3 == frac.sign()); + mln_assertion(ref4 == frac.eval()); + + std::cout << "frac.numerator() : ok" << std::endl; + std::cout << "frac.denominator() : ok" << std::endl; + std::cout << "frac.sign() : ok" << std::endl; + std::cout << "frac.eval() : ok" << std::endl; +} + +void test_frac_base_manipulator() +{ + const int ref1 = 5; + const int ref2 = 3; + const mln::algebra::frac<int> frac(-25,15); + + mln_assertion(ref1 == frac.numerator()); + mln_assertion(ref2 == frac.denominator()); + std::cout << "frac.indicible() : ok" << std::endl; +} + + +// +// TEST ASSIGNEMENT +// +void test_assignement_zero() +{ + const mln::algebra::frac<int> ref(0,1); + mln::algebra::frac<int> frac; + + frac = mln::literal::zero; + mln_assertion(ref == frac); + + std::cout << "frac = zero : ok" << std::endl; +} + +void test_assignement_one() +{ + const mln::algebra::frac<int> ref(1,1); + mln::algebra::frac<int> frac; + + frac = mln::literal::one; + mln_assertion(ref == frac); + + std::cout << "frac = one : ok" << std::endl; +} + +void test_assignement_frac() +{ + const mln::algebra::frac<int> ref(-2,3); + mln::algebra::frac<int> frac; + + frac = ref; + mln_assertion(ref == frac); + + std::cout << "frac = frac : ok" << std::endl; +} + +void test_assignement_integer() +{ + const mln::algebra::frac<int> ref(-5,1); + mln::algebra::frac<int> frac; + + frac = -5; + mln_assertion(ref == frac); + + std::cout << "frac = integer : ok" << std::endl; +} + + +// +// TEST COMPARAISON +// +void test_comparaison_equal_to() +{ + const mln::algebra::frac<int> op1(4,6); + const mln::algebra::frac<int> op2(6,4); + + mln_assertion(op1 == op1); + mln_assertion(!(op1 == op2)); + + std::cout << "frac == frac : ok" << std::endl; +} + +void test_comparaison_not_equal_to() +{ + const mln::algebra::frac<int> op1(4,6); + const mln::algebra::frac<int> op2(6,4); + + mln_assertion(!(op1 != op1)); + mln_assertion(op1 != op2); + + std::cout << "frac != frac : ok" << std::endl; +} + +void test_comparaison_less_equal_than() +{ + const mln::algebra::frac<int> op1(1,5); + const mln::algebra::frac<int> op2(2,5); + + mln_assertion(op1 <= op2); + mln_assertion(op2 <= op2); + mln_assertion(!(op2 <= op1)); + + std::cout << "frac <= frac : ok" << std::endl; +} + +void test_comparaison_less_than() +{ + const mln::algebra::frac<int> op1(1,5); + const mln::algebra::frac<int> op2(2,5); + + mln_assertion(op1 < op2); + mln_assertion(!(op2 < op2)); + mln_assertion(!(op2 < op1)); + + std::cout << "frac < frac : ok" << std::endl; +} + +void test_comparaison_greater_than() +{ + const mln::algebra::frac<int> op1(2,5); + const mln::algebra::frac<int> op2(1,5); + + mln_assertion(op1 > op2); + mln_assertion(!(op2 > op2)); + mln_assertion(!(op2 > op1)); + + std::cout << "frac > frac : ok" << std::endl; +} + +void test_comparaison_greater_equal_than() +{ + const mln::algebra::frac<int> op1(2,5); + const mln::algebra::frac<int> op2(1,5); + + mln_assertion(op1 >= op2); + mln_assertion(op2 >= op2); + mln_assertion(!(op2 >= op1)); + + std::cout << "frac >= frac : ok" << std::endl; +} + +// +// TEST FRAC ARITHMETIC +// +void test_frac_arithmetic_uminus() +{ + const mln::algebra::frac<int> ref(-1,4); + const mln::algebra::frac<int> op1(1,4); + + mln_assertion(ref == (-op1)); + std::cout << "-frac : ok" << std::endl; +} + +void test_frac_arithmetic_plus() +{ + const mln::algebra::frac<int> ref1(6,4); + const mln::algebra::frac<int> ref2(10,4); + const mln::algebra::frac<int> ref3(14,4); + const mln::algebra::frac<int> op1(2,4); + const mln::algebra::frac<int> op2(1,1); + mln::algebra::frac<int> res = op1; + + res += op2; + + mln_assertion(ref1 == (op1 + op2)); + mln_assertion(ref1 == res); + mln_assertion(ref1 == (res++)); + mln_assertion(ref2 == res); + mln_assertion(ref3 == (++res)); + mln_assertion(ref3 == res); + + std::cout << "frac + frac : ok" << std::endl; + std::cout << "frac += frac : ok" << std::endl; + std::cout << "frac++ : ok" << std::endl; + std::cout << "++frac : ok" << std::endl; +} + +void test_frac_arithmetic_minus() +{ + const mln::algebra::frac<int> ref1(-1,4); + const mln::algebra::frac<int> ref2(-5,4); + const mln::algebra::frac<int> ref3(-9,4); + const mln::algebra::frac<int> op1(3,4); + const mln::algebra::frac<int> op2(1,1); + mln::algebra::frac<int> res = op1; + + res -= op2; + + mln_assertion(ref1 == (op1 - op2)); + mln_assertion(ref1 == res); + mln_assertion(ref1 == (res--)); + mln_assertion(ref2 == res); + mln_assertion(ref3 == (--res)); + mln_assertion(ref3 == res); + + std::cout << "frac - frac : ok" << std::endl; + std::cout << "frac -= frac : ok" << std::endl; + std::cout << "frac-- : ok" << std::endl; + std::cout << "--frac : ok" << std::endl; +} + +void test_frac_arithmetic_times() +{ + const mln::algebra::frac<int> ref(3,8); + const mln::algebra::frac<int> op1(2,4); + const mln::algebra::frac<int> op2(3,4); + mln::algebra::frac<int> res = op1; + + res *= op2; + + mln_assertion(ref == (op1 * op2)); + mln_assertion(ref == res); + + std::cout << "frac * frac : ok" << std::endl; + std::cout << "frac *= frac : ok" << std::endl; +} + +void test_frac_arithmetic_div() +{ + const mln::algebra::frac<int> ref(2,3); + const mln::algebra::frac<int> op1(2,4); + const mln::algebra::frac<int> op2(3,4); + mln::algebra::frac<int> res = op1; + + res /= op2; + + mln_assertion(ref == (op1 / op2)); + mln_assertion(ref == res); + + std::cout << "frac / frac : ok" << std::endl; + std::cout << "frac /= frac : ok" << std::endl; +} + +// +// TEST SCALAR ARITHMETIC +// + +void test_scalar_arithmetic_plus() +{ + const mln::algebra::frac<int> ref(6,4); + const mln::algebra::frac<int> op1(2,4); + const int op2 = 1; + mln::algebra::frac<int> res = op1; + + res += op2; + + mln_assertion(ref == (op1 + op2)); + mln_assertion(ref == res); + + std::cout << "frac + integer : ok" << std::endl; + std::cout << "frac += integer : ok" << std::endl; +} + +void test_scalar_arithmetic_minus() +{ + const mln::algebra::frac<int> ref1(-1,4); + const mln::algebra::frac<int> op1(3,4); + const int op2 = 1; + mln::algebra::frac<int> res = op1; + + res -= op2; + + mln_assertion(ref1 == (op1 - op2)); + mln_assertion(ref1 == res); + + std::cout << "frac - integer : ok" << std::endl; + std::cout << "frac -= integer : ok" << std::endl; +} + +void test_scalar_arithmetic_times() +{ + const mln::algebra::frac<int> ref(6,4); + const mln::algebra::frac<int> op1(2,4); + const int op2 = 3; + mln::algebra::frac<int> res = op1; + + res *= op2; + + mln_assertion(ref == (op1 * op2)); + mln_assertion(ref == res); + + std::cout << "frac * integer : ok" << std::endl; + std::cout << "frac *= integer : ok" << std::endl; +} + +void test_scalar_arithmetic_div() +{ + const mln::algebra::frac<int> ref(2,12); + const mln::algebra::frac<int> op1(2,4); + const int op2 = 3; + mln::algebra::frac<int> res = op1; + + res /= op2; + + mln_assertion(ref == (op1 / op2)); + mln_assertion(ref == res); + + std::cout << "frac / integer : ok" << std::endl; + std::cout << "frac /= integer : ok" << std::endl; +} + + +int main2() +{ + // TEST INSTANTIATION + std::cout << std::endl << "TEST INSTANTIATION" << std::endl; + test_instantiation_without_argument(); + test_instantiation_numerator_denominator(); + test_instantiation_frac(); + test_instantiation_zero(); + test_instantiation_one(); + test_instantiation_integer(); + + // TEST FRAC_BASE + std::cout << std::endl << "TEST FRAC_BASE" << std::endl; + test_frac_base_accessor(); + test_frac_base_manipulator(); + + // TEST ASSIGNEMENT + std::cout << std::endl << "TEST ASSIGNEMENT" << std::endl; + test_assignement_zero(); + test_assignement_one(); + test_assignement_frac(); + test_assignement_integer(); + + // TEST COMPARAISON + std::cout << std::endl << "TEST COMPARAISON" << std::endl; + test_comparaison_equal_to(); + test_comparaison_not_equal_to(); + test_comparaison_less_equal_than(); + test_comparaison_less_than(); + test_comparaison_greater_equal_than(); + test_comparaison_greater_than(); + + // TEST FRAC ARITHMETIC + std::cout << std::endl << "TEST FRAC ARITHMETIC" << std::endl; + test_frac_arithmetic_uminus(); + test_frac_arithmetic_plus(); + test_frac_arithmetic_minus(); + test_frac_arithmetic_times(); + test_frac_arithmetic_div(); + + // TEST SCALAR ARITHMETIC + std::cout << std::endl << "TEST SCALAR ARITHMETIC" << std::endl; + test_scalar_arithmetic_plus(); + test_scalar_arithmetic_minus(); + test_scalar_arithmetic_times(); + test_scalar_arithmetic_div(); + + return 0; +} diff --git a/trunk/milena/sandbox/green/Fraction/frac.hh b/trunk/milena/sandbox/green/fraction/frac.hh similarity index 50% rename from trunk/milena/sandbox/green/Fraction/frac.hh rename to trunk/milena/sandbox/green/fraction/frac.hh index b8ec226..d9f8c99 100644 --- a/trunk/milena/sandbox/green/Fraction/frac.hh +++ b/trunk/milena/sandbox/green/fraction/frac.hh @@ -1,4 +1,4 @@ -// Copyright (C) 2006, 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE) +// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) // // This file is part of Olena. // @@ -26,7 +26,6 @@ #ifndef MLN_ALGEBRA_FRAC_HH # define MLN_ALGEBRA_FRAC_HH -// includes #include <iostream> #include <mln/core/concept/object.hh> @@ -36,9 +35,8 @@ #include <mln/value/scalar.hh> #include <mln/debug/format.hh> -#include <mln/math/min.hh> -#include <mln/math/max.hh> #include <mln/math/abs.hh> +#include <mln/math/sign.hh> #include <mln/literal/zero.hh> #include <mln/literal/one.hh> @@ -46,6 +44,11 @@ #include <mln/trace/entering.hh> #include <mln/trace/exiting.hh> +#include <mln/value/int_u8.hh> + +#include "sign_prod.hh" +#include "gcd.hh" + namespace mln { namespace algebra @@ -62,6 +65,14 @@ namespace mln struct one_t; } + // FIXME : frac += scalar ... doesn't compile ... + // FIXME : Comment s'assurer que le type T ne contient que des non flottants + // de type entier ... ??? + // FIXME : Comment trouver la fraction equivalente à un flottant + // FIXME : Comment enregistrer correctement les traits ?? + // FIXME : Comment intégrer frac pour qu'il fonctionne avec la variance ?? + // FIXME : Code experimental + namespace trait { template<typename T> @@ -92,15 +103,37 @@ namespace mln class frac_base_ : public Object< frac<T> > { private: - T numerator_; - T denominator_; + T numerator_; + T denominator_; + math::sign_t sign_; public: - const T& numerator(const T& numerator) {this->numerator_ = numerator; return numerator;} - const T& denominator(const T& denominator) {this->denominator_ = denominator; return denominator;} + const T& numerator() const {return numerator_;} + const T& denominator() const {return denominator_;} + const math::sign_t& sign() const {return sign_;} - const T& numerator() const {return numerator_;} - const T& denominator() const {return denominator_;} + float eval() const + { + T sign = math::sign_to_coeff<T>(sign_); + float numerator = static_cast<float>(numerator_); + float denominator = static_cast<float>(denominator_); + float result = sign * numerator/denominator; + + return result; + } + + void irreducible(const T& numerator, const T& denominator) + { + trace::entering("mln::algebra::internal::frac_base_::irreducible"); + + T divisor = math::gcd(numerator, denominator); + this->sign_ = math::sign_prod<T>(numerator, denominator); + this->numerator_ = math::abs(numerator) / divisor; + this->denominator_ = math::abs(denominator) / divisor; + + trace::exiting("mln::algebra::internal::frac_base_::irreducible"); + } + }; } // end of namespace mln::algebra::internal @@ -109,23 +142,21 @@ namespace mln { typedef internal::frac_base_<T> super_; - private: - const T gcd_(const T& a, const T& b) const; - public: // Constructor without argument ==> very dangerous one in this context frac(); // Constructor to convert scalar in fraction (transtyping) + template <typename S> + frac(const value::scalar_<S>& scalar); frac(const T& scalar); + //frac(const value::int_u8& scalar); // Constructor with literal zero frac(const literal::zero_t& zero); - frac& operator=(const literal::zero_t& zero); // Constructor with literal one frac(const literal::one_t& one); - frac& operator=(const literal::one_t& one); // Constructor setting the internal values frac(const T& numerator_, const T& denominator_); @@ -138,19 +169,13 @@ namespace mln frac(const frac<F>& rhs); // Assignement operator + frac& operator=(const literal::zero_t& zero); + frac& operator=(const literal::one_t& one); frac& operator=(const frac<T>& rhs); // Second assignement operator template<typename F> frac& operator=(const frac<F>& rhs); - - // Greatest common divisor (Euclidian Algorithm) - const T gcd(const T& a, const T& b) const; - - const frac<T>& irreducible(); - - // Return the quotient - float eval() const; }; } // end of namespace mln::algebra @@ -165,26 +190,25 @@ namespace mln }; - // - frac - template <typename T> - struct set_precise_unary_<op::uminus, algebra::frac<T> > - { - typedef mln_trait_op_uminus(T) V; - typedef algebra::frac<V> ret; - }; - + // + // SCALAR ARITHMETIC + // + // frac + s template <typename T, typename S> - struct set_precise_binary_<op::plus, algebra::frac<T>, mln::value::scalar_<S> > + struct set_precise_binary_<op::plus, + algebra::frac<T>, + mln::value::scalar_<S> > { typedef mln_trait_op_plus(T, S) V; typedef algebra::frac<V> ret; }; - // frac - s template <typename T, typename S> - struct set_precise_binary_<op::minus, algebra::frac<T>, mln::value::scalar_<S> > + struct set_precise_binary_<op::minus, + algebra::frac<T>, + mln::value::scalar_<S> > { typedef mln_trait_op_minus(T, S) V; typedef algebra::frac<V> ret; @@ -193,7 +217,9 @@ namespace mln // frac * s template <typename T, typename S> - struct set_precise_binary_<op::times, algebra::frac<T>, mln::value::scalar_<S> > + struct set_precise_binary_<op::times, + algebra::frac<T>, + mln::value::scalar_<S> > { typedef mln_trait_op_times(T, S) V; typedef algebra::frac<V> ret; @@ -202,12 +228,18 @@ namespace mln // frac / s template <typename T, typename S> - struct set_precise_binary_<op::div, algebra::frac<T>, mln::value::scalar_<S> > + struct set_precise_binary_<op::div, + algebra::frac<T>, + mln::value::scalar_<S> > { typedef mln_trait_op_div(T, S) V; typedef algebra::frac<V> ret; }; + + // + // FRAC ARITHMETIC + // // frac + frac template <typename T, typename F> @@ -231,7 +263,6 @@ namespace mln template <typename T, typename F> struct set_precise_binary_<op::times, algebra::frac<T>, algebra::frac<F> > { - //typedef mln_sum_poduct(T, F) ret; typedef mln_trait_op_times(T, F) V; typedef algebra::frac<V> ret; }; @@ -246,15 +277,49 @@ namespace mln }; + // + // COMPARAISON + // + + // frac == frac + template <typename T, typename F> + struct set_precise_binary_<op::eq, algebra::frac<T>, algebra::frac<F> > + { + typedef bool ret; + }; + + // frac < frac + template <typename T, typename F> + struct set_precise_binary_<op::less, algebra::frac<T>, algebra::frac<F> > + { + typedef bool ret; + }; + }// end of namespace mln::trait namespace algebra { + // + // COMPARAISON + // + + template <typename T, typename F> + math::sign_t compare(const frac<T>& lhs, const frac<F>& rhs); + // frac == frac template <typename T, typename F> bool operator==(const frac<T>& lhs, const frac<F>& rhs); + // frac < frac + template <typename T, typename F> + bool + operator<(const frac<T>& lhs, const frac<F>& rhs); + + // + // INPUT/OUTPUT STREAM + // + // << template <typename T> std::ostream& @@ -265,10 +330,9 @@ namespace mln std::istream& operator<<(std::istream& istr, const frac<T>& rhs); - // - frac - template <typename T> - frac<mln_trait_op_uminus(T)> - operator-(const frac<T>& rhs); + // + // SCALAR ARITHMETIC + // // frac + s template <typename T, typename S> @@ -290,6 +354,10 @@ namespace mln frac<mln_trait_op_div(T,S)> operator/(const frac<T>& lhs, const mln::value::scalar_<S>& s); + // + // FRAC ARITHMETIC + // + // frac + frac template <typename T, typename F> frac<mln_trait_op_plus(T,F)> @@ -317,260 +385,226 @@ namespace mln namespace algebra { + + // + // INSTANTIATION + // template <typename T> inline frac<T>::frac() : super_() { - trace::entering("mln::algebra::frac<T>::frac()"); + trace::entering("mln::algebra::frac<T>::frac"); - this->numerator(0); - this->denominator(1); + this->irreducible(0, 1); - trace::exiting("mln::algebra::frac<T>::frac()"); + trace::exiting("mln::algebra::frac<T>::frac"); } template <typename T> frac<T>::frac(const T& scalar) : super_() { - trace::entering("mln::algebra::frac<T>::frac(const S& scalar)"); + trace::entering("mln::algebra::frac<T>::frac"); - this->numerator(scalar); - this->denominator(1); + this->irreducible(scalar, 1); - trace::exiting("mln::algebra::frac<T>::frac(const S& scalar)"); + trace::exiting("mln::algebra::frac<T>::frac"); } - + template <typename T> - inline - frac<T>::frac(const T& numerator, const T& denominator) : super_() + template <typename S> + frac<T>::frac(const value::scalar_<S>& scalar) : super_() { - trace::entering("mln::algebra::frac<T>::frac(const T& numerator, const T& denominator)"); - - this->numerator(numerator); - this->denominator(denominator); - - irreducible(); + trace::entering("mln::algebra::frac<T>::frac"); + + this->irreducible(scalar, 1); - trace::exiting("mln::algebra::frac<T>::frac(const T& numerator, const T& denominator)"); + trace::exiting("mln::algebra::frac<T>::frac"); } - + template <typename T> inline - frac<T>::frac(const literal::zero_t& zero) : super_() + frac<T>::frac(const T& numerator, const T& denominator) : super_() { - trace::entering("mln::algebra::frac<T>::frac(const literal::zero_t& zero)"); + trace::entering("mln::algebra::frac<T>::frac"); - this->numerator(zero); - this->denominator(1); + this->irreducible(numerator, denominator); - trace::exiting("mln::algebra::frac<T>::frac(const literal::zero_t& zero)"); + trace::exiting("mln::algebra::frac<T>::frac"); } template <typename T> inline - frac<T>& frac<T>::operator=(const literal::zero_t& zero) + frac<T>::frac(const literal::zero_t& zero) : super_() { - trace::entering("frac<T>& mln::algebra::frac<T>::operator=(const literal::zero_t& zero)"); + trace::entering("mln::algebra::frac<T>::frac"); - this->numerator(zero); - this->denominator(1); + this->irreducible(zero, 1); - trace::exiting("frac<T>& mln::algebra::frac<T>::operator=(const literal::zero_t& zero)"); - return *this; + trace::exiting("mln::algebra::frac<T>::frac"); } - - template <typename T> inline frac<T>::frac(const literal::one_t& one) : super_() { - trace::entering("frac<T>::frac(const literal::one_t& one)"); + trace::entering("frac<T>::frac"); - this->numerator(one); - this->denominator(1); + this->irreducible(one, 1); - trace::exiting("frac<T>::frac(const literal::one_t& one)"); + trace::exiting("frac<T>::frac"); } template <typename T> inline - frac<T>& frac<T>::operator=(const literal::one_t& one) + frac<T>::frac(const frac<T>& rhs) : super_() { - trace::entering("frac<T>& mln::algebra::frac<T>::operator=(const literal::one_t& one)"); - - this->numerator(one); - this->denominator(1); + trace::entering("mln::algebra::frac<T>::frac"); + + T rhs_sign = math::sign_to_coeff<T>(rhs.sign()); + + this->irreducible(rhs_sign*rhs.numerator(), rhs.denominator()); - trace::exiting("frac<T>& mln::algebra::frac<T>::operator=(const literal::one_t& one)"); - return *this; + trace::exiting("mln::algebra::frac<T>::frac"); } template <typename T> + template <typename F> inline - frac<T>::frac(const frac<T>& rhs) : super_() + frac<T>::frac(const frac<F>& rhs) : super_() { - trace::entering("mln::algebra::frac<T>::frac(const frac<T>& rhs)"); + trace::entering("mln::algebra::frac<T>::frac"); + mlc_converts_to(F, T)::check(); - this->numerator(rhs.numerator()); - this->denominator(rhs.denominator()); + T rhs_sign = math::sign_to_coeff<T>(rhs.sign()); + T rhs_numerator = rhs_sign*static_cast<T>(rhs.numerator()); + T rhs_denominator = static_cast<T>(rhs.denominator()); - irreducible(); + this->irreducible(rhs_numerator, rhs_denominator); - trace::exiting("mln::algebra::frac<T>::frac(const frac<T>& rhs)"); + trace::exiting("mln::algebra::frac<T>::frac"); } - + + // + // ASSIGNEMENT + // + template <typename T> inline frac<T>& frac<T>::operator=(const frac<T>& rhs) { - trace::entering("frac<T>& mln::algebra::frac<T>::operator=(const frac<T>& rhs)"); - - numerator(rhs.numerator()); - denominator(rhs.denominator()); + trace::entering("mln::algebra::frac<T>::operator="); + + T rhs_sign = math::sign_to_coeff<T>(rhs.sign()); - irreducible(); - trace::exiting("frac<T>& mln::algebra::frac<T>::operator=(const frac<T>& rhs)"); + this->irreducible(rhs_sign*rhs.numerator(), rhs.denominator()); + + trace::exiting("mln::algebra::frac<T>::operator="); return *this; } template <typename T> - template <typename F> inline - frac<T>::frac(const frac<F>& rhs) : super_() + frac<T>& frac<T>::operator=(const literal::one_t& one) { - trace::entering("mln::algebra::frac<T>::frac(const frac<F>& rhs)"); - mlc_converts_to(F, T)::check(); - - numerator(static_cast<T>(rhs.numerator())); - denominator(static_cast<T>(rhs.denominator())); + trace::entering("mln::algebra::frac<T>::operator="); - irreducible(); + this->irreducible(one, 1); - trace::exiting("mln::algebra::frac<T>::frac(const frac<F>& rhs)"); + trace::exiting("mln::algebra::frac<T>::operator="); + return *this; } template <typename T> - template <typename F> inline - frac<T>& frac<T>::operator=(const frac<F>& rhs) + frac<T>& frac<T>::operator=(const literal::zero_t& zero) { - trace::entering("frac<T>& mln::algebra::frac<T>::operator=(const frac<F>& rhs)"); - mlc_converts_to(F, T)::check(); + trace::entering("mln::algebra::frac<T>::operator="); - numerator(static_cast<T>(rhs.numerator())); - denominator(static_cast<T>(rhs.denominator())); - - irreducible(); - trace::exiting("frac<T>& mln::algebra::frac<T>::operator=(const frac<F>& rhs)"); + this->irreducible(zero, 1); + trace::exiting("mln::algebra::frac<T>::operator="); return *this; } - // Greatest common divisor (Euclidian algorithm) template <typename T> + template <typename F> inline - const T frac<T>::gcd(const T& a, const T& b) const + frac<T>& frac<T>::operator=(const frac<F>& rhs) { - trace::entering("const T mln::algebra::frac<T>::gcd(const T& a, const T& b)"); + trace::entering("mln::algebra::frac<T>::operator="); + mlc_converts_to(F, T)::check(); - T result; - T abs_a = math::abs(a); - T abs_b = math::abs(b); + T rhs_sign = math::sign_to_coeff<T>(rhs.sign()); + T rhs_numerator = rhs_sign*static_cast<T>(rhs.numerator()); + T rhs_denominator = static_cast<T>(rhs.denominator()); - if ((0 == abs_a) || (0 == abs_b)) - result = 1; - else - result = gcd_(math::max(abs_a, abs_b), math::min(abs_a, abs_b)); + this->irreducible(rhs_numerator, rhs_denominator); + + trace::exiting("mln::algebra::frac<T>::operator="); - trace::exiting("const T mln::algebra::frac<T>::gcd(const T& a, const T& b)"); - return result; + return *this; } - template <typename T> + // + // COMPARAISON + // + template <typename T, typename F> inline - const T frac<T>::gcd_(const T& a, const T& b) const + math::sign_t compare(const frac<T>& lhs, const frac<F>& rhs) { - trace::entering("const T mln::algebra::frac<T>::cgd_(const T& a, const T& b)"); - mln_assertion(a > 0); - mln_assertion(b > 0); - mln_assertion(a >= b); - - T rest = a%b; + trace::entering("mln::algebra::compare"); + mlc_converts_to(F, T)::check(); - if (0 == rest) - rest = b; - else - rest = gcd(b, rest); + T rhs_sign = math::sign_to_coeff<T>(rhs.sign()); + T lhs_sign = math::sign_to_coeff<T>(lhs.sign()); + T side1 = rhs_sign*lhs.numerator()*rhs.denominator(); + T side2 = lhs_sign*rhs.numerator()*lhs.denominator(); + math::sign_t result = math::sign(side1 - side2); - trace::exiting("const T mln::algebra::frac<T>::cgd_(const T& a, const T& b)"); - return rest; + trace::exiting("mln::algebra::compare"); + return result; } - template <typename T> + template <typename T, typename F> inline - const frac<T>& frac<T>::irreducible() + bool operator==(const frac<T>& lhs, const frac<F>& rhs) { - trace::entering("frac<T>& mln::algebra::frac<T>::irreducible()"); + trace::entering("mln::algebra::operator=="); - const T& numerator = this->numerator(); - const T& denominator = this->denominator(); - T divisor = this->gcd(numerator, denominator); + bool result = is_null(compare(lhs, rhs)); - this->numerator(numerator/divisor); - this->denominator(denominator/divisor); - - trace::exiting("frac<T>& mln::algebra::frac<T>::irreducible()"); - return *this; + trace::exiting("mln::algebra::operator=="); + return result; } - - template <typename T> - inline - float frac<T>::eval() const - { - trace::entering("frac<T>& mln::algebra::frac<T>::eval()"); - const T& numerator = super_::numerator(); - const T& denominator = super_::denominator(); - - float float_num = static_cast<float>(numerator); - float float_denom = static_cast<float>(denominator); - float result = float_num / float_denom; - - trace::exiting("frac<T>& mln::algebra::frac<T>::eval()"); - return result ; - } - template <typename T, typename F> inline - bool operator==(const frac<T>& lhs, const frac<F>& rhs) + bool operator<(const frac<T>& lhs, const frac<F>& rhs) { - trace::entering("bool mln::algebra::operator==(const frac<T>& lhs, const frac<F>& rhs)"); + trace::entering("mln::algebra::operator<"); - frac<T> lhsi(lhs); - frac<T> rhsi(rhs); + bool result = is_negative(compare(lhs, rhs)); - lhsi.irreducible(); - rhsi.irreducible(); + trace::exiting("mln::algebra::operator<"); + return result; + } - bool same_numerator = lhsi.numerator() == rhsi.numerator(); - bool same_denominator = rhsi.denominator() == rhsi.denominator(); - bool result = same_numerator && same_denominator; + // + // INPUT/OUTPUT STREAM + // - trace::exiting("bool mln::algebra::operator==(const frac<T>& lhs, const frac<F>& rhs)"); - return result; - } - template <typename T> std::ostream& operator<<(std::ostream& ostr, const frac<T>& rhs) { - trace::entering("std::ostream& mln::algebra::operator<<(std::ostream& ostr, const frac<T>& rhs)"); + trace::entering("mln::algebra::operator<<"); - ostr << '(' << debug::format(rhs.numerator()) << '/' << debug::format(rhs.denominator()) << ')'; + ostr << (math::is_negative(rhs.sign())? '-' : '+'); + ostr << '(' << debug::format(rhs.numerator()); + ostr << '/' << debug::format(rhs.denominator()) << ')'; - trace::exiting("std::ostream& mln::algebra::operator<<(std::ostream& ostr, const frac<T>& rhs)"); + trace::exiting("mln::algebra::operator<<"); return ostr; } @@ -578,48 +612,116 @@ namespace mln std::istream& operator>>(std::istream& istr, const frac<T>& rhs) { - trace::entering("std::istream& mln::algebra::operator>>(std::istream& istr, const frac<T>& rhs)"); + trace::entering("mln::algebra::operator>>"); istr >> rhs.numerator(); istr >> rhs.denominator(); - trace::exiting("std::istream& mln::algebra::operator>>(std::istream& istr, const frac<T>& rhs)"); + trace::exiting("mln::algebra::operator>>"); return istr; } - // - frac - template <typename T> - frac<mln_trait_op_uminus(T)> - operator-(const frac<T>& lhs) + // + // FRAC ARITHMETIC + // + + // frac + frac + template <typename T, typename F> + frac<mln_trait_op_plus(T,F)> + operator+(const frac<T>& lhs, const frac<F>& rhs) { - trace::entering("frac<mln_trait_op_uminus(T)> mln::algebra::operator-(const frac<T>& lhs)"); - typedef mln_trait_op_uminus(T) R; - frac<R> tmp = lhs; - - tmp.numerator(-lhs.numerator()); - tmp.denominator(lhs.denominator()); + trace::entering("mln::algebra::operator+"); + typedef mln_trait_op_plus(T,F) R; + + R rhs_sign = math::sign_to_coeff<R>(rhs.sign()); + R lhs_sign = math::sign_to_coeff<R>(lhs.sign()); + R side1 = lhs_sign*lhs.numerator()*rhs.denominator(); + R side2 = rhs_sign*rhs.numerator()*lhs.denominator(); + R numerator = side1 + side2; + R denominator = lhs.denominator()*rhs.denominator(); + frac<R> tmp(numerator, denominator); - tmp.irreducible(); + trace::exiting("mln::algebra::operator+"); + return tmp; + } + + // frac - frac + template <typename T, typename F> + frac<mln_trait_op_minus(T,F)> + operator-(const frac<T>& lhs, const frac<F>& rhs) + { + trace::entering("mln::algebra::operator-"); + typedef mln_trait_op_minus(T,F) R; + + R lhs_sign = math::sign_to_coeff<R>(lhs.sign()); + R rhs_sign = math::sign_to_coeff<R>(rhs.sign()); + R side1 = lhs_sign*lhs.numerator()*rhs.denominator(); + R side2 = rhs_sign*rhs.numerator()*lhs.denominator(); + R numerator = side1 - side2; + R denominator = lhs.denominator()*rhs.denominator(); + frac<R> tmp(numerator, denominator); - trace::exiting("frac<mln_trait_op_uminus(T)> mln::algebra::operator-(const frac<T>& lhs)"); + trace::exiting("mln::algebra::operator-"); return tmp; } + // frac * frac + template <typename T, typename F> + frac<mln_trait_op_times(T,F)> + operator*(const frac<T>& lhs, const frac<F>& rhs) + { + trace::entering("mln::algebra::operator*"); + typedef mln_trait_op_times(T,F) R; + + R lhs_sign = math::sign_to_coeff<R>(lhs.sign()); + R rhs_sign = math::sign_to_coeff<R>(rhs.sign()); + R numerator = lhs_sign*lhs.numerator()*rhs.numerator(); + R denominator = rhs_sign*lhs.denominator()*rhs.denominator(); + frac<R> tmp(numerator, denominator); + + trace::exiting("mln::algebra::operator*"); + return tmp; + } + + // frac / frac + template <typename T, typename F> + frac<mln_trait_op_div(T,F)> + operator/(const frac<T>& lhs, const frac<F>& rhs) + { + trace::entering("mln::algebra::operator/"); + typedef mln_trait_op_div(T,F) R; + + R lhs_sign = math::sign_to_coeff<R>(lhs.sign()); + R rhs_sign = math::sign_to_coeff<R>(rhs.sign()); + R numerator = lhs_sign*lhs.numerator()*rhs.denominator(); + R denominator = rhs_sign*lhs.denominator()*rhs.numerator(); + frac<R> tmp(numerator, denominator); + + trace::exiting("mln::algebra::operator/"); + return tmp; + } + + // + // SCALAR ARITHMETIC + // + // frac + s template <typename T, typename S> frac<mln_trait_op_plus(T,S)> operator+(const frac<T>& lhs, const value::scalar_<S>& s) { - trace::entering("frac<mln_trait_op_plus(T,S)> mln::algebra::operator+(const frac<T>& lhs, value::scalar<S>& s)"); + trace::entering("mln::algebra::operator+"); typedef mln_trait_op_plus(T,S) R; - frac<R> tmp = lhs; - - tmp.numerator(lhs.numerator() + s.to_equiv() * lhs.denominator()); - tmp.denominator(lhs.denominator()); - tmp.irreducible(); + R scalar = static_cast<R>(s.to_equiv()); + R lhs_sign = math::sign_to_coeff<R>(lhs.sign()); + R side1 = lhs_sign * lhs.numerator(); + R side2 = scalar * lhs.denominator(); + R numerator = side1 + side2; + R denominator = lhs.denominator(); + frac<R> tmp(numerator, denominator); - trace::exiting("frac<mln_trait_op_plus(T,S)> mln::algebra::operator+(const frac<T>& lhs, value::scalar<S>& s)"); + trace::exiting("mln::algebra::operator+"); return tmp; } @@ -628,16 +730,18 @@ namespace mln frac<mln_trait_op_minus(T,S)> operator-(const frac<T>& lhs, const value::scalar_<S>& s) { - trace::entering("frac<mln_trait_op_minus(T,S)> mln::algebra::operator-(const frac<T>& lhs, value::scalar<S>& s)"); + trace::entering("mln::algebra::operator-"); typedef mln_trait_op_minus(T,S) R; - frac<R> tmp = lhs; - - tmp.numerator(lhs.numerator() - s.to_equiv() * lhs.denominator()); - tmp.denominator(lhs.denominator()); - tmp.irreducible(); + R scalar = static_cast<R>(s.to_equiv()); + R lhs_sign = math::sign_to_coeff<R>(lhs.sign()); + R side1 = lhs_sign * lhs.numerator(); + R side2 = scalar * lhs.denominator(); + R numerator = side1 - side2; + R denominator = lhs.denominator(); + frac<R> tmp(numerator, denominator); - trace::exiting("frac<mln_trait_op_minus(T,S)> mln::algebra::operator-(const frac<T>& lhs, value::scalar<S>& s)"); + trace::exiting("mln::algebra::operator-"); return tmp; } @@ -646,22 +750,16 @@ namespace mln frac<mln_trait_op_times(T,S)> operator*(const frac<T>& lhs, const value::scalar_<S>& s) { - trace::entering("frac<mln_trait_op_times(T,S)> mln::algebra::operator*(const frac<T>& lhs, value::scalar<S>& s)"); + trace::entering("mln::algebra::operator*"); typedef mln_trait_op_times(T,S) R; - frac<R> tmp = lhs; - - std::cout << tmp << std::endl; - tmp.numerator(lhs.numerator() * s.to_equiv()); - tmp.denominator(lhs.denominator()); + R scalar = static_cast<R>(s.to_equiv()); + R lhs_sign = math::sign_to_coeff<R>(lhs.sign()); + R numerator = lhs_sign * lhs.numerator() * scalar; + R denominator = lhs.denominator(); + frac<R> tmp(numerator, denominator); - std::cout << tmp << std::endl; - - tmp.irreducible(); - - std::cout << tmp << std::endl; - - trace::exiting("frac<mln_trait_op_times(T,S)> mln::algebra::operator*(const frac<T>& lhs, value::scalar<S>& s)"); + trace::exiting("mln::algebra::operator*"); return tmp; } @@ -670,96 +768,19 @@ namespace mln frac<mln_trait_op_div(T,S)> operator/(const frac<T>& lhs, const value::scalar_<S>& s) { - trace::entering("frac<mln_trait_op_div(T,S)> mln::algebra::operator/(const frac<T>& lhs, value::scalar<S>& s)"); + trace::entering("mln::algebra::operator/"); typedef mln_trait_op_div(T,S) R; - frac<R> tmp = lhs; - - std::cout << tmp << std::endl; - - tmp.numerator(lhs.numerator()); - tmp.denominator(lhs.denominator() * s.to_equiv()); - - std::cout << tmp << std::endl; - - tmp.irreducible(); - std::cout << tmp << std::endl; + R scalar = static_cast<R>(s.to_equiv()); + R lhs_sign = math::sign_to_coeff<R>(lhs.sign()); + R numerator = lhs_sign * lhs.numerator(); + R denominator = lhs.denominator() * scalar; + frac<R> tmp(numerator, denominator); - trace::exiting("frac<mln_trait_op_div(T,S)> mln::algebra::operator/(const frac<T>& lhs, value::scalar<S>& s)"); + trace::exiting("mln::algebra::operator/"); return tmp; } - // frac + frac - template <typename T, typename F> - frac<mln_trait_op_plus(T,F)> - operator+(const frac<T>& lhs, const frac<F>& rhs) - { - trace::entering("frac<mln_trait_op_plus(T,F)> mln::algebra::operator+(const frac<T>& lhs, const frac<F>& rhs)"); - typedef mln_trait_op_plus(T,F) R; - frac<R> tmp; - - tmp.numerator(lhs.numerator()*rhs.denominator() + lhs.denominator()*rhs.numerator()); - tmp.denominator(lhs.denominator()*rhs.denominator()); - - tmp.irreducible(); - - trace::exiting("frac<mln_trait_op_plus(T,F)> mln::algebra::operator+(const frac<T>& lhs, const frac<F>& rhs)"); - return tmp; - } - - // frac - frac - template <typename T, typename F> - frac<mln_trait_op_minus(T,F)> - operator-(const frac<T>& lhs, const frac<F>& rhs) - { - trace::entering("frac<mln_trait_op_minus(T,F)> mln::algebra::operator-(const frac<T>& lhs, const frac<F>& rhs)"); - typedef mln_trait_op_minus(T,F) R; - frac<R> tmp; - - tmp.numerator(lhs.numerator()*rhs.denominator() - lhs.denominator()*rhs.numerator()); - tmp.denominator(lhs.denominator()*rhs.denominator()); - - tmp.irreducible(); - - trace::exiting("frac<mln_trait_op_minus(T,F)> mln::algebra::operator-(const frac<T>& lhs, const frac<F>& rhs)"); - return tmp; - } - - // frac * frac - template <typename T, typename F> - frac<mln_trait_op_times(T,F)> - operator*(const frac<T>& lhs, const frac<F>& rhs) - { - trace::entering("frac<mln_trait_op_times(T,F)> mln::algebra::operator*(const frac<T>& lhs, const frac<F>& rhs)"); - typedef mln_trait_op_times(T,F) R; - frac<R> tmp; - - tmp.numerator(lhs.numerator()*rhs.numerator()); - tmp.denominator(lhs.denominator()*rhs.denominator()); - - tmp.irreducible(); - - trace::exiting("frac<mln_trait_op_times(T,F)> mln::algebra::operator*(const frac<T>& lhs, const frac<F>& rhs)"); - return tmp; - } - - // frac / frac - template <typename T, typename F> - frac<mln_trait_op_div(T,F)> - operator/(const frac<T>& lhs, frac<F>& rhs) - { - trace::entering("frac<mln_trait_op_div(T,F)> mln::algebra::operator/(const frac<T>& lhs, const frac<F>& rhs)"); - typedef mln_trait_op_div(T,F) R; - frac<R> tmp; - - tmp.numerator(lhs.numerator()*rhs.denominator()); - tmp.denominator(lhs.denominator()*rhs.numerator()); - - tmp.irreducible(); - - trace::exiting("frac<mln_trait_op_div(T,F)> mln::algebra::operator/(const frac<T>& lhs, const frac<F>& rhs)"); - return tmp; - } } // end of namespace mln::algebra diff --git a/trunk/milena/sandbox/green/fraction/gcd.hh b/trunk/milena/sandbox/green/fraction/gcd.hh new file mode 100644 index 0000000..b087d71 --- /dev/null +++ b/trunk/milena/sandbox/green/fraction/gcd.hh @@ -0,0 +1,91 @@ +// Copyright (C) 2006, 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena 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 Olena. If not, see <
http://www.gnu.org/licenses/
>. +// +// As a special exception, you may use this file as part of a free +// software project 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 MLN_MATH_GCD_HH +# define MLN_MATH_GCD_HH + +#include <mln/math/min.hh> +#include <mln/math/max.hh> +#include <mln/math/abs.hh> + +namespace mln +{ + namespace math + { + template <typename T> + T gcd(const T& a, const T& b); + + template <typename T> + T gcd_(const T& a, const T& b); + +# ifndef MLN_INCLUDE_ONLY + + // Safety interface for the greatest common divisor + template <typename T> + inline + T gcd(const T& a, const T& b) + { + trace::entering("const T mln::math::gcd(const T& a, const T& b)"); + + T result; + T abs_a = math::abs(a); + T abs_b = math::abs(b); + + if ((0 == abs_a) || (0 == abs_b)) + result = 1; + else + result = gcd_(math::max(abs_a, abs_b), math::min(abs_a, abs_b)); + + trace::exiting("const T mln::math::gcd(const T& a, const T& b)"); + return result; + } + + // Euclidian algorithm for the greatest common divisor + template <typename T> + inline + T gcd_(const T& a, const T& b) + { + trace::entering("T mln::math::cgd_(const T& a, const T& b)"); + mln_assertion(a > 0); + mln_assertion(b > 0); + mln_assertion(a >= b); + + T rest = a%b; + + if (0 == rest) + rest = b; + else + rest = gcd_(b, rest); + + trace::exiting("T mln::math::cgd_(const T& a, const T& b)"); + return rest; + } + +# endif // ! MLN_INCLUDE_ONLY + + } +} + +#endif // ! MLN_MATH_GCD_HH diff --git a/trunk/milena/sandbox/green/fraction/sign_prod.hh b/trunk/milena/sandbox/green/fraction/sign_prod.hh new file mode 100644 index 0000000..b081904 --- /dev/null +++ b/trunk/milena/sandbox/green/fraction/sign_prod.hh @@ -0,0 +1,74 @@ +// Copyright (C) 2006, 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena 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 Olena. If not, see <
http://www.gnu.org/licenses/
>. +// +// As a special exception, you may use this file as part of a free +// software project 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 MLN_MATH_SIGN_PROD_HH +# define MLN_MATH_SIGN_PROD_HH + +#include <mln/math/sign.hh> + +namespace mln +{ + + namespace math + { + template <typename T> + sign_t sign_prod(const T& a, const T& b); + + template <typename T> + T sign_to_coeff(const sign_t& s); + + sign_t sign_prod_(const sign_t& a, const sign_t& b); + + bool is_positive(const sign_t& s); + bool is_negative(const sign_t& s); + bool is_positive_or_null(const sign_t& s); + bool is_negative_or_null(const sign_t& s); + bool is_null(const sign_t& s); + bool is_not_null(const sign_t& s); + +# ifndef MLN_INCLUDE_ONLY + + template <typename T> + sign_t sign_prod(const T& a, const T& b) {return sign_prod_(math::sign(a), math::sign(b));} + + template <typename T> + T sign_to_coeff(const sign_t& s) {return static_cast<T>(s);} + + + sign_t sign_prod_(const sign_t& a, const sign_t& b){return static_cast<sign_t>(a*b); } + + bool is_positive(const sign_t& s) {return 0 < s;} + bool is_negative(const sign_t& s) {return 0 > s;} + bool is_positive_or_null(const sign_t& s) {return 0 <= s;} + bool is_negative_or_null(const sign_t& s) {return 0 >= s;} + bool is_null(const sign_t& s) {return 0 == s;} + bool is_not_null(const sign_t& s) {return 0 != s;} + +# endif // ! MLN_INCLUDE_ONLY + + } +} + +#endif // ! MLN_MATH_SIGN_PROD_HH -- 1.5.6.5
15 years, 4 months
1
0
0
0
4336: Integration of the fraction type in the accumulators.
by Yann Jacquelet
* green/Fraction/frac.cc : Complete unary tests. * green/Fraction/frac.hh : Complete fraction type. --- trunk/milena/sandbox/ChangeLog | 7 + trunk/milena/sandbox/green/Fraction/frac.cc | 271 +++++++++++++++++++++++++++ trunk/milena/sandbox/green/Fraction/frac.hh | 59 ++++++- 3 files changed, 336 insertions(+), 1 deletions(-) create mode 100644 trunk/milena/sandbox/green/Fraction/frac.cc diff --git a/trunk/milena/sandbox/ChangeLog b/trunk/milena/sandbox/ChangeLog index 1d4ab9d..010a2b9 100644 --- a/trunk/milena/sandbox/ChangeLog +++ b/trunk/milena/sandbox/ChangeLog @@ -24,6 +24,13 @@ 2009-07-28 Yann Jacquelet <jacquelet(a)lrde.epita.fr> + Integration of the fraction type in the accumulators. + + * green/Fraction/frac.cc : Complete unary tests. + * green/Fraction/frac.hh : Complete fraction type. + +2009-07-28 Yann Jacquelet <jacquelet(a)lrde.epita.fr> + Learn how creating new types in milena (Fraction). * green/Fraction/Makefile.am : New Makefile. diff --git a/trunk/milena/sandbox/green/Fraction/frac.cc b/trunk/milena/sandbox/green/Fraction/frac.cc new file mode 100644 index 0000000..4a7f452 --- /dev/null +++ b/trunk/milena/sandbox/green/Fraction/frac.cc @@ -0,0 +1,271 @@ +#include <iostream> +#include "frac.hh" + +// +// TEST INSTANTIATION +// +void test_instantiation_without_argument() +{ + const mln::algebra::frac<int> constant; + mln::algebra::frac<int> variable; + + mln_assertion(constant == variable); + std::cout << "const frac<T> f : ok" << std::endl; + std::cout << "frac<T> f : ok" << std::endl; +} + +void test_instantiation_numerator_denominator() +{ + const mln::algebra::frac<int> constant(2,5); + mln::algebra::frac<int> variable(2,5); + + mln_assertion(constant == variable); + std::cout << "const frac<T> f(n,d) : ok" << std::endl; + std::cout << "frac<T> f(n,d) : ok" << std::endl; +} + +void test_instantiation_frac() +{ + const mln::algebra::frac<int> ref_int(2,5); + const mln::algebra::frac<long> ref_long(2,5); + + const mln::algebra::frac<int> constant1 = ref_int; + const mln::algebra::frac<int> constant2 = ref_long; + mln::algebra::frac<int> variable1 = ref_int; + mln::algebra::frac<int> variable2 = ref_long; + + mln_assertion(constant1 == ref_int); + mln_assertion(constant2 == ref_long); + mln_assertion(variable1 == ref_int); + mln_assertion(variable2 == ref_long); + std::cout << "const frac<T> f = frac<T> : ok" << std::endl; + std::cout << "const frac<T> f = frac<F> : ok" << std::endl; + std::cout << "frac<T> f = frac<T> : ok" << std::endl; + std::cout << "frac<T> f = frac<F> : ok" << std::endl; +} + +void test_instantiation_zero() +{ + const mln::algebra::frac<int> zero(0,0); + const mln::algebra::frac<int> f_cst = mln::literal::zero; + mln::algebra::frac<int> f_var = mln::literal::zero; + + mln_assertion(zero == f_cst); + mln_assertion(zero == f_var); + std::cout << "const frac<T> f = zero : ok" << std::endl; + std::cout << "frac<T> f = zero : ok" << std::endl; +} + +void test_instantiation_one() +{ + const mln::algebra::frac<int> one(1,0); + const mln::algebra::frac<int> f_cst = mln::literal::one; + mln::algebra::frac<int> f_var = mln::literal::one; + + mln_assertion(one == f_cst); + mln_assertion(one == f_var); + std::cout << "const frac<T> f = one : ok" << std::endl; + std::cout << "frac<T> f = one : ok" << std::endl; +} + +void test_instantiation_integer() +{ + const mln::algebra::frac<int> ref(5,0); + const mln::algebra::frac<int> f_cst = 5; + mln::algebra::frac<int> f_var = 5; + + mln_assertion(ref == f_cst); + mln_assertion(ref == f_var); + std::cout << "const frac<T> f = integer : ok" << std::endl; + std::cout << "frac<T> f = integer : ok" << std::endl; +} + + +// +// TEST ASSIGNEMENT +// +void test_assignement_zero() +{ + const mln::algebra::frac<int> zero(0,0); + mln::algebra::frac<int> f; + + f = mln::literal::zero; + mln_assertion(zero == f); + std::cout << "frac = zero : ok" << std::endl; +} + +void test_assignement_one() +{ + const mln::algebra::frac<int> one(1,0); + mln::algebra::frac<int> f; + + f = mln::literal::one; + mln_assertion(one == f); + std::cout << "frac = one : ok" << std::endl; +} + +void test_assignement_frac() +{ + const mln::algebra::frac<int> ref(2,3); + mln::algebra::frac<int> f; + + f = ref; + mln_assertion(ref == f); + std::cout << "frac = frac : ok" << std::endl; +} + +void test_assignement_integer() +{ + const mln::algebra::frac<int> ref(5,0); + mln::algebra::frac<int> f; + + f = 5; + mln_assertion(ref == f); + std::cout << "frac = integer: ok" << std::endl; +} + +int main() +{ + using namespace std; + using namespace mln; + using namespace mln::algebra; + + trace::quiet = true; + + // Testing instanciation + frac<int> f0; + frac<int> op1a(5,10); + frac<int> op1b(op1a); + frac<int> op2a(1,2); + frac<int> op2b = op2a; + int op3a = 1; + int op3b = 1; + int op4a = 2; + int op4b = 2; + frac<int> resPlus(literal::one); + frac<int> resMinus(literal::zero); + frac<int> resTimes(1,4); + frac<int> resDiv(literal::one); + frac<int> resPlusScalar(3,2); + frac<int> resMinusScalar(-1,2); + frac<int> resTimesScalar(literal::one); + frac<int> resDivScalar(1,4); + frac<int> resUminus(-1,4); + frac<int> resZero(0,0); + frac<int> resOne(1,0); + cout << "frac<T> f : ok" << endl; + + test_instantiation_without_argument(); + test_instantiation_numerator_denominator(); + test_instantiation_frac(); + test_instantiation_zero(); + test_instantiation_one(); + test_instantiation_integer(); + + // trace::quiet = false; + + //trace::quiet = true; + + test_assignement_zero(); + test_assignement_one(); + test_assignement_frac(); + test_assignement_integer(); + + + // Test frac.eval() + mln_assertion(0.5 == op2b.eval()); + mln_assertion(op2a == op2b); + cout << "frac.eval() : ok" << endl; + + // Test - frac + mln_assertion(resUminus == (-op2b)); + cout << "- frac() : ok" << endl; + + // Test frac + frac + mln_assertion(resPlus == (op1b + op2b)); + mln_assertion(op1a == op1b); + mln_assertion(op2a == op2b); + cout << "frac + frac : ok" << endl; + + // Test frac - frac + mln_assertion(resMinus == (op1b - op2b)); + mln_assertion(op1a == op1b); + mln_assertion(op2a == op2b); + cout << "frac - frac : ok" << endl; + + // Test frac * frac + mln_assertion(resTimes == (op1b * op2b)); + mln_assertion(op1a == op1b); + mln_assertion(op2a == op2b); + cout << "frac * frac : ok" << endl; + + // Test frac / frac + mln_assertion(resDiv == (op1b / op2b)); + mln_assertion(op1a == op1b); + mln_assertion(op2a == op2b); + cout << "frac / frac : ok" << endl; + + // Test frac + scalar + mln_assertion(resPlusScalar == (op1b + op3b)); + mln_assertion(op1a == op1b); + mln_assertion(op3a == op3b); + cout << "frac + scalar : ok" << endl; + + // Test frac - scalar + mln_assertion(resMinusScalar == (op1b - op3b)); + mln_assertion(op1a == op1b); + mln_assertion(op3a == op3b); + cout << "frac - scalar : ok" << endl; + + // Test frac * scalar + mln_assertion(resTimesScalar == (op1b * op4b)); + mln_assertion(op1a == op1b); + mln_assertion(op4a == op4b); + cout << "frac * scalar : ok" << endl; + + // Test frac / scalar + mln_assertion(resDivScalar == (op1b / op4b)); + mln_assertion(op1a == op1b); + mln_assertion(op4a == op4b); + cout << "frac / scalar : ok" << endl; + + return 0; +} + +#include <mln/core/image/image2d.hh> +#include <mln/value/int_u8.hh> +#include <mln/io/pgm/load.hh> +#include <mln/data/compute.hh> +#include <mln/accu/math/sum.hh> +#include <mln/accu/stat/mean.hh> +#include <mln/accu/stat/variance.hh> + + +int main2() +{ + using namespace mln; + using namespace std; + using namespace mln::algebra; + + image2d<value::int_u8> input; + io::pgm::load(input, "/usr/local/share/olena/images/small.pgm"); + + /* + accu::math::sum< value::int_u8 > sum0; + accu::math::sum< value::int_u8, frac<long> > sum1; + + cout << data::compute(sum0, input) << endl; + cout << data::compute(sum1, input) << endl; + + accu::stat::mean< value::int_u8 > mean0; + accu::stat::mean< value::int_u8, frac<long> > mean1; + */ + // cout << data::compute(mean0, input) << endl; + //cout << data::compute(mean1, input) << endl; + + //frac<long> count = data::compute(accu::math::count< frac<long> >(), input); + //frac<long> variance = data::compute(accu::stat::variance< frac<long>, frac<long>, frac<long> >(), input); + + + return 0; +} diff --git a/trunk/milena/sandbox/green/Fraction/frac.hh b/trunk/milena/sandbox/green/Fraction/frac.hh index a9c40ec..b8ec226 100644 --- a/trunk/milena/sandbox/green/Fraction/frac.hh +++ b/trunk/milena/sandbox/green/Fraction/frac.hh @@ -113,9 +113,12 @@ namespace mln const T gcd_(const T& a, const T& b) const; public: - // Constructor without argument + // Constructor without argument ==> very dangerous one in this context frac(); + // Constructor to convert scalar in fraction (transtyping) + frac(const T& scalar); + // Constructor with literal zero frac(const literal::zero_t& zero); frac& operator=(const literal::zero_t& zero); @@ -325,6 +328,17 @@ namespace mln trace::exiting("mln::algebra::frac<T>::frac()"); } + + template <typename T> + frac<T>::frac(const T& scalar) : super_() + { + trace::entering("mln::algebra::frac<T>::frac(const S& scalar)"); + + this->numerator(scalar); + this->denominator(1); + + trace::exiting("mln::algebra::frac<T>::frac(const S& scalar)"); + } template <typename T> inline @@ -354,6 +368,21 @@ namespace mln template <typename T> inline + frac<T>& frac<T>::operator=(const literal::zero_t& zero) + { + trace::entering("frac<T>& mln::algebra::frac<T>::operator=(const literal::zero_t& zero)"); + + this->numerator(zero); + this->denominator(1); + + trace::exiting("frac<T>& mln::algebra::frac<T>::operator=(const literal::zero_t& zero)"); + return *this; + } + + + + template <typename T> + inline frac<T>::frac(const literal::one_t& one) : super_() { trace::entering("frac<T>::frac(const literal::one_t& one)"); @@ -366,6 +395,19 @@ namespace mln template <typename T> inline + frac<T>& frac<T>::operator=(const literal::one_t& one) + { + trace::entering("frac<T>& mln::algebra::frac<T>::operator=(const literal::one_t& one)"); + + this->numerator(one); + this->denominator(1); + + trace::exiting("frac<T>& mln::algebra::frac<T>::operator=(const literal::one_t& one)"); + return *this; + } + + template <typename T> + inline frac<T>::frac(const frac<T>& rhs) : super_() { trace::entering("mln::algebra::frac<T>::frac(const frac<T>& rhs)"); @@ -379,6 +421,21 @@ namespace mln } template <typename T> + inline + frac<T>& frac<T>::operator=(const frac<T>& rhs) + { + trace::entering("frac<T>& mln::algebra::frac<T>::operator=(const frac<T>& rhs)"); + + numerator(rhs.numerator()); + denominator(rhs.denominator()); + + irreducible(); + trace::exiting("frac<T>& mln::algebra::frac<T>::operator=(const frac<T>& rhs)"); + + return *this; + } + + template <typename T> template <typename F> inline frac<T>::frac(const frac<F>& rhs) : super_() -- 1.5.6.5
15 years, 4 months
1
0
0
0
r4335: Implement support for 2D tiled images and other drafts
by Fabien Freling
URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
ChangeLog: 2009-08-03 Fabien Freling <fabien.freling(a)lrde.epita.fr> Implement support for 2D tiled images and other drafts. * fabien/igr/segment_us_morpho.sh: Small update. * fabien/magick/Makefile: Minor fix. * fabien/mln/canvas/browsing/directional.hh: Draft. * fabien/mln/canvas/browsing/snake.hh: Draft. * fabien/mln/core/image/magick_tiled2d.hh: Implement 2D tiled image with ImageMagick. * fabien/mln/core/image/tiled2d.hh: Implement 2D tiled image. * fabien/mln/data/fast_median.hh: Draft. * fabien/mln/io/pnm/load.hh: Add support for tiled images. * fabien/tests/core/image/Makefile: New Makefile for building. * fabien/tests/core/image/tiled2d.cc: New test for tiled images. --- igr/segment_us_morpho.sh | 4 mln/core/image/magick_tiled2d.hh | 56 ++++++ mln/io/pnm/load.hh | 334 +++++++++++++++++++++++++++++++++++++++ tests/core/image/Makefile | 7 tests/core/image/tiled2d.cc | 37 ++++ 5 files changed, 434 insertions(+), 4 deletions(-) Index: trunk/milena/sandbox/fabien/igr/segment_us_morpho.sh =================================================================== --- trunk/milena/sandbox/fabien/igr/segment_us_morpho.sh (revision 4334) +++ trunk/milena/sandbox/fabien/igr/segment_us_morpho.sh (revision 4335) @@ -4,10 +4,6 @@ process () { nlabels=`./filter_morpho_us $@` -#if [ $? -gt 0 ]; then -# echo "error: filter_morpho_us failed" -# exit -# fi ../bin/dump2pgm8b closing.dump closing.pgm convert closing.pgm 01_closing.png Index: trunk/milena/sandbox/fabien/tests/core/image/tiled2d.cc =================================================================== --- trunk/milena/sandbox/fabien/tests/core/image/tiled2d.cc (revision 0) +++ trunk/milena/sandbox/fabien/tests/core/image/tiled2d.cc (revision 4335) @@ -0,0 +1,37 @@ +#include <mln/core/image/tiled2d.hh> + +#include <mln/io/ppm/load.hh> +#include <mln/literal/colors.hh> +#include <mln/value/rgb8.hh> + +#include <mln/debug/quiet.hh> + + +using namespace mln; +using value::rgb8; + + +int main(int argc, char* argv[]) +{ + if (argc != 2) + { + std::cout << "Usage: " << argv[0] << " input output" << std::endl; + return 1; + } + + tiled2d<rgb8> tiled_ima; + + io::ppm::load(tiled_ima, argv[1]); + + std::cout << "bbox: " << tiled_ima.bbox() << std::endl; + /*mln_piter_(tiled2d<rgb8>) p(tiled_ima.domain()); + for_all(p) + { + if (p.col() % 64 == 0) + { + tiled_ima(p) = literal::purple; + } + }*/ + + return 0; +} Index: trunk/milena/sandbox/fabien/tests/core/image/Makefile =================================================================== --- trunk/milena/sandbox/fabien/tests/core/image/Makefile (revision 0) +++ trunk/milena/sandbox/fabien/tests/core/image/Makefile (revision 4335) @@ -0,0 +1,7 @@ +CXX = g++ +CXXFLAGS = -DNDEBUG -O1 +LIBS = `Magick++-config --cppflags --cxxflags --ldflags --libs` +INC = -I../../../ -I../../../../../ + +tiled2d: tiled2d.cc + ${CXX} ${CXXFLAGS} ${INC} $^ -o tiled2d Index: trunk/milena/sandbox/fabien/mln/io/pnm/load.hh =================================================================== --- trunk/milena/sandbox/fabien/mln/io/pnm/load.hh (revision 0) +++ trunk/milena/sandbox/fabien/mln/io/pnm/load.hh (revision 4335) @@ -0,0 +1,334 @@ +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena 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 Olena. If not, see <
http://www.gnu.org/licenses/
>. +// +// As a special exception, you may use this file as part of a free +// software project 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 MLN_IO_PNM_LOAD_HH +# define MLN_IO_PNM_LOAD_HH + +/// \file +/// +/// Define a function which loads an image of kind PNM 8/16bits with +/// given path. + +# include <iostream> +# include <fstream> +# include <string> + +# include <mln/core/image/image2d.hh> +# include <mln/core/image/tiled2d.hh> + +# include <mln/value/int_u8.hh> +# include <mln/value/rgb.hh> + +# include <mln/io/pnm/load_header.hh> +# include <mln/io/pnm/max_component.hh> +# include <mln/io/pnm/macros.hh> + +# include <mln/metal/is_a.hh> + +namespace mln +{ + + namespace io + { + + namespace pnm + { + + +# ifndef MLN_INCLUDE_ONLY + + template <typename I> + void load_ascii_value(std::ifstream& file, I& ima); + + template <typename I> + void load_ascii_builtin(std::ifstream& file, I& ima); + + + namespace internal + { + + template <typename I> + inline + void + load_ascii_dispatch(std::ifstream& file, I& ima, const metal::bool_<true>&) + { + load_ascii_value(file, ima); + } + + template <typename I> + inline + void + load_ascii_dispatch(std::ifstream& file, I& ima, const metal::bool_<false>&) + { + load_ascii_builtin(file, ima); + } + + } // end of namespace mln::io::pnm::internal + + + // Read a Milena rgb value (sizeof(int_u8) != 1). + template <unsigned int n> + inline + void read_value(std::ifstream& file, value::rgb<n>& v) + { + typedef typename value::int_u<n>::enc E; + + E c; + file.read((char*)(&c), sizeof(E)); + v.red() = c; + file.read((char*)(&c), sizeof(E)); + v.green() = c; + file.read((char*)(&c), sizeof(E)); + v.blue() = c; + } + + // Read a Milena scalar value (sizeof(int_u8) != 1). + template <class V> + inline + void read_value(std::ifstream& file, value::Scalar<V>& v) + { + typedef typename V::enc E; + + E c; + file.read((char*)(&c), sizeof(E)); + exact(v) = c; + } + + // Read a builtin scalar value. + template <typename V> + inline + void read_value(std::ifstream& file, V& v) + { + V c; + file.read((char*)(&c), sizeof(V)); + v = c; + } + + // used when (sizeof(int_u8) != 1) + template <typename V> + inline + void load_raw_2d_uncontiguous(std::ifstream& file, image2d<V>& ima) + { + const def::coord + min_row = geom::min_row(ima), + max_row = geom::max_row(ima), + min_col = geom::min_col(ima), + max_col = geom::max_col(ima); + + point2d p; + for (p.row() = min_row; p.row() <= max_row; ++p.row()) + for (p.col() = min_col; p.col() <= max_col; ++p.col()) + read_value(file, ima(p)); + } + + // Warning if we try to load uncontiguous 2D PNM file into a tiled + // image, this is not currently supported. + template <typename V> + inline + void load_raw_2d_uncontiguous(std::ifstream& file, tiled2d<V>& ima) + { + (void) file; + (void) ima; + std::cout << "You can't load an uncontiguous 2D PNM file into "; + std::cout << "a tiled image" << std::endl; + abort(); + } + + // used in g++ > 2.95 + template <typename I> + inline + void load_raw_2d_contiguous(std::ifstream& file, I& ima, std::string& filename) + { + (void) filename; + point2d p = point2d(0, ima.domain().pmin().col()); + typedef mln_value(I) V; + const mln_deduce(I, site, coord) + min_row = geom::min_row(ima), + max_row = geom::max_row(ima); + + std::size_t len = geom::ncols(ima) * sizeof(V); + for (p.row() = min_row; p.row() <= max_row; ++p.row()) + file.read((char*)(&ima(p)), len); + } + + // Load raw 2d for tiled images. + template <typename T> + inline + void load_raw_2d_contiguous(std::ifstream& file, tiled2d<T>& ima, std::string& filename) + { + ima.pos_() = file.tellg(); + ima.file_() = filename; + } + + /// load_ascii for Milena value types. + template <typename I> + inline + void load_ascii_value(std::ifstream& file, I& ima) + { + mln_equiv(mln_value_(I)) c; + mln_fwd_piter(I) p(ima.domain()); + for_all(p) + { + file >> c; + ima(p) = c; + } + } + + /// load_ascii for builtin value types. + template <typename I> + inline + void load_ascii_builtin(std::ifstream& file, I& ima) + { + mln_fwd_piter(I) p(ima.domain()); + + // FIXME: May be wrong! + // Worked out with an image with a max value of 255 + // loaded in an image2d<unsigned char>. + unsigned n; + + for_all(p) + { + file >> n; + ima(p) = n; + } + } + + /// load_raw_2d. + /// for all pnm 8/16 bits formats + template <typename I> + inline + void load_raw_2d(std::ifstream& file, I& ima, std::string& filename) + { + if (sizeof(value::int_u8) == 1) + load_raw_2d_contiguous(file, ima, filename); + else + load_raw_2d_uncontiguous(file, ima); + } + + /// main function : load pnm format + template <typename V> + inline + image2d<V> load(char type_, const std::string& filename) + { + trace::entering("mln::io::pnm::load"); + + std::ifstream file(filename.c_str()); + if (! file) + { + std::cerr << "error: file '" << filename + << "' not found!"; + abort(); + } + char type = 0; + int nrows, ncols; + unsigned int maxval; + read_header(static_cast<char>(type_ - 3), type_, file, type, + nrows, ncols, maxval); + + if (max_component(V()) != maxval) + { + std::cerr << "error: file '" << filename + << "' cannot be loaded into this type of image" + << std::endl; + + std::cerr << "input image have " << maxval + << " as maximum value while the destination's one is " + << max_component(V()) << " (should be the same)." + << std::endl; + abort(); + } + + image2d<V> ima(nrows, ncols); + if (type == type_) + load_raw_2d(file, ima, filename); + else + if (type == (type_ - 3)) + pnm::internal::load_ascii_dispatch(file, ima, mlc_is_a(V, mln::Value)()); + + trace::exiting("mln::io::pnm::load"); + + return ima; + } + + /// An other way to load pnm files : + /// the destination is an argument to check if + /// the type match the file to load. + template <typename I> + inline + void load(char type_, + Image<I>& ima_, + const std::string& filename) + { + trace::entering("mln::io::pnm::load"); + + std::ifstream file(filename.c_str()); + if (! file) + { + std::cerr << "error: file '" << filename + << "' not found!"; + abort(); + } + + I& ima = exact(ima_); + + char type = 0; + int nrows, ncols; + unsigned int maxval; + read_header(static_cast<char>(type_ - 3), type_, file, type, + nrows, ncols, maxval); + + if (max_component(mln_value(I)()) != maxval) + { + std::cerr << "error: file '" << filename + << "' cannot be loaded into this type of image" + << std::endl; + + std::cerr << "input image have " << maxval + << " as maximum value while the destination's one is " + << max_component(mln_value(I)()) << "." + << std::endl; + abort(); + } + + ima.init_(make::box2d(nrows, ncols)); + if (type == type_) + load_raw_2d(file, ima); + else + if (type == (type_ - 3)) + pnm::internal::load_ascii_dispatch(file, ima, mlc_is_a(mln_value(I), mln::Value)()); + + trace::exiting("mln::io::pnm::load"); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::io::pnm + + } // end of namespace mln::io + +} // end of namespace mln + + +#endif // ! MLN_IO_PNM_LOAD_HH Index: trunk/milena/sandbox/fabien/mln/core/image/magick_tiled2d.hh =================================================================== --- trunk/milena/sandbox/fabien/mln/core/image/magick_tiled2d.hh (revision 0) +++ trunk/milena/sandbox/fabien/mln/core/image/magick_tiled2d.hh (revision 4335) @@ -0,0 +1,659 @@ +// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena 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 Olena. If not, see <
http://www.gnu.org/licenses/
>. +// +// As a special exception, you may use this file as part of a free +// software project 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 MLN_CORE_IMAGE_TILED2D_HH +# define MLN_CORE_IMAGE_TILED2D_HH + +/// \file +/// Definition of the basic mln::tiled2d class. + +# include <Magick++.h> + +# include <mln/core/internal/image_primary.hh> +# include <mln/core/internal/fixme.hh> +# include <mln/core/alias/box2d.hh> +# include <mln/core/routine/init.hh> + +# include <mln/border/thickness.hh> +# include <mln/value/set.hh> +# include <mln/fun/i2v/all_to.hh> +# include <mln/value/proxy.hh> + + + +namespace mln +{ + + // Forward declaration. + template <typename T> struct tiled2d; + + + namespace internal + { + + /// Data structure for \c mln::tiled2d<T>. + template <typename T> + struct data< tiled2d<T> > + { +// data(const box2d& b, unsigned bdr); + data(const std::string& filename); + ~data(); + + Magick::Image buffer_; + Magick::PixelPacket* pixel_cache; + T value_; + + box2d b_; // theoretical box + unsigned bdr_; + box2d vb_; // virtual box, i.e., box including the virtual border + + void update_vb_(); + void allocate_(); + void deallocate_(); + void swap_(data< tiled2d<T> >& other_); + void reallocate_(unsigned new_border); + }; + + } // end of namespace mln::internal + + + namespace trait + { + + template <typename T> + struct image_< tiled2d<T> > : default_image_< T, tiled2d<T> > + { + // misc + typedef trait::image::category::primary category; + typedef trait::image::speed::slow speed; + typedef trait::image::size::regular size; + + // value + typedef trait::image::vw_io::none vw_io; + typedef trait::image::vw_set::none vw_set; + typedef trait::image::value_access::direct value_access; + typedef trait::image::value_storage::one_block value_storage; + typedef trait::image::value_browsing::site_wise_only value_browsing; + typedef trait::image::value_alignment::with_grid value_alignment; + typedef trait::image::value_io::read_only value_io; + + // site / domain + typedef trait::image::pw_io::read_write pw_io; + typedef trait::image::localization::basic_grid localization; + typedef trait::image::dimension::two_d dimension; + + // extended domain + typedef trait::image::ext_domain::extendable ext_domain; + typedef trait::image::ext_value::multiple ext_value; + typedef trait::image::ext_io::read_only ext_io; + }; + + } // end of namespace mln::trait + + + + /// Basic 2D image class. + /// + /// The parameter \c T is the type of pixel values. This image class + /// stores data in memory and has a virtual border with constant + /// thickness around data. + /// + /// \ingroup modimageconcrete + // + template <typename T> + class tiled2d : public internal::image_primary< T, mln::box2d, tiled2d<T> > + { + typedef internal::image_primary< T, mln::box2d, tiled2d<T> > super_; + public: + + /// Value associated type. + typedef T value; + + /// Return type of read-only access. + typedef const T& rvalue; + + /// Return type of read-write access. + typedef mln::value::proxy< tiled2d<T> > lvalue; + + + /// Skeleton. + typedef tiled2d< tag::value_<T> > skeleton; + + + /// Constructor without argument. + tiled2d(); + + /// Constructor with the numbers of rows and columns and the + /// border thickness. + //tiled2d(int nrows, int ncols, unsigned bdr = border::thickness); + + /// Constructor with a box and the border thickness (default is + /// 3). + // tiled2d(const box2d& b, unsigned bdr = border::thickness); + + /// Constructor with a filename. + tiled2d(const std::string& filename); + + + /// Initialize an empty image. + //void init_(const box2d& b, unsigned bdr = border::thickness); + + /// Initialize an empty image. + void init_(const std::string& filename); + + + /// Test if \p p is valid. + bool has(const point2d& p) const; + + /// Give the definition domain. + const box2d& domain() const; + + /// Give the bounding box domain. + const box2d& bbox() const; + + /// Read-only access to the image value located at point \p p. + const T& operator()(const point2d& p) const; + + /// Read-write access to the image value located at point \p p. + mln::value::proxy< tiled2d<T> > operator()(const point2d& p); + + // Read access to the image value located at point \p p. + const T& read_(const point2d& p) const; + + // Write access to the image value located at point \p p. + void write_(const point2d& p, const T& value); + + + template <typename P> + T& alt(const P& p) + { + typedef def::coord coord_t; + mln_precondition(this->has(p)); + + return this->data_->array_ [*(coord_t*)(&p.p_hook_())] [*((coord_t*)(&p.p_hook_()) + 1)]; + } + + + // Specific methods: + // ----------------- + + /// Read-only access to the image value located at (\p row, \p col). + const T& at_(unsigned row, unsigned col) const; + + /// Read-write access to the image value located at (\p row, \p col). + T& at_(unsigned row, unsigned col); + + /// Give the number of rows. + unsigned nrows() const; + + /// Give the number of columns. + unsigned ncols() const; + + + // As a fastest image: + // ------------------- + + // Give the index of a point. + //using super_::index_of_point; + + /// Give the border thickness. + unsigned border() const; + + /// Give the number of elements (points including border ones). + unsigned nelements() const; + + /// Read-only access to the image value located at index \p i. + const T& element(unsigned i) const; + + /// Read-write access to the image value located at index \p i. + T& element(unsigned i); + + /// Give the delta-index corresponding to the delta-point \p dp. + int delta_index(const dpoint2d& dp) const; + + /// Give the point corresponding to the index \p i. + point2d point_at_index(unsigned i) const; + + /// Give a hook to the value buffer. + const Magick::Image buffer() const; + + /// Give a hook to the value buffer. + Magick::Image buffer(); + + + /// Resize image border with new_border. + void resize_(unsigned new_border); + }; + + + + // Forward declaration + + template <typename T> + void init_(tag::border_t, unsigned& bdr, const tiled2d<T>& model); + + template <typename T, typename J> + void init_(tag::image_t, mln::tiled2d<T>& target, const J& model); + + + +# ifndef MLN_INCLUDE_ONLY + + // init_ + + template <typename T> + inline + void init_(tag::border_t, unsigned& bdr, const tiled2d<T>& model) + { + bdr = model.border(); + } + + template <typename T, typename J> + inline + void init_(tag::image_t, tiled2d<T>& target, const J& model) + { + box2d b; + init_(tag::bbox, b, model); + unsigned bdr; + init_(tag::border, bdr, model); + target.init_(b, bdr); + } + + + // internal::data< tiled2d<T> > + + namespace internal + { +/* template <typename T> + inline + data< tiled2d<T> >::data(const box2d& b, unsigned bdr) + : buffer_(0), + b_ (b), + bdr_ (bdr) + { + allocate_(); + }*/ + + template <typename T> + inline + data< tiled2d<T> >::data(const std::string& filename) + { + buffer_.read(filename); + // DELETEME + std::cout << "columns: " << buffer_.columns() << std::endl; + std::cout << "rows: " << buffer_.rows() << std::endl; + // ! DELETEME + b_ = make::box2d(buffer_.rows(), buffer_.columns()); + std::cout << "bbox: " << b_ << std::endl; // DELETEME + } + + template <typename T> + inline + data< tiled2d<T> >::~data() + { + deallocate_(); + } + + template <typename T> + inline + void + data< tiled2d<T> >::update_vb_() + { + vb_.pmin() = b_.pmin() - dpoint2d(all_to(bdr_)); + vb_.pmax() = b_.pmax() + dpoint2d(all_to(bdr_)); + } + + template <typename T> + inline + void + data< tiled2d<T> >::allocate_() + { + update_vb_(); +// unsigned +// nr = vb_.len(0), +// nc = vb_.len(1); +// buffer_ = new T[nr * nc]; +// array_ = new T*[nr]; +// T* buf = buffer_ - vb_.pmin().col(); +// for (unsigned i = 0; i < nr; ++i) +// { +// array_[i] = buf; +// buf += nc; +// } +// array_ -= vb_.pmin().row(); + mln_postcondition(vb_.len(0) == b_.len(0) + 2 * bdr_); + mln_postcondition(vb_.len(1) == b_.len(1) + 2 * bdr_); + } + + template <typename T> + inline + void + data< tiled2d<T> >::deallocate_() + { +// if (buffer_) +// { +// delete[] buffer_; +// buffer_ = 0; +// } +// if (array_) +// { +// array_ += vb_.pmin().row(); +// delete[] array_; +// array_ = 0; +// } + } + + template <typename T> + inline + void + data< tiled2d<T> >::swap_(data< tiled2d<T> >& other_) + { + data< tiled2d<T> > self_ = *this; + *this = other_; + other_ = self_; + } + + template <typename T> + inline + void + data< tiled2d<T> >::reallocate_(unsigned new_border) + { + data< tiled2d<T> >& tmp = *(new data< tiled2d<T> >(this->b_, new_border)); + this->swap_(tmp); + } + + + } // end of namespace mln::internal + + + // tiled2d<T> + + template <typename T> + inline + tiled2d<T>::tiled2d() + { + } + + template <typename T> + inline + tiled2d<T>::tiled2d(const std::string& filename) + { + init_(filename); + } + + template <typename T> + inline + void + tiled2d<T>::init_(const std::string& filename) + { + mln_precondition(! this->is_valid()); + this->data_ = new internal::data< tiled2d<T> >(filename); + } + + template <typename T> + inline + const box2d& + tiled2d<T>::domain() const + { + mln_precondition(this->is_valid()); + return this->data_->b_; + } + + template <typename T> + inline + const box2d& + tiled2d<T>::bbox() const + { + mln_precondition(this->is_valid()); + return this->data_->b_; + } + + template <typename T> + inline + bool + tiled2d<T>::has(const point2d& p) const + { + mln_precondition(this->is_valid()); + return this->data_->vb_.has(p); + } + + template <typename T> + inline + const T& + tiled2d<T>::operator()(const point2d& p) const + { + return read_(p); + } + + template <typename T> + inline + mln::value::proxy< tiled2d<T> > + tiled2d<T>::operator()(const point2d& p) + { + mln::value::proxy<tiled2d> prx(*this, p); + return prx; + } + + template <typename T> + inline + const T& + tiled2d<T>::read_(const point2d& p) const + { + mln::tiled2d<T>* this_ = const_cast<mln::tiled2d<T>* >(this); // Trust me, I have to do this(_). + this_->data_->pixel_cache = this_->data_->buffer_.getPixels(p.col(), p.row(), p.col(), p.row()); + this->data_->value_.red() = this->data_->pixel_cache->red % 256; + this->data_->value_.green() = this->data_->pixel_cache->green % 256; + this->data_->value_.blue() = this->data_->pixel_cache->blue % 256; + return this->data_->value_; + } + + template <typename T> + inline + void + tiled2d<T>::write_(const point2d& p, const T& value) + { + std::cout << "setting value " << value << " at point " << p << std::endl; // DELETEME + /*this->data_->pixel_cache = this->data_->buffer_.getPixels(p.col(), p.row(), p.col(), p.row()); + *(this->data_->pixel_cache) = Magick::ColorRGB(256 - value.red(), + 256 - value.green(), + 256 - value.blue());*/ + } + + + // Specific methods: + + template <typename T> + inline + const T& + tiled2d<T>::at_(unsigned row, unsigned col) const + { + mln_precondition(this->has(point2d(row, col))); + //FIXME: use the cache Luke. + this->data_->pixel_cache = this->data_->buffer_.getPixels(col, row, col, row); + this->data_->value_.red() = this->data_->pixel_cache->red % 256; + this->data_->value_.green() = this->data_->pixel_cache->green % 256; + this->data_->value_.blue() = this->data_->pixel_cache->blue % 256; + return this->data_->value_; + } + + template <typename T> + inline + T& + tiled2d<T>::at_(unsigned row, unsigned col) + { + mln_precondition(this->has(point2d(row, col))); + //FIXME: use the cache Luke. + this->data_->pixel_cache = this->data_->buffer_.getPixels(col, row, col, row); + this->data_->value_.red() = this->data_->pixel_cache->red % 256; + this->data_->value_.green() = this->data_->pixel_cache->green % 256; + this->data_->value_.blue() = this->data_->pixel_cache->blue % 256; + return this->data_->value_; + } + + template <typename T> + inline + unsigned + tiled2d<T>::nrows() const + { + mln_precondition(this->is_valid()); + return this->data_->b_.len(0); + } + + template <typename T> + inline + unsigned + tiled2d<T>::ncols() const + { + mln_precondition(this->is_valid()); + return this->data_->b_.len(1); + } + + + // Hooks. + + template <typename T> + inline + const Magick::Image + tiled2d<T>::buffer() const + { + mln_precondition(this->is_valid()); + return this->data_->buffer_; + } + + template <typename T> + inline + Magick::Image + tiled2d<T>::buffer() + { + mln_precondition(this->is_valid()); + return this->data_->buffer_; + } + + +# endif // ! MLN_INCLUDE_ONLY + +} // end of namespace mln + + + +# include <mln/core/trait/pixter.hh> +# include <mln/core/dpoints_pixter.hh> +# include <mln/core/pixter2d.hh> +// # include <mln/core/w_window.hh> + + +namespace mln +{ + + namespace trait + { + + // pixter + + template <typename T> + struct fwd_pixter< tiled2d<T> > + { + typedef fwd_pixter2d< tiled2d<T> > ret; + }; + + template <typename T> + struct fwd_pixter< const tiled2d<T> > + { + typedef fwd_pixter2d< const tiled2d<T> > ret; + }; + + template <typename T> + struct bkd_pixter< tiled2d<T> > + { + typedef bkd_pixter2d< tiled2d<T> > ret; + }; + + template <typename T> + struct bkd_pixter< const tiled2d<T> > + { + typedef bkd_pixter2d< const tiled2d<T> > ret; + }; + + // qixter + + template <typename T, typename W> + struct fwd_qixter< tiled2d<T>, W > + { + typedef dpoints_fwd_pixter< tiled2d<T> > ret; + }; + + template <typename T, typename W> + struct fwd_qixter< const tiled2d<T>, W > + { + typedef dpoints_fwd_pixter< const tiled2d<T> > ret; + }; + + template <typename T, typename W> + struct bkd_qixter< tiled2d<T>, W > + { + typedef dpoints_bkd_pixter< tiled2d<T> > ret; + }; + + template <typename T, typename W> + struct bkd_qixter< const tiled2d<T>, W > + { + typedef dpoints_bkd_pixter< const tiled2d<T> > ret; + }; + + // nixter + + template <typename T, typename N> + struct fwd_nixter< tiled2d<T>, N > + { + typedef dpoints_fwd_pixter< tiled2d<T> > ret; + }; + + template <typename T, typename N> + struct fwd_nixter< const tiled2d<T>, N > + { + typedef dpoints_fwd_pixter< const tiled2d<T> > ret; + }; + + template <typename T, typename N> + struct bkd_nixter< tiled2d<T>, N > + { + typedef dpoints_bkd_pixter< tiled2d<T> > ret; + }; + + template <typename T, typename N> + struct bkd_nixter< const tiled2d<T>, N > + { + typedef dpoints_bkd_pixter< const tiled2d<T> > ret; + }; + + } // end of namespace mln::trait + +} // end of namespace mln + + +# include <mln/make/image.hh> + + +#endif // ! MLN_CORE_IMAGE_TILED2D_HH Index: trunk/milena/sandbox/fabien/mln/core/image/tiled2d.hh =================================================================== --- trunk/milena/sandbox/fabien/mln/core/image/tiled2d.hh (revision 0) +++ trunk/milena/sandbox/fabien/mln/core/image/tiled2d.hh (revision 4335) @@ -0,0 +1,676 @@ +// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena 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 Olena. If not, see <
http://www.gnu.org/licenses/
>. +// +// As a special exception, you may use this file as part of a free +// software project 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 MLN_CORE_IMAGE_TILED2D_HH +# define MLN_CORE_IMAGE_TILED2D_HH + +/// \file +/// Definition of the basic mln::tiled2d class. + +# include <mln/core/internal/image_primary.hh> +# include <mln/core/internal/fixme.hh> +# include <mln/core/alias/box2d.hh> +# include <mln/core/routine/init.hh> + +# include <mln/border/thickness.hh> +# include <mln/value/set.hh> +# include <mln/fun/i2v/all_to.hh> +# include <mln/value/proxy.hh> + + + +namespace mln +{ + + // Forward declaration. + template <typename T> struct tiled2d; + + + namespace internal + { + + /// Data structure for \c mln::tiled2d<T>. + template <typename T> + struct data< tiled2d<T> > + { +// data(const box2d& b, unsigned bdr); + data(const box2d& b, unsigned bdr); + ~data(); + + std::fstream* f_; + std::streampos pos_; + T value_; + + box2d b_; // theoretical box + unsigned bdr_; + box2d vb_; // virtual box, i.e., box including the virtual border + + void update_vb_(); + void allocate_(); + void deallocate_(); + void swap_(data< tiled2d<T> >& other_); + void reallocate_(unsigned new_border); + }; + + } // end of namespace mln::internal + + + namespace trait + { + + template <typename T> + struct image_< tiled2d<T> > : default_image_< T, tiled2d<T> > + { + // misc + typedef trait::image::category::primary category; + typedef trait::image::speed::slow speed; + typedef trait::image::size::regular size; + + // value + typedef trait::image::vw_io::none vw_io; + typedef trait::image::vw_set::none vw_set; + typedef trait::image::value_access::direct value_access; + typedef trait::image::value_storage::one_block value_storage; + typedef trait::image::value_browsing::site_wise_only value_browsing; + typedef trait::image::value_alignment::with_grid value_alignment; + typedef trait::image::value_io::read_only value_io; + + // site / domain + typedef trait::image::pw_io::read_write pw_io; + typedef trait::image::localization::basic_grid localization; + typedef trait::image::dimension::two_d dimension; + + // extended domain + typedef trait::image::ext_domain::extendable ext_domain; + typedef trait::image::ext_value::multiple ext_value; + typedef trait::image::ext_io::read_only ext_io; + }; + + } // end of namespace mln::trait + + + + /// Basic 2D image class. + /// + /// The parameter \c T is the type of pixel values. This image class + /// stores data in memory and has a virtual border with constant + /// thickness around data. + /// + /// \ingroup modimageconcrete + // + template <typename T> + class tiled2d : public internal::image_primary< T, mln::box2d, tiled2d<T> > + { + typedef internal::image_primary< T, mln::box2d, tiled2d<T> > super_; + public: + + /// Value associated type. + typedef T value; + + /// Return type of read-only access. + typedef const T& rvalue; + + /// Return type of read-write access. + typedef mln::value::proxy< tiled2d<T> > lvalue; + + + /// Skeleton. + typedef tiled2d< tag::value_<T> > skeleton; + + + /// Constructor without argument. + tiled2d(); + + /// Constructor with the numbers of rows and columns and the + /// border thickness. + //tiled2d(int nrows, int ncols, unsigned bdr = border::thickness); + + /// Constructor with a box and the border thickness (default is + /// 3). + tiled2d(const box2d& b, unsigned bdr = border::thickness); + + /// Constructor with a filename. + //tiled2d(const std::string& filename); + + + /// Initialize an empty image. + void init_(const box2d& b, unsigned bdr = border::thickness); + + /// Initialize an empty image. + //void init_(const std::string& filename); + + + /// Test if \p p is valid. + bool has(const point2d& p) const; + + /// Give the definition domain. + const box2d& domain() const; + + /// Give the bounding box domain. + const box2d& bbox() const; + + /// Read-only access to the image value located at point \p p. + const T& operator()(const point2d& p) const; + + /// Read-write access to the image value located at point \p p. + mln::value::proxy< tiled2d<T> > operator()(const point2d& p); + + // Read access to the image value located at point \p p. + const T& read_(const point2d& p) const; + + // Write access to the image value located at point \p p. + void write_(const point2d& p, const T& value); + + + template <typename P> + T& alt(const P& p) + { + typedef def::coord coord_t; + mln_precondition(this->has(p)); + + return this->data_->array_ [*(coord_t*)(&p.p_hook_())] [*((coord_t*)(&p.p_hook_()) + 1)]; + } + + + // Specific methods: + // ----------------- + + /// Read-only access to the image value located at (\p row, \p col). + const T& at_(unsigned row, unsigned col) const; + + /// Read-write access to the image value located at (\p row, \p col). + T& at_(unsigned row, unsigned col); + + /// Give the number of rows. + unsigned nrows() const; + + /// Give the number of columns. + unsigned ncols() const; + + + + /// Give the border thickness. + unsigned border() const; + + /// Give the number of elements (points including border ones). + unsigned nelements() const; + + /// Read-only access to the image value located at index \p i. + const T& element(unsigned i) const; + + /// Read-write access to the image value located at index \p i. + T& element(unsigned i); + + /// Give the delta-index corresponding to the delta-point \p dp. + int delta_index(const dpoint2d& dp) const; + + /// Give the point corresponding to the index \p i. + point2d point_at_index(unsigned i) const; + + + // Hooks + + /// Give a hook to the value buffer. + const std::fstream* buffer() const; + + /// Give a hook to the value buffer. + std::fstream* buffer(); + + /// Give a hook to the offset for accessing data. + const std::streampos pos_() const; + + /// Give a hook to the offset for accessing data. + std::streampos pos_(); + + + /// Resize image border with new_border. + void resize_(unsigned new_border); + }; + + + + // Forward declaration + + template <typename T> + void init_(tag::border_t, unsigned& bdr, const tiled2d<T>& model); + + template <typename T, typename J> + void init_(tag::image_t, mln::tiled2d<T>& target, const J& model); + + + +# ifndef MLN_INCLUDE_ONLY + + // init_ + + template <typename T> + inline + void init_(tag::border_t, unsigned& bdr, const tiled2d<T>& model) + { + bdr = model.border(); + } + + template <typename T, typename J> + inline + void init_(tag::image_t, tiled2d<T>& target, const J& model) + { + box2d b; + init_(tag::bbox, b, model); + unsigned bdr; + init_(tag::border, bdr, model); + target.init_(b, bdr); + } + + + // internal::data< tiled2d<T> > + + namespace internal + { + template <typename T> + inline + data< tiled2d<T> >::data(const box2d& b, unsigned bdr) + : b_ (b), + bdr_ (bdr) + { + allocate_(); + } + + /*template <typename T> + inline + data< tiled2d<T> >::data(const std::string& filename) + { + // FIXME + //b_ = make::box2d(buffer_.rows(), buffer_.columns()); + }*/ + + template <typename T> + inline + data< tiled2d<T> >::~data() + { + deallocate_(); + } + + template <typename T> + inline + void + data< tiled2d<T> >::update_vb_() + { + vb_.pmin() = b_.pmin() - dpoint2d(all_to(bdr_)); + vb_.pmax() = b_.pmax() + dpoint2d(all_to(bdr_)); + } + + template <typename T> + inline + void + data< tiled2d<T> >::allocate_() + { + update_vb_(); +// unsigned +// nr = vb_.len(0), +// nc = vb_.len(1); +// buffer_ = new T[nr * nc]; +// array_ = new T*[nr]; +// T* buf = buffer_ - vb_.pmin().col(); +// for (unsigned i = 0; i < nr; ++i) +// { +// array_[i] = buf; +// buf += nc; +// } +// array_ -= vb_.pmin().row(); + mln_postcondition(vb_.len(0) == b_.len(0) + 2 * bdr_); + mln_postcondition(vb_.len(1) == b_.len(1) + 2 * bdr_); + } + + template <typename T> + inline + void + data< tiled2d<T> >::deallocate_() + { +// if (f_) +// delete(f_); + } + + template <typename T> + inline + void + data< tiled2d<T> >::swap_(data< tiled2d<T> >& other_) + { + data< tiled2d<T> > self_ = *this; + *this = other_; + other_ = self_; + } + + template <typename T> + inline + void + data< tiled2d<T> >::reallocate_(unsigned new_border) + { + data< tiled2d<T> >& tmp = *(new data< tiled2d<T> >(this->b_, new_border)); + this->swap_(tmp); + } + + + } // end of namespace mln::internal + + + // tiled2d<T> + + template <typename T> + inline + tiled2d<T>::tiled2d() + { + } + + template <typename T> + inline + tiled2d<T>::tiled2d(const box2d& b, unsigned bdr) + { + init_(b, bdr); + } + + template <typename T> + inline + void + tiled2d<T>::init_(const box2d& b, unsigned bdr) + { + mln_precondition(! this->is_valid()); + this->data_ = new internal::data< tiled2d<T> >(b, bdr); + } + + /*template <typename T> + inline + tiled2d<T>::tiled2d(const std::string& filename) + { + init_(filename); + } + + template <typename T> + inline + void + tiled2d<T>::init_(const std::string& filename) + { + mln_precondition(! this->is_valid()); + this->data_ = new internal::data< tiled2d<T> >(filename); + }*/ + + template <typename T> + inline + const box2d& + tiled2d<T>::domain() const + { + mln_precondition(this->is_valid()); + return this->data_->b_; + } + + template <typename T> + inline + const box2d& + tiled2d<T>::bbox() const + { + mln_precondition(this->is_valid()); + return this->data_->b_; + } + + template <typename T> + inline + bool + tiled2d<T>::has(const point2d& p) const + { + mln_precondition(this->is_valid()); + return this->data_->vb_.has(p); + } + + template <typename T> + inline + const T& + tiled2d<T>::operator()(const point2d& p) const + { + return read_(p); + } + + template <typename T> + inline + mln::value::proxy< tiled2d<T> > + tiled2d<T>::operator()(const point2d& p) + { + mln::value::proxy<tiled2d> prx(*this, p); + return prx; + } + + template <typename T> + inline + const T& + tiled2d<T>::read_(const point2d& p) const + { + std::cout << "setting at point " << p << std::endl; // DELETEME + return this->data_->value_; + } + + template <typename T> + inline + void + tiled2d<T>::write_(const point2d& p, const T& value) + { + std::cout << "setting value " << value << " at point " << p << std::endl; // DELETEME + /*this->data_->pixel_cache = this->data_->buffer_.getPixels(p.col(), p.row(), p.col(), p.row()); + *(this->data_->pixel_cache) = Magick::ColorRGB(256 - value.red(), + 256 - value.green(), + 256 - value.blue());*/ + } + + + // Specific methods: + + template <typename T> + inline + const T& + tiled2d<T>::at_(unsigned row, unsigned col) const + { + mln_precondition(this->has(point2d(row, col))); + //FIXME: use the cache Luke. + this->data_->pixel_cache = this->data_->buffer_.getPixels(col, row, col, row); + this->data_->value_.red() = this->data_->pixel_cache->red % 256; + this->data_->value_.green() = this->data_->pixel_cache->green % 256; + this->data_->value_.blue() = this->data_->pixel_cache->blue % 256; + return this->data_->value_; + } + + template <typename T> + inline + T& + tiled2d<T>::at_(unsigned row, unsigned col) + { + mln_precondition(this->has(point2d(row, col))); + //FIXME: use the cache Luke. + this->data_->pixel_cache = this->data_->buffer_.getPixels(col, row, col, row); + this->data_->value_.red() = this->data_->pixel_cache->red % 256; + this->data_->value_.green() = this->data_->pixel_cache->green % 256; + this->data_->value_.blue() = this->data_->pixel_cache->blue % 256; + return this->data_->value_; + } + + template <typename T> + inline + unsigned + tiled2d<T>::nrows() const + { + mln_precondition(this->is_valid()); + return this->data_->b_.len(0); + } + + template <typename T> + inline + unsigned + tiled2d<T>::ncols() const + { + mln_precondition(this->is_valid()); + return this->data_->b_.len(1); + } + + + // Hooks. + + template <typename T> + inline + const std::fstream* + tiled2d<T>::buffer() const + { + mln_precondition(this->is_valid()); + return this->data_->f_; + } + + template <typename T> + inline + std::fstream* + tiled2d<T>::buffer() + { + mln_precondition(this->is_valid()); + return this->data_->f_; + } + + template <typename T> + inline + const std::streampos + tiled2d<T>::pos_() const + { + mln_precondition(this->is_valid()); + return this->data_->pos_; + } + + template <typename T> + inline + std::streampos + tiled2d<T>::pos_() + { + mln_precondition(this->is_valid()); + return this->data_->pos_; + } + + +# endif // ! MLN_INCLUDE_ONLY + +} // end of namespace mln + + + +# include <mln/core/trait/pixter.hh> +# include <mln/core/dpoints_pixter.hh> +# include <mln/core/pixter2d.hh> +// # include <mln/core/w_window.hh> + + +namespace mln +{ + + namespace trait + { + + // pixter + + template <typename T> + struct fwd_pixter< tiled2d<T> > + { + typedef fwd_pixter2d< tiled2d<T> > ret; + }; + + template <typename T> + struct fwd_pixter< const tiled2d<T> > + { + typedef fwd_pixter2d< const tiled2d<T> > ret; + }; + + template <typename T> + struct bkd_pixter< tiled2d<T> > + { + typedef bkd_pixter2d< tiled2d<T> > ret; + }; + + template <typename T> + struct bkd_pixter< const tiled2d<T> > + { + typedef bkd_pixter2d< const tiled2d<T> > ret; + }; + + // qixter + + template <typename T, typename W> + struct fwd_qixter< tiled2d<T>, W > + { + typedef dpoints_fwd_pixter< tiled2d<T> > ret; + }; + + template <typename T, typename W> + struct fwd_qixter< const tiled2d<T>, W > + { + typedef dpoints_fwd_pixter< const tiled2d<T> > ret; + }; + + template <typename T, typename W> + struct bkd_qixter< tiled2d<T>, W > + { + typedef dpoints_bkd_pixter< tiled2d<T> > ret; + }; + + template <typename T, typename W> + struct bkd_qixter< const tiled2d<T>, W > + { + typedef dpoints_bkd_pixter< const tiled2d<T> > ret; + }; + + // nixter + + template <typename T, typename N> + struct fwd_nixter< tiled2d<T>, N > + { + typedef dpoints_fwd_pixter< tiled2d<T> > ret; + }; + + template <typename T, typename N> + struct fwd_nixter< const tiled2d<T>, N > + { + typedef dpoints_fwd_pixter< const tiled2d<T> > ret; + }; + + template <typename T, typename N> + struct bkd_nixter< tiled2d<T>, N > + { + typedef dpoints_bkd_pixter< tiled2d<T> > ret; + }; + + template <typename T, typename N> + struct bkd_nixter< const tiled2d<T>, N > + { + typedef dpoints_bkd_pixter< const tiled2d<T> > ret; + }; + + } // end of namespace mln::trait + +} // end of namespace mln + + +# include <mln/make/image.hh> + + +#endif // ! MLN_CORE_IMAGE_TILED2D_HH Index: trunk/milena/sandbox/fabien/mln/data/fast_median.hh =================================================================== --- trunk/milena/sandbox/fabien/mln/data/fast_median.hh (revision 0) +++ trunk/milena/sandbox/fabien/mln/data/fast_median.hh (revision 4335) @@ -0,0 +1,180 @@ +// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena 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 Olena. If not, see <
http://www.gnu.org/licenses/
>. +// +// As a special exception, you may use this file as part of a free +// software project 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 MLN_DATA_FAST_MEDIAN_HH +# define MLN_DATA_FAST_MEDIAN_HH + +/*! \file + * + * \brief Fast Median filtering of an image. + * + * \todo There are implicit assumptions about input being 2D!!! + */ + +# include <mln/core/concept/image.hh> +# include <mln/core/alias/window2d.hh> +# include <mln/accu/stat/median_h.hh> + +# include <mln/win/shift.hh> +# include <mln/win/diff.hh> + +# include <mln/geom/min_col.hh> +# include <mln/geom/min_row.hh> +# include <mln/geom/max_col.hh> +# include <mln/geom/max_row.hh> + + +namespace mln +{ + + namespace data + { + + /*! Compute in \p output the median filter of image \p input by + * the window \p win. + * + * \param[in] input The image to be filtered. + * \param[in] win The window. + * \param[in,out] output The output image. + * + * \pre \p input and \p output have to be initialized. + */ + template <typename I, typename W, typename O> + void fast_median(const Image<I>& input, const Window<W>& win, + Image<O>& output); + + +# ifndef MLN_INCLUDE_ONLY + + + namespace impl + { + + template <typename I, typename W, typename O> + inline + void fast_median(const I& input, + const W& win, + O& output) + { + mln_precondition(input.is_valid()); + mln_precondition(output.is_valid()); + + def::coord + min_row = geom::min_row(input), max_row = geom::max_row(input), + min_col = geom::min_col(input), max_col = geom::max_col(input); + + window2d + win_fwd_plus = win - win::shift(win, left), + win_fwd_minus = win::shift(win, left) - win, + win_bkd_plus = win - win::shift(win, right), + win_bkd_minus = win::shift(win, right) - win, + win_bot = win - win::shift(win, up), + win_top = win::shift(win, up) - win; + + accu::stat::median_h<mln_value(I)> med; + + // initialization + + point2d p = input.domain().pmin() + up; + + mln_qixter(const I, window2d) + q_fp(input, win_fwd_plus, p), q_fm(input, win_fwd_minus, p), + q_bp(input, win_bkd_plus, p), q_bm(input, win_bkd_minus, p), + q_top(input, win_top, p), q_bot(input, win_bot, p); + + med.init(); + { + mln_qixter(const I, W) q(input, win, p); + for_all(q) + med.take(q.val()); + } + + def::coord& row = p.row(); + def::coord& col = p.col(); + bool fwd = true; + + mln_assertion(p.col() == min_col); + mln_assertion(p.row() == min_row - 1); + + for (row = min_row; row <= max_row; ++row) + { + + // "go down" + for_all(q_top) + med.untake(q_top.val()); + + for_all(q_bot) + med.take(q_bot.val()); + + output(p) = med; + + if (fwd) + // browse line fwd + while (col < max_col) + { + ++col; + for_all(q_fm) + med.untake(q_fm.val()); + for_all(q_fp) + med.take(q_fp.val()); + output(p) = med; + } + else + // browse line bkd + while (col > min_col) + { + --col; + for_all(q_bm) + med.untake(q_bm.val()); + for_all(q_bp) + med.take(q_bp.val()); + output(p) = med; + } + // change browsing + fwd = ! fwd; + } + } + + } // end of namespace mln::data::impl + + + // facade + + template <typename I, typename W, typename O> + inline + void fast_median(const Image<I>& input, const Window<W>& win, + Image<O>& output) + { + impl::fast_median(exact(input), exact(win), exact(output)); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::data + +} // end of namespace mln + + +#endif // ! MLN_DATA_FAST_MEDIAN_HH Index: trunk/milena/sandbox/fabien/mln/canvas/browsing/snake.hh =================================================================== --- trunk/milena/sandbox/fabien/mln/canvas/browsing/snake.hh (revision 0) +++ trunk/milena/sandbox/fabien/mln/canvas/browsing/snake.hh (revision 4335) @@ -0,0 +1,128 @@ +// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena 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 Olena. If not, see <
http://www.gnu.org/licenses/
>. +// +// As a special exception, you may use this file as part of a free +// software project 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 MLN_CANVAS_BROWSING_SNAKE_HH +# define MLN_CANVAS_BROWSING_SNAKE_HH + +/// \file +/// +/// Browsing in a snake-way, forward. + +# include <vector> +# include <mln/core/concept/browsing.hh> + + +namespace mln +{ + + namespace canvas + { + + namespace browsing + { + + template <typename I, typename W, typename F> + inline + mln_ch_value(I, mln_result(F)) + snake(const Image<I>& input, const Neighborhood<N>& nbh, F& functor); + + +# ifndef MLN_INCLUDE_ONLY + + template <typename I, typename W, typename F> + inline + mln_ch_value(I, mln_result(F)) + snake(const Image<I>& input_, const Neighborhood<N>& nbh, F& functor) + { + trace::entering("canvas::browsing::snake"); + + I input = exact(input_); + mln_precondition(input.is_valid()); + + // p init + f.p = f.input.bbox().pmin();// - f.dps[0]; + + std::vector< int > directions(f.moves.size(), 0); + unsigned deph = 0; + unsigned total_deph = f.moves.size() / 2 + 1; + + // initialization + f.init(); + + bool first = true; + directions[deph] = 1; + deph = total_deph - 1; + + // Call the move function (for the first point) + (f.*(f.moves[(deph - 1) * 2 - 1 + directions[deph - 1]])) (); + while (deph > 0) // If direction is empty, break + { + mln_assertion(deph <= total_deph); + mln_assertion(deph > 0); + // If f.p is near the border (we ended a direction) -> next child + if (!f.input.domain().has(f.p + + f.dps[(deph - 1) * 2 - 1 + directions[deph - 1]])) + { + // Go up the tree + deph--; + if (deph >= 1) + // Change directions + directions[deph] = directions[deph] == 1 ? 0 : 1; + continue; + } + + if (!first) + { + // Move f.p + f.p += f.dps[(deph - 1) * 2 - 1 + directions[deph - 1]]; + // Call the move function + (f.*(f.moves[(deph - 1) * 2 - 1 + directions[deph - 1]])) (); + } + else + first = false; + + if (deph != total_deph) + { + // Go down the tree + deph++; + first = true; + } + } + + trace::exiting("canvas::browsing::snake"); + } + + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::canvas::browsing + + } // end of namespace mln::canvas + +} // end of namespace mln + + +#endif // ! MLN_CANVAS_BROWSING_SNAKE_HH + Index: trunk/milena/sandbox/fabien/mln/canvas/browsing/directional.hh =================================================================== --- trunk/milena/sandbox/fabien/mln/canvas/browsing/directional.hh (revision 0) +++ trunk/milena/sandbox/fabien/mln/canvas/browsing/directional.hh (revision 4335) @@ -0,0 +1,157 @@ +// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena 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 Olena. If not, see <
http://www.gnu.org/licenses/
>. +// +// As a special exception, you may use this file as part of a free +// software project 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 MLN_CANVAS_BROWSING_DIRECTIONAL_HH +# define MLN_CANVAS_BROWSING_DIRECTIONAL_HH + +/// \file +/// +/// Directional browsing of an image. + +# include <mln/core/concept/browsing.hh> +# include <mln/core/concept/image.hh> + +namespace mln +{ + + namespace canvas + { + + namespace browsing + { + + /// Browsing in a certain direction. + /// + /// This canvas browse all the point of an image 'input' of type + /// 'I' and of dimension 'dim' in the direction 'dir'. + /// + /// The functor should provide (In addition to 'input', 'I', + /// 'dim' and 'dir') three methods : + /// + /// - init() : Will be called at the beginning. + /// - next() : Will be called at each point 'p' (also provided by + /// the fonctor). + /// - final(): Will be called at the end. + /// + /// F shall features : \n + /// { \n + /// --- as types: \n + /// I; \n + /// --- as attributes: \n + /// dim; \n + /// dir; // and test dir < dim \n + /// input; \n + /// p; \n + /// --- as methods: \n + /// void init(); \n + /// void next(); \n + /// void final(); \n + /// } \n + /// + /// Example : \n + /// + /// 1 0 0 + /// 2 0 0 + /// 3 0 0 + /// + /// 4 0 0 + /// 5 0 0 + /// 6 0 0 + /// + /// 7 0 0 + /// 8 0 0 + /// 9 0 0 + /// + /// + /// + template<typename I, typename W, typename F> + inline + void + directional(const Image<I>& input, F& functor); + + +# ifndef MLN_INCLUDE_ONLY + + template <typename I, typename W, typename F> + inline + void + directional(const Image<I>& input_, F& functor) + { + trace::entering("canvas::browsing::directional"); + + const I& input = exact(input_); + + mln_precondition(f.dir < f.dim); + + mln_psite(I) + pmin = f.input.domain().pmin(), + pmax = f.input.domain().pmax(); + + f.p = pmin; + + f.init(); + + do + { + + // Browse the run + f.init_run(); + while (f.p[f.dir] <= pmax[f.dir]) + { + f.next(); + ++f.p[f.dir]; + } + f.p[f.dir] = pmin[f.dir]; + + + // Select the next run start + for (int c = F::dim - 1; c >= 0; --c) + { + if (c == int(f.dir)) + continue; + if (f.p[c] != pmax[c]) + { + ++f.p[c]; + break; + } + f.p[c] = pmin[c]; + } + + } while (f.p != pmin); + + f.final(); + + trace::exiting("canvas::browsing::directional"); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::canvas::browsing + + } // end of namespace mln::canvas + +} // end of namespace mln + +#endif // ! MLN_CANVAS_BROWSING_DIRECTIONAL_HH Index: trunk/milena/sandbox/fabien/magick/Makefile =================================================================== --- trunk/milena/sandbox/fabien/magick/Makefile (revision 4334) +++ trunk/milena/sandbox/fabien/magick/Makefile (revision 4335) @@ -1,12 +1,14 @@ -CXX = llvm-g++ -CXXFLAGS = -DNDEBUG -O4 +CXX = g++ +CXXFLAGS = -DNDEBUG -O1 LIBS = `Magick++-config --cppflags --cxxflags --ldflags --libs` INC = -I../../../ -all: magick magick: magick.cc ${CXX} ${INC} ${LIBS} $^ -o mln_magick save: save.cc ${CXX} ${INC} ${LIBS} $^ -o magick_save + +tiled: tiled_image.cc + ${CXX} ${INC} ${LIBS} $^ -o tiled
15 years, 4 months
1
0
0
0
← Newer
1
...
8
9
10
11
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
Results per page:
10
25
50
100
200