URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-11 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add border::resize and fix bug in println_with_border for 3d.
* border/resize.hh: Resize border.
* core/image1d.hh,
* core/image2d.hh,
* core/image3d.hh: Add reallocate for resize border.
* debug/println_with_border.hh: Fix bug.
---
border/resize.hh | 26 +++++++++++++++++--
core/image1d.hh | 53 ++++++++++++++++++++++++++++++++++++++++
core/image2d.hh | 56 +++++++++++++++++++++++++++++++++++++++++--
core/image3d.hh | 54 ++++++++++++++++++++++++++++++++++++++++-
debug/println_with_border.hh | 3 +-
5 files changed, 185 insertions(+), 7 deletions(-)
Index: trunk/milena/mln/debug/println_with_border.hh
===================================================================
--- trunk/milena/mln/debug/println_with_border.hh (revision 1309)
+++ trunk/milena/mln/debug/println_with_border.hh (revision 1310)
@@ -88,10 +88,11 @@
std::size_t len_s = b.len(P::dim - 3);
std::size_t len_r = b.len(P::dim - 2);
std::size_t len_c = b.len(P::dim - 1);
+
std::size_t border = input.border ();
std::size_t real_len_s = len_s + 2 * border;
- std::size_t real_len_r = len_r + 2 * border;
std::size_t real_len_c = len_c + 2 * border;
+ std::size_t real_len_r = len_r + 2 * border;
for (std::size_t k = 0; k < real_len_s; ++k)
{
Index: trunk/milena/mln/core/image1d.hh
===================================================================
--- trunk/milena/mln/core/image1d.hh (revision 1309)
+++ trunk/milena/mln/core/image1d.hh (revision 1310)
@@ -76,6 +76,8 @@
void update_vb_();
void allocate_();
void deallocate_();
+ void swap_ (data_< image1d<T> >& other_);
+ void reallocate_(unsigned new_border);
};
} // end of namespace mln::internal
@@ -205,6 +207,12 @@
/// Give a hook to the value buffer.
T* buffer();
+
+
+
+ /// Resize image border with new_border.
+ void resize_(unsigned new_border);
+
};
template <typename T, typename J>
@@ -281,6 +289,44 @@
}
}
+
+ template <typename T>
+ void
+ data_< image1d<T> >::swap_(data_< image1d<T> >& other_)
+ {
+
+ T* sw_buffer_ = this->buffer_;
+ this->buffer_ = other_.buffer_;
+ other_.buffer_ = sw_buffer_;
+
+ T* sw_array_ = this->array_;
+ this->array_ = other_.array_;
+ other_.array_ = sw_array_;
+
+ unsigned sw_bdr_ = this->bdr_;
+ this->bdr_ = other_.bdr_;
+ other_.bdr_ = sw_bdr_;
+
+ /// box1d vb_ virtual box, i.e., box including the virtual border
+ box1d sw_vb_ = this->vb_;
+ this->vb_ = other_.vb_;
+ other_.vb_ = sw_vb_;
+
+ /// box1d b_ theoretical box
+ box1d sw_b_ = this->b_;
+ this->b_ = other_.b_;
+ other_.b_ = sw_b_;
+
+ }
+
+ template <typename T>
+ void
+ data_< image1d<T> >::reallocate_(unsigned new_border)
+ {
+ data_< image1d<T> >& tmp = *(new data_< image1d<T>
>(this->b_, new_border));
+ this->swap_(tmp);
+ }
+
} // end of namespace mln::internal
@@ -434,6 +480,13 @@
return p;
}
+ template <typename T>
+ void
+ image1d<T>::resize_(unsigned new_border)
+ {
+ this->data_->reallocate_(new_border);
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
Index: trunk/milena/mln/core/image2d.hh
===================================================================
--- trunk/milena/mln/core/image2d.hh (revision 1309)
+++ trunk/milena/mln/core/image2d.hh (revision 1310)
@@ -59,7 +59,6 @@
namespace internal
{
-
template <typename T>
struct data_< image2d<T> >
{
@@ -76,6 +75,8 @@
void update_vb_();
void allocate_();
void deallocate_();
+ void swap_ (data_< image2d<T> >& other_);
+ void reallocate_(unsigned new_border);
};
} // end of namespace mln::internal
@@ -205,6 +206,13 @@
/// Give a hook to the value buffer.
T* buffer();
+
+
+
+
+ /// Resize image border with new_border.
+ void resize_(unsigned new_border);
+
};
@@ -244,7 +252,6 @@
namespace internal
{
-
template <typename T>
data_< image2d<T> >::data_(const box2d& b, unsigned bdr)
: buffer_(0),
@@ -307,6 +314,44 @@
}
}
+ template <typename T>
+ void
+ data_< image2d<T> >::swap_(data_< image2d<T> >& other_)
+ {
+
+ T* sw_buffer_ = this->buffer_;
+ this->buffer_ = other_.buffer_;
+ other_.buffer_ = sw_buffer_;
+
+ T** sw_array_ = this->array_;
+ this->array_ = other_.array_;
+ other_.array_ = sw_array_;
+
+ unsigned sw_bdr_ = this->bdr_;
+ this->bdr_ = other_.bdr_;
+ other_.bdr_ = sw_bdr_;
+
+ /// box2d vb_ virtual box, i.e., box including the virtual border
+ box2d sw_vb_ = this->vb_;
+ this->vb_ = other_.vb_;
+ other_.vb_ = sw_vb_;
+
+ /// box2d b_ theoretical box
+ box2d sw_b_ = this->b_;
+ this->b_ = other_.b_;
+ other_.b_ = sw_b_;
+
+ }
+
+ template <typename T>
+ void
+ data_< image2d<T> >::reallocate_(unsigned new_border)
+ {
+ data_< image2d<T> >& tmp = *(new data_< image2d<T>
>(this->b_, new_border));
+ this->swap_(tmp);
+ }
+
+
} // end of namespace mln::internal
@@ -460,6 +505,13 @@
return p;
}
+ template <typename T>
+ void
+ image2d<T>::resize_(unsigned new_border)
+ {
+ this->data_->reallocate_(new_border);
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
Index: trunk/milena/mln/core/image3d.hh
===================================================================
--- trunk/milena/mln/core/image3d.hh (revision 1309)
+++ trunk/milena/mln/core/image3d.hh (revision 1310)
@@ -76,7 +76,8 @@
void update_vb_();
void allocate_();
void deallocate_();
-
+ void swap_ (data_< image3d<T> >& other_);
+ void reallocate_(unsigned new_border);
};
} // end of namespace mln::internal
@@ -213,6 +214,12 @@
/// To use the track pointer inherited.
using super_::data_;
+
+
+
+ /// Resize image border with new_border.
+ void resize_(unsigned new_border);
+
};
template <typename T, typename J>
@@ -323,6 +330,44 @@
}
}
+ template <typename T>
+ void
+ data_< image3d<T> >::swap_(data_< image3d<T> >& other_)
+ {
+
+ T* sw_buffer_ = this->buffer_;
+ this->buffer_ = other_.buffer_;
+ other_.buffer_ = sw_buffer_;
+
+ T*** sw_array_ = this->array_;
+ this->array_ = other_.array_;
+ other_.array_ = sw_array_;
+
+ unsigned sw_bdr_ = this->bdr_;
+ this->bdr_ = other_.bdr_;
+ other_.bdr_ = sw_bdr_;
+
+ /// box3d vb_ virtual box, i.e., box including the virtual border
+ box3d sw_vb_ = this->vb_;
+ this->vb_ = other_.vb_;
+ other_.vb_ = sw_vb_;
+
+ /// box3d b_ theoretical box
+ box3d sw_b_ = this->b_;
+ this->b_ = other_.b_;
+ other_.b_ = sw_b_;
+
+ }
+
+ template <typename T>
+ void
+ data_< image3d<T> >::reallocate_(unsigned new_border)
+ {
+ data_< image3d<T> >& tmp = *(new data_< image3d<T>
>(this->b_, new_border));
+ this->swap_(tmp);
+ }
+
+
} // end of namespace mln::internal
// image3d<T>
@@ -476,6 +521,13 @@
return p;
}
+ template <typename T>
+ void
+ image3d<T>::resize_(unsigned new_border)
+ {
+ this->data_->reallocate_(new_border);
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
Index: trunk/milena/mln/border/resize.hh
===================================================================
--- trunk/milena/mln/border/resize.hh (revision 1309)
+++ trunk/milena/mln/border/resize.hh (revision 1310)
@@ -30,11 +30,15 @@
/*! \file mln/border/resize.hh
*
- * \brief FIXME.
+ * \brief Resize border.
*/
+# include <cstring>
+
# include <mln/core/concept/image.hh>
-# include <mln/core/internal/fixme.hh>
+# include <mln/core/image2d.hh>
+# include <mln/core/clone.hh>
+# include <mln/level/fill.hh>
namespace mln
@@ -62,6 +66,22 @@
# ifndef MLN_INCLUDE_ONLY
+ namespace impl
+ {
+ template <typename I>
+ void resize_(const Image<I>& ima_, unsigned new_border)
+ {
+ I& ima = const_cast<I&> (exact(ima_));
+ I src = clone(ima);
+
+ ima.resize_(new_border);
+ level::fill(ima, src);
+ }
+
+ } // end of namespace mln::border::resize
+
+ /// Facade.
+
template <typename I>
void resize(const Image<I>& ima_, unsigned thickness)
{
@@ -70,7 +90,7 @@
mln_precondition(ima.has_data());
if (ima.border() >= thickness)
return;
- mln::internal::fixme();
+ impl::resize_(ima, thickness);
mln_postcondition(ima.border() >= thickness);
return;
}