Skip to content

Commit

Permalink
ENH: average possible overlapping points.
Browse files Browse the repository at this point in the history
  • Loading branch information
ntustison committed Dec 31, 2022
1 parent 6d37a42 commit 8c10b7d
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions ants/lib/LOCAL_fitBsplineDisplacementFieldToScatteredData.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,22 @@ py::capsule fitBsplineVectorImageToScatteredDataHelper(
weightImage->Allocate();
weightImage->FillBuffer( 0.0 );

WeightImagePointerType countImage = WeightImageType::New();
countImage->SetOrigin( bsplineFilter->GetBSplineDomainOrigin() );
countImage->SetSpacing( bsplineFilter->GetBSplineDomainSpacing() );
countImage->SetDirection( bsplineFilter->GetBSplineDomainDirection() );
countImage->SetRegions( bsplineFilter->GetBSplineDomainSize() );
countImage->Allocate();
countImage->FillBuffer( 0.0 );

VectorType zeroVector( 0.0 );
ITKFieldPointerType rasterizedField = ITKFieldType::New();
rasterizedField->SetOrigin( bsplineFilter->GetBSplineDomainOrigin() );
rasterizedField->SetSpacing( bsplineFilter->GetBSplineDomainSpacing() );
rasterizedField->SetDirection( bsplineFilter->GetBSplineDomainDirection() );
rasterizedField->SetRegions( bsplineFilter->GetBSplineDomainSize() );
rasterizedField->Allocate();
rasterizedField->FillBuffer( zeroVector );

for( unsigned int n = 0; n < numberOfPoints; n++ )
{
Expand All @@ -126,34 +136,37 @@ py::capsule fitBsplineVectorImageToScatteredDataHelper(
imagePoint[d] = displacementOriginsP(n, d);
imageDisplacement[d] = displacementsP(n, d);
}
typename ITKFieldType::IndexType imageIndex =
typename ITKFieldType::IndexType imageIndex =
weightImage->TransformPhysicalPointToIndex( imagePoint );
weightImage->SetPixel( imageIndex, displacementWeights[n] );
rasterizedField->SetPixel( imageIndex, imageDisplacement );
weightImage->SetPixel( imageIndex, displacementWeights[n] + weightImage->GetPixel( imageIndex ) );
rasterizedField->SetPixel( imageIndex, imageDisplacement + rasterizedField->GetPixel( imageIndex ) );
countImage->SetPixel( imageIndex, 1.0 + countImage->GetPixel( imageIndex ) );
}

// Second, iterate through the weight image and pull those indices/points which have non-zero weights.

unsigned count = 0;
unsigned count = 0;

typename itk::ImageRegionIteratorWithIndex<WeightImageType>
ItW( weightImage, weightImage->GetLargestPossibleRegion() );
for( ItW.GoToBegin(); ! ItW.IsAtEnd(); ++ItW )
typename itk::ImageRegionIteratorWithIndex<WeightImageType>
ItC( countImage, countImage->GetLargestPossibleRegion() );
for( ItC.GoToBegin(); ! ItC.IsAtEnd(); ++ItC )
{
if( ItW.Get() > 0.0 )
if( ItC.Get() > 0.0 )
{
typename ITKFieldType::PointType imagePoint;
weightImage->TransformIndexToPhysicalPoint( ItW.GetIndex(), imagePoint );
weightImage->TransformIndexToPhysicalPoint( ItC.GetIndex(), imagePoint );
typename PointSetType::PointType point;
point.CastFrom( imagePoint );
pointSet->SetPoint( count, point );
pointSet->SetPointData( count, rasterizedField->GetPixel( ItW.GetIndex() ) );
weights->InsertElement( count, ItW.Get() );
VectorType imageDisplacement = rasterizedField->GetPixel( ItC.GetIndex() ) / ItC.Get();
RealType weight = weightImage->GetPixel( ItC.GetIndex() ) / ItC.Get();
pointSet->SetPointData( count, imageDisplacement );
weights->InsertElement( count, weight );
count++;
}
}
}
else
}
}
else
{
for( unsigned int n = 0; n < numberOfPoints; n++ )
{
Expand Down

0 comments on commit 8c10b7d

Please sign in to comment.