se_stat.hh

00001 // Copyright (C) 2004  EPITA Research and Development Laboratory
00002 //
00003 // This file is part of the Olena Library.  This library is free
00004 // software; you can redistribute it and/or modify it under the terms
00005 // of the GNU General Public License version 2 as published by the
00006 // Free Software Foundation.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this library; see the file COPYING.  If not, write to
00015 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
00016 // MA 02111-1307, USA.
00017 //
00018 // As a special exception, you may use this file as part of a free
00019 // software library without restriction.  Specifically, if other files
00020 // instantiate templates or use macros or inline functions from this
00021 // file, or you compile this file and link it with other files to
00022 // produce an executable, this file does not by itself cause the
00023 // resulting executable to be covered by the GNU General Public
00024 // License.  This exception does not however invalidate any other
00025 // reasons why the executable file might be covered by the GNU General
00026 // Public License.
00027 
00028 
00029 #ifndef OLN_UTILS_SE_STAT_HH
00030 # define OLN_UTILS_SE_STAT_HH
00031 
00032 # include <oln/core/abstract/point.hh>
00033 # include <oln/core/abstract/image.hh>
00034 # include <oln/core/abstract/struct_elt.hh>
00035 
00036 # include <ntg/core/abstract_hierarchy.hh>
00037 # include <ntg/all.hh>
00038 # include <ntg/core/macros.hh>
00039 # include <oln/math/macros.hh>
00040 
00041 namespace oln {
00042   namespace utils {
00043     namespace internal {
00063       template <typename DestT,
00064                 typename SrcT>
00065       struct f_to_float_
00066       {
00067         static
00068         DestT
00069         doit(const SrcT& s)
00070         {
00071           return s;
00072         }
00073       };
00074 
00076       template <unsigned ncomps,
00077                 unsigned qbits,
00078                 template <unsigned> class color_system>
00079       struct f_to_float_<typename ntg::color<ncomps,
00080                                              qbits,
00081                                              color_system>::float_vec_type,
00082                          ntg::color<ncomps, qbits, color_system> >
00083       {
00084         static
00085         typename ntg::color<ncomps, qbits, color_system>::float_vec_type
00086         doit(const ntg::color<ncomps, qbits, color_system>& s)
00087         {
00088           return s.to_float();
00089         }
00090       };
00091     } // end namespace internal
00092 
00093 
00102     template <typename Sum = ntg::float_s, typename Var = ntg::float_s>
00103     class se_stat
00104     {
00105     public:
00107       typedef Sum sum_type;
00109       typedef Var variance_type;
00110 
00116       template <class I, class S>
00117       se_stat(const oln::abstract::image<I> &im,
00118               const oln_point_type(I) &p,
00119               const oln::abstract::struct_elt<S> &s)
00120       {
00121         compute(im, p, s);
00122       }
00123 
00125       template <class I, class S>
00126       se_stat &
00127       compute(const oln::abstract::image<I> &im,
00128               const oln_point_type(I) &p,
00129               const oln::abstract::struct_elt<S> &s);
00130 
00132       inline Sum
00133       mean() const
00134       {
00135         return mean_;
00136       }
00137 
00139       inline Var
00140       variance() const
00141       {
00142         return variance_;
00143       }
00144 
00146       inline Sum
00147       sum() const
00148       {
00149         return sum_;
00150       }
00151 
00153       inline unsigned
00154       card() const
00155       {
00156         return card_;
00157       }
00158 
00159     protected:
00160       Var variance_;    
00161       Sum mean_;        
00162       Sum sum_;         
00163       int card_;        
00164     };
00165 
00166   } // end namespace utils
00167 
00168 } // end namespace oln
00169 
00170 #include "se_stat.hxx"
00171 
00172 #endif 

Generated on Thu Apr 15 20:13:14 2004 for Olena by doxygen 1.3.6-20040222