Skip to content

Commit

Permalink
PERF: ImageMaskSpatialObject use image regions from its base class
Browse files Browse the repository at this point in the history
A significant performance improvement appears to be achieved by using the
buffered region and the requested region as cached in its base class, instead
of calling the virtual functions `GetBufferedRegion()` and
`GetRequestedRegion()` from its image.

A performance improvement of more than 8 percent was observed, from more than
0.80 sec. (before this commit) to less than 0.73 sec. (after this commit), when
calling `ImageMaskSpatialObject::IsInsideInObjectSpace` 2^27 times, using a
Visual Studio 2022 Release build.
  • Loading branch information
N-Dekker authored and hjmjohnson committed Feb 7, 2024
1 parent 5e528ec commit 671d758
Showing 1 changed file with 2 additions and 2 deletions.
Expand Up @@ -39,7 +39,7 @@ ImageMaskSpatialObject<TDimension, TPixel>::IsInsideInObjectSpace(const PointTyp

const IndexType index = image->TransformPhysicalPointToIndex(point);

return image->GetBufferedRegion().IsInside(index) &&
return Superclass::GetBufferedRegion().IsInside(index) &&
Math::NotExactlyEquals(image->GetPixel(index), NumericTraits<PixelType>::ZeroValue());
}

Expand Down Expand Up @@ -163,7 +163,7 @@ ImageMaskSpatialObject<TDimension, TPixel>::ComputeMyBoundingBoxInIndexSpace() c
return RegionType{ minIndex, regionSize };
};

const RegionType requestedRegion = image.GetRequestedRegion();
const RegionType requestedRegion = Superclass::GetRequestedRegion();

if (requestedRegion.GetNumberOfPixels() == 0)
{
Expand Down

0 comments on commit 671d758

Please sign in to comment.