Commit 797fb1c7 authored by Thierry Geraud's avatar Thierry Geraud
Browse files

Add the morphological sum attribute.

	* mln/morpho/attribute/sum.hh: New.
	* mln/morpho/attribute/volume.hh (area): New .
	* mln/morpho/attribute/card.hh: Layout.
	(take_as_init): New overload for util::pix.
	* mln/morpho/attribute/all.hh: Update.
	* tests/morpho/attribute/sum.cc: New.
	* tests/morpho/attribute/volume.cc: New.
	* tests/morpho/attribute/Makefile.am: Update.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@3368 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 98610765
2009-02-13 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Add the morphological sum attribute.
* mln/morpho/attribute/sum.hh: New.
* mln/morpho/attribute/volume.hh (area): New .
* mln/morpho/attribute/card.hh: Layout.
(take_as_init): New overload for util::pix.
* mln/morpho/attribute/all.hh: Update.
* tests/morpho/attribute/sum.cc: New.
* tests/morpho/attribute/volume.cc: New.
* tests/morpho/attribute/Makefile.am: Update.
2009-02-13 Thierry Geraud <thierry.geraud@lrde.epita.fr>
 
Add a label wrapper in fun::l2l.
......@@ -46,6 +46,8 @@ namespace mln
# include <mln/morpho/attribute/card.hh>
# include <mln/morpho/attribute/sum.hh>
# include <mln/morpho/attribute/volume.hh>
#endif // ! MLN_MORPHO_ATTRIBUTE_ALL_HH
......@@ -88,13 +88,13 @@ namespace mln
/// \{
void init();
void take();
void take(const argument& s);
void take(const card<I>& other);
void take(const util::pix<I>& px);
void take(const card<I>& other);
void take();
void take_as_init();
void take_as_init(const util::pix<I>& px);
using super_::take_as_init;
/// \}
......@@ -129,20 +129,22 @@ namespace mln
c_ = 0;
}
// take.
template <typename I>
inline
void
card<I>::take(const argument&)
card<I>::take()
{
take();
++c_;
}
template <typename I>
inline
void
card<I>::take(const card<I>& other)
card<I>::take(const argument&)
{
c_ += other.c_;
take();
}
template <typename I>
......@@ -156,11 +158,13 @@ namespace mln
template <typename I>
inline
void
card<I>::take()
card<I>::take(const card<I>& other)
{
++c_;
c_ += other.c_;
}
// take_as_init.
template <typename I>
inline
void
......@@ -170,6 +174,14 @@ namespace mln
take();
}
template <typename I>
inline
void
card<I>::take_as_init(const util::pix<I>&)
{
take_as_init();
}
template <typename I>
inline
unsigned
......
// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
//
// 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, 51 Franklin Street, Fifth Floor,
// 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 MLN_MORPHO_ATTRIBUTE_SUM_HH
# define MLN_MORPHO_ATTRIBUTE_SUM_HH
/// \file mln/morpho/attribute/sum.hh
///
/// Define an accumulator that computes the sum of component values.
# include <mln/accu/internal/base.hh>
# include <mln/trait/value_.hh> // For mln_sum.
# include <mln/value/builtin/all.hh> // In the case of summing builtin values.
# include <mln/literal/zero.hh> // For initialization.
namespace mln
{
// Forward declaration.
namespace morpho {
namespace attribute {
template <typename I, typename S> class sum;
}
}
// Traits.
namespace trait
{
template <typename I, typename S>
struct accumulator_< morpho::attribute::sum<I,S> >
{
typedef accumulator::has_untake::no has_untake;
typedef accumulator::has_set_value::no has_set_value;
typedef accumulator::has_stop::no has_stop;
typedef accumulator::when_pix::use_v when_pix;
};
} // end of namespace mln::trait
namespace morpho
{
namespace attribute
{
/// Suminality accumulator class.
template <typename I, typename S = mln_sum(mln_value(I))>
class sum : public mln::accu::internal::base< S, sum<I,S> >
{
typedef mln::accu::internal::base< S, sum<I> > super_;
public:
typedef mln_value(I) argument;
sum();
/// Manipulators.
/// \{
void init();
void take(const argument& v);
void take(const util::pix<I>& px);
void take(const sum<I,S>& other);
void take_as_init(const argument& v);
void take_as_init(const util::pix<I>& px);
/// \}
/// Get the value of the accumulator.
S to_result() const;
/// Check whether this accu is able to return a result.
/// Return always true.
bool is_valid() const;
protected:
/// The sum value.
S s_;
};
# ifndef MLN_INCLUDE_ONLY
template <typename I, typename S>
inline
sum<I,S>::sum()
{
init();
}
template <typename I, typename S>
inline
void
sum<I,S>::init()
{
s_ = literal::zero;
}
// take.
template <typename I, typename S>
inline
void
sum<I,S>::take(const argument& v)
{
s_ += v;
}
template <typename I, typename S>
inline
void
sum<I,S>::take(const util::pix<I>& px)
{
take(px.v());
}
template <typename I, typename S>
inline
void
sum<I,S>::take(const sum<I,S>& other)
{
s_ += other.s_;
}
// take_as_init.
template <typename I, typename S>
inline
void
sum<I,S>::take_as_init(const argument& v)
{
s_ = v;
}
template <typename I, typename S>
inline
void
sum<I,S>::take_as_init(const util::pix<I>& px)
{
take_as_init(px.v());
}
template <typename I, typename S>
inline
S
sum<I,S>::to_result() const
{
return s_;
}
template <typename I, typename S>
inline
bool
sum<I,S>::is_valid() const
{
return true;
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::morpho::attribute
} // end of namespace mln::morpho
} // end of namespace mln
#endif // ! MLN_MORPHO_ATTRIBUTE_SUM_HH
......@@ -103,6 +103,9 @@ namespace mln
/// Always true here.
bool is_valid() const;
/// Give the area.
unsigned area() const;
protected:
/// The current level.
mln_value(I) level_;
......@@ -195,6 +198,14 @@ namespace mln
return volume_;
}
template <typename I>
inline
unsigned
volume<I>::area() const
{
return area_;
}
template <typename I>
inline
bool
......
......@@ -3,8 +3,12 @@
include $(top_srcdir)/milena/tests/tests.mk
check_PROGRAMS = \
card
card \
sum \
volume
card_SOURCES = card.cc
sum_SOURCES = sum.cc
volume_SOURCES = volume.cc
TESTS = $(check_PROGRAMS)
// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
//
// 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, 51 Franklin Street, Fifth Floor,
// 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.
/// \file tests/morpho/attribute/sum.cc
///
/// Test on mln::morpho::attribute::sum.
#include <mln/core/image/image2d.hh>
#include <mln/morpho/attribute/sum.hh>
int main()
{
using namespace mln;
typedef image2d<int> I;
I ima(3, 3);
point2d p(0, 0);
ima(p) = 17;
util::pix<I> px(ima, p);
morpho::attribute::sum<I> s;
s.take(px);
s.take(px);
s.take(px);
mln_assertion(s == 51);
}
// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
//
// 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, 51 Franklin Street, Fifth Floor,
// 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.
/// \file tests/morpho/attribute/volume.cc
///
/// Test on mln::morpho::attribute::volume.
#include <mln/core/image/image2d.hh>
#include <mln/morpho/attribute/volume.hh>
int main()
{
using namespace mln;
typedef image2d<int> I;
I ima(3, 3);
util::pix<I> px(ima, point2d(0,0));
morpho::attribute::volume<I> v;
v.take(px);
mln_assertion(v == 1);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment