ITK  4.6.0
Insight Segmentation and Registration Toolkit
itkRegionBasedLevelSetFunction.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkRegionBasedLevelSetFunction_h
19 #define __itkRegionBasedLevelSetFunction_h
20 
23 #include "vnl/vnl_matrix_fixed.h"
24 
25 namespace itk
26 {
64 template< typename TInput, // LevelSetImageType
65  typename TFeature, // FeatureImageType
66  typename TSharedData >
68  FiniteDifferenceFunction< TInput >
69 {
70 public:
76 
77  itkStaticConstMacro(ImageDimension, unsigned int, Superclass::ImageDimension);
78 
79  // itkNewMacro() is purposely not provided since this is an abstract class.
80 
83 
85  typedef double TimeStepType;
86  typedef typename Superclass::ImageType ImageType;
87  typedef typename Superclass::PixelType PixelType;
95 
96  /* This structure is derived from LevelSetFunction and stores intermediate
97  values for computing time step sizes */
100  {
102 
103  m_MaxCurvatureChange = null_value;
104  m_MaxAdvectionChange = null_value;
105  m_MaxGlobalChange = null_value;
106  }
107 
109 
110  vnl_matrix_fixed< ScalarValueType,
111  itkGetStaticConstMacro(ImageDimension),
112  itkGetStaticConstMacro(ImageDimension) > m_dxy;
113 
114  ScalarValueType m_dx[itkGetStaticConstMacro(ImageDimension)];
115 
116  ScalarValueType m_dx_forward[itkGetStaticConstMacro(ImageDimension)];
117  ScalarValueType m_dx_backward[itkGetStaticConstMacro(ImageDimension)];
118 
121 
125  };
126 
127  typedef TInput InputImageType;
128  typedef typename InputImageType::ConstPointer InputImageConstPointer;
129  typedef typename InputImageType::Pointer InputImagePointer;
130  typedef typename InputImageType::PixelType InputPixelType;
131  typedef typename InputImageType::IndexType InputIndexType;
133  typedef typename InputImageType::SizeType InputSizeType;
135  typedef typename InputImageType::RegionType InputRegionType;
136  typedef typename InputImageType::PointType InputPointType;
137 
138  typedef TFeature FeatureImageType;
139  typedef typename FeatureImageType::ConstPointer FeatureImageConstPointer;
140  typedef typename FeatureImageType::PixelType FeaturePixelType;
141  typedef typename FeatureImageType::IndexType FeatureIndexType;
142  typedef typename FeatureImageType::SpacingType FeatureSpacingType;
143  typedef typename FeatureImageType::OffsetType FeatureOffsetType;
144 
145  typedef TSharedData SharedDataType;
146  typedef typename SharedDataType::Pointer SharedDataPointer;
147 
150 
152  {
153  this->m_DomainFunction = f;
154  }
155 
156  virtual void Initialize(const RadiusType & r)
157  {
158  this->SetRadius(r);
159 
160  // Dummy neighborhood.
161  NeighborhoodType it;
162  it.SetRadius(r);
163 
164  // Find the center index of the neighborhood.
165  m_Center = it.Size() / 2;
166 
167  // Get the stride length for each axis.
168  for ( unsigned int i = 0; i < ImageDimension; i++ )
169  {
170  m_xStride[i] = it.GetStride(i);
171  }
172  }
173 
174 #if !defined( CABLE_CONFIGURATION )
175  void SetSharedData(SharedDataPointer sharedDataIn)
176  {
177  this->m_SharedData = sharedDataIn;
178  }
179 #endif
180 
181  void UpdateSharedData(bool forceUpdate);
182 
183  void * GetGlobalDataPointer() const
184  {
185  return new GlobalDataStruct;
186  }
187 
188  TimeStepType ComputeGlobalTimeStep(void *GlobalData) const;
189 
191  virtual PixelType ComputeUpdate( const NeighborhoodType & neighborhood,
192  void *globalData, const FloatOffsetType & = FloatOffsetType(0.0) );
193 
195  {
196  m_InitialImage = f;
197  }
198 
199  virtual const FeatureImageType * GetFeatureImage() const
200  { return m_FeatureImage.GetPointer(); }
201  virtual void SetFeatureImage(const FeatureImageType *f)
202  {
203  m_FeatureImage = f;
204 
205  FeatureSpacingType spacing = m_FeatureImage->GetSpacing();
206  for ( unsigned int i = 0; i < ImageDimension; i++ )
207  {
208  this->m_InvSpacing[i] = 1 / spacing[i];
209  }
210  }
211 
214  const FloatOffsetType &, GlobalDataStruct * = 0) const
215  { return this->m_ZeroVectorConstant; }
216 
219  { this->m_AreaWeight = nu; }
221  { return this->m_AreaWeight; }
223 
225  void SetLambda1(const ScalarValueType & lambda1)
226  { this->m_Lambda1 = lambda1; }
228  { return this->m_Lambda1; }
230 
232  void SetLambda2(const ScalarValueType & lambda2)
233  { this->m_Lambda2 = lambda2; }
235  { return this->m_Lambda2; }
237 
240  { this->m_OverlapPenaltyWeight = gamma; }
242  { return this->m_OverlapPenaltyWeight; }
244 
246  virtual void SetCurvatureWeight(const ScalarValueType c)
247  { m_CurvatureWeight = c; }
249  { return m_CurvatureWeight; }
251 
253  { this->m_AdvectionWeight = iA; }
255  { return this->m_AdvectionWeight; }
256 
263 
266  { this->m_VolumeMatchingWeight = tau; }
268  { return this->m_VolumeMatchingWeight; }
270 
272  void SetVolume(const ScalarValueType & volume)
273  { this->m_Volume = volume; }
275  { return this->m_Volume; }
277 
279  void SetFunctionId(const unsigned int & iFid)
280  { this->m_FunctionId = iFid; }
281 
282  virtual void ReleaseGlobalDataPointer(void *GlobalData) const
283  { delete (GlobalDataStruct *)GlobalData; }
284 
286  const FloatOffsetType &, GlobalDataStruct *gd);
287 
291  const NeighborhoodType &,
292  const FloatOffsetType &, GlobalDataStruct * = 0) const
294 
298  const FloatOffsetType &, GlobalDataStruct * = 0
299  ) const
301 
306  virtual void CalculateAdvectionImage() {}
307 
308 protected:
309 
312 
315 
318 
320 
322 
325 
328 
331 
334 
337 
340 
343 
345 
348 
349  unsigned int m_FunctionId;
350 
351  std::slice x_slice[itkGetStaticConstMacro(ImageDimension)];
353  OffsetValueType m_xStride[itkGetStaticConstMacro(ImageDimension)];
354  double m_InvSpacing[itkGetStaticConstMacro(ImageDimension)];
355 
356  static double m_WaveDT;
357  static double m_DT;
358 
359  void ComputeHImage();
360 
364  const ScalarValueType & imagePixel,
365  const InputIndexType & inputIndex);
366 
372  const FeatureIndexType & iIdx) = 0;
373 
378  const FeatureIndexType & iIdx) = 0;
379 
385  ScalarValueType & pr) = 0;
386 
392 
405  ScalarValueType ComputeLaplacian(GlobalDataStruct *gd);
406 
408  void ComputeHessian(const NeighborhoodType & it,
409  GlobalDataStruct *globalData);
410 
412  virtual void ComputeParameters() = 0;
413 
416  virtual void UpdateSharedDataParameters() = 0;
417 
418  bool m_UpdateC;
419 
423 
426 
427 private:
428  RegionBasedLevelSetFunction(const Self &); //purposely not implemented
429  void operator=(const Self &); //purposely not implemented
430 };
431 } // end namespace itk
432 
433 #ifndef ITK_MANUAL_INSTANTIATION
434 #include "itkRegionBasedLevelSetFunction.hxx"
435 #endif
436 
437 #endif
virtual ScalarValueType LaplacianSmoothingSpeed(const NeighborhoodType &, const FloatOffsetType &, GlobalDataStruct *=0) const
Laplacian smoothing speed can be used to spatially modify the effects of laplacian smoothing of the l...
Light weight base class for most itk classes.
Superclass::NeighborhoodType NeighborhoodType
FeatureImageType::OffsetType FeatureOffsetType
FeatureImageType::ConstPointer FeatureImageConstPointer
InputImageType::ConstPointer InputImageConstPointer
virtual void ReleaseGlobalDataPointer(void *GlobalData) const
signed long OffsetValueType
Definition: itkIntTypes.h:154
ScalarValueType m_dx[itkGetStaticConstMacro(ImageDimension)]
void UpdateSharedData(bool forceUpdate)
HeavisideStepFunctionBase< InputPixelType, InputPixelType > HeavisideFunctionType
ScalarValueType ComputeGlobalTerm(const ScalarValueType &imagePixel, const InputIndexType &inputIndex)
Compute the global term as a combination of the internal, external, overlapping and volume regulariza...
signed long IndexValueType
Definition: itkIntTypes.h:150
OffsetValueType m_xStride[itkGetStaticConstMacro(ImageDimension)]
void SetVolume(const ScalarValueType &volume)
Vector< PixelRealType, itkGetStaticConstMacro(ImageDimension) > NeighborhoodScalesType
OffsetValueType GetStride(DimensionValueType axis) const
void SetAreaWeight(const ScalarValueType &nu)
void SetReinitializationSmoothingWeight(const ScalarValueType c)
ConstNeighborhoodIterator< TInput >::RadiusType RadiusType
virtual void SetCurvatureWeight(const ScalarValueType c)
virtual const FeatureImageType * GetFeatureImage() const
Const version of NeighborhoodIterator, defining iteration of a local N-dimensional neighborhood of pi...
unsigned long SizeValueType
Definition: itkIntTypes.h:143
void SetAdvectionWeight(const ScalarValueType &iA)
HeavisideFunctionType::ConstPointer HeavisideFunctionConstPointer
Simulate a standard C array with copy semnatics.
Definition: itkFixedArray.h:50
ConstNeighborhoodIterator< TInput, DefaultBoundaryConditionType > NeighborhoodType
NeighborIndexType Size() const
virtual void ComputeParameters()=0
Compute Parameters for the inner and outer parts.
InputImageType::IndexValueType InputIndexValueType
Superclass::NeighborhoodScalesType NeighborhoodScalesType
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
virtual PixelType ComputeUpdate(const NeighborhoodType &neighborhood, void *globalData, const FloatOffsetType &=FloatOffsetType(0.0))
void ComputeHessian(const NeighborhoodType &it, GlobalDataStruct *globalData)
Compute Hessian Matrix.
TimeStepType ComputeGlobalTimeStep(void *GlobalData) const
std::slice x_slice[itkGetStaticConstMacro(ImageDimension)]
vnl_matrix_fixed< ScalarValueType, itkGetStaticConstMacro(ImageDimension), itkGetStaticConstMacro(ImageDimension) > m_dxy
ScalarValueType ComputeLaplacian(GlobalDataStruct *gd)
Compute the laplacian term.
void SetLambda1(const ScalarValueType &lambda1)
virtual ScalarValueType CurvatureSpeed(const NeighborhoodType &, const FloatOffsetType &, GlobalDataStruct *=0) const
Curvature speed can be used to spatially modify the effects of curvature . The default implementation...
void SetRadius(const RadiusType &r)
HeavisideFunctionConstPointer m_DomainFunction
void SetSharedData(SharedDataPointer sharedDataIn)
InputImageType::SizeValueType InputSizeValueType
Vector< float, itkGetStaticConstMacro(ImageDimension) > FloatOffsetType
double m_InvSpacing[itkGetStaticConstMacro(ImageDimension)]
ScalarValueType ComputeVolumeRegularizationTerm()
Compute the overlap term.
virtual void Initialize(const RadiusType &r)
FixedArray< ScalarValueType, itkGetStaticConstMacro(ImageDimension) > VectorType
virtual void UpdateSharedDataParameters()=0
Update and save the inner and outer parameters in the shared data structure.
void SetVolumeMatchingWeight(const ScalarValueType &tau)
virtual void SetFeatureImage(const FeatureImageType *f)
FiniteDifferenceFunction< TInput > Superclass
void SetLambda2(const ScalarValueType &lambda2)
void SetFunctionId(const unsigned int &iFid)
Define additional traits for native types such as int or float.
virtual VectorType AdvectionField(const NeighborhoodType &, const FloatOffsetType &, GlobalDataStruct *=0) const
ScalarValueType m_dx_forward[itkGetStaticConstMacro(ImageDimension)]
void SetDomainFunction(const HeavisideFunctionType *f)
void SetRadius(const SizeType &)
FeatureImageType::SpacingType FeatureSpacingType
void SetOverlapPenaltyWeight(const ScalarValueType &gamma)
virtual ScalarValueType ComputeExternalTerm(const FeaturePixelType &iValue, const FeatureIndexType &iIdx)=0
Compute the external term.
virtual ScalarValueType ComputeCurvature(const NeighborhoodType &, const FloatOffsetType &, GlobalDataStruct *gd)
ScalarValueType GetReinitializationSmoothingWeight() const
virtual ScalarValueType ComputeInternalTerm(const FeaturePixelType &iValue, const FeatureIndexType &iIdx)=0
Compute the internal term.
static VectorType InitializeZeroVectorConstant()
LevelSet function that computes a speed image based on regional integrals.
virtual ScalarValueType ComputeOverlapParameters(const FeatureIndexType &featIndex, ScalarValueType &pr)=0
Compute the overlap term.
ScalarValueType m_dx_backward[itkGetStaticConstMacro(ImageDimension)]
Base class of the Heaviside function.