URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2008-03-21 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Debug tiled_image2d.
* sandbox/garrigues/tiled_image2d/block.hh: Remove the union, to use a
block with a value type of milena.
* sandbox/garrigues/tiled_image2d/layout/image2d/lrtb.hh: in a
milena's point2d, we have p[0] = row index, p[1] = col index, update
to respect this.
* sandbox/garrigues/tiled_image2d/layout/page2d/lrtb.hh: likewise,
(unsigned image2d_lrtb::size(unsigned nrows, unsigned ncols)) New.
* sandbox/garrigues/tiled_image2d/tiled_image2d.cc: Test the type with
a big image.
* sandbox/garrigues/tiled_image2d/tiled_image2d.hh: Allocate enough
space for the image. Fixme : some debug will be removed later.
---
block.hh | 13 +++++++++----
layout/image2d/lrtb.hh | 15 ++++++++++-----
layout/page2d/lrtb.hh | 2 +-
tiled_image2d.cc | 13 +++++++++++--
tiled_image2d.hh | 33 +++++++++++++++++++++++----------
5 files changed, 54 insertions(+), 22 deletions(-)
Index: trunk/milena/sandbox/garrigues/tiled_image2d/tiled_image2d.hh
===================================================================
--- trunk/milena/sandbox/garrigues/tiled_image2d/tiled_image2d.hh (revision 1794)
+++ trunk/milena/sandbox/garrigues/tiled_image2d/tiled_image2d.hh (revision 1795)
@@ -38,11 +38,14 @@
# include <mln/core/box2d.hh>
# include <mln/core/inplace.hh>
# include <mln/core/init.hh>
+# include <mln/core/line_piter.hh>
+
+# include <mln/geom/size2d.hh>
+
# include <mln/border/thickness.hh>
# include <mln/value/set.hh>
# include <mln/fun/i2v/all_to.hh>
-# include <mln/core/line_piter.hh>
# include <fcntl.h>
# include "support/lru.hh"
@@ -52,7 +55,8 @@
# include "page.hh"
// FIXME : give the side's side of the square of the block.
-# define SIDE 128
+# define BLOCK_SIDE 128
+# define BLOCK_SIZE (BLOCK_SIDE * BLOCK_SIDE)
namespace mln
{
@@ -68,10 +72,10 @@
template <typename T>
struct data_< tiled_image2d<T> >
{
- typedef block<T, SIDE * SIDE> block;
+ typedef block<T, BLOCK_SIZE> block;
typedef mmap_backend<block> backend;
typedef lru_support<backend> support;
- typedef layout2d<SIDE, SIDE> layout;
+ typedef layout2d<BLOCK_SIDE, BLOCK_SIDE> layout;
data_(const box2d& b);
~data_();
@@ -149,12 +153,12 @@
typedef mln::value::set<T> vset;
/// Block type.
- typedef block<T, SIDE * SIDE> block;
+ typedef block<T, BLOCK_SIZE> block;
/// Support type.
typedef lru_support<mmap_backend<block> > support;
/// Layout type
- typedef layout2d<SIDE, SIDE> layout;
+ typedef layout2d<BLOCK_SIDE, BLOCK_SIDE> layout;
/// Page type
typedef page<T, layout> page;
@@ -238,11 +242,20 @@
data_< tiled_image2d<T> >::data_(const box2d& b)
: b_ (b),
// FIXME : hard coded path.
- support_(*new support(*new backend( open("/tmp/milena_tiled.image", O_RDWR |
O_CREAT | O_TRUNC, 0664), b.npoints()) ))
- {
- std::cout << b.npoints() * sizeof(T) << std::endl;
+ support_(*new support(
+ *new backend( open("/tmp/milena_tiled.image", O_RDWR | O_CREAT |
O_TRUNC, 0664),
+ layout::image_layout::size(geom::nrows(b), geom::ncols(b))),
+ 1500 // Fixme : size of lru cache.
+ )
+ )
+ {
+ std::cout << layout::image_layout::size(geom::nrows(b), geom::ncols(b))
<< " block dans l'image." << std::endl;
+ std::cout << layout::image_layout::size(geom::nrows(b), geom::ncols(b)) *
BLOCK_SIZE * sizeof(T) << " o au total." << std::endl;
+ std::cout << layout::image_layout::size(geom::nrows(b), geom::ncols(b)) *
BLOCK_SIZE * sizeof(T) / 1024. << " Ko au total." << std::endl;
+ std::cout << layout::image_layout::size(geom::nrows(b), geom::ncols(b)) *
BLOCK_SIZE * sizeof(T) / (1024 * 1024.) << " Mo au total." <<
std::endl;
+
char a = 0;
- lseek(support_.backend_.fd_, b.npoints() * sizeof(T) - 1, SEEK_SET);
+ lseek(support_.backend_.fd_, layout::image_layout::size(geom::nrows(b),
geom::ncols(b)) * BLOCK_SIZE * sizeof(T), SEEK_SET);
write(support_.backend_.fd_, &a, 1);
}
Index: trunk/milena/sandbox/garrigues/tiled_image2d/block.hh
===================================================================
--- trunk/milena/sandbox/garrigues/tiled_image2d/block.hh (revision 1794)
+++ trunk/milena/sandbox/garrigues/tiled_image2d/block.hh (revision 1795)
@@ -37,20 +37,25 @@
struct block : public Object< block<T, size> > {
typedef T value_type;
enum { nitems = size, nbytes = size * sizeof(T) };
- union {
- char bytes[nbytes];
- T array[nitems];
- };
+
+ char bytes[nitems];
+
+// union {
+// char bytes[nbytes];
+// T array[nitems];
+// };
T& operator[](unsigned p)
{
assert(p < nitems);
+ T* array = (T*)(void*) bytes;
return array[p];
}
const T& operator[](unsigned p) const
{
assert(p < nbytes);
+ T* array = (T*)(void*) bytes;
return array[p];
}
};
Index: trunk/milena/sandbox/garrigues/tiled_image2d/tiled_image2d.cc
===================================================================
--- trunk/milena/sandbox/garrigues/tiled_image2d/tiled_image2d.cc (revision 1794)
+++ trunk/milena/sandbox/garrigues/tiled_image2d/tiled_image2d.cc (revision 1795)
@@ -32,14 +32,23 @@
#include "tiled_image2d.hh"
+#include <mln/core/cast_image.hh>
+
#include <mln/level/fill.hh>
+#include <mln/value/int_u8.hh>
#include <mln/debug/println.hh>
+#include <mln/debug/iota.hh>
+#include <mln/io/pgm/save.hh>
int main()
{
using namespace mln;
- tiled_image2d<int> ima(10700, 10700);
+ std::cout << "allocate the image." << std::endl;
+ tiled_image2d<value::int_u8> ima(1024 * 1024, 1024 * 1.5);
+ std::cout << "fill the image." << std::endl;
+ debug::iota(ima);
- level::fill(ima, 6);
+ std::cout << "save the image." << std::endl;
+ io::pgm::save(ima, "test.pgm");
}
Index: trunk/milena/sandbox/garrigues/tiled_image2d/layout/page2d/lrtb.hh
===================================================================
--- trunk/milena/sandbox/garrigues/tiled_image2d/layout/page2d/lrtb.hh (revision 1794)
+++ trunk/milena/sandbox/garrigues/tiled_image2d/layout/page2d/lrtb.hh (revision 1795)
@@ -41,7 +41,7 @@
static unsigned pixel_at(const point2d& p)
{
- return p[1] * width + p[0];
+ return p[0] * width + p[1];
}
};
Index: trunk/milena/sandbox/garrigues/tiled_image2d/layout/image2d/lrtb.hh
===================================================================
--- trunk/milena/sandbox/garrigues/tiled_image2d/layout/image2d/lrtb.hh (revision 1794)
+++ trunk/milena/sandbox/garrigues/tiled_image2d/layout/image2d/lrtb.hh (revision 1795)
@@ -36,30 +36,35 @@
namespace layout {
template<unsigned W, unsigned H>
- struct image2d_lrtb : public Object<image2d_lrtb<W, H> > {
+ struct image2d_lrtb {
enum { dim = 2, page_width = W, page_height = H };
template<typename Image>
static unsigned size(const Image& im) {
const typename Image::domain_type& d = im.domain();
- return (d.len(0) / page_width ) * (d.len(1) / page_height);
+ return (1 + d.len(0) / page_width ) * (1 + d.len(1) / page_height);
+ }
+
+
+ static unsigned size(unsigned nrows, unsigned ncols) {
+ return (1 + ncols / page_width ) * (1 + nrows / page_height);
}
template<typename Image>
static unsigned page_at(const Image& im, const point2d& p)
{
- return (p[1] / page_height) * (im.domain().len(0) / page_width) + p[0] / page_width;
+ unsigned n = (p[0] / page_height) * (1 + im.domain().len(1) / page_width) + (p[1] /
page_width);
+ return n;
};
static point2d changeref(const point2d& p)
{
- return point2d(p[0] % page_width, p[1] % page_height);
+ return point2d(p[0] % page_height, p[1] % page_width);
}
};
}
-
} // end of namespace mln
#endif