Olena-patches
Threads by month
- ----- 2025 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
June 2005
- 8 participants
- 22 discussions
Index: ChangeLog
from Christophe Berger <christophe(a)lrde.epita.fr>
* oln/appli/astro/graphical_interface: New.
* oln/appli/astro/graphical_interface/interface.pro: New.
* oln/appli/astro/graphical_interface/image_viewer.hh: New.
* oln/appli/astro/graphical_interface/visualization_window.ui: New.
* oln/appli/astro/graphical_interface/filterinterface.hh: New.
* oln/appli/astro/graphical_interface/main.cc: New.
* oln/appli/astro/graphical_interface/qtincludes.hh: New.
* oln/appli/astro/graphical_interface/Readme: New.
* oln/appli/astro/graphical_interface/utils.hh: New.
Readme | 15 +
filterinterface.hh | 180 +++++++++++++++++++++++
image_viewer.hh | 147 ++++++++++++++++++
interface.pro | 17 ++
main.cc | 59 +++++++
qtincludes.hh | 35 ++++
utils.hh | 50 ++++++
visualization_window.ui | 375 ++++++++++++++++++++++++++++++++++++++++++++++++
8 files changed, 878 insertions(+)
Index: oln/appli/astro/graphical_interface/main.cc
--- oln/appli/astro/graphical_interface/main.cc (revision 0)
+++ oln/appli/astro/graphical_interface/main.cc (revision 0)
@@ -0,0 +1,59 @@
+// Copyright (C) 2005 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#include <oln/basics2d.hh>
+#include <ntg/real/int_u.hh>
+#include <oln/fancy/iota.hh>
+#include <oln/fancy/print.hh>
+#include <oln/appli/astro/clean.hh>
+#include <oln/io/write_image.hh>
+#include <oln/io/read_image.hh>
+#include <qapplication.h>
+#include "filterinterface.hh"
+
+int main(int argc, char * argv[])
+{
+ typedef oln::image_with_nbh<oln::image2d<ntg::int_u8>, oln::neighborhood2d> ima_type;
+
+ QApplication app(argc, argv);
+
+ if (argc < 2)
+ {
+ std::cout << "Usage: " << argv[0] << " <image_file>" << std::endl;
+ return 1;
+ }
+
+ oln::image2d<ntg::int_u8> ima_raw;
+ ima_raw = oln::io::read(argv[1]);
+ ima_type ima(ima_raw, oln::neighb_c4());
+ oln::appli::astro::clean<ima_type> mt(ima);
+
+ FilterVisualizationWindow win(argv[1], mt);
+ app.setMainWidget(&win);
+ win.show();
+ return app.exec();
+}
Index: oln/appli/astro/graphical_interface/visualization_window.ui
--- oln/appli/astro/graphical_interface/visualization_window.ui (revision 0)
+++ oln/appli/astro/graphical_interface/visualization_window.ui (revision 0)
@@ -0,0 +1,375 @@
+<!DOCTYPE UI><UI version="3.3" stdsetdef="1">
+<class>visualisation_window</class>
+<widget class="QMainWindow">
+ <property name="name">
+ <cstring>visualisation_window</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>583</width>
+ <height>467</height>
+ </rect>
+ </property>
+ <property name="caption">
+ <string>Connected Filters</string>
+ </property>
+ <widget class="QPushButton">
+ <property name="name">
+ <cstring>compute_button</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>20</x>
+ <y>70</y>
+ <width>120</width>
+ <height>31</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Compute tree</string>
+ </property>
+ </widget>
+ <widget class="QPushButton">
+ <property name="name">
+ <cstring>view_input_image_button</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>20</x>
+ <y>20</y>
+ <width>120</width>
+ <height>30</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Display input</string>
+ </property>
+ </widget>
+ <widget class="QPushButton">
+ <property name="name">
+ <cstring>save_result_button</cstring>
+ </property>
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>20</x>
+ <y>190</y>
+ <width>120</width>
+ <height>31</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Save result</string>
+ </property>
+ </widget>
+ <widget class="QPushButton">
+ <property name="name">
+ <cstring>redraw_button</cstring>
+ </property>
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>20</x>
+ <y>120</y>
+ <width>120</width>
+ <height>31</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Redraw output</string>
+ </property>
+ </widget>
+ <widget class="QLabel">
+ <property name="name">
+ <cstring>text_intro</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>210</x>
+ <y>20</y>
+ <width>190</width>
+ <height>45</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Please choose attributes
+you want to use :</string>
+ </property>
+ </widget>
+ <widget class="QLabel">
+ <property name="name">
+ <cstring>text_state</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>20</x>
+ <y>390</y>
+ <width>540</width>
+ <height>30</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string></string>
+ </property>
+ </widget>
+ <widget class="QSpinBox">
+ <property name="name">
+ <cstring>value_height</cstring>
+ </property>
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>330</x>
+ <y>180</y>
+ <width>59</width>
+ <height>29</height>
+ </rect>
+ </property>
+ <property name="maxValue">
+ <number>999999</number>
+ </property>
+ </widget>
+ <widget class="QCheckBox">
+ <property name="name">
+ <cstring>active_tower</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>230</x>
+ <y>330</y>
+ <width>180</width>
+ <height>26</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Rectangular "towers"</string>
+ </property>
+ </widget>
+ <widget class="QCheckBox">
+ <property name="name">
+ <cstring>active_center_point</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>230</x>
+ <y>280</y>
+ <width>120</width>
+ <height>26</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Center point</string>
+ </property>
+ </widget>
+ <widget class="QCheckBox">
+ <property name="name">
+ <cstring>active_circle</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>230</x>
+ <y>230</y>
+ <width>80</width>
+ <height>26</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Circle</string>
+ </property>
+ </widget>
+ <widget class="QCheckBox">
+ <property name="name">
+ <cstring>active_height</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>230</x>
+ <y>180</y>
+ <width>80</width>
+ <height>26</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Height</string>
+ </property>
+ </widget>
+ <widget class="QCheckBox">
+ <property name="name">
+ <cstring>active_area</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>230</x>
+ <y>130</y>
+ <width>80</width>
+ <height>26</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Area</string>
+ </property>
+ </widget>
+ <widget class="QCheckBox">
+ <property name="name">
+ <cstring>active_level</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>230</x>
+ <y>80</y>
+ <width>80</width>
+ <height>26</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Level</string>
+ </property>
+ </widget>
+ <widget class="QSpinBox">
+ <property name="name">
+ <cstring>value_area</cstring>
+ </property>
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>330</x>
+ <y>130</y>
+ <width>60</width>
+ <height>31</height>
+ </rect>
+ </property>
+ <property name="maxValue">
+ <number>999999</number>
+ </property>
+ <property name="value">
+ <number>0</number>
+ </property>
+ </widget>
+ <widget class="QSpinBox">
+ <property name="name">
+ <cstring>value_level</cstring>
+ </property>
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>330</x>
+ <y>80</y>
+ <width>60</width>
+ <height>29</height>
+ </rect>
+ </property>
+ <property name="maxValue">
+ <number>255</number>
+ </property>
+ </widget>
+</widget>
+<toolbars>
+</toolbars>
+<connections>
+ <connection>
+ <sender>compute_button</sender>
+ <signal>clicked()</signal>
+ <receiver>visualisation_window</receiver>
+ <slot>ComputeTree()</slot>
+ </connection>
+ <connection>
+ <sender>redraw_button</sender>
+ <signal>clicked()</signal>
+ <receiver>visualisation_window</receiver>
+ <slot>DisplayImage()</slot>
+ </connection>
+ <connection>
+ <sender>save_result_button</sender>
+ <signal>clicked()</signal>
+ <receiver>visualisation_window</receiver>
+ <slot>SaveResult()</slot>
+ </connection>
+ <connection>
+ <sender>value_area</sender>
+ <signal>valueChanged(int)</signal>
+ <receiver>visualisation_window</receiver>
+ <slot>UpdateValues()</slot>
+ </connection>
+ <connection>
+ <sender>value_height</sender>
+ <signal>valueChanged(int)</signal>
+ <receiver>visualisation_window</receiver>
+ <slot>UpdateValues()</slot>
+ </connection>
+ <connection>
+ <sender>value_level</sender>
+ <signal>valueChanged(int)</signal>
+ <receiver>visualisation_window</receiver>
+ <slot>UpdateValues()</slot>
+ </connection>
+ <connection>
+ <sender>view_input_image_button</sender>
+ <signal>clicked()</signal>
+ <receiver>visualisation_window</receiver>
+ <slot>DisplayInputImage()</slot>
+ </connection>
+ <connection>
+ <sender>active_area</sender>
+ <signal>stateChanged(int)</signal>
+ <receiver>visualisation_window</receiver>
+ <slot>Attribute_area()</slot>
+ </connection>
+ <connection>
+ <sender>active_center_point</sender>
+ <signal>stateChanged(int)</signal>
+ <receiver>visualisation_window</receiver>
+ <slot>Attribute_center_point()</slot>
+ </connection>
+ <connection>
+ <sender>active_circle</sender>
+ <signal>stateChanged(int)</signal>
+ <receiver>visualisation_window</receiver>
+ <slot>Attribute_circle()</slot>
+ </connection>
+ <connection>
+ <sender>active_height</sender>
+ <signal>stateChanged(int)</signal>
+ <receiver>visualisation_window</receiver>
+ <slot>Attribute_height()</slot>
+ </connection>
+ <connection>
+ <sender>active_level</sender>
+ <signal>stateChanged(int)</signal>
+ <receiver>visualisation_window</receiver>
+ <slot>Attribute_level()</slot>
+ </connection>
+ <connection>
+ <sender>active_tower</sender>
+ <signal>stateChanged(int)</signal>
+ <receiver>visualisation_window</receiver>
+ <slot>Attribute_tower()</slot>
+ </connection>
+</connections>
+<slots>
+ <slot>DisplayImage()</slot>
+ <slot>UpdateValues()</slot>
+ <slot>ComputeTree()</slot>
+ <slot>DisplayInputImage()</slot>
+ <slot>SaveResult()</slot>
+ <slot>Attribute_level()</slot>
+ <slot>Attribute_area()</slot>
+ <slot>Attribute_height()</slot>
+ <slot>Attribute_center_point()</slot>
+ <slot>Attribute_circle()</slot>
+ <slot>Attribute_tower()</slot>
+</slots>
+<pixmapinproject/>
+<layoutdefaults spacing="6" margin="11"/>
+</UI>
Index: oln/appli/astro/graphical_interface/utils.hh
--- oln/appli/astro/graphical_interface/utils.hh (revision 0)
+++ oln/appli/astro/graphical_interface/utils.hh (revision 0)
@@ -0,0 +1,50 @@
+// Copyright (C) 2005 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef _UTILS_HH_
+# define _UTILS_HH_
+
+namespace Utils {
+ std::string int2string(int inum)
+ {
+ using namespace std;
+ ostringstream oss;
+ oss << inum;
+ string snum(oss.str());
+ return snum;
+ }
+ int string2int(std::string snum)
+ {
+ using namespace std;
+ istringstream iss(snum);
+ int inum;
+ iss >> inum;
+ return inum;
+ }
+}
+
+#endif // !_UTILS_HH_
Index: oln/appli/astro/graphical_interface/image_viewer.hh
--- oln/appli/astro/graphical_interface/image_viewer.hh (revision 0)
+++ oln/appli/astro/graphical_interface/image_viewer.hh (revision 0)
@@ -0,0 +1,147 @@
+// Copyright (C) 2005 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef _IMAGE_VIEWER_HH_
+# define _IMAGE_VIEWER_HH_
+# include "qtincludes.hh"
+
+class image_viewer : public QWidget
+{
+
+public:
+
+ QImage img_;
+ int loaded;
+ int h_;
+ int w_;
+ double coeff_;
+
+ image_viewer()
+ {
+ loaded = 0;
+ }
+
+ ~image_viewer()
+ {
+ close();
+ }
+
+ void load(const char *fname)
+ {
+ loaded = 1;
+ if (!img_.load(fname))
+ {
+ setCaption((std::string("LOAD FAILED ") + fname).c_str());
+ resize(width(), 200);
+ resize(height(), 200);
+ loaded = 0;
+ return;
+ }
+ w_ = img_.width();
+ h_ = img_.height();
+ coeff_ = 1;
+ resize_window(w_, h_);
+ };
+
+ void reload(const char *fname)
+ {
+ if (!loaded)
+ load(fname);
+ else
+ {
+ double scoeff = coeff_;
+ QWMatrix m;
+ load(fname);
+ coeff_ = scoeff;
+ m.scale(coeff_, coeff_);
+ img_ = img_.xForm(m);
+ }
+ resize_window(img_.width(), img_.height());
+ }
+
+ void resize_window(int w, int h)
+ {
+ resize(w, h);
+ setMinimumSize(w, h);
+ setMaximumSize(w, h);
+ }
+
+ void resize_image(int scale_type)
+ {
+ QWMatrix m;
+ if (scale_type < 0)
+ {
+ m.scale(0.5, 0.5);
+ coeff_ *= 0.5;
+ }
+ else if (scale_type > 0)
+ {
+ m.scale(2, 2);
+ coeff_ *= 2;
+ }
+ else
+ {
+ m.scale(coeff_, coeff_);
+ coeff_ = 1;
+ }
+ img_ = img_.xForm(m);
+ resize_window(img_.width(), img_.height());
+ }
+
+
+protected:
+
+ void closeEvent(QCloseEvent *e)
+ {
+ hide();
+ };
+
+ void paintEvent(QPaintEvent *pe)
+ {
+ if (!loaded) return;
+ bitBlt(this, 0, 0, &img_, 0, 0, img_.width(), img_.height(), CopyROP);
+ };
+
+ void mouseReleaseEvent(QMouseEvent * e)
+ {
+ switch(e->button())
+ {
+ case LeftButton:
+ resize_image(-1);
+ break;
+ case RightButton:
+ resize_image(1);
+ break;
+ case MidButton:
+ resize_image(0);
+ break;
+ }
+ }
+
+};
+
+#endif // !_IMAGE_VIEWER_HH_
Index: oln/appli/astro/graphical_interface/qtincludes.hh
--- oln/appli/astro/graphical_interface/qtincludes.hh (revision 0)
+++ oln/appli/astro/graphical_interface/qtincludes.hh (revision 0)
@@ -0,0 +1,35 @@
+// Copyright (C) 2005 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#include <qapplication.h>
+#include <qpushbutton.h>
+#include <qlabel.h>
+#include <qimage.h>
+#include <qwmatrix.h>
+#include <qslider.h>
+#include <qcheckbox.h>
+#include <qspinbox.h>
Index: oln/appli/astro/graphical_interface/interface.pro
--- oln/appli/astro/graphical_interface/interface.pro (revision 0)
+++ oln/appli/astro/graphical_interface/interface.pro (revision 0)
@@ -0,0 +1,17 @@
+TEMPLATE = app
+LANGUAGE = C++
+
+INCLUDEPATH += .
+
+SOURCES += main.cc
+
+HEADERS += filterinterface.hh image_viewer.hh qtincludes.hh utils.hh
+
+FORMS = visualization_window.ui
+
+######################################################################
+# Automatically generated by qmake (1.07a) Wed May 25 10:08:50 2005
+######################################################################
+
+
+# Input
Index: oln/appli/astro/graphical_interface/Readme
--- oln/appli/astro/graphical_interface/Readme (revision 0)
+++ oln/appli/astro/graphical_interface/Readme (revision 0)
@@ -0,0 +1,15 @@
+you will need qt3 library (and headers) to compile this graphical interface.
+
+to create the Makefile just type:
+qmake
+
+You will need to edit the Makefile to insert the include paths for Olena:
+INCPATH = .... -I/path/to/olena/metalic -I/path/to/olena/integre \
+ -I/path/to/olena/olena
+
+Please also delete "-W" and "-Wall" from the following lines :
+CFLAGS = ...
+CXXFLAGS = ...
+
+You can add -DNDEBUG to these lines.
+
Index: oln/appli/astro/graphical_interface/filterinterface.hh
--- oln/appli/astro/graphical_interface/filterinterface.hh (revision 0)
+++ oln/appli/astro/graphical_interface/filterinterface.hh (revision 0)
@@ -0,0 +1,180 @@
+// Copyright (C) 2005 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef _FILTERINTERFACE_HH_
+# define _FILTERINTERFACE_HH_
+# include <string>
+# include <oln/appli/astro/clean.hh>
+# include "qtincludes.hh"
+# include "visualization_window.h"
+# include "image_viewer.hh"
+# include "utils.hh"
+
+class FilterVisualizationWindow : public visualisation_window
+{
+
+public:
+
+ typedef oln::image_with_nbh<oln::image2d<ntg::int_u8>, oln::neighborhood2d> ima_type;
+
+ FilterVisualizationWindow(const std::string& input_file_,
+ oln::appli::astro::clean<ima_type>& mt)
+ : mt_(mt), input_file_(input_file_)
+ {
+ display_in_.reload(input_file_.c_str());
+ display_in_.hide();
+ display_out_.hide();
+ sprintf(tmp_, "/tmp/olni.XXXXXX");
+ mkstemp(tmp_);
+ sprintf(tmp_ + 16, ".pgm");
+ }
+
+ ~FilterVisualizationWindow() {}
+
+ virtual void UpdateValues()
+ {
+ mt_.set_area(value_area->value());
+ mt_.set_level(value_level->value());
+ mt_.set_height(value_height->value());
+ std::string out = "attributes value changed.";// area("
+// + Utils::int2string(value_area->value())
+// + "), point_value("
+// + Utils::int2string(value_level->value())
+// + ")";
+ this->text_state->setText(out.c_str());
+ }
+
+ virtual void ComputeTree()
+ {
+ this->text_state->setText("computing tree, please wait...");
+ this->compute_button->setEnabled(false);
+
+ mt_.compute_tree();
+
+ this->redraw_button->setEnabled(true);
+ this->save_result_button->setEnabled(true);
+ this->text_state->setText("Tree computed, please choose attributes'values to draw the result.");
+ }
+
+ virtual void DisplayImage()
+ {
+ this->text_state->setText("computing resulting image, please wait...");
+ mt_.filter_process();
+ oln::io::write(mt_.output, tmp_);
+ this->text_state->setText("displaying result");
+ display_out_.reload(tmp_);
+ this->text_state->setText("");
+ display_out_.show();
+ }
+
+ virtual void DisplayInputImage()
+ {
+ display_in_.show();
+ }
+
+ virtual void SaveResult()
+ {
+ this->text_state->setText("saving resulting image, please wait...");
+ oln::io::write(mt_.output, "./out.pgm");
+ this->text_state->setText("image succesfully saved to ./out.pgm");
+ }
+
+ virtual void Attribute_area()
+ {
+ if (this->active_area->isChecked())
+ {
+ this->value_area->setEnabled(true);
+ mt_.area_tag_ = true;
+ }
+ else
+ {
+ this->value_area->setEnabled(false);
+ mt_.area_tag_ = false;
+ }
+ }
+
+ virtual void Attribute_level()
+ {
+ if (this->active_level->isChecked())
+ {
+ this->value_level->setEnabled(true);
+ mt_.level_tag_ = true;
+ }
+ else
+ {
+ this->value_level->setEnabled(false);
+ mt_.level_tag_ = false;
+ }
+ }
+
+ virtual void Attribute_height()
+ {
+ if (this->active_height->isChecked())
+ {
+ this->value_height->setEnabled(true);
+ mt_.height_tag_ = true;
+ }
+ else
+ {
+ this->value_height->setEnabled(false);
+ mt_.height_tag_ = false;
+ }
+ }
+
+ virtual void Attribute_circle()
+ {
+ if (this->active_circle->isChecked())
+ mt_.circle_tag_ = true;
+ else
+ mt_.circle_tag_ = false;
+ }
+
+ virtual void Attribute_center_point()
+ {
+ if (this->active_center_point->isChecked())
+ mt_.center_p_tag_ = true;
+ else
+ mt_.center_p_tag_ = false;
+ }
+
+ virtual void Attribute_tower()
+ {
+ if (this->active_tower->isChecked())
+ mt_.tour_tag_ = true;
+ else
+ mt_.tour_tag_ = false;
+ }
+
+protected:
+ oln::appli::astro::clean<ima_type>& mt_;
+ image_viewer display_in_;
+ image_viewer display_out_;
+ std::string input_file_;
+ char tmp_[21];
+};
+
+#endif // !_FILTERINTERFACE_HH_
3
2
Index: ChangeLog
from Christophe Berger <christophe(a)lrde.epita.fr>
* oln/appli/astro/tree_coherance_checks.hh: Update doc.
* oln/appli/astro/tree_statistics.hh: Add count of local root.
* oln/appli/astro/graphical_interface/interface.pro: Qmake options to compile without -w -Wall.
* oln/appli/astro/graphical_interface/visualization_window.ui: Add options in interface.
* oln/appli/astro/graphical_interface/filterinterface.hh: Handle these options.
graphical_interface/filterinterface.hh | 45 ++-
graphical_interface/interface.pro | 6
graphical_interface/visualization_window.ui | 347 ++++++++++++++++++++++------
tree_coherance_checks.hh | 22 -
tree_statistics.hh | 60 ++++
5 files changed, 375 insertions(+), 105 deletions(-)
Index: oln/appli/astro/graphical_interface/visualization_window.ui
--- oln/appli/astro/graphical_interface/visualization_window.ui (revision 214)
+++ oln/appli/astro/graphical_interface/visualization_window.ui (working copy)
@@ -118,133 +118,148 @@
<string></string>
</property>
</widget>
- <widget class="QSpinBox">
+ <widget class="QLabel">
<property name="name">
- <cstring>value_height</cstring>
- </property>
- <property name="enabled">
- <bool>false</bool>
+ <cstring>area_min</cstring>
</property>
<property name="geometry">
<rect>
- <x>330</x>
- <y>180</y>
- <width>59</width>
- <height>29</height>
+ <x>310</x>
+ <y>130</y>
+ <width>30</width>
+ <height>31</height>
</rect>
</property>
- <property name="maxValue">
- <number>999999</number>
+ <property name="text">
+ <string>min</string>
</property>
</widget>
<widget class="QCheckBox">
<property name="name">
- <cstring>active_tower</cstring>
+ <cstring>active_level</cstring>
</property>
<property name="geometry">
<rect>
<x>230</x>
- <y>330</y>
- <width>180</width>
+ <y>80</y>
+ <width>80</width>
<height>26</height>
</rect>
</property>
<property name="text">
- <string>Rectangular "towers"</string>
+ <string>Level</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
</property>
</widget>
<widget class="QCheckBox">
<property name="name">
- <cstring>active_center_point</cstring>
+ <cstring>active_area</cstring>
</property>
<property name="geometry">
<rect>
<x>230</x>
- <y>280</y>
- <width>120</width>
+ <y>130</y>
+ <width>80</width>
<height>26</height>
</rect>
</property>
<property name="text">
- <string>Center point</string>
+ <string>Area</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
</property>
</widget>
<widget class="QCheckBox">
<property name="name">
- <cstring>active_circle</cstring>
+ <cstring>active_height</cstring>
</property>
<property name="geometry">
<rect>
<x>230</x>
- <y>230</y>
+ <y>180</y>
<width>80</width>
<height>26</height>
</rect>
</property>
<property name="text">
- <string>Circle</string>
+ <string>Height</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
</property>
</widget>
<widget class="QCheckBox">
<property name="name">
- <cstring>active_height</cstring>
+ <cstring>active_circle</cstring>
</property>
<property name="geometry">
<rect>
<x>230</x>
- <y>180</y>
+ <y>230</y>
<width>80</width>
<height>26</height>
</rect>
</property>
<property name="text">
- <string>Height</string>
+ <string>Circle</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
</property>
</widget>
<widget class="QCheckBox">
<property name="name">
- <cstring>active_area</cstring>
+ <cstring>active_center_point</cstring>
</property>
<property name="geometry">
<rect>
<x>230</x>
- <y>130</y>
- <width>80</width>
+ <y>280</y>
+ <width>120</width>
<height>26</height>
</rect>
</property>
<property name="text">
- <string>Area</string>
+ <string>Center point</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
</property>
</widget>
<widget class="QCheckBox">
<property name="name">
- <cstring>active_level</cstring>
+ <cstring>active_tower</cstring>
</property>
<property name="geometry">
<rect>
<x>230</x>
- <y>80</y>
- <width>80</width>
+ <y>330</y>
+ <width>180</width>
<height>26</height>
</rect>
</property>
<property name="text">
- <string>Level</string>
+ <string>Rectangular "towers"</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
</property>
</widget>
<widget class="QSpinBox">
<property name="name">
- <cstring>value_area</cstring>
+ <cstring>value_area_min</cstring>
</property>
<property name="enabled">
- <bool>false</bool>
+ <bool>true</bool>
</property>
<property name="geometry">
<rect>
- <x>330</x>
+ <x>350</x>
<y>130</y>
- <width>60</width>
+ <width>80</width>
<height>31</height>
</rect>
</property>
@@ -257,16 +272,57 @@
</widget>
<widget class="QSpinBox">
<property name="name">
+ <cstring>value_area_max</cstring>
+ </property>
+ <property name="enabled">
+ <bool>true</bool>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>490</x>
+ <y>130</y>
+ <width>80</width>
+ <height>31</height>
+ </rect>
+ </property>
+ <property name="maxValue">
+ <number>999999</number>
+ </property>
+ <property name="lineStep">
+ <number>0</number>
+ </property>
+ <property name="value">
+ <number>999999</number>
+ </property>
+ </widget>
+ <widget class="QLabel">
+ <property name="name">
+ <cstring>area_min_2</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>450</x>
+ <y>130</y>
+ <width>30</width>
+ <height>31</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>max</string>
+ </property>
+ </widget>
+ <widget class="QSpinBox">
+ <property name="name">
<cstring>value_level</cstring>
</property>
<property name="enabled">
- <bool>false</bool>
+ <bool>true</bool>
</property>
<property name="geometry">
<rect>
- <x>330</x>
+ <x>350</x>
<y>80</y>
- <width>60</width>
+ <width>80</width>
<height>29</height>
</rect>
</property>
@@ -274,11 +330,174 @@
<number>255</number>
</property>
</widget>
+ <widget class="QSpinBox">
+ <property name="name">
+ <cstring>value_height</cstring>
+ </property>
+ <property name="enabled">
+ <bool>true</bool>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>350</x>
+ <y>180</y>
+ <width>80</width>
+ <height>29</height>
+ </rect>
+ </property>
+ <property name="maxValue">
+ <number>999999</number>
+ </property>
+ </widget>
+ <widget class="QLabel">
+ <property name="name">
+ <cstring>textLabel2_3</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>440</x>
+ <y>230</y>
+ <width>20</width>
+ <height>30</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>%</string>
+ </property>
+ </widget>
+ <widget class="QLabel">
+ <property name="name">
+ <cstring>textLabel2</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>440</x>
+ <y>280</y>
+ <width>20</width>
+ <height>30</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>%</string>
+ </property>
+ </widget>
+ <widget class="QSpinBox">
+ <property name="name">
+ <cstring>value_center_point</cstring>
+ </property>
+ <property name="enabled">
+ <bool>true</bool>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>350</x>
+ <y>280</y>
+ <width>80</width>
+ <height>31</height>
+ </rect>
+ </property>
+ <property name="maxValue">
+ <number>100</number>
+ </property>
+ </widget>
+ <widget class="QLabel">
+ <property name="name">
+ <cstring>textLabel2_2</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>500</x>
+ <y>330</y>
+ <width>20</width>
+ <height>30</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>%</string>
+ </property>
+ </widget>
+ <widget class="QSpinBox">
+ <property name="name">
+ <cstring>value_tower</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>420</x>
+ <y>330</y>
+ <width>70</width>
+ <height>31</height>
+ </rect>
+ </property>
+ <property name="maxValue">
+ <number>100</number>
+ </property>
+ </widget>
+ <widget class="QSpinBox">
+ <property name="name">
+ <cstring>value_circle</cstring>
+ </property>
+ <property name="enabled">
+ <bool>true</bool>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>350</x>
+ <y>230</y>
+ <width>80</width>
+ <height>31</height>
+ </rect>
+ </property>
+ <property name="maxValue">
+ <number>100</number>
+ </property>
+ </widget>
</widget>
<toolbars>
</toolbars>
<connections>
<connection>
+ <sender>value_tower</sender>
+ <signal>valueChanged(int)</signal>
+ <receiver>visualisation_window</receiver>
+ <slot>UpdateValues()</slot>
+ </connection>
+ <connection>
+ <sender>active_area</sender>
+ <signal>stateChanged(int)</signal>
+ <receiver>visualisation_window</receiver>
+ <slot>Attribute_area()</slot>
+ </connection>
+ <connection>
+ <sender>active_center_point</sender>
+ <signal>stateChanged(int)</signal>
+ <receiver>visualisation_window</receiver>
+ <slot>Attribute_center_point()</slot>
+ </connection>
+ <connection>
+ <sender>active_circle</sender>
+ <signal>stateChanged(int)</signal>
+ <receiver>visualisation_window</receiver>
+ <slot>Attribute_circle()</slot>
+ </connection>
+ <connection>
+ <sender>active_height</sender>
+ <signal>stateChanged(int)</signal>
+ <receiver>visualisation_window</receiver>
+ <slot>Attribute_height()</slot>
+ </connection>
+ <connection>
+ <sender>active_level</sender>
+ <signal>stateChanged(int)</signal>
+ <receiver>visualisation_window</receiver>
+ <slot>Attribute_level()</slot>
+ </connection>
+ <connection>
+ <sender>active_tower</sender>
+ <signal>stateChanged(int)</signal>
+ <receiver>visualisation_window</receiver>
+ <slot>Attribute_tower()</slot>
+ </connection>
+ <connection>
<sender>compute_button</sender>
<signal>clicked()</signal>
<receiver>visualisation_window</receiver>
@@ -297,64 +516,46 @@
<slot>SaveResult()</slot>
</connection>
<connection>
- <sender>value_area</sender>
+ <sender>value_area_max</sender>
<signal>valueChanged(int)</signal>
<receiver>visualisation_window</receiver>
<slot>UpdateValues()</slot>
</connection>
<connection>
- <sender>value_height</sender>
+ <sender>value_area_min</sender>
<signal>valueChanged(int)</signal>
<receiver>visualisation_window</receiver>
<slot>UpdateValues()</slot>
</connection>
<connection>
- <sender>value_level</sender>
+ <sender>value_center_point</sender>
<signal>valueChanged(int)</signal>
<receiver>visualisation_window</receiver>
<slot>UpdateValues()</slot>
</connection>
<connection>
- <sender>view_input_image_button</sender>
- <signal>clicked()</signal>
- <receiver>visualisation_window</receiver>
- <slot>DisplayInputImage()</slot>
- </connection>
- <connection>
- <sender>active_area</sender>
- <signal>stateChanged(int)</signal>
- <receiver>visualisation_window</receiver>
- <slot>Attribute_area()</slot>
- </connection>
- <connection>
- <sender>active_center_point</sender>
- <signal>stateChanged(int)</signal>
- <receiver>visualisation_window</receiver>
- <slot>Attribute_center_point()</slot>
- </connection>
- <connection>
- <sender>active_circle</sender>
- <signal>stateChanged(int)</signal>
+ <sender>value_height</sender>
+ <signal>valueChanged(int)</signal>
<receiver>visualisation_window</receiver>
- <slot>Attribute_circle()</slot>
+ <slot>UpdateValues()</slot>
</connection>
<connection>
- <sender>active_height</sender>
- <signal>stateChanged(int)</signal>
+ <sender>value_level</sender>
+ <signal>valueChanged(int)</signal>
<receiver>visualisation_window</receiver>
- <slot>Attribute_height()</slot>
+ <slot>UpdateValues()</slot>
</connection>
<connection>
- <sender>active_level</sender>
- <signal>stateChanged(int)</signal>
+ <sender>view_input_image_button</sender>
+ <signal>clicked()</signal>
<receiver>visualisation_window</receiver>
- <slot>Attribute_level()</slot>
+ <slot>DisplayInputImage()</slot>
</connection>
<connection>
- <sender>active_tower</sender>
- <signal>stateChanged(int)</signal>
+ <sender>value_circle</sender>
+ <signal>valueChanged(int)</signal>
<receiver>visualisation_window</receiver>
- <slot>Attribute_tower()</slot>
+ <slot>UpdateValues()</slot>
</connection>
</connections>
<slots>
Index: oln/appli/astro/tree_statistics.hh
--- oln/appli/astro/tree_statistics.hh (revision 214)
+++ oln/appli/astro/tree_statistics.hh (working copy)
@@ -112,10 +112,50 @@
template<typename I>
int node_count(oln::appli::astro::clean<I>& tree)
{
- return tree.input.width() * tree.input.height()
+ return tree.input.size().nrows() * tree.input.size().ncols()
- leaf_count(tree);
}
+
+ /**
+ ** Counts the number of local root points in the tree.
+ **
+ ** \param I Type of maxtree's image.
+ **
+ ** \arg tree Maxtree structure to check.
+ **
+ ** \warning Maxtree should have already been computed.
+ **
+ ** \code
+ ** Algorithm used :
+ **
+ ** count <- 0
+ ** for all points of input
+ ** if p is global root or if p has a different value than his parent's value in input image
+ ** then increment count (p is a local root)
+ ** at the end, return the count
+ **
+ ** \endcode
+ **
+ ** \return Number of local roots.
+ **
+ */
+ template<typename I>
+ int local_root_count(oln::appli::astro::clean<I>& tree)
+ {
+ typedef oln_type_of(I, point) point_type;
+ oln_type_of(I, fwd_piter) p(tree.input.size());
+ int count = 0;
+ for_all_p(p)
+ {
+ if (tree.parent[p] == p ||
+ tree.input[p] != tree.input[tree.parent[p]])
+ ++count;
+ }
+ return count;
+ }
+
+
/**
** Makes the children per node average.
**
Index: oln/appli/astro/graphical_interface/interface.pro
--- oln/appli/astro/graphical_interface/interface.pro (revision 214)
+++ oln/appli/astro/graphical_interface/interface.pro (working copy)
@@ -1,11 +1,13 @@
TEMPLATE = app
LANGUAGE = C++
-INCLUDEPATH += .
+CONFIG += warn_off release qt
+
+INCLUDEPATH += . ../../../../../olena ../../../../../metalic ../../../../../integre
SOURCES += main.cc
-HEADERS += filterinterface.hh image_viewer.hh qtincludes.hh utils.hh
+HEADERS += filterinterface.hh image_viewer.hh qtincludes.hh utils.hh ../../../canvas/tree.hh ../../../canvas/maxtree.hh
FORMS = visualization_window.ui
Index: oln/appli/astro/tree_coherance_checks.hh
Index: oln/appli/astro/graphical_interface/filterinterface.hh
--- oln/appli/astro/graphical_interface/filterinterface.hh (revision 214)
+++ oln/appli/astro/graphical_interface/filterinterface.hh (working copy)
@@ -57,9 +57,14 @@
virtual void UpdateValues()
{
- mt_.set_area(value_area->value());
+ mt_.set_area_min(value_area_min->value());
+ mt_.set_area_max(value_area_max->value());
mt_.set_level(value_level->value());
mt_.set_height(value_height->value());
+ mt_.set_circle(value_circle->value() / 100);
+ mt_.set_center_point(value_center_point->value() / 100);
+ mt_.set_tower(value_tower->value() / 100);
+
std::string out = "attributes value changed.";// area("
// + Utils::int2string(value_area->value())
// + "), point_value("
@@ -78,6 +83,8 @@
this->redraw_button->setEnabled(true);
this->save_result_button->setEnabled(true);
this->text_state->setText("Tree computed, please choose attributes'values to draw the result.");
+
+ UpdateValues();
}
virtual void DisplayImage()
@@ -108,12 +115,14 @@
{
if (this->active_area->isChecked())
{
- this->value_area->setEnabled(true);
+ this->value_area_min->setEnabled(true);
+ this->value_area_max->setEnabled(true);
mt_.area_tag_ = true;
}
else
{
- this->value_area->setEnabled(false);
+ this->value_area_min->setEnabled(false);
+ this->value_area_max->setEnabled(false);
mt_.area_tag_ = false;
}
}
@@ -149,25 +158,43 @@
virtual void Attribute_circle()
{
if (this->active_circle->isChecked())
+ {
+ this->value_circle->setEnabled(true);
mt_.circle_tag_ = true;
+ }
else
+ {
mt_.circle_tag_ = false;
+ this->value_circle->setEnabled(false);
+ }
}
virtual void Attribute_center_point()
{
if (this->active_center_point->isChecked())
+ {
+ this->value_center_point->setEnabled(true);
mt_.center_p_tag_ = true;
+ }
else
+ {
mt_.center_p_tag_ = false;
+ this->value_center_point->setEnabled(false);
+ }
}
virtual void Attribute_tower()
{
if (this->active_tower->isChecked())
+ {
+ this->value_tower->setEnabled(true);
mt_.tour_tag_ = true;
+ }
else
+ {
mt_.tour_tag_ = false;
+ this->value_tower->setEnabled(false);
+ }
}
protected:
2
1
Index: ChangeLog
from Christophe Berger <christophe(a)lrde.epita.fr>
* oln/appli/astro/tree_coherance_checks.hh: Remove.
* oln/appli/astro/tree_coherence_check.hh: New.
tree_coherance_checks.hh | 354 -----------------------------------------------
tree_coherence_check.hh | 2
2 files changed, 1 insertion(+), 355 deletions(-)
Index: oln/appli/astro/tree_coherence_check.hh
--- oln/appli/astro/tree_coherence_check.hh (revision 224)
+++ oln/appli/astro/tree_coherence_check.hh (working copy)
@@ -345,7 +345,7 @@
}
- } // end of namespace coherance_check
+ } // end of namespace coherence_check
} // end of namespace maxtree
Index: oln/appli/astro/tree_coherance_checks.hh
--- oln/appli/astro/tree_coherance_checks.hh (revision 224)
+++ oln/appli/astro/tree_coherance_checks.hh (working copy)
@@ -1,354 +0,0 @@
-// Copyright (C) 2005 EPITA Research and Development Laboratory
-//
-// This file is part of the Olena Library. This library is free
-// software; you can redistribute it and/or modify it under the terms
-// of the GNU General Public License version 2 as published by the
-// Free Software Foundation.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this library; see the file COPYING. If not, write to
-// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
-// MA 02111-1307, USA.
-//
-// As a special exception, you may use this file as part of a free
-// software library without restriction. Specifically, if other files
-// instantiate templates or use macros or inline functions from this
-// file, or you compile this file and link it with other files to
-// produce an executable, this file does not by itself cause the
-// resulting executable to be covered by the GNU General Public
-// License. This exception does not however invalidate any other
-// reasons why the executable file might be covered by the GNU General
-// Public License.
-
-#ifndef OLENA_APPLI_ASTRO_TREE_COHERENCE_CHECKS
-# define OLENA_APPLI_ASTRO_TREE_COHERENCE_CHECKS
-
-# include <mlc/any.hh>
-
-# include <oln/core/abstract/image_entry.hh>
-# include <oln/core/ch_value_type.hh>
-# include <oln/level/fill.hh>
-
-# include <oln/core/pw/check.hh>
-# include <oln/appli/astro/clean.hh>
-# include <oln/basics.hh>
-
-# include <queue>
-
-namespace oln {
-
- namespace maxtree {
-
- namespace coherence_check {
-
- /**
- ** Check if tree starts from an unique root point.
- **
- ** \param I Type of maxtree's image.
- **
- ** \arg tree Maxtree structure to check.
- **
- ** Check if the maxtree built has an unique starting
- ** point (global root point)
- **
- ** \warning Maxtree should have already been computed.
- **
- ** \code
- ** Algorithm used :
- ** The count of points that are parent of themselves
- ** should be exactly one.
- ** \endcode
- **
- ** \return true if tree is ok.
- **
- */
- template<typename I>
- bool
- global_root_unicity(oln::appli::astro::clean<I>& tree)
- {
- typedef oln_type_of(I, point) point_type;
- int count = 0;
- oln_type_of(I, fwd_piter) p(tree.input.size());
- for_all_p(p)
- {
- assert(tree.input.hold(p));
- if (tree.parent[p] == p)
- ++count;
- }
- assert(count == 1);
- if (count == 1)
- return true;
- else
- return false;
- }
-
- /**
- ** Check if parent relashionship is coherent in the tree.
- **
- ** \param I Type of maxtree's image.
- **
- ** \arg tree Maxtree structure to check.
- **
- ** \warning Maxtree should have already been computed.
- **
- ** \code
- ** Algorithm used :
- **
- ** for all points (p) from input
- ** check if children's parent is (p)
- **
- ** \endcode
- **
- ** \return true if relationships are ok.
- **
- */
- template<typename I>
- bool
- parent_relationship_integrity(oln::appli::astro::clean<I>& tree)
- {
- typedef oln_type_of(I, point) point_type;
- oln_type_of(I, fwd_piter) p(tree.input.size());
- for_all_p(p)
- {
- std::vector<point_type> child = tree.children[p];
- typename std::vector<point_type>::const_iterator pchild;
- for (pchild = child.begin();
- pchild != child.end();
- pchild++)
- {
- assert(tree.parent[*pchild] == p);
- if (tree.parent[*pchild] != p)
- return false;
- }
- }
- return true;
- }
-
- /**
- ** Check if children relashionship is coherent in the tree.
- **
- ** \param I Exact type of maxtree's image.
- **
- ** \arg tree maxtree structure to check.
- **
- ** \warning Maxtree should have already been computed.
- **
- ** \code
- ** Algorithm used :
- **
- ** For all points (p) of input
- ** if (p) is not the root
- ** search for parent (par) of p
- ** ensure (p) is contained in children of (par)
- ** else
- ** // nothing, root parent of hitself
- **
- ** \endcode
- **
- ** \return true if relationships are ok.
- **
- */
- template<typename I>
- bool
- children_relationship_integrity(oln::appli::astro::clean<I>& tree)
- {
- typedef oln_type_of(I, point) point_type;
- oln_type_of(I, fwd_piter) p(tree.input.size());
- for_all_p(p)
- {
- point_type par = tree.parent[p];
- bool found = false;
- if (par != p) // special case for the root
- {
- std::vector<point_type> child = tree.children[par];
- typename std::vector<point_type>::const_iterator pchild;
- for (pchild = child.begin();
- pchild != child.end() and not found;
- pchild++)
- {
- if (*pchild == p)
- found = true;
- }
- assert(found == true);
- if (not found)
- return false;
- }
- }
- return true;
- }
-
- /**
- ** Check if there is no recursion between parent and children.
- **
- ** \param I Exact type of maxtree's image.
- **
- ** \arg tree maxtree structure to check.
- **
- ** A node cannot be children of hitelf, this check if this
- ** property is satisfied.
- **
- ** \warning Maxtree should have already been computed.
- **
- ** \code
- ** Algorithm used :
- **
- ** For all points (p) of input
- ** for all children (c) of (p)
- ** ensure (c) is not (p)
- **
- ** \endcode
- **
- ** \return true if there is no recursion.
- **
- */
- template<typename I>
- bool
- no_children_recursion_check(oln::appli::astro::clean<I>& tree)
- {
- typedef oln_type_of(I, point) point_type;
- oln_type_of(I, fwd_piter) p(tree.input.size());
- for_all_p(p)
- {
- std::vector<point_type> child = tree.children[p];
- typename std::vector<point_type>::const_iterator pchild;
- for (pchild = child.begin();
- pchild != child.end();
- pchild++)
- {
- assert(*pchild != p);
- if (*pchild == p)
- return false;
- }
- }
- return true;
- }
-
-
- /**
- ** Check if maxtree construction was well done.
- **
- ** \param I Exact type of maxtree's image.
- **
- ** \arg tree maxtree structure to check.
- **
- ** The maxtree structure is based on Tarjan's Union-Find
- ** algorithm which works on decreasing point levels.
- ** This property guarantees that leafs are seen first in
- ** first pass order. The check exists to ensure this.
- **
- ** \warning Maxtree should have already been computed.
- **
- ** \code
- ** Algorithm used :
- **
- ** For all points (p) in decreasing order
- ** ensure parent of (p) was not seen before
- ** for all children (c) of (p)
- ** ensure they were seen before
- ** mark (p) as seen
- **
- ** \endcode
- **
- ** \return true if tree is good.
- **
- */
- template<typename I>
- bool
- check_child_seen_before_parent(oln::appli::astro::clean<I>& tree)
- {
- typedef oln_type_of(I, point) point_type;
- oln_ch_concrete_type(I, bool) seen(tree.input.size());
- level::fill(seen, false);
- typename std::vector<std::vector<point_type> >::reverse_iterator pvect;
- typename std::vector<point_type>::const_iterator p;
- for (pvect = tree.S.rbegin(); pvect != tree.S.rend(); pvect++)
- {
- for (p = pvect->begin(); p != pvect->end(); p++)
- {
- const std::vector<point_type> children = tree.children_get(*p);
- typename std::vector<point_type>::const_iterator pchild;
- assert(seen[tree.parent[*p]] == false);
- for (pchild = children.begin();
- pchild != children.end();
- pchild++)
- {
- assert(seen[*pchild] == true);
- if (seen[*pchild] != true)
- return false;
- }
- seen[*p] = true;
- }
- }
- return true;
- }
-
- /**
- ** Check if all points of the image are contained
- ** in the maxtree.
- **
- ** \param I Exact type of maxtree's image.
- **
- ** \arg tree maxtree structure to check.
- **
- ** Maxtree should cover the whole area of the base image.
- **
- ** \warning Maxtree should have already been computed.
- **
- ** \code
- ** Algorithm used :
- **
- ** Tree is traversed using breadth-first traversal with a queue.
- ** Every point is marked, at the end all the points must
- ** have been marked.
- **
- ** \endcode
- **
- ** \return True if all points were marked.
- **
- */
- template<typename I>
- bool
- complete_image_coverage(oln::appli::astro::clean<I>& tree)
- {
- typedef oln_type_of(I, point) point_type;
- oln_ch_concrete_type(I, bool) seen(tree.input.size());
- level::fill(seen, false);
- std::queue<point_type> q;
- q.push(tree.find_root(point_type(0,0)));
- while (not q.empty())
- {
- point_type &p = q.front();
- q.pop();
- const std::vector<point_type> children = tree.children_get(p);
- typename std::vector<point_type>::const_iterator pchild;
- assert(seen[p] == false);
- seen[p] = true;
- for (pchild = children.begin();
- pchild != children.end();
- pchild++)
- q.push(*pchild);
- }
-
- // FIXME : real pw::check function
- // return pw::check(pw::value(seen) == true);
- oln_type_of(I, fwd_piter) p(seen.size());
- for_all_p (p)
- if (not seen[p])
- return false;
- return true;
- // end FIXME
- }
-
-
- } // end of namespace coherance_check
-
- } // end of namespace maxtree
-
-} // end of namespace oln
-
-#endif // ! OLENA_APPLI_ASTRO_TREE_COHERENCE_CHECKS
1
0
Index: ChangeLog
from Christophe Berger <christophe(a)lrde.epita.fr>
* oln/makefile.src: Add astro files.
* oln/appli/astro/tree_coherance_checks.hh: Fix typo.
* oln/appli/astro/tree_statistics.hh: Fix typo.
appli/astro/tree_coherance_checks.hh | 12 ++++++------
appli/astro/tree_statistics.hh | 9 +++++----
makefile.src | 2 ++
3 files changed, 13 insertions(+), 10 deletions(-)
Index: oln/appli/astro/tree_statistics.hh
--- oln/appli/astro/tree_statistics.hh (revision 223)
+++ oln/appli/astro/tree_statistics.hh (working copy)
@@ -157,7 +157,7 @@
/**
- ** Makes the children per node average.
+ ** Compute the children per node average.
**
** \param I Type of maxtree's image.
**
@@ -178,7 +178,7 @@
**
*/
template<typename I>
- float children_average(oln::appli::astro::clean<I>& tree)
+ double children_average(oln::appli::astro::clean<I>& tree)
{
typedef oln_type_of(I, point) point_type;
std::queue<point_type> q;
@@ -212,7 +212,7 @@
**
** \warning Maxtree should have already been computed.
**
- ** This algorith is not the best way to compute max depth!
+ ** This algorithm is not the best way to compute max depth!
**
**
** \return Maximal depth of tree.
@@ -257,7 +257,8 @@
**
*/
template<typename I>
- void dotty_output(oln::appli::astro::clean<I>& tree, const std::string& filename)
+ void dotty_output(oln::appli::astro::clean<I>& tree,
+ const std::string& filename)
{
typedef oln_type_of(I, point) point_type;
std::queue<point_type> q;
Index: oln/appli/astro/tree_coherance_checks.hh
--- oln/appli/astro/tree_coherance_checks.hh (revision 223)
+++ oln/appli/astro/tree_coherance_checks.hh (working copy)
@@ -44,7 +44,7 @@
namespace maxtree {
- namespace coherance_check {
+ namespace coherence_check {
/**
** Check if tree starts from an unique root point.
@@ -146,7 +146,7 @@
** search for parent (par) of p
** ensure (p) is contained in children of (par)
** else
- ** // nothing, root parent of hiself
+ ** // nothing, root parent of hitself
**
** \endcode
**
@@ -189,7 +189,7 @@
**
** \arg tree maxtree structure to check.
**
- ** A node cannot be children of hiself, this check if this
+ ** A node cannot be children of hitelf, this check if this
** property is satisfied.
**
** \warning Maxtree should have already been computed.
@@ -236,7 +236,7 @@
**
** \arg tree maxtree structure to check.
**
- ** The maxtree structure is based on Tarjan's union find
+ ** The maxtree structure is based on Tarjan's Union-Find
** algorithm which works on decreasing point levels.
** This property guarantees that leafs are seen first in
** first pass order. The check exists to ensure this.
@@ -303,12 +303,12 @@
** Algorithm used :
**
** Tree is traversed using breadth-first traversal with a queue.
- ** Every points are marked, at the end all the points must
+ ** Every point is marked, at the end all the points must
** have been marked.
**
** \endcode
**
- ** \return True if all points where marked.
+ ** \return True if all points were marked.
**
*/
template<typename I>
Index: oln/makefile.src
--- oln/makefile.src (revision 223)
+++ oln/makefile.src (working copy)
@@ -7,6 +7,8 @@
all.hh \
\
appli/astro/clean.hh \
+ appli/astro/tree_coherance_checks.hh \
+ appli/astro/tree_statistics.hh \
\
basics1d.hh \
basics2d.hh \
1
0
Index: ChangeLog
from Christophe Berger <christophe(a)lrde.epita.fr>
* oln/appli/astro/graphical_interface/filterinterface.hh: Set the default
values at the beginning.
filterinterface.hh | 19 ++++++++++++++++---
1 files changed, 16 insertions(+), 3 deletions(-)
Index: oln/appli/astro/graphical_interface/filterinterface.hh
--- oln/appli/astro/graphical_interface/filterinterface.hh (revision 221)
+++ oln/appli/astro/graphical_interface/filterinterface.hh (working copy)
@@ -51,9 +51,24 @@
sprintf(tmp_, "/tmp/olni.XXXXXX");
mkstemp(tmp_);
sprintf(tmp_ + 16, ".pgm");
+
+ Attribute_area();
+ Attribute_level();
+ Attribute_height();
+ Attribute_tower();
+ Attribute_tower();
+ Attribute_center_point();
+ Attribute_circle();
+ Attribute_height();
+ Attribute_level();
+ Attribute_area();
+ UpdateValues();
}
- ~FilterVisualizationWindow() {}
+ ~FilterVisualizationWindow()
+ {
+ unlink(tmp_);
+ }
virtual void UpdateValues()
{
@@ -82,8 +97,6 @@
this->redraw_button->setEnabled(true);
this->save_result_button->setEnabled(true);
this->text_state->setText("Tree computed, please choose attributes'values to draw the result.");
-
- UpdateValues();
}
virtual void DisplayImage()
1
0
Index: ChangeLog
from Christophe Berger <christophe(a)lrde.epita.fr>
* oln/appli/astro/graphical_interface/interface.pro: Modify interface appareance.
* oln/appli/astro/graphical_interface/visualization_window.ui: likewise.
* oln/appli/astro/graphical_interface/filterinterface.hh: likewise.
filterinterface.hh | 11 ----
interface.pro | 2
visualization_window.ui | 117 ++++++++++++++++--------------------------------
3 files changed, 44 insertions(+), 86 deletions(-)
Index: oln/appli/astro/graphical_interface/visualization_window.ui
--- oln/appli/astro/graphical_interface/visualization_window.ui (revision 215)
+++ oln/appli/astro/graphical_interface/visualization_window.ui (working copy)
@@ -272,47 +272,6 @@
</widget>
<widget class="QSpinBox">
<property name="name">
- <cstring>value_area_max</cstring>
- </property>
- <property name="enabled">
- <bool>true</bool>
- </property>
- <property name="geometry">
- <rect>
- <x>490</x>
- <y>130</y>
- <width>80</width>
- <height>31</height>
- </rect>
- </property>
- <property name="maxValue">
- <number>999999</number>
- </property>
- <property name="lineStep">
- <number>0</number>
- </property>
- <property name="value">
- <number>999999</number>
- </property>
- </widget>
- <widget class="QLabel">
- <property name="name">
- <cstring>area_min_2</cstring>
- </property>
- <property name="geometry">
- <rect>
- <x>450</x>
- <y>130</y>
- <width>30</width>
- <height>31</height>
- </rect>
- </property>
- <property name="text">
- <string>max</string>
- </property>
- </widget>
- <widget class="QSpinBox">
- <property name="name">
<cstring>value_level</cstring>
</property>
<property name="enabled">
@@ -365,25 +324,9 @@
<string>%</string>
</property>
</widget>
- <widget class="QLabel">
- <property name="name">
- <cstring>textLabel2</cstring>
- </property>
- <property name="geometry">
- <rect>
- <x>440</x>
- <y>280</y>
- <width>20</width>
- <height>30</height>
- </rect>
- </property>
- <property name="text">
- <string>%</string>
- </property>
- </widget>
<widget class="QSpinBox">
<property name="name">
- <cstring>value_center_point</cstring>
+ <cstring>value_circle</cstring>
</property>
<property name="enabled">
<bool>true</bool>
@@ -391,7 +334,7 @@
<property name="geometry">
<rect>
<x>350</x>
- <y>280</y>
+ <y>230</y>
<width>80</width>
<height>31</height>
</rect>
@@ -399,21 +342,24 @@
<property name="maxValue">
<number>100</number>
</property>
+ <property name="value">
+ <number>90</number>
+ </property>
</widget>
<widget class="QLabel">
<property name="name">
- <cstring>textLabel2_2</cstring>
+ <cstring>area_min_2</cstring>
</property>
<property name="geometry">
<rect>
- <x>500</x>
- <y>330</y>
- <width>20</width>
- <height>30</height>
+ <x>440</x>
+ <y>130</y>
+ <width>30</width>
+ <height>31</height>
</rect>
</property>
<property name="text">
- <string>%</string>
+ <string>max</string>
</property>
</widget>
<widget class="QSpinBox">
@@ -422,7 +368,7 @@
</property>
<property name="geometry">
<rect>
- <x>420</x>
+ <x>430</x>
<y>330</y>
<width>70</width>
<height>31</height>
@@ -431,24 +377,49 @@
<property name="maxValue">
<number>100</number>
</property>
+ <property name="value">
+ <number>50</number>
+ </property>
+ </widget>
+ <widget class="QLabel">
+ <property name="name">
+ <cstring>textLabel2_2</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>510</x>
+ <y>330</y>
+ <width>20</width>
+ <height>30</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>%</string>
+ </property>
</widget>
<widget class="QSpinBox">
<property name="name">
- <cstring>value_circle</cstring>
+ <cstring>value_area_max</cstring>
</property>
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
- <x>350</x>
- <y>230</y>
+ <x>490</x>
+ <y>130</y>
<width>80</width>
<height>31</height>
</rect>
</property>
<property name="maxValue">
- <number>100</number>
+ <number>99999</number>
+ </property>
+ <property name="lineStep">
+ <number>0</number>
+ </property>
+ <property name="value">
+ <number>99999</number>
</property>
</widget>
</widget>
@@ -528,12 +499,6 @@
<slot>UpdateValues()</slot>
</connection>
<connection>
- <sender>value_center_point</sender>
- <signal>valueChanged(int)</signal>
- <receiver>visualisation_window</receiver>
- <slot>UpdateValues()</slot>
- </connection>
- <connection>
<sender>value_height</sender>
<signal>valueChanged(int)</signal>
<receiver>visualisation_window</receiver>
Index: oln/appli/astro/graphical_interface/interface.pro
Index: oln/appli/astro/graphical_interface/filterinterface.hh
--- oln/appli/astro/graphical_interface/filterinterface.hh (revision 215)
+++ oln/appli/astro/graphical_interface/filterinterface.hh (working copy)
@@ -62,7 +62,6 @@
mt_.set_level(value_level->value());
mt_.set_height(value_height->value());
mt_.set_circle(value_circle->value() / 100);
- mt_.set_center_point(value_center_point->value() / 100);
mt_.set_tower(value_tower->value() / 100);
std::string out = "attributes value changed.";// area("
@@ -172,15 +171,9 @@
virtual void Attribute_center_point()
{
if (this->active_center_point->isChecked())
- {
- this->value_center_point->setEnabled(true);
mt_.center_p_tag_ = true;
- }
else
- {
mt_.center_p_tag_ = false;
- this->value_center_point->setEnabled(false);
- }
}
virtual void Attribute_tower()
1
0
27 Jun '05
Index: ChangeLog
from Christophe Berger <christophe(a)lrde.epita.fr>
* oln/appli/astro/tree_coherance_checks.hh: New.
* oln/appli/astro/tree_statistics.hh: New.
* oln/canvas/tree.hh: Put the vector of sorted points in public.
This attribute is needed by checks and statistics functions.
appli/astro/tree_coherance_checks.hh | 354 +++++++++++++++++++++++++++++++++++
appli/astro/tree_statistics.hh | 260 +++++++++++++++++++++++++
canvas/tree.hh | 3
3 files changed, 615 insertions(+), 2 deletions(-)
Index: oln/appli/astro/tree_statistics.hh
--- oln/appli/astro/tree_statistics.hh (revision 0)
+++ oln/appli/astro/tree_statistics.hh (revision 0)
@@ -0,0 +1,260 @@
+// Copyright (C) 2005 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLENA_APPLI_ASTRO_TREE_STATISTICS
+# define OLENA_APPLI_ASTRO_TREE_STATISTICS
+
+# include <mlc/any.hh>
+
+# include <oln/core/abstract/image_entry.hh>
+# include <oln/core/ch_value_type.hh>
+# include <oln/level/fill.hh>
+
+# include <oln/core/pw/check.hh>
+# include <oln/appli/astro/clean.hh>
+# include <oln/basics.hh>
+
+# include <queue>
+
+namespace oln {
+
+ namespace maxtree {
+
+ namespace statistics {
+
+ /**
+ ** Counts the number of leafs in the tree.
+ **
+ ** \param I Type of maxtree's image.
+ **
+ ** \arg tree Maxtree structure to check.
+ **
+ ** \warning Maxtree should have already been computed.
+ **
+ ** \code
+ ** Algorithm used :
+ **
+ ** Tree is traversed using breadth-first traversal with a queue.
+ ** Increments count on leaf (no children).
+ **
+ ** \endcode
+ **
+ ** \return Number of leafs (terminal nodes).
+ **
+ */
+ template<typename I>
+ int leaf_count(oln::appli::astro::clean<I>& tree)
+ {
+ typedef oln_type_of(I, point) point_type;
+ std::queue<point_type> q;
+ q.push(tree.find_root(point_type(0,0)));
+ int count = 0;
+ while (not q.empty())
+ {
+ point_type &p = q.front();
+ q.pop();
+ const std::vector<point_type> children = tree.children_get(p);
+ typename std::vector<point_type>::const_iterator pchild;
+ if (children.empty())
+ ++count;
+ else
+ for (pchild = children.begin();
+ pchild != children.end();
+ pchild++)
+ q.push(*pchild);
+ }
+ return count;
+ }
+
+ /**
+ ** Counts the number of (internal) nodes in the tree.
+ **
+ ** \param I Type of maxtree's image.
+ **
+ ** \arg tree Maxtree structure to check.
+ **
+ ** \warning Maxtree should have already been computed.
+ **
+ ** \code
+ ** Algorithm used :
+ **
+ ** Number of points - leafs count
+ **
+ ** \endcode
+ **
+ ** \return Number of internal nodes.
+ **
+ */
+ template<typename I>
+ int node_count(oln::appli::astro::clean<I>& tree)
+ {
+ return tree.input.width() * tree.input.height()
+ - leaf_count(tree);
+ }
+
+ /**
+ ** Makes the children per node average.
+ **
+ ** \param I Type of maxtree's image.
+ **
+ ** \arg tree Maxtree structure to check.
+ **
+ ** \warning Maxtree should have already been computed.
+ **
+ ** \code
+ ** Algorithm used :
+ **
+ ** Tree is traversed using breadth-first traversal with a queue.
+ ** Counts the children and nodes, The average is
+ ** children_count / node_count.
+ **
+ ** \endcode
+ **
+ ** \return Children per node average.
+ **
+ */
+ template<typename I>
+ float children_average(oln::appli::astro::clean<I>& tree)
+ {
+ typedef oln_type_of(I, point) point_type;
+ std::queue<point_type> q;
+ q.push(tree.find_root(point_type(0,0)));
+ double node_count = 0;
+ double children_count = 0;
+ while (not q.empty())
+ {
+ point_type &p = q.front();
+ q.pop();
+ ++node_count;
+ const std::vector<point_type> children = tree.children_get(p);
+ typename std::vector<point_type>::const_iterator pchild;
+ for (pchild = children.begin();
+ pchild != children.end();
+ pchild++)
+ {
+ q.push(*pchild);
+ ++children_count;
+ }
+ }
+ return children_count / node_count;
+ }
+
+ /**
+ ** Max depth of tree.
+ **
+ ** \param I Type of maxtree's image.
+ **
+ ** \arg tree Maxtree structure to check.
+ **
+ ** \warning Maxtree should have already been computed.
+ **
+ ** This algorith is not the best way to compute max depth!
+ **
+ **
+ ** \return Maximal depth of tree.
+ **
+ */
+ template<typename I>
+ int depth(oln::appli::astro::clean<I>& tree)
+ {
+ typedef oln_type_of(I, point) point_type;
+ oln_type_of(I, fwd_piter) p(tree.input.size());
+ int max_depth = 0;
+ for_all_p(p)
+ {
+ const std::vector<point_type> children = tree.children_get(p);
+ if (children.empty())
+ {
+ point_type q = p;
+ int depth = 0;
+ while (tree.parent[q] != q)
+ {
+ ++depth;
+ q = tree.parent[q];
+ }
+ max_depth = max_depth < depth ? depth : max_depth;
+ }
+ }
+ return max_depth;
+ }
+
+ /**
+ ** Graphical tree output with Dotty
+ ** (http://www.research.att.com/sw/tools/graphviz/)
+ **
+ ** \param I Type of maxtree's image.
+ **
+ ** \arg tree Maxtree structure to check.
+ ** \arg filename Output will be written to the file.
+ **
+ ** \warning Maxtree should have already been computed.
+ **
+ **
+ **
+ */
+ template<typename I>
+ void dotty_output(oln::appli::astro::clean<I>& tree, const std::string& filename)
+ {
+ typedef oln_type_of(I, point) point_type;
+ std::queue<point_type> q;
+ q.push(tree.find_root(point_type(0,0)));
+
+
+ std::ofstream out(filename.c_str());
+
+ out << "digraph MaxtreeRepresentation {" << std::endl;
+
+ oln_type_of(I, fwd_piter) p(tree.input.size());
+ for_all_p(p)
+ {
+ out << '"' << p << "\";" << std::endl;
+ }
+ while (not q.empty())
+ {
+ point_type &p = q.front();
+ q.pop();
+ const std::vector<point_type> children = tree.children_get(p);
+ typename std::vector<point_type>::const_iterator pchild;
+ for (pchild = children.begin();
+ pchild != children.end();
+ pchild++)
+ {
+ q.push(*pchild);
+ out << '"' << p << "\" -> \"" << *pchild << "\";" << std::endl;
+ }
+ }
+ out << "}" << std::endl;
+ out.close();
+ }
+
+ } // end of namespace statistics
+
+ } // end of namespace maxtree
+
+} // end of namespace oln
+
+#endif // ! OLENA_APPLI_ASTRO_TREE_STATISTICS
Index: oln/canvas/tree.hh
--- oln/canvas/tree.hh (revision 210)
+++ oln/canvas/tree.hh (working copy)
@@ -182,13 +182,12 @@
// Attributes.
box<const I> input;
oln_type_of(I, concrete) output;
+ std::vector<std::vector<point_type> > S;
protected:
- std::vector<std::vector<point_type> > S;
oln_ch_concrete_type(I, T1) aux_data_;
std::vector<std::vector<T2> > aux_level_data_;
-
// Ctor.
tree(const abstract::image_with_nbh<I>& input) :
input(input),
Index: oln/appli/astro/tree_coherance_checks.hh
--- oln/appli/astro/tree_coherance_checks.hh (revision 0)
+++ oln/appli/astro/tree_coherance_checks.hh (revision 0)
@@ -0,0 +1,354 @@
+// Copyright (C) 2005 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLENA_APPLI_ASTRO_TREE_COHERENCE_CHECKS
+# define OLENA_APPLI_ASTRO_TREE_COHERENCE_CHECKS
+
+# include <mlc/any.hh>
+
+# include <oln/core/abstract/image_entry.hh>
+# include <oln/core/ch_value_type.hh>
+# include <oln/level/fill.hh>
+
+# include <oln/core/pw/check.hh>
+# include <oln/appli/astro/clean.hh>
+# include <oln/basics.hh>
+
+# include <queue>
+
+namespace oln {
+
+ namespace maxtree {
+
+ namespace coherance_check {
+
+ /**
+ ** Check if tree starts from an unique root point.
+ **
+ ** \param I Type of maxtree's image.
+ **
+ ** \arg tree Maxtree structure to check.
+ **
+ ** Check if the maxtree built has an unique starting
+ ** point (global root point)
+ **
+ ** \warning Maxtree should have already been computed.
+ **
+ ** \code
+ ** Algorithm used :
+ ** The count of points that are parent of themselves
+ ** should be exactly one.
+ ** \endcode
+ **
+ ** \return true if tree is ok.
+ **
+ */
+ template<typename I>
+ bool
+ global_root_unicity(oln::appli::astro::clean<I>& tree)
+ {
+ typedef oln_type_of(I, point) point_type;
+ int count = 0;
+ oln_type_of(I, fwd_piter) p(tree.input.size());
+ for_all_p(p)
+ {
+ assert(tree.input.hold(p));
+ if (tree.parent[p] == p)
+ ++count;
+ }
+ assert(count == 1);
+ if (count == 1)
+ return true;
+ else
+ return false;
+ }
+
+ /**
+ ** Check if parent relashionship is coherent in the tree.
+ **
+ ** \param I Type of maxtree's image.
+ **
+ ** \arg tree Maxtree structure to check.
+ **
+ ** \warning Maxtree should have already been computed.
+ **
+ ** \code
+ ** Algorithm used :
+ **
+ ** for all points (p) from input
+ ** check if children's parent is (p)
+ **
+ ** \endcode
+ **
+ ** \return true if relationships are ok.
+ **
+ */
+ template<typename I>
+ bool
+ parent_relationship_integrity(oln::appli::astro::clean<I>& tree)
+ {
+ typedef oln_type_of(I, point) point_type;
+ oln_type_of(I, fwd_piter) p(tree.input.size());
+ for_all_p(p)
+ {
+ std::vector<point_type> child = tree.children[p];
+ typename std::vector<point_type>::const_iterator pchild;
+ for (pchild = child.begin();
+ pchild != child.end();
+ pchild++)
+ {
+ assert(tree.parent[*pchild] == p);
+ if (tree.parent[*pchild] != p)
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ ** Check if children relashionship is coherent in the tree.
+ **
+ ** \param I Exact type of maxtree's image.
+ **
+ ** \arg tree maxtree structure to check.
+ **
+ ** \warning Maxtree should have already been computed.
+ **
+ ** \code
+ ** Algorithm used :
+ **
+ ** For all points (p) of input
+ ** if (p) is not the root
+ ** search for parent (par) of p
+ ** ensure (p) is contained in children of (par)
+ ** else
+ ** // nothing, root parent of hiself
+ **
+ ** \endcode
+ **
+ ** \return true if relationships are ok.
+ **
+ */
+ template<typename I>
+ bool
+ children_relationship_integrity(oln::appli::astro::clean<I>& tree)
+ {
+ typedef oln_type_of(I, point) point_type;
+ oln_type_of(I, fwd_piter) p(tree.input.size());
+ for_all_p(p)
+ {
+ point_type par = tree.parent[p];
+ bool found = false;
+ if (par != p) // special case for the root
+ {
+ std::vector<point_type> child = tree.children[par];
+ typename std::vector<point_type>::const_iterator pchild;
+ for (pchild = child.begin();
+ pchild != child.end() and not found;
+ pchild++)
+ {
+ if (*pchild == p)
+ found = true;
+ }
+ assert(found == true);
+ if (not found)
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ ** Check if there is no recursion between parent and children.
+ **
+ ** \param I Exact type of maxtree's image.
+ **
+ ** \arg tree maxtree structure to check.
+ **
+ ** A node cannot be children of hiself, this check if this
+ ** property is satisfied.
+ **
+ ** \warning Maxtree should have already been computed.
+ **
+ ** \code
+ ** Algorithm used :
+ **
+ ** For all points (p) of input
+ ** for all children (c) of (p)
+ ** ensure (c) is not (p)
+ **
+ ** \endcode
+ **
+ ** \return true if there is no recursion.
+ **
+ */
+ template<typename I>
+ bool
+ no_children_recursion_check(oln::appli::astro::clean<I>& tree)
+ {
+ typedef oln_type_of(I, point) point_type;
+ oln_type_of(I, fwd_piter) p(tree.input.size());
+ for_all_p(p)
+ {
+ std::vector<point_type> child = tree.children[p];
+ typename std::vector<point_type>::const_iterator pchild;
+ for (pchild = child.begin();
+ pchild != child.end();
+ pchild++)
+ {
+ assert(*pchild != p);
+ if (*pchild == p)
+ return false;
+ }
+ }
+ return true;
+ }
+
+
+ /**
+ ** Check if maxtree construction was well done.
+ **
+ ** \param I Exact type of maxtree's image.
+ **
+ ** \arg tree maxtree structure to check.
+ **
+ ** The maxtree structure is based on Tarjan's union find
+ ** algorithm which works on decreasing point levels.
+ ** This property guarantees that leafs are seen first in
+ ** first pass order. The check exists to ensure this.
+ **
+ ** \warning Maxtree should have already been computed.
+ **
+ ** \code
+ ** Algorithm used :
+ **
+ ** For all points (p) in decreasing order
+ ** ensure parent of (p) was not seen before
+ ** for all children (c) of (p)
+ ** ensure they were seen before
+ ** mark (p) as seen
+ **
+ ** \endcode
+ **
+ ** \return true if tree is good.
+ **
+ */
+ template<typename I>
+ bool
+ check_child_seen_before_parent(oln::appli::astro::clean<I>& tree)
+ {
+ typedef oln_type_of(I, point) point_type;
+ oln_ch_concrete_type(I, bool) seen(tree.input.size());
+ level::fill(seen, false);
+ typename std::vector<std::vector<point_type> >::reverse_iterator pvect;
+ typename std::vector<point_type>::const_iterator p;
+ for (pvect = tree.S.rbegin(); pvect != tree.S.rend(); pvect++)
+ {
+ for (p = pvect->begin(); p != pvect->end(); p++)
+ {
+ const std::vector<point_type> children = tree.children_get(*p);
+ typename std::vector<point_type>::const_iterator pchild;
+ assert(seen[tree.parent[*p]] == false);
+ for (pchild = children.begin();
+ pchild != children.end();
+ pchild++)
+ {
+ assert(seen[*pchild] == true);
+ if (seen[*pchild] != true)
+ return false;
+ }
+ seen[*p] = true;
+ }
+ }
+ return true;
+ }
+
+ /**
+ ** Check if all points of the image are contained
+ ** in the maxtree.
+ **
+ ** \param I Exact type of maxtree's image.
+ **
+ ** \arg tree maxtree structure to check.
+ **
+ ** Maxtree should cover the whole area of the base image.
+ **
+ ** \warning Maxtree should have already been computed.
+ **
+ ** \code
+ ** Algorithm used :
+ **
+ ** Tree is traversed using breadth-first traversal with a queue.
+ ** Every points are marked, at the end all the points must
+ ** have been marked.
+ **
+ ** \endcode
+ **
+ ** \return True if all points where marked.
+ **
+ */
+ template<typename I>
+ bool
+ complete_image_coverage(oln::appli::astro::clean<I>& tree)
+ {
+ typedef oln_type_of(I, point) point_type;
+ oln_ch_concrete_type(I, bool) seen(tree.input.size());
+ level::fill(seen, false);
+ std::queue<point_type> q;
+ q.push(tree.find_root(point_type(0,0)));
+ while (not q.empty())
+ {
+ point_type &p = q.front();
+ q.pop();
+ const std::vector<point_type> children = tree.children_get(p);
+ typename std::vector<point_type>::const_iterator pchild;
+ assert(seen[p] == false);
+ seen[p] = true;
+ for (pchild = children.begin();
+ pchild != children.end();
+ pchild++)
+ q.push(*pchild);
+ }
+
+ // FIXME : real pw::check function
+ // return pw::check(pw::value(seen) == true);
+ oln_type_of(I, fwd_piter) p(seen.size());
+ for_all_p (p)
+ if (not seen[p])
+ return false;
+ return true;
+ // end FIXME
+ }
+
+
+ } // end of namespace coherance_check
+
+ } // end of namespace maxtree
+
+} // end of namespace oln
+
+#endif // ! OLENA_APPLI_ASTRO_TREE_COHERENCE_CHECKS
2
1
ChangeLog | 12 +++++
Makefile.am | 1
img/Makefile.am | 1
img/lena-small.pgm | 5 ++
oln/makefile.src | 4 +
oln/morpho/gradient.hh | 104 ++++++++++++++++++++++++++++++++++++++++++++
tests/morpho/tests/gradient | 48 ++++++++++++++++++++
7 files changed, 175 insertions(+)
Index: olena/ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Add morphological gradients.
* oln/morpho/gradient.hh: New file.
* tests/morpho/tests/gradient: New test.
* img/lena-small.pgm: New image.
* img/Makefile.am (SOURCE_IMGS): Add $(srcdir)/lena-small.pgm.
* oln/makefile.src (OLN_DEP): Add convert/abstract/conversion.hh,
convert/conversion.hh, convert/force.hh and morpho/gradient.hh.
* Makefile.am (EXTRA_DIST): Add TODO.
2005-06-23 Roland Levillain <roland(a)lrde.epita.fr>
Index: olena/tests/morpho/tests/gradient
--- olena/tests/morpho/tests/gradient (révision 0)
+++ olena/tests/morpho/tests/gradient (révision 0)
@@ -0,0 +1,48 @@
+ // -*- C++ -*-
+#include "data.hh"
+#include <oln/utils/md5.hh>
+
+#include <ntg/int.hh>
+#include <oln/core/2d/image2d.hh>
+#include <oln/core/gen/image_with_nbh.hh>
+#include <oln/io/read_image.hh>
+#include <oln/io/write_image.hh>
+#include <oln/morpho/gradient.hh>
+
+using namespace oln;
+
+bool check()
+{
+ typedef image2d<ntg::int_u8> ima_type;
+ ima_type input;
+ input = io::read(rdata("lena-small.pgm"));
+
+ // Beucher gradient.
+ utils::key::value_type bg_data_key[16] =
+ {0x89, 0xaa, 0x5b, 0xca, 0x8, 0xec, 0xb3, 0xe7,
+ 0x86, 0xfb, 0x4b, 0x59, 0xf0, 0x8, 0xf5, 0x59};
+ utils::key bg_key(bg_data_key);
+ ima_type bg = morpho::beucher_gradient(input, win_c8p());
+ if (utils::md5(bg) != bg_key)
+ return true;
+
+ // Internal gradient.
+ utils::key::value_type ig_data_key[16] =
+ {0xe7, 0xff, 0x90, 0x2a, 0x50, 0x44, 0x30, 0x65,
+ 0xeb, 0xe3, 0xf2, 0xc4, 0x6f, 0xfe, 0x65, 0x84};
+ utils::key ig_key(ig_data_key);
+ ima_type ig = morpho::internal_gradient(input, win_c8p());
+ if (utils::md5(ig) != ig_key)
+ return true;
+
+ // External gradient.
+ utils::key::value_type eg_data_key[16] =
+ {0xf7, 0xb7, 0x9e, 0x74, 0xe0, 0xd1, 0xe7, 0xd8,
+ 0x5b, 0x0, 0xe8, 0x37, 0x57, 0xdc, 0x2c, 0x27};
+ utils::key eg_key(eg_data_key);
+ ima_type eg = morpho::external_gradient(input, win_c8p());
+ if (utils::md5(eg) != eg_key)
+ return true;
+
+ return false;
+}
Index: olena/oln/makefile.src
--- olena/oln/makefile.src (révision 216)
+++ olena/oln/makefile.src (copie de travail)
@@ -22,6 +22,9 @@
config/pconf.hh \
config/system.hh \
\
+ convert/abstract/conversion.hh \
+ convert/conversion.hh \
+ convert/force.hh \
convert/value_to_point.hh \
\
core/1d/array1d.hh \
@@ -166,6 +169,7 @@
morpho/erosion.hh \
morpho/geodesic_dilation.hh \
morpho/geodesic_erosion.hh \
+ morpho/gradient.hh \
morpho/lower_completion.hh \
morpho/opening.hh \
morpho/reconstruction_by_dilation.hh \
Index: olena/oln/morpho/gradient.hh
--- olena/oln/morpho/gradient.hh (révision 0)
+++ olena/oln/morpho/gradient.hh (révision 0)
@@ -0,0 +1,104 @@
+// Copyright (C) 2001, 2002, 2004, 2005 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLENA_MORPHO_GRADIENT_HH
+# define OLENA_MORPHO_GRADIENT_HH
+
+# include <oln/morpho/dilation.hh>
+# include <oln/morpho/erosion.hh>
+# include <oln/level/arith.hh>
+# include <oln/convert/force.hh>
+# include <oln/core/ch_value_type.hh>
+
+namespace oln {
+
+ namespace morpho {
+
+ // FIXME: Document! (Get the documentation from Olena 0.10 and
+ // adjust it.)
+
+ template<class C, class B, class I, class W>
+ typename ch_value_type<I, typename convoutput<C, B, oln_type_of(I, value)>::ret>::ret
+ beucher_gradient(const convert::abstract::conversion<C, B>& c,
+ const abstract::scalar_valued_image<I>& input,
+ const abstract::window<W>& win)
+ {
+ return level::minus(c, dilation(input, win), erosion(input, win));
+ }
+
+ template<class I, class W>
+ oln_type_of(I, concrete)
+ beucher_gradient(const abstract::scalar_valued_image<I>& input,
+ const abstract::window<W>& win)
+ {
+ return beucher_gradient(convert::force<oln_type_of(I, value)>(),
+ input, win);
+ }
+
+
+ template<class C, class B, class I, class W>
+ typename ch_value_type<I, typename convoutput<C, B, oln_type_of(I, value)>::ret>::ret
+ internal_gradient(const convert::abstract::conversion<C, B>& c,
+ const abstract::scalar_valued_image<I>& input,
+ const abstract::window<W>& win)
+ {
+ return level::minus(c, input, erosion(input, win));
+ }
+
+ template<class I, class W>
+ oln_type_of(I, concrete)
+ internal_gradient(const abstract::scalar_valued_image<I>& input,
+ const abstract::window<W>& win)
+ {
+ return internal_gradient(convert::force<oln_type_of(I, value)>(),
+ input, win);
+ }
+
+
+ template<class C, class B, class I, class W>
+ typename ch_value_type<I, typename convoutput<C, B, oln_type_of(I, value)>::ret>::ret
+ external_gradient(const convert::abstract::conversion<C, B>& c,
+ const abstract::scalar_valued_image<I>& input,
+ const abstract::window<W>& win)
+ {
+ return level::minus(c, dilation(input, win), input);
+ }
+
+ template<class I, class W>
+ oln_type_of (I, concrete)
+ external_gradient(const abstract::scalar_valued_image<I>& input,
+ const abstract::window<W>& win)
+ {
+ return external_gradient(convert::force<oln_type_of(I, value)>(),
+ input, win);
+ }
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+#endif // OLENA_MORPHO_GRADIENT_HH
Index: olena/Makefile.am
--- olena/Makefile.am (révision 216)
+++ olena/Makefile.am (copie de travail)
@@ -3,3 +3,4 @@
# OLN_SRC_SUBDIRS is set when "configure" is run.
SUBDIRS = img oln $(OLN_SRC_SUBDIRS)
+EXTRA_DIST = TODO
Index: olena/img/Makefile.am
--- olena/img/Makefile.am (révision 216)
+++ olena/img/Makefile.am (copie de travail)
@@ -13,6 +13,7 @@
$(srcdir)/lena.pgm.gz \
$(srcdir)/lena.ppm \
$(srcdir)/lena.ppm.gz \
+ $(srcdir)/lena-small.pgm \
$(srcdir)/marker.pbm \
$(srcdir)/mask.pbm \
$(srcdir)/object.pbm \
1
0
23 Jun '05
ChangeLog | 10 ++++++
oln/level/arith.hh | 34 ++++++++++++++++++++
tests/level/tests/arith_and_conversion | 55 +++++++++++++++++++++++++++++++++
3 files changed, 99 insertions(+)
Index: olena/ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Add level::minus taking a conversion function.
* oln/level/arith.hh
(minus (const convert::abstract::conversion<C, B>&,
const abstract::image<I1>&, const abstract::image<I2>& input2)):
New.
* tests/level/tests/arith_and_conversion: New test.
2005-06-23 Roland Levillain <roland(a)lrde.epita.fr>
Index: olena/oln/level/arith.hh
--- olena/oln/level/arith.hh (révision 216)
+++ olena/oln/level/arith.hh (copie de travail)
@@ -35,6 +35,7 @@
# include <oln/core/apply.hh>
# include <oln/ops/arith.hh>
+# include <oln/convert/conversion.hh>
# include <oln/utils/clone.hh>
@@ -169,6 +170,39 @@
return output;
}
+ // Variant taking a conversion function in parameter.
+ template <typename C, typename B, typename I1, typename I2>
+ typename ch_value_type<I1, typename convoutput<C, B, typename arith_output<f_::minus_, I1, I2>::T>::ret>::ret
+ minus (const convert::abstract::conversion<C, B>& conv,
+ const abstract::image<I1>& input1,
+ const abstract::image<I2>& input2)
+ {
+ mlc::eq<oln_type_of(I1, grid), oln_type_of(I2, grid)>::ensure();
+
+ entering("level::minus");
+ registering(input1, "input1");
+ registering(input2, "input2");
+
+ precondition(input1.size() == input2.size());
+
+ typedef oln_type_of(I1, value) T1;
+ typedef oln_type_of(I2, value) T2;
+
+ // The return type, if there were no conversion.
+ typedef typename arith_output<f_::minus_, I1, I2>::T oper_output_type;
+ // The actual return type.
+ typedef typename
+ ch_value_type<I1,
+ typename convoutput<C, B, oper_output_type>::ret>::ret
+ output_type;
+ output_type output("output");
+ output = apply2(convert::compconv2(conv, f_::minus_<T1, T2>()),
+ input1, input2);
+
+ exiting("level::minus");
+ return output;
+ }
+
// times
Index: olena/tests/level/tests/arith_and_conversion
--- olena/tests/level/tests/arith_and_conversion (révision 0)
+++ olena/tests/level/tests/arith_and_conversion (révision 0)
@@ -0,0 +1,55 @@
+ // -*- C++ -*-
+#include <ntg/int.hh>
+#include <oln/basics2d.hh>
+#include <oln/convert/force.hh>
+#include <oln/level/arith.hh>
+#include <oln/level/fill.hh>
+#include <oln/level/compare.hh>
+
+using namespace oln;
+
+
+// FIXME: Not safe, nor generic. Re-introduce static initialization
+// in Olena and use it instead.
+template<typename T>
+image2d<T>
+image_from_array(coord_t nrows, coord_t ncols, T values[])
+{
+ image2d<T> output(nrows, ncols);
+ unsigned i = 0;
+ oln_type_of(image2d<T>, fwd_piter) p(output.size());
+ for_all_p (p)
+ {
+ output[p] = values[i];
+ ++i;
+ }
+ return output;
+}
+
+
+bool check()
+{
+ typedef ntg::int_u8 value_type;
+
+ value_type ima1_values[] = { 2, 8, 2,
+ 3, 4, 5,
+ 6, 7, 8 };
+ image2d<value_type> ima1 = image_from_array<value_type>(3, 3, ima1_values);
+
+ image2d<value_type> ima2(3, 3);
+ level::fill(ima2, 2);
+
+ // Checking level::minus, with convert::force conversion.
+ {
+ image2d<value_type> diff =
+ level::minus(convert::force<value_type>(), ima1, ima2);
+ value_type diff_ref[] = { 0, 6, 0,
+ 1, 2, 3,
+ 4, 5, 6 };
+ if (not level::is_equal(diff,
+ image_from_array<value_type>(3, 3, diff_ref)))
+ return true;
+ }
+
+ return false;
+}
1
0
23 Jun '05
ChangeLog | 16 +
TODO | 17 +
oln/convert/abstract/conversion.hh | 358 +++++++++++++++++++++++++++++++++++++
oln/convert/conversion.hh | 174 +++++++++++++++++
oln/convert/force.hh | 63 ++++++
oln/core/apply.hh | 30 ++-
oln/funobj/compose.hh | 45 ++++
tests/convert/tests/force | 22 ++
8 files changed, 717 insertions(+), 8 deletions(-)
Index: olena/ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Add conversion abstractions.
* oln/convert/abstract/conversion.hh, oln/convert/conversion.hh:
New files.
Add convert::force operator.
* oln/convert/force.hh: New file.
* tests/convert/tests/force: New test.
* oln/funobj/compose.hh (f_::identity_): New functor.
* oln/core/apply.hh: Update doxygen comments.
* TODO: New file.
Index: olena/oln/convert/abstract/conversion.hh
--- olena/oln/convert/abstract/conversion.hh (révision 0)
+++ olena/oln/convert/abstract/conversion.hh (révision 0)
@@ -0,0 +1,179 @@
+// Copyright (C) 2001, 2002, 2003, 2004, 2005 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLENA_CONVERT_ABSTRACT_CONVERSION_HH
+# define OLENA_CONVERT_ABSTRACT_CONVERSION_HH
+
+# include <ntg/utils/debug.hh>
+# include <functional>
+
+namespace oln {
+
+ namespace convert {
+ /*!
+ ** \brief Base classes for conversion.
+ */
+ namespace abstract {
+
+ // fwd_decl
+ template <class Exact, class Base>
+ class conversion;
+
+ template<class Result_Type,
+ class Exact, class Base>
+ struct conversion_to_type;
+
+ template<class Argument_Type, class Result_Type,
+ class Exact, class Base>
+ struct conversion_from_type_to_type;
+
+ template<class Conv>
+ struct conversion_traits;
+
+ /*! \brief Internal purpose only.
+ */
+ namespace internal {
+ /// Retrieve the result type of a conversion.
+ template <class Base, class T>
+ struct output {};
+
+ template <class Argument_Type, class Result_Type,
+ class Exact, class Base>
+ struct output<conversion_from_type_to_type<Argument_Type, Result_Type, Exact, Base >, Argument_Type>
+ {
+ typedef Result_Type ret;
+ };
+
+ template <class Result_Type,
+ class Exact, class Base, class T>
+ struct output<conversion_to_type<Result_Type, Exact, Base >, T>
+ {
+ typedef Result_Type ret;
+ };
+
+ } // end of namespace oln::convert::abstract::internal
+
+ } // end of namespace oln::convert::abstract
+
+ namespace abstract {
+
+ /*! Base class for conversion.
+ **
+ ** \note If you write an class derived from this one, you
+ ** must write the specialization of the output trait.
+ */
+ template<class Exact, class Base>
+ struct conversion : public mlc::any< Exact >
+ {
+ static std::string
+ name()
+ {
+ return std::string("conversion<") + Exact::name() + ">";
+ }
+
+ public:
+ template<class T>
+ struct output
+ {
+ typedef typename internal::output<Base, T>::ret ret;
+ };
+
+ /// Call the conversion written in the exact class.
+ template <class T>
+ typename output<T>::ret
+ operator()(const T& in) const
+ {
+ return this->exact().doit(in);
+ }
+
+ protected:
+ conversion() {}
+ };
+
+ /// Base class for the conversion to a specific type.
+ template<class Result_Type, class Exact,
+ class Base = conversion_to_type<Result_Type, Exact, Exact> >
+ struct conversion_to_type :
+ public conversion< Exact, Base >
+ {
+ /* Additionally define result_type. This is not required
+ in a conversion class (generally not possible to define).
+ But it's useful when it's available (like here)
+ because it make the conversion appear almost as Adaptable
+ Unary Function (it will just lack the argument_type, but
+ this typedef is not used very much.) */
+
+ typedef Result_Type result_type;
+
+ static std::string
+ name()
+ {
+ // FIXME: Exact is not an integre type !
+ return std::string("conversion_to_type<")
+ + ntg_name(Result_Type) + ", "
+ + Exact::name() + ">";
+ }
+
+ protected:
+ conversion_to_type() {}
+ };
+
+ /// Base class if both input and output types of the conversion
+ /// are fixed.
+ template<class Argument_Type, class Result_Type, class Exact,
+ class Base = conversion_from_type_to_type<Argument_Type, Result_Type, Exact, Exact> >
+ struct conversion_from_type_to_type:
+ public conversion_to_type< Result_Type, Exact , Base >
+ {
+
+ /* By defining argument_type, and inheriting from result_type,
+ we comply to the STL concept of Adaptable Unary Function. */
+
+ typedef Argument_Type argument_type;
+
+ static std::string
+ name()
+ {
+ // FIXME: Exact is not an integre type !
+ return std::string("conversion_from_type_to_type<")
+ + ntg_name(Argument_Type) + ", "
+ + ntg_name(Result_Type) + ", "
+ + "FIXME: ntg_name(Exact)" + ">";
+ }
+
+ protected :
+ conversion_from_type_to_type() {}
+ };
+
+ } // end of namespace oln::convert::abstract
+
+ } // end of namespace oln::convert
+
+} // end of namespace oln
+
+
+#endif // OLENA_CONVERT_ABSTRACT_CONVERSION_HH
Index: olena/oln/convert/conversion.hh
--- olena/oln/convert/conversion.hh (révision 0)
+++ olena/oln/convert/conversion.hh (révision 0)
@@ -0,0 +1,174 @@
+// Copyright (C) 2001, 2002, 2003, 2004, 2005 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLENA_CONVERT_CONVERSION_HH
+# define OLENA_CONVERT_CONVERSION_HH
+
+# include <oln/core/abstract/image.hh>
+# include <oln/core/ch_value_type.hh>
+# include <oln/funobj/abstract/unary.hh>
+# include <oln/funobj/abstract/binary.hh>
+# include <oln/convert/abstract/conversion.hh>
+
+namespace oln {
+ /*!
+ ** \brief Conversion implementation (for example cast, color, or
+ ** neighborhood to window).
+ */
+ namespace convert {
+
+ /// \brief Internal purpose only.
+ namespace internal {
+ template <typename C, typename UF> struct compconv1_;
+ template <typename C, typename BF> struct compconv2_;
+ } // end of namespace oln::convert::internal
+
+ } // end of namespace oln::convert
+
+ template <typename C, typename UF>
+ struct set_super_type < convert::internal::compconv1_<C, UF> > { typedef f_::abstract::unary< convert::internal::compconv1_<C, UF> > ret; };
+
+ template <typename C, typename BF>
+ struct set_super_type < convert::internal::compconv2_<C, BF> > { typedef f_::abstract::binary< convert::internal::compconv2_<C, BF> > ret; };
+
+ template <typename C, typename UF>
+ struct set_props < category::fun1, convert::internal::compconv1_<C, UF> >
+ {
+ typedef oln_fun1_type_of(UF, arg) arg_type;
+ typedef typename C::template output<oln_fun1_type_of(UF, res)>::ret
+ res_type;
+ };
+
+ template <typename C, typename BF>
+ struct set_props < category::fun2, convert::internal::compconv2_<C, BF> >
+ {
+ typedef oln_fun2_type_of(BF, left) left_type;
+ typedef oln_fun2_type_of(BF, right) right_type;
+ typedef typename C::template output<oln_fun2_type_of(BF, res)>::ret
+ res_type;
+ };
+
+ namespace convert {
+
+ /*! Trait that returns the output of a conversion.
+ **
+ ** convoutput queries the output type of conversion ConvType for
+ ** an input of type InputType. This comes handy when computing
+ ** the return type of a function which takes a conversion function
+ ** in argument.
+ **
+ ** \note convoutput is exported in the namespace oln for convenience.
+ */
+ template<class ConvType, class Base, class InputType>
+ struct convoutput
+ {
+ typedef typename abstract::conversion<ConvType, Base>::template output<InputType>::ret ret;
+ };
+
+ namespace internal {
+
+ /*! Compose a conversion C and an unary functor UF, producing an
+ ** unary functor.
+ */
+ template <class C, class UF>
+ struct compconv1_ : public oln_super2_of_(compconv1_<C, UF>)
+ {
+ typedef compconv1_<C, UF> self_type;
+ typedef oln_fun1_type_of(self_type, arg) arg_type;
+ typedef oln_fun1_type_of(self_type, res) res_type;
+
+ compconv1_(const C& conv, const UF& func) :
+ conv_(conv.exact()), func_(func.exact())
+ {
+ }
+
+ const res_type impl_unop(const arg_type& arg) const
+ {
+ return conv_(func_(arg));
+ }
+
+ private:
+ const C conv_;
+ const UF func_;
+ };
+
+ /*! Compose a conversion C and a binary functor BF, producing
+ ** a binary functor.
+ */
+ template <class C, class BF>
+ struct compconv2_ : public oln_super2_of_(compconv2_<C, BF>)
+ {
+ typedef compconv2_<C, BF> self_type;
+ typedef oln_fun2_type_of(self_type, left) left_type;
+ typedef oln_fun2_type_of(self_type, right) right_type;
+ typedef oln_fun2_type_of(self_type, res) res_type;
+
+ compconv2_(const C& conv, const BF& func) :
+ conv_(conv.exact()), func_(func.exact())
+ {
+ }
+
+ const res_type impl_binop(const left_type& left,
+ const right_type& right) const
+ {
+ return conv_(func_(left, right));
+ }
+
+ private:
+ const C conv_;
+ const BF func_;
+ };
+
+ } // end of namespace oln::convert::internal
+
+ /*! Friendly procedure that build an internal::compconv1_ with
+ ** type deduction.
+ */
+ template <class C, class B, class UF>
+ internal::compconv1_<C, UF>
+ compconv1(const abstract::conversion<C, B>& conv, const UF &func)
+ {
+ return internal::compconv1_<C, UF>(conv.exact(), func);
+ }
+
+ /*! Likewise for compconv2_. */
+ template <class C, class B, class BF>
+ internal::compconv2_<C, BF>
+ compconv2(const abstract::conversion<C, B>& conv, const BF &func)
+ {
+ return internal::compconv2_<C, BF>(conv.exact(), func);
+ }
+
+ } // end of namespace oln::convert
+
+ // Export conversion and convouput into oln:: to simplify the
+ // writing of processings.
+ using convert::convoutput;
+
+} // end of namespace oln
+
+#endif // OLENA_CONVERT_CONVERSION_HH
Index: olena/oln/convert/force.hh
--- olena/oln/convert/force.hh (révision 0)
+++ olena/oln/convert/force.hh (révision 0)
@@ -0,0 +1,63 @@
+// Copyright (C) 2001, 2002, 2003, 2004, 2005 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+
+#ifndef OLENA_CONVERT_FORCE_HH
+# define OLENA_CONVERT_FORCE_HH
+
+# include <oln/convert/abstract/conversion.hh>
+# include <ntg/utils/cast.hh>
+
+namespace oln {
+
+ namespace convert {
+
+ /*! Like cast::force, but as a conversion functor. */
+ template<class Output>
+ struct force : public abstract::conversion_to_type< Output, force<Output> >
+ {
+ template< class Input >
+ Output
+ doit(const Input& v) const
+ {
+ return ntg::cast::force<Output>(v);
+ }
+
+ static std::string
+ name()
+ {
+ // FIXME: Exact is not an integre type !
+ return std::string("force<")
+ + ntg_name(Output) + ">";
+ }
+ };
+
+ } // end of namespace oln::convert
+
+} // end of namespace oln
+
+#endif // OLENA_CONVERT_FORCE_HH
Index: olena/tests/convert/tests/force
--- olena/tests/convert/tests/force (révision 0)
+++ olena/tests/convert/tests/force (révision 0)
@@ -0,0 +1,22 @@
+ // -*- C++ -*-
+#include <ntg/int.hh>
+#include <oln/funobj/arith.hh>
+#include <oln/convert/conversion.hh>
+#include <oln/convert/force.hh>
+
+using namespace oln;
+
+bool check()
+{
+ typedef ntg::int_u8 value_type;
+ f_::plus_<value_type, value_type> f_plus;
+ oln::convert::force<value_type> f_force;
+
+ value_type a = 1;
+ value_type b = 2;
+ value_type c = convert::compconv2(f_force, f_plus)(a, b);
+ if (c != 3)
+ return true;
+
+ return false;
+}
Index: olena/oln/funobj/compose.hh
--- olena/oln/funobj/compose.hh (révision 216)
+++ olena/oln/funobj/compose.hh (copie de travail)
@@ -48,6 +48,11 @@
typedef oln_fun1_type_of(F2, arg) arg_type;
};
+
+ /*-----------------------------------.
+ | Composition of two unary functor. |
+ `-----------------------------------*/
+
namespace f_
{
@@ -87,6 +92,46 @@
return f_::compose_uu_<UF1, UF2>(f1, f2);
}
+
+ /*-------------------.
+ | Identity functor. |
+ `-------------------*/
+
+ namespace f_ {
+ template <typename T> struct identity_;
+ } // end of namespace oln::f_
+
+ template <typename T>
+ struct set_super_type < f_::identity_<T> > { typedef f_::abstract::unary< f_::identity_<T> > ret; };
+
+ template <typename T>
+ struct set_props < category::fun1, f_::identity_<T> >
+ {
+ typedef T res_type;
+ typedef T arg_type;
+ };
+
+ namespace f_
+ {
+
+ /*! \class f_identity
+ **
+ ** This functor returns its argument.
+ */
+ template<class T>
+ struct identity_ : public oln_super_of_(f_::identity_<T>)
+ {
+ const T impl_unop(const T& t) const
+ {
+ return t;
+ }
+ };
+
+ typedef f_::unary_meta<f_::identity_> f_identity_type;
+ static f_identity_type f_identity;
+
+ } // end of namespace oln::f_
+
} // end of namespace oln
#endif // ! OLENA_CORE_FUNOBJ_CONVERSION_HH
Index: olena/oln/core/apply.hh
--- olena/oln/core/apply.hh (révision 216)
+++ olena/oln/core/apply.hh (copie de travail)
@@ -44,7 +44,8 @@
| Unary. |
`--------*/
- /*! \brief Standard unary \a apply procedure.
+ /*! \brief Standard unary \a apply procedure of an
+ ** mlc:abstract::unary_function<F>
**
** Apply a function \a f to each element of \a input, the function
** is passed as a type and is instantiated.
@@ -69,8 +70,12 @@
return output;
}
- // version with oln::f_::abstract::unary<F>
-
+ /*! \brief Standard unary \a apply procedure of an
+ ** oln::f_::abstract::unary
+ **
+ ** Apply a function \a f to each element of \a input, the function
+ ** is passed as a type and is instantiated.
+ */
template <typename F, typename I>
typename ch_value_type<I, oln_fun1_type_of(F, res)>::ret
apply(const oln::f_::abstract::unary<F>& f,
@@ -96,7 +101,8 @@
| Binary. |
`---------*/
- /*! \brief Standard binary \a apply procedure.
+ /*! \brief Standard binary \a apply procedure of a
+ ** mlc:abstract::binary_function<F>
**
** Apply a function \a f to each pair of elements of
** \a input1 x \a input2.
@@ -128,8 +134,12 @@
}
- // version with oln::f_::abstract::binary<F>
-
+ /*! \brief Standard binary \a apply procedure of a
+ ** oln::f_::abstract::binary<F>
+ **
+ ** Apply a function \a f to each pair of elements of
+ ** \a input1 x \a input2.
+ */
template <typename F, typename I1, typename I2>
typename ch_value_type<I1, oln_fun2_type_of(F, res)>::ret
apply2(const oln::f_::abstract::binary<F>& f,
@@ -157,8 +167,12 @@
}
- // version with oln::f_::abstract::mbinary<F>
-
+ /*! \brief Standard binary \a apply procedure of a
+ ** oln::f_::abstract::mbinary<F>
+ **
+ ** Apply a function \a f to each pair of elements of
+ ** \a input1 x \a input2.
+ */
template <typename F, typename I1, typename I2>
typename ch_value_type<I1, typename f_::mbinary_result<F,
oln_type_of(I1, value),
Index: olena/TODO
--- olena/TODO (révision 0)
+++ olena/TODO (révision 0)
@@ -0,0 +1,17 @@
+* Possibly dead code
+
+** oln/core/compose.hh
+Seems to be used nowhere. Morever, redundant with the new
+oln/funobj/compose.hh, which deals with oln/funobj functors (whereas
+the former handles functors à la STL).
+
+
+* Lack of consistency in file naming
+
+** oln/level/compare.hh vs oln/ops/cmp.hh
+
+
+Local Variables:
+mode: outline
+ispell-local-dictionary: "american"
+End:
Index: olena/oln/convert/abstract/conversion.hh
--- olena/oln/convert/abstract/conversion.hh (révision 0)
+++ olena/oln/convert/abstract/conversion.hh (révision 0)
@@ -0,0 +1,179 @@
+// Copyright (C) 2001, 2002, 2003, 2004, 2005 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLENA_CONVERT_ABSTRACT_CONVERSION_HH
+# define OLENA_CONVERT_ABSTRACT_CONVERSION_HH
+
+# include <ntg/utils/debug.hh>
+# include <functional>
+
+namespace oln {
+
+ namespace convert {
+ /*!
+ ** \brief Base classes for conversion.
+ */
+ namespace abstract {
+
+ // fwd_decl
+ template <class Exact, class Base>
+ class conversion;
+
+ template<class Result_Type,
+ class Exact, class Base>
+ struct conversion_to_type;
+
+ template<class Argument_Type, class Result_Type,
+ class Exact, class Base>
+ struct conversion_from_type_to_type;
+
+ template<class Conv>
+ struct conversion_traits;
+
+ /*! \brief Internal purpose only.
+ */
+ namespace internal {
+ /// Retrieve the result type of a conversion.
+ template <class Base, class T>
+ struct output {};
+
+ template <class Argument_Type, class Result_Type,
+ class Exact, class Base>
+ struct output<conversion_from_type_to_type<Argument_Type, Result_Type, Exact, Base >, Argument_Type>
+ {
+ typedef Result_Type ret;
+ };
+
+ template <class Result_Type,
+ class Exact, class Base, class T>
+ struct output<conversion_to_type<Result_Type, Exact, Base >, T>
+ {
+ typedef Result_Type ret;
+ };
+
+ } // end of namespace oln::convert::abstract::internal
+
+ } // end of namespace oln::convert::abstract
+
+ namespace abstract {
+
+ /*! Base class for conversion.
+ **
+ ** \note If you write an class derived from this one, you
+ ** must write the specialization of the output trait.
+ */
+ template<class Exact, class Base>
+ struct conversion : public mlc::any< Exact >
+ {
+ static std::string
+ name()
+ {
+ return std::string("conversion<") + Exact::name() + ">";
+ }
+
+ public:
+ template<class T>
+ struct output
+ {
+ typedef typename internal::output<Base, T>::ret ret;
+ };
+
+ /// Call the conversion written in the exact class.
+ template <class T>
+ typename output<T>::ret
+ operator()(const T& in) const
+ {
+ return this->exact().doit(in);
+ }
+
+ protected:
+ conversion() {}
+ };
+
+ /// Base class for the conversion to a specific type.
+ template<class Result_Type, class Exact,
+ class Base = conversion_to_type<Result_Type, Exact, Exact> >
+ struct conversion_to_type :
+ public conversion< Exact, Base >
+ {
+ /* Additionally define result_type. This is not required
+ in a conversion class (generally not possible to define).
+ But it's useful when it's available (like here)
+ because it make the conversion appear almost as Adaptable
+ Unary Function (it will just lack the argument_type, but
+ this typedef is not used very much.) */
+
+ typedef Result_Type result_type;
+
+ static std::string
+ name()
+ {
+ // FIXME: Exact is not an integre type !
+ return std::string("conversion_to_type<")
+ + ntg_name(Result_Type) + ", "
+ + Exact::name() + ">";
+ }
+
+ protected:
+ conversion_to_type() {}
+ };
+
+ /// Base class if both input and output types of the conversion
+ /// are fixed.
+ template<class Argument_Type, class Result_Type, class Exact,
+ class Base = conversion_from_type_to_type<Argument_Type, Result_Type, Exact, Exact> >
+ struct conversion_from_type_to_type:
+ public conversion_to_type< Result_Type, Exact , Base >
+ {
+
+ /* By defining argument_type, and inheriting from result_type,
+ we comply to the STL concept of Adaptable Unary Function. */
+
+ typedef Argument_Type argument_type;
+
+ static std::string
+ name()
+ {
+ // FIXME: Exact is not an integre type !
+ return std::string("conversion_from_type_to_type<")
+ + ntg_name(Argument_Type) + ", "
+ + ntg_name(Result_Type) + ", "
+ + "FIXME: ntg_name(Exact)" + ">";
+ }
+
+ protected :
+ conversion_from_type_to_type() {}
+ };
+
+ } // end of namespace oln::convert::abstract
+
+ } // end of namespace oln::convert
+
+} // end of namespace oln
+
+
+#endif // OLENA_CONVERT_ABSTRACT_CONVERSION_HH
1
0