2006-09-20 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
Add classes for classical 2d neighborhood.
* oln/core/neighborhood_entry.hh: New.
* oln/core/abstract/neighborhood.hh: New.
* oln/core/2d/neighb2d.hh: New.
* oln/core/gen/neighb.hh: New.
* oln/core/2d/aliases.hh (neighb2d): New.
* oln/basics2d.hh: Update.
Index: oln/core/neighborhood_entry.hh
===================================================================
--- oln/core/neighborhood_entry.hh (revision 0)
+++ oln/core/neighborhood_entry.hh (revision 0)
@@ -0,0 +1,63 @@
+// Copyright (C) 2006 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 OLENA_CORE_NEIGHBORHOOD_ENTRY_HH
+# define OLENA_CORE_NEIGHBORHOOD_ENTRY_HH
+
+# include <oln/core/abstract/entry.hh>
+# include <oln/core/abstract/neighborhood.hh>
+
+
+
+namespace oln
+{
+
+
+ /// Entry class for point sets: neighborhood_entry<E> is an alias for
+ /// entry< abstract::neighborhood, E>.
+
+ template <typename E>
+ struct neighborhood_entry : public entry< abstract::neighborhood, E>
+ {
+ protected:
+ neighborhood_entry() {}
+ };
+
+
+ /// Virtual types associated to neighborhood_entry<E>.
+
+ template <typename E>
+ struct vtypes< neighborhood_entry<E> >
+ {
+ typedef mlc::undefined grid_type;
+ };
+
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_CORE_NEIGHBORHOOD_ENTRY_HH
Index: oln/core/abstract/neighborhood.hh
===================================================================
--- oln/core/abstract/neighborhood.hh (revision 0)
+++ oln/core/abstract/neighborhood.hh (revision 0)
@@ -0,0 +1,82 @@
+// Copyright (C) 2006 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 OLENA_CORE_ABSTRACT_NEIGHBORHOOD_HH
+# define OLENA_CORE_ABSTRACT_NEIGHBORHOOD_HH
+
+# include <oln/core/typedefs.hh>
+
+
+namespace oln
+{
+
+ namespace abstract
+ {
+
+
+ /// Abstract neighborhood class.
+ template <typename E>
+ class neighborhood : public virtual stc::any__simple<E>,
+ public virtual oln::type
+ {
+ public:
+
+ bool is_valid() const
+ {
+ return this->exact().impl_is_valid();
+ }
+
+ struct decl
+ {
+ stc_virtual_typedef(grid);
+
+ decl() {
+ }
+ };
+
+ protected:
+
+ neighborhood()
+ {}
+
+ ~neighborhood() { decl(); }
+
+ }; // end of class oln::abstract::neighborhood<E>
+
+
+
+ } // end of namespace oln::abstract
+
+} // end of namespace oln
+
+
+
+// # include <oln/core/abstract/neighborhood_hierarchies.hh>
+
+
+
+#endif // ! OLENA_CORE_ABSTRACT_NEIGHBORHOOD_HH
Index: oln/core/2d/aliases.hh
===================================================================
--- oln/core/2d/aliases.hh (revision 552)
+++ oln/core/2d/aliases.hh (working copy)
@@ -37,6 +37,7 @@
/// Forward declarations.
template <typename C> class point2d_;
template <typename C> class dpoint2d_;
+ template <typename D> class neighb_;
template <typename P> class bbox_;
template <typename P> class topo_bbox_;
template <typename P> class bbox_fwd_piter_;
@@ -50,6 +51,8 @@
typedef point2d_<int> point2d;
typedef dpoint2d_<int> dpoint2d;
+ typedef neighb_<dpoint2d> neighb2d;
+
typedef bbox_<point2d> bbox2d;
typedef bbox_fwd_piter_<point2d> fwd_piter2d;
typedef bbox_bkd_piter_<point2d> bkd_piter2d;
Index: oln/core/2d/neighb2d.hh
===================================================================
--- oln/core/2d/neighb2d.hh (revision 0)
+++ oln/core/2d/neighb2d.hh (revision 0)
@@ -0,0 +1,104 @@
+// Copyright (C) 2001, 2002, 2003, 2004, 2006 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 OLENA_CORE_2D_NEIGHB2D_HH
+# define OLENA_CORE_2D_NEIGHB2D_HH
+
+# include <oln/core/gen/neighb.hh>
+# include <oln/core/2d/aliases.hh>
+
+
+namespace oln
+{
+
+
+ neighb2d c4()
+ {
+ static bool flower = true;
+ static neighb2d the_;
+ if (flower)
+ {
+ the_
+ .add(dpoint2d(0, 1))
+ .add(dpoint2d(1, 0));
+ flower = false;
+ }
+ return the_;
+ }
+
+
+ neighb2d c8()
+ {
+ static bool flower = true;
+ static neighb2d the_;
+ if (flower)
+ {
+ the_
+ .add(dpoint2d(0, 1))
+ .add(dpoint2d(1,-1))
+ .add(dpoint2d(1, 0))
+ .add(dpoint2d(1, 1));
+ flower = false;
+ }
+ return the_;
+ }
+
+
+ neighb2d c2_row()
+ {
+ static bool flower = true;
+ static neighb2d the_;
+ if (flower)
+ {
+ the_
+ .add(dpoint2d(0, 1));
+ flower = false;
+ }
+ return the_;
+ }
+
+
+ neighb2d c2_col()
+ {
+ static bool flower = true;
+ static neighb2d the_;
+ if (flower)
+ {
+ the_
+ .add(dpoint2d(1, 0));
+ flower = false;
+ }
+ return the_;
+ }
+
+
+} // end of namespace oln
+
+
+
+#endif // ! OLENA_CORE_2D_NEIGHB2D_HH
+
Index: oln/core/gen/neighb.hh
===================================================================
--- oln/core/gen/neighb.hh (revision 0)
+++ oln/core/gen/neighb.hh (revision 0)
@@ -0,0 +1,123 @@
+// Copyright (C) 2001, 2003, 2004, 2005, 2006 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 OLENA_CORE_GEN_NEIGHB_HH
+# define OLENA_CORE_GEN_NEIGHB_HH
+
+# include <set>
+# include <vector>
+# include <oln/core/neighborhood_entry.hh>
+
+
+namespace oln
+{
+
+
+ // Forward declaration.
+ template <typename dpoint> class neighb_;
+
+
+ // Super type declaration.
+ template <typename dpoint>
+ struct set_super_type< neighb_<dpoint> >
+ {
+ typedef neighb_<dpoint> self_t;
+ typedef neighborhood_entry<self_t> ret;
+ };
+
+
+ /// Virtual types associated to oln::neighb_<dpoint>.
+ template <typename dpoint>
+ struct vtypes< neighb_<dpoint> >
+ {
+ typedef oln_type_of(dpoint, grid) grid_type;
+ };
+
+
+
+ /// Abstract forward dpoint iterator class.
+ template <typename dpoint>
+ class neighb_ : public neighborhood_entry< neighb_<dpoint> >,
+ private mlc::assert_< mlc_is_a(dpoint, abstract::dpoint) >
+ {
+ typedef neighb_<dpoint> self_t;
+ typedef neighborhood_entry<self_t> super_t;
+
+ public:
+
+ neighb_()
+ {
+ }
+
+ self_t& add(const dpoint& dp)
+ {
+ s_.insert(dp);
+ s_.insert(-dp);
+ update_();
+ return *this;
+ }
+
+ template <typename D>
+ self_t& add(const abstract::dpoint<D>& dp)
+ {
+ return this->add(dp.exact());
+ }
+
+ unsigned card() const
+ {
+ return v_.size();
+ }
+
+ dpoint dp(unsigned i) const
+ {
+ precondition(i < v_.size());
+ return v_[i];
+ }
+
+ // void print(std::ostream& ostr) const;
+ // friend std::ostream& operator<<(std::ostream& ostr, const
neighb_<dpoint>& nbh);
+
+ protected:
+
+ std::set<dpoint> s_;
+ std::vector<dpoint> v_;
+
+ void update_()
+ {
+ v_.clear();
+ std::copy(s_.begin(), s_.end(),
+ std::back_inserter(v_));
+ }
+
+ }; // end of class oln::neighb_<dpoint>
+
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_CORE_GEN_NEIGHB_HH
Index: oln/basics2d.hh
===================================================================
--- oln/basics2d.hh (revision 552)
+++ oln/basics2d.hh (working copy)
@@ -50,7 +50,11 @@
# include <oln/core/gen/topo_bbox.hh>
namespace oln { template class topo_bbox_<point2d>; }
+# include <oln/core/gen/neighb.hh>
+namespace oln { template class neighb_<dpoint2d>; }
+# include <oln/core/2d/neighb2d.hh>
+
# include <oln/core/2d/image2d.hh>