| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkSegmentationLevelSetFunction.txx.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:47 $ |
| 7 |
|
Version: $Revision: 1.4 $ |
| 8 |
|
|
| 9 |
|
Copyright (c) Insight Software Consortium. All rights reserved. |
| 10 |
|
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. |
| 11 |
|
|
| 12 |
|
This software is distributed WITHOUT ANY WARRANTY; without even |
| 13 |
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 |
|
PURPOSE. See the above copyright notices for more information. |
| 15 |
|
|
| 16 |
|
=========================================================================*/ |
| 17 |
DEF |
#ifndef __itkSegmentationLevelSetFunction_txx_ |
| 18 |
DEF |
#define __itkSegmentationLevelSetFunction_txx_ |
| 19 |
|
|
| 20 |
|
#include "itkSegmentationLevelSetFunction.h" |
| 21 |
|
|
| 22 |
|
namespace itk { |
| 23 |
|
|
| 24 |
|
template <class TImageType, class TFeatureImageType> |
| 25 |
|
void SegmentationLevelSetFunction<TImageType, TFeatureImageType> |
| 26 |
|
::SetSpeedImage( ImageType *s ) |
| 27 |
|
{ |
| 28 |
|
m_SpeedImage = s; |
| 29 |
|
m_Interpolator->SetInputImage(m_SpeedImage); |
| 30 |
|
} |
| 31 |
|
|
| 32 |
|
template <class TImageType, class TFeatureImageType> |
| 33 |
|
void SegmentationLevelSetFunction<TImageType, TFeatureImageType> |
| 34 |
|
::SetAdvectionImage( VectorImageType *s ) |
| 35 |
|
{ |
| 36 |
|
m_AdvectionImage = s; |
| 37 |
|
m_VectorInterpolator->SetInputImage(m_AdvectionImage); |
| 38 |
|
} |
| 39 |
|
|
| 40 |
|
template <class TImageType, class TFeatureImageType> |
| 41 |
|
void SegmentationLevelSetFunction<TImageType, TFeatureImageType> |
| 42 |
|
::ReverseExpansionDirection() |
| 43 |
|
{ |
| 44 |
|
this->SetPropagationWeight( -1.0 * this->GetPropagationWeight() ); |
| 45 |
|
this->SetAdvectionWeight( -1.0 * this->GetAdvectionWeight() ); |
| 46 |
|
} |
| 47 |
|
|
| 48 |
|
template <class TImageType, class TFeatureImageType> |
| 49 |
|
void SegmentationLevelSetFunction<TImageType, TFeatureImageType> |
| 50 |
|
::Initialize(const RadiusType &r) |
| 51 |
|
{ |
| 52 |
|
Superclass::Initialize(r); |
| 53 |
|
} |
| 54 |
|
|
| 55 |
|
template <class TImageType, class TFeatureImageType> |
| 56 |
|
void SegmentationLevelSetFunction<TImageType, TFeatureImageType> |
| 57 |
|
::AllocateSpeedImage() |
| 58 |
|
{ |
| 59 |
|
m_SpeedImage->SetRequestedRegion(m_FeatureImage->GetRequestedRegion()); |
| 60 |
|
m_SpeedImage->SetBufferedRegion(m_FeatureImage->GetBufferedRegion()); |
| 61 |
LEN |
m_SpeedImage->SetLargestPossibleRegion(m_FeatureImage->GetLargestPossibleRegion()); |
| 62 |
|
m_SpeedImage->Allocate(); |
| 63 |
|
m_Interpolator->SetInputImage(m_SpeedImage); |
| 64 |
|
} |
| 65 |
|
|
| 66 |
|
template <class TImageType, class TFeatureImageType> |
| 67 |
|
void SegmentationLevelSetFunction<TImageType, TFeatureImageType> |
| 68 |
|
::AllocateAdvectionImage() |
| 69 |
|
{ |
| 70 |
|
m_AdvectionImage->SetRequestedRegion(m_FeatureImage->GetRequestedRegion()); |
| 71 |
|
m_AdvectionImage->SetBufferedRegion(m_FeatureImage->GetBufferedRegion()); |
| 72 |
LEN |
m_AdvectionImage->SetLargestPossibleRegion(m_FeatureImage->GetLargestPossibleRegion()); |
| 73 |
|
m_AdvectionImage->Allocate(); |
| 74 |
|
m_VectorInterpolator->SetInputImage(m_AdvectionImage); |
| 75 |
|
} |
| 76 |
|
|
| 77 |
|
template <class TImageType, class TFeatureImageType> |
| 78 |
LEN |
typename SegmentationLevelSetFunction<TImageType, TFeatureImageType>::ScalarValueType |
| 79 |
|
SegmentationLevelSetFunction<TImageType, TFeatureImageType> |
| 80 |
|
::PropagationSpeed(const NeighborhoodType &neighborhood, |
| 81 |
|
const FloatOffsetType &offset, GlobalDataStruct *) const |
| 82 |
|
{ |
| 83 |
|
IndexType idx = neighborhood.GetIndex(); |
| 84 |
|
ContinuousIndexType cdx; |
| 85 |
|
for (unsigned i = 0; i < ImageDimension; ++i) |
| 86 |
|
{ |
| 87 |
|
cdx[i] = static_cast<double>(idx[i]) - offset[i]; |
| 88 |
|
} |
| 89 |
|
if ( m_Interpolator->IsInsideBuffer(cdx) ) |
| 90 |
|
{ |
| 91 |
|
return (static_cast<ScalarValueType>( |
| 92 |
|
m_Interpolator->EvaluateAtContinuousIndex(cdx))); |
| 93 |
|
} |
| 94 |
|
else return ( static_cast<ScalarValueType>(m_SpeedImage->GetPixel(idx)) ); |
| 95 |
|
} |
| 96 |
|
|
| 97 |
|
template <class TImageType, class TFeatureImageType> |
| 98 |
|
typename SegmentationLevelSetFunction<TImageType, TFeatureImageType>::VectorType |
| 99 |
|
SegmentationLevelSetFunction<TImageType, TFeatureImageType> |
| 100 |
|
::AdvectionField(const NeighborhoodType &neighborhood, |
| 101 |
|
const FloatOffsetType &offset, GlobalDataStruct *) const |
| 102 |
|
{ |
| 103 |
|
IndexType idx = neighborhood.GetIndex(); |
| 104 |
|
ContinuousIndexType cdx; |
| 105 |
|
for (unsigned i = 0; i < ImageDimension; ++i) |
| 106 |
|
{ |
| 107 |
|
cdx[i] = static_cast<double>(idx[i]) - offset[i]; |
| 108 |
|
} |
| 109 |
|
if ( m_VectorInterpolator->IsInsideBuffer(cdx) ) |
| 110 |
|
{ |
| 111 |
LEN |
return ( m_VectorCast(m_VectorInterpolator->EvaluateAtContinuousIndex(cdx))); |
| 112 |
|
} |
| 113 |
|
//Just return the default else |
| 114 |
IND |
****return ( m_AdvectionImage->GetPixel(idx) ); |
| 115 |
|
|
| 116 |
|
} |
| 117 |
|
|
| 118 |
|
} // end namespace itk |
| 119 |
|
|
| 120 |
|
#endif |
| 121 |
|
|