Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_CONTAINERS_GRID_UTIL_GRID_BOX_FILTER_H
00002 #define OPENTISSUE_CORE_CONTAINERS_GRID_UTIL_GRID_BOX_FILTER_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <boost/lambda/lambda.hpp>
00013 #include <cmath>
00014
00015 namespace OpenTissue
00016 {
00017 namespace grid
00018 {
00027 template <typename grid_type>
00028 inline void box_filter(grid_type const& src, size_t size, grid_type & dst)
00029 {
00030 typedef typename grid_type::value_type value_type;
00031
00032 grid_type tmp=src;
00033
00034 size_t center=size/2;
00035 for(size_t x=0; x<src.I(); ++x)
00036 for(size_t y=0; y<src.J(); ++y)
00037 {
00038 value_type sum= value_type(0);
00039
00040 for(size_t z=0; z<src.K()+center; ++z)
00041 {
00042 if(z<src.K())
00043 sum+=tmp(x,y,z);
00044 if(z>=size)
00045 sum-=tmp(x,y,z-size);
00046 if(z>=center)
00047 dst(x,y,z-center)=sum;
00048 }
00049 }
00050 tmp = dst;
00051 for(size_t x=0; x<src.I(); ++x)
00052 for(size_t z=0; z<src.K(); ++z)
00053 {
00054 value_type sum= value_type(0);
00055 for(size_t y=0; y<src.J()+center; ++y)
00056 {
00057 if(y<src.J())
00058 sum+=tmp(x,y,z);
00059 if(y>=size)
00060 sum-=tmp(x,y-size,z);
00061 if(y>=center)
00062 dst(x,y-center,z)=sum;
00063 }
00064 }
00065 tmp=dst;
00066 for(size_t y=0; y<src.J(); ++y)
00067 for(size_t z=0; z<src.K(); ++z)
00068 {
00069 value_type sum= value_type(0);
00070 for(size_t x=0; x<src.I()+center; ++x)
00071 {
00072 if(x<src.I())
00073 sum+=tmp(x,y,z);
00074 if(x>=size)
00075 sum-=tmp(x-size,y,z);
00076 if(x>=center)
00077 dst(x-center,y,z)=sum;
00078 }
00079 }
00080
00081 std::for_each(
00082 dst.begin()
00083 , dst.end()
00084 , boost::lambda::_1 *= boost::lambda::make_const( 1.0/pow(static_cast<double>(size),3) )
00085 );
00086 }
00087
00088 }
00089 }
00090
00091
00092 #endif