Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_CONTAINERS_GRID_UTIL_TRANSLATE_H
00002 #define OPENTISSUE_CORE_CONTAINERS_GRID_UTIL_TRANSLATE_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <boost/iterator/reverse_iterator.hpp>
00013
00014 #include <cstdlib>
00015
00016 namespace OpenTissue
00017 {
00018 namespace grid
00019 {
00030 template <typename grid_type, typename vector3_int_type>
00031 inline void translate(grid_type const& src, vector3_int_type const& v, grid_type & dst)
00032 {
00033 assert( v(0)>0 && !"translate(): Only works for positive translations for now");
00034 assert( v(1)>0 && !"translate(): Only works for positive translations for now");
00035 assert( v(2)>0 && !"translate(): Only works for positive translations for now");
00036
00037 typedef typename grid_type::const_index_iterator const_index_iterator;
00038 typedef typename grid_type::math_types math_types;
00039 typedef typename math_types::vector3_type vector3_type;
00040
00041
00042 vector3_int_type t=v;
00043
00044
00045
00046
00047
00048
00049
00050
00051 grid_type tmp;
00052 tmp.create(vector3_type(0,0,0), vector3_type(1,1,1), t(0), t(1), t(2));
00053 size_t ti = src.I()-t(0);
00054 size_t tj = src.J()-t(1);
00055 size_t tk = src.K()-t(2);
00056 size_t lk=0;
00057 size_t lj=0;
00058 size_t li=0;
00059 for (size_t gk=tk; gk<src.K(); ++gk, ++lk)
00060 for (size_t gj=tj; gj<src.J(); ++gj, ++lj)
00061 for (size_t gi=ti; gi<src.I(); ++gi, ++li)
00062 tmp(li,lj,lk) = src(gi,gj,gk);
00063
00064
00065
00066
00067
00068
00069
00070
00071 for(const_index_iterator p=src.end()-1; p!=src.begin()-1; --p)
00072 {
00073 dst( (p.i()+t(0))%src.I(), (p.j()+t(1))%src.J(), (p.k()+t(2))%src.K() ) = *p;
00074 }
00075
00076 for (size_t k=0; k<tmp.K(); ++k)
00077 for (size_t j=0; j<tmp.J(); ++j)
00078 for (size_t i=0; i<tmp.I(); ++i)
00079 dst(i,j,k) = tmp(i,j,k);
00080 }
00081
00082 }
00083
00084 }
00085
00086
00087 #endif