2005-04-08 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
* ntg/decls.hh: New file.
Index: ntg/decls.hh
===================================================================
--- ntg/decls.hh (revision 0)
+++ ntg/decls.hh (revision 0)
@@ -0,0 +1,63 @@
+// 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 NTG_DECLS_HH
+# define NTG_DECLS_HH
+
+# include <ntg/vect/cplx_representation.hh>
+
+
+namespace ntg
+{
+
+ // abstract classes
+ template <typename E> class value;
+ template <typename E> class enum_value;
+ template <typename E> class real_value;
+ template <typename E> class float_value;
+ template <typename E> class int_value;
+ template <typename E> class uint_value;
+ template <typename E> class sint_value;
+ template <typename E> class vect_value;
+ template <unsigned N, class T, class E> class vec;
+ template <typename E> class color_value;
+
+ // concrete classes
+ class bin;
+ template <unsigned nbits, class behavior> class int_u;
+ template <unsigned nbits, class behavior> class int_s;
+ template <class T, class interval> class cycle;
+ template <class T, class interval, class behavior> class range;
+ template <cplx_representation R, class T> class cplx;
+ template <unsigned ncomps, unsigned qbits,
+ template <unsigned> class color_system> struct color;
+
+} // end of namespace ntg
+
+
+#endif // ! NTG_DECLS_HH
+
Index: ChangeLog
from Nicolas Widynski <nicolas.widynski(a)lrde.epita.fr>
* oln/core/abstract/niter.hh: New. Abstract neighborhood iterator class.
* oln/core/abstract/regular_niter.hh: New. Abstract neighborhood iterator for windows.
* oln/core/2d/fwd_regular_niter2d.hh: New. Concrete 2d neighborhood class
2d/fwd_regular_niter2d.hh | 138 +++++++++++++++++++++++++++++++++++++++
abstract/niter.hh | 159 ++++++++++++++++++++++++++++++++++++++++++++++
abstract/regular_niter.hh | 138 +++++++++++++++++++++++++++++++++++++++
3 files changed, 435 insertions(+)
Index: oln/core/abstract/niter.hh
--- oln/core/abstract/niter.hh (revision 0)
+++ oln/core/abstract/niter.hh (revision 0)
@@ -0,0 +1,159 @@
+// 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_CORE_ABSTRACT_NITER_HH
+# define OLENA_CORE_ABSTRACT_NITER_HH
+
+# include <vector>
+
+# include <mlc/any.hh>
+# include <mlc/types.hh>
+# include <mlc/contract.hh>
+
+# include <oln/core/gen/image_with_nbh.hh>
+# include <oln/core/abstract/point.hh>
+# include <oln/core/properties.hh>
+# include <oln/core/abstract/image.hh>
+# include <oln/core/abstract/neighborhood.hh>
+# include <oln/core/abstract/image_neighbness.hh>
+
+
+# define for_all_n(n) \
+ for(n.start(); n.is_valid(); n.next())
+
+# define for_all_remaining_n(n) \
+ for(; n.is_valid(); n.next())
+
+
+// FIXME : bad place
+# include <oln/core/abstract/piter.hh>
+
+# define for_all_n_of_p(p, n) \
+ for(p.start(); p.is_valid(); p.next()) \
+ for(n.center_at(p), n.start(); n.is_valid(); n.next())
+
+namespace oln {
+
+ // fwd decl
+ namespace abstract {
+ template <typename E> struct niter;
+ }
+
+ // category
+ template <typename E>
+ struct set_category< abstract::niter<E> > { typedef category::niter ret; };
+
+
+ /// properties of any type in category::niter
+
+ template <typename type>
+ struct props_of < category::niter, type >
+ {
+ typedef mlc::true_type user_defined_;
+
+ mlc_decl_prop(category::niter, point_type);
+ mlc_decl_prop(category::niter, dpoint_type);
+ mlc_decl_prop(category::niter, neighb_type);
+ mlc_decl_prop(category::niter, image_type);
+
+ static void echo(std::ostream& ostr)
+ {
+ ostr << "props_of( category::niter, "
+ << typeid(type).name() << ") = {"
+ << " neighb_type = " << typeid(neighb_type).name()
+ << " image_type = " << typeid(image_type).name()
+ << " point_type = " << typeid(point_type).name() << " }" << std::endl;
+ }
+
+ };
+
+ mlc_register_prop(category::niter, neighb_type);
+ mlc_register_prop(category::niter, point_type);
+ mlc_register_prop(category::niter, dpoint_type);
+ mlc_register_prop(category::niter, image_type);
+
+
+ namespace abstract {
+
+ template <typename E>
+ struct niter : public mlc::any__best_speed<E>
+ {
+
+ /// typedefs
+
+ typedef niter<E> self_type;
+
+ typedef oln_type_of(E, point) point_type;
+ typedef oln_type_of(E, neighb) neighb_type;
+ typedef oln_type_of(E, image) image_type;
+
+ void start()
+ {
+ this->exact().impl_start();
+ }
+
+ void next()
+ {
+ this->exact().impl_next();
+ }
+
+ operator point_type() const
+ {
+ return this->exact().impl_cast_point();
+ }
+
+ void center_at(const point_type& pt)
+ {
+ this->exact().impl_center_at(pt);
+ }
+
+ bool is_valid() const
+ {
+ return this->exact().impl_is_valid();
+ }
+
+ void invalidate()
+ {
+ return this->exact().impl_invalidate();
+ }
+
+ protected:
+
+ template <typename T>
+ niter(const abstract::image_with_nbh<T>& ima) :
+ p_(), nbh_(ima.nbh_get())
+ {
+ }
+
+ point_type p_;
+ const neighb_type& nbh_;
+ };
+ }
+}
+
+
+#endif // ! OLENA_CORE_ABSTRACT_NITER_HH
Index: oln/core/abstract/regular_niter.hh
--- oln/core/abstract/regular_niter.hh (revision 0)
+++ oln/core/abstract/regular_niter.hh (revision 0)
@@ -0,0 +1,138 @@
+// 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_CORE_ABSTRACT_REGULAR_NITER_HH
+# define OLENA_CORE_ABSTRACT_REGULAR_NITER_HH
+
+# include <vector>
+
+# include <mlc/any.hh>
+# include <mlc/types.hh>
+# include <mlc/contract.hh>
+
+# include <oln/core/abstract/niter.hh>
+# include <oln/core/gen/image_with_nbh.hh>
+# include <oln/core/abstract/point.hh>
+# include <oln/core/abstract/dpoint.hh>
+# include <oln/core/properties.hh>
+# include <oln/core/abstract/image.hh>
+# include <oln/core/abstract/neighborhood.hh>
+# include <oln/core/abstract/image_neighbness.hh>
+
+
+namespace oln {
+
+ // fwd decls
+
+ namespace abstract {
+ template <typename E> struct regular_niter;
+ }
+
+ // category
+
+ template <typename E>
+ struct set_category< abstract::regular_niter<E> > {
+ typedef category::niter ret;
+ };
+
+ // super type
+
+ template <typename E>
+ struct set_super_type < abstract::regular_niter<E> >
+ {
+ typedef abstract::niter<E> ret;
+ };
+
+
+ namespace abstract {
+
+ template <typename E>
+ struct regular_niter : public niter<E>
+ {
+
+ /// typedefs
+ typedef oln_type_of(E, point) point_type;
+ typedef oln_type_of(E, dpoint) dpoint_type;
+ typedef regular_niter<E> self_type;
+
+ void impl_start()
+ {
+ dp_cur_ = dp_.begin();
+ }
+
+ void impl_next()
+ {
+ precondition(this->is_valid());
+ dp_cur_ ++;
+ }
+
+ void impl_center_at(const point_type& pt)
+ {
+ this->p_ = pt;
+ dp_.clear();
+ this->exact().impl_determine_neighb();
+ }
+
+ bool impl_is_valid() const
+ {
+ return dp_cur_ != dp_.end();
+ }
+
+ const point_type impl_cast_point() const
+ {
+ precondition(this->is_valid());
+ return *dp_cur_ + this->p_;
+ }
+
+ void impl_invalidate()
+ {
+ dp_cur_ = dp_.end();
+ postcondition(! this->is_valid());
+ }
+
+ protected:
+
+ void impl_determine_neighb()
+ {
+ for (unsigned i = 0; i < this->nbh_.card(); ++i)
+ dp_.push_back(this->nbh_[i]);
+ }
+
+ template <typename T>
+ regular_niter(const abstract::image_with_nbh<T>& ima) :
+ niter<E>(ima)
+ {
+ }
+
+ typename std::vector<dpoint_type>::iterator dp_cur_;
+ std::vector<dpoint_type> dp_;
+ };
+ }
+}
+
+
+#endif // ! OLENA_CORE_ABSTRACT_REGULAR_NITER_HH
Index: oln/core/2d/fwd_regular_niter2d.hh
--- oln/core/2d/fwd_regular_niter2d.hh (revision 0)
+++ oln/core/2d/fwd_regular_niter2d.hh (revision 0)
@@ -0,0 +1,138 @@
+// 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_CORE_ABSTRACT_REGULAR_NITER_HH
+# define OLENA_CORE_ABSTRACT_REGULAR_NITER_HH
+
+# include <vector>
+
+# include <mlc/any.hh>
+# include <mlc/types.hh>
+# include <mlc/contract.hh>
+
+# include <oln/core/abstract/niter.hh>
+# include <oln/core/gen/image_with_nbh.hh>
+# include <oln/core/abstract/point.hh>
+# include <oln/core/abstract/dpoint.hh>
+# include <oln/core/properties.hh>
+# include <oln/core/abstract/image.hh>
+# include <oln/core/abstract/neighborhood.hh>
+# include <oln/core/abstract/image_neighbness.hh>
+
+
+namespace oln {
+
+ // fwd decls
+
+ namespace abstract {
+ template <typename E> struct regular_niter;
+ }
+
+ // category
+
+ template <typename E>
+ struct set_category< abstract::regular_niter<E> > {
+ typedef category::niter ret;
+ };
+
+ // super type
+
+ template <typename E>
+ struct set_super_type < abstract::regular_niter<E> >
+ {
+ typedef abstract::niter<E> ret;
+ };
+
+
+ namespace abstract {
+
+ template <typename E>
+ struct regular_niter : public niter<E>
+ {
+
+ /// typedefs
+ typedef oln_type_of(E, point) point_type;
+ typedef oln_type_of(E, dpoint) dpoint_type;
+ typedef regular_niter<E> self_type;
+
+ void impl_start()
+ {
+ dp_cur_ = dp_.begin();
+ }
+
+ void impl_next()
+ {
+ precondition(this->is_valid());
+ dp_cur_ ++;
+ }
+
+ void impl_center_at(const point_type& pt)
+ {
+ this->p_ = pt;
+ dp_.clear();
+ this->exact().impl_determine_neighb();
+ }
+
+ bool impl_is_valid() const
+ {
+ return dp_cur_ != dp_.end();
+ }
+
+ const point_type impl_cast_point() const
+ {
+ precondition(this->is_valid());
+ return *dp_cur_ + this->p_;
+ }
+
+ void impl_invalidate()
+ {
+ dp_cur_ = dp_.end();
+ postcondition(! this->is_valid());
+ }
+
+ protected:
+
+ void impl_determine_neighb()
+ {
+ for (unsigned i = 0; i < this->nbh_.card(); ++i)
+ dp_.push_back(this->nbh_[i]);
+ }
+
+ template <typename T>
+ regular_niter(const abstract::image_with_nbh<T>& ima) :
+ niter<E>(ima)
+ {
+ }
+
+ typename std::vector<dpoint_type>::iterator dp_cur_;
+ std::vector<dpoint_type> dp_;
+ };
+ }
+}
+
+
+#endif // ! OLENA_CORE_ABSTRACT_REGULAR_NITER_HH