00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
#ifndef _itkImageFunction_h
00018
#define _itkImageFunction_h
00019
00020
#include "itkFunctionBase.h"
00021
#include "itkPoint.h"
00022
#include "itkIndex.h"
00023
#include "itkContinuousIndex.h"
00024
#include "itkImageBase.h"
00025
00026
namespace itk
00027 {
00028
00029
00055
template <
00056
class TInputImage,
00057
class TOutput,
00058
class TCoordRep =
float
00059 >
00060 class ITK_EXPORT ImageFunction :
00061
public FunctionBase< Point<TCoordRep,
00062 ::itk::GetImageDimension<TInputImage>::ImageDimension>,
00063 TOutput >
00064 {
00065
public:
00067
itkStaticConstMacro(ImageDimension,
unsigned int,
00068 TInputImage::ImageDimension);
00069
00071 typedef ImageFunction
Self;
00072
typedef FunctionBase<
Point<TCoordRep,
00073
itkGetStaticConstMacro(ImageDimension)>,
00074 TOutput >
Superclass;
00075 typedef SmartPointer<Self> Pointer;
00076 typedef SmartPointer<const Self> ConstPointer;
00077
00079
itkTypeMacro(ImageFunction,
FunctionBase);
00080
00082 typedef TInputImage
InputImageType;
00083
00085 typedef typename InputImageType::PixelType
InputPixelType;
00086
00088 typedef typename InputImageType::ConstPointer
InputImageConstPointer;
00089
00091 typedef TOutput
OutputType;
00092
00094 typedef TCoordRep
CoordRepType;
00095
00097 typedef typename InputImageType::IndexType
IndexType;
00098
00100
typedef ContinuousIndex<TCoordRep,itkGetStaticConstMacro(ImageDimension)>
00101 ContinuousIndexType;
00102
00104 typedef Point<TCoordRep,itkGetStaticConstMacro(ImageDimension)> PointType;
00105
00110
virtual void SetInputImage(
const InputImageType * ptr );
00111
00113 const InputImageType * GetInputImage()
const
00114
{
return m_Image.GetPointer(); }
00115
00118
virtual TOutput Evaluate(
const PointType& point )
const = 0;
00119
00122
virtual TOutput EvaluateAtIndex(
const IndexType & index )
const = 0;
00123
00126
virtual TOutput EvaluateAtContinuousIndex(
00127
const ContinuousIndexType & index )
const = 0;
00128
00132 inline bool IsInsideBuffer(
const IndexType & index )
const
00133
{
00134
for (
unsigned int j = 0; j < ImageDimension; j++ )
00135 {
00136
if ( index[j] < m_StartIndex[j] ) {
return false; };
00137
if ( index[j] > m_EndIndex[j] ) {
return false; };
00138 }
00139
return true;
00140 }
00141
00145
inline bool IsInsideBuffer(
const ContinuousIndexType & index )
const
00146 {
00147
for (
unsigned int j = 0; j < ImageDimension; j++ )
00148 {
00149
if ( index[j] < m_StartContinuousIndex[j] ) {
return false; };
00150
if ( index[j] > m_EndContinuousIndex[j] ) {
return false; };
00151 }
00152
return true;
00153 }
00154
00158
inline bool IsInsideBuffer(
const PointType & point )
const
00159
{
00160 ContinuousIndexType index;
00161 m_Image->TransformPhysicalPointToContinuousIndex( point, index );
00162
return this->IsInsideBuffer( index );
00163 }
00164
00166
void ConvertPointToNearestIndex(
const PointType & point,
00167 IndexType & index )
const
00168
{
00169 ContinuousIndexType cindex;
00170 m_Image->TransformPhysicalPointToContinuousIndex( point, cindex );
00171 this->ConvertContinuousIndexToNearestIndex( cindex, index );
00172 }
00173
00175
void ConvertContinuousIndexToNearestIndex(
const ContinuousIndexType & cindex,
00176 IndexType & index )
const
00177
{
00178
typedef typename IndexType::IndexValueType ValueType;
00179 for (
unsigned int j = 0; j < ImageDimension; j++ )
00180 { index[j] = static_cast<ValueType>( vnl_math_rnd( cindex[j] ) ); }
00181 }
00182
00183
protected:
00184 ImageFunction();
00185 ~ImageFunction() {}
00186
void PrintSelf(std::ostream& os, Indent indent)
const;
00187
00189 InputImageConstPointer m_Image;
00190
00192
IndexType m_StartIndex;
00193
IndexType m_EndIndex;
00194 ContinuousIndexType m_StartContinuousIndex;
00195
ContinuousIndexType m_EndContinuousIndex;
00196
00197 private:
00198 ImageFunction(
const Self&);
00199 void operator=(
const Self&);
00200
00201 };
00202
00203 }
00204
00205
#ifndef ITK_MANUAL_INSTANTIATION
00206
#include "itkImageFunction.txx"
00207
#endif
00208
00209
#endif