https://svn.lrde.epita.fr/svn/oln/trunk/milena
Please feel free to revert my changes if you think they're not
relevant ! :)
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Minor fixes on the First Part of the Milena Tutorial.
* doc/tutorial/slides.tex: Typos and aesthetic changes..
slides.tex | 72 ++++++++++++++++++++++++++++++++++---------------------------
1 file changed, 41 insertions(+), 31 deletions(-)
Index: doc/tutorial/slides.tex
--- doc/tutorial/slides.tex (revision 1444)
+++ doc/tutorial/slides.tex (working copy)
@@ -252,7 +252,7 @@
\begin{block}{No!}
\begin{itemize}
- \item \mln is rather different that available libraries.
+ \item \mln is rather different than available libraries.
\item A lot of convenient data structures that \emph{really} helps
you in developing IP solutions.
\end{itemize}
@@ -310,7 +310,7 @@
\smallskip
\begin{lstlisting}[basicstyle={\tiny\sffamily}]
template <typename I, typename H>
-void oper(Image<I>& f_, const Function_v2v<H>& h_)
+void transform_inplace(Image<I>& f_, const Function_v2v<H>& h_)
{
I& f = exact(f);
const H& h = exact(h_);
@@ -333,7 +333,7 @@
template< typename H,
template< class U > class get_A = get_value,
typename P = Pred_true >
-struct oper
+struct transform_inplace
{
template< typename I > static
void on( I& f,
@@ -389,7 +389,7 @@
\begin{itemize}
\item Generic...
\item Efficient so that one can process large images.
- \item Quite as easy to use than a C or Java library.
+ \item Quite as easy to use as a C or Java library.
\item Many tools to help writing readable algorithms in a concise way.
\end{itemize}
@@ -435,7 +435,7 @@
\begin{block}{\mln is easy to use}
\begin{itemize}
\item Just slightly more difficult to use than a library in C or Java.
- \item The user mainly write procedure calls.
+ \item The user mainly write routine calls.
\end{itemize}
\end{block}
@@ -703,7 +703,7 @@
an object.
\begin{itemize}
- \item it allows for initializing the state of this object
+ \item it allows initializing the state of this object
\end{itemize}
\end{block}
@@ -767,17 +767,20 @@
The previous example is just the \cpp equivalent of this C code:
\begin{lstlisting}
+#include <stdio.h>
+
struct point2d {
int row, col;
};
-int get_row(point2d p) {
+int get_row(struct point2d p) {
return p.row;
}
int main() {
- point2d p;
- printf("%d", get_row(p));
+ struct point2d p;
+ printf("%d\n", get_row(p));
+ return 0;
}
\end{lstlisting}
@@ -793,21 +796,22 @@
\begin{lstlisting}
p.row() = 7; // method call
-std::cout << p.row() << std::endl; // now give 7
+std::cout << p.row() << std::endl; // now gives 7
\end{lstlisting} % >>
\smallskip
the C equivalent of this method would be:
\begin{lstlisting}
-void set_row(point2d* p, int r) {
+void set_row(struct point2d* p, int r) {
assert(p != 0);
p->row = r;
}
int main() {
- point2d p;
+ struct point2d p;
set_row(&p, 7);
+ return 0;
}
\end{lstlisting}
@@ -820,7 +824,7 @@
\begin{frame}[fragile]
\frametitle{Modifying the State of an Object (2/2)}
- accessing and modifying through method calls allow for some controls:
+ accessing and modifying through method calls allow some control:
\begin{itemize}
\item one cannot do everything with an object
\item especially putting it in an invalid state
@@ -1111,7 +1115,8 @@
int main() {
rabbit r;
feed(r); // first call
- sheep s; feed(s); // another call
+ sheep s;
+ feed(s); // another call
}
\end{lstlisting}
@@ -1255,7 +1260,7 @@
Sample use:
\begin{lstlisting}
-std:::cout << point2d::dim << std::endl; // gives 2
+std::cout << point2d::dim << std::endl; // gives 2
point2d::coord c; // \code{c} is an \code{int}
\end{lstlisting}
@@ -1370,7 +1375,7 @@
\begin{itemize}
\item it is redundant
\begin{itemize}
- \item tedious to write (copy-paste, many lines at end)
+ \item tedious to write (copy-paste, many lines at the end)
\item thus error-prone
\end{itemize}
\smallskip
@@ -1385,7 +1390,7 @@
\end{itemize}
\end{itemize}
-Though overload is great; think of \code{operator*}...
+Nevertheless overloading is great; think of \code{operator*}...
\end{frame}
@@ -1404,14 +1409,14 @@
\begin{lstlisting}
// ...
T twice(T t) {
- return t;
+ return 2 * t;
}
\end{lstlisting}
except that we have to say first what \code{T} is:
\begin{lstlisting}
template <typename T>
T twice(T t) {
- return t;
+ return 2 * t;
}
\end{lstlisting}
@@ -1456,10 +1461,10 @@
With
\begin{lstlisting}
int main() {
- int i = 1, j;
- j = twice(i); // Calls twice with \code{T} being \kw{int}
- float pi = 3.14, two_pi;
- two_pi = twice(pi); // Calls another ``version'' of twice with \code{T} being \kw{float}
+ int i = 1;
+ int j = twice(i); // Calls twice with \code{T} being \kw{int}
+ float pi = 3.14;
+ float two_pis = twice(pi); // Calls another ``version'' of twice with \code{T} being \kw{float}
}
\end{lstlisting}
@@ -1516,7 +1521,7 @@
f_a: \left\{
\begin{array}{lll}
\mathbb{R} &\rightarrow & \mathbb{R} \\
- x & \leadsto & \cos(a x)
+ x & \mapsto & \cos(a x)
\end{array}
\right.
$$
@@ -1620,7 +1625,7 @@
point2d p(4, -1);
dpoint2d dp(1, 2); // \code{dpoint} is ``delta-point'' for short
std::cout << (p + dp) << std::endl; // gives (5, 1)
-\end{lstlisting}
+\end{lstlisting}% Please Emacs. >>
\end{frame}
@@ -1632,14 +1637,16 @@
Our objectives:
\begin{itemize}
-\item write the \code{operator+} (resp. '-') routine corresponding to\\
+\item write the \code{operator+} (resp. '\code{-}') routine corresponding to\\
\begin{center}
- ``a \code{point2d} ~+~ a \code{dpoint2d} $~\rightarrow~$ a \code{point2d}''
+ ``a \code{point2d} ~+~ a \code{dpoint2d} $~\mapsto~$ a
+ \code{point2d}''
\end{center}
%
\item understand that we actually want:\\
\begin{center}
- ``any \code{point P} ~+~ a compatible \code{dpoint D} $~\rightarrow~$ a \code{point P}''
+ ``any \code{point P} ~+~ a compatible \code{dpoint D} $~\mapsto~$
+ a \code{point P}''
\end{center}
\scriptsize{for instance with \code{P} and \code{D} being
respectively \code{point3d} and \code{dpoint3d}}
@@ -1958,12 +1965,14 @@
\begin{center}
\begin{tabular}{lp{5mm}l}
- the class && derives from \\
+ the class && derives from (``is a'') \\
&&\\
\lstinline@point2d@ && \lstinline@Point< point2d >@ \\
\lstinline@point3d@ && \lstinline@Point< point3d >@ \\
&&\\
\lstinline@image2d<float>@ && \lstinline@Image< image2d<float> >@ \\
+ \lstinline@image3d<int>@ && \lstinline@Image< image3d<int> >@ \\
+ &&\\
\lstinline@win::rectangle@ && \lstinline@Window< win::rectangle >@ \\
&&\\
\lstinline@box2d@ && \lstinline@Point_Set< box2d >@ \\
@@ -2023,7 +2032,7 @@
\begin{lstlisting}
template <typename E>
-class Dpoint<E>
+class Dpoint
{};
class dpoint2d : public Dpoint< dpoint2d >
@@ -2085,7 +2094,8 @@
\end{lstlisting}
\begin{block}{Exact}
- The ``\code{exact}'' routine allows for getting a variable with the exact type of an object.
+ The ``\code{exact}'' routine allows getting a variable with the
+ exact type of an object.
\end{block}
\end{frame}
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-11-06 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add an iterator on branch.
* mln/util/branch_iter_ind.hh: New, this is a copy of
branch_iter, but this one can walk a tree in which we are push_backing
elements.
---
branch_iter_ind.hh | 198 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 198 insertions(+)
Index: trunk/milena/mln/util/branch_iter_ind.hh
===================================================================
--- trunk/milena/mln/util/branch_iter_ind.hh (revision 0)
+++ trunk/milena/mln/util/branch_iter_ind.hh (revision 1440)
@@ -0,0 +1,198 @@
+// Copyright (C) 2007 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, 51 Franklin Street, Fifth Floor,
+// 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 MLN_UTIL_BRANCH_ITER_HH
+# define MLN_UTIL_BRANCH_ITER_HH
+
+# include <stack>
+# include <mln/util/tree.hh>
+/*!
+ * \file mln/util/branch.hh
+ *
+ * \brief Definition of a iterator on branch.
+ *
+ */
+
+namespace mln
+{
+
+ namespace util
+ {
+
+ /*! \brief Basic 2D image class.
+ *
+ * The parameter \c T is the type of node's data. branch_iter is used to pre-order walk a branch.
+
+ */
+ template <typename T>
+ class branch_iter
+ {
+ public:
+ branch_iter(branch<T> branch);
+
+ /// Convertion to node.
+ operator util::node<T>&() const;
+ util::node<T>& operator *();
+
+ /// Test the iterator validity.
+ bool is_valid() const;
+
+ /// Invalidate the iterator.
+ void invalidate();
+
+ /// Start an iteration.
+ void start();
+
+ /// Go to the next point.
+ void next();
+
+ /// Give how deep is the iterator in the branch.
+ unsigned deepness() const;
+ private:
+ /// The branch to iter.
+ util::branch<T> branch_;
+
+
+ typedef typename std::vector< util::node<T>* > child_list;
+ typedef std::pair< child_list*, int> iter_pair;
+ /// Store child().begin() and child().end().
+ std::stack< iter_pair > s_;
+
+ util::node<T>* n_;
+ };
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename T>
+ branch_iter<T>::branch_iter(branch<T> branch)
+ : branch_(branch)
+ {
+ invalidate();
+ }
+
+ template <typename T>
+ branch_iter<T>::operator node<T>&() const
+ {
+ mln_assertion(n_);
+ return *n_;
+ }
+
+ template <typename T>
+ util::node<T>&
+ branch_iter<T>::operator*()
+ {
+ mln_assertion(n_);
+ return *n_;
+ }
+
+ template <typename T>
+ unsigned
+ branch_iter<T>::deepness() const
+ {
+ mln_assertion(is_valid());
+ unsigned i = 0;
+ node<T>* p = n_;
+ while (p)
+ {
+ p = p->parent();
+ i++;
+ }
+ return i;
+ }
+
+ template <typename T>
+ bool
+ branch_iter<T>::is_valid() const
+ {
+ return n_ != 0;
+ }
+
+ template <typename T>
+ void
+ branch_iter<T>::invalidate()
+ {
+ n_ = 0;
+ }
+
+
+ template <typename T>
+ void
+ branch_iter<T>::start()
+ {
+ s_.push(make_pair(&branch_.apex().children(), 0));
+
+ n_ = &branch_.apex();
+ }
+
+ template <typename T>
+ void
+ branch_iter<T>::next()
+ {
+ // First : list of children.
+ // Second : i;
+
+ if (s_.size() == 0)
+ invalidate();
+ else
+ {
+ if ((s_.top().first->size()) == s_.top().second)
+ {
+ s_.pop();
+ next();
+ return;
+ }
+ else
+ {
+ n_ = (*(s_.top().first))[s_.top().second];
+ s_.top().second++;
+
+ if (!n_)
+ {
+ next();
+ return;
+ }
+
+ mln_assertion(n_);
+ if (n_->children().size() > 0)
+ {
+ s_.push(make_pair(&n_->children(), 0));
+ }
+ return;
+ }
+ }
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+
+ }
+
+} // end of namespace mln
+
+
+#endif // !MLN_UTIL_BRANCH_HH