18 #ifndef __itkMultiphaseSparseFiniteDifferenceImageFilter_txx
19 #define __itkMultiphaseSparseFiniteDifferenceImageFilter_txx
25 template<
class TInputImage,
class TFeatureImage,
class TOutputImage,
class TFunction,
typename TIdCell >
26 double MultiphaseSparseFiniteDifferenceImageFilter< TInputImage, TFeatureImage, TOutputImage, TFunction, TIdCell >
27 ::m_ConstantGradientValue = 1.0;
29 template<
class TInputImage,
class TFeatureImage,
class TOutputImage,
class TFunction,
typename TIdCell >
30 const ITK_TYPENAME MultiphaseSparseFiniteDifferenceImageFilter< TInputImage, TFeatureImage,
31 TOutputImage, TFunction, TIdCell >::ValueType
32 MultiphaseSparseFiniteDifferenceImageFilter< TInputImage, TFeatureImage, TOutputImage, TFunction, TIdCell >
34 MultiphaseSparseFiniteDifferenceImageFilter< TInputImage, TFeatureImage, TOutputImage, TFunction, TIdCell >
37 template<
class TInputImage,
class TFeatureImage,
class TOutputImage,
class TFunction,
typename TIdCell >
38 const ITK_TYPENAME MultiphaseSparseFiniteDifferenceImageFilter< TInputImage, TFeatureImage,
39 TOutputImage, TFunction, TIdCell >::ValueType
40 MultiphaseSparseFiniteDifferenceImageFilter< TInputImage, TFeatureImage, TOutputImage, TFunction, TIdCell >
42 MultiphaseSparseFiniteDifferenceImageFilter< TInputImage, TFeatureImage, TOutputImage, TFunction, TIdCell >::
45 template<
class TInputImage,
class TFeatureImage,
class TOutputImage,
class TFunction,
typename TIdCell >
46 const ITK_TYPENAME MultiphaseSparseFiniteDifferenceImageFilter< TInputImage, TFeatureImage,
47 TOutputImage, TFunction, TIdCell >::StatusType
48 MultiphaseSparseFiniteDifferenceImageFilter< TInputImage, TFeatureImage, TOutputImage, TFunction, TIdCell >
50 MultiphaseSparseFiniteDifferenceImageFilter< TInputImage, TFeatureImage, TOutputImage, TFunction, TIdCell >::
51 StatusType >::NonpositiveMin();
53 template<
class TInputImage,
class TFeatureImage,
class TOutputImage,
class TFunction,
typename TIdCell >
54 const ITK_TYPENAME MultiphaseSparseFiniteDifferenceImageFilter< TInputImage, TFeatureImage,
55 TOutputImage, TFunction, TIdCell >::StatusType
56 MultiphaseSparseFiniteDifferenceImageFilter< TInputImage, TFeatureImage, TOutputImage, TFunction, TIdCell >
57 ::m_StatusChanging = -1;
59 template<
class TInputImage,
class TFeatureImage,
class TOutputImage,
class TFunction,
typename TIdCell >
60 const ITK_TYPENAME MultiphaseSparseFiniteDifferenceImageFilter< TInputImage, TFeatureImage,
61 TOutputImage, TFunction, TIdCell >::StatusType
62 MultiphaseSparseFiniteDifferenceImageFilter< TInputImage, TFeatureImage, TOutputImage, TFunction, TIdCell >
63 ::m_StatusActiveChangingUp = -2;
65 template<
class TInputImage,
class TFeatureImage,
class TOutputImage,
class TFunction,
typename TIdCell >
66 const ITK_TYPENAME MultiphaseSparseFiniteDifferenceImageFilter< TInputImage, TFeatureImage,
67 TOutputImage, TFunction, TIdCell >::StatusType
68 MultiphaseSparseFiniteDifferenceImageFilter< TInputImage, TFeatureImage, TOutputImage, TFunction, TIdCell >
69 ::m_StatusActiveChangingDown = -3;
71 template<
class TInputImage,
class TFeatureImage,
class TOutputImage,
class TFunction,
typename TIdCell >
72 const ITK_TYPENAME MultiphaseSparseFiniteDifferenceImageFilter< TInputImage, TFeatureImage,
73 TOutputImage, TFunction, TIdCell >::StatusType
74 MultiphaseSparseFiniteDifferenceImageFilter< TInputImage, TFeatureImage, TOutputImage, TFunction, TIdCell >
75 ::m_StatusBoundaryPixel = -4;
77 template<
class TInputImage,
class TFeatureImage,
class TOutputImage,
class TFunction,
typename TIdCell >
81 this->m_CurrentFunctionIndex = 0;
82 this->m_IsoSurfaceValue = m_ValueZero;
83 this->m_BackgroundValue = NumericTraits<ValueType>::max();
84 this->m_NumberOfLayers = ImageDimension;
85 this->m_InterpolateSurfaceLocation =
true;
86 this->m_BoundsCheckingActive =
false;
89 template<
class TInputImage,
class TFeatureImage,
class TOutputImage,
class TFunction,
typename TIdCell >
94 for(
IdCellType i = 0; i < this->m_FunctionCount; i++ )
100 tempImage->SetRegions( input->GetRequestedRegion() );
101 tempImage->CopyInformation( input );
102 tempImage->Allocate();
122 zeroCrossingFilter->SetInput( tempImage );
123 zeroCrossingFilter->SetBackgroundValue( m_ValueOne );
124 zeroCrossingFilter->SetForegroundValue( m_ValueZero );
125 zeroCrossingFilter->Update();
135 if ( zIt.Get() == 0 )
145 template <
class TInputImage,
class TFeatureImage,
class TOutputImage,
class TFunction,
typename TIdCell >
147 TOutputImage, TFunction, TIdCell >::TimeStepType
152 TimeStepType minTimeStep = NumericTraits< TimeStepType >::max();
157 for (
IdCellType fId = 0; fId < this->m_FunctionCount; ++fId )
159 this->m_CurrentFunctionIndex = fId;
167 forward, backward, current;
170 void *globalData = df->GetGlobalDataPointer();
173 this->m_LevelSet[fId], this->m_LevelSet[fId]->GetRequestedRegion() );
175 if( m_BoundsCheckingActive ==
false )
191 while( layerIt != sparsePtr->
m_Layers[0]->End() )
193 outputIt.SetLocation ( layerIt->m_Value );
195 current = outputIt.GetCenterPixel();
200 if ( this->GetInterpolateSurfaceLocation() && current != 0.0 )
206 gradientMagnitudeSqr = 0.0;
208 for ( j = 0; j < ImageDimension; ++j )
210 forward = outputIt.GetNext ( j );
211 backward = outputIt.GetPrevious ( j );
213 if ( forward * backward >= 0 )
217 if ( vnl_math_abs ( forward - current ) > vnl_math_abs( current - backward ) )
219 offset[j] = ( forward - current ) / spacing[j];
223 offset[j] = ( current - backward ) / spacing[j];
228 if ( forward * current < 0 )
230 offset[j] = ( forward - current ) / spacing[j];
234 offset[j] = ( current - backward ) / spacing[j];
238 gradientMagnitudeSqr += offset[j] * offset[j];
246 ValueType coeff = current * vcl_sqrt( ImageDimension
247 + 0.5 ) / ( gradientMagnitudeSqr + MIN_NORM );
249 for ( j = 0; j < ImageDimension; ++j )
254 sparsePtr->
m_UpdateBuffer.push_back ( df->ComputeUpdate ( outputIt, globalData, offset ) );
258 sparsePtr->
m_UpdateBuffer.push_back ( df->ComputeUpdate ( outputIt, globalData ) );
267 timeStep = df->ComputeGlobalTimeStep ( globalData );
268 df->ReleaseGlobalDataPointer ( globalData );
270 if ( timeStep < minTimeStep )
272 minTimeStep = timeStep;
282 template<
class TInputImage,
class TFeatureImage,
class TOutputImage,
class TFunction,
typename TIdCell >
291 for (
IdCellType fId = 0; fId < this->m_FunctionCount; ++fId )
293 this->m_CurrentFunctionIndex = fId;
304 for ( j = 0; j < 2; ++j )
306 UpList[j] = LayerType::New();
307 DownList[j] = LayerType::New();
316 this->UpdateActiveLayerValues( dt, UpList[0], DownList[0] );
323 this->ProcessStatusList ( UpList[0], UpList[1], 2, 1 );
324 this->ProcessStatusList ( DownList[0], DownList[1], 1, 2 );
331 while ( down_search < static_cast<StatusType>(sparsePtr->
m_Layers.size()))
333 this->ProcessStatusList(UpList[j], UpList[k], up_to, up_search );
334 this->ProcessStatusList(DownList[j], DownList[k], down_to, down_search);
357 this->ProcessStatusList(UpList[j], UpList[k], up_to, m_StatusNull );
358 this->ProcessStatusList(DownList[j], DownList[k], down_to, m_StatusNull);
363 this->ProcessOutsideList ( UpList[k], static_cast<signed char> (
365 this->ProcessOutsideList ( DownList[k], static_cast<signed char> (
370 this->PropagateAllLayerValues();
373 this->m_CurrentFunctionIndex = 0;
376 template <
class TInputImage,
class TFeatureImage,
class TOutputImage,
377 class TFunction,
typename TIdCell >
384 SparseDataStruct *sparsePtr = this->m_SparseData[this->m_CurrentFunctionIndex];
389 while ( ! OutsideList->
Empty() )
392 node = OutsideList->
Front();
394 sparsePtr->
m_Layers[ChangeToStatus]->PushFront ( node );
398 template<
class TInputImage,
class TFeatureImage,
class TOutputImage,
class TFunction,
typename TIdCell >
406 SparseDataStruct *sparsePtr = this->m_SparseData[this->m_CurrentFunctionIndex];
414 this->m_LevelSet[this->m_CurrentFunctionIndex]->GetRequestedRegion() );
416 if ( !m_BoundsCheckingActive )
425 while ( ! InputList->
Empty() )
427 statusIt.SetLocation ( InputList->
Front()->m_Value );
428 statusIt.SetCenterPixel ( ChangeToStatus );
430 node = InputList->
Front();
432 sparsePtr->
m_Layers[ChangeToStatus]->PushFront ( node );
435 for ( i = 0; i < m_NeighborList.GetSize(); ++i )
437 neighbor_status = statusIt.GetPixel (
438 m_NeighborList.GetArrayIndex ( i ) );
442 if ( neighbor_status == m_StatusBoundaryPixel )
444 m_BoundsCheckingActive =
true;
448 if ( neighbor_status == SearchForStatus )
451 statusIt.SetPixel ( m_NeighborList.GetArrayIndex ( i ),
452 m_StatusChanging, bounds_status );
453 if ( bounds_status ==
true )
456 node->
m_Value = statusIt.GetIndex() +
457 m_NeighborList.GetNeighborhoodOffset ( i );
466 template<
class TInputImage,
class TFeatureImage,
class TOutputImage,
class TFunction,
typename TIdCell >
474 SparseDataStruct *sparsePtr = this->m_SparseData[this->m_CurrentFunctionIndex];
485 const ValueType LOWER_ACTIVE_THRESHOLD = -( m_ConstantGradientValue/2.0 );
486 const ValueType UPPER_ACTIVE_THRESHOLD = m_ConstantGradientValue / 2.0;
492 bool bounds_status, flag;
498 outputIt ( m_NeighborList.GetRadius(),
499 this->m_LevelSet[this->m_CurrentFunctionIndex],
500 this->m_LevelSet[this->m_CurrentFunctionIndex]->GetRequestedRegion() );
503 statusIt ( m_NeighborList.GetRadius(),
505 this->m_LevelSet[this->m_CurrentFunctionIndex]->GetRequestedRegion() );
508 if ( !m_BoundsCheckingActive )
511 statusIt.NeedToUseBoundaryConditionOff();
516 layerIt = sparsePtr->
m_Layers[0]->Begin();
519 while( layerIt != sparsePtr->
m_Layers[0]->End() )
521 outputIt.SetLocation ( layerIt->m_Value );
522 statusIt.SetLocation ( layerIt->m_Value );
524 new_value = this->CalculateUpdateValue ( layerIt->m_Value,
525 dt, outputIt.GetCenterPixel(), *updateIt );
538 if ( new_value >= UPPER_ACTIVE_THRESHOLD )
546 for ( i = 0; i < m_NeighborList.GetSize(); ++i )
548 if ( statusIt.GetPixel( m_NeighborList.GetArrayIndex( i ) )
549 == m_StatusActiveChangingDown )
564 for ( i = 0; i < m_NeighborList.GetSize(); ++i )
566 temp_value = new_value - m_ConstantGradientValue * m_PixelDistance[i];
567 idx = m_NeighborList.GetArrayIndex ( i );
568 neighbor_status = statusIt.GetPixel ( idx );
570 if ( neighbor_status == 1 )
574 if ( outputIt.GetPixel ( idx ) < LOWER_ACTIVE_THRESHOLD ||
575 vnl_math_abs ( temp_value ) < vnl_math_abs (
576 outputIt.GetPixel ( idx ) ) )
578 UpdatePixel ( this->m_CurrentFunctionIndex, idx, outputIt, temp_value, bounds_status );
584 node->
m_Value = layerIt->m_Value;
586 statusIt.SetCenterPixel ( m_StatusActiveChangingUp );
590 sparsePtr->
m_Layers[0]->Unlink ( release_node );
594 else if ( new_value < LOWER_ACTIVE_THRESHOLD )
602 for ( i = 0; i < m_NeighborList.GetSize(); ++i )
605 if ( statusIt.GetPixel( m_NeighborList.GetArrayIndex( i ) )
606 == m_StatusActiveChangingUp )
621 for ( i = 0; i < m_NeighborList.GetSize(); ++i )
623 temp_value = new_value + m_ConstantGradientValue * m_PixelDistance[i];
624 idx = m_NeighborList.GetArrayIndex ( i );
625 neighbor_status = statusIt.GetPixel ( idx );
626 if ( neighbor_status == 2 )
630 if ( outputIt.GetPixel ( idx ) >= UPPER_ACTIVE_THRESHOLD ||
631 vnl_math_abs ( temp_value ) < vnl_math_abs (
632 outputIt.GetPixel ( idx ) ) )
634 UpdatePixel ( this->m_CurrentFunctionIndex, idx, outputIt, temp_value, bounds_status );
640 node->
m_Value = layerIt->m_Value;
642 statusIt.SetCenterPixel ( m_StatusActiveChangingDown );
646 sparsePtr->
m_Layers[0]->Unlink ( release_node );
651 UpdatePixel( this->m_CurrentFunctionIndex, outputIt.Size()/2, outputIt, new_value, bounds_status );
660 template<
class TInputImage,
class TFeatureImage,
class TOutputImage,
class TFunction,
typename TIdCell >
665 ::InitializeActiveLayerValues()
674 for (
IdCellType i = 0; i < this->m_FunctionCount; i++ )
682 m_NeighborList.GetRadius(),
683 levelset, levelset->GetRequestedRegion() );
689 center = outputIt.Size()/2;
690 ValueType dx, gradientMagnitude, gradientMagnitudeSqr,
691 distance, forward, current, backward;
694 activeIt = sparsePtr->
m_Layers[0]->Begin();
695 while( activeIt != sparsePtr->
m_Layers[0]->End() )
699 outputIt.SetLocation ( activeIt->m_Value );
701 gradientMagnitudeSqr = m_ValueZero;
703 for (
unsigned int j = 0; j < ImageDimension; ++j )
706 forward = outputIt.GetPixel ( center + m_NeighborList.GetStride( j ) );
707 current = outputIt.GetCenterPixel();
708 backward = outputIt.GetPixel ( center - m_NeighborList.GetStride ( j ) );
710 if ( forward * backward >= 0 )
714 if ( ::vnl_math_abs ( forward - center ) >::vnl_math_abs( center - backward ) )
716 dx = ( forward - current ) / spacing[j];
720 dx = ( current - backward ) / spacing[j];
726 if ( vnl_math_sgn( current*forward ) == -1 )
728 dx = ( forward - current ) / spacing[j];
732 dx = ( current - backward ) / spacing[j];
735 gradientMagnitudeSqr += dx * dx;
737 gradientMagnitude = vcl_sqrt ( gradientMagnitudeSqr ) + MIN_NORM;
740 distance = outputIt.GetCenterPixel() / gradientMagnitude;
744 vnl_math_min ( vnl_math_max ( -MIN_NORM, distance ),
750 activeIt = sparsePtr->
m_Layers[0]->Begin();
751 while( activeIt != sparsePtr->
m_Layers[0]->End() )
755 - levelset->GetPixel ( activeIt->m_Value ) );
756 m_RMSSum += temp * temp;
759 levelset->SetPixel ( activeIt->m_Value, sparsePtr->
m_UpdateBuffer.front() );
766 template<
class TInputImage,
class TFeatureImage,
class TOutputImage,
class TFunction,
typename TIdCell >
771 ::PropagateAllLayerValues()
773 for (
IdCellType i = 0; i < this->m_FunctionCount; i++ )
776 PropagateFunctionLayerValues ( i );
780 template<
class TInputImage,
class TFeatureImage,
class TOutputImage,
class TFunction,
typename TIdCell >
785 ::PropagateFunctionLayerValues (
unsigned int fId )
793 this->PropagateLayerValues ( sparsePtr, 0, 1, 3, 1 );
794 this->PropagateLayerValues ( sparsePtr, 0, 2, 4, 2 );
797 for (
unsigned int i = 1; i < sparsePtr->
m_Layers.size() - 2; ++i )
799 this->PropagateLayerValues ( sparsePtr, i, i+2, i+4, ( i+2 ) %2 );
803 template<
class TInputImage,
class TFeatureImage,
class TOutputImage,
class TFunction,
typename TIdCell >
816 ValueType value = NumericTraits<ValueType>::Zero;
817 bool found_neighbor_flag;
825 delta = ( InOrOut == 1 ) ? -1: 1;
828 outputIt ( m_NeighborList.GetRadius(),
829 this->m_LevelSet[sparsePtr->
m_Index],
830 this->m_LevelSet[sparsePtr->
m_Index]->GetRequestedRegion() );
832 statusIt ( m_NeighborList.GetRadius(), sparsePtr->
m_StatusImage,
833 this->m_LevelSet[sparsePtr->
m_Index]->GetRequestedRegion() );
835 if ( !m_BoundsCheckingActive )
838 statusIt.NeedToUseBoundaryConditionOff();
842 toIt = sparsePtr->
m_Layers[to]->Begin();
843 while ( toIt != sparsePtr->
m_Layers[to]->End() )
847 statusIt.SetLocation ( indexCurrent );
852 if ( statusIt.GetCenterPixel() != to )
856 sparsePtr->
m_Layers[to]->Unlink ( node );
862 outputIt.SetLocation ( toIt->m_Value );
865 found_neighbor_flag =
false;
866 unsigned int indexNeighbor;
867 for ( i = 0; i < m_NeighborList.GetSize(); ++i )
872 indexNeighbor = m_NeighborList.GetArrayIndex ( i );
873 if ( statusIt.GetPixel ( indexNeighbor ) == from )
880 this->m_LevelSet[sparsePtr->
m_Index]->TransformIndexToPhysicalPoint(
881 statusIt.GetIndex( indexNeighbor ), p1 );
882 this->m_LevelSet[sparsePtr->
m_Index]->TransformIndexToPhysicalPoint(
884 for(
unsigned int j = 0; j < ImageDimension; j++ )
885 dist += (p1[j] - p2[j]) * (p1[j] - p2[j]);
886 dist = delta * vcl_sqrt( dist );
888 value_temp = dist + outputIt.GetPixel ( indexNeighbor );
890 if ( !found_neighbor_flag )
901 if ( value_temp > value )
909 if ( value_temp < value )
916 found_neighbor_flag =
true;
920 if ( found_neighbor_flag )
925 unsigned int center = outputIt.Size()/2;
927 UpdatePixel(sparsePtr->
m_Index, center, outputIt, value, bounds_status);
930 m_RMSSum += ( value - outputIt.GetCenterPixel() ) * ( value - outputIt.GetCenterPixel() );
943 sparsePtr->
m_Layers[to]->Unlink ( node );
944 if ( promote > past_end )
948 statusIt.SetCenterPixel ( m_StatusNull );
950 this->m_LevelSet[sparsePtr->
m_Index]->SetPixel( indexCurrent ,
951 delta * this->m_BackgroundValue );
955 sparsePtr->
m_Layers[promote]->PushFront ( node );
956 statusIt.SetCenterPixel ( promote );
962 template<
class TInputImage,
class TFeatureImage,
class TOutputImage,
class TFunction,
typename TIdCell >
967 Superclass::InitializeIteration();
973 this->InitializeActiveLayerValues();
976 this->PropagateAllLayerValues();
979 if ( m_RMSCounter == 0 )
981 this->SetRMSChange ( static_cast<double> ( 0. ) );
985 this->SetRMSChange ( vcl_sqrt ( m_RMSSum / m_RMSCounter ) );
990 template<
class TInputImage,
class TFeatureImage,
class TOutputImage,
class TFunction,
typename TIdCell >
1000 this->m_PixelDistance.clear();
1001 this->m_PixelDistance.resize ( m_NeighborList.GetSize() );
1002 for (
unsigned int i = 0; i < m_NeighborList.GetSize(); ++i )
1004 offset = m_NeighborList.GetNeighborhoodOffset ( i );
1005 m_PixelDistance[i] = 0;
1006 for(
unsigned int j = 0; j < ImageDimension; j++ )
1008 m_PixelDistance[i] += offset[j]*spacing[j]*offset[j]*spacing[j];
1010 m_PixelDistance[i] = vcl_sqrt( m_PixelDistance[i] );
1014 for (
IdCellType fId = 0; fId < this->m_FunctionCount; ++fId )
1021 this->m_LevelSet[fId]->GetRequestedRegion() );
1022 sparsePtr->
m_StatusImage->CopyInformation( this->m_LevelSet[fId] );
1034 typename BFCType::FaceListType::iterator fit;
1041 fit = faceList.begin();
1042 for( ++fit; fit != faceList.end(); ++fit )
1050 statusIt.
Set ( m_StatusBoundaryPixel );
1056 for (
unsigned int i = 0; i < sparsePtr->
m_Layers.size(); ++i )
1058 while ( ! sparsePtr->
m_Layers[i]->Empty() )
1061 sparsePtr->
m_Layers[i]->PopFront();
1067 sparsePtr->
m_Layers.reserve( 2 * this->m_NumberOfLayers + 1 );
1069 while( sparsePtr->
m_Layers.size() < ( 2 * this->m_NumberOfLayers+1 ) )
1071 sparsePtr->
m_Layers.push_back( LayerType::New() );
1075 if ( sparsePtr->
m_Layers.size() < 3 )
1077 itkExceptionMacro ( <<
"Not enough layers have been allocated for the"
1078 "sparse field. Requires at least one layer." );
1083 this->InitializeBackgroundConstants();
1087 this->ConstructActiveLayer();
1089 for (
IdCellType fId = 0; fId < this->m_FunctionCount; ++fId )
1097 for (
unsigned int i = 1; i < sparsePtr->
m_Layers.size() - 2; ++i )
1100 this->ConstructLayer( sparsePtr, i, i+2 );
1105 this->InitializeActiveLayerValues();
1108 this->PropagateAllLayerValues();
1114 this->InitializeBackgroundPixels();
1118 template<
class TInputImage,
class TFeatureImage,
class TOutputImage,
class TFunction,
typename TIdCell >
1125 float maxSpacing = NumericTraits<float>::min();
1127 for(
unsigned int i = 0; i < ImageDimension; i++ )
1128 maxSpacing = vnl_math_max( maxSpacing, static_cast<float>( spacing[i] ) );
1136 this->m_BackgroundValue = ( max_layer + 1 ) * maxSpacing;
1140 template<
class TInputImage,
class TFeatureImage,
class TOutputImage,
class TFunction,
typename TIdCell >
1145 for (
IdCellType fId = 0; fId < this->m_FunctionCount; fId++ )
1151 this->m_LevelSet[fId]->GetRequestedRegion() );
1154 this->m_LevelSet[fId],
1155 this->m_LevelSet[fId]->GetRequestedRegion() );
1158 statusIt.GoToBegin();
1162 if( statusIt.Get() == m_StatusNull || statusIt.Get() ==
1163 m_StatusBoundaryPixel )
1165 if( outputIt.
Get() > 0 )
1167 outputIt.Set ( this->m_BackgroundValue );
1169 if( outputIt.
Get() < 0 )
1171 outputIt.Set ( - this->m_BackgroundValue );
1181 template<
class TInputImage,
class TFeatureImage,
class TOutputImage,
class TFunction,
typename TIdCell >
1187 for (
IdCellType fId = 0; fId < this->m_FunctionCount; fId++ )
1203 outputIt ( m_NeighborList.GetRadius(),
1204 this->m_LevelSet[fId],
1205 this->m_LevelSet[fId]->GetRequestedRegion() );
1208 statusIt ( m_NeighborList.GetRadius(),
1210 this->m_LevelSet[fId]->GetRequestedRegion() );
1220 lowerBounds = this->m_LevelSet[fId]->GetRequestedRegion().GetIndex();
1221 upperBounds = this->m_LevelSet[fId]->GetRequestedRegion().GetSize();
1224 outputIt.GoToBegin();
1225 while( !outputIt.IsAtEnd() )
1229 if ( outputIt.GetCenterPixel() == m_ValueZero )
1232 center_index = outputIt.
GetIndex();
1234 statusIt.SetLocation ( center_index );
1238 for (
unsigned int i = 0; i < ImageDimension; i++ )
1240 if ( ( center_index[i] + static_cast< long > (
1241 this->m_NumberOfLayers ) >= static_cast< long>( upperBounds[i] - 1 ) )
1242 || center_index[i] - static_cast< long >(
1243 this->m_NumberOfLayers ) <= static_cast< long >(lowerBounds[i]) )
1245 m_BoundsCheckingActive =
true;
1255 sparsePtr->
m_Layers[0]->PushFront ( node );
1256 statusIt.SetCenterPixel ( 0 );
1260 for (
unsigned int i = 0; i < m_NeighborList.GetSize(); ++i )
1264 unsigned int neighborIndex = m_NeighborList.GetArrayIndex( i );
1265 if ( outputIt.GetPixel( neighborIndex ) != m_ValueZero )
1268 layer_number = ( outputIt.GetPixel ( neighborIndex ) > 0 ) ? 2 : 1;
1272 if ( statusIt.GetPixel( neighborIndex ) == m_StatusNull )
1274 statusIt.SetPixel ( neighborIndex, layer_number, bounds_status );
1276 if ( bounds_status )
1278 offset_index = center_index + m_NeighborList.GetNeighborhoodOffset ( i );
1281 sparsePtr->
m_Layers[layer_number]->PushFront ( node );
1292 template<
class TInputImage,
class TFeatureImage,
class TOutputImage,
class TFunction,
typename TIdCell >
1298 bool boundary_status;
1302 this->m_LevelSet[sparsePtr->
m_Index]->GetRequestedRegion() );
1306 fromIt = sparsePtr->
m_Layers[from]->Begin();
1309 while( fromIt != sparsePtr->
m_Layers[from]->End() )
1315 statusIt.SetLocation ( fromIt->m_Value );
1316 for (
unsigned int i = 0; i < m_NeighborList.GetSize(); ++i )
1319 unsigned int neighborIndex = m_NeighborList.GetArrayIndex ( i );
1320 if ( statusIt.GetPixel ( neighborIndex ) == m_StatusNull )
1322 statusIt.SetPixel ( neighborIndex, to, boundary_status );
1323 if ( boundary_status ==
true )
1326 node->
m_Value = statusIt.GetIndex() + m_NeighborList.GetNeighborhoodOffset ( i );
1327 sparsePtr->
m_Layers[to]->PushFront ( node );
1335 template<
class TInputImage,
class TFeatureImage,
class TOutputImage,
class TFunction,
typename TIdCell >
1342 output->FillBuffer( NumericTraits<OutputPixelType>::Zero );
1345 this->InitializeActiveLayerValues();
1347 this->PropagateAllLayerValues();
1353 this->InitializeBackgroundPixels();
1355 for (
IdCellType fId = 0; fId < this->m_FunctionCount; fId++ )
1363 this->m_LevelSet[fId]->GetRequestedRegion() );
1367 output->TransformPhysicalPointToIndex( origin, start );
1371 region.SetSize( input->GetRequestedRegion().GetSize() );
1372 region.SetIndex( start );
1374 if ( !input || !output )
1376 itkExceptionMacro ( <<
"Either input and/or output is NULL." );
1388 if ( inIt.
Get() < 0 )
1398 template<
class TInputImage,
class TFeatureImage,
class TOutputImage,
class TFunction,
typename TIdCell >
1403 Superclass::PrintSelf(os,indent);
1405 os << indent <<
"m_IsoSurfaceValue: " << this->m_IsoSurfaceValue << std::endl;
1406 os << indent <<
"m_BoundsCheckingActive: " << m_BoundsCheckingActive;
1408 for(
IdCellType i = 0; i < this->m_FunctionCount; i++ )
1411 os << indent <<
"m_LayerNodeStore: " << std::endl;
1413 for ( i = 0; i < sparsePtr->
m_Layers.size(); i++ )
1415 os << indent <<
"m_Layers[" << i <<
"]: size="
1416 << sparsePtr->
m_Layers[i]->Size() << std::endl;
1417 os << indent << sparsePtr->
m_Layers[i];
1420 os << indent <<
"m_UpdateBuffer: size=" <<
1421 static_cast< unsigned long > ( sparsePtr->
m_UpdateBuffer.size() )
1422 <<
" capacity = " <<
1423 static_cast<unsigned long> ( sparsePtr->
m_UpdateBuffer.capacity() ) <<
1427 os << indent <<
"Interpolate Surface Location " << m_InterpolateSurfaceLocation << std::endl;
1428 os << indent <<
"Number of Layers " << m_NumberOfLayers << std::endl;
1429 os << indent <<
"Value Zero " <<
1430 static_cast< typename NumericTraits<ValueType>::PrintType
>( m_ValueZero ) << std::endl;
1431 os << indent <<
"Value One " <<
1432 static_cast< typename NumericTraits<ValueType>::PrintType
>( m_ValueOne ) << std::endl;