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

compute_parent.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/var.hh>
00027 #include <mln/core/image/image2d.hh>
00028 #include <mln/core/alias/neighb2d.hh>
00029 #include <mln/core/image/dmorph/image_if.hh>
00030 #include <mln/core/site_set/p_array.hh>
00031 
00032 #include <mln/data/sort_psites.hh>
00033 #include <mln/data/compare.hh>
00034 #include <mln/pw/value.hh>
00035 #include <mln/debug/println.hh>
00036 
00037 #include <mln/morpho/tree/compute_parent.hh>
00038 
00039 
00040 static mln::image2d<mln::point2d> ref1()
00041 {
00042   using namespace mln;
00043 
00044   image2d<point2d> ref1(make::box2d(3,3));
00045 
00046   ref1(point2d(0,0)) = point2d(0,0);
00047   ref1(point2d(0,1)) = point2d(0,0);
00048   ref1(point2d(0,2)) = point2d(0,0);
00049   ref1(point2d(1,1)) = point2d(0,0);
00050   ref1(point2d(2,2)) = point2d(2,2);
00051 
00052   return ref1;
00053 }
00054 
00055 
00056 static mln::image2d<mln::point2d> ref2()
00057 {
00058   using namespace mln;
00059 
00060   image2d<point2d> ref2(make::box2d(3,3));
00061 
00062   ref2(point2d(0,0)) = point2d(0,1);
00063   ref2(point2d(0,1)) = point2d(0,2);
00064   ref2(point2d(0,2)) = point2d(0,2);
00065   ref2(point2d(1,0)) = point2d(0,0);
00066   ref2(point2d(1,1)) = point2d(0,1);
00067   ref2(point2d(1,2)) = point2d(0,1);
00068   ref2(point2d(2,0)) = point2d(0,0);
00069   ref2(point2d(2,1)) = point2d(0,0);
00070   ref2(point2d(2,2)) = point2d(0,2);
00071 
00072   return ref2;
00073 }
00074 
00075 
00076 int main()
00077 {
00078   using namespace mln;
00079 
00080   {
00081     bool vals[] = { 1, 1, 1,
00082                     0, 1, 0,
00083                     0, 0, 1  };
00084     image2d<bool> ima = make::image2d(vals);
00085     typedef image_if<image2d<bool>, pw::value_<image2d<bool> > > sub_t;
00086     sub_t sub = ima | pw::value(ima);
00087 
00088     typedef image_if<image2d<point2d>, pw::value_<image2d<bool> > > par_t;
00089     par_t par = morpho::tree::compute_parent(sub, c4(), sub.domain());
00090     mln_assertion(par == (ref1() | sub.domain()));
00091   }
00092 
00093   {
00094     unsigned char vals[] = { 3, 2, 1,
00095                              3, 2, 3,
00096                              3, 4, 1 };
00097     image2d<unsigned char> ima = make::image2d(vals);
00098 
00099     typedef p_array<point2d> S;
00100     S s = data::sort_psites_increasing(ima);
00101     image2d<point2d> par = morpho::tree::compute_parent(ima, c4(), s);
00102     mln_assertion(par == ref2());
00103   }
00104 
00105 }

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