https://svn.lrde.epita.fr/svn/oln/prototypes/proto-1.0
ChangeLog | 37 +++++++++++++++
oln/core/1d/array1d.hh | 52 +++++++++++++++++++---
oln/core/1d/image1d.hh | 2
oln/core/2d/array2d.hh | 3 -
oln/core/3d/array3d.hh | 91 ++++++++++++++++++++++++++++++---------
oln/core/3d/image3d.hh | 2
tests/core/tests/fwd_witer2d | 1
tests/core/tests/piter1d | 21 +++++++--
tests/core/tests/piter2d | 6 +-
tests/core/tests/piter3d | 21 +++++++--
tests/core/tests/readwrite_image | 5 --
11 files changed, 198 insertions(+), 43 deletions(-)
Index: olena/ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Fix some 1D and 3D classes and have more tests pass.
* oln/basics1d.hh (oln/core/1d/fwd_piter1d.hh)
(oln/core/1d/bkd_piter1d.hh): Include them.
* oln/core/1d/image1d.hh (bkd_piter_type) New typedef.
* oln/core/1d/array1d.hh: Do not set exact_ptr, since this class
not longer inherits from mlc::any__best_speed, but from mlc::any.
* oln/core/1d/array1d.hh (alloc_and_init): New function.
(resize, impl_clear_data): Handle the border.
(size): Rename method as...
(impl_size): ...this.
(~array1d): Call clear_data() instead of impl_clear_data().
(impl_resize_border): New method.
* oln/core/2d/array2d.hh (alloc_and_init): Remove useless
assignment.
(~array2d): Call clear_data() instead of impl_clear_data().
* oln/basics3d.hh (oln/core/3d/fwd_piter3d.hh)
* oln/core/3d/image3d.hh (bkd_piter_type) New typedef.
* oln/core/3d/array3d.hh: Do not set exact_ptr, since this class
(oln/core/3d/bkd_piter3d.hh): Include them.
not longer inherits from mlc::any__best_speed, but from mlc::any.
(size): Rename method as...
(impl_size): ...this.
(~array3d): Call clear_data() instead of impl_clear_data().
(impl_resize): Move allocation code...
(alloc_and_init): ...here (new function).
(impl_resize_border): New method.
* tests/core/tests/readwrite_image: Catch up with the new property
system.
* tests/core/tests/piter1d (check): Test bkd_piter1d too.
* tests/core/tests/piter3d (check): Test bkd_piter3d too.
Index: olena/tests/core/tests/fwd_witer2d
--- olena/tests/core/tests/fwd_witer2d (revision 147)
+++ olena/tests/core/tests/fwd_witer2d (working copy)
@@ -1,3 +1,4 @@
+ // -*- C++ -*-
#include <oln/core/2d/fwd_witer2d.hh>
#include <oln/core/abstract/piter.hh>
Index: olena/tests/core/tests/readwrite_image
--- olena/tests/core/tests/readwrite_image (revision 147)
+++ olena/tests/core/tests/readwrite_image (working copy)
@@ -1,3 +1,4 @@
+ // -*- C++ -*-
#include <iostream>
#include <ntg/all.hh>
@@ -19,12 +20,10 @@
};
template <>
- struct set_props <category::image, dummy_image> :
- public props_of < category::image >
+ struct set_props <category::image, dummy_image>
{
typedef is_a<abstract::readwrite_image> image_constness;
typedef is_a<abstract::image2d> image_dimension_type;
- typedef vectorialness_from_valuetype_(ntg::int_u8) image_vectorialness_type;
typedef size2d size_type;
typedef point2d point_type;
Index: olena/tests/core/tests/piter1d
--- olena/tests/core/tests/piter1d (revision 147)
+++ olena/tests/core/tests/piter1d (working copy)
@@ -1,4 +1,4 @@
-
+ // -*- C++ -*-
#include <iostream>
#include <ntg/all.hh>
@@ -15,15 +15,28 @@
oln::image1d<int> ima(10);
int cpt = 0;
- oln::fwd_piter1d it(ima.size());
- for_all (it)
+ oln::fwd_piter1d fwd_it(ima.size());
+ for_all_p (fwd_it)
+ {
+ ima[fwd_it] = 0;
+ cpt++;
+ }
+
+ if (cpt != 10)
+ return true;
+
+
+ cpt = 0;
+ oln::bkd_piter1d bkd_it(ima.size());
+ for_all_p (bkd_it)
{
- ima[it] = 0;
+ ima[bkd_it] = 0;
cpt++;
}
if (cpt != 10)
return true;
+
return false;
}
Index: olena/tests/core/tests/piter2d
--- olena/tests/core/tests/piter2d (revision 147)
+++ olena/tests/core/tests/piter2d (working copy)
@@ -1,4 +1,4 @@
-
+ // -*- C++ -*-
#include <iostream>
#include <ntg/all.hh>
@@ -16,7 +16,7 @@
int cpt = 0;
oln::fwd_piter2d fwd_it(ima.size());
- for_all (fwd_it)
+ for_all_p (fwd_it)
{
ima[fwd_it] = 0;
cpt++;
@@ -28,7 +28,7 @@
cpt = 0;
oln::bkd_piter2d bkd_it(ima.size());
- for_all (bkd_it)
+ for_all_p (bkd_it)
{
ima[bkd_it] = 0;
cpt++;
Index: olena/tests/core/tests/piter3d
--- olena/tests/core/tests/piter3d (revision 147)
+++ olena/tests/core/tests/piter3d (working copy)
@@ -1,4 +1,4 @@
-
+ // -*- C++ -*-
#include <iostream>
#include <ntg/all.hh>
@@ -15,15 +15,28 @@
oln::image3d<int> ima(10, 10, 10);
int cpt = 0;
- oln::fwd_piter3d it(ima.size());
- for_all (it)
+ oln::fwd_piter3d fwd_it(ima.size());
+ for_all_p (fwd_it)
+ {
+ ima[fwd_it] = 0;
+ cpt++;
+ }
+
+ if (cpt != 1000)
+ return true;
+
+
+ cpt = 0;
+ oln::bkd_piter3d bkd_it(ima.size());
+ for_all_p (bkd_it)
{
- ima[it] = 0;
+ ima[bkd_it] = 0;
cpt++;
}
if (cpt != 1000)
return true;
+
return false;
}
Index: olena/oln/core/1d/array1d.hh
--- olena/oln/core/1d/array1d.hh (revision 147)
+++ olena/oln/core/1d/array1d.hh (working copy)
@@ -52,6 +52,14 @@
};
+ template<class T>
+ void alloc_and_init(T*& buffer, const size1d& s)
+ {
+ size_t nelts_eff = s.nindices() + 2 * s.border();
+ buffer = new T[nelts_eff];
+ buffer += s.border();
+ }
+
template <typename T>
class array1d : public abstract::data_storage< array1d<T> >
@@ -63,7 +71,6 @@
buffer_(0),
size_()
{
- this->exact_ptr = this;
invariant_();
}
@@ -76,13 +83,12 @@
buffer_(0),
size_()
{
- this->exact_ptr = this;
this->resize(s);
}
~array1d()
{
- this->impl_clear_data();
+ this->clear_data();
}
bool impl_has_data() const
@@ -97,6 +103,7 @@
if (this->has_data())
{
// buffer
+ buffer_ -= size_.border();
delete[] buffer_;
buffer_ = 0;
// size
@@ -105,7 +112,7 @@
invariant_();
}
- const size1d& size() const
+ const size1d& impl_size() const
{
return size_;
}
@@ -117,8 +124,41 @@
invariant_();
this->clear_data();
size_ = s;
- size_t nelts_eff = size_.nindices() + 2 * size_.border();
- buffer_ = new T[nelts_eff];
+
+ alloc_and_init(buffer_, s);
+ invariant_();
+ }
+
+ void impl_resize_border(size_t new_border, bool copy_border)
+ {
+ invariant_();
+ T* new_buffer_;
+ size1d new_size_(this->size_.nindices(), new_border);
+
+ alloc_and_init(new_buffer_, new_size_);
+
+ if (buffer_ != 0)
+ {
+ size_t border = this->size_.border();
+
+ if (border > new_border)
+ border = new_border;
+
+ coord_t indice_min = copy_border ? -border : 0;
+ coord_t indice_max = int(this->size_.nindices())
+ + (copy_border ? border : 0);
+ size_t nindices = int(this->size_.nindices()) +
+ (copy_border ? (border * 2) : 0);
+
+ memcpy(new_buffer_ + indice_min, this->buffer_ + indice_min,
+ nindices * sizeof (T));
+
+ this->clear_data();
+ }
+
+ buffer_ = new_buffer_;
+ size_ = new_size_;
+
invariant_();
}
Index: olena/oln/core/1d/image1d.hh
--- olena/oln/core/1d/image1d.hh (revision 147)
+++ olena/oln/core/1d/image1d.hh (working copy)
@@ -41,6 +41,7 @@
// fwd decls
struct fwd_piter1d;
+ struct bkd_piter1d;
template <typename T> class image1d;
// super type
@@ -63,6 +64,7 @@
typedef fwd_piter1d piter_type;
typedef fwd_piter1d fwd_piter_type;
+ typedef bkd_piter1d bkd_piter_type;
// please note that value_storage_type means data_type
// since image1d is an image_with_data
Index: olena/oln/core/2d/array2d.hh
--- olena/oln/core/2d/array2d.hh (revision 147)
+++ olena/oln/core/2d/array2d.hh (working copy)
@@ -58,7 +58,6 @@
buffer = new T[nelts_eff];
array = new T*[nrows_eff];
- buffer = buffer;
T* buf = buffer + s.border();
for (size_t row = 0; row < nrows_eff; ++row)
{
@@ -97,7 +96,7 @@
~array2d()
{
- this->impl_clear_data();
+ this->clear_data();
}
bool impl_has_data() const
Index: olena/oln/core/3d/array3d.hh
--- olena/oln/core/3d/array3d.hh (revision 147)
+++ olena/oln/core/3d/array3d.hh (working copy)
@@ -53,6 +53,32 @@
};
+ template<class T>
+ void alloc_and_init(T*& buffer, T***& array, T**& array2, const size3d&
s)
+ {
+ size_t nslices_eff = s.nslices() + 2 * s.border();
+ size_t nrows_eff = s.nrows() + 2 * s.border();
+ size_t ncols_eff = s.ncols() + 2 * s.border();
+ size_t nelts_eff = nslices_eff * nrows_eff * ncols_eff;
+
+ buffer = new T[nelts_eff];
+ array = new T**[nslices_eff];
+ array2 = new T*[nslices_eff * nrows_eff];
+
+ T* buf = buffer + s.border();
+ for (size_t slice = 0; slice < nslices_eff; ++slice)
+ {
+ T** a2 = array2 + slice * nrows_eff;
+ array[slice] = a2 + s.border();
+ for (size_t row = 0; row < nrows_eff; ++row)
+ {
+ a2[row] = buf;
+ buf += ncols_eff;
+ }
+ }
+ array += s.border();
+ }
+
template <typename T>
class array3d : public abstract::data_storage< array3d<T> >
{
@@ -65,7 +91,6 @@
array2_(0),
size_()
{
- this->exact_ptr = this;
invariant_();
}
@@ -80,13 +105,12 @@
array2_(0),
size_()
{
- this->exact_ptr = this;
this->resize(s);
}
~array3d()
{
- this->impl_clear_data();
+ this->clear_data();
}
bool impl_has_data() const
@@ -116,7 +140,7 @@
invariant_();
}
- const size3d& size() const
+ const size3d& impl_size() const
{
return size_;
}
@@ -131,27 +155,52 @@
this->clear_data();
size_ = s;
- size_t nslices_eff = size_.nslices() + 2 * size_.border();
- size_t nrows_eff = size_.nrows() + 2 * size_.border();
- size_t ncols_eff = size_.ncols() + 2 * size_.border();
- size_t nelts_eff = nslices_eff * nrows_eff * ncols_eff;
-
- buffer_ = new T[nelts_eff];
- array_ = new T**[nslices_eff];
- array2_ = new T*[nslices_eff * nrows_eff];
+ alloc_and_init(buffer_, array_, array2_, s);
+ invariant_();
+ }
- T* buf = buffer_ + size_.border();
- for (size_t slice = 0; slice < nslices_eff; ++slice)
+ void impl_resize_border(size_t new_border, bool copy_border)
{
- T** a2 = array2_ + slice * nrows_eff;
- array_[slice] = a2 + size_.border();
- for (size_t row = 0; row < nrows_eff; ++row)
+ invariant_();
+ T* new_buffer_;
+ T*** new_array_;
+ T** new_array2_;
+ size3d new_size_(this->size_.nslices(), this->size_.nrows(),
+ this->size_.ncols(), new_border);
+
+ alloc_and_init(new_buffer_, new_array_, new_array2_, new_size_);
+
+ if (buffer_ != 0)
{
- a2[row] = buf;
- buf += ncols_eff;
- }
+ size_t border = this->size_.border();
+
+ if (border > new_border)
+ border = new_border;
+
+ coord_t slice_min = copy_border ? -border : 0;
+ coord_t slice_max = int(this->size_.nslices())
+ + (copy_border ? border : 0);
+ coord_t row_min = copy_border ? -border : 0;
+ coord_t row_max = int(this->size_.nrows())
+ + (copy_border ? border : 0);
+ coord_t col_min = copy_border ? -border : 0;
+ size_t ncols = int(this->size_.ncols()) +
+ (copy_border ? (border * 2) : 0);
+
+ for (coord_t slice = slice_min; slice < slice_max; ++slice)
+ for (coord_t row = row_min; row < row_max; ++row)
+ memcpy(new_array_[slice][row] + col_min,
+ this->array_[slice][row] + col_min,
+ ncols * sizeof (T));
+
+ this->clear_data();
}
- array_ += size_.border();
+
+ buffer_ = new_buffer_;
+ array_ = new_array_;
+ array2_ = new_array2_;
+ size_ = new_size_;
+
invariant_();
}
Index: olena/oln/core/3d/image3d.hh
--- olena/oln/core/3d/image3d.hh (revision 147)
+++ olena/oln/core/3d/image3d.hh (working copy)
@@ -44,6 +44,7 @@
// fwd decls
struct fwd_piter3d;
+ struct bkd_piter3d;
template <typename T> class image3d;
// super
@@ -66,6 +67,7 @@
typedef fwd_piter3d piter_type;
typedef fwd_piter3d fwd_piter_type;
+ typedef bkd_piter3d bkd_piter_type;
// please note that value_storage_type means data_type
// since image3d is an image_with_data