1 #ifndef TIL_IMAGEEXTRAPOLATOR_H 2 #define TIL_IMAGEEXTRAPOLATOR_H 49 #define TIL_EXTRAPOL_FUNC(imname, posname) \ 50 template < typename TImage > \ 52 static typename TImage::value_type \ 53 getValue(const TImage &im, numeric_array<int,3> pos) \ 54 { if (contains(im,pos)) { return im.getUnsafeValue(pos); } \ 55 else { return Self::getExtrapolatedValue(im, pos); } } \ 57 template < typename TImage > \ 59 static typename TImage::value_type \ 60 getExtrapolatedValue(const TImage & imname, numeric_array<int,3> posname) \ 83 throw std::out_of_range(
mySprintf(
"Coordinates out of image range: (%i, %i, %i)", pos[0], pos[1], pos[2])); }
98 return typename TImage::value_type();
114 if (pos[0]<0) pos[0]=0;
else if (pos[0] >= im.dim()[0]) pos[0] = im.dim()[0]-1;
115 if (pos[1]<0) pos[1]=0;
else if (pos[1] >= im.dim()[1]) pos[1] = im.dim()[1]-1;
116 if (pos[2]<0) pos[2]=0;
else if (pos[2] >= im.dim()[2]) pos[2] = im.dim()[2]-1;
121 return im.getUnsafeValue(pos);
139 Self::mirror(pos[0], im.dim()[0]-1);
140 Self::mirror(pos[1], im.dim()[1]-1);
141 Self::mirror(pos[2], im.dim()[2]-1);
142 return im.getUnsafeValue(pos);
147 static void mirror(
int &i,
int n)
150 if (i > n) i = 2*n - i;
167 Self::cyclic(pos[0], im.dim()[0]);
168 Self::cyclic(pos[1], im.dim()[1]);
169 Self::cyclic(pos[2], im.dim()[2]);
170 return im.getUnsafeValue(pos);
175 static void cyclic(
int &i,
int n)
195 template <
typename TImage >
197 static typename TImage::value_type
199 {
return im.getUnsafeValue(pos); }
201 template <
typename TImage >
203 static typename TImage::value_type
205 {
return im.getUnsafeValue(pos); }
209 #undef TIL_EXTRAPOL_FUNC 230 template <
class TImageExtrapolator,
class TImage >
242 return this->getUnsafeValue(p);
246 return TImageExtrapolator::getExtrapolatedValue(*
this, p);
256 template <
class TImageExtrapolator,
class TImage >
ExtrapolableImage< TImageExtrapolator, TImage > extrapolable(const TImage &im)
Belongs to package Box Do not include directly, include til/Box.h instead.
General macros, definitions and functions.
Defines empty classes that serves as labels.
numeric_array< T, D > abs(const numeric_array< T, D > &a)
Absolute value, element-wise.
boost::enable_if< is_numeric_container< TStorage >, bool >::type contains(const Box< T, D > &box, const TStorage &v)
Check whether a point lies within box.
TIL_API char * mySprintf(const char *format,...)