URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-10 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
bug fix in image1d_b
* mln/core/image1d_b.hh: re-add array_ attribute in the image1d_b class
we actually need it to handle the border offset
=> array_ = buffer_ - vb_.pmin().ind();
)
* mln/debug/println.hh: update
* tests/debug_println_with_border.cc: add 1d test.
---
mln/core/image1d_b.hh | 21 +++++++++++++--------
mln/debug/println.hh | 5 ++---
tests/debug_println_with_border.cc | 30 +++++++++++++++++++++++++++++-
3 files changed, 44 insertions(+), 12 deletions(-)
Index: trunk/milena/tests/debug_println_with_border.cc
===================================================================
--- trunk/milena/tests/debug_println_with_border.cc (revision 1093)
+++ trunk/milena/tests/debug_println_with_border.cc (revision 1094)
@@ -31,6 +31,7 @@
*/
#include <mln/core/image2d_b.hh>
+#include <mln/core/image1d_b.hh>
#include <mln/level/fill.hh>
#include <mln/debug/println.hh>
@@ -41,7 +42,34 @@
int main()
{
border::thickness = 3;
+
+ {
image2d_b<bool> msk(3, 3);
- msk.at(1, 1) = true;
+ msk.at(0, 0) = true;
+ msk.at(1, 0) = true;
+ msk.at(2, 0) = true;
+
+ msk.at(0, 1) = true;
+ msk.at(1, 1) = false;
+ msk.at(2, 1) = true;
+
+ msk.at(0, 2) = true;
+ msk.at(1, 2) = true;
+ msk.at(2, 2) = true;
+
+ debug::println(msk);
debug::println_with_border(msk);
}
+
+ {
+ image1d_b<bool> msk(3);
+ msk.at(0) = false;
+ msk.at(1) = true;
+ msk.at(2) = false;
+
+ debug::println(msk);
+ debug::println_with_border(msk);
+
+ }
+
+}
Index: trunk/milena/mln/debug/println.hh
===================================================================
--- trunk/milena/mln/debug/println.hh (revision 1093)
+++ trunk/milena/mln/debug/println.hh (revision 1094)
@@ -71,9 +71,8 @@
void println_with_border(const S&, const Fast_Image<I>& input_)
{
const I& input = exact(input_);
- std::cout << input.ncells() << std::endl;
for (int i = 0; i < input.ncells(); i++)
- std::cout << input.buffer()[i] << ' ';
+ std::cout << format( input.buffer()[i] ) << ' ';
std::cout << std::endl;
}
@@ -105,7 +104,7 @@
const std::size_t ncols = b.ncols() + 2 * input.border();
for (size_t i = 0; i < input.ncells(); i++)
{
- std::cout << input.buffer()[i] << ' ';
+ std::cout << format( input.buffer()[i] ) << ' ';
if (((i+1) % ncols) == 0)
std::cout << std::endl;
}
Index: trunk/milena/mln/core/image1d_b.hh
===================================================================
--- trunk/milena/mln/core/image1d_b.hh (revision 1093)
+++ trunk/milena/mln/core/image1d_b.hh (revision 1094)
@@ -189,6 +189,7 @@
private:
T* buffer_;
+ T* array_;
box1d b_; // theoretical box
unsigned bdr_;
@@ -209,14 +210,16 @@
template <typename T>
image1d_b<T>::image1d_b()
- : buffer_(0)
+ : buffer_(0),
+ array_ (0)
{
bdr_ = border::thickness; // default value in ctors.
}
template <typename T>
image1d_b<T>::image1d_b(int ninds, unsigned bdr)
- : buffer_(0)
+ : buffer_(0),
+ array_ (0)
{
init_with(ninds, bdr);
}
@@ -233,7 +236,8 @@
template <typename T>
image1d_b<T>::image1d_b(const box1d& b, unsigned bdr)
- : buffer_(0)
+ : buffer_(0),
+ array_ (0)
{
init_with(b, bdr);
}
@@ -286,7 +290,7 @@
bool
image1d_b<T>::has_data() const
{
- return buffer_ != 0;
+ return buffer_ != 0 && array_ != 0;;
}
template <typename T>
@@ -333,7 +337,7 @@
image1d_b<T>::operator()(const point1d& p) const
{
mln_precondition(this->owns_(p));
- return buffer_[p.ind()];
+ return array_[p.ind()];
}
template <typename T>
@@ -341,7 +345,7 @@
image1d_b<T>::operator()(const point1d& p)
{
mln_precondition(this->owns_(p));
- return buffer_[p.ind()];
+ return array_[p.ind()];
}
template <typename T>
@@ -365,7 +369,7 @@
image1d_b<T>::at(int ind) const
{
mln_precondition(this->owns_(make::point1d(ind)));
- return buffer_[ind];
+ return array_[ind];
}
template <typename T>
@@ -373,7 +377,7 @@
image1d_b<T>::at(int ind)
{
mln_precondition(this->owns_(make::point1d(ind)));
- return buffer_[ind];
+ return array_[ind];
}
template <typename T>
@@ -436,6 +440,7 @@
unsigned
ni = vb_.len(0);
buffer_ = new T[ni];
+ array_ = buffer_ - vb_.pmin().ind();
mln_postcondition(vb_.len(0) == b_.len(0) + 2 * bdr_);
}