Index: ChangeLog
from Simon Odou <simon(a)lrde.epita.fr>
* tests/core/tests/image1d: New.
* oln/fancy/print.hh: Add print for image1d.
* oln/fancy/iota.hh: Add iota for image1d.
* oln/basics1d.hh: Add image1d include.
* oln/core/2d/image2d.hh: Move the has_data method to...
* oln/core/abstract/image_with_data.hh: here.
* oln/core/1d/image1d.hh: New.
* oln/core/1d/size1d.hh: Fix a forgotten initialization in
constructor.
ChangeLog | 15 -----
oln/basics1d.hh | 1
oln/core/1d/image1d.hh | 101 +++++++++++++++++++++++++++++++++++
oln/core/1d/size1d.hh | 3 -
oln/core/2d/image2d.hh | 5 -
oln/core/abstract/image_with_data.hh | 10 +++
oln/fancy/iota.hh | 21 ++++++-
oln/fancy/print.hh | 14 ++++
tests/core/tests/image1d | 40 +++++++++++++
9 files changed, 186 insertions(+), 24 deletions(-)
Index: tests/core/tests/image1d
--- tests/core/tests/image1d (revision 0)
+++ tests/core/tests/image1d (revision 0)
@@ -0,0 +1,40 @@
+
+#include <iostream>
+
+#include <ntg/real/int_u8.hh>
+#include <oln/basics1d.hh>
+
+#include <oln/fancy/iota.hh>
+#include <oln/fancy/print.hh>
+
+#include "check.hh"
+#include "data.hh"
+
+
+
+template <typename I>
+void foo(oln::abstract::image<I>& input, const oln_point_type(I)& p)
+{
+ // FIXME: dummy code below
+// struct dummy {};
+// oln_typeof(I,value) tmp = (dummy*)0;
+ input[p] = 7;
+}
+
+
+bool check()
+{
+ oln::point1d p(0);
+
+ typedef oln::image1d<ntg::int_u8> image_type;
+ image_type ima(3);
+ oln::fancy::iota(ima);
+ oln::fancy::println(ima);
+
+ image_type ima2;
+ ima2 = ima;
+
+ foo(ima, p);
+ oln::fancy::println(ima2);
+ return false;
+}
Index: oln/fancy/print.hh
--- oln/fancy/print.hh (revision 12)
+++ oln/fancy/print.hh (working copy)
@@ -8,6 +8,7 @@
# include <ntg/real/int_u8.hh> // FIXME: no coupling like that!
+# include <oln/core/1d/image1d.hh>
# include <oln/core/2d/image2d.hh>
namespace oln {
@@ -21,6 +22,8 @@
namespace impl {
template <typename T>
+ void print(const image1d<T>& input, std::ostream& ostr);
+ template <typename T>
void print(const image2d<T>& input, std::ostream& ostr);
// FIXME: it should be abstract::image2d<I>...
@@ -79,6 +82,17 @@
}
}
+ template <typename T>
+ void print(const image1d<T>& input, std::ostream& ostr)
+ {
+ // FIXME: lacks cleaning
+ for (coord_t index = 0; index < input.size().nindices(); ++index)
+ {
+ ostr << internal::pp<T>(input[point1d(index)]) << ' ';
+ }
+ ostr << std::endl;
+ }
+
} // end of namespace impl
Index: oln/fancy/iota.hh
--- oln/fancy/iota.hh (revision 12)
+++ oln/fancy/iota.hh (working copy)
@@ -2,6 +2,7 @@
# define OLENA_FANCY_IOTA_HH
# include <oln/core/2d/image2d.hh>
+# include <oln/core/1d/image1d.hh>
namespace oln {
@@ -9,7 +10,10 @@
namespace impl {
- template <typename T> void iota(image2d<T>& inout); // FIXME:
abstract::image2d<I>...
+ template <typename T>
+ void iota(image1d<T>& inout); // FIXME: abstract::image1d<I>...
+ template <typename T>
+ void iota(image2d<T>& inout); // FIXME: abstract::image2d<I>...
} // end of namespace impl
@@ -28,15 +32,28 @@
namespace impl {
+ // FIXME: must be generic, of course ! But for now, we have not yet
+ // iterators and we just want to test.
+
template <typename T>
void iota(image2d<T>& inout)
{
unsigned counter = 0;
- for (coord_t row = 0; row < inout.size().nrows(); ++row) // FIXME: lacks cleaning
+ // FIXME: lacks cleaning
+ for (coord_t row = 0; row < inout.size().nrows(); ++row)
for (coord_t col = 0; col < inout.size().ncols(); ++col)
inout[point2d(row,col)] = ++counter;
}
+ template <typename T>
+ void iota(image1d<T>& inout)
+ {
+ unsigned counter = 0;
+ // FIXME: lacks cleaning
+ for (coord_t index = 0; index < inout.size().nindices(); ++index)
+ inout[point1d(index)] = ++counter;
+ }
+
} // end of namespace impl
Index: oln/basics1d.hh
--- oln/basics1d.hh (revision 12)
+++ oln/basics1d.hh (working copy)
@@ -6,5 +6,6 @@
# include <oln/core/1d/size1d.hh>
# include <oln/core/1d/point1d.hh>
+# include <oln/core/1d/image1d.hh>
#endif // ! OLENA_BASICS1D_HH
Index: oln/core/abstract/image_with_data.hh
--- oln/core/abstract/image_with_data.hh (revision 12)
+++ oln/core/abstract/image_with_data.hh (working copy)
@@ -97,6 +97,14 @@
return this->data_->set(p, v);
}
+ /*! \brief True if the image contains data.
+ */
+ bool has_data() const
+ {
+ return data_ != 0;
+ }
+
+
protected:
/*! \brief Constructor (protected) with no memory allocation for
@@ -107,6 +115,7 @@
data_ = 0;
}
+
/*! \brief Constructor (protected) with memory allocation for
** data.
*/
@@ -123,7 +132,6 @@
this->data_ = rhs.data_;
}
-
/*! \brief Data storage.
*/
mlc::tracked_ptr<oln_value_container_type(E)> data_;
Index: oln/core/1d/image1d.hh
--- oln/core/1d/image1d.hh (revision 0)
+++ oln/core/1d/image1d.hh (revision 0)
@@ -0,0 +1,101 @@
+#ifndef OLENA_CORE_IMAGE1D_HH
+# define OLENA_CORE_IMAGE1D_HH
+
+# include <mlc/traits.hh>
+
+# include <oln/core/abstract/image_with_data.hh>
+# include <oln/core/1d/array1d.hh>
+
+/*! \namespace oln
+** \brief oln namespace.
+*/
+namespace oln {
+
+
+ // fwd decl
+ template <typename T> class image1d;
+
+ // category decl
+ template <typename T> struct category_type< image1d<T> > { typedef
cat::image ret; };
+
+
+ /*! \class props< abstract::image, image1d<T> >
+ **
+ ** Properties of common 1D images. Specialization of props<abstraction,type>.
+ ** Parameter T is the type of pixel values.
+ **
+ ** \see image1d<T>, props<category,type>
+ */
+
+ template <typename T>
+ struct props < cat::image, image1d<T> > : public default_props <
cat::image >
+ {
+ typedef mlc::no_type delegated_type;
+
+ typedef size1d size_type;
+ typedef point1d point_type;
+ typedef T value_type;
+
+ // please note that value_storage_type means data_type
+ // since image1d is an image_with_data
+ typedef mlc_encoding_type(T) value_storage_type;
+
+ // please note that value_container_type means
+ // data_container_type (or value_storage_container_type)
+ // FIXME: find a better name...
+ typedef array1d<value_storage_type> value_container_type;
+
+ // tags
+ typedef tag::readwrite constness_tag;
+
+ // functions
+
+ template <typename U>
+ struct ch_value_type
+ {
+ typedef image1d<U> ret;
+ };
+
+ };
+
+
+
+ /*! \class image1d<T>
+ **
+ ** Common class for 1D images. Pixels values are stored in memory.
+ ** FIXME: give details about other properties (border, etc.)
+ **
+ ** Parameter T is the type of pixel values.
+ */
+
+ template <typename T>
+ class image1d : public abstract::image_with_data< image1d<T> >
+ {
+ public:
+
+ typedef abstract::image_with_data< image1d<T> > super_type;
+
+ image1d()
+ {
+ this->exact_ptr = this;
+ }
+
+ image1d(coord_t nindices) :
+ super_type(size1d(nindices))
+ {
+ this->exact_ptr = this;
+ }
+
+ image1d(image1d& rhs) :
+ super_type(rhs)
+ {
+ this->exact_ptr = this;
+ }
+
+ };
+
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_CORE_IMAGE1D_HH
Index: oln/core/1d/size1d.hh
--- oln/core/1d/size1d.hh (revision 12)
+++ oln/core/1d/size1d.hh (working copy)
@@ -12,7 +12,8 @@
struct size1d : public abstract::size< size1d >
{
size1d() :
- nindices_(0)
+ nindices_(0),
+ border_(0)
{}
size1d(coord_t nindices_) :
Index: oln/core/2d/image2d.hh
--- oln/core/2d/image2d.hh (revision 12)
+++ oln/core/2d/image2d.hh (working copy)
@@ -109,11 +109,6 @@
// FIXME: idem with abstract::image2d<E> (?)
- bool has_data() const // FIXME: should be defined in abstract::something_image...
- {
- return this->data_ != 0;
- }
-
};