Commit 85ccfb2e authored by Edwin Carlinet's avatar Edwin Carlinet
Browse files

Alternate representation of tree (some tries...).

	* edwin/exec/benchmark/Makefile,
	* edwin/exec/benchmark/newv.cc,
	* edwin/exec/benchmark/oldv.cc,
	* edwin/exec/benchmark:
	Applications, and comparaisons between the old and new
	version.

	* edwin/mln/core,
	* edwin/mln/core/concept/dindex_site.hh,
	* edwin/mln/core/concept/index_site.hh,
	* edwin/mln/core/dindex_site.hh,
	* edwin/mln/core/internal/index_site_base.hh,
	* edwin/mln/core/internal,
	* edwin/mln/core/site_set/p_run_idx.hh,
	* edwin/mln/core/site_set/p_run_idx_piter.hh,
	* edwin/mln/core/site_set:
	Temporary type for index site (used by the node type), its
	site set and its iterators.

	* edwin/mln/core/concept/tree.hh,
	* edwin/mln/core/concept:
	Tree concept.

	* edwin/mln/core/image,
	* edwin/mln/core/image/attribute_image.hh:
	Attribute image type.

	* edwin/mln/debug,
	* edwin/mln/debug/ctree.hh:
	Debug tools with println overloads.

	* edwin/mln/morpho/tree/component_tree.hh: Shortcuts for
	building min and max tree.

	* edwin/mln/morpho/tree/compute_attribute_image.hh: Compute an
        attribute using the new tree representation.

	* edwin/mln/morpho/tree/impl,
	* edwin/mln/morpho/tree/impl/union_find.hh:
	(Simple) tree computation based on union-find method.

	* edwin/mln/morpho/tree/propagate_node.hh:
	Temporary methods for fast propagation. Will be useless as
	soon as the subdomain morpher will be specialized.

	* edwin/mln/util,
	* edwin/mln/util/ctree,
	* edwin/mln/util/ctree/ctree.hh,
	* edwin/mln/util/ctree/internal,
	* edwin/mln/util/ctree/internal/tree_base.hh,
	* edwin/mln/util/ctree/node.hh:
	Materials for the new tree representation.

git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@4620 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 260a0ff4
2009-10-07 Edwin Carlinet <carlinet@lrde.epita.fr>
Alternate representation of tree (some tries...).
* edwin/exec/benchmark/Makefile,
* edwin/exec/benchmark/newv.cc,
* edwin/exec/benchmark/oldv.cc,
* edwin/exec/benchmark:
Applications, and comparaisons between the old and new
version.
* edwin/mln/core,
* edwin/mln/core/concept/dindex_site.hh,
* edwin/mln/core/concept/index_site.hh,
* edwin/mln/core/dindex_site.hh,
* edwin/mln/core/internal/index_site_base.hh,
* edwin/mln/core/internal,
* edwin/mln/core/site_set/p_run_idx.hh,
* edwin/mln/core/site_set/p_run_idx_piter.hh,
* edwin/mln/core/site_set:
Temporary type for index site (used by the node type), its
site set and its iterators.
* edwin/mln/core/concept/tree.hh,
* edwin/mln/core/concept:
Tree concept.
* edwin/mln/core/image,
* edwin/mln/core/image/attribute_image.hh:
Attribute image type.
* edwin/mln/debug,
* edwin/mln/debug/ctree.hh:
Debug tools with println overloads.
* edwin/mln/morpho/tree/component_tree.hh: Shortcuts for
building min and max tree.
* edwin/mln/morpho/tree/compute_attribute_image.hh: Compute an
attribute using the new tree representation.
* edwin/mln/morpho/tree/impl,
* edwin/mln/morpho/tree/impl/union_find.hh:
(Simple) tree computation based on union-find method.
* edwin/mln/morpho/tree/propagate_node.hh:
Temporary methods for fast propagation. Will be useless as
soon as the subdomain morpher will be specialized.
* edwin/mln/util,
* edwin/mln/util/ctree,
* edwin/mln/util/ctree/ctree.hh,
* edwin/mln/util/ctree/internal,
* edwin/mln/util/ctree/internal/tree_base.hh,
* edwin/mln/util/ctree/node.hh:
Materials for the new tree representation.
2009-10-07 Yann Jacquelet <jacquelet@lrde.epita.fr>
Update the demo for debugging purpose.
......
-include makefile.rules
MLN_DIR = ~/olena/trunk/milena
CXXFLAGS += -W -Wall
CXXFLAGS += $(if $(DEBUG), -g -ggdb, -DNDEBUG $(if $(RELEASE), -O3, -O1))
MY_CXXFLAGS := $(CXXFLAGS) -I $(MLN_DIR)/sandbox/edwin -I $(MLN_DIR)
CXXFLAGS += -I $(MLN_DIR)
CC = g++
LDFLAGS =
all: oldv newv
newv.o: newv.cc
$(CXX) $(MY_CXXFLAGS) -c $<
clean:
rm -f *.o
newv: newv.o
oldv: oldv.o
#include <mln/core/image/image2d.hh>
#include <mln/core/image/attribute_image.hh>
#include <mln/core/alias/neighb2d.hh>
#include <mln/value/int_u8.hh>
#include <mln/util/ctree/ctree.hh>
#include <mln/morpho/tree/component_tree.hh>
#include <mln/morpho/tree/compute_attribute_image.hh>
#include <mln/morpho/tree/filter/min.hh>
#include <mln/morpho/attribute/volume.hh>
#include <mln/morpho/attribute/card.hh>
#include <mln/io/pgm/load.hh>
#include <mln/io/pgm/save.hh>
#include <mln/pw/all.hh>
#include <mln/core/var.hh>
#include <mln/util/timer.hh>
#include <iostream>
#include <mln/debug/ctree.hh>
#include <mln/debug/println.hh>
void usage(char** argv)
{
std::cout << "Usage: " << argv[0] << " image lambda [new.pgm]"
<< std::endl;
abort();
}
static mln::util::timer tm;
void bench(const char* msg)
{
std::cout << msg << " in " << tm << " s" << std::endl;
tm.restart();
}
int main(int argc, char** argv)
{
using namespace mln;
using value::int_u8;
if (argc < 3)
usage(argv);
const char* finput = argv[1];
const unsigned lambda = atoi(argv[2]);
const char* foutput = (argc > 3) ? argv[3] : "new.pgm";
tm.start();
typedef image2d<int_u8> I;
I input;
io::pgm::load(input, finput);
bench("Image Loadin");
// Tree Computation
typedef util::ctree::ctree<I> tree_t;
tree_t tree = morpho::tree::max_tree(input, c4());
bench("Tree construction");
// Compute Attribute
typedef attribute_image<tree_t, unsigned> A;
morpho::attribute::volume<I> attribute;
A attr_img = morpho::tree::compute_attribute_image(tree, attribute);
bench("Attribute Computation (volume)");
// Filtering
attribute_image<tree_t, int_u8> out = tree.to_image();
mln_VAR(predicate, pw::value(attr_img) > pw::cst(lambda));
morpho::tree::filter::min(out, predicate);
bench("Filtering");
// Converting
I output;
convert::over_load::from_to_(out, output); // FIXME !
bench("Restore");
io::pgm::save(output, foutput);
bench("Image Savin");
}
#include <mln/core/image/image2d.hh>
#include <mln/core/alias/neighb2d.hh>
#include <mln/value/int_u8.hh>
#include <mln/morpho/tree/data.hh>
#include <mln/morpho/tree/component_tree.hh>
#include <mln/io/pgm/load.hh>
#include <mln/io/pgm/save.hh>
#include <mln/morpho/tree/compute_attribute_image.hh>
#include <mln/morpho/tree/propagate_representative.hh>
#include <mln/morpho/tree/filter/min.hh>
#include <mln/morpho/attribute/volume.hh>
#include <mln/morpho/attribute/card.hh>
#include <mln/pw/all.hh>
#include <mln/core/var.hh>
#include <mln/debug/println.hh>
#include <mln/util/timer.hh>
#include <iostream>
void usage(char** argv)
{
std::cout << "Usage: " << argv[0] << " image lambda [old.pgm]"
<< std::endl;
abort();
}
static mln::util::timer tm;
void bench(const char* msg)
{
std::cout << msg << " in " << tm << " s" << std::endl;
tm.restart();
}
int main(int argc, char** argv)
{
using namespace mln;
using value::int_u8;
if (argc < 3)
usage(argv);
const char* finput = argv[1];
const unsigned lambda = atoi(argv[2]);
const char* foutput = (argc > 3) ? argv[3] : "old.pgm";
tm.start();
typedef image2d<int_u8> I;
I input;
io::pgm::load(input, finput);
bench("Image Loadin");
// Tree Computation
typedef morpho::tree::data<I, p_array<mln_psite_(I)> > tree_t;
tree_t tree = morpho::tree::max_tree(input, c4());
bench("Tree construction");
// Compute Attribute
typedef mln_ch_value_(I, unsigned) A;
morpho::attribute::volume<I> attribute;
A attr_img = morpho::tree::compute_attribute_image(attribute, tree);
bench("Attribute Computation (volume)");
// Filtering
I out = duplicate(input);
mln_VAR(predicate, pw::value(attr_img) > pw::cst(lambda));
morpho::tree::filter::min(tree, out, predicate);
bench("Filtering");
// Restore
morpho::tree::propagate_representative(tree, out);
bench("Restore");
io::pgm::save(out, foutput);
bench("Image Savin");
}
// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
// Olena is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation, version 2 of the License.
//
// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
//
// As a special exception, you may use this file as part of a free
// software project 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
///
/// Definition of the concept mln::Dindex_Site
///
#ifndef MLN_CORE_CONCEPT_DINDEX_SITE_HH
# define MLN_CORE_CONCEPT_DINDEX_SITE_HH
namespace mln
{
// Forward declaration.
template <typename E> struct Dindex_Site;
namespace trait
{
// FIXME: Add promotion.
template < typename L, typename R >
struct set_binary_< op::plus,
mln::Dindex_Site, L, mln::Dindex_Site, R >
{
typedef L ret;
};
template < typename L, typename R >
struct set_binary_< op::minus,
mln::Dindex_Site, L, mln::Dindex_Site, R >
{
typedef L ret;
};
template < typename L, typename S>
struct set_binary_< op::plus,
mln::Dindex_Site, L, mln::value::Scalar, S >
{
typedef L ret;
};
template < typename L, typename S>
struct set_binary_< op::minus,
mln::Dindex_Site, L, mln::value::Scalar, S >
{
typedef L ret;
};
template < typename D, typename S >
struct set_binary_< op::times,
mln::Dindex_Site, D,
mln::value::Scalar, S >
{
typedef D ret;
};
template <typename D>
struct set_unary_< op::ord, mln::Dindex_Site, D >
{
typedef mln::internal::ord_less< D > ret;
};
} // end of namespace mln::trait
/// Delta point site category flag type.
template <>
struct Dindex_Site<void>
{
typedef Object<void> super;
};
/// FIXME: Doc!
template <typename E>
struct Dindex_Site : public Object<E>
{
typedef Dindex_Site<void> category;
/*
typedef value_t;
typedef site;
typedef psite;
const value_t& value();
void change_value(const value_t&);
*/
protected:
Dindex_Site();
};
// Operators.
template <typename D>
std::ostream&
operator<<(std::ostream& ostr, const Dindex_Site<D>& dp);
template <typename L, typename R>
bool
operator==(const Dindex_Site<L>& lhs, const Dindex_Site<R>& rhs);
template <typename L, typename R>
L operator+(const Dindex_Site<L>& lhs, const Dindex_Site<R>& rhs);
template <typename L, typename R>
L operator-(const Dindex_Site<L>& lhs, const Dindex_Site<R>& rhs);
template <typename L, typename S>
L operator+(const Dindex_Site<L>& lhs, const value::Scalar<S>& rhs);
template <typename L, typename S>
L operator-(const Dindex_Site<L>& lhs, const value::Scalar<S>& rhs);
template <typename D, typename S>
D operator*(const Dindex_Site<D>& lhs, const value::Scalar<S>& rhs);
namespace convert
{
namespace over_load
{
template <typename D>
void
from_to_(const Dindex_Site<D>& from, mln_site(D)& to);
} // end of namespace mln::convert::over_load
} // end of namespace mln::convert
# ifndef MLN_INCLUDE_ONLY
template <typename E>
inline
Dindex_Site<E>::Dindex_Site()
{
typedef typename E::value_t value_t;
const value_t& (E::*m)() const = & E::value;
m = 0;
}
template <typename D>
inline
std::ostream& operator<<(std::ostream& ostr, const Dindex_Site<D>& dp)
{
ostr << '(' << debug::format(exact(dp).value()) << ')';
return ostr;
}
template <typename L, typename R>
inline
bool operator==(const Dindex_Site<L>& lhs, const Dindex_Site<R>& rhs)
{
return exact(lhs).value() == exact(rhs).value();
}
template <typename L, typename R>
inline
L operator+(const Dindex_Site<L>& lhs, const Dindex_Site<R>& rhs)
{
L tmp(exact(lhs).value() + exact(rhs).value());
return tmp;
}
template <typename L, typename R>
inline
L operator-(const Dindex_Site<L>& lhs, const Dindex_Site<R>& rhs)
{
L tmp(exact(lhs).value() - exact(rhs).value());
return tmp;
}
template <typename L, typename S>
inline
L operator+(const Dindex_Site<L>& lhs, const value::Scalar<S>& rhs)
{
L tmp(exact(lhs).value() + exact(rhs).to_equiv());
return tmp;
}
template <typename L, typename S>
inline
L operator-(const Dindex_Site<L>& lhs, const value::Scalar<S>& rhs)
{
L tmp(exact(lhs).value() - exact(rhs).to_equiv());
return tmp;
}
template <typename D, typename S>
D operator*(const Dindex_Site<D>& lhs, const value::Scalar<S>& rhs)
{
D tmp(exact(lhs).value() * exact(rhs).to_equiv());
return tmp;
}
namespace convert
{
namespace over_load
{
template <typename D>
inline
void
from_to_(const Dindex_Site<D>& dp, mln_site(D)& p)
{
p.change_index(exact(dp).value());
}
} // end of namespace mln::convert::over_load
} // end of namespace mln::convert
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
#endif // !MLN_CORE_CONCEPT_DINDEX_SITE_HH
// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
// Olena is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation, version 2 of the License.
//
// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
//
// As a special exception, you may use this file as part of a free
// software project 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.
///
/// \brief Definition of the concept mln::index_site.
///
/// FIXME: doc!
///
#ifndef MLN_CORE_CONCEPT_INDEX_SITE_HH
# define MLN_CORE_CONCEPT_INDEX_SITE_HH
# include <mln/core/concept/site.hh>
# include <mln/value/concept/integer.hh>
# include <mln/core/concept/dindex_site.hh>
namespace mln
{
// Forward declaration.
template <typename E> struct Index_Site;
namespace trait
{
template < typename P, typename D >
struct set_binary_< op::plus,
mln::Index_Site, P, mln::Dindex_Site, D >
{
typedef P ret;
};
template < typename P, typename D >
struct set_binary_< op::minus,
mln::Index_Site, P, mln::Dindex_Site, D >
{
typedef P ret;
};
template < typename L, typename R >
struct set_binary_< op::minus,
mln::Index_Site, L, mln::Index_Site, R >
{
typedef mln_delta(L) ret;
};
template < typename L, typename R >
struct set_binary_< op::times,
mln::Index_Site, L,
mln::Object, mln::value::scalar_<R> >
{
typedef L ret;
};
template < typename L, typename R >
struct set_binary_< op::div,
mln::Index_Site, L,
mln::Object, mln::value::scalar_<R> >
{
typedef L ret;
};
template <typename P>
struct set_unary_< op::ord, mln::Index_Site, P >
{
typedef mln::internal::ord_less< P > ret;
};
}
// Index Site category flag type.
template <>
struct Index_Site<void>
{
typedef Site<void> super;