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_
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
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 \
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
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