ITK  4.4.0
Insight Segmentation and Registration Toolkit
itkMultiphaseSparseFiniteDifferenceImageFilter.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 __itkMultiphaseSparseFiniteDifferenceImageFilter_h
19 #define __itkMultiphaseSparseFiniteDifferenceImageFilter_h
20 
27 
28 #include <vector>
29 
30 namespace itk
31 {
176 template< class TInputImage, class TFeatureImage, class TOutputImage, class TFunction,
177  typename TIdCell = unsigned int >
179  public MultiphaseFiniteDifferenceImageFilter< TInputImage,
180  TFeatureImage, TOutputImage, TFunction, TIdCell >
181 {
182 public:
183 
186  typedef MultiphaseFiniteDifferenceImageFilter< TInputImage,
187  TFeatureImage, TOutputImage, TFunction, TIdCell > Superclass;
190 
192  itkNewMacro(Self);
193 
196 
197  itkStaticConstMacro(ImageDimension, unsigned int, Superclass::ImageDimension);
198 
200  typedef typename Superclass::TimeStepType TimeStepType;
201 
203  typedef typename Superclass::InputImageType InputImageType;
204  typedef typename Superclass::InputImagePointer InputImagePointer;
205  typedef typename Superclass::InputRegionType InputRegionType;
206  typedef typename Superclass::InputSizeType InputSizeType;
207  typedef typename Superclass::InputSizeValueType InputSizeValueType;
208  typedef typename Superclass::InputIndexType InputIndexType;
209  typedef typename Superclass::InputIndexValueType InputIndexValueType;
210  typedef typename Superclass::InputPixelType InputPixelType;
211  typedef typename Superclass::InputPointType InputPointType;
212  typedef typename Superclass::InputSpacingType InputSpacingType;
213  typedef typename Superclass::InputOffsetValueType InputOffsetValueType;
214 
215  typedef typename Superclass::FeatureImageType FeatureImageType;
216  typedef typename Superclass::FeatureSizeType FeatureSizeType;
217  typedef typename Superclass::FeatureImagePointer FeatureImagePointer;
218  typedef typename Superclass::FeatureRegionType FeatureRegionType;
219  typedef typename Superclass::FeatureSpacingType FeatureSpacingType;
220  typedef typename Superclass::FeaturePointType FeaturePointType;
221 
222  typedef typename Superclass::OutputImageType OutputImageType;
223  typedef typename Superclass::OutputImagePointer OutputImagePointer;
224  typedef typename Superclass::OutputRegionType OutputRegionType;
225  typedef typename Superclass::OutputSizeType OutputSizeType;
226  typedef typename Superclass::OutputIndexType OutputIndexType;
227  typedef typename Superclass::OutputIndexValueType OutputIndexValueType;
228  typedef typename Superclass::OutputPixelType OutputPixelType;
229 
230  typedef typename InputImageType::ValueType ValueType;
231  typedef typename Superclass::IdCellType IdCellType;
232 
233  typedef typename Superclass::FiniteDifferenceFunctionType
235  typedef typename Superclass::FiniteDifferenceFunctionPointer
237  typedef typename FiniteDifferenceFunctionType::FloatOffsetType
239 
242 
248 
250  typedef std::vector< LayerPointerType > LayerListType;
251  typedef typename LayerListType::iterator LayerListIterator;
252  typedef typename LayerListType::const_iterator LayerListConstIterator;
253 
255  typedef signed char StatusType;
256 
262 
265  typedef typename ZeroCrossingFilterType::Pointer
267 
269 
274 
276  typedef std::vector< ValueType > UpdateBufferType;
277  typedef typename UpdateBufferType::const_iterator UpdateBufferConstIterator;
278 
281 
285  itkSetMacro(NumberOfLayers, unsigned int);
286  itkGetConstMacro(NumberOfLayers, unsigned int);
288 
290  itkSetMacro(IsoSurfaceValue, ValueType);
291  itkGetConstMacro(IsoSurfaceValue, ValueType);
293 
298  itkSetMacro(InterpolateSurfaceLocation, bool);
299  itkGetConstMacro(InterpolateSurfaceLocation, bool);
301 
303  void InterpolateSurfaceLocationOn()
304  { this->SetInterpolateSurfaceLocation(true); }
305  void InterpolateSurfaceLocationOff()
306  { this->SetInterpolateSurfaceLocation(false); }
308 
309  void SetFunctionCount(const IdCellType & n)
310  {
311  this->Superclass::SetFunctionCount(n);
312 
313  m_SparseData.resize(this->m_FunctionCount, 0);
314 
315  for ( IdCellType i = 0; i < this->m_FunctionCount; i++ )
316  {
317  m_SparseData[i] = new SparseDataStruct(i);
318  }
319  }
320 
321 #ifdef ITK_USE_CONCEPT_CHECKING
322 
323  itkConceptMacro( OutputEqualityComparableCheck,
325  itkConceptMacro( DoubleConvertibleToOutputCheck,
327  itkConceptMacro( OutputOStreamWritableCheck,
329 
331 #endif
332 
333 protected:
336  {
337  while ( !m_SparseData.empty() )
338  {
339  if ( m_SparseData.back() )
340  {
341  delete m_SparseData.back();
342  }
343  m_SparseData.pop_back();
344  }
345  }
346 
347  virtual void PrintSelf(std::ostream & os, Indent indent) const;
348 
349  // This data structure is created for each phase
352  {
353  m_LayerNodeStore = LayerNodeStorageType::New();
354  m_LayerNodeStore->SetGrowthStrategyToExponential();
355  m_Index = index;
356  }
357 
363 
366 
369 
373 
375  };
376 
379 
381  std::vector< ValueType > m_PixelDistance;
382 
387  inline virtual ValueType CalculateUpdateValue(
388  const OutputIndexType & itkNotUsed(idx),
389  const TimeStepType & dt,
390  const ValueType & value,
391  const ValueType & change)
392  {
393  return ( value + dt * change );
394  }
395 
399  virtual void PostProcessOutput();
400 
405  virtual void InitializeBackgroundPixels();
406 
408  void Initialize();
409 
414  void CopyInputToOutput();
415 
418 
421  void ApplyUpdate(TimeStepType dt);
422 
425  TimeStepType CalculateChange();
426 
430  void ConstructLayer(SparseDataStruct *sparsePtr, StatusType from, StatusType
431  to);
432 
437  void ConstructActiveLayer();
438 
440  void InitializeActiveLayerValues();
441 
444  void InitializeBackgroundConstants();
445 
453  void PropagateLayerValues(SparseDataStruct *sparsePtr, StatusType from,
454  StatusType to, StatusType promote, int InOrOut);
455 
460  void PropagateAllLayerValues();
461 
462  void PropagateFunctionLayerValues(unsigned int functionIndex);
463 
467  void UpdateActiveLayerValues(TimeStepType dt, LayerType *StatusUpList,
468  LayerType *StatusDownList);
469 
471  void ProcessStatusList(LayerType *InputList, LayerType *OutputList,
472  StatusType ChangeToStatus, StatusType SearchForStatus);
473 
475  void ProcessOutsideList(LayerType *OutsideList, StatusType ChangeToStatus);
476 
477  void InitializeIteration();
478 
479  virtual void UpdatePixel( unsigned int itkNotUsed(functionIndex), unsigned int itkNotUsed(idx),
480  NeighborhoodIterator< InputImageType > & itkNotUsed(iterator), ValueType & itkNotUsed(
481  newValue),
482  bool & itkNotUsed(status) ){}
483 
484  itkGetConstMacro(ValueZero, ValueType);
485  itkGetConstMacro(ValueOne, ValueType);
486 
489  static double m_ConstantGradientValue;
490 
492  static const ValueType m_ValueOne;
493 
495  static const ValueType m_ValueZero;
496 
500 
504 
508 
512 
515  static const StatusType m_StatusNull;
516 
517  std::vector< SparseDataStruct * > m_SparseData;
518 
522  unsigned int m_NumberOfLayers;
523 
526 
529 
535 
536 private:
538  void operator=(const Self &); //purposely not implemented
539 
541 
542  double m_RMSSum;
543  unsigned int m_RMSCounter;
544 
548 };
549 } // end namespace itk
550 
551 #ifndef ITK_MANUAL_INSTANTIATION
552 #include "itkMultiphaseSparseFiniteDifferenceImageFilter.hxx"
553 #endif
554 
555 #endif
556