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

horizontal_symmetry.hh

00001 // Copyright (C) 2010 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 
00029 
00030 #ifndef MLN_GEOM_HORIZONTAL_SYMMETRY_HH
00031 # define MLN_GEOM_HORIZONTAL_SYMMETRY_HH
00032 
00033 # include <mln/core/concept/image.hh>
00034 # include <mln/core/box_runend_piter.hh>
00035 # include <mln/core/box_runstart_piter.hh>
00036 
00037 namespace mln
00038 {
00039 
00040   namespace geom
00041   {
00042 
00044     //
00045     template <typename I>
00046     mln_concrete(I)
00047     horizontal_symmetry(const Image<I>& input);
00048 
00049 
00050 # ifndef MLN_INCLUDE_ONLY
00051 
00052 
00053     // Implementations
00054 
00055     namespace impl
00056     {
00057 
00058       namespace generic
00059       {
00060 
00061         template <typename I>
00062         mln_concrete(I)
00063         horizontal_symmetry(const Image<I>& input_)
00064         {
00065           const I& input = exact(input_);
00066           mln_precondition(input.is_valid());
00067 
00068           mln_concrete(I) output(input.domain());
00069 
00070           typedef mln_site(I) P;
00071           box_runstart_piter<P> pi(input.domain());
00072           box_runend_piter<P> po(output.domain());
00073 
00074           unsigned ncols = input.ncols();
00075 
00076           for_all_2(pi, po)
00077           {
00078             mln_site(I) idi = pi, ido = po;
00079             ido[1] -= ncols - 1;
00080             for (unsigned n = 0; n < ncols; ++n, ++idi[1], ++ido[1])
00081               output(ido) = input(idi);
00082           }
00083 
00084           return output;
00085         }
00086 
00087       } // end of namespace mln::geom::impl::generic
00088 
00089 
00090       template <typename I>
00091       mln_concrete(I)
00092       horizontal_symmetry_fastest(const Image<I>& input_)
00093       {
00094         const I& input = exact(input_);
00095         mln_precondition(input.is_valid());
00096 
00097         mln_concrete(I) output(input.domain());
00098 
00099         typedef mln_site(I) P;
00100         box_runstart_piter<P> pi(input.domain());
00101         box_runend_piter<P> po(output.domain());
00102 
00103         unsigned ncols = input.ncols();
00104 
00105         typedef mln_value(I)* ptr_t;
00106 
00107         for_all_2(pi, po)
00108         {
00109           const mln_value(I)* ptr_in  = & input(pi);
00110           ptr_t ptr_out = (& output(po)) - ncols + 1;
00111 
00112           for (unsigned n = 0; n < ncols; ++n)
00113             *ptr_out++ = *ptr_in++;
00114         }
00115 
00116         return output;
00117       }
00118 
00119 
00120     } // end of namespace mln::geom::impl
00121 
00122 
00123 
00124     // Dispatch
00125 
00126     namespace internal
00127     {
00128 
00129       template <typename I>
00130       mln_concrete(I)
00131       horizontal_symmetry_dispatch(
00132         trait::image::value_alignment::any,
00133         trait::image::value_storage::any,
00134         trait::image::value_access::any,
00135         const Image<I>& input)
00136       {
00137         return impl::generic::horizontal_symmetry(input);
00138       }
00139 
00140 
00141       template <typename I>
00142       mln_concrete(I)
00143       horizontal_symmetry_dispatch(
00144         trait::image::value_alignment::with_grid,
00145         trait::image::value_storage::one_block,
00146         trait::image::value_access::direct,
00147         const Image<I>& input)
00148       {
00149         return impl::horizontal_symmetry_fastest(input);
00150       }
00151 
00152 
00153       template <typename I>
00154       mln_concrete(I)
00155       horizontal_symmetry_dispatch(const Image<I>& input)
00156       {
00157         return horizontal_symmetry_dispatch(
00158           mln_trait_image_value_alignment(I)(),
00159           mln_trait_image_value_storage(I)(),
00160           mln_trait_image_value_access(I)(),
00161           input);
00162       }
00163 
00164     } // end of namespace mln::geom::internal
00165 
00166 
00167 
00168     // Facade
00169 
00170     template <typename I>
00171     mln_concrete(I)
00172     horizontal_symmetry(const Image<I>& input_)
00173     {
00174       trace::entering("geom::horizontal_symmetry");
00175 
00176       const I& input = exact(input_);
00177       mln_precondition(input.is_valid());
00178 
00179       mln_concrete(I) output = internal::horizontal_symmetry_dispatch(input);
00180 
00181       trace::exiting("geom::horizontal_symmetry");
00182       return output;
00183     }
00184 
00185 
00186 # endif // ! MLN_INCLUDE_ONLY
00187 
00188 
00189   } // end of namespace mln::geom
00190 
00191 } // end of namespace mln
00192 
00193 
00194 #endif // ! MLN_GEOM_HORIZONTAL_SYMMETRY_HH

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