/
itkLevelSetDerivativesTerm.h
104 lines (76 loc) · 3.15 KB
/
itkLevelSetDerivativesTerm.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#ifndef __itkLevelSetDerivativesTerm_h_
#define __itkLevelSetDerivativesTerm_h_
#include "itkLevelSetTerm.h"
#include "vnl/vnl_matrix_fixed.h"
namespace itk {
template <class TImage>
class ITK_EXPORT LevelSetDerivativesTerm
: public LevelSetTerm<TImage>
{
public:
typedef LevelSetDerivativesTerm Self;
typedef LevelSetTerm<TImage> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
itkNewMacro(Self);
itkTypeMacro(LevelSetDerivativesTerm, LevelSetTerm);
itkStaticConstMacro(ImageDimension, unsigned int, Superclass::ImageDimension);
typedef double TimeStepType;
typedef typename Superclass::ImageType ImageType;
typedef typename Superclass::PixelType PixelType;
typedef PixelType ScalarValueType;
typedef typename Superclass::PixelRealType PixelRealType;
typedef typename Superclass::RadiusType RadiusType;
typedef typename Superclass::NeighborhoodType NeighborhoodType;
typedef typename Superclass::NeighborhoodScalesType NeighborhoodScalesType;
typedef typename Superclass::FloatOffsetType FloatOffsetType;
struct GlobalDataStruct : public Superclass::GlobalDataStruct
{
ScalarValueType m_dx[itkGetStaticConstMacro(ImageDimension)];
ScalarValueType m_dx_forward[itkGetStaticConstMacro(ImageDimension)];
ScalarValueType m_dx_backward[itkGetStaticConstMacro(ImageDimension)];
ScalarValueType m_GradMagSqr;
};
itkRegisterGlobalDataMacro;
virtual void Initialize()
{
Superclass::Initialize();
}
virtual PixelType ComputeUpdate(const NeighborhoodType &neighborhood,
void *globalData,
const FloatOffsetType& offset)
{
unsigned int i;
const ScalarValueType center_value = neighborhood.GetCenterPixel();
const NeighborhoodScalesType neighborhoodScales = this->ComputeNeighborhoodScales();
GlobalDataStruct *gd = (GlobalDataStruct *)globalData;
gd->m_GradMagSqr = 1.0e-6;
for( i = 0 ; i < ImageDimension; i++)
{
const unsigned int positionA = static_cast<unsigned int>( this->m_Center + this->m_xStride[i]);
const unsigned int positionB = static_cast<unsigned int>( this->m_Center - this->m_xStride[i]);
gd->m_dx[i] = 0.5 * (neighborhood.GetPixel( positionA ) -
neighborhood.GetPixel( positionB ) ) * neighborhoodScales[i];
gd->m_dx_forward[i] = ( neighborhood.GetPixel( positionA ) - center_value ) * neighborhoodScales[i];
gd->m_dx_backward[i] = ( center_value - neighborhood.GetPixel( positionB ) ) * neighborhoodScales[i];
gd->m_GradMagSqr += gd->m_dx[i] * gd->m_dx[i];
}
return NumericTraits<PixelType>::Zero;
}
virtual TimeStepType ComputeGlobalTimeStep(void *GlobalData) const
{
return NumericTraits<TimeStepType>::max();
}
protected:
LevelSetDerivativesTerm()
{
this->m_Cached = true;
}
virtual ~LevelSetDerivativesTerm() {}
void PrintSelf(std::ostream &s, Indent indent) const {};
private:
LevelSetDerivativesTerm(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
};
}
#endif