hop :
---
:from: Thierry Geraud <theo(a)lrde.epita.fr>
:server:
:subject: "proto-1.0 98: Use oln::box"
:groups:
- lrde.olena.patches
---
Index: ChangeLog
from Thierry Geraud <theo(a)lrde.epita.fr>
* oln/core/box.hh: New.
* oln/core/abstract/image.hh
(resize_border): Temporary method to pass make check.
* oln/core/abstract/image_with_data.hh: Update.
* oln/core/abstract/op.hh: Likewise.
* oln/utils/clone.hh: Likewise.
* oln/basics.hh: Likewise.
* oln/morpho/dilation.hh: Likewise.
* oln/morpho/erosion.hh: Likewise.
* oln/arith/min.hh: Likewise.
* oln/arith/max.hh: Likewise.
* oln/morpho/stat.hh: Add test (hold) to pass make check.
arith/max.hh | 14 +-
arith/min.hh | 14 +-
basics.hh | 2
core/abstract/image.hh | 17 ++-
core/abstract/image_with_data.hh | 2
core/abstract/op.hh | 1
core/box.hh | 212 +++++++++++++++++++++++++++++++++++++++
morpho/dilation.hh | 15 +-
morpho/erosion.hh | 18 ++-
morpho/stat.hh | 20 ++-
utils/clone.hh | 18 +--
11 files changed, 288 insertions(+), 45 deletions(-)
Index: oln/core/abstract/image.hh
--- oln/core/abstract/image.hh (revision 97)
+++ oln/core/abstract/image.hh (working copy)
@@ -303,6 +303,14 @@
return this->exact().impl_get(p);
}
+
+ // FIXME: patch!
+
+ void resize_border(size_t new_border, bool copy_border = false) const
+ {
+ this->exact().impl_resize_border(new_border, copy_border);
+ }
+
protected:
/*! \brief Constructor (protected, empty).
@@ -382,9 +390,16 @@
const value_type impl_get(const point_type& p) const
{
this->exact().impl_get_extra(p);
- return this->delegate().impl_get(p);
+ return this->delegate().get(p);
}
+ // FIXME: patch
+
+ void impl_resize_border(size_t new_border, bool copy_border) const
+ {
+ this->delegate().impl_resize_border(new_border, copy_border);
+ }
+
// extra code; default is "do nothing"
void impl_size_extra(const size_type& s) const {}
Index: oln/core/abstract/image_with_data.hh
--- oln/core/abstract/image_with_data.hh (revision 97)
+++ oln/core/abstract/image_with_data.hh (working copy)
@@ -179,7 +179,7 @@
return data_ != 0;
}
- void resize_border(size_t new_border, bool copy_border = false) const
+ void impl_resize_border(size_t new_border, bool copy_border) const
{
(const_cast<storage_type&>(*this->data_)).resize_border(new_border,
copy_border);
}
Index: oln/core/abstract/op.hh
--- oln/core/abstract/op.hh (revision 97)
+++ oln/core/abstract/op.hh (working copy)
@@ -28,6 +28,7 @@
#ifndef OLENA_CORE_ABSTRACT_OP_HH
# define OLENA_CORE_ABSTRACT_OP_HH
+# include <oln/core/box.hh>
# include <oln/core/abstract/image_identity.hh>
namespace oln {
Index: oln/core/box.hh
--- oln/core/box.hh (revision 0)
+++ oln/core/box.hh (revision 0)
@@ -0,0 +1,212 @@
+// Copyright (C) 2005 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLENA_CORE_BOX_HH
+# define OLENA_CORE_BOX_HH
+
+# include <oln/core/properties.hh>
+# include <oln/core/abstract/entry.hh>
+
+namespace oln {
+
+
+ // fwd decl
+ template <typename I> struct box;
+
+ // category
+
+ template <typename I>
+ struct set_category< box<I> > {
+ typedef category::image ret;
+ };
+
+ template <typename I>
+ struct set_category< box<const I> > {
+ typedef category::image ret;
+ };
+
+ // props
+
+ template <typename I>
+ struct set_props < category::image, box<I> >
+ : public get_props< category::image, I >
+ {
+ typedef I delegated_type;
+ };
+
+ template <typename I>
+ struct set_props < category::image, box<const I> >
+ : public get_props< category::image, I >
+ {
+ typedef I delegated_type;
+ };
+
+
+ /// Class oln::box...
+
+ template <typename I>
+ struct box : public abstract::image_entry< box<I> >
+ {
+ public:
+
+ box () :
+ image_()
+ {
+ this->exact_ptr = this;
+ }
+
+ box(abstract::image<I>& ima) :
+ image_(ima.exact())
+ {
+ this->exact_ptr = this;
+ }
+
+ box<I>& operator=(abstract::image<I>& rhs)
+ {
+ this->image_ = rhs.exact();
+ return *this;
+ }
+
+ box(const box<I>& rhs) :
+ image_(const_cast<I&>(rhs.image_))
+ {
+ this->exact_ptr = this;
+ }
+
+ box<I> operator=(const box<I>& rhs)
+ {
+ this->image_ = const_cast<I&>(rhs.image_);
+ return *this;
+ }
+
+ // FIXME: add versions for I2 (neq I) to produce explicit errors
+
+ I& impl_delegate()
+ {
+ return this->image_;
+ }
+
+ const I& impl_delegate() const
+ {
+ return this->image_;
+ }
+
+ /// Hooks.
+
+// I& image()
+// {
+// return this->image_;
+// }
+
+// const I& image() const
+// {
+// return this->image_;
+// }
+
+ private:
+
+ /// attribute
+ mutable I image_;
+
+ };
+
+
+ template <typename I>
+ struct box<const I> : public abstract::image_entry< box<const I> >
+ {
+ public:
+
+ box() :
+ image_()
+ {
+ this->exact_ptr = this;
+ }
+
+ box(const abstract::image<I>& ima) :
+ image_(const_cast<I&>(ima.exact()))
+ {
+ this->exact_ptr = this;
+ }
+
+ box<const I> operator=(const abstract::image<I>& rhs)
+ {
+ this->image_ = const_cast<I&>(rhs.exact());
+ return *this;
+ }
+
+ /// Classical copy ctor (image remains const).
+ box(const box<const I>& rhs) :
+ image_(const_cast<I&>(rhs.image_))
+ {
+ this->exact_ptr = this;
+ }
+
+ /// Classical op= (image remains const).
+ box<const I> operator=(const box<const I>& rhs)
+ {
+ this->image_ = const_cast<I&>(rhs.image_);
+ return *this;
+ }
+
+ /// Copy ctor with promotion (image becomes const).
+ box(const box<I>& rhs) :
+ image_(const_cast<I&>(rhs.image_))
+ {
+ this->exact_ptr = this;
+ }
+
+ /// Op= with promotion (image becomes const).
+ box<const I> operator=(const box<I>& rhs)
+ {
+ this->image_ = const_cast<I&>(rhs.image_);
+ return *this;
+ }
+
+ /// Delegation relies on a constant image.
+ const I& impl_delegate() const
+ {
+ return this->image_;
+ }
+
+ /// Hook.
+
+// const I& image() const
+// {
+// return this->image_;
+// }
+
+ private:
+
+ /// attribute
+ mutable I image_;
+
+ };
+
+}
+
+
+#endif // ! OLENA_CORE_BOX_HH
Index: oln/utils/clone.hh
--- oln/utils/clone.hh (revision 97)
+++ oln/utils/clone.hh (working copy)
@@ -67,20 +67,20 @@
{
typedef abstract::op<I, clone_type<I> > super_type;
- mlc::box<I> input_;
+ box<I> input_;
- clone_type(I& input) : input_(input)
- {}
+ clone_type(I& input) :
+ input_(input)
+ {
+ }
void impl_run()
{
- I ima(input_->size());
- oln_type_of(I, fwd_piter) it(input_->size());
+ I ima(input_.size());
+ oln_type_of(I, fwd_piter) p(input_.size());
- for_all(it)
- {
- ima[it] = (*input_)[it];
- }
+ for_all(p)
+ ima[p] = input_[p];
*this->image_ = ima;
}
Index: oln/basics.hh
--- oln/basics.hh (revision 97)
+++ oln/basics.hh (working copy)
@@ -43,7 +43,6 @@
# include <mlc/traits.hh>
# include <mlc/any.hh>
# include <mlc/types.hh>
-# include <mlc/box.hh>
// ntg::
@@ -58,6 +57,7 @@
# include <oln/core/abstract/point.hh>
# include <oln/core/abstract/images.hh>
# include <oln/core/abstract/entry.hh>
+# include <oln/core/box.hh>
# include <oln/core/abstract/op.hh>
# include <oln/core/abstract/piter.hh>
Index: oln/morpho/dilation.hh
--- oln/morpho/dilation.hh (revision 97)
+++ oln/morpho/dilation.hh (working copy)
@@ -113,8 +113,8 @@
template <class I, class E>
struct dilation_type : abstract::op<I, dilation_type<I, E> >
{
- mlc::box<const I> input_;
- mlc::box<const E> se_;
+ box<const I> input_;
+ const E se_;
dilation_type(const abstract::non_vectorial_image<I>& input,
const abstract::struct_elt<E>& se) :
@@ -138,12 +138,15 @@
{
mlc::is_true<mlc::type::eq<oln_type_of(I, size),
oln_type_of(E, size)>::ret>::ensure();
- I output(this->input_->size());
- this->input_->resize_border(this->se_->get_delta());
- oln_type_of(I, fwd_piter) p(this->input_->size());
+ I output(this->input_.size());
+ // FIXME: see erosion.hh
+ this->input_.resize_border(this->se_.get_delta());
+
+ oln_type_of(I, fwd_piter) p(this->input_.size());
+
for_all (p)
- output[p] = morpho::max(*this->input_, p, *this->se_);
+ output[p] = morpho::max(this->input_, p, this->se_);
*this->image_ = output;
}
};
Index: oln/morpho/stat.hh
--- oln/morpho/stat.hh (revision 97)
+++ oln/morpho/stat.hh (working copy)
@@ -71,8 +71,9 @@
dp.start();
V val = input[p + dp];
for_all_remaining (dp)
- if (val < input[p + dp].value())
- val = input[p + dp].value();
+ if (input.hold(p + dp))
+ if (val < input[p + dp].value())
+ val = input[p + dp].value();
return val;
}
@@ -97,8 +98,9 @@
dp.start();
V val = input[p + dp];
for_all_remaining (dp)
- if (val > input[p + dp].value())
- val = input[p + dp].value();
+ if (input.hold(p + dp))
+ if (val > input[p + dp].value())
+ val = input[p + dp].value();
return val;
}
@@ -116,8 +118,9 @@
oln_type_of(E, size)>::ret>::ensure();
oln_type_of(E, fwd_witer) dp(se);
for_all (dp)
- if (input[p + dp] == true)
- return true;
+ if (input.hold(p + dp))
+ if (input[p + dp] == true)
+ return true;
return false;
}
@@ -128,8 +131,9 @@
oln_type_of(E, size)>::ret>::ensure();
oln_type_of(E, fwd_witer) dp(se);
for_all (dp)
- if (input[p + dp] == false)
- return false;
+ if (input.hold(p + dp))
+ if (input[p + dp] == false)
+ return false;
return true;
}
Index: oln/morpho/erosion.hh
--- oln/morpho/erosion.hh (revision 97)
+++ oln/morpho/erosion.hh (working copy)
@@ -108,8 +108,8 @@
template <class I, class E>
struct erosion_type : abstract::op<I, erosion_type<I, E> >
{
- mlc::box<const I> input_;
- mlc::box<const E> se_;
+ box<const I> input_;
+ const E se_;
erosion_type(const abstract::non_vectorial_image<I>& input,
const abstract::struct_elt<E>& se) :
@@ -133,12 +133,18 @@
{
mlc::is_true<mlc::type::eq<oln_type_of(I, size),
oln_type_of(E, size)>::ret>::ensure();
- I output(this->input_->size());
- this->input_->resize_border(this->se_->get_delta());
- oln_type_of(I, fwd_piter) p(this->input_->size());
+ I output(this->input_.size());
+ // FIXME: not only resize but also set values in border!
+ // FIXME: code commented below cause only valid with bordered_image
+
+ this->input_.resize_border(this->se_.get_delta());
+
+ oln_type_of(I, fwd_piter) p(this->input_.size());
+
for_all (p)
- output[p] = morpho::min(*this->input_, p, *this->se_);
+ output[p] = morpho::min(this->input_, p, this->se_);
+ // FIXME: remove * below (oln::box)
*this->image_ = output;
}
};
Index: oln/arith/min.hh
--- oln/arith/min.hh (revision 97)
+++ oln/arith/min.hh (working copy)
@@ -62,8 +62,8 @@
template <class I>
struct min_type : abstract::op<I, min_type<I> >
{
- mlc::box<const I> input1_;
- mlc::box<const I> input2_;
+ box<const I> input1_;
+ box<const I> input2_;
min_type(const abstract::non_vectorial_image<I>& input1,
const abstract::non_vectorial_image<I>& input2) :
@@ -73,12 +73,12 @@
void impl_run()
{
- precondition(input1_->size() == input2_->size());
- I output(input1_->size());
- oln_type_of(I, fwd_piter) p(input1_->size());
+ precondition(input1_.size() == input2_.size());
+ I output(input1_.size());
+ oln_type_of(I, fwd_piter) p(input1_.size());
for_all(p)
- output[p] = ntg::min((*input1_)[p].value(), (*input2_)[p].value());
+ output[p] = ntg::min(input1_[p].value(), input2_[p].value());
*this->image_ = output;
}
@@ -87,6 +87,8 @@
}
+ // FIXME: replace non_vectorial_image by scalar_image
+ // FIXME: cause arithmetics is not defined for Booleans and labels...
template <typename I>
impl::min_type<I> min(const abstract::non_vectorial_image<I>&
input1,
const abstract::non_vectorial_image<I>& input2)
Index: oln/arith/max.hh
--- oln/arith/max.hh (revision 97)
+++ oln/arith/max.hh (working copy)
@@ -62,8 +62,8 @@
template <class I>
struct max_type : abstract::op<I, max_type<I> >
{
- mlc::box<const I> input1_;
- mlc::box<const I> input2_;
+ box<const I> input1_;
+ box<const I> input2_;
max_type(const abstract::non_vectorial_image<I>& input1,
const abstract::non_vectorial_image<I>& input2) :
@@ -73,14 +73,14 @@
void impl_run()
{
- precondition(input1_->size() == input2_->size());
- I output(input1_->size());
- oln_type_of(I, fwd_piter) p(input1_->size());
+ precondition(input1_.size() == input2_.size());
+ I output(input1_.size());
+ oln_type_of(I, fwd_piter) p(input1_.size());
for_all(p)
- output[p] = ntg::max((*input1_)[p].value(), (*input2_)[p].value());
+ output[p] = ntg::max(input1_[p].value(), input2_[p].value());
- *this->image_ = output;
+ *this->image_ = output; // FIXME: remove * when image_ is oln::box
}
};