Olena-patches
Threads by month
- ----- 2025 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- 9625 discussions
Index: ChangeLog
from Alexandre Abraham <abraham(a)lrde.epita.fr>
Fix mini-oln, add mutable image type and rgb value.
* samples/mini-oln/mini-oln.cc,
samples/mini-oln/concept-c++/mini-oln.cc : code for image3d tests,
new lvalue_t and rvalue_t vtypes for mutable images.
* samples/mini-oln/mini-oln.cc,
(oln::Image::rvalue_t) : New typedef.
(oln::Image) : operator() now return a rvalue_t as it is a read
only Image by default
(oln::Image2d), (oln::Image3d) : operator() is now inherited
from oln::Image.
(oln::Mutable_Image) : New.
(oln::Mutable_Image::lvalue) : New typedef.
(oln::switch_image_base_mutable) : New.
(oln::image2d) : split impl_op_parens into two versions returning
rvalue_t and lvalue_t.
(oln::rgb) : new type.
(oln::Iterator3d) : New.
(oln::niter3d) : New.
(oln::Image3d) : New.
* samples/mini-oln/concept-c++/mini-oln.cc:
(oln::concepts::Image::rvalue_t) : New typedef.
(oln::concetps::Image) : operator() now return a rvalue_t as it is
a read only Image by default
(oln::concepts::Mutable_Image) : New.
(oln::concetps::Mutable_Image::lvalue) : New typedef.
(oln::image_mutability_switch) : New.
(oln::image2d) : split impl_op_parens into two versions returning
rvalue_t and lvalue_t.
(oln::Iterator3d) : New.
(oln::niter3d) : New.
(oln::Image3d) : New.
concept-c++/mini-oln.cc | 292 +++++++++++++++++++++++++++++++++--------
mini-oln.cc | 339 ++++++++++++++++++++++++++++++++++++++++++------
2 files changed, 538 insertions(+), 93 deletions(-)
Index: samples/mini-oln/mini-oln.cc
--- samples/mini-oln/mini-oln.cc (revision 888)
+++ samples/mini-oln/mini-oln.cc (working copy)
@@ -33,7 +33,7 @@
#include <mlc/case.hh>
#include <stc/any.hh>
#include <stc/scoop.hh>
-
+#include <iostream>
/*-------------.
| Equipement. |
@@ -47,7 +47,7 @@
typename oln_type_of_(FromType, Alias)
// Add equipment
-stc_scoop_equipment_for_namespace(oln);
+stc_scoop_equipment_for_namespace(oln)
mlc_case_equipment_for_namespace(oln);
// Virtual types declaration.
@@ -56,6 +56,8 @@
mlc_decl_typedef(point_type);
mlc_decl_typedef(iter_type);
mlc_decl_typedef(value_type);
+ mlc_decl_typedef(rvalue_type);
+ mlc_decl_typedef(lvalue_type);
mlc_decl_typedef(nbh_type);
mlc_decl_typedef(niter_type);
@@ -118,9 +120,9 @@
struct Image : public stc::any<E>
{
typedef oln_type_of(E, point) point_t;
- typedef oln_type_of(E, value) value_t;
+ typedef oln_type_of(E, rvalue) rvalue_t;
- value_t& operator ()(point_t& p)
+ rvalue_t operator ()(point_t& p) const
{
return this->exact().impl_op_parens(p);
}
@@ -137,16 +139,18 @@
// --------- //
template <typename E>
- struct Image2d : public Image<E>
+ struct Image2d : public virtual Image<E>
{
typedef oln_type_of(E, point) point_t;
- typedef oln_type_of(E, value) value_t;
- // FIXME: delete?
- value_t& operator ()(point_t& p)
- {
- return this->exact().impl_op_parens(p);
- }
+ // inherited from Image
+
+ // typedef oln_type_of(E, rvalue) rvalue_t;
+
+ // rvalue_t& operator ()(point_t& p)
+ // {
+ // return this->exact().impl_op_parens(p);
+ // }
int nrows_get() const
{
@@ -165,16 +169,18 @@
// --------- //
template <typename E>
- struct Image3d : public Image<E>
+ struct Image3d : public virtual Image<E>
{
typedef oln_type_of(E, point) point_t;
- typedef oln_type_of(E, value) value_t;
- // FIXME: delete?
- value_t& operator ()(point_t& p)
- {
- return this->exact().impl_op_parens(p);
- }
+ // inherited from Image
+
+ // typedef oln_type_of(E, rvalue) rvalue_t;
+
+ // rvalue_t& operator ()(point_t& p)
+ // {
+ // return this->exact().impl_op_parens(p);
+ // }
int nrows_get() const
{
@@ -193,12 +199,29 @@
};
+ // ------------- //
+ // Mutable_Image //
+ // ------------- //
+
+ template <typename E>
+ struct Mutable_Image : public virtual Image<E>
+ {
+ typedef oln_type_of(E, point) point_t;
+ typedef oln_type_of(E, lvalue) lvalue_t;
+
+ lvalue_t operator ()(point_t& p)
+ {
+ return this->exact().impl_op_parens(p);
+ }
+ };
+
+
// ------------------------- //
// Image_with_neighborhood. //
// ------------------------- //
template <typename E>
- struct Image_with_neighborhood : public Image<E>
+ struct Image_with_neighborhood : public virtual Image<E>
{
typedef oln_type_of(E, nbh) nbh_t;
typedef oln_type_of(E, niter) niter_t;
@@ -249,6 +272,25 @@
typedef Image<E> ret;
};
+ // ----------------- //
+ // Mutability Switch //
+ // ----------------- //
+
+ // Tag.
+ struct switch_image_base_mutable;
+
+ template <typename E>
+ struct case_<switch_image_base_mutable, E, 1> :
+ public mlc::where_ < mlc::is_found_< stc_vtype(oln, E, lvalue) > >
+ {
+ typedef Mutable_Image<E> ret;
+ };
+
+ template <typename E>
+ struct default_case_<switch_image_base_mutable, E>
+ {
+ typedef Image<E> ret;
+ };
// ------------ //
// Image base. //
@@ -269,13 +311,16 @@
typedef stc::abstract point_type;
typedef stc::abstract iter_type;
typedef stc::abstract value_type;
+ typedef stc::abstract rvalue_type;
+ typedef stc::abstract lvalue_type;
typedef mlc::none niter_type;
typedef mlc::none nbh_type;
};
template <typename E>
- struct image_base : public switch_<switch_image_base, E>::ret
+ struct image_base : public virtual switch_<switch_image_base, E>::ret,
+ public virtual switch_<switch_image_base_mutable, E>::ret
{
image_base()
{
@@ -362,7 +407,7 @@
return p.row < nrows;
}
- point_t& impl_op_point_type()
+ point_t impl_op_point_type() const
{
return p;
}
@@ -393,6 +438,8 @@
typedef point2d point_type;
typedef iterator2d iter_type;
typedef T value_type;
+ typedef value_type rvalue_type;
+ typedef value_type& lvalue_type;
};
template <typename T>
@@ -402,18 +449,24 @@
typedef oln_type_of(self_t, point) point_t;
typedef oln_type_of(self_t, iter) iter_t;
typedef oln_type_of(self_t, value) value_t;
+ typedef oln_type_of(self_t, rvalue) rvalue_t;
+ typedef oln_type_of(self_t, lvalue) lvalue_t;
image2d(int nrows, int ncols) :
- data (0),
nrows (nrows),
- ncols (ncols)
+ ncols (ncols),
+ data (nrows * ncols)
{
- data = new std::vector<value_t>;
}
- value_t& impl_op_parens(const point_t& p)
+ rvalue_t impl_op_parens(const point_t& p) const
{
- return this->data[p.row * nrows + p.col];
+ return this->data[p.row * ncols + p.col];
+ }
+
+ lvalue_t impl_op_parens(const point_t& p)
+ {
+ return this->data[p.row * ncols + p.col];
}
int impl_nrows_get() const
@@ -433,12 +486,11 @@
}
protected:
- std::vector<value_t>* data;
int nrows;
int ncols;
+ std::vector<value_t> data;
};
-
// ----------------- //
// Neighborhood 2d. //
// ----------------- //
@@ -451,6 +503,172 @@
};
+ // ------------- //
+ // Iterator 3d. //
+ // ------------- //
+
+ // Forward declarations.
+ struct iterator3d;
+ template <typename T> struct image3d;
+
+ template<>
+ struct set_super_type<iterator3d>
+ {
+ typedef mlc::none ret;
+ };
+
+ template <>
+ struct vtypes<iterator3d>
+ {
+ typedef point3d point_type;
+ };
+
+ struct iterator3d : public Iterator<iterator3d>
+ {
+ typedef oln_type_of_(iterator3d, point) point_t;
+
+ template <typename T>
+ iterator3d(image3d<T>& ima) :
+ nrows (ima.nrows_get()),
+ ncols (ima.ncols_get()),
+ nslis (ima.nslis_get())
+ {
+ }
+
+ void impl_start()
+ {
+ p.row = 0;
+ p.col = 0;
+ p.sli = 0;
+ }
+
+ void impl_next()
+ {
+ p.sli = p.sli + 1;
+
+ if (p.sli == nslis)
+ {
+ p.sli = 0;
+ p.col = p.col + 1;
+ }
+
+ if (p.col == ncols)
+ {
+ p.col = 0;
+ p.row = p.row + 1;
+ }
+ }
+
+ bool impl_is_valid() const
+ {
+ return p.row < nrows;
+ }
+
+ point_t impl_op_point_type() const
+ {
+ return p;
+ }
+
+ protected:
+ int nrows;
+ int ncols;
+ int nslis;
+ point_t p;
+ };
+
+ // ---------- //
+ // Image 3d. //
+ // ---------- //
+
+ // Forward declaration.
+ template <typename T> struct image3d;
+
+ template<typename T>
+ struct set_super_type< image3d<T> >
+ {
+ typedef image_base< image3d<T> > ret;
+ };
+
+ template <typename T>
+ struct vtypes< image3d<T> >
+ {
+ typedef point3d point_type;
+ typedef iterator3d iter_type;
+ typedef T value_type;
+ typedef value_type rvalue_type;
+ typedef value_type& lvalue_type;
+ };
+
+ template <typename T>
+ struct image3d : public image_base< image3d<T> >
+ {
+ typedef image3d<T> self_t;
+ typedef oln_type_of(self_t, point) point_t;
+ typedef oln_type_of(self_t, iter) iter_t;
+ typedef oln_type_of(self_t, value) value_t;
+ typedef oln_type_of(self_t, rvalue) rvalue_t;
+ typedef oln_type_of(self_t, lvalue) lvalue_t;
+
+ image3d(int nrows, int ncols, int nslis) :
+ nrows (nrows),
+ ncols (ncols),
+ nslis (nslis),
+ data (nrows * ncols * nslis)
+ {
+ }
+
+ rvalue_t impl_op_parens(const point_t& p) const
+ {
+ return this->data[p.row * ncols * nslis + p.col * nslis + p.sli];
+ }
+
+ lvalue_t impl_op_parens(const point_t& p)
+ {
+ return this->data[p.row * ncols * nslis + p.col * nslis + p.sli];
+ }
+
+ int impl_nrows_get() const
+ {
+ return nrows;
+ }
+
+ int impl_ncols_get() const
+ {
+ return ncols;
+ }
+
+ int nslis_get() const
+ {
+ return nslis;
+ }
+
+ bool impl_has(point_t& p) const
+ {
+ assert(!!data);
+ return p.row >= 0 && p.row < nrows && p.col >= 0 && p.col < ncols
+ && p.sli >= 0 && p.sli < nslis;
+ }
+
+ protected:
+ int nrows;
+ int ncols;
+ int nslis;
+ std::vector<value_t> data;
+ };
+
+
+ // ----------------- //
+ // Neighborhood 3d. //
+ // ----------------- //
+
+ struct niter3d {};
+
+ struct neighborhood3d
+ {
+ typedef niter3d niter_type;
+ };
+
+
// --------------- //
// Image morpher. //
// --------------- //
@@ -542,8 +760,32 @@
return res;
}
+ template <typename T>
+ struct rgb
+ {
+ public:
+ rgb () : data_(3) {}
+ T& r_get() { return data_[0]; }
+ T& g_get() { return data_[1]; }
+ T& b_get() { return data_[2]; }
+ T r_get() const { return data_[0]; }
+ T g_get() const { return data_[1]; }
+ T b_get() const { return data_[2]; }
+ T& operator[] (int i) { assert(i >= 0 && i < 3); return data_[i]; }
+ T operator[] (int i) const { assert(i >= 0 && i < 3); return data_[i]; }
+
+ private:
+ std::vector<T> data_;
+ };
+
} // End of namespace oln.
+/*-----------------.
+| Useful Typedefs |
+`-----------------*/
+
+//template <typename T>
+//typedef image2d< rgb<T> > image2d_rgb<T>;
/*--------------.
| Client code. |
@@ -554,24 +796,47 @@
using namespace oln;
point2d p;
- typedef image2d<int> ima_t;
- ima_t ima1(10, 10);
+ typedef image2d<int> ima_2D_t;
+ ima_2D_t ima1(10, 10);
- iterator2d it(ima1);
+ iterator2d it_2D(ima1);
- typedef neighborhood2d nbh_t;
+ typedef neighborhood2d nbh_2D_t;
// A type of image with neighborhood2d.
- typedef plus<ima_t, nbh_t> ima_wih_nbh_t;
- neighborhood2d nbh;
- ima_wih_nbh_t ima2(ima1, nbh);
+ typedef plus<ima_2D_t, nbh_2D_t> ima_wih_nbh_2D_t;
+ neighborhood2d nbh_2D;
+ ima_wih_nbh_2D_t ima2(ima1, nbh_2D);
// Another way to build an image with neigborhood.
- ima_wih_nbh_t ima3 = ima1 + nbh;
+ ima_wih_nbh_2D_t ima3 = ima1 + nbh_2D;
- // FIXME: Same with 3d.
+ // Same with 3d.
point3d q;
+ typedef image3d<int> ima_3D_t;
+ ima_3D_t ima1_3D(2, 2, 2);
+
+ iterator3d it_3D(ima1_3D);
+
+ typedef neighborhood3d nbh_3D_t;
+
+ // A type of image with neighborhood3d.
+ typedef plus<ima_3D_t, nbh_3D_t> ima_wih_nbh_3D_t;
+ neighborhood3d nbh_3D;
+ ima_wih_nbh_3D_t ima2_3D(ima1_3D, nbh_3D);
+ // Another way to build an image with neigborhood.
+ ima_wih_nbh_3D_t ima3_3D = ima1_3D + nbh_3D;
+
+ std::cout << "Show a 3D Image" << std::endl;
+ for (it_3D.start(); it_3D.is_valid(); it_3D.next())
+ {
+ point3d runner = it_3D;
+ std::cout << "[" << runner.row << ", " << runner.col << ", " << runner.sli << "] " << ima1_3D(runner) << std::endl;
+ }
// ...
+
+ rgb<int> tst;
+ std::cout << tst.r_get();
}
Index: samples/mini-oln/concept-c++/mini-oln.cc
--- samples/mini-oln/concept-c++/mini-oln.cc (revision 888)
+++ samples/mini-oln/concept-c++/mini-oln.cc (working copy)
@@ -49,7 +49,7 @@
typename oln_type_of_(FromType, Alias)
// Add equipment
-stc_scoop_equipment_for_namespace(oln);
+stc_scoop_equipment_for_namespace(oln)
mlc_case_equipment_for_namespace(oln);
// Virtual types declaration.
@@ -58,6 +58,8 @@
mlc_decl_typedef(point_type);
mlc_decl_typedef(iter_type);
mlc_decl_typedef(value_type);
+ mlc_decl_typedef(rvalue_type);
+ mlc_decl_typedef(lvalue_type);
mlc_decl_typedef(nbh_type);
mlc_decl_typedef(niter_type);
@@ -73,37 +75,20 @@
namespace concepts
{
- // These concepts are not automatic (i.e., prefixed with `auto'),
- // since we cannot rely on type signatures for them. For instance,
- // using only structural conformance, oln::point3d could be a model
- // of concepts::Point2d!
- concept Point2d<typename P>
+ auto concept Point<typename I>
{
typename coord_type;
- // For simplicity purpose, the canonical model of
- // concepts::Point2d -- oln::point2d -- does not expose its
- // interface through methods (that's bad OO software engineering
- // practice, but hey, we're just prototyping here). Therefore we
- // cannot express sigatures on row and col accesses, since C++0x
- // concepts forbid attribute (member) signatures.
- };
-
- concept Point3d<typename P>
- {
- typename coord_type;
- // Same remark as above for concepts::Point2d regarding member
- // signatures.
};
auto concept Image<typename I>
{
typename point_t;
typename iter_t;
- typename value_t;
+ typename rvalue_t;
// ConceptGCC doesn't support operator signatures yet.
#if 0
- value_t& I::operator ()(point_t&);
+ rvalue_t I::operator ()(point_t&) const;
#endif
bool I::has(const point_t&) const;
};
@@ -121,6 +106,16 @@
int I::nslis_get() const;
};
+ auto concept Mutable_Image<typename I> : Image<I>
+ {
+ typename lvalue_t;
+
+ // ConceptGCC doesn't support operator signatures yet.
+#if 0
+ lvalue_t I::operator ()(point_t&);
+#endif
+ };
+
} // End of namespace oln::concepts.
} // End of namespace oln.
@@ -182,9 +177,9 @@
struct Image : public stc::any<E>
{
typedef oln_type_of(E, point) point_t;
- typedef oln_type_of(E, value) value_t;
+ typedef oln_type_of(E, rvalue) rvalue_t;
- value_t& operator ()(point_t& p)
+ rvalue_t operator ()(point_t& p) const
{
return this->exact().impl_op_parens(p);
}
@@ -204,13 +199,6 @@
struct Image2d : public Image<E>
{
typedef oln_type_of(E, point) point_t;
- typedef oln_type_of(E, value) value_t;
-
- // FIXME: delete?
- value_t& operator ()(point_t& p)
- {
- return this->exact().impl_op_parens(p);
- }
int nrows_get() const
{
@@ -234,12 +222,6 @@
typedef oln_type_of(E, point) point_t;
typedef oln_type_of(E, value) value_t;
- // FIXME: delete?
- value_t& operator ()(point_t& p)
- {
- return this->exact().impl_op_parens(p);
- }
-
int nrows_get() const
{
return this->exact().impl_nrows_get();
@@ -273,6 +255,22 @@
}
};
+ // ------------- //
+ // Mutable_Image //
+ // ------------- //
+
+ template <typename E>
+ struct Mutable_image : public Image<E>
+ {
+ typedef oln_type_of(E, lvalue) lvalue_t;
+ typedef oln_type_of(E, point) point_t;
+
+ lvalue_t operator ()(point_t& p)
+ {
+ return this->exact().impl_op_parens(p);
+ }
+ };
+
} // End of namespace oln.
@@ -301,7 +299,7 @@
// Concept-based overloading for Image2d.
template <typename E>
- requires concepts::Point2d< oln_type_of(E, point) >
+ requires concepts::Point< oln_type_of(E, point) >
struct image_dimension_switch<E> : public oln::Image2d<E>
{
public:
@@ -315,7 +313,7 @@
// Concept-based overloading for Image3d.
template <typename E>
- requires concepts::Point3d< oln_type_of(E, point) >
+ requires concepts::Point< oln_type_of(E, point) >
struct image_dimension_switch<E> : public oln::Image3d<E>
{
public:
@@ -327,6 +325,26 @@
}
};
+ // ----------------- //
+ // Mutability Switch //
+ // ----------------- //
+
+ // Forward Declaration
+ template <typename E> struct image_mutability_switch;
+
+ template <typename E>
+ requires concepts::Mutable_Image<E>
+ struct image_mutability_switch : public oln::Mutable_Image<E>
+ {
+ public:
+ image_dimension_switch()
+ {
+ std::cout << "image_mutability_switch<E> "
+ << "requires oln::concepts::Mutable_Image<E>"
+ << std::endl;
+ }
+ };
+
// ------------ //
// Image base. //
@@ -388,21 +406,6 @@
coord_type sli;
};
- // Explicitly map point2d and point3d to their concepts.
- namespace concepts
- {
- concept_map Point2d<oln::point2d>
- {
- typedef oln::point2d::coord_type coord_type;
- };
-
- concept_map Point3d<oln::point3d>
- {
- typedef oln::point2d::coord_type coord_type;
- };
-
- } // End of namespace oln::concepts
-
// ------------- //
// Iterator 2d. //
@@ -488,6 +491,8 @@
typedef point2d point_type;
typedef iterator2d iter_type;
typedef T value_type;
+ typedef T rvalue_type;
+ typedef T& lvalue_type;
};
template <typename T>
@@ -497,16 +502,23 @@
typedef oln_type_of(self_t, point) point_t;
typedef oln_type_of(self_t, iter) iter_t;
typedef oln_type_of(self_t, value) value_t;
+ typedef oln_type_of(self_t, rvalue) rvalue_t;
+ typedef oln_type_of(self_t, lvalue) lvalue_t;
image2d(int nrows, int ncols) :
data (0),
nrows (nrows),
ncols (ncols)
{
- data = new std::vector<value_t>;
+ data = new value_t[nrows * ncols];
}
- value_t& impl_op_parens(const point_t& p)
+ rvalue_t impl_op_parens(const point_t& p) const
+ {
+ return this->data[p.row * nrows + p.col];
+ }
+
+ lvalue_t impl_op_parens(const point_t& p)
{
return this->data[p.row * nrows + p.col];
}
@@ -528,7 +540,7 @@
}
protected:
- std::vector<value_t>* data;
+ value_t* data;
int nrows;
int ncols;
};
@@ -546,6 +558,174 @@
};
+ // ------------- //
+ // Iterator 3d. //
+ // ------------- //
+
+ // Forward declarations.
+ struct iterator3d;
+ template <typename T> struct image3d;
+
+ template<>
+ struct set_super_type<iterator3d>
+ {
+ typedef mlc::none ret;
+ };
+
+ template <>
+ struct vtypes<iterator3d>
+ {
+ typedef point3d point_type;
+ };
+
+ struct iterator3d : public Iterator<iterator3d>
+ {
+ typedef oln_type_of_(iterator2d, point) point_t;
+
+ template <typename T>
+ iterator3d(image3d<T>& ima) :
+ nrows (ima.nrows_get()),
+ ncols (ima.ncols_get()).
+ nslis (ima.nslis_get())
+ {
+ }
+
+ void impl_start()
+ {
+ p.row = 0;
+ p.col = 0;
+ p.sli = 0;
+ }
+
+ void impl_next()
+ {
+ p.sli = p.sli + 1;
+
+ if (p.sli == nslis)
+ {
+ p.sli = 0;
+ p.col = p.col + 1;
+ }
+
+ if (p.col == ncols)
+ {
+ p.col = 0;
+ p.row = p.row + 1;
+ }
+ }
+
+ bool impl_is_valid() const
+ {
+ return p.row < nrows;
+ }
+
+ point_t& impl_op_point_type()
+ {
+ return p;
+ }
+
+ protected:
+ int nrows;
+ int ncols;
+ int nslis;
+ point_t p;
+ };
+
+
+ // ---------- //
+ // Image 3d. //
+ // ---------- //
+
+ // Forward declaration.
+ template <typename T> struct image3d;
+
+ template<typename T>
+ struct set_super_type< image3d<T> >
+ {
+ typedef image_base< image3d<T> > ret;
+ };
+
+ template <typename T>
+ struct vtypes< image3d<T> >
+ {
+ typedef point3d point_type;
+ typedef iterator3d iter_type;
+ typedef T value_type;
+ typedef T rvalue_type;
+ typedef T& lvalue_type;
+ };
+
+ template <typename T>
+ struct image3d : public image_base< image3d<T> >
+ {
+ typedef image2d<T> self_t;
+ typedef oln_type_of(self_t, point) point_t;
+ typedef oln_type_of(self_t, iter) iter_t;
+ typedef oln_type_of(self_t, value) value_t;
+ typedef oln_type_of(self_t, rvalue) rvalue_t;
+ typedef oln_type_of(self_t, lvalue) lvalue_t;
+
+ image3d(int nrows, int ncols, int nslis) :
+ data (0),
+ nrows (nrows),
+ ncols (ncols),
+ nslis (nslis)
+ {
+ data = new value_t[nrows * ncols * nslis];
+ }
+
+ rvalue_t impl_op_parens(const point_t& p) const
+ {
+ return this->data[p.row * ncols * nslis + p.col * nslis + p.sli];
+ }
+
+ lvalue_t impl_op_parens(const point_t& p)
+ {
+ return this->data[p.row * ncols * nslis + p.col * nslis + p.sli];
+ }
+
+ int impl_nrows_get() const
+ {
+ return nrows;
+ }
+
+ int impl_ncols_get() const
+ {
+ return ncols;
+ }
+
+ int impl_nslis_get() const
+ {
+ return nslis;
+ }
+
+ bool impl_has(point_t& p) const
+ {
+ assert(!!data);
+ return p.row >= 0 && p.row < nrows && p.col >= 0 && p.col < ncols
+ && p.sli >= 0 && p.sli < nslis;
+ }
+
+ protected:
+ value_t* data;
+ int nrows;
+ int ncols;
+ int nslis;
+ };
+
+
+ // ----------------- //
+ // Neighborhood 3d. //
+ // ----------------- //
+
+ struct niter3d {};
+
+ struct neighborhood3d
+ {
+ typedef niter3d niter_type;
+ };
+
+
// --------------- //
// Image morpher. //
// --------------- //
1
0
19 Mar '07
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Clean-up morpho, accumulators, and vtypes in base classes.
* oln/morpho/erosion.hh: Rename as...
* oln/morpho/elementary_erosion.hh: ...this.
(erosion): Rename as...
(elementary_erosion): ...this and update.
* oln/core/concept/function.hh (Accumulator): Move to...
* oln/core/concept/accumulator.hh: ...this new file.
* oln/accumulator/: New.
* oln/function/min.hh: Rename as...
* oln/accumulator/min.hh: ...this.
Split decls and defs.
* oln/core/internal/dpoint_nd.hh: Remove; obsolete.
* oln/level/apply.hh (apply_local): Uncomment and move to...
* oln/level/apply_local.hh: ...this new file.
* oln/level/apply.hh (apply_inplace): Uncomment and move to...
* oln/level/apply_inplace.hh: ...this new file.
* oln/level/local.hh: Fix sigs.
* oln/core/init.hh (init): Strengthen sigs with Any.
* oln/core/equipment.hh (argument, oln_argument): New.
(oln_dim, oln_dpoint, oln_grid): New.
(include): Reject init.hh to end of file.
* oln/core/gen/fun.hh (fun_v2v_, functorize_v2v): New.
* oln/core/internal/point_base.hh,
* oln/core/internal/dpoint_base.hh,
* oln/core/internal/point_set_base.hh,
* oln/core/internal/window_base.hh,
* oln/core/internal/neighborhood_base.hh,
* oln/core/internal/image_base.hh: Simplify type deductions.
accumulator/min.hh | 58 ++++++++++---
core/concept/accumulator.hh | 60 +++++++++++++
core/concept/function.hh | 12 --
core/equipment.hh | 18 +++-
core/gen/fun.hh | 51 +++++++++++
core/init.hh | 26 ++---
core/internal/dpoint_base.hh | 2
core/internal/image_base.hh | 9 --
core/internal/neighborhood_base.hh | 2
core/internal/point_base.hh | 2
core/internal/point_set_base.hh | 5 -
core/internal/window_base.hh | 2
level/apply.hh | 143 ++++----------------------------
level/apply_inplace.hh | 162 +++++--------------------------------
level/apply_local.hh | 153 ++++------------------------------
level/local.hh | 38 +++-----
morpho/elementary_erosion.hh | 42 +++++----
17 files changed, 300 insertions(+), 485 deletions(-)
Index: oln/accumulator/min.hh
--- oln/accumulator/min.hh (revision 0)
+++ oln/accumulator/min.hh (working copy)
@@ -25,43 +25,73 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef _FUNCTION_MIN_HH
-# define _FUNCTION_MIN_HH
+#ifndef OLN_ACCUMULATOR_MIN_HH
+# define OLN_ACCUMULATOR_MIN_HH
-#include <oln/core/concept/functions.hh>
+# include <oln/core/concept/accumulator.hh>
#include <oln/core/internal/max_value.hh>
namespace oln
{
- namespace function
+ namespace accumulator
{
template <typename T>
- struct min_ : public oln::Accumulator< min_<T> >
+ struct min_ : public Accumulator< min_<T> >
{
typedef T argument;
typedef T result;
- min_() { this->init(); }
+ min_();
- void init() const { val_ = oln_max(T); }
- result value() const { return val_; }
+ void init() const;
+ result value() const;
template <typename U>
- void operator()(U i) const
- {
- if (i < val_)
- val_ = static_cast<T>(i);
- }
+ void operator()(U i) const;
private:
mutable T val_;
};
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename T>
+ min_<T>::min_()
+ {
+ this->init();
+ }
+
+ template <typename T>
+ void
+ min_<T>::init() const
+ {
+ this->val_ = oln_max(T);
+ }
+
+ template <typename T>
+ typename min_<T>::result
+ min_<T>::value() const
+ {
+ return this->val_;
}
+ template <typename T>
+ template <typename U>
+ void
+ min_<T>::operator()(U i) const
+ {
+ if (i < this->val_)
+ this->val_ = static_cast<T>(i);
}
-#endif // ! OLN_FUNCTION_MIN_HH
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::accumulator
+
+} // end of namespace oln
+
+#endif // ! OLN_ACCUMULATOR_MIN_HH
Index: oln/morpho/elementary_erosion.hh
--- oln/morpho/elementary_erosion.hh (revision 886)
+++ oln/morpho/elementary_erosion.hh (working copy)
@@ -1,5 +1,4 @@
-// Copyright (C) 2007 EPITA Research and
-// Development Laboratory
+// 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
@@ -26,11 +25,12 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_MORPHO_EROSION_HH
-# define OLN_MORPHO_EROSION_HH
+#ifndef OLN_MORPHO_ELEMENTARY_EROSION_HH
+# define OLN_MORPHO_ELEMENTARY_EROSION_HH
+
+#include <oln/level/apply_local.hh>
+#include <oln/accumulator/min.hh>
-#include <oln/level/local.hh>
-#include <oln/function/min.hh>
namespace oln
{
@@ -38,8 +38,12 @@
namespace morpho
{
+ // Fwd decl.
+
template <typename I>
- I erosion(const Image_with_Nbh<I>& input);
+ oln_plain(I)
+ elementary_erosion(const Image_with_Nbh<I>& input);
+
# ifndef OLN_INCLUDE_ONLY
@@ -49,24 +53,30 @@
/// Generic version
template <typename I>
- I erosion(const Image_with_Nbh<I>& input)
+ oln_plain(I)
+ elementary_erosion_(const Image_with_Nbh<I>& input)
{
- function::min_<oln_value(I)> min;
- return ::oln::level::apply_local(min, input);
- }
+ accumulator::min_<oln_value(I)> min;
+ return level::apply_local(min, input);
}
+ } // end of namespace oln::morpho::impl
+
+
// Facade.
template <typename I>
- I erosion(const Image_with_Nbh<I>& input)
+ oln_plain(I)
+ elementary_erosion(const Image_with_Nbh<I>& input)
{
- return impl::erosion(exact(input));
+ return impl::elementary_erosion_(exact(input));
}
#endif // ! OLN_INCLUDE_ONLY
- } // end of namespace
-}
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
-#endif // ! OLN_MORPHO_EROSION_HH
+#endif // ! OLN_MORPHO_ELEMENTARY_EROSION_HH
Index: oln/level/apply.hh
--- oln/level/apply.hh (revision 887)
+++ oln/level/apply.hh (working copy)
@@ -30,9 +30,9 @@
# define OLN_LEVEL_APPLY_HH
# include <oln/core/concept/image.hh>
-# include <oln/core/concept/iterator.hh>
+# include <oln/core/gen/fun.hh>
# include <oln/core/internal/f_ch_value.hh>
-# include <oln/level/local.hh>
+
namespace oln
{
@@ -40,24 +40,15 @@
namespace level
{
- /// Fwd decl.
- template <typename R, typename A, typename I>
- oln_plain_value(I, R)
- apply(R (*fun)(A), const Image<I>& input);
-
-
-// /// Fwd decl.
-// template <typename I, typename F>
-// oln_plain_value(I, typename F::result_value)
-// apply(const abstract::image<I>& input, const abstract::fun_v2v<F>& fun);
+ /// Fwd decls.
-// /// Fwd decl.
-// template <typename I, typename V>
-// void apply_inplace(abstract::mutable_image<I>& input, V (*fun)(const oln_value(I)&));
+ template <typename F, typename I>
+ oln_plain_value(I, typename F::result)
+ apply(const Function_v2v<F>& f, const Image<I>& input);
-// /// Fwd decl.
-// template <typename I, typename F>
-// void apply_inplace(abstract::mutable_image<I>& input, const abstract::fun_v2v<F>& fun);
+ template <typename R, typename A, typename I>
+ oln_plain_value(I, R)
+ apply(R (*f)(A), const Image<I>& input);
# ifndef OLN_INCLUDE_ONLY
@@ -65,138 +56,42 @@
namespace impl
{
- /// apply
+ // Generic version.
template <typename F, typename I>
oln_plain_value(I, typename F::result)
- apply( F& f, const Image<I>& input)
+ apply_(const F& f, const Image<I>& input)
{
- typedef typename F::result result;
typedef typename F::argument argument;
-
- oln_ch_value(I, result) output(input.points());
- oln_piter(I) p(input.points());
- for_all(p)
- output(p) = f( static_cast< argument >(input(p)) );
- return output;
- }
-
-
- /// apply_local
-
- template <typename F, typename I>
- I apply_local(const Accumulator<F>& f,
- const Image_with_Nbh<I>& input)
- {
typedef typename F::result result;
- typedef typename F::argument argument;
- typename I::delegatee out(input.points());
- I output(out, input.nbhood());
- // I output(exact(input).image(), input.nbhood());
- // FIXME: init(output, with, input);
+ oln_plain_value(I, result) output;
+ init(output, with, input);
oln_piter(I) p(input.points());
for_all(p)
- output(p) = level::local(f, input, p);
+ output(p) = f(input(p));
return output;
}
-
-// /// Generic version.
-// template <typename I, typename F>
-// oln_plain_value(I, typename F::result_value)
-// apply(const abstract::image<I>& input, const abstract::fun_v2v<F>& fun)
-// {
-// oln_plain_value(I, typename F::result_value) output(input.topo());
-// oln_piter(I) p(input.topo());
-// for_all(p)
-// output(p) = fun.exact()(input(p));
-// return output;
-// }
-
-
-// /// Generic version.
-// template <typename I, typename V>
-// void
-// apply_inplace(abstract::mutable_image<I>& input, V (*fun)(const oln_value(I)&))
-// {
-// oln_piter(I) p(input.topo());
-// for_all(p)
-// input(p) = fun(input(p));
-// }
-
-// /// Generic version.
-// template <typename I, typename F>
-// void
-// apply_inplace(abstract::mutable_image<I>& input, const abstract::fun_v2v<F>& fun)
-// {
-// oln_piter(I) p(input.topo());
-// for_all(p)
-// input(p) = fun.exact()(input(p));
-// }
-
} // end of namespace oln::level::impl
- /// Facades.
- //----------------------------
-
- /// Apply.
- template <typename R, typename A, typename I>
- oln_plain_value(I, R)
- apply(R (*fun)(A), const Image<I>& input)
- {
- return impl::apply(fun, exact(input));
- }
+ /// Facades.
template <typename F, typename I>
oln_plain_value(I, typename F::result)
- apply(F& f, const Image<I>& input)
+ apply(const Function_v2v<F>& f, const Image<I>& input)
{
- return impl::apply(f, exact(input));
+ return impl::apply_(exact(f), exact(input));
}
- /// Apply local
-
template <typename R, typename A, typename I>
oln_plain_value(I, R)
- apply_local(R (*fun)(A), const Image<I>& input)
- {
- return impl::apply_local(fun, exact(input));
- }
-
- template <typename F, typename I>
- oln_plain_value(I, typename F::result)
- apply_local(const Accumulator<F>& fun,
- const Image_with_Nbh<I>& input)
+ apply(R (*f)(A), const Image<I>& input)
{
- return impl::apply_local(fun, input);
+ return impl::apply_(functorize_v2v(f), exact(input));
}
-// /// Facade.
-// template <typename I, typename F>
-// oln_plain_value(I, typename F::result_value)
-// apply(const abstract::image<I>& input, const abstract::fun_v2v<F>& fun)
-// {
-// return impl::apply(input, fun);
-// }
-
-
-// /// Facade.
-// template <typename I, typename V>
-// void
-// apply_inplace(abstract::mutable_image<I>& input, V (*fun)(const oln_value(I)&))
-// {
-// return impl::apply_inplace(input, fun);
-// }
-
-// /// Facade.
-// template <typename I, typename F>
-// void
-// apply_inplace(abstract::mutable_image<I>& input, const abstract::fun_v2v<F>& fun)
-// {
-// return impl::apply_inplace(input, fun);
-// }
# endif
Index: oln/level/local.hh
--- oln/level/local.hh (revision 887)
+++ oln/level/local.hh (working copy)
@@ -29,11 +29,9 @@
# define OLN_LEVEL_LOCAL_HH
#include <oln/core/concept/image.hh>
-#include <oln/core/concept/point.hh>
-#include <oln/core/concept/functions.hh>
#include <oln/core/concept/window.hh>
-#include <oln/core/concept/iterator.hh> // bizarre
-#include <oln/core/equipment.hh>
+# include <oln/core/concept/accumulator.hh>
+
namespace oln
{
@@ -42,7 +40,7 @@
{
template <typename A, typename I>
- int //typename A::result
+ typename A::result
local(const Accumulator<A>& f,
const Image_with_Nbh<I>& input,
const oln_point(I)& p);
@@ -54,37 +52,32 @@
const oln_point(I)& p,
const Window<W>& win);
+
# ifndef OLN_INCLUDE_ONLY
namespace impl
{
- /// Local Apply on neighborhood (nbh included in image).
+ // Generic version with neighborhood.
template <typename A, typename I>
- int//typename A::result
+ typename A::result
local_(const A& f,
const Image_with_Nbh<I>& input,
const oln_point(I)& p)
{
f.init();
- oln_niter(I) n(p, input.points());
+ oln_niter(I) n(p, input.nbhood()); // FIXME: 2nd arg should be 'input'!
for_all(n)
f(input(n));
return f.value();
}
- /// Local Apply on neighborhood (nhb given as argument).
-
- // ...FIXME
+ // FIXME: Generic version with nbh given as argument?
- /// Local Apply on window (window included in image).
-
- // ...FIXME
-
- /// Local Apply on window (window is given).
+ // Generic version with window.
template <typename F, typename I, typename W>
typename F::result
@@ -97,16 +90,16 @@
oln_qiter(W) q(p, win);
for_all(q)
f(input(q));
-
return f.value();
}
- }
+ } // end of namespace oln::level::impl
+
- /// Facades.
+ // Facades.
template <typename A, typename I>
- int//typename A::result
+ typename A::result
local(const Accumulator<A>& f,
const Image_with_Nbh<I>& input,
const oln_point(I)& p)
@@ -126,7 +119,8 @@
#endif // ! OLN_INCLUDE_ONLY
- }
-}
+ } // end of namespace oln::level
+
+} // end of namespace oln
#endif // ! OLN_LEVEL_LOCAL_HH
Index: oln/level/apply_local.hh
--- oln/level/apply_local.hh (revision 886)
+++ oln/level/apply_local.hh (working copy)
@@ -1,5 +1,4 @@
-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 EPITA
-// Research and Development Laboratory
+// 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
@@ -26,14 +25,15 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_LEVEL_APPLY_HH
-# define OLN_LEVEL_APPLY_HH
+#ifndef OLN_LEVEL_APPLY_LOCAL_HH
+# define OLN_LEVEL_APPLY_LOCAL_HH
# include <oln/core/concept/image.hh>
-# include <oln/core/concept/iterator.hh>
+# include <oln/core/concept/accumulator.hh>
# include <oln/core/internal/f_ch_value.hh>
# include <oln/level/local.hh>
+
namespace oln
{
@@ -41,23 +41,11 @@
{
/// Fwd decl.
- template <typename R, typename A, typename I>
- oln_plain_value(I, R)
- apply(R (*fun)(A), const Image<I>& input);
-
-
-// /// Fwd decl.
-// template <typename I, typename F>
-// oln_plain_value(I, typename F::result_value)
-// apply(const abstract::image<I>& input, const abstract::fun_v2v<F>& fun);
-
-// /// Fwd decl.
-// template <typename I, typename V>
-// void apply_inplace(abstract::mutable_image<I>& input, V (*fun)(const oln_value(I)&));
-
-// /// Fwd decl.
-// template <typename I, typename F>
-// void apply_inplace(abstract::mutable_image<I>& input, const abstract::fun_v2v<F>& fun);
+
+ template <typename F, typename I>
+ oln_plain_value(I, typename F::result)
+ apply_local(const Accumulator<F>& f,
+ const Image_with_Nbh<I>& input);
# ifndef OLN_INCLUDE_ONLY
@@ -65,139 +53,34 @@
namespace impl
{
- /// apply
+ // Generic version.
template <typename F, typename I>
oln_plain_value(I, typename F::result)
- apply( F& f, const Image<I>& input)
- {
- typedef typename F::result result;
- typedef typename F::argument argument;
-
- oln_ch_value(I, result) output(input.points());
- oln_piter(I) p(input.points());
- for_all(p)
- output(p) = f( static_cast< argument >(input(p)) );
- return output;
- }
-
-
- /// apply_local
-
- template <typename F, typename I>
- I apply_local(const Accumulator<F>& f,
+ apply_local_(const Accumulator<F>& f,
const Image_with_Nbh<I>& input)
{
- typedef typename F::result result;
- typedef typename F::argument argument;
-
- typename I::delegatee out(input.points());
- I output(out, input.nbhood());
- // I output(exact(input).image(), input.nbhood());
- // FIXME: init(output, with, input);
+ oln_plain_value(I, typename F::result) output;
+ init(output, with, input);
oln_piter(I) p(input.points());
for_all(p)
output(p) = level::local(f, input, p);
return output;
}
-
-// /// Generic version.
-// template <typename I, typename F>
-// oln_plain_value(I, typename F::result_value)
-// apply(const abstract::image<I>& input, const abstract::fun_v2v<F>& fun)
-// {
-// oln_plain_value(I, typename F::result_value) output(input.topo());
-// oln_piter(I) p(input.topo());
-// for_all(p)
-// output(p) = fun.exact()(input(p));
-// return output;
-// }
-
-
-// /// Generic version.
-// template <typename I, typename V>
-// void
-// apply_inplace(abstract::mutable_image<I>& input, V (*fun)(const oln_value(I)&))
-// {
-// oln_piter(I) p(input.topo());
-// for_all(p)
-// input(p) = fun(input(p));
-// }
-
-// /// Generic version.
-// template <typename I, typename F>
-// void
-// apply_inplace(abstract::mutable_image<I>& input, const abstract::fun_v2v<F>& fun)
-// {
-// oln_piter(I) p(input.topo());
-// for_all(p)
-// input(p) = fun.exact()(input(p));
-// }
-
} // end of namespace oln::level::impl
- /// Facades.
- //----------------------------
- /// Apply.
-
- template <typename R, typename A, typename I>
- oln_plain_value(I, R)
- apply(R (*fun)(A), const Image<I>& input)
- {
- return impl::apply(fun, exact(input));
- }
+ // Facade.
template <typename F, typename I>
oln_plain_value(I, typename F::result)
- apply(F& f, const Image<I>& input)
- {
- return impl::apply(f, exact(input));
- }
-
- /// Apply local
-
- template <typename R, typename A, typename I>
- oln_plain_value(I, R)
- apply_local(R (*fun)(A), const Image<I>& input)
- {
- return impl::apply_local(fun, exact(input));
- }
-
- template <typename F, typename I>
- oln_plain_value(I, typename F::result)
- apply_local(const Accumulator<F>& fun,
+ apply_local(const Accumulator<F>& f,
const Image_with_Nbh<I>& input)
{
- return impl::apply_local(fun, input);
+ return impl::apply_local_(exact(f), exact(input));
}
-// /// Facade.
-// template <typename I, typename F>
-// oln_plain_value(I, typename F::result_value)
-// apply(const abstract::image<I>& input, const abstract::fun_v2v<F>& fun)
-// {
-// return impl::apply(input, fun);
-// }
-
-
-// /// Facade.
-// template <typename I, typename V>
-// void
-// apply_inplace(abstract::mutable_image<I>& input, V (*fun)(const oln_value(I)&))
-// {
-// return impl::apply_inplace(input, fun);
-// }
-
-// /// Facade.
-// template <typename I, typename F>
-// void
-// apply_inplace(abstract::mutable_image<I>& input, const abstract::fun_v2v<F>& fun)
-// {
-// return impl::apply_inplace(input, fun);
-// }
-
# endif
} // end of namespace oln::level
@@ -205,4 +88,4 @@
} // end of namespace oln
-#endif // ! OLN_LEVEL_APPLY_HH
+#endif // ! OLN_LEVEL_APPLY_LOCAL_HH
Index: oln/level/apply_inplace.hh
--- oln/level/apply_inplace.hh (revision 886)
+++ oln/level/apply_inplace.hh (working copy)
@@ -1,5 +1,4 @@
-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 EPITA
-// Research and Development Laboratory
+// 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
@@ -26,13 +25,12 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_LEVEL_APPLY_HH
-# define OLN_LEVEL_APPLY_HH
+#ifndef OLN_LEVEL_APPLY_INPLACE_HH
+# define OLN_LEVEL_APPLY_INPLACE_HH
# include <oln/core/concept/image.hh>
-# include <oln/core/concept/iterator.hh>
-# include <oln/core/internal/f_ch_value.hh>
-# include <oln/level/local.hh>
+# include <oln/core/gen/fun.hh>
+
namespace oln
{
@@ -40,24 +38,15 @@
namespace level
{
- /// Fwd decl.
- template <typename R, typename A, typename I>
- oln_plain_value(I, R)
- apply(R (*fun)(A), const Image<I>& input);
+ /// Fwd decls.
+ template <typename F, typename I>
+ void
+ apply_inplace(const Function_v2v<F>& f, Mutable_Image<I>& input)
-// /// Fwd decl.
-// template <typename I, typename F>
-// oln_plain_value(I, typename F::result_value)
-// apply(const abstract::image<I>& input, const abstract::fun_v2v<F>& fun);
-
-// /// Fwd decl.
-// template <typename I, typename V>
-// void apply_inplace(abstract::mutable_image<I>& input, V (*fun)(const oln_value(I)&));
-
-// /// Fwd decl.
-// template <typename I, typename F>
-// void apply_inplace(abstract::mutable_image<I>& input, const abstract::fun_v2v<F>& fun);
+ template <typename R, typename A, typename I>
+ void
+ apply_inplace(R (*f)(A), Mutable_Image<I>& input);
# ifndef OLN_INCLUDE_ONLY
@@ -65,139 +54,38 @@
namespace impl
{
- /// apply
-
- template <typename F, typename I>
- oln_plain_value(I, typename F::result)
- apply( F& f, const Image<I>& input)
- {
- typedef typename F::result result;
- typedef typename F::argument argument;
-
- oln_ch_value(I, result) output(input.points());
- oln_piter(I) p(input.points());
- for_all(p)
- output(p) = f( static_cast< argument >(input(p)) );
- return output;
- }
-
-
- /// apply_local
+ // Generic version.
template <typename F, typename I>
- I apply_local(const Accumulator<F>& f,
- const Image_with_Nbh<I>& input)
+ void
+ apply_inplace_(const F& f, Mutable_Image<I>& input)
{
- typedef typename F::result result;
- typedef typename F::argument argument;
-
- typename I::delegatee out(input.points());
- I output(out, input.nbhood());
- // I output(exact(input).image(), input.nbhood());
- // FIXME: init(output, with, input);
oln_piter(I) p(input.points());
for_all(p)
- output(p) = level::local(f, input, p);
- return output;
+ input(p) = f(input(p));
+ // FIXME: input(p) = static_cast<oln_value(I)>( f_( static_cast<oln_argument(F)>(input(p)) ) );
}
-// /// Generic version.
-// template <typename I, typename F>
-// oln_plain_value(I, typename F::result_value)
-// apply(const abstract::image<I>& input, const abstract::fun_v2v<F>& fun)
-// {
-// oln_plain_value(I, typename F::result_value) output(input.topo());
-// oln_piter(I) p(input.topo());
-// for_all(p)
-// output(p) = fun.exact()(input(p));
-// return output;
-// }
-
-
-// /// Generic version.
-// template <typename I, typename V>
-// void
-// apply_inplace(abstract::mutable_image<I>& input, V (*fun)(const oln_value(I)&))
-// {
-// oln_piter(I) p(input.topo());
-// for_all(p)
-// input(p) = fun(input(p));
-// }
-
-// /// Generic version.
-// template <typename I, typename F>
-// void
-// apply_inplace(abstract::mutable_image<I>& input, const abstract::fun_v2v<F>& fun)
-// {
-// oln_piter(I) p(input.topo());
-// for_all(p)
-// input(p) = fun.exact()(input(p));
-// }
-
} // end of namespace oln::level::impl
- /// Facades.
- //----------------------------
-
- /// Apply.
- template <typename R, typename A, typename I>
- oln_plain_value(I, R)
- apply(R (*fun)(A), const Image<I>& input)
- {
- return impl::apply(fun, exact(input));
- }
+ /// Facades.
template <typename F, typename I>
- oln_plain_value(I, typename F::result)
- apply(F& f, const Image<I>& input)
+ void
+ apply_inplace(const Function_v2v<F>& f, Mutable_Image<I>& input)
{
- return impl::apply(f, exact(input));
+ impl::apply_inplace_(exact(f), exact(input));
}
- /// Apply local
-
template <typename R, typename A, typename I>
- oln_plain_value(I, R)
- apply_local(R (*fun)(A), const Image<I>& input)
- {
- return impl::apply_local(fun, exact(input));
- }
-
- template <typename F, typename I>
- oln_plain_value(I, typename F::result)
- apply_local(const Accumulator<F>& fun,
- const Image_with_Nbh<I>& input)
+ void
+ apply_inplace(R (*f)(A), Mutable_Image<I>& input)
{
- return impl::apply_local(fun, input);
+ impl::apply_inplace_(functorize_v2v(fun), exact(input));
}
-// /// Facade.
-// template <typename I, typename F>
-// oln_plain_value(I, typename F::result_value)
-// apply(const abstract::image<I>& input, const abstract::fun_v2v<F>& fun)
-// {
-// return impl::apply(input, fun);
-// }
-
-
-// /// Facade.
-// template <typename I, typename V>
-// void
-// apply_inplace(abstract::mutable_image<I>& input, V (*fun)(const oln_value(I)&))
-// {
-// return impl::apply_inplace(input, fun);
-// }
-
-// /// Facade.
-// template <typename I, typename F>
-// void
-// apply_inplace(abstract::mutable_image<I>& input, const abstract::fun_v2v<F>& fun)
-// {
-// return impl::apply_inplace(input, fun);
-// }
-
# endif
} // end of namespace oln::level
@@ -205,4 +93,4 @@
} // end of namespace oln
-#endif // ! OLN_LEVEL_APPLY_HH
+#endif // ! OLN_LEVEL_APPLY_INPLACE_HH
Index: oln/core/concept/function.hh
--- oln/core/concept/function.hh (revision 887)
+++ oln/core/concept/function.hh (working copy)
@@ -90,16 +90,6 @@
};
- // Values -> Value.
-
- template <typename Exact>
- struct Accumulator : public Function<Exact>
- {
- protected:
- Accumulator();
- };
-
-
/*
// Value1 -> Value2 *and* Value2 -> Value1.
@@ -187,7 +177,7 @@
{
}
-# endif // OLN_INCLUDE_ONLY
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/concept/accumulator.hh
--- oln/core/concept/accumulator.hh (revision 0)
+++ oln/core/concept/accumulator.hh (revision 0)
@@ -0,0 +1,60 @@
+// 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 OLN_CORE_CONCEPT_ACCUMULATOR_HH
+# define OLN_CORE_CONCEPT_ACCUMULATOR_HH
+
+# include <oln/core/concept/function.hh>
+
+
+namespace oln
+{
+
+ // Values -> Value.
+
+ template <typename Exact>
+ struct Accumulator : public Function<Exact>
+ {
+ protected:
+ Accumulator();
+ };
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename Exact>
+ Accumulator<Exact>::Accumulator()
+ {
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_CONCEPT_ACCUMULATOR_HH
Index: oln/core/init.hh
--- oln/core/init.hh (revision 887)
+++ oln/core/init.hh (working copy)
@@ -84,19 +84,19 @@
// Regular version.
template <typename Target, typename Data>
- bool init(Target& target, with_t, const Data& data);
+ bool init(Any<Target>& target, with_t, const Any<Data>& data);
// Assignment.
template <typename T>
- bool init(T& target, with_t, const T& data);
+ bool init(Any<T>& target, with_t, const Any<T>& data);
- // Unconst data version.
+ // Unconst->const data version.
template <typename Target, typename Data>
- bool init(Target& target, with_t, Data& data);
+ bool init(Any<Target>& target, with_t, Any<Data>& data);
// Guard: we cannot have "const Target".
template <typename Target, typename Data>
- bool init(const Target& target, with_t, const Data& data);
+ bool init(const Any<Target>& target, with_t, const Any<Data>& data);
@@ -145,24 +145,24 @@
// Regular version.
template <typename Target, typename Data>
- bool init(Target& target, with_t, const Data& data)
+ bool init(Any<Target>& target, with_t, const Any<Data>& data)
{
- return init_(&target, data);
+ return init_(exact(&target), exact(data));
}
// Assignment.
template <typename T>
- bool init(T& target, with_t, const T& data)
+ bool init(Any<T>& target, with_t, const Any<T>& data)
{
- target = data;
+ exact(target) = exact(data);
return true;
}
- // Unconst data version.
+ // Unconst->const data version.
template <typename Target, typename Data>
- bool init(Target& target, with_t, Data& data)
+ bool init(Any<Target>& target, with_t, Any<Data>& data)
{
- return init_(&target, const_cast<const Data&>(data));
+ return init(target, const_cast<const Data&>(data));
}
@@ -174,7 +174,7 @@
// Guard: we cannot have "const Target".
template <typename Target, typename Data>
- bool init(const Target&, with_t, const Data&)
+ bool init(const Any<Target>&, with_t, const Any<Data>&)
{
mlc::abort_< Target, ERROR::initialization_of_temporary_or_const_object_<Target> >::check();
return false;
Index: oln/core/equipment.hh
--- oln/core/equipment.hh (revision 887)
+++ oln/core/equipment.hh (working copy)
@@ -34,7 +34,6 @@
# else
# include <stc/scoop-alt.hh>
# endif
-# include <oln/core/init.hh>
# define oln_typename_shortcut__(Type, Alias) typename Type::Alias
@@ -52,6 +51,9 @@
// a
stc_decl_associated_type( adapted );
+ stc_decl_associated_type( argument );
+
+# define oln_argument(T) oln_typename_shortcut__(T, argument)
// b
stc_decl_associated_type( bkd_niter );
@@ -74,6 +76,9 @@
stc_decl_associated_type( dim );
stc_decl_associated_type( dpoint );
+# define oln_dim(T) oln_typename_shortcut__(T, dim)
+# define oln_dpoint(T) oln_typename_shortcut__(T, dpoint)
+
// f
stc_decl_associated_type( fwd_niter );
stc_decl_associated_type( fwd_piter );
@@ -86,6 +91,8 @@
// g
stc_decl_associated_type( grid );
+# define oln_grid(T) oln_typename_shortcut__(T, grid)
+
// i
stc_decl_associated_type( index );
@@ -144,5 +151,14 @@
+/// \{
+/// FIXME: Bad!
+
+# include <oln/core/init.hh>
+
+/// \}
+
+
+
#endif // ! OLN_CORE_EQUIPMENT_HH
Index: oln/core/gen/fun.hh
--- oln/core/gen/fun.hh (revision 887)
+++ oln/core/gen/fun.hh (working copy)
@@ -82,6 +82,9 @@
+ // ----------------------------- fun_p2b_<F>
+
+
// Fwd decl.
template <typename F> struct fun_p2b_;
@@ -114,6 +117,54 @@
};
+
+
+ // ----------------------------- fun_v2v_<F>
+
+
+ // Fwd decl.
+ template <typename F> struct fun_v2v_;
+
+ // Category.
+ namespace internal
+ {
+ template <typename F>
+ struct set_category_of_< fun_v2v_<F> >
+ {
+ typedef stc::is< Function_v2v > ret;
+ };
+ }
+
+ // Class.
+ template <typename F>
+ struct fun_v2v_ : public Function_v2v< fun_v2v_<F> >
+ {
+ typedef oln_arg_of_(F) argument;
+ typedef oln_res_of_(F) result;
+
+ fun_v2v_(F f) : f_(f) {}
+
+ result operator()(argument arg) const
+ {
+ return this->f_(arg);
+ }
+
+ private:
+ F f_;
+ };
+
+
+ // functorize_v2v
+ template <typename R, typename A>
+ fun_v2v_<R (*)(A)>
+ functorize_v2v(R (*f)(A))
+ {
+ fun_v2v_<R (*)(A)> tmp(f);
+ return tmp;
+ }
+
+
+
} // end of namespace oln
Index: oln/core/internal/point_base.hh
--- oln/core/internal/point_base.hh (revision 887)
+++ oln/core/internal/point_base.hh (working copy)
@@ -57,7 +57,7 @@
typedef stc_deferred(grid) grid__;
// Final:
- typedef stc::final<typename grid__::dim> dim; // FIXME: Propagate this kind of changes.
+ typedef stc::final< oln_dim(grid__) > dim;
typedef stc::final< stc::is<Point> > category;
};
Index: oln/core/internal/dpoint_base.hh
--- oln/core/internal/dpoint_base.hh (revision 887)
+++ oln/core/internal/dpoint_base.hh (working copy)
@@ -54,7 +54,7 @@
typedef stc::abstract grid;
typedef stc_deferred(grid) grid__;
- typedef stc::final<stc_type(grid__, dim)> dim;
+ typedef stc::final< oln_dim(grid__) > dim;
typedef stc::abstract coord;
typedef stc::abstract point; // FIXME: Just like in point_base.hh
Index: oln/core/internal/point_set_base.hh
--- oln/core/internal/point_set_base.hh (revision 887)
+++ oln/core/internal/point_set_base.hh (working copy)
@@ -59,9 +59,8 @@
typedef stc_deferred(fwd_piter) fwd_piter__;
typedef stc::final< stc::is<Point_Set> > category;
-
typedef stc::final< box_<point__> > box;
- typedef stc::final<stc_type(point__, grid)> grid;
+ typedef stc::final< oln_grid(point__) > grid;
typedef stc::final<fwd_piter__> piter;
};
@@ -117,7 +116,7 @@
{
typedef oln_strip_(P) P_;
mlc::assert_< mlc_is_a(P_, Point) >::check(); // FIXME: Add err msg.
- mlc::assert_equal_< P_, typename S::point >::check();
+ mlc::assert_equal_< P_, oln_point(S) >::check();
op_<const S, such_as, const fun_p2b_<B (*)(P)> > tmp(exact(lhs), f);
return tmp;
}
Index: oln/core/internal/window_base.hh
--- oln/core/internal/window_base.hh (revision 887)
+++ oln/core/internal/window_base.hh (working copy)
@@ -58,7 +58,7 @@
typedef stc_deferred(point) point__;
typedef stc_deferred(fwd_qiter) fwd_qiter__;
- typedef stc::final< stc_type(point__, grid) > grid;
+ typedef stc::final< oln_grid(point__) > grid;
typedef stc::final< fwd_qiter__ > qiter;
};
Index: oln/core/internal/neighborhood_base.hh
--- oln/core/internal/neighborhood_base.hh (revision 887)
+++ oln/core/internal/neighborhood_base.hh (working copy)
@@ -55,7 +55,7 @@
typedef stc::abstract point;
typedef stc_deferred(point) point__;
- typedef stc::final< stc_type(point__, grid) > grid;
+ typedef stc::final< oln_grid(point__) > grid;
typedef stc::final< stc::is<Neighborhood> > category;
};
Index: oln/core/internal/image_base.hh
--- oln/core/internal/image_base.hh (revision 887)
+++ oln/core/internal/image_base.hh (working copy)
@@ -149,10 +149,10 @@
typedef stc::final< stc::is<Image> > category;
typedef stc::final< box_<point__> > box;
- typedef stc::final< stc_type(point__, grid) > grid;
- typedef stc::final< stc_type(point__, dpoint) > dpoint;
- typedef stc::final< typename pset__::fwd_piter > fwd_piter;
- typedef stc::final< typename pset__::bkd_piter > bkd_piter;
+ typedef stc::final< oln_grid(point__) > grid;
+ typedef stc::final< oln_dpoint(point__) > dpoint;
+ typedef stc::final< oln_fwd_piter(pset__) > fwd_piter;
+ typedef stc::final< oln_bkd_piter(pset__) > bkd_piter;
typedef fwd_piter piter;
};
@@ -432,7 +432,6 @@
// init
-
template <typename P, typename I>
bool init_(box_<P>* this_, const internal::image_base_<I>& data);
1
0
Index: ChangeLog
from Nicolas Ballas <ballas(a)lrde.epita.fr>
Clean code.
* oln/core/rle/rle_image.hh, oln/core/rle/rle_psite.hh,
* oln/core/rle/rle_pset.hh, oln/core/encode/sparse_encode.hh: .
* oln/core/encode/rle_encode.hh: clean code, add comments, change comments form...
encode/rle_encode.hh | 12 +++++----
encode/sparse_encode.hh | 15 ++++++-----
rle/rle_image.hh | 30 ++++++++++++-----------
rle/rle_pset.hh | 61 +++++++++++++++++++++++++-----------------------
rle/rle_psite.hh | 19 +++++++-------
5 files changed, 73 insertions(+), 64 deletions(-)
Index: oln/core/rle/rle_image.hh
--- oln/core/rle/rle_image.hh (revision 886)
+++ oln/core/rle/rle_image.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 EPITA
+// Copyright (C) 2007 EPITA
// Research and Development Laboratory
//
// This file is part of the Olena Library. This library is free
@@ -26,8 +26,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_CORE_RLE_RLE_IMAGE_HH_
-# define OLN_CORE_RLE_RLE_IMAGE_HH_
+#ifndef OLN_CORE_RLE_RLE_IMAGE_HH
+# define OLN_CORE_RLE_RLE_IMAGE_HH
# include <map>
# include <utility>
@@ -78,13 +78,6 @@
** \class rle_image
** \brief rle image (use a pair of point range and value as representation)
**
- ** method:
- ** pset impl_points() const : return image pset
- ** bool impl_has(const point& p) const : rle_image has p?
- ** bool impl_owns_(const psite& p) const : same has impl_has
- ** void insert(const point& p, unsigned len, value val) : insert a new range on the image
- ** rvalue impl_read(const psite& p) const : return value associated to psite (for reading)
- ** lvalue impl_read_write(const psite& p) : lvalue impl_read_write(const psite& p) (for writing)
*/
template < typename P, typename T>
class rle_image : public internal::primitive_image_< rle_image<P, T> >
@@ -103,11 +96,17 @@
rle_image();
+ /// pset impl_points() const : return image pset
pset impl_points() const;
+ /// bool impl_has(const point& p) const : rle_image has p?
bool impl_has(const point& p) const;
+ /// bool impl_owns_(const psite& p) const : same has impl_has
bool impl_owns_(const psite& p) const;
+ /// void insert(const point& p, unsigned len, value val) : insert a new range on the image
void insert(const point& p, unsigned len, value val);
+ /// rvalue impl_read(const psite& p) const : return value associated to psite (for reading)
rvalue impl_read(const psite& p) const;
+ /// lvalue impl_read_write(const psite& p) : lvalue impl_read_write(const psite& p) (for writing)
lvalue impl_read_write(const psite& p);
};
@@ -143,7 +142,8 @@
template <typename P, typename T>
void
- rle_image<P, T>::insert(const typename rle_image<P, T>::point& p, unsigned len, rle_image<P, T>::value val)
+ rle_image<P, T>::insert(const typename rle_image<P, T>::point& p,
+ unsigned len, rle_image<P, T>::value val)
{
this->data_->first.insert(p, len);
this->data_->second[p] = val;
@@ -156,7 +156,8 @@
typename std::map<point, value>::const_iterator irun;
irun = this->data_->second.find(ps.start_);
- assert(irun != this->data_->second.end() && ps.index_ < this->data_->first.range_len_(ps.start_));
+ assert(irun != this->data_->second.end() &&
+ ps.index_ < this->data_->first.range_len_(ps.start_));
return irun->second;
}
@@ -167,7 +168,8 @@
typename std::map<point, value>::iterator irun;
irun = this->data_->second.find(ps.start_);
- assert(irun != this->data_->second.end() && ps.index_ < this->data_->first.range_len_(ps.start_));
+ assert(irun != this->data_->second.end() &&
+ ps.index_ < this->data_->first.range_len_(ps.start_));
return irun->second;
}
@@ -175,4 +177,4 @@
} // end of namespace oln
-#endif /* !OLN_CORE_RLE_RLE_IMAGE_HH_ */
+#endif // !OLN_CORE_RLE_RLE_IMAGE_HH
Index: oln/core/rle/rle_psite.hh
--- oln/core/rle/rle_psite.hh (revision 886)
+++ oln/core/rle/rle_psite.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2006, 2007 EPITA Research and Development Laboratory
+// 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
@@ -25,8 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_CORE_RLE_RLE_PSITE_HH_
-# define OLN_CORE_RLE_RLE_PSITE_HH_
+#ifndef OLN_CORE_RLE_RLE_PSITE_HH
+# define OLN_CORE_RLE_RLE_PSITE_HH
# include <map>
@@ -44,9 +44,6 @@
** \brief psite for rle image
**
** Note: P must be a point type
- ** method:
- ** to_point: convert the psite to corresponding point
- ** operator P(): convert psite to the corresponding point
*/
template <typename P>
class rle_psite
@@ -54,11 +51,15 @@
public:
rle_psite();
+ // to_point: convert the psite to corresponding point
P to_point() const;
+ // operator P(): convert psite to the corresponding point
operator P () const;
- P start_; /*!< start of the range which contains the psite */
- unsigned index_; /*!< index of the point in the range */
+ /// start of the range which contains the psite
+ P start_;
+ /// index of the point in the range
+ unsigned index_;
};
# ifndef OLN_INCLUDE_ONLY
@@ -88,4 +89,4 @@
//end of class rle_psite
}
-#endif /* !OLN_CORE_RLE_RLE_PSITE_HH_ */
+#endif // !OLN_CORE_RLE_RLE_PSITE_HH
Index: oln/core/rle/rle_pset.hh
--- oln/core/rle/rle_pset.hh (revision 886)
+++ oln/core/rle/rle_pset.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2006, 2007 EPITA Research and Development Laboratory
+// 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
@@ -25,8 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_CORE_RLE_RLE_PSET_HH_
-# define OLN_CORE_RLE_RLE_PSET_HH_
+#ifndef OLN_CORE_RLE_RLE_PSET_HH
+# define OLN_CORE_RLE_RLE_PSET_HH
# include <set>
# include <utility>
@@ -71,13 +71,6 @@
** \brief pset correspoding to the rle_image class
**
** Note: P must be a point type
- ** method:
- ** unsigned impl_npoints() const : return number of point in the point set
- ** const box& impl_bbox() const : return a box which includes all poin into the set
- ** void insert(const P& p, unsigned len): insert a new range on the point set
- ** bool impl_has(const P& p) const : if p include in the set
- ** const std_container& con() const : return the container of the point
- **
*/
template <typename P>
class rle_pset : public internal::point_set_base_<rle_pset <P> >
@@ -92,17 +85,25 @@
rle_pset();
+ /// unsigned impl_npoints() const : return number of point in the point set
unsigned impl_npoints() const;
+ /// const box& impl_bbox() const : return a box which includes all poin into the set
const box& impl_bbox() const;
+ /// void insert(const P& p, unsigned len): insert a new range on the point set
void insert(const P& p, unsigned len);
+ /// bool impl_has(const P& p) const : if p include in the set
bool impl_has(const P& p) const;
+ /// const std_container& con() const : return the container of the point
const std_container& con() const;
unsigned range_len_(const P& range_len_) const;
protected:
- unsigned npts; /*!< number of point in the set*/
- std_container con_; /*!< container of the set*/
- fbbox_<point> fb_; /*!< pset box*/
+ /// number of point in the set
+ unsigned npts;
+ /// container of the set
+ std_container con_;
+ /// pset box
+ fbbox_<point> fb_;
};
@@ -204,12 +205,6 @@
** \brief foward iterator for rle_pset
**
** P must be a point type
- ** method:
- ** void impl_start(): set the iterator to the start of pset
- ** void impl_next(): go to next point
- ** void impl_invalidate(): invalidate iterator
- ** void impl_valid(): is the iterator valid?
- ** + conversions methods
*/
template <typename P>
class rle_pset_fwd_piter_ : public Iterator_on_Points< rle_pset_fwd_piter_<P> >
@@ -221,11 +216,16 @@
rle_pset_fwd_piter_(const rle_pset<P>& con);
+ /// void impl_start(): set the iterator to the start of pset
void impl_start();
+ /// void impl_next(): go to next point
void impl_next();
+ /// void impl_invalidate(): invalidate iterator
void impl_invalidate();
+ /// void impl_valid(): is the iterator valid?
bool impl_is_valid() const;
+ /// conversion method
const rle_psite<P>& impl_to_psite() const;
point impl_to_point() const;
const point* impl_psite_adr() const;
@@ -235,13 +235,15 @@
protected:
const typename rle_pset<P>::std_container& con_;
typename rle_pset<P>::std_container::const_iterator it_;
- rle_psite<P> ps_; /*!< current point */
+ /// current point
+ rle_psite<P> ps_;
};
# ifndef OLN_INCLUDE_ONLY
template <typename P>
- rle_pset_fwd_piter_<P>::rle_pset_fwd_piter_(const rle_pset<P>& cont) : con_(cont.con())
+ rle_pset_fwd_piter_<P>::rle_pset_fwd_piter_(const rle_pset<P>& cont) :
+ con_(cont.con())
{
this->it_ = this->con_.end();
}
@@ -340,12 +342,6 @@
** \brief backward iterator for rle_pset
**
** P must be a point type
- ** method:
- ** void impl_start(): set the iterator to the start of pset
- ** void impl_next(): go to next point
- ** void impl_invalidate(): invalidate iterator
- ** void impl_valid(): is the iterator valid?
- ** + conversion method
*/
template <typename P>
class rle_pset_bkd_piter_ : public Iterator_on_Points< rle_pset_bkd_piter_<P> >
@@ -357,10 +353,16 @@
rle_pset_bkd_piter_(const rle_pset<P>& con);
+ /// void impl_start(): set the iterator to the start of pset
void impl_start();
+ /// void impl_next(): go to next point
void impl_next();
+ /// void impl_invalidate(): invalidate iterator
void impl_invalidate();
+ /// void impl_valid(): is the iterator valid?
bool impl_is_valid() const;
+
+ /// conversion methods
const rle_psite<P>& impl_to_psite() const;
point impl_to_point() const;
const point* impl_psite_adr() const;
@@ -369,7 +371,8 @@
protected:
const typename rle_pset<P>::std_container& con_;
typename rle_pset<P>::std_container::const_reverse_iterator it_;
- rle_psite<P> ps_; /*!< current point*/
+ /// current point
+ rle_psite<P> ps_;
};
# ifndef OLN_INCLUDE_ONLY
@@ -454,4 +457,4 @@
} // end of namespace oln
-#endif /* !OLN_CORE_RLE_RLE_PSET_HH_ */
+#endif // !OLN_CORE_RLE_RLE_PSET_HH
Index: oln/core/encode/sparse_encode.hh
--- oln/core/encode/sparse_encode.hh (revision 886)
+++ oln/core/encode/sparse_encode.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 EPITA
+// Copyright (C) 2007 EPITA
// Research and Development Laboratory
//
// This file is part of the Olena Library. This library is free
@@ -26,8 +26,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef SPARSE_ENCODE_HH_
-# define SPARSE_ENCODE_HH_
+#ifndef OLN_CORE_ENCODE_SPARSE_ENCODE_HH
+# define OLN_CORE_ENCODE_SPARSE_ENCODE_HH
# include <oln/core/concept/image.hh>
@@ -61,16 +61,17 @@
return output;
rstart = p;
+
//FIXME: is it generall ?
old = (p.to_point())[0];
- values.push_back(input(p.to_point()));
+ values.push_back(input(p));
p.next();
while (p.is_valid())
{
if ((p.to_point())[0] - 1 == old)
{
++len;
- values.push_back(input(p.to_point()));
+ values.push_back(input(p));
}
else
{
@@ -78,7 +79,7 @@
rstart = p;
len = 1;
values.clear();
- values.push_back(input(p.to_point()));
+ values.push_back(input(p));
}
old = (p.to_point())[0];
p.next();
@@ -88,4 +89,4 @@
}
}
-#endif /* !SPARSE_ENCODE_HH_ */
+#endif // !OLN_CORE_ENCODE_SPARSE_ENCODE_HH
Index: oln/core/encode/rle_encode.hh
--- oln/core/encode/rle_encode.hh (revision 886)
+++ oln/core/encode/rle_encode.hh (working copy)
@@ -26,8 +26,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef RLE_ENCODE_HH_
-# define RLE_ENCODE_HH_
+#ifndef OLN_CORE_ENCODE_RLE_ENCODE_HH
+# define OLN_CORE_ENCODE_RLE_ENCODE_HH
# include <oln/core/concept/image.hh>
@@ -50,8 +50,10 @@
rle_image<typename I::point, typename I::value> output;
typename I::piter p (input.points());
unsigned len = 1;
- typename I::point rstart; /*!< range pointstart */
- typename I::value rvalue; /*!< range value */
+ /// range point start
+ typename I::point rstart;
+ /// range value
+ typename I::value rvalue;
p.start();
if (!p.is_valid())
@@ -78,4 +80,4 @@
}
} // end of namespace oln
-#endif /* !RLE_ENCODE_HH_ */
+#endif /* !OLN_CORE_ENCODE_RLE_ENCODE_HH */
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add the type of 'point set such as f : point -> bool.
* oln/core/concept/functions.hh: Rename as...
* oln/core/concept/function.hh: ...this.
* oln/core/gen/piter_isubset.hh: Rename as...
* oln/core/internal/piter_adaptor.hh: ...this.
* oln/core/gen/fun.hh: New.
* oln/core/internal/op_pset_such_as_fp2b.hh: New.
* oln/core/concept/value.hh (Boolean): New.
* oln/core/2d/grid2d.hh (grid2d_rec): Rename as...
(grid2d): ...this.
(grid2d): Rename as...
(grid2d_rec): ...this.
* oln/core/2d/point2d.hh: Cosmetic change.
* oln/core/equipment.hh (adapted): New.
* oln/core/gen/op.hh (category_of_): Move to...
* oln/core/internal/category_of.hh: ...this new file.
* oln/core/internal/point_base.hh: Add commentary.
* oln/core/internal/dpoint_base.hh (vtypes): Add category.
* oln/core/internal/point_set_base.hh (operator|): New.
(include): Update.
* oln/core/internal/op_image_plus_nbh.hh: Cosmetic change.
* oln/core/internal/special_op.hh (include): Remove image_base.hh.
2d/grid2d.hh | 10 -
2d/point2d.hh | 2
concept/function.hh | 30 ++-
concept/value.hh | 18 +
equipment.hh | 4
gen/fun.hh | 120 ++++++++++++
gen/op.hh | 22 --
gen/pset_such_as.hh | 380 +++++++++++++++++++++++++++++++++++++++
internal/category_of.hh | 124 ++++++++++++
internal/dpoint_base.hh | 4
internal/op_image_plus_nbh.hh | 2
internal/op_pset_such_as_fp2b.hh | 336 ++++++++++++++++++++++++++++++++++
internal/piter_adaptor.hh | 147 +++++----------
internal/point_base.hh | 10 -
internal/point_set_base.hh | 35 +++
internal/special_op.hh | 2
16 files changed, 1119 insertions(+), 127 deletions(-)
Index: oln/core/concept/function.hh
--- oln/core/concept/function.hh (revision 877)
+++ oln/core/concept/function.hh (working copy)
@@ -25,15 +25,18 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_CORE_CONCEPT_FUNCTIONS_HH
-# define OLN_CORE_CONCEPT_FUNCTIONS_HH
+#ifndef OLN_CORE_CONCEPT_FUNCTION_HH
+# define OLN_CORE_CONCEPT_FUNCTION_HH
# include <oln/core/equipment.hh>
+
+
namespace oln
{
+
/*
// Fwd decl.
@@ -46,6 +49,10 @@
*/
template <typename Exact>
+ struct Function;
+
+
+ template <typename Exact>
struct Function : public Any<Exact>
{
protected:
@@ -63,6 +70,16 @@
};
+ // Point -> bool.
+
+ template <typename Exact>
+ struct Function_p2b : public Function<Exact>
+ {
+ protected:
+ Function_p2b();
+ };
+
+
// Value -> Value.
template <typename Exact>
@@ -73,7 +90,7 @@
};
- // Neighborhood -> Value.
+ // Values -> Value.
template <typename Exact>
struct Accumulator : public Function<Exact>
@@ -137,6 +154,11 @@
}
template <typename Exact>
+ Function_p2b<Exact>::Function_p2b()
+ {
+ }
+
+ template <typename Exact>
Function_p2v<Exact>::Function_p2v()
{
}
@@ -170,4 +192,4 @@
} // end of namespace oln
-#endif // ! OLN_CORE_CONCEPT_FUNCTIONS_HH
+#endif // ! OLN_CORE_CONCEPT_FUNCTION_HH
Index: oln/core/concept/value.hh
--- oln/core/concept/value.hh (revision 885)
+++ oln/core/concept/value.hh (working copy)
@@ -44,14 +44,32 @@
Value();
};
+ /// Concept-class "Boolean".
+
+ template <typename Exact>
+ struct Boolean : public Value<Exact>
+ {
+ protected:
+ Boolean();
+ };
+
# ifndef OLN_INCLUDE_ONLY
+ // Value.
+
template <typename Exact>
Value<Exact>::Value()
{
}
+ // Boolean.
+
+ template <typename Exact>
+ Boolean<Exact>::Boolean()
+ {
+ }
+
# endif
} // end of namespace oln
Index: oln/core/2d/grid2d.hh
--- oln/core/2d/grid2d.hh (revision 885)
+++ oln/core/2d/grid2d.hh (working copy)
@@ -53,7 +53,7 @@
/// Fwd decls.
template <typename Exact> struct Grid_2D;
- struct grid2d_rec;
+ struct grid2d;
struct grid2d_hex;
struct grid2d_tri;
@@ -83,9 +83,9 @@
/// Super types.
template<>
- struct super_trait_< grid2d_rec >
+ struct super_trait_< grid2d >
{
- typedef Grid_2D< grid2d_rec > ret;
+ typedef Grid_2D< grid2d > ret;
};
template<>
@@ -107,10 +107,10 @@
/// Rectangular grid struct.
- struct grid2d_rec : public Grid_2D< grid2d_rec >
+ struct grid2d : public Grid_2D< grid2d >
{};
- typedef grid2d_rec grid2d; // for short
+ typedef grid2d grid2d_rec; // more explicit
/// Hexagonal grid struct.
Index: oln/core/2d/point2d.hh
--- oln/core/2d/point2d.hh (revision 885)
+++ oln/core/2d/point2d.hh (working copy)
@@ -93,7 +93,7 @@
this->col() = dat->second.value;
}
-# endif
+# endif // OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/equipment.hh
--- oln/core/equipment.hh (revision 885)
+++ oln/core/equipment.hh (working copy)
@@ -49,6 +49,10 @@
# include <stc/scoop-alt.inc>
# endif
+ // a
+
+ stc_decl_associated_type( adapted );
+
// b
stc_decl_associated_type( bkd_niter );
stc_decl_associated_type( bkd_piter );
Index: oln/core/gen/fun.hh
--- oln/core/gen/fun.hh (revision 0)
+++ oln/core/gen/fun.hh (revision 0)
@@ -0,0 +1,120 @@
+// 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 OLN_CORE_GEN_FUN_HH
+# define OLN_CORE_GEN_FUN_HH
+
+# include <oln/core/internal/category_of.hh>
+# include <oln/core/concept/function.hh>
+# include <oln/core/concept/point.hh>
+# include <oln/core/concept/value.hh>
+
+
+
+// FIXME: Add "fun" to names below.
+# define oln_arg_of_(T) typename oln::internal::argument_of_< T >::ret
+# define oln_res_of_(T) typename oln::internal::result_of_< T >::ret
+
+
+
+namespace oln
+{
+
+
+ namespace internal
+ {
+
+ // result_of_
+
+ template <typename F>
+ struct result_of_
+ {
+ typedef typename F::result ret;
+ };
+
+ template <typename R, typename A>
+ struct result_of_< R (*)(A) >
+ {
+ typedef R ret;
+ };
+
+
+ // argument_of_
+
+ template <typename F>
+ struct argument_of_
+ {
+ typedef typename F::argument ret;
+ };
+
+ template <typename R, typename A>
+ struct argument_of_< R (*)(A) >
+ {
+ typedef A ret;
+ };
+
+
+ } // end of namespace oln::internal
+
+
+
+ // Fwd decl.
+ template <typename F> struct fun_p2b_;
+
+ // Category.
+ namespace internal
+ {
+ template <typename F>
+ struct set_category_of_< fun_p2b_<F> >
+ {
+ typedef stc::is< Function_p2b > ret;
+ };
+ }
+
+ // Class.
+ template <typename F>
+ struct fun_p2b_ : public Function_p2b< fun_p2b_<F> >
+ {
+ typedef oln_arg_of_(F) argument;
+ typedef oln_res_of_(F) result;
+
+ fun_p2b_(F f) : f_(f) {}
+
+ result operator()(argument arg) const
+ {
+ return this->f_(arg);
+ }
+
+ private:
+ F f_;
+ };
+
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_GEN_FUN_HH
Index: oln/core/gen/op.hh
--- oln/core/gen/op.hh (revision 885)
+++ oln/core/gen/op.hh (working copy)
@@ -29,6 +29,9 @@
# define OLN_CORE_GEN_OP_HH
# include <oln/core/internal/special_op.hh>
+# include <oln/core/internal/category_of.hh>
+# include <oln/core/concept/function.hh>
+# include <oln/core/concept/value.hh>
@@ -78,28 +81,10 @@
-
-# define oln_category_of_(Type) typename oln::internal::category_of_<Type>::ret
-
-
namespace oln
{
- namespace internal
- {
- template <typename T>
- struct category_of_
- {
- typedef stc_type(T, category) ret;
- };
-
- // ...
-
- } // end of namespace oln::internal
-
-
-
/// \{
/// Operator Names.
@@ -111,6 +96,7 @@
+
// Fwd decl.
template <typename L, typename OpName, typename R> class op_;
Index: oln/core/gen/pset_such_as.hh
--- oln/core/gen/pset_such_as.hh (revision 0)
+++ oln/core/gen/pset_such_as.hh (revision 0)
@@ -0,0 +1,380 @@
+// 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 OLN_CORE_INTERNAL_POINT_SET_STD_BASED_HH
+# define OLN_CORE_INTERNAL_POINT_SET_STD_BASED_HH
+
+# include <ostream>
+# include <algorithm>
+
+# include <oln/core/internal/point_set_base.hh>
+# include <oln/core/concept/iterator_on_points.hh>
+# include <oln/core/gen/fbbox.hh>
+
+
+namespace oln
+{
+
+
+ /// Fwd decl.
+ namespace internal { template <typename Exact> struct point_set_std_based_; }
+ template <typename P> class pset_std_based_fwd_piter_;
+ template <typename P> class pset_std_based_bkd_piter_;
+
+
+ /// Super type.
+ template <typename Exact>
+ struct super_trait_< internal::point_set_std_based_<Exact> >
+ {
+ typedef internal::point_set_base_<Exact> ret;
+ };
+
+
+ /// Virtual types.
+ template <typename Exact>
+ struct vtypes< internal::point_set_std_based_<Exact> >
+ {
+ typedef stc::abstract std_container;
+
+ typedef stc_deferred(std_container) std_container__;
+ typedef stc::final< typename std_container__::value_type > point;
+ typedef stc::final< pset_std_based_fwd_piter_<std_container__> > fwd_piter;
+ typedef stc::final< pset_std_based_bkd_piter_<std_container__> > bkd_piter;
+ };
+
+
+ namespace internal
+ {
+
+ /// Base class for point sets defined over std containers.
+
+ template <typename Exact>
+ struct point_set_std_based_ : public point_set_base_<Exact>
+ {
+ typedef point_set_base_<Exact> super;
+ public:
+
+ stc_using(point);
+ stc_using(box);
+
+ unsigned impl_npoints() const;
+ bool impl_has(const point& p) const;
+ const box& impl_bbox() const;
+
+ stc_typename(std_container);
+ const std_container& con() const;
+
+ protected:
+
+ point_set_std_based_();
+
+ void take_(const point& p);
+
+ std_container con_;
+ fbbox_<point> fb_;
+
+ }; // end of class point_set_std_based_<Exact>
+
+
+ template <typename Exact>
+ std::ostream& operator<<(std::ostream& ostr,
+ const point_set_std_based_<Exact>& pts)
+ {
+ typename Exact::fwd_piter i(pts);
+ ostr << "{ ";
+ for_all(i)
+ ostr << i.to_point() << ' ';
+ ostr << "}";
+ return ostr;
+ }
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename Exact>
+ unsigned
+ point_set_std_based_<Exact>::impl_npoints() const
+ {
+ return this->con_.size();
+ }
+
+ template <typename Exact>
+ bool
+ point_set_std_based_<Exact>::impl_has(const typename point_set_std_based_<Exact>::point& p) const
+ {
+ return std::find(this->con_.begin(), this->con_.end(), p) != this->con_.end();
+ }
+
+ template <typename Exact>
+ const typename point_set_std_based_<Exact>::box&
+ point_set_std_based_<Exact>::impl_bbox() const
+ {
+ precondition(this->fb_.is_valid());
+ return this->fb_.box();
+ }
+
+ template <typename Exact>
+ point_set_std_based_<Exact>::point_set_std_based_()
+ {
+ }
+
+ template <typename Exact>
+ void
+ point_set_std_based_<Exact>::take_(const typename point_set_std_based_<Exact>::point& p)
+ {
+ this->fb_.take(p);
+ }
+
+ template <typename Exact>
+ const typename point_set_std_based_<Exact>::std_container&
+ point_set_std_based_<Exact>::con() const
+ {
+ return this->con_;
+ }
+
+# endif
+
+ } // end of namespace oln::internal
+
+
+
+
+ // -------------------- iterators on classes deriving from internal::point_set_std_based_<Exact>
+
+
+
+ // Super types.
+
+ template <typename C>
+ struct super_trait_< pset_std_based_fwd_piter_<C> >
+ {
+ typedef pset_std_based_fwd_piter_<C> current__;
+ typedef Iterator_on_Points<current__> ret;
+ };
+
+ template <typename C>
+ struct super_trait_< pset_std_based_bkd_piter_<C> >
+ {
+ typedef pset_std_based_bkd_piter_<C> current__;
+ typedef Iterator_on_Points<current__> ret;
+ };
+
+
+
+ /// Virtual types.
+
+ template <typename C>
+ struct vtypes< pset_std_based_fwd_piter_<C> >
+ {
+ typedef typename C::value_type point;
+ };
+
+ template <typename C>
+ struct vtypes< pset_std_based_bkd_piter_<C> >
+ {
+ typedef typename C::value_type point;
+ };
+
+
+ // Class pset_std_based_fwd_piter_<C>.
+
+ template <typename C>
+ class pset_std_based_fwd_piter_ : public Iterator_on_Points< pset_std_based_fwd_piter_<C> >
+ {
+ typedef pset_std_based_fwd_piter_<C> current;
+ typedef Iterator_on_Points<current> super;
+ public:
+
+ stc_using(point);
+
+ template <typename Ps>
+ pset_std_based_fwd_piter_(const internal::point_set_std_based_<Ps>& con);
+
+ void impl_start();
+ void impl_next();
+ void impl_invalidate();
+ bool impl_is_valid() const;
+ point impl_to_point() const;
+ const point* impl_point_adr() const;
+
+ private:
+
+ const C& con_;
+ typename C::const_iterator it_;
+
+ }; // end of class pset_std_based_fwd_piter_<C>
+
+
+ // Class pset_std_based_bkd_piter_<C>.
+
+ template <typename C>
+ class pset_std_based_bkd_piter_ : public Iterator_on_Points< pset_std_based_bkd_piter_<C> >
+ {
+ typedef pset_std_based_bkd_piter_<C> current;
+ typedef Iterator_on_Points<current> super;
+ public:
+
+ stc_using(point);
+
+ template <typename Ps>
+ pset_std_based_bkd_piter_(const internal::point_set_std_based_<Ps>& pts);
+
+ void impl_start();
+ void impl_next();
+ void impl_invalidate();
+ bool impl_is_valid() const;
+ point impl_to_point() const;
+ const point* impl_point_adr() const;
+
+ private:
+
+ const C& con_;
+ typename C::const_reverse_iterator it_;
+
+ }; // end of class pset_std_based_bkd_piter_<C>
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+
+
+ // -------------------- pset_std_based_fwd_piter_<C>
+
+
+ template <typename C>
+ template <typename Ps>
+ pset_std_based_fwd_piter_<C>::pset_std_based_fwd_piter_(const internal::point_set_std_based_<Ps>& pts)
+ : con_(pts.con())
+ {
+ this->it_ = this->con_.end();
+ }
+
+ template <typename C>
+ void pset_std_based_fwd_piter_<C>::impl_start()
+ {
+ this->it_ = this->con_.begin();
+ }
+
+ template <typename C>
+ void pset_std_based_fwd_piter_<C>::impl_next()
+ {
+ ++this->it_;
+ }
+
+ template <typename C>
+ void pset_std_based_fwd_piter_<C>::impl_invalidate()
+ {
+ this->it_ = this->con_.end();
+ }
+
+ template <typename C>
+ bool pset_std_based_fwd_piter_<C>::impl_is_valid() const
+ {
+ return this->it_ != this->con_.end();
+ }
+
+ template <typename C>
+ typename pset_std_based_fwd_piter_<C>::point
+ pset_std_based_fwd_piter_<C>::impl_to_point() const
+ {
+ return *this->it_;
+ }
+
+ template <typename C>
+ const typename pset_std_based_fwd_piter_<C>::point*
+ pset_std_based_fwd_piter_<C>::impl_point_adr() const
+ {
+ return &(*(this->it_));
+ // FIXME: "&(*it_)" is not always correct because the std does not
+ // ensure that "*it_" is dereferenceable (Cf. std trivial iterator
+ // concept). However, "::point_adr()" is only required so that an
+ // iterator based on another iterator (e.g., a niter constructed
+ // from a piter) can stick to the point location of the latter.
+ // This is not required for iterators on point set so this method
+ // should be optional.
+ }
+
+
+ // -------------------- pset_std_based_bkd_piter_<C>
+
+
+ template <typename C>
+ template <typename Ps>
+ pset_std_based_bkd_piter_<C>::pset_std_based_bkd_piter_(const internal::point_set_std_based_<Ps>& pts)
+ : con_(pts.con())
+ {
+ this->it_ = this->con_.rend();
+ }
+
+ template <typename C>
+ void pset_std_based_bkd_piter_<C>::impl_start()
+ {
+ this->it_ = this->con_.rbegin();
+ }
+
+ template <typename C>
+ void pset_std_based_bkd_piter_<C>::impl_next()
+ {
+ ++this->it_;
+ }
+
+ template <typename C>
+ void pset_std_based_bkd_piter_<C>::impl_invalidate()
+ {
+ this->it_ = this->con_.rend();
+ }
+
+ template <typename C>
+ bool pset_std_based_bkd_piter_<C>::impl_is_valid() const
+ {
+ return this->it_ != this->con_.rend();
+ }
+
+ template <typename C>
+ typename pset_std_based_bkd_piter_<C>::point
+ pset_std_based_bkd_piter_<C>::impl_to_point() const
+ {
+ return *this->it_;
+ }
+
+ template <typename C>
+ const typename pset_std_based_bkd_piter_<C>::point*
+ pset_std_based_bkd_piter_<C>::impl_point_adr() const
+ {
+ return &(*(this->it_));
+ // FIXME: Read comments in pset_std_based_fwd_piter_<C>.
+ }
+
+
+# endif
+
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_INTERNAL_POINT_SET_STD_BASED_HH
Index: oln/core/internal/point_base.hh
--- oln/core/internal/point_base.hh (revision 885)
+++ oln/core/internal/point_base.hh (working copy)
@@ -50,13 +50,15 @@
template <typename Exact>
struct vtypes< internal::point_base_<Exact> >
{
- typedef stc::abstract grid;
+ typedef stc::abstract grid; // FIXME: Could be defined and final?
+ typedef stc::abstract coord; // FIXME: Likewise?
+ typedef stc::abstract dpoint;
typedef stc_deferred(grid) grid__;
- typedef stc::final<stc_type(grid__, dim)> dim;
- typedef stc::abstract coord;
- typedef stc::abstract dpoint;
+ // Final:
+ typedef stc::final<typename grid__::dim> dim; // FIXME: Propagate this kind of changes.
+ typedef stc::final< stc::is<Point> > category;
};
Index: oln/core/internal/op_pset_such_as_fp2b.hh
--- oln/core/internal/op_pset_such_as_fp2b.hh (revision 0)
+++ oln/core/internal/op_pset_such_as_fp2b.hh (revision 0)
@@ -0,0 +1,336 @@
+// 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 OLN_CORE_INTERNAL_OP_PSET_SUCH_AS_FP2B_HH
+# define OLN_CORE_INTERNAL_OP_PSET_SUCH_AS_FP2B_HH
+
+# include <oln/core/concept/function.hh>
+# include <oln/core/gen/op.hh>
+# include <oln/core/internal/piter_adaptor.hh>
+# include <oln/core/internal/point_set_base.hh>
+
+
+namespace oln
+{
+
+
+# define current \
+ special_op_< stc::is<Point_Set>, S, such_as, stc::is<Function_p2b>, F >
+
+
+ /// Fwd decls.
+ namespace internal
+ {
+ template <typename S, typename F> class current;
+ }
+ template <typename S, typename F> class pset_such_as_fp2b_fwd_piter_;
+ template <typename S, typename F> class pset_such_as_fp2b_bkd_piter_;
+
+
+
+ /// Super type.
+ template <typename S, typename F>
+ struct super_trait_< internal::current >
+ {
+ typedef internal::point_set_base_< op_<S, such_as, F> > ret;
+ };
+
+
+ /// Virtual types.
+ template <typename S, typename F>
+ struct vtypes< internal::current >
+ {
+ typedef typename S::point point;
+ typedef pset_such_as_fp2b_fwd_piter_<S, F> fwd_piter;
+ typedef pset_such_as_fp2b_bkd_piter_<S, F> bkd_piter;
+ };
+
+
+ namespace internal
+ {
+
+ /// Implementation class the result of "Point_Set S | Function_p2b F".
+
+ template <typename S, typename F>
+ class current
+ :
+ public internal::point_set_base_< op_<S, such_as, F> >
+ {
+ typedef internal::point_set_base_< op_<S, such_as, F> > super;
+ public:
+
+ stc_using(point);
+ stc_using(box);
+
+ unsigned impl_npoints() const;
+ bool impl_has(const point& p) const;
+ const box& impl_bbox() const;
+
+ const S& adapted_() const;
+ F fun_() const;
+
+ protected:
+ special_op_();
+ special_op_(S& pset, F& f);
+
+ S pset_;
+ F f_;
+
+ // template <typename D>
+ // friend
+ // bool init_(internal::current* this_, const D& dat);
+ };
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename S, typename F>
+ current::special_op_()
+ {
+ }
+
+ template <typename S, typename F>
+ current::special_op_(S& pset, F& f)
+ : pset_(pset),
+ f_(f)
+ {
+ }
+
+ template <typename S, typename F>
+ unsigned
+ current::impl_npoints() const
+ {
+ return 0; // FIXME: Wrong!!!
+ }
+
+ template <typename S, typename F>
+ bool
+ current::impl_has(const typename current::point& p) const
+ {
+ return this->pset_.has(p) and this->f_(p);
+ }
+
+ template <typename S, typename F>
+ const typename current::box&
+ current::impl_bbox() const
+ {
+ return this->pset_.bbox();
+ }
+
+ template <typename S, typename F>
+ const S&
+ current::adapted_() const
+ {
+ return this->pset_;
+ }
+
+ template <typename S, typename F>
+ F current::fun_() const
+ {
+ return this->f_;
+ }
+
+# endif
+
+ } // end of namespace oln::internal
+
+
+// // Fixme: Activate init
+
+// template <typename S, typename F, typename D>
+// bool init_(internal::current* this_, const D& dat)
+// {
+// bool pset_ok = init(this_->pset_, with, dat);
+// bool fun_ok = init(this_->f_, with, dat);
+// postcondition(pset_ok);
+// postcondition(fun_ok);
+// return pset_ok and fun_ok;
+// }
+
+
+# undef current
+
+
+
+
+
+
+
+# define current pset_such_as_fp2b_fwd_piter_<S, F>
+ // ----------------------------------
+
+# define super internal::piter_adaptor_< current >
+
+
+ // Super type.
+ template <typename S, typename F>
+ struct super_trait_< current >
+ {
+ typedef super ret;
+ };
+
+
+ // Virtual types.
+ template <typename S, typename F>
+ struct vtypes< current >
+ {
+ typedef typename S::point point;
+ typedef typename S::fwd_piter adapted;
+ };
+
+
+ // Class.
+ template <typename S, typename F>
+ class pset_such_as_fp2b_fwd_piter_ : public super
+ {
+ public:
+
+ pset_such_as_fp2b_fwd_piter_();
+ pset_such_as_fp2b_fwd_piter_(const Point_Set< op_<S, such_as, F> >& pset);
+
+ void impl_start();
+ void impl_next();
+
+ private:
+ F f_;
+
+ };
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename S, typename F>
+ current::pset_such_as_fp2b_fwd_piter_(const Point_Set< op_<S, such_as, F> >& pset)
+ : super(exact(pset).adapted_()),
+ f_(exact(pset).fun_())
+ {
+ }
+
+ template <typename S, typename F>
+ void
+ current::impl_start()
+ {
+ this->p_.start();
+ while (this->p_.is_valid() and not f_(this->p_))
+ this->p_.next();
+ }
+
+ template <typename S, typename F>
+ void
+ current::impl_next()
+ {
+ do
+ this->p_.next();
+ while (this->p_.is_valid() and not f_(this->p_));
+ }
+
+# endif // OLN_INCLUDE_ONLY
+
+# undef super
+# undef current
+
+
+
+
+
+# define current pset_such_as_fp2b_bkd_piter_<S, F>
+ // ----------------------------------
+
+# define super internal::piter_adaptor_< current >
+
+
+ // Super type.
+ template <typename S, typename F>
+ struct super_trait_< current >
+ {
+ typedef super ret;
+ };
+
+
+ // Virtual types.
+ template <typename S, typename F>
+ struct vtypes< current >
+ {
+ typedef typename S::point point;
+ typedef typename S::fwd_piter adapted;
+ };
+
+
+ // Class.
+ template <typename S, typename F>
+ class pset_such_as_fp2b_bkd_piter_ : public super
+ {
+ public:
+
+ pset_such_as_fp2b_bkd_piter_(const Point_Set< op_<S, such_as, F> >& pset);
+
+ void impl_start();
+ void impl_next();
+
+ private:
+ F f_;
+
+ };
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename S, typename F>
+ current::pset_such_as_fp2b_bkd_piter_(const Point_Set< op_<S, such_as, F> >& pset)
+ : super(exact(pset).adapted_()),
+ f_(exact(pset).fun_())
+ {
+ }
+
+ template <typename S, typename F>
+ void
+ current::impl_start()
+ {
+ this->p_.start();
+ while (this->p_.is_valid() and not f_(this->p_))
+ this->p_.next();
+ }
+
+ template <typename S, typename F>
+ void
+ current::impl_next()
+ {
+ do
+ this->p_.next();
+ while (this->p_.is_valid() and not f_(this->p_));
+ }
+
+# endif // OLN_INCLUDE_ONLY
+
+# undef super
+# undef current
+
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_INTERNAL_OP_PSET_SUCH_AS_FP2B_HH
Index: oln/core/internal/dpoint_base.hh
--- oln/core/internal/dpoint_base.hh (revision 885)
+++ oln/core/internal/dpoint_base.hh (working copy)
@@ -57,7 +57,9 @@
typedef stc::final<stc_type(grid__, dim)> dim;
typedef stc::abstract coord;
- typedef stc::abstract point;
+ typedef stc::abstract point; // FIXME: Just like in point_base.hh
+
+ typedef stc::final< stc::is<Dpoint> > category;
};
Index: oln/core/internal/piter_adaptor.hh
--- oln/core/internal/piter_adaptor.hh (revision 879)
+++ oln/core/internal/piter_adaptor.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2006 EPITA Research and Development Laboratory
+// Copyright (C) 2006, 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
@@ -25,159 +25,124 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_CORE_GEN_PITER_ISUBSET_HH
-# define OLN_CORE_GEN_PITER_ISUBSET_HH
+#ifndef OLN_CORE_INTERNAL_PITER_ADAPTOR_HH
+# define OLN_CORE_INTERNAL_PITER_ADAPTOR_HH
-# include <oln/core/abstract/iterator_on_points.hh>
-# include <oln/core/abstract/topology.hh>
-# include <oln/core/gen/topo_add_isubset.hh>
+# include <oln/core/concept/iterator_on_points.hh>
namespace oln
{
- // Forward declaration.
- template <typename piter_t, typename isubset_t> class piter_isubset_;
+ // Fwd decl.
+ namespace internal { template <typename Exact> class piter_adaptor_; }
- // Super type declaration.
- template <typename piter_t, typename isubset_t>
- struct set_super_type< piter_isubset_<piter_t, isubset_t> >
+ // Super type.
+ template <typename Exact>
+ struct super_trait_< internal::piter_adaptor_<Exact> >
{
- typedef piter_isubset_<piter_t, isubset_t> self_t;
- typedef abstract::iterator_on_points<self_t> ret;
+ typedef Iterator_on_Points<Exact> ret;
};
- /// Virtual types associated to oln::piter_isubset_<piter_t, isubset_t>.
- template <typename piter_t, typename isubset_t>
- struct vtypes< piter_isubset_<piter_t, isubset_t> >
+ // Virtual types.
+ template <typename Exact>
+ struct vtypes< internal::piter_adaptor_<Exact> >
{
- typedef oln_vtype(piter_t, point) point_type;
- typedef oln_vtype(piter_t, grid) grid_type;
-
- typedef topo_add_isubset<oln_vtype(piter_t, topo), isubset_t> topo_type;
+ typedef stc::abstract point;
+ typedef stc::abstract adapted;
};
-
- /// Abstract forward point iterator class.
- template <typename piter_t, typename isubset_t>
- class piter_isubset_ : public abstract::iterator_on_points< piter_isubset_<piter_t, isubset_t> >
+ namespace internal
{
- typedef piter_isubset_<piter_t, isubset_t> self_t;
- typedef abstract::iterator_on_points<self_t> super_t;
- typedef oln_vtype(self_t, topo) topo_t;
- typedef oln_vtype(self_t, point) point_t;
+ // Base implementation class for types of iterator on points
+ // defined over other types of iterator on points.
+ template <typename Exact>
+ class piter_adaptor_ : public Iterator_on_Points<Exact>
+ {
+ typedef Iterator_on_Points<Exact> super;
public:
- template <typename T>
- piter_isubset_(const abstract::topology<T>& topo);
+ stc_using(point);
+ stc_typename(adapted);
- template <typename P, typename T>
- piter_isubset_(const P& p, const abstract::topology<T>& topo);
+ piter_adaptor_(adapted p);
+ // Default impl is delegation.
void impl_start();
-
void impl_next();
-
void impl_invalidate();
-
bool impl_is_valid() const;
-
- point_t impl_to_point() const;
-
- const point_t* impl_point_adr() const;
-
- const topo_t topo() const;
+ point impl_to_point() const;
+ const point* impl_point_adr() const;
protected:
+ adapted p_;
- piter_t p_;
- isubset_t isubset_; // Cpy.
-
- }; // end of class oln::piter_isubset_<point>
+ }; // end of class oln::internal::piter_adaptor_<Exact>
# ifndef OLN_INCLUDE_ONLY
- template <typename piter_t, typename isubset_t>
- template <typename T>
- piter_isubset_<piter_t, isubset_t>::piter_isubset_(const abstract::topology<T>& topo)
- : p_(topo),
- isubset_(topo.exact().subset())
- {
- }
-
- template <typename piter_t, typename isubset_t>
- template <typename P, typename T>
- piter_isubset_<piter_t, isubset_t>::piter_isubset_(const P& p, const abstract::topology<T>& topo)
- : p_(p, topo),
- isubset_(topo.exact().subset())
+ template <typename Exact>
+ piter_adaptor_<Exact>::piter_adaptor_(adapted p)
+ : p_(p)
{
}
- template <typename piter_t, typename isubset_t>
+ template <typename Exact>
void
- piter_isubset_<piter_t, isubset_t>::impl_start()
+ piter_adaptor_<Exact>::impl_start()
{
- p_.start();
- while (p_.is_valid() and isubset_(p_) = false)
- p_.next();
+ this->p_.start();
}
- template <typename piter_t, typename isubset_t>
+ template <typename Exact>
void
- piter_isubset_<piter_t, isubset_t>::impl_next()
+ piter_adaptor_<Exact>::impl_next()
{
- do
- p_.next();
- while (p_.is_valid() and isubset_(p_) = false);
+ this->p_.next();
}
- template <typename piter_t, typename isubset_t>
+ template <typename Exact>
void
- piter_isubset_<piter_t, isubset_t>::impl_invalidate()
+ piter_adaptor_<Exact>::impl_invalidate()
{
- p_.invalidate();
+ this->p_.invalidate();
}
- template <typename piter_t, typename isubset_t>
+ template <typename Exact>
bool
- piter_isubset_<piter_t, isubset_t>::impl_is_valid() const
+ piter_adaptor_<Exact>::impl_is_valid() const
{
- return p_.is_valid();
+ return this->p_.is_valid();
}
- template <typename piter_t, typename isubset_t>
- typename piter_isubset_<piter_t, isubset_t>::point_t
- piter_isubset_<piter_t, isubset_t>::impl_to_point() const
+ template <typename Exact>
+ typename piter_adaptor_<Exact>::point
+ piter_adaptor_<Exact>::impl_to_point() const
{
- return p_.to_point();
+ return this->p_.to_point();
}
- template <typename piter_t, typename isubset_t>
- const typename piter_isubset_<piter_t, isubset_t>::point_t*
- piter_isubset_<piter_t, isubset_t>::impl_point_adr() const
+ template <typename Exact>
+ const typename piter_adaptor_<Exact>::point*
+ piter_adaptor_<Exact>::impl_point_adr() const
{
- return p_.point_adr();
- }
-
- template <typename piter_t, typename isubset_t>
- const typename piter_isubset_<piter_t, isubset_t>::topo_t
- piter_isubset_<piter_t, isubset_t>::topo() const
- {
- topo_t tmp(p_.topo(), isubset_);
- return tmp;
+ return this->p_.point_adr();
}
# endif
+ } // end of namespace oln::internal
+
} // end of namespace oln
-#endif // ! OLN_CORE_GEN_PITER_ISUBSET_HH
+#endif // ! OLN_CORE_INTERNAL_PITER_ADAPTOR_HH
Index: oln/core/internal/point_set_base.hh
--- oln/core/internal/point_set_base.hh (revision 885)
+++ oln/core/internal/point_set_base.hh (working copy)
@@ -93,4 +93,39 @@
} // end of namespace oln
+
+/// \{
+/// FIXME: Bad!
+
+# include <oln/core/gen/fun.hh>
+# include <oln/core/internal/op_pset_such_as_fp2b.hh>
+
+namespace oln
+{
+
+ // Point_Set | Function.
+
+ oln_decl_op_such_as(Point_Set, Function_p2b);
+
+
+ // Specialization.
+
+ template <typename S, typename B, typename P>
+ op_<const S, such_as, const fun_p2b_<B (*)(P)> >
+ operator | (const Point_Set<S>& lhs,
+ B (*f)(P))
+ {
+ typedef oln_strip_(P) P_;
+ mlc::assert_< mlc_is_a(P_, Point) >::check(); // FIXME: Add err msg.
+ mlc::assert_equal_< P_, typename S::point >::check();
+ op_<const S, such_as, const fun_p2b_<B (*)(P)> > tmp(exact(lhs), f);
+ return tmp;
+ }
+
+
+} // end of namespace oln
+
+/// \}
+
+
#endif // ! OLN_CORE_INTERNAL_POINT_SET_BASE_HH
Index: oln/core/internal/category_of.hh
--- oln/core/internal/category_of.hh (revision 0)
+++ oln/core/internal/category_of.hh (revision 0)
@@ -0,0 +1,124 @@
+// Copyright (C) 2006, 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 OLN_CORE_INTERNAL_CATEGORY_OF_HH
+# define OLN_CORE_INTERNAL_CATEGORY_OF_HH
+
+
+# define oln_category_of_(Type) typename oln::internal::category_of_< Type >::ret
+# define oln_strip_(Type) typename oln::internal::strip_< Type >::ret
+
+
+namespace oln
+{
+
+ // Fwd decls.
+ template <typename Exact> struct Boolean;
+
+
+
+ namespace internal
+ {
+
+ // Strip_
+
+
+ template <typename T>
+ struct strip_
+ {
+ typedef T ret;
+ };
+
+ template <typename T>
+ struct strip_< T* >
+ {
+ typedef typename strip_<T>::ret ret;
+ };
+
+ template <typename T>
+ struct strip_< T& >
+ {
+ typedef typename strip_<T>::ret ret;
+ };
+
+ template <typename T>
+ struct strip_< const T >
+ {
+ typedef typename strip_<T>::ret ret;
+ };
+
+
+
+
+ // Category_of_
+
+
+ template <typename T>
+ struct set_category_of_
+ {
+ typedef stc_type(T, category) ret;
+ };
+
+ template <>
+ struct set_category_of_< bool >
+ {
+ typedef stc::is< Boolean > ret;
+ };
+
+
+ template <typename T>
+ struct category_of_
+ {
+ typedef typename strip_<T>::ret T_;
+ typedef typename set_category_of_<T_>::ret ret;
+ };
+
+ // ...
+
+
+
+
+ // only_if_
+
+ template < typename Ret,
+ typename Check_1,
+ typename Check_2 = void,
+ typename Check_3 = void,
+ typename Check_4 = void >
+ struct only_if_
+ {
+ typedef Ret ret;
+ };
+
+
+
+ } // end of namespace oln::internal
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_INTERNAL_CATEGORY_OF_HH
Index: oln/core/internal/op_image_plus_nbh.hh
--- oln/core/internal/op_image_plus_nbh.hh (revision 885)
+++ oln/core/internal/op_image_plus_nbh.hh (working copy)
@@ -82,7 +82,7 @@
/// Implementation class the result of "Image I + Neighborhood N".
template <typename I, typename N>
- class special_op_< stc::is<Image>, I, plus, stc::is<Neighborhood>, N >
+ class current
:
public internal::image_extension_< op_<I, plus, N> >,
private mlc::assert_< mlc_is_not_a(I, Image_with_Nbh) > // FIXME: Add err msg.
Index: oln/core/internal/special_op.hh
--- oln/core/internal/special_op.hh (revision 885)
+++ oln/core/internal/special_op.hh (working copy)
@@ -28,8 +28,6 @@
#ifndef OLN_CORE_INTERNAL_SPECIAL_OP_HH
# define OLN_CORE_INTERNAL_SPECIAL_OP_HH
-# include <oln/core/internal/image_base.hh>
-
namespace oln
{
1
0
I had some probleme with neighborhood image initialisation from another image_with_nbh. See erosion.hh and apply.hh
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Update : erosion (bring some error to light).
* oln/morpho,
* oln/morpho/dilation.hh: New.
* oln/morpho/dilatation.hh: Remove.
* oln/morpho/erosion.hh: .
* oln/function/min.hh: .
* oln/level/apply.hh: .
* oln/level/local.hh: .
* oln/core/concept/functions.hh: .
* oln/core/internal/op_image_plus_nbh.hh: .
* oln/morphomath,
* oln/morphomath/dilatation.hh,
* oln/morphomath/erosion.hh: Remove.
core/concept/functions.hh | 5 +++++
core/internal/op_image_plus_nbh.hh | 1 +
function/min.hh | 2 +-
level/apply.hh | 12 +++++++-----
level/local.hh | 18 +++++++++---------
morpho/dilation.hh | 29 +++++++++++++++++++++++++++++
morpho/erosion.hh | 12 +++++++++---
7 files changed, 61 insertions(+), 18 deletions(-)
Index: oln/morpho/dilation.hh
--- oln/morpho/dilation.hh (revision 0)
+++ oln/morpho/dilation.hh (revision 0)
@@ -0,0 +1,29 @@
+#ifndef OLN_MORPHOMATH_DILATATION_HH_
+# define OLN_MORPHOMATH_DILATATION_HH_
+
+// Facade.
+
+namespace impl
+{
+
+ /// Generic version
+
+ template <typename I, typename W>
+ I dilatation(const Image<I>& input)
+ {
+ max_<oln_value(I)> max;
+ return apply(max, input);
+ }
+
+}
+
+
+/// Facade.
+
+template <typename I, typename W>
+I erosion(const Image<I>& input)
+{
+ return impl::dilatation(exact(input));
+}
+
+#endif /* !OLN_MORPHOMATH_DILATATION_HH_ */
Index: oln/morpho/erosion.hh
--- oln/morpho/erosion.hh (revision 884)
+++ oln/morpho/erosion.hh (working copy)
@@ -38,16 +38,20 @@
namespace morpho
{
+ template <typename I>
+ I erosion(const Image_with_Nbh<I>& input);
+
+# ifndef OLN_INCLUDE_ONLY
+
namespace impl
{
/// Generic version
template <typename I>
- I erosion(Image_with_Nbh<I>& input)
+ I erosion(const Image_with_Nbh<I>& input)
{
function::min_<oln_value(I)> min;
-
return ::oln::level::apply_local(min, input);
}
}
@@ -55,11 +59,13 @@
// Facade.
template <typename I>
- I erosion(Image_with_Nbh<I>& input)
+ I erosion(const Image_with_Nbh<I>& input)
{
return impl::erosion(exact(input));
}
+#endif // ! OLN_INCLUDE_ONLY
+
} // end of namespace
}
Index: oln/function/min.hh
--- oln/function/min.hh (revision 884)
+++ oln/function/min.hh (working copy)
@@ -46,7 +46,7 @@
min_() { this->init(); }
- void init() { val_ = oln_max(T); }
+ void init() const { val_ = oln_max(T); }
result value() const { return val_; }
template <typename U>
Index: oln/level/apply.hh
--- oln/level/apply.hh (revision 884)
+++ oln/level/apply.hh (working copy)
@@ -85,17 +85,19 @@
/// apply_local
template <typename F, typename I>
- oln_plain_value(I, typename F::result)
- apply_local(const Accumulator<F>& fun,
+ I apply_local(const Accumulator<F>& f,
const Image_with_Nbh<I>& input)
{
typedef typename F::result result;
typedef typename F::argument argument;
- oln_ch_value(I, argument) output(input.points());
+ typename I::delegatee out(input.points());
+ I output(out, input.nbhood());
+ // I output(exact(input).image(), input.nbhood());
+ // FIXME: init(output, with, input);
oln_piter(I) p(input.points());
for_all(p)
- output(p) = local(fun, input, p);
+ output(p) = level::local(f, input, p);
return output;
}
@@ -168,7 +170,7 @@
apply_local(const Accumulator<F>& fun,
const Image_with_Nbh<I>& input)
{
- return impl::apply_local(fun, exact(input));
+ return impl::apply_local(fun, input);
}
// /// Facade.
Index: oln/level/local.hh
--- oln/level/local.hh (revision 884)
+++ oln/level/local.hh (working copy)
@@ -5,8 +5,8 @@
// 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
+// 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.
//
@@ -42,7 +42,7 @@
{
template <typename A, typename I>
- typename A::result
+ int //typename A::result
local(const Accumulator<A>& f,
const Image_with_Nbh<I>& input,
const oln_point(I)& p);
@@ -62,8 +62,8 @@
/// Local Apply on neighborhood (nbh included in image).
template <typename A, typename I>
- typename A::result
- local(const Accumulator<A>& f,
+ int//typename A::result
+ local_(const A& f,
const Image_with_Nbh<I>& input,
const oln_point(I)& p)
{
@@ -88,7 +88,7 @@
template <typename F, typename I, typename W>
typename F::result
- local(const Accumulator<F>& f,
+ local_(const F& f,
const Image<I>& input,
const oln_point(I)& p,
const Window<W>& win)
@@ -106,12 +106,12 @@
/// Facades.
template <typename A, typename I>
- typename A::result
+ int//typename A::result
local(const Accumulator<A>& f,
const Image_with_Nbh<I>& input,
const oln_point( I )& p)
{
- return impl::local(f, input, p);
+ return impl::local_(exact(f), input, p);
}
template <typename F, typename I, typename W>
@@ -121,7 +121,7 @@
const oln_point(I)& p,
const Window<W>& win)
{
- return impl::local(f, input, p, win);
+ return impl::local_(exact(f), input, p, win);
}
#endif // ! OLN_INCLUDE_ONLY
Index: oln/core/concept/functions.hh
--- oln/core/concept/functions.hh (revision 884)
+++ oln/core/concept/functions.hh (working copy)
@@ -165,6 +165,11 @@
{
}
+ template <typename Exact>
+ Accumulator<Exact>::Accumulator()
+ {
+ }
+
# endif // OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/internal/op_image_plus_nbh.hh
--- oln/core/internal/op_image_plus_nbh.hh (revision 884)
+++ oln/core/internal/op_image_plus_nbh.hh (working copy)
@@ -97,6 +97,7 @@
const delegatee& impl_image() const;
nbh impl_nbhood() const;
+ nbh& impl_nbhood();
protected:
special_op_();
1
0
16 Mar '07
Roland Levillain wrote:
> Note: In order to avoid writing even more boring messages, I sometimes
> make remarks or ...
Thanks for all your advice ;)
1
0
884: Update : Norme, Sanity, apply of user functors. erosion not yet usable.
by Ugo Jardonnet 16 Mar '07
by Ugo Jardonnet 16 Mar '07
16 Mar '07
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Update : Norme, Sanity, apply of user functors. erosion not yet usable.
* oln/function/min.hh: .
* oln/level/apply.hh: .
* oln/level/local.hh: .
* oln/core/concept/functions.hh: .
* oln/core/internal/max_value.hh: .
* oln/morphomath/erosion.hh: .
core/internal/max_value.hh | 1
function/min.hh | 39 ++++++++---------
level/apply.hh | 71 ++++++++++---------------------
level/local.hh | 102 ++++++++++++++++++++++++++++++---------------
morphomath/erosion.hh | 27 +++++++----
5 files changed, 129 insertions(+), 111 deletions(-)
Index: oln/function/min.hh
--- oln/function/min.hh (revision 883)
+++ oln/function/min.hh (working copy)
@@ -1,5 +1,4 @@
-// Copyright (C) 2007 EPITA Research and
-// Development Laboratory
+// 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
@@ -26,32 +25,29 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_FUNCTION_MIN_HH_
-# define OLN_FUNCTION_MIN_HH_
+#ifndef _FUNCTION_MIN_HH
+# define _FUNCTION_MIN_HH
+
+#include <oln/core/concept/functions.hh>
+#include <oln/core/internal/max_value.hh>
+
namespace oln
{
- template <typename T>
- struct min_ : oln::Function< min_<T> >
+ namespace function
{
- typedef T argument;
- typedef void result;
- min_()
+ template <typename T>
+ struct min_ : public oln::Accumulator< min_<T> >
{
- init();
- }
+ typedef T argument;
+ typedef T result;
- void init()
- {
- val_ = oln_max_value(T);
- }
+ min_() { this->init(); }
- T value() const
- {
- return val_;
- }
+ void init() { val_ = oln_max(T); }
+ result value() const { return val_; }
template <typename U>
void operator()(U i) const
@@ -59,10 +55,13 @@
if (i < val_)
val_ = static_cast<T>(i);
}
+
private:
mutable T val_;
};
}
-#endif /* !OLN_FUNCTION_MIN_HH_ */
+}
+
+#endif // ! OLN_FUNCTION_MIN_HH
Index: oln/level/apply.hh
--- oln/level/apply.hh (revision 883)
+++ oln/level/apply.hh (working copy)
@@ -1,5 +1,5 @@
-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 EPITA Research and
-// Development Laboratory
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 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
@@ -30,7 +30,9 @@
# define OLN_LEVEL_APPLY_HH
# include <oln/core/concept/image.hh>
-
+# include <oln/core/concept/iterator.hh>
+# include <oln/core/internal/f_ch_value.hh>
+# include <oln/level/local.hh>
namespace oln
{
@@ -63,63 +65,37 @@
namespace impl
{
- template < typename F >
- struct result
- {
- typedef typename F::result ret;
- };
-
- template < typename R (*fun)(A) >
- struct result
- {
- typedef typename R ret;
- };
-
- template < typename F >
- struct argument
- {
- typedef typename F::argument ret;
- };
-
- template < typename R (*fun)(A) >
- struct argument
- {
- typedef typename A ret;
- };
-
-
- // APPLY //
- //---------
+ /// apply
template <typename F, typename I>
- oln_plain_value(I, result<typename F>::ret)
- apply(const F& fun, const Image<I>& input)
+ oln_plain_value(I, typename F::result)
+ apply( F& f, const Image<I>& input)
{
- typedef argument<typename F>::ret A;
- typedef result<typename F>::ret R;
+ typedef typename F::result result;
+ typedef typename F::argument argument;
- oln_ch_value(I, R) output(input.points());
+ oln_ch_value(I, result) output(input.points());
oln_piter(I) p(input.points());
for_all(p)
- output(p) = fun( static_cast<A>(input(p)) );
+ output(p) = f( static_cast< argument >(input(p)) );
return output;
}
- // APPLY_LOCAL //
- //---------------
+ /// apply_local
template <typename F, typename I>
- oln_plain_value(I, result<typename F>::ret)
- apply_local(const F& fun, const Image<I>& input)
+ oln_plain_value(I, typename F::result)
+ apply_local(const Accumulator<F>& fun,
+ const Image_with_Nbh<I>& input)
{
- typedef argument<typename F>::ret A;
- typedef result<typename F>::ret R;
+ typedef typename F::result result;
+ typedef typename F::argument argument;
- oln_ch_value(I, R) output(input.points());
+ oln_ch_value(I, argument) output(input.points());
oln_piter(I) p(input.points());
for_all(p)
- output(p) = local_apply(fun, input, p);
+ output(p) = local(fun, input, p);
return output;
}
@@ -173,9 +149,9 @@
template <typename F, typename I>
oln_plain_value(I, typename F::result)
- apply(const F& fun, const Image<I>& input)
+ apply(F& f, const Image<I>& input)
{
- return impl::apply(fun, exact(input));
+ return impl::apply(f, exact(input));
}
/// Apply local
@@ -189,7 +165,8 @@
template <typename F, typename I>
oln_plain_value(I, typename F::result)
- apply_local(const F& fun, const Image<I>& input)
+ apply_local(const Accumulator<F>& fun,
+ const Image_with_Nbh<I>& input)
{
return impl::apply_local(fun, exact(input));
}
Index: oln/level/local.hh
--- oln/level/local.hh (revision 883)
+++ oln/level/local.hh (working copy)
@@ -1,5 +1,4 @@
-// Copyright (C) 2007 EPITA Research and
-// Development Laboratory
+// 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
@@ -16,81 +15,118 @@
// 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 OLN_LEVEL_LOCAL_HH_
-# define OLN_LEVEL_LOCAL_HH_
+// 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 OLN_LEVEL_LOCAL_HH
+# define OLN_LEVEL_LOCAL_HH
+
+#include <oln/core/concept/image.hh>
+#include <oln/core/concept/point.hh>
+#include <oln/core/concept/functions.hh>
+#include <oln/core/concept/window.hh>
+#include <oln/core/concept/iterator.hh> // bizarre
+#include <oln/core/equipment.hh>
namespace oln
{
- namespace impl
+ namespace level
{
- // LOCAL APPLICATION ON NBH //
- //----------------------------
+ template <typename A, typename I>
+ typename A::result
+ local(const Accumulator<A>& f,
+ const Image_with_Nbh<I>& input,
+ const oln_point(I)& p);
+
+ template <typename F, typename I, typename W>
+ typename F::result
+ local(const Accumulator<F>& f,
+ const Image<I>& input,
+ const oln_point(I)& p,
+ const Window<W>& win);
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
/// Local Apply on neighborhood ( nbh included in image ).
- template <typename R, typename A, typename I>
+ template <typename A, typename I>
typename A::result
- local_apply(const Accumulator< A >& fun,
+ local(const Accumulator<A>& f,
const Image_with_Nbh< I >& input,
const oln_point( I )& p)
{
- fun.init();
+ f.init();
oln_niter(I) n(p, input.points());
for_all(n)
- fun(input(n));
- return fun.value();
+ f(input(n));
+ return f.value();
}
- /// Local Apply on neighborhood ( nhb has to be given ).
+ /// Local Apply on neighborhood (nhb given as argument).
// ...FIXME
- // LOCAL APPLICATION ON WINDOW //
- //-------------------------------
-
/// Local Apply on window ( window included in image).
// ...FIXME
-
/// Local Apply on window ( window is given ).
template <typename F, typename I, typename W>
typename F::result
- local_apply(const Accumulator<F>& fun,
+ local(const Accumulator<F>& f,
const Image<I>& input,
const oln_point(I)& p,
const Window<W>& win)
{
- fun.init();
+ f.init();
oln_qiter(W) q(p, win);
for_all(q)
- fun(input(q));
- return fun.value();
+ f(input(q));
+
+ return f.value();
}
}
/// Facades.
- local_apply( )
+ template <typename A, typename I>
+ typename A::result
+ local(const Accumulator<A>& f,
+ const Image_with_Nbh<I>& input,
+ const oln_point( I )& p)
{
+ return impl::local(f, input, p);
+ }
+ template <typename F, typename I, typename W>
+ typename F::result
+ local(const Accumulator<F>& f,
+ const Image<I>& input,
+ const oln_point(I)& p,
+ const Window<W>& win)
+ {
+ return impl::local(f, input, p, win);
}
+#endif // ! OLN_INCLUDE_ONLY
+
+ }
}
-#endif /* !OLN_LEVEL_LOCAL_HH_ */
+
+#endif // ! OLN_LEVEL_LOCAL_HH
Index: oln/core/concept/functions.hh
Index: oln/core/internal/max_value.hh
--- oln/core/internal/max_value.hh (revision 883)
+++ oln/core/internal/max_value.hh (working copy)
@@ -30,7 +30,6 @@
#include <cassert>
#include <limits>
-#include <iostream>
namespace oln
{
Index: oln/morphomath/erosion.hh
--- oln/morphomath/erosion.hh (revision 883)
+++ oln/morphomath/erosion.hh (working copy)
@@ -26,34 +26,41 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_MORPHOMATH_EROSION_HH_
-# define OLN_MORPHOMATH_EROSION_HH_
+#ifndef OLN_MORPHO_EROSION_HH
+# define OLN_MORPHO_EROSION_HH
-#include <oln/fonction/min.hh>
#include <oln/level/local.hh>
+#include <oln/function/min.hh>
namespace oln
{
+
+ namespace morpho
+ {
+
namespace impl
{
/// Generic version
- template <typename I, typename W>
- I erosion(const Image<I>& input)
+ template <typename I>
+ I erosion(Image_with_Nbh<I>& input)
{
- min_<oln_value(I)> min;
- return apply(min, input);
+ function::min_<oln_value(I)> min;
+
+ return ::oln::level::apply_local(min, input);
}
}
// Facade.
- template <typename I, typename W>
- I erosion(const Point_Wise_Accessible_Image<I>& input)
+ template <typename I>
+ I erosion(Image_with_Nbh<I>& input)
{
return impl::erosion(exact(input));
}
+
+ } // end of namespace
}
-#endif /* !OLN_MORPHOMATH_EROSION_HH_ */
+#endif // ! OLN_MORPHO_EROSION_HH
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/olena
This is only half of the work: I didn't add the new files (but the
build farm will tell us which are missing). :)
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
* oln/Makefile.am (nobase_oln_HEADERS): Remove obsolete files.
Makefile.am | 134 ------------------------------------------------------------
1 files changed, 134 deletions
Index: oln/Makefile.am
--- oln/Makefile.am (revision 882)
+++ oln/Makefile.am (working copy)
@@ -3,177 +3,43 @@
olndir = $(includedir)/oln
nobase_oln_HEADERS = \
\
- core/1d/aliases.hh \
core/1d/array1d.hh \
core/1d/dpoint1d.hh \
- core/1d/fwd_decls.hh \
core/1d/image1d.hh \
core/1d/neighb1d.hh \
core/1d/point1d.hh \
- core/1d/topo1d.hh \
core/1d/window1d.hh \
\
- core/2d/aliases.hh \
core/2d/array2d.hh \
core/2d/dpoint2d.hh \
- core/2d/fwd_decls.hh \
core/2d/image2d.hh \
core/2d/neighb2d.hh \
core/2d/point2d.hh \
- core/2d/topo2d.hh \
core/2d/window2d.hh \
\
- core/3d/aliases.hh \
core/3d/array3d.hh \
core/3d/dpoint3d.hh \
- core/3d/fwd_decls.hh \
core/3d/image3d.hh \
core/3d/neighb3d.hh \
core/3d/point3d.hh \
- core/3d/topo3d.hh \
core/3d/window3d.hh \
\
- core/abstract/image/bbox/hierarchy.hh \
- \
- core/abstract/image/computability/hierarchy.hh \
- \
- core/abstract/image/dimension/1d.hh \
- core/abstract/image/dimension/2d.hh \
- core/abstract/image/dimension/3d.hh \
- core/abstract/image/dimension/hierarchy.hh \
- \
- core/abstract/image/hybrid/classical.hh \
- \
- core/abstract/image/mutability/hierarchy.hh \
- \
- core/abstract/image/neighborhood/hierarchy.hh \
- \
- core/abstract/image/point_wise_accessibility/hierarchy.hh \
- \
- core/abstract/image/type/binary.hh \
- core/abstract/image/type/color.hh \
- core/abstract/image/type/data.hh \
- core/abstract/image/type/grey_level.hh \
- core/abstract/image/type/hierarchy.hh \
- core/abstract/image/type/integre.hh \
- core/abstract/image/type/label.hh \
- \
- core/abstract/image/value_wise_accessibility/hierarchy.hh \
- \
- core/abstract/image/all.hh \
- core/abstract/image/hierarchies.hh \
- \
- core/abstract/internal/image_impl.hh \
- \
- core/abstract/point_set/all.hh \
- core/abstract/point_set/hierarchies.hh \
- core/abstract/point_set/point_set_being_connected.hh \
- core/abstract/point_set/point_set_being_random_accessible.hh \
- core/abstract/point_set/point_set_having_bbox.hh \
- core/abstract/point_set/point_set_having_known_size.hh \
- \
- core/abstract/topology/all.hh \
- core/abstract/topology/hierarchies.hh \
- core/abstract/topology/topology_being_random_accessible.hh \
- core/abstract/topology/topology_having_bbox.hh \
- core/abstract/topology/topology_having_neighborhood.hh \
- core/abstract/topology/topology_having_subset.hh \
- \
- core/abstract/any.hh \
- core/abstract/array.hh \
- core/abstract/bbox.hh \
- core/abstract/dpoint.hh \
- core/abstract/entry.hh \
- core/abstract/functions.hh \
- core/abstract/fwd_decls.hh \
- core/abstract/grid.hh \
- core/abstract/image.hh \
- core/abstract/iterator.hh \
- core/abstract/iterator_on_points.hh \
- core/abstract/iterator_on_values.hh \
- core/abstract/neighborhood.hh \
- core/abstract/point.hh \
- core/abstract/point_set.hh \
- core/abstract/topology.hh \
- core/abstract/value.hh \
- core/abstract/window.hh \
- \
- core/automatic/image/image.hh \
- core/automatic/image/image1d.hh \
- core/automatic/image/image2d.hh \
- core/automatic/image/image3d.hh \
- core/automatic/image/mutable_image.hh \
- core/automatic/image/mutable_image1d.hh \
- core/automatic/image/mutable_image2d.hh \
- core/automatic/image/mutable_image3d.hh \
- core/automatic/image/image_being_point_wise_random_accessible.hh \
- core/automatic/image/image_being_value_wise_random_accessible.hh \
- core/automatic/image/image_having_neighborhood.hh \
- \
- core/automatic/topology/topology_being_random_accessible.hh \
- core/automatic/topology/topology_having_bbox.hh \
- core/automatic/topology/topology_having_neighborhood.hh \
- core/automatic/topology/topology_having_subset.hh \
- \
- core/automatic/impl.hh \
- \
- core/gen/bbox.hh \
- core/gen/bbox_bkd_piter.hh \
- core/gen/bbox_fwd_piter.hh \
- core/gen/bkd_niter_neighb.hh \
- core/gen/bkd_piter_bbox.hh \
- core/gen/bkd_qiter_win.hh \
core/gen/bkd_viter_lut.hh \
- core/gen/fwd_decls.hh \
- core/gen/fwd_niter_neighb.hh \
- core/gen/fwd_piter_bbox.hh \
- core/gen/fwd_qiter_win.hh \
core/gen/fwd_viter_lut.hh \
core/gen/piter_isubset.hh \
core/gen/piter_isubset.hh \
- core/gen/pset_.hh \
- core/gen/pset_list.hh \
- core/gen/pset_vec.hh \
- core/gen/grid.hh \
core/gen/mapimage.hh \
core/gen/neighb.hh \
- core/gen/piter_on_std_based_pset.hh \
core/gen/pw_value.hh \
- core/gen/topo_add_isubset.hh \
- core/gen/topo_add_nbh.hh \
- core/gen/topo_bbox.hh \
- core/gen/topo_lbbox.hh \
core/gen/window.hh \
\
- core/spe/col.hh \
- core/spe/row.hh \
- core/spe/slice.hh \
- \
- core/type_fun/ch_value.hh \
- core/type_fun/plain.hh \
- core/type_fun/slice.hh \
- \
- core/internal/bbox_bkd_piter.hh \
- core/internal/bbox_fwd_piter.hh \
core/internal/dpoint_nd.hh \
- core/internal/point_nd.hh \
- core/internal/topology_morpher.hh \
core/internal/tracked_ptr.hh \
\
- core/aliases.hh \
core/case.hh \
- core/fwd_decls.hh \
- core/image_entry.hh \
- core/iterator_vtypes.hh \
core/lookup_table.hh \
- core/macros.hh \
- core/neighborhood_entry.hh \
- core/point_set_entry.hh \
core/traits.hh \
core/traits_id.hh \
- core/topology_entry.hh \
- core/typedefs.hh \
- core/type.hh \
\
debug/print.hh \
debug/track.hh \
1
0
16 Mar '07
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Allow Olena to use the SCOOP Alternative implementation (back).
* oln/core/equipment.hh [OLENA_USE_SCOOP_ALT]: Include
stc/scoop-alt.hh and stc/scoop-alt.inc instead of
oln/stc/scoop.hh and oln/stc/scoop.hxx.
* oln/stc/scoop.hh (stc::is): Name the template parameter for a
better understanding.
core/equipment.hh | 8 ++++++++
stc/scoop.hh | 2 +-
2 files changed, 9 insertions(+), 1 deletion(-)
Index: oln/core/equipment.hh
--- oln/core/equipment.hh (revision 881)
+++ oln/core/equipment.hh (working copy)
@@ -29,7 +29,11 @@
# define OLN_CORE_EQUIPMENT_HH
# include <mlc/contract.hh>
+# ifndef OLENA_USE_SCOOP_ALT
# include <oln/stc/scoop.hh> // FIXME: Remove "oln/" later.
+# else
+# include <stc/scoop-alt.hh>
+# endif
# include <oln/core/init.hh>
# define oln_typename_shortcut__(Type, Alias) typename Type::Alias
@@ -39,7 +43,11 @@
namespace oln
{
+# ifndef OLENA_USE_SCOOP_ALT
# include <oln/stc/scoop.hxx> // FIXME: Remove "oln/" later.
+# else
+# include <stc/scoop-alt.inc>
+# endif
// b
stc_decl_associated_type( bkd_niter );
Index: oln/stc/scoop.hh
--- oln/stc/scoop.hh (revision 881)
+++ oln/stc/scoop.hh (working copy)
@@ -53,7 +53,7 @@
template <typename T>
struct final;
- template < template <class> class >
+ template < template <class> class category >
struct is;
typedef mlc::true_ true_;
1
0
Index: ChangeLog
from Nicolas Ballas <ballas(a)lrde.epita.fr>
New rle_encode function.
* oln/core/encode,
* oln/core/encode/rle_encode.hh: New
encode/rle_encode.hh | 81 ++++++++++++++++++++++++++++++++++++++
rle/rle_image.hh | 34 ++++++++++------
rle/rle_pset.hh | 108 ++++++++++++++++++++++++++++++++++++---------------
rle/rle_psite.hh | 29 +------------
4 files changed, 185 insertions(+), 67 deletions(-)
Index: oln/core/rle/rle_image.hh
--- oln/core/rle/rle_image.hh (revision 872)
+++ oln/core/rle/rle_image.hh (working copy)
@@ -67,7 +67,6 @@
typedef rle_psite<P> psite;
typedef rle_pset<point> pset;
-// typedef typename pset::box box;
typedef mlc::none plain;
@@ -75,7 +74,19 @@
};
- // Rle image class
+ /*
+ ** \class rle_image
+ ** \brief rle image (use a pair of point range and value as representation)
+ **
+ ** method:
+ ** pset impl_points() const : return image pset
+ ** box impl_bbox() const : return image bbox
+ ** bool impl_has(const point& p) const : rle_image has p?
+ ** bool impl_owns_(const psite& p) const : same has impl_has
+ ** void insert(const point& p, unsigned len, value val) : insert a new range on the image
+ ** rvalue impl_read(const psite& p) const : return value associated to psite (for reading)
+ ** lvalue impl_read_write(const psite& p) : lvalue impl_read_write(const psite& p) (for writing)
+ */
template < typename P, typename T>
class rle_image : public internal::primitive_image_< rle_image<P, T> >
{
@@ -136,7 +147,7 @@
bool
rle_image<P, T>::impl_owns_(const typename rle_image<P, T>::psite& p) const
{
- return this->data_->first.has(p);
+ return this->data_->first.has(p.start_);
}
template <typename P, typename T>
@@ -151,21 +162,22 @@
typename rle_image<P, T>::rvalue
rle_image<P, T>::impl_read(const rle_image<P, T>::psite& ps) const
{
- // precondition(p.iterator_() != this->data_->second.end());
- return this->data_->second[ps];
+ typename std::map<point, value>::const_iterator irun;
+
+ irun = this->data_->second.find(ps.start_);
+ assert(irun != this->data_->second.end() && ps.index_ < this->data_->first.range_len_(ps.start_));
+ return irun->second;
}
- int a = 5;
template <typename P, typename T>
typename rle_image<P, T>::lvalue
rle_image<P, T>::impl_read_write(const rle_image<P, T>::psite& ps)
{
- std::cout << "read_write: " << std::endl;
- std::cout << (point)ps << std::endl;
+ typename std::map<point, value>::iterator irun;
- // precondition(p.iterator_() != this->data_->second.end());
- //return this->data_->second[ps];
- return a;
+ irun = this->data_->second.find(ps.start_);
+ assert(irun != this->data_->second.end() && ps.index_ < this->data_->first.range_len_(ps.start_));
+ return irun->second;
}
# endif // !OLN_INCLUDE_ONLY
Index: oln/core/rle/rle_psite.hh
--- oln/core/rle/rle_psite.hh (revision 872)
+++ oln/core/rle/rle_psite.hh (working copy)
@@ -43,16 +43,16 @@
** \class rle_piste
** \brief psite for rle image
**
- **
- **
+ ** Note: P must be a point type
+ ** method:
+ ** to_point: convert the psite to corresponding point
+ ** operator P(): convert psite to the corresponding point
*/
template <typename P>
class rle_psite
{
public:
rle_psite();
- // template <typename T>
-// rle_psite(const rle_image<P, T>& ima, const P& p);
P to_point() const;
operator P () const;
@@ -68,27 +68,6 @@
{
}
-// template <typename P>
-// template <typename T>
-// rle_psite<P>::rle_psite(const rle_image<P, T>& ima, const P& p) : start_(p)
-// {
-// P pend;
-
-// typename rle_image<P, T>::piter it (ima.points());
-
-// for (it.start(); it.is_valid(); it.next())
-// {
-// pend = it;
-// pend[0] += it->second - 1;
-// if (*it >= p && p <= pend)
-// {
-// this->start_ = it->first;
-// this->index_ = it->second - this->start[0];
-// }
-// }
-// }
-
-
template <typename P>
P
rle_psite<P>::to_point() const
Index: oln/core/rle/rle_pset.hh
--- oln/core/rle/rle_pset.hh (revision 872)
+++ oln/core/rle/rle_pset.hh (working copy)
@@ -47,21 +47,38 @@
template <typename P> struct rle_pset_fwd_piter_;
template <typename P> struct rle_pset_bkd_piter_;
+ // Super type.
+ template <typename P>
+ struct super_trait_< rle_pset<P> >
+ {
+ typedef rle_pset<P> current;
+ typedef internal::point_set_base_<current> ret;
+ };
+
// Vtypes associated to rle_pset class
template <typename P>
struct vtypes< rle_pset<P> >
{
typedef P point;
- typedef typename P::grid grid;
-
- typedef box_<point> box;
typedef rle_pset_fwd_piter_<P> fwd_piter;
typedef rle_pset_bkd_piter_<P> bkd_piter;
- typedef fwd_piter piter;
};
// rle_pset class
+ /*
+ ** \class rle_pset
+ ** \brief pset correspoding to the rle_image class
+ **
+ ** Note: P must be a point type
+ ** method:
+ ** unsigned impl_npoints() const : return number of point in the point set
+ ** const box& impl_bbox() const : return a box which includes all poin into the set
+ ** void insert(const P& p, unsigned len): insert a new range on the point set
+ ** bool impl_has(const P& p) const : if p include in the set
+ ** const std_container& con() const : return the container of the point
+ **
+ */
template <typename P>
class rle_pset : public internal::point_set_base_<rle_pset <P> >
{
@@ -81,11 +98,11 @@
bool impl_has(const P& p) const;
const std_container& con() const;
- unsigned range_len_(const P& range_start);
+ unsigned range_len_(const P& range_len_) const;
protected:
- unsigned npts;
- std_container con_;
- fbbox_<point> fb_;
+ unsigned npts; /*!< number of point in the set*/
+ std_container con_; /*!< container of the set*/
+ fbbox_<point> fb_; /*!< pset box*/
};
@@ -133,18 +150,10 @@
bool
rle_pset<P>::impl_has(const P& p) const
{
- P pend;
+ typename std_container::const_iterator irun;
- typename std_container::const_iterator iter;
-
- for (iter = con_.begin(); iter != con_.end(); ++iter )
- {
- pend = iter->first;
- pend[0] += iter->second - 1;
- if (iter->first >= p && p <= pend)
- return 1;
- }
- return 0;
+ irun = this->con_.find(p);
+ return irun != this->con_.end();
}
template <typename P>
@@ -156,9 +165,13 @@
template <typename P>
unsigned
- rle_pset<P>::range_len_(const P& range_start)
+ rle_pset<P>::range_len_(const P& range_start) const
{
- return this->con_[range_start];
+ typename std_container::const_iterator irun;
+
+ irun = this->con_.find(range_start);
+ assert(irun != this->con_.end());
+ return (irun->second);
}
# endif // !OLN_INCLUDE_ONLY
@@ -166,11 +179,18 @@
// end of rle_pset class
// -------------------- iterators on classes deriving from internal::rle_pset<P>
-
// Forward declaration
template <typename P>
class rle_pset_fwd_piter_;
+ // Super type.
+ template <typename P>
+ struct super_trait_< rle_pset_fwd_piter_<P> >
+ {
+ typedef rle_pset_fwd_piter_<P> current;
+ typedef Iterator_on_Points<current> ret;
+ };
+
// Virtual types
template <typename P>
struct vtypes< rle_pset_fwd_piter_<P> >
@@ -179,6 +199,18 @@
};
// class rle_pset_fwd_iterator_
+ /*
+ ** \class rle_pset_fwd_piter_
+ ** \brief foward iterator for rle_pset
+ **
+ ** P must be a point type
+ ** method:
+ ** void impl_start(): set the iterator to the start of pset
+ ** void impl_next(): go to next point
+ ** void impl_invalidate(): invalidate iterator
+ ** void impl_valid(): is the iterator valid?
+ ** + conversions methods
+ */
template <typename P>
class rle_pset_fwd_piter_ : public Iterator_on_Points< rle_pset_fwd_piter_<P> >
{
@@ -203,7 +235,7 @@
protected:
const typename rle_pset<P>::std_container& con_;
typename rle_pset<P>::std_container::const_iterator it_;
- rle_psite<P> ps_;
+ rle_psite<P> ps_; /*!< current point */
};
# ifndef OLN_INCLUDE_ONLY
@@ -229,11 +261,8 @@
{
precondition(this->is_valid());
- std::cout << "next: " << std::endl;
- std::cout << "point start: " << ps_.start_ << " index: " << ps_.index_ << std::endl;
- std::cout << "point start: " << it_->first << " index: " << it_->second << " ref" << std::endl;
-
++this->ps_.index_;
+
if (this->ps_.index_ >= this->it_->second)
{
++it_;
@@ -291,6 +320,14 @@
template <typename P>
class rle_pset_bkd_piter_;
+ // Super type.
+ template <typename P>
+ struct super_trait_< rle_pset_bkd_piter_<P> >
+ {
+ typedef rle_pset_bkd_piter_<P> current;
+ typedef Iterator_on_Points<current> ret;
+ };
+
// Virtual type
template <typename P>
struct vtypes< rle_pset_bkd_piter_<P> >
@@ -298,8 +335,18 @@
typedef P point;
};
- // class rle_pset_bkd_piter_
-
+ /*
+ ** \class rle_pset_bkd_piter_
+ ** \brief backward iterator for rle_pset
+ **
+ ** P must be a point type
+ ** method:
+ ** void impl_start(): set the iterator to the start of pset
+ ** void impl_next(): go to next point
+ ** void impl_invalidate(): invalidate iterator
+ ** void impl_valid(): is the iterator valid?
+ ** + conversion method
+ */
template <typename P>
class rle_pset_bkd_piter_ : public Iterator_on_Points< rle_pset_bkd_piter_<P> >
{
@@ -322,7 +369,7 @@
protected:
const typename rle_pset<P>::std_container& con_;
typename rle_pset<P>::std_container::const_reverse_iterator it_;
- rle_psite<P> ps_;
+ rle_psite<P> ps_; /*!< current point*/
};
# ifndef OLN_INCLUDE_ONLY
@@ -350,7 +397,6 @@
--ps_.index_;
- // ps.index_ is unsigned
if (ps_.index_ + 1 == 0)
{
++it_;
Index: oln/core/encode/rle_encode.hh
--- oln/core/encode/rle_encode.hh (revision 0)
+++ oln/core/encode/rle_encode.hh (revision 0)
@@ -0,0 +1,81 @@
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 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 RLE_ENCODE_HH_
+# define RLE_ENCODE_HH_
+
+# include <oln/core/concept/image.hh>
+
+# include <oln/core/rle/rle_image.hh>
+
+namespace oln
+{
+
+ /*!
+ ** encode an image class to a rle_image
+ **
+ ** @param input has to respect the Image concept
+ **
+ ** @return rle_image
+ */
+ template <typename I>
+ rle_image<typename Image<I>::point, typename I::value>
+ rle_encode(const Image<I>& input)
+ {
+ rle_image<typename I::point, typename I::value> output;
+ typename I::piter p (input.points());
+ unsigned len = 1;
+ typename I::point rstart; /*!< range pointstart */
+ typename I::value rvalue; /*!< range value */
+
+ p.start();
+ if (!p.is_valid())
+ return output;
+
+ rstart = p;
+ rvalue = input(p);
+ p.next();
+ while (p.is_valid())
+ {
+ if (rvalue == input(p))
+ ++len;
+ else
+ {
+ output.insert(rstart, len, rvalue);
+ len = 1;
+ rstart = p;
+ rvalue = input(p);
+ }
+ p.next();
+ }
+ output.insert(rstart, len, rvalue);
+ return output;
+ }
+} // end of namespace oln
+
+#endif /* !RLE_ENCODE_HH_ */
2
1