Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_CONTAINERS_GRID_UTIL_BLOCKIFY_H
00002 #define OPENTISSUE_CORE_CONTAINERS_GRID_UTIL_BLOCKIFY_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <boost/cast.hpp>
00013
00014 #include <iostream>
00015 #include <cmath>
00016 #include <algorithm>
00017
00018 namespace OpenTissue
00019 {
00020 namespace grid
00021 {
00029 template<typename grid_type>
00030 inline void blockify(grid_type & phi)
00031 {
00032 typedef typename grid_type::value_type value_type;
00033 typedef typename grid_type::index_iterator iterator;
00034
00035 value_type unused = phi.unused();
00036 value_type inside = value_type(-1.0);
00037 value_type outside = value_type( 1.0);
00038
00039 size_t offset = 7u;
00040 size_t spacing = 11u;
00041 size_t block = offset + spacing;
00042 iterator begin = phi.begin();
00043 iterator end = phi.end();
00044 iterator p;
00045 for(p=begin;p!=end;++p)
00046 {
00047 if(*p==unused)
00048 continue;
00049
00050 bool inside_i = ((p.i() % block)>offset);
00051 bool inside_j = ((p.j() % block)>offset);
00052 bool inside_k = ((p.k() % block)>offset);
00053 if(inside_i && inside_j && inside_k)
00054 *p = inside;
00055 else
00056 *p = outside;
00057 }
00058 }
00059
00068 template<typename grid_type,typename value_type>
00069 inline void blockify(grid_type & phi, value_type inside, value_type outside, size_t offset, size_t spacing)
00070 {
00071 typedef typename grid_type::value_type internal_type;
00072 typedef typename grid_type::index_iterator iterator;
00073
00074 internal_type unused = phi.unused();
00075 internal_type inside_ = boost::numeric_cast<internal_type>( inside );
00076 internal_type outside_ = boost::numeric_cast<internal_type>( outside );
00077
00078 size_t block = offset + spacing;
00079 iterator begin = phi.begin();
00080 iterator end = phi.end();
00081 iterator p;
00082 for(p=begin;p!=end;++p)
00083 {
00084 if(*p==unused)
00085 continue;
00086
00087 bool inside_i = ((p.i() % block)>offset);
00088 bool inside_j = ((p.j() % block)>offset);
00089 bool inside_k = ((p.k() % block)>offset);
00090 if(inside_i && inside_j && inside_k)
00091 *p = inside_;
00092 else
00093 *p = outside_;
00094 }
00095 }
00096
00106 template<typename grid_type,typename value_type>
00107 inline void blockify(grid_type & phi, value_type inside, value_type outside, size_t offset, size_t spacing, size_t slice)
00108 {
00109 typedef typename grid_type::value_type internal_type;
00110 typedef typename grid_type::index_iterator iterator;
00111
00112 internal_type unused = phi.unused();
00113 internal_type inside_ = boost::numeric_cast<internal_type>( inside );
00114 internal_type outside_ = boost::numeric_cast<internal_type>( outside );
00115
00116 size_t block = offset + spacing;
00117 iterator begin = phi.begin();
00118 iterator end = phi.end();
00119 iterator p;
00120 for(p=begin;p!=end;++p)
00121 {
00122 if (p.k()!=slice)
00123 continue;
00124 if(*p==unused)
00125 continue;
00126 bool inside_i = ((p.i() % block)>offset);
00127 bool inside_j = ((p.j() % block)>offset);
00128 if(inside_i && inside_j)
00129 *p = inside_;
00130 else
00131 *p = outside_;
00132 }
00133 }
00134
00135
00136 }
00137 }
00138
00139
00140 #endif