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

rotate.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 
00029 
00030 #ifndef MLN_GEOM_ROTATE_HH
00031 # define MLN_GEOM_ROTATE_HH
00032 
00033 # include <mln/core/concept/image.hh>
00034 # include <mln/core/concept/site_set.hh>
00035 # include <mln/core/concept/box.hh>
00036 
00037 # include <mln/core/routine/extend.hh>
00038 
00039 # include <mln/core/image/imorph/tr_image.hh>
00040 
00041 # include <mln/accu/shape/bbox.hh>
00042 
00043 # include <mln/data/paste.hh>
00044 
00045 # include <mln/geom/bbox.hh>
00046 
00047 # include <mln/fun/x2x/composed.hh>
00048 # include <mln/fun/x2x/rotation.hh>
00049 # include <mln/fun/x2x/translation.hh>
00050 
00051 # include <mln/literal/zero.hh>
00052 
00053 # include <mln/math/pi.hh>
00054 
00055 
00056 namespace mln
00057 {
00058 
00059   namespace geom
00060   {
00061 
00075     //
00076     template <typename I, typename Ext, typename S>
00077     mln_concrete(I)
00078     rotate(const Image<I>& input, double angle,
00079            const Ext& extension, const Site_Set<S>& output_domain);
00080 
00081 
00083     template <typename I, typename Ext>
00084     mln_concrete(I)
00085     rotate(const Image<I>& input, double angle, const Ext& extension);
00086 
00087 
00090     template <typename I>
00091     mln_concrete(I)
00092     rotate(const Image<I>& input, double angle);
00093 
00094 
00095 
00096 # ifndef MLN_INCLUDE_ONLY
00097 
00098 
00099     template <typename I, typename Ext, typename S>
00100     mln_concrete(I)
00101     rotate(const Image<I>& input_, double angle,
00102            const Ext& extension_, const Site_Set<S>& output_domain_)
00103     {
00104       trace::entering("geom::rotate");
00105 
00106       const I& input = exact(input_);
00107       const S& output_domain = exact(output_domain_);
00108       const mln_exact(Ext)& extension = exact(extension_);
00109 
00110       // Do not check that output_domain_ is valid. If it is not,
00111       // further in this routine, we define a default domain.
00112       mln_precondition(input.is_valid());
00113       mln_precondition(angle >= -360.0f && angle <= 360.0f);
00114       mlc_converts_to(mln_exact(Ext), mln_value(I))::check();
00115       mlc_is_a(S,Box)::check();
00116       // FIXME: A precondition is probably missing for the extension value.
00117 
00118       mln_site(I) c = geom::bbox(input).center();
00119       typedef fun::x2x::translation<2,double> trans_t;
00120       trans_t
00121         t(-1 * c.to_vec()),
00122         t_1(c.to_vec());
00123 
00124       typedef fun::x2x::rotation<2,double> rot_t;
00125       rot_t rot(math::pi * angle / 180.f, literal::origin);
00126 
00127       typedef
00128         fun::x2x::composed<trans_t, fun::x2x::composed<rot_t, trans_t> >
00129         comp_transf_t;
00130 
00131       comp_transf_t comp_transf = compose(t_1, compose(rot, t));
00132 
00133       S b = output_domain;
00134       // Automatically adjusting the output domain if needed.
00135       if (!output_domain.is_valid())
00136       {
00137         accu::shape::bbox<mln_site(I)> accu;
00138 
00139         typedef mln_site(I) P;
00140         accu.take(P(comp_transf(input.domain().pmin().to_vec())));
00141         accu.take(P(comp_transf(input.domain().pmax().to_vec())));
00142 
00143         b = accu.to_result();
00144       }
00145 
00146       typedef
00147         tr_image<mln_box(I), extension_val<const I>, comp_transf_t> tr_t;
00148 
00149       tr_t tr = transposed_image(b, extend(input, extension), comp_transf);
00150 
00151       typedef mln_site(I) P;
00152       P rpmin = P(rot(input.domain().pmin().to_vec()));
00153 
00154       mln_concrete(I) output;
00155       initialize(output, tr);
00156 
00157       data::paste(tr, output);
00158 
00159       trace::exiting("geom::rotate");
00160       return output;
00161     }
00162 
00163 
00164     template <typename I, typename Ext>
00165     mln_concrete(I)
00166     rotate(const Image<I>& input, double angle, const Ext& extension)
00167     {
00168       // Old versions of GCC (including Apple GCC 4.0.1) do not parse
00169       // correctly `mln_box(I)()'.  Hence, we need to typedef
00170       // `mln_box(I)' first.
00171       typedef mln_domain(I) domain_t;
00172       return rotate(input, angle, extension, domain_t());
00173     }
00174 
00175 
00176     template <typename I>
00177     mln_concrete(I)
00178     rotate(const Image<I>& input, double angle)
00179     {
00180       return rotate(input, angle, literal::zero);
00181     }
00182 
00183 
00184 # endif // ! MLN_INCLUDE_ONLY
00185 
00186 
00187   } // end of namespace mln::geom
00188 
00189 } // end of namespace mln
00190 
00191 
00192 #endif // ! MLN_GEOM_ROTATE_HH

Generated on Thu Sep 8 2011 18:32:23 for Milena (Olena) by  doxygen 1.7.1