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

to_window.cc

00001 // Copyright (C) 2007, 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/alias/dpoint2d.hh>
00027 #include <mln/core/image/image2d.hh>
00028 #include <mln/core/image/dmorph/sub_image.hh>
00029 #include <mln/core/alias/window2d.hh>
00030 #include <mln/core/alias/box2d.hh>
00031 #include <mln/core/alias/neighb2d.hh>
00032 
00033 
00034 #include <mln/data/fill.hh>
00035 
00036 #include <mln/convert/to_window.hh>
00037 #include <mln/convert/to_p_set.hh>
00038 
00039 #include <mln/util/ord.hh>
00040 
00041 using namespace mln;
00042 
00043   void test(window2d ref, window2d cmp)
00044   {
00045     mln_assertion(ref.size() == cmp.size());
00046     for (unsigned i = 0; i < ref.size(); ++i)
00047       mln_assertion(ref.dp(i) == cmp.dp(i));
00048   }
00049 
00050 int main()
00051 {
00052   dpoint2d
00053     a(1, 0),
00054     b(0, 1),
00055     c(-1,0),
00056     d(0,-1);
00057 
00058   window2d ref;
00059   ref.insert(a);
00060   ref.insert(b);
00061   ref.insert(c);
00062   ref.insert(d);
00063   // Reference constructed.
00064 
00065   // Nbh :
00066   neighb2d nbh = c4();
00067   window2d test_nbh = convert::to_window(nbh);
00068   test(ref, test_nbh);
00069 
00070   // Image :
00071   image2d<bool> ima(make::box2d(-6, -6, 6, 6));
00072   data::fill(ima, false);
00073   data::fill((ima | convert::to_p_set(ref)).rw(), true);
00074   window2d test_ima = convert::to_window(ima);
00075   test(ref, test_ima);
00076 
00077   // Window :
00078   p_set<point2d> setp;
00079   setp.insert(point2d::origin + a);
00080   setp.insert(point2d::origin + b);
00081   setp.insert(point2d::origin + c);
00082   setp.insert(point2d::origin + d);
00083   window2d test_setp = convert::to_window(setp);
00084   test(ref, test_setp);
00085 
00086   // std::set :
00087   std::set<dpoint2d, util::ord<dpoint2d> > set;
00088   set.insert(a);
00089   set.insert(b);
00090   set.insert(c);
00091   set.insert(d);
00092   window2d test_set = convert::to_window(set);
00093   test(ref, test_set);
00094 
00095   // FIXME: To upper window.
00096 }

Generated on Fri Sep 16 2011 16:34:04 for Milena (Olena) by  doxygen 1.7.1