Skip to content

Commit c60439c

Browse files
committed
PERF: Locally cache ComputeIndex() result in Watershed Segmenter
Avoided calling `ImageConstIterator::ComputeIndex()` multiple times on one and the same iterator, in one and the same iteration, by caching the computed index, in `watershed::Segmenter::GradientDescent`
1 parent d086c8c commit c60439c

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Modules/Segmentation/Watersheds/include/itkWatershedSegmenter.hxx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -820,8 +820,9 @@ Segmenter<TInputImage>::GradientDescent(InputImageTypePointer img, ImageRegionTy
820820
{
821821
if (it.Get() == NULL_LABEL)
822822
{
823-
valueIt.SetLocation(it.ComputeIndex());
824-
labelIt.SetLocation(it.ComputeIndex());
823+
const auto computeIndex = it.ComputeIndex();
824+
valueIt.SetLocation(computeIndex);
825+
labelIt.SetLocation(computeIndex);
825826
IdentifierType newLabel = NULL_LABEL; // Follow the path of steep-
826827
while (newLabel == NULL_LABEL) // est descent until a label
827828
{

0 commit comments

Comments
 (0)