• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

data.cc

00001 // Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE)
00002 //
00003 // This file is part of Olena.
00004 //
00005 // Olena is free software: you can redistribute it and/or modify it under
00006 // the terms of the GNU General Public License as published by the Free
00007 // Software Foundation, version 2 of the License.
00008 //
00009 // Olena is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 // As a special exception, you may use this file as part of a free
00018 // software project without restriction.  Specifically, if other files
00019 // instantiate templates or use macros or inline functions from this
00020 // file, or you compile this file and link it with other files to produce
00021 // an executable, this file does not by itself cause the resulting
00022 // executable to be covered by the GNU General Public License.  This
00023 // exception does not however invalidate any other reasons why the
00024 // executable file might be covered by the GNU General Public License.
00025 
00026 #include <mln/core/image/image2d.hh>
00027 #include <mln/core/alias/neighb2d.hh>
00028 #include <mln/core/site_set/p_array.hh>
00029 
00030 #include <mln/data/sort_psites.hh>
00031 #include <mln/debug/println.hh>
00032 
00033 #include <mln/morpho/tree/data.hh>
00034 
00035 
00036 int main()
00037 {
00038   using namespace mln;
00039 
00040   typedef image2d<unsigned char> I;
00041 //   unsigned char vals[] = { 3, 2, 1,
00042 //                         3, 2, 3,
00043 //                         3, 4, 1 };
00044 
00045   unsigned char vals[] = { 3, 3, 3,
00046                            3, 4, 4,
00047                            3, 4, 4 };
00048 
00049   I ima = make::image2d(vals);
00050 
00051   debug::println("ima = ", ima);
00052 
00053   typedef p_array<point2d> S;
00054   S s = data::sort_psites_decreasing(ima);
00055 
00056   typedef morpho::tree::data<I,S> tree_t;
00057   tree_t t(ima, s, c4());
00058 
00059   debug::println( "parent  = ", t.parent_image() | t.domain() );
00060   debug::println( "on node = ", t.parent_image() | t.nodes()  );
00061   debug::println( "on leaves = ", t.parent_image() | t.leaves()  );
00062 
00063   {
00064     /* Check site and node up order */
00065     tree_t::up_node_piter n(t);
00066     tree_t::up_site_piter s(t);
00067     tree_t::up_leaf_piter l(t);
00068     n.start();
00069     l.start();
00070     for_all(s)
00071       if (t.is_a_node(s))
00072         {
00073           mln_assertion(s == n);
00074           if (t.is_a_leaf(n))
00075             {
00076               mln_assertion(l == n);
00077               l.next();
00078             }
00079           n.next();
00080         }
00081     mln_assertion(!n.is_valid() && !s.is_valid() && !l.is_valid());
00082   }
00083 
00084   {
00085     /* Check site and node up order */
00086     tree_t::dn_node_piter n(t);
00087     tree_t::dn_site_piter s(t);
00088     tree_t::dn_leaf_piter l(t);
00089     n.start();
00090     l.start();
00091     for_all(s)
00092       if (t.is_a_node(s))
00093         {
00094           mln_assertion(s == n);
00095           if (t.is_a_leaf(n))
00096             {
00097               mln_assertion(l == n);
00098               l.next();
00099             }
00100           n.next();
00101         }
00102     mln_assertion(!n.is_valid() && !s.is_valid() && !l.is_valid());
00103   }
00104 
00105 
00106   {
00107     std::cout << "nodes = ";
00108     tree_t::up_node_piter n(t);
00109     for_all(n)
00110       std::cout << n << ' ';
00111     std::cout << std::endl
00112               << std::endl;
00113   }
00114 
00115 
00116   {
00117     image2d<unsigned> area(ima.domain());
00118     data::fill(area, 1);
00119     tree_t::up_site_piter p(t);
00120     for_all(p)
00121       if (! t.is_root(p))
00122         area(t.parent(p)) += area(p);
00123     debug::println("area = ", area | t.nodes());
00124   }
00125 
00126 }

Generated on Tue Oct 4 2011 15:23:40 for Milena (Olena) by  doxygen 1.7.1