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

stretch.hh

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 #ifndef MLN_DATA_STRETCH_HH
00027 # define MLN_DATA_STRETCH_HH
00028 
00037 
00038 # include <mln/estim/min_max.hh>
00039 # include <mln/value/int_u.hh>
00040 # include <mln/fun/v2v/linear.hh>
00041 # include <mln/data/transform.hh>
00042 
00043 
00044 # include <mln/value/internal/encoding.hh>
00045 # include <iomanip>
00046 namespace mln
00047 {
00048 
00049   namespace data
00050   {
00051 
00062     template <typename V, typename I>
00063     mln_ch_value(I, V)
00064     stretch(const V& v, const Image<I>& input);
00065 
00066 
00067 # ifndef MLN_INCLUDE_ONLY
00068 
00069     namespace impl
00070     {
00071 
00078       //
00079       template <typename V, typename I>
00080       inline
00081       mln_ch_value(I, V)
00082       stretch(const V& v, const Image<I>& input)
00083       {
00084         trace::entering("data::impl::stretch");
00085 
00086         (void) v;
00087         mlc_converts_to(float, V)::check();
00088 
00089         mln_ch_value(I, V) output;
00090 
00091         mln_value(I) min_, max_;
00092         estim::min_max(input, min_, max_);
00093         if (max_ != min_)
00094           {
00095             //FIXME: we would like to use float instead of double but we
00096             //can't for precision reasons. See ticket #179.
00097             double
00098               min = double(min_),
00099               max = double(max_),
00100               epsilon = mln_epsilon(float),
00101               M = mln_max(V) + 0.5f - epsilon,
00102               m = 0.0f - 0.5f + epsilon,
00103               a = (M - m) / (max - min),
00104               b = (m * max - M * min) / (max - min);
00105             fun::v2v::linear_sat<mln_value(I), double, V> f(a, b);
00106             output = data::transform(input, f);
00107           }
00108         else
00109           {
00110             initialize(output, input);
00111             trace::warning("output has no significative data!");
00112           }
00113 
00114         trace::exiting("data::impl::stretch");
00115         return output;
00116       }
00117 
00118     } // end of namespace mln::data::impl
00119 
00120 
00121 
00122     // Facade
00123 
00124     template <typename V, typename I>
00125     inline
00126     mln_ch_value(I, V)
00127     stretch(const V& v, const Image<I>& input)
00128     {
00129       trace::entering("data::stretch");
00130 
00131       (void) v;
00132       mln_precondition(exact(input).is_valid());
00133 
00134       mln_ch_value(I, V) output = impl::stretch(V(), input);
00135 
00136       trace::exiting("data::stretch");
00137       return output;
00138     }
00139 
00140 # endif // ! MLN_INCLUDE_ONLY
00141 
00142   } // end of namespace mln::data
00143 
00144 } // end of namespace mln
00145 
00146 
00147 #endif // ! MLN_DATA_STRETCH_HH

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