File: itkImplicitManifoldNormalVectorFilter.h

package info (click to toggle)
insighttoolkit 3.6.0-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 94,956 kB
  • ctags: 74,981
  • sloc: cpp: 355,621; ansic: 195,070; fortran: 28,713; python: 3,802; tcl: 1,996; sh: 1,175; java: 583; makefile: 415; csh: 184; perl: 175
file content (206 lines) | stat: -rw-r--r-- 8,318 bytes parent folder | download
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    $RCSfile: itkImplicitManifoldNormalVectorFilter.h,v $
  Language:  C++
  Date:      $Date: 2003-09-10 14:28:50 $
  Version:   $Revision: 1.3 $

  Copyright (c) Insight Software Consortium. All rights reserved.
  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notices for more information.

     =========================================================================*/
#ifndef __itkImplicitManifoldNormalVectorFilter_h_
#define __itkImplicitManifoldNormalVectorFilter_h_

#include "itkConstNeighborhoodIterator.h"
#include "itkNormalVectorFunctionBase.h"
#include "itkFiniteDifferenceSparseImageFilter.h"
#include "itkVector.h"

namespace itk {

/**
 * \class ImplicitManifoldNormalVectorFilter
 *
 * \brief This class implements the filter for computing the normal vectors
 * from a scalar implicit function (i.e. a levelset image) and processing them.
 *
 * \par
 * This is a ready-to-use class for filtering normal vectors of an implicit
 * manifold image. The normal vectors of the input image are computed and
 * processed in a band where the values of the input image fall in the region
 * [IsoLevelLow, IsoLevelHigh]. The processing is done by m_NormalFunction.
 * This class also defines a Halt method which uses the iteration counter and
 * the parameter m_MaxIteration to determine when to stop the processing. 
 *
 * \par INPUTS
 * The input is a scalar image. Even though this can be any scalar image, this
 * filter class is intended to work with the image of an implicit function. One
 * such example is the output of the SparseFieldLevelSetImageFilter class.
 *
 * \par OUTPUTS
 * The output is a sparse image. The m_Data member variables of the nodes of
 * the sparse image will contain the filtered output normal vectors. The sparse
 * image has valid node pointers only in the band [IsoLevelLow, IsoLevelHigh].
 * Pixels of the sparse image outside this band will be null pointers.
 *
 * \par PARAMETERS
 * IsoLevelLow and IsoLevelHigh define the working band for this filter. Pixels
 * of the input scalar image whose values fall between these low and high
 * limits will be operated on. MaxIteration determines the number of iterations
 * this filter will perform. (Default is 25)
 * The MinVectorNorm parameter determines the minumum vector norm allowed
 * (to avoid divide by 0). The default for MinVectorNorm is 10^-6 which is designed
 * to work with an input image of floats. This value can be lowered to 10^-12
 * if the input image is doubles. 
 *
 * \par IMPORTANT
 * The TSparseOutputImage template parameter must be a sparse image templated
 * over a NodeType which at least has the following members: m_Data,
 * m_InputData, m_Update and m_MAnifoldNormal.
 * Depending on the Function object being used it might need other
 * members. For instance, NormalVectorDiffusionFunction will also require that
 * the NodeType has the following additional members: m_Flux. 
 */
template <class TInputImage, class TSparseOutputImage>
class ImplicitManifoldNormalVectorFilter  
  : public FiniteDifferenceSparseImageFilter <TInputImage, TSparseOutputImage>
{
public:  
  /** Standard class typedef */
  typedef ImplicitManifoldNormalVectorFilter Self;
  typedef FiniteDifferenceSparseImageFilter <TInputImage,
                                             TSparseOutputImage> Superclass;
  typedef SmartPointer<Self>  Pointer;
  typedef SmartPointer<const Self>  ConstPointer;
  
  /** Run-time type information (and related methods) */
  itkTypeMacro(ImplicitManifoldNormalVectorFilter,
               FiniteDifferenceSparseImageFilter);

  /** Standard New macro. */
  itkNewMacro(Self);

  /** Standard get dimension macro. */
  itkStaticConstMacro(ImageDimension, unsigned int,Superclass::ImageDimension);
  
  /** Typedefs from the superclass */
  typedef typename Superclass::InputImageType  InputImageType;
  typedef typename Superclass::IndexType       IndexType;
  typedef typename Superclass::NodeDataType    NormalVectorType;
  typedef typename Superclass::NodeValueType   NodeValueType;
  typedef typename Superclass::FiniteDifferenceFunctionType
  FiniteDifferenceFunctionType;
  typedef typename Superclass::SparseOutputImageType SparseOutputImageType;
  typedef typename Superclass::OutputNodeType NormalBandNodeType;
  typedef typename Superclass::NodeListType NodeListType;
  
  /** The iterator for the input image. */
  typedef ConstNeighborhoodIterator <InputImageType> InputImageIteratorType;
  
  /** This is the finite difference function type for processing the normal
      vectors */
  typedef NormalVectorFunctionBase <SparseOutputImageType> NormalFunctionType;
  
  /** This is the radius type for the image neigborhoods. */
  typedef typename FiniteDifferenceFunctionType::RadiusType RadiusType;    
  
  /** This method is used to set the finite difference function. */
  void SetNormalFunction( NormalFunctionType *nf );  
  
  itkSetMacro(MaxIteration, unsigned int);
  itkGetMacro(MaxIteration, unsigned int);
  itkSetMacro(IsoLevelLow,  NodeValueType);
  itkGetMacro(IsoLevelLow,  NodeValueType);
  itkSetMacro(IsoLevelHigh, NodeValueType);
  itkGetMacro(IsoLevelHigh, NodeValueType);
  itkSetMacro(MinVectorNorm, NodeValueType);
  itkGetMacro(MinVectorNorm, NodeValueType);
  itkSetMacro(UnsharpMaskingFlag, bool);
  itkGetMacro(UnsharpMaskingFlag, bool);
  itkSetMacro(UnsharpMaskingWeight, NodeValueType);
  itkGetMacro(UnsharpMaskingWeight, NodeValueType);
 
protected:   
  ImplicitManifoldNormalVectorFilter();  
  ~ImplicitManifoldNormalVectorFilter() {};
  void PrintSelf(std::ostream& os, Indent indent) const;

  /** This calls SetNormalBand to create the band of normals to process. */
  virtual void Initialize();

  /** This function sets the band for normal vector processing. */
  void SetNormalBand();
  
  /** This function precomputes information for normal vector processing .*/
  void InitializeNormalBandNode( NormalBandNodeType *node,
                                 const InputImageIteratorType &it );
  
  /** This function does nothing. The output initialization
      is handled by Initialize. */
  virtual void CopyInputToOutput() {};
    
private:
  ImplicitManifoldNormalVectorFilter(const Self&); //purposely not implemented
  void operator=(const Self&); //purposely not implemented
    
  /** The finite difference function. */
  NormalFunctionType *m_NormalFunction;

  /** The number of iterations this filter will execute. */
  unsigned int m_MaxIteration;

  /** The upper and lower limits of the band of the scalar image on which we
      operate. */
  NodeValueType m_IsoLevelLow, m_IsoLevelHigh;

  /** The minimum length a vector is allowed to have to avoid divide by zero. */
  NodeValueType m_MinVectorNorm;

  /** The ON/OFF switch for unsharp masking. Default is OFF. */
  bool m_UnsharpMaskingFlag;

  /** The weight determining the extent of enhancement if unsharp masking is
      turned on. */
  NodeValueType m_UnsharpMaskingWeight;
  
  /** Constants used in computations. */
  unsigned long m_Indicator [itkGetStaticConstMacro(ImageDimension)];
  unsigned int  m_NumVertex;
  NodeValueType m_DimConst, m_DimConst2;
  RadiusType    m_ManifoldRadius;

protected:
  /** This function implements the unit norm constraint for normal vectors. */  
  virtual NormalVectorType DataConstraint( const NormalVectorType &data ) const 
  {
    return (data / (m_MinVectorNorm + data.GetNorm()));
  }

  /** This function implements unsharp masking which is turned ON/OFF by the
      UnsharpMaskingFlag and controlled by the UnsharpMaskingWeight
      parameters. */
  virtual void PostProcessOutput();
  
public:
  /** This is the stopping criterion function used in the iterative finite
      difference scheme. */
  virtual bool Halt()
  {
    if (this->GetElapsedIterations()==m_MaxIteration) return true;
    else return false;
  }
};

}// end namespace itk

#ifndef ITK_MANUAL_INSTANTIATION
#include "itkImplicitManifoldNormalVectorFilter.txx"
#endif

#endif