1 #ifndef TIL_NEIGHBORHOOD_CONFIGURATION_H 2 #define TIL_NEIGHBORHOOD_CONFIGURATION_H 19 template <
class _TImage,
class _TNeighborhood>
44 void setForeground(value_type foreground) { m_foreground = foreground; }
45 void setBackground(value_type background) { m_background = background; }
66 value_type m_foreground;
67 value_type m_background;
71 template <
class TVolumetricIterator,
class _TNeighborhood = Neighborhood>
77 typedef typename TVolumetricIterator::value_type
value_type;
83 : m_foreground(1), m_background(0),
m_nh()
89 : m_foreground(1), m_background(0),
m_nh(nh) {};
92 : m_foreground(foreground), m_background(background),
m_nh(nh) {};
111 const value_type m_foreground;
113 const value_type m_background;
123 template <
class _TImage,
class _TNeighborhood = Neighborhood >
144 this->cond<-1, 0, 0>(iIm) &&
145 this->cond< 0,-1, 0>(iIm) &&
146 this->cond< 0, 0,-1>(iIm) &&
147 this->cond<+1, 0, 0>(iIm) &&
148 this->cond< 0,+1, 0>(iIm) &&
149 this->cond< 0, 0,+1>(iIm) &&
152 this->cond<-1,-1, 0>(iIm) &&
153 this->cond<-1, 0,-1>(iIm) &&
154 this->cond< 0,-1,-1>(iIm) &&
155 this->cond<+1,+1, 0>(iIm) &&
156 this->cond<+1, 0,+1>(iIm) &&
157 this->cond< 0,+1,+1>(iIm) &&
158 this->cond<-1,+1, 0>(iIm) &&
159 this->cond<-1, 0,+1>(iIm) &&
160 this->cond< 0,-1,+1>(iIm) &&
161 this->cond<+1,-1, 0>(iIm) &&
162 this->cond<+1, 0,-1>(iIm) &&
163 this->cond< 0,+1,-1>(iIm) &&
166 this->cond<-1,-1,-1>(iIm) &&
167 this->cond<+1,+1,+1>(iIm) &&
168 this->cond<+1,-1,-1>(iIm) &&
169 this->cond<-1,+1,-1>(iIm) &&
170 this->cond<-1,-1,+1>(iIm) &&
171 this->cond<-1,+1,+1>(iIm) &&
172 this->cond<+1,-1,+1>(iIm) &&
173 this->cond<+1,+1,-1>(iIm)
192 return _compute(iIm);
197 template <
int i,
int j,
int k>
198 bool cond(
const ConstVolumetricIterator &iIm)
const 201 !this->
m_nh.template isNeighbor<i,j,k>() ||
202 !containsNeighbor<i,j,k>(iIm) ||
203 iIm.template getUnsafeValue<i,j,k>() == this->getForeground()
212 template <
class _TImage,
class _TNeighborhood = Neighborhood >
233 this->cond<-1, 0, 0>(iIm) ||
234 this->cond< 0,-1, 0>(iIm) ||
235 this->cond< 0, 0,-1>(iIm) ||
236 this->cond<+1, 0, 0>(iIm) ||
237 this->cond< 0,+1, 0>(iIm) ||
238 this->cond< 0, 0,+1>(iIm) ||
241 this->cond<-1,-1, 0>(iIm) ||
242 this->cond<-1, 0,-1>(iIm) ||
243 this->cond< 0,-1,-1>(iIm) ||
244 this->cond<+1,+1, 0>(iIm) ||
245 this->cond<+1, 0,+1>(iIm) ||
246 this->cond< 0,+1,+1>(iIm) ||
247 this->cond<-1,+1, 0>(iIm) ||
248 this->cond<-1, 0,+1>(iIm) ||
249 this->cond< 0,-1,+1>(iIm) ||
250 this->cond<+1,-1, 0>(iIm) ||
251 this->cond<+1, 0,-1>(iIm) ||
252 this->cond< 0,+1,-1>(iIm) ||
255 this->cond<-1,-1,-1>(iIm) ||
256 this->cond<+1,+1,+1>(iIm) ||
257 this->cond<+1,-1,-1>(iIm) ||
258 this->cond<-1,+1,-1>(iIm) ||
259 this->cond<-1,-1,+1>(iIm) ||
260 this->cond<-1,+1,+1>(iIm) ||
261 this->cond<+1,-1,+1>(iIm) ||
262 this->cond<+1,+1,-1>(iIm)
281 return _compute(iIm);
286 template <
int i,
int j,
int k>
287 bool cond(
const ConstVolumetricIterator &iIm)
const 290 this->
m_nh.template isNeighbor<i,j,k>() &&
291 containsNeighbor<i,j,k>(iIm) &&
292 iIm.template getUnsafeValue<i,j,k>() != this->getForeground()
299 template <
class _TImage,
class _TNeighborhood = Neighborhood >
322 this->cond<-1, 0, 0>(iIm) &&
323 this->cond< 0,-1, 0>(iIm) &&
324 this->cond< 0, 0,-1>(iIm) &&
325 this->cond<+1, 0, 0>(iIm) &&
326 this->cond< 0,+1, 0>(iIm) &&
327 this->cond< 0, 0,+1>(iIm) &&
330 this->cond<-1,-1, 0>(iIm) &&
331 this->cond<-1, 0,-1>(iIm) &&
332 this->cond< 0,-1,-1>(iIm) &&
333 this->cond<+1,+1, 0>(iIm) &&
334 this->cond<+1, 0,+1>(iIm) &&
335 this->cond< 0,+1,+1>(iIm) &&
336 this->cond<-1,+1, 0>(iIm) &&
337 this->cond<-1, 0,+1>(iIm) &&
338 this->cond< 0,-1,+1>(iIm) &&
339 this->cond<+1,-1, 0>(iIm) &&
340 this->cond<+1, 0,-1>(iIm) &&
341 this->cond< 0,+1,-1>(iIm) &&
344 this->cond<-1,-1,-1>(iIm) &&
345 this->cond<+1,+1,+1>(iIm) &&
346 this->cond<+1,-1,-1>(iIm) &&
347 this->cond<-1,+1,-1>(iIm) &&
348 this->cond<-1,-1,+1>(iIm) &&
349 this->cond<-1,+1,+1>(iIm) &&
350 this->cond<+1,-1,+1>(iIm) &&
351 this->cond<+1,+1,-1>(iIm)
370 return this->_compute(iIm);
376 template <
int i,
int j,
int k>
377 bool cond(
const ConstVolumetricIterator &iIm)
const 380 !this->
m_nh.template isNeighbor<i,j,k>() ||
381 !containsNeighbor<i,j,k>(iIm) ||
382 iIm.template getUnsafeValue<i,j,k>() == this->getBackground()
388 template <
class TVolumetricIterator,
class _TNeighborhood = Neighborhood >
391 public std::unary_function<TVolumetricIterator, bool>
410 IsIsolated(value_type foreground, value_type background,
const TNeighborhood &nh = _TNeighborhood())
411 : Base(foreground, background, nh) {}
422 this->cond<-1, 0, 0>(iIm) &&
423 this->cond< 0,-1, 0>(iIm) &&
424 this->cond< 0, 0,-1>(iIm) &&
425 this->cond<+1, 0, 0>(iIm) &&
426 this->cond< 0,+1, 0>(iIm) &&
427 this->cond< 0, 0,+1>(iIm) &&
430 this->cond<-1,-1, 0>(iIm) &&
431 this->cond<-1, 0,-1>(iIm) &&
432 this->cond< 0,-1,-1>(iIm) &&
433 this->cond<+1,+1, 0>(iIm) &&
434 this->cond<+1, 0,+1>(iIm) &&
435 this->cond< 0,+1,+1>(iIm) &&
436 this->cond<-1,+1, 0>(iIm) &&
437 this->cond<-1, 0,+1>(iIm) &&
438 this->cond< 0,-1,+1>(iIm) &&
439 this->cond<+1,-1, 0>(iIm) &&
440 this->cond<+1, 0,-1>(iIm) &&
441 this->cond< 0,+1,-1>(iIm) &&
444 this->cond<-1,-1,-1>(iIm) &&
445 this->cond<+1,+1,+1>(iIm) &&
446 this->cond<+1,-1,-1>(iIm) &&
447 this->cond<-1,+1,-1>(iIm) &&
448 this->cond<-1,-1,+1>(iIm) &&
449 this->cond<-1,+1,+1>(iIm) &&
450 this->cond<+1,-1,+1>(iIm) &&
451 this->cond<+1,+1,-1>(iIm)
472 return this->_compute(iIm);
478 template <
int i,
int j,
int k >
479 bool cond(
const TVolumetricIterator &iIm)
const 482 !this->
m_nh.template isNeighbor<i,j,k>() ||
483 !containsNeighbor<i,j,k>(iIm) ||
484 iIm.template getUnsafeValue<i,j,k>() == this->getBackground()
490 template <
class _TImage,
class _TNeighborhood = Neighborhood >
505 this->setNNeighbors(nNeighbors);
522 if (this->cond<-1, 0, 0>(iIm)) { ++count;
if (count >= m_nNeighbors)
return true; }
523 if (this->cond< 0,-1, 0>(iIm)) { ++count;
if (count >= m_nNeighbors)
return true; }
524 if (this->cond< 0, 0,-1>(iIm)) { ++count;
if (count >= m_nNeighbors)
return true; }
526 if (this->cond<+1, 0, 0>(iIm)) { ++count;
if (count >= m_nNeighbors)
return true; }
527 if (this->cond< 0,+1, 0>(iIm)) { ++count;
if (count >= m_nNeighbors)
return true; }
528 if (this->cond< 0, 0,+1>(iIm)) { ++count;
if (count >= m_nNeighbors)
return true; }
531 if (this->cond<-1,-1, 0>(iIm)) { ++count;
if (count >= m_nNeighbors)
return true; }
532 if (this->cond<-1, 0,-1>(iIm)) { ++count;
if (count >= m_nNeighbors)
return true; }
533 if (this->cond< 0,-1,-1>(iIm)) { ++count;
if (count >= m_nNeighbors)
return true; }
535 if (this->cond<+1,+1, 0>(iIm)) { ++count;
if (count >= m_nNeighbors)
return true; }
536 if (this->cond<+1, 0,+1>(iIm)) { ++count;
if (count >= m_nNeighbors)
return true; }
537 if (this->cond< 0,+1,+1>(iIm)) { ++count;
if (count >= m_nNeighbors)
return true; }
539 if (this->cond<-1,+1, 0>(iIm)) { ++count;
if (count >= m_nNeighbors)
return true; }
540 if (this->cond<-1, 0,+1>(iIm)) { ++count;
if (count >= m_nNeighbors)
return true; }
541 if (this->cond< 0,-1,+1>(iIm)) { ++count;
if (count >= m_nNeighbors)
return true; }
543 if (this->cond<+1,-1, 0>(iIm)) { ++count;
if (count >= m_nNeighbors)
return true; }
544 if (this->cond<+1, 0,-1>(iIm)) { ++count;
if (count >= m_nNeighbors)
return true; }
545 if (this->cond< 0,+1,-1>(iIm)) { ++count;
if (count >= m_nNeighbors)
return true; }
548 if (this->cond<-1,-1,-1>(iIm)) { ++count;
if (count >= m_nNeighbors)
return true; }
549 if (this->cond<+1,+1,+1>(iIm)) { ++count;
if (count >= m_nNeighbors)
return true; }
551 if (this->cond<+1,-1,-1>(iIm)) { ++count;
if (count >= m_nNeighbors)
return true; }
552 if (this->cond<-1,+1,-1>(iIm)) { ++count;
if (count >= m_nNeighbors)
return true; }
553 if (this->cond<-1,-1,+1>(iIm)) { ++count;
if (count >= m_nNeighbors)
return true; }
555 if (this->cond<-1,+1,+1>(iIm)) { ++count;
if (count >= m_nNeighbors)
return true; }
556 if (this->cond<+1,-1,+1>(iIm)) { ++count;
if (count >= m_nNeighbors)
return true; }
557 if (this->cond<+1,+1,-1>(iIm)) { ++count;
if (count >= m_nNeighbors)
return true; }
570 return this->_compute(iIm);
575 template <
int i,
int j,
int k >
576 INLINE bool cond(
const ConstVolumetricIterator &iIm)
const 579 this->
m_nh.template isNeighbor<i,j,k>() &&
580 containsNeighbor<i,j,k>(iIm) &&
581 iIm.template getUnsafeValue<i,j,k>() == this->getBackground()
Iterator< TImage >::ConstVolumetric ConstVolumetricIterator
A trait class to assign iterators to image types.
INLINE bool compute(const ConstVolumetricIterator &iIm) const
TImage::value_type value_type
INLINE bool compute(const ConstVolumetricIterator &iIm) const
TImage::value_type value_type
TVolumetricIterator::value_type value_type
_TNeighborhood TNeighborhood
PT_NeighborhoodConfigurations(const TNeighborhood &nh)
PT_IsBoundary(const TNeighborhood &nh=_TNeighborhood())
_TNeighborhood TNeighborhood
Belongs to package Box Do not include directly, include til/Box.h instead.
value_type getBackground() const
NeighborhoodConfigurations(const TNeighborhood &nh)
_TNeighborhood TNeighborhood
Iterator< TImage >::ConstVolumetric ConstVolumetricIterator
General macros, definitions and functions.
Defines empty classes that serves as labels.
NeighborhoodConfigurations()
Iterator< TImage >::ConstVolumetric ConstVolumetricIterator
PT_IsInterior(const TNeighborhood &nh=_TNeighborhood())
INLINE bool _compute(const ConstVolumetricIterator &iIm) const
INLINE bool _compute(const ConstVolumetricIterator &iIm) const
_TNeighborhood TNeighborhood
INLINE bool _compute(const ConstVolumetricIterator &iIm) const
void setNNeighbors(int nNeighbors)
_TNeighborhood TNeighborhood
INLINE bool _compute(const ConstVolumetricIterator &iIm) const
INLINE bool compute(const ConstVolumetricIterator &iIm) const
_TNeighborhood TNeighborhood
value_type getBackground() const
value_type getForeground() const
IsIsolated(value_type foreground, value_type background, const TNeighborhood &nh=_TNeighborhood())
TImage::value_type value_type
Iterator< TImage >::ConstVolumetric ConstVolumetricIterator
INLINE bool operator()(const TVolumetricIterator &iIm) const
void setForeground(value_type foreground)
NeighborhoodConfigurations< TVolumetricIterator, _TNeighborhood > Base
INLINE bool _compute(const TVolumetricIterator &iIm) const
INLINE bool compute(const ConstVolumetricIterator &iIm) const
TImage::value_type value_type
PT_HasNBackgroundNeighbors(int nNeighbors, const TNeighborhood &nh=_TNeighborhood())
TVolumetricIterator::value_type value_type
void setBackground(value_type background)
PT_IsIsolated(const TNeighborhood &nh=_TNeighborhood())
_TNeighborhood TNeighborhood
value_type getForeground() const
TImage::value_type value_type
IsIsolated(const TNeighborhood &nh)
NeighborhoodConfigurations(value_type foreground, value_type background, const TNeighborhood &nh=TNeighborhood())
Iterator< TImage >::ConstVolumetric ConstVolumetricIterator