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

make_complex2d.hh

00001 // Copyright (C) 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 #ifndef APPS_GRAPH_MORPHO_MAKE_COMPLEX2D_HH
00027 # define APPS_GRAPH_MORPHO_MAKE_COMPLEX2D_HH
00028 
00031 
00032 # include <mln/core/image/image2d.hh>
00033 # include <mln/world/inter_pixel/dim2/is_pixel.hh>
00034 
00044 template <typename I>
00045 inline
00046 mln_concrete(I)
00047 make_complex2d(const mln::Image<I>& input_)
00048 {
00049   using namespace mln;
00050 
00051   const I& input = exact(input_);
00052   /* FIXME: The construction of OUTPUT is obvioulsy not generic, since
00053      it expects I's domain to provide the interface of an mln::box2d.
00054      There should be a static precondition on I at the beginning of
00055      this function.  */
00056   typedef mln_concrete(I) O;
00057   O output(2 * input.nrows() - 1, 2 * input.ncols() - 1);
00058 
00059   mln_piter(O) p(output.domain());
00060   for_all(p)
00061   {
00062     point2d p_ = p;
00063     if (p_.row() % 2 == 0)
00064       {
00065         if (p_.col() % 2 == 0)
00066           // Pixel site.
00067           output(p) = input.at_(p_.row() / 2, p_.col() / 2);
00068         else
00069           // Horizontal edge site.
00070           output(p) =
00071             input.at_(p_.row() / 2, (p_.col() - 1) / 2) &&
00072             input.at_(p_.row() / 2, (p_.col() + 1) / 2);
00073       }
00074     else
00075       {
00076         if (p_.col() % 2 == 0)
00077           // Vertical edge site.
00078           output(p) =
00079             input.at_((p_.row() - 1) / 2, p_.col() / 2) &&
00080             input.at_((p_.row() + 1) / 2, p_.col() / 2);
00081         else
00082           // Square site (not handled, but still set for possible
00083           // debug outputs).
00084           output(p) = 
00085             input.at_((p_.row() - 1) / 2, (p_.col() - 1) / 2) &&
00086             input.at_((p_.row() - 1) / 2, (p_.col() + 1) / 2) &&
00087             input.at_((p_.row() + 1) / 2, (p_.col() - 1) / 2) &&
00088             input.at_((p_.row() + 1) / 2, (p_.col() + 1) / 2);
00089       }
00090   }
00091   return output;
00092 }
00093 
00094 
00100 template <typename I>
00101 inline
00102 mln_concrete(I)
00103 unmake_complex2d(const mln::Image<I>& input_)
00104 {
00105   using namespace mln;
00106 
00107   const I& input = exact(input_);
00108   // The input image must have an odd number of rows and columns.
00109   mln_precondition(input.nrows() % 2 == 1);
00110   mln_precondition(input.ncols() % 2 == 1);
00111 
00112   // Create a (morpher) image of the pixels of INPUT.
00113   typedef image_if< const I, world::inter_pixel::dim2::is_pixel > J;
00114   J input_pixels = input | world::inter_pixel::dim2::is_pixel();
00115 
00116   /* FIXME: The construction of OUTPUT is obvioulsy not generic, since
00117      it expects I's domain to provide the interface of an mln::box2d.
00118      There should be a static precondition on I at the beginning of
00119      this function.  */
00120   typedef mln_concrete(I) O;
00121   // FIXME: This won't work if INPUT's domain does not start at (0,0).
00122   O output(input.nrows() / 2 + 1, input.ncols() / 2 + 1);
00123 
00124   mln_piter(J) p_in(input_pixels.domain());
00125   mln_piter(O) p_out(output.domain());
00126   for_all_2(p_in, p_out)
00127     output(p_out) = input(p_in);
00128   return output;
00129 }
00130 
00131 
00132 #endif // ! APPS_GRAPH_MORPHO_MAKE_COMPLEX2D_HH

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