| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkZeroFluxNeumannBoundaryCondition.txx.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:49 $ |
| 7 |
|
Version: $Revision: 1.4 $ |
| 8 |
|
|
| 9 |
|
Copyright (c) Insight Software Consortium. All rights reserved. |
| 10 |
|
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. |
| 11 |
|
|
| 12 |
|
This software is distributed WITHOUT ANY WARRANTY; without even |
| 13 |
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 |
|
PURPOSE. See the above copyright notices for more information. |
| 15 |
|
|
| 16 |
|
=========================================================================*/ |
| 17 |
|
#ifndef __itkZeroFluxNeumannBoundaryCondition_txx |
| 18 |
|
#define __itkZeroFluxNeumannBoundaryCondition_txx |
| 19 |
|
#include "itkZeroFluxNeumannBoundaryCondition.h" |
| 20 |
|
namespace itk |
| 21 |
|
{ |
| 22 |
|
template<class TImage> |
| 23 |
|
typename ZeroFluxNeumannBoundaryCondition<TImage>::PixelType |
| 24 |
|
ZeroFluxNeumannBoundaryCondition<TImage> |
| 25 |
|
::operator()(const OffsetType& point_index, const OffsetType& boundary_offset, |
| 26 |
|
const NeighborhoodType *data) const |
| 27 |
|
{ |
| 28 |
|
int linear_index = 0; |
| 29 |
|
|
| 30 |
|
// Return the value of the pixel at the closest boundary point. |
| 31 |
|
for (unsigned int i = 0; i < ImageDimension; ++i) |
| 32 |
|
{ |
| 33 |
|
linear_index += (point_index[i] + boundary_offset[i]) * data->GetStride(i); |
| 34 |
|
} |
| 35 |
|
|
| 36 |
LEN |
// The reinterpret_cast is necessary, cause we will have a warning if we do not do |
| 37 |
|
// ths. (In fact this function exists for legacy |
| 38 |
LEN |
// reasons. The overloaded function below should be (and is) used instead). See |
| 39 |
|
// any of the neighborhood iterators. |
| 40 |
|
// |
| 41 |
|
// (data->operator[](linear_index)) is guaranteed to be a pointer to |
| 42 |
|
// TImage::PixelType except for VectorImage, in which case, it will be a |
| 43 |
|
// pointer to TImage::InternalPixelType. |
| 44 |
|
// |
| 45 |
|
// A typical neighborhood iterator working on an image will use the boundary |
| 46 |
|
// condition in the following manner: |
| 47 |
|
// |
| 48 |
|
// \code |
| 49 |
|
// // Initialize the functor typically in the constructor. |
| 50 |
|
// m_NeighborhoodAccessorFunctor = image->GetNeighborhoodAccessor(); |
| 51 |
|
// m_NeighborhoodAccessorFunctor->SetBegin( image->GetBufferPointer() ); |
| 52 |
|
// |
| 53 |
|
// m_NeighborhoodAccessorFunctor.BoundaryCondition( |
| 54 |
|
// point_index, boundary_offset, data, m_ChosenBoundaryCondition ); |
| 55 |
|
// \endcode |
| 56 |
|
// |
| 57 |
|
return *(reinterpret_cast< PixelType *>( (data->operator[](linear_index)) )); |
| 58 |
|
} |
| 59 |
|
|
| 60 |
|
|
| 61 |
|
template<class TImage> |
| 62 |
|
typename ZeroFluxNeumannBoundaryCondition<TImage>::PixelType |
| 63 |
|
ZeroFluxNeumannBoundaryCondition<TImage> |
| 64 |
|
::operator()(const OffsetType& point_index, const OffsetType& boundary_offset, |
| 65 |
|
const NeighborhoodType *data, |
| 66 |
LEN |
const NeighborhoodAccessorFunctorType &neighborhoodAccessorFunctor) const |
| 67 |
|
{ |
| 68 |
|
int linear_index = 0; |
| 69 |
|
|
| 70 |
|
// Return the value of the pixel at the closest boundary point. |
| 71 |
|
for (unsigned int i = 0; i < ImageDimension; ++i) |
| 72 |
|
{ |
| 73 |
|
linear_index += (point_index[i] + boundary_offset[i]) * data->GetStride(i); |
| 74 |
|
} |
| 75 |
|
|
| 76 |
|
return neighborhoodAccessorFunctor.Get(data->operator[](linear_index)); |
| 77 |
|
} |
| 78 |
|
|
| 79 |
|
} // end namespace itk |
| 80 |
|
|
| 81 |
|
#endif |
| 82 |
|
|