3387: Add fun::x2v::trilinear.
* mln/fun/x2v/trilinear.hh: new file. New interpolation algorithm. * mln/fun/x2v/all.hh: include new file. --- milena/mln/fun/x2v/all.hh | 12 ++-- milena/mln/fun/x2v/trilinear.hh | 139 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 146 insertions(+), 5 deletions(-) create mode 100644 milena/mln/fun/x2v/trilinear.hh diff --git a/milena/mln/fun/x2v/all.hh b/milena/mln/fun/x2v/all.hh index 91c4562..d8ba3ae 100644 --- a/milena/mln/fun/x2v/all.hh +++ b/milena/mln/fun/x2v/all.hh @@ -1,4 +1,5 @@ -// Copyright (C) 2008 EPITA Research and Development Laboratory +// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory +// (LRDE) // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -28,10 +29,10 @@ #ifndef MLN_FUN_X2V_ALL_HH # define MLN_FUN_X2V_ALL_HH -/*! \file mln/fun/x2v/all.hh - * - * \brief File that includes all functions from vector to value. - */ +/// \file mln/fun/x2v/all.hh +/// +/// File that includes all functions from vector to value. + namespace mln @@ -57,5 +58,6 @@ namespace mln # include <mln/fun/x2v/linear.hh> # include <mln/fun/x2v/bilinear.hh> # include <mln/fun/x2v/nneighbor.hh> +# include <mln/fun/x2v/trilinear.hh> #endif // ! MLN_FUN_X2V_ALL_HH diff --git a/milena/mln/fun/x2v/trilinear.hh b/milena/mln/fun/x2v/trilinear.hh new file mode 100644 index 0000000..3015502 --- /dev/null +++ b/milena/mln/fun/x2v/trilinear.hh @@ -0,0 +1,139 @@ +// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory +// (LRDE) +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef MLN_FUN_X2V_TRILINEAR_HH +# define MLN_FUN_X2V_TRILINEAR_HH + +# include <mln/core/image/image2d.hh> +# include <mln/core/concept/function.hh> +# include <mln/fun/internal/selector.hh> +# include <mln/convert/to.hh> +# include <mln/algebra/vec.hh> + +/// \file mln/fun/x2v/trilinear.hh +/// +/// Define a trilinear interpolation of values from an underlying image +/// +/// Source: http://en.wikipedia.org/wiki/Rotation_matrix + +namespace mln +{ + + namespace fun + { + + namespace x2v + { + + /// Represent a trilinear interolation of values from an underlying image + /// + template < typename I > + struct trilinear + : public fun::internal::selector_<const algebra::vec<3,float>, + // 3,float is a dummy parameter (real is n,T) + mln_value(I), trilinear<I> >::ret + { + typedef mln_value(I) result; + + trilinear(const I& ima); + + template <typename T> + mln_value(I) + operator()(const algebra::vec<3,T>& v) const; + + const I& ima; + }; + + +# ifndef MLN_INCLUDE_ONLY + + template <typename I> + trilinear<I>::trilinear(const I& ima) : ima(ima) + { + mlc_bool(I::psite::dim == 3)::check(); + } + + + template <typename I> + template <typename T> + mln_value(I) + trilinear<I>::operator()(const algebra::vec<3,T>& v) const + { + typedef mln_sum(mln_value(I)) vsum; + + double x = v[1]; // row + double y = v[2]; // col + double z = v[0]; // sli + + math::round<double> f; + unsigned x1 = f(std::floor(x)); + unsigned x2 = f(std::floor(x) + 1); + unsigned y1 = f(std::floor(y)); + unsigned y2 = f(std::floor(y) + 1); + unsigned z1 = f(std::floor(z)); + unsigned z2 = f(std::floor(z) + 1); + + double xd = x - x1; + double yd = y - y1; + double zd = z - z1; + + // interpolating in z direction + // Following access are supposed valid. + vsum i1 = ima(point3d(z1,x1,y1)) * (1 - zd) + + ima(point3d(z2,x1,y1)) * zd; + + vsum i2 = ima(point3d(z1,x1,y2)) * (1 - zd) + + ima(point3d(z2,x1,y2)) * zd; + + vsum j1 = ima(point3d(z1,x2,y1)) * (1 - zd) + + ima(point3d(z2,x2,y1)) * zd; + + vsum j2 = ima(point3d(z1,x2,y2)) * (1 - zd) + + ima(point3d(z2,x2,y2)) * zd; + + // interpolating in y direction + vsum w1 = i1 * (1 - yd) + i2 * yd; + vsum w2 = j1 * (1 - yd) + j2 * yd; + + // interpolating in x direction + vsum res = w1 * (1 - xd) + w2 * xd; + + return convert::to<mln_value(I)>(res); + } + + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::fun::x2v + + } // end of namespace mln::fun + +} // end of namespace mln + + +#endif // ! MLN_FUN_X2V_TRILINEAR_HH -- 1.5.6.5
participants (1)
-
Guillaume Lazzara