diff --git a/Modules/Segmentation/RegionGrowing/include/itkConfidenceConnectedImageFilter.h b/Modules/Segmentation/RegionGrowing/include/itkConfidenceConnectedImageFilter.h index 1d1178f93da..818723157eb 100644 --- a/Modules/Segmentation/RegionGrowing/include/itkConfidenceConnectedImageFilter.h +++ b/Modules/Segmentation/RegionGrowing/include/itkConfidenceConnectedImageFilter.h @@ -141,9 +141,11 @@ class ITK_TEMPLATE_EXPORT ConfidenceConnectedImageFilter : public ImageToImageFi * executed using the Update() method. */ itkGetConstReferenceMacro(Variance, InputRealType); - /** Method to access seed container. */ - virtual const SeedsContainerType & - GetSeeds() const; + /** Set/Get the seed container. */ + /** @ITKStartGrouping */ + itkSetMacro(Seeds, SeedsContainerType); + itkGetConstReferenceMacro(Seeds, SeedsContainerType); + /** @ITKEndGrouping */ itkConceptMacro(InputHasNumericTraitsCheck, (Concept::HasNumericTraits)); itkConceptMacro(OutputHasNumericTraitsCheck, (Concept::HasNumericTraits)); diff --git a/Modules/Segmentation/RegionGrowing/include/itkConfidenceConnectedImageFilter.hxx b/Modules/Segmentation/RegionGrowing/include/itkConfidenceConnectedImageFilter.hxx index 7f8018c98e8..e311c9b1f0e 100644 --- a/Modules/Segmentation/RegionGrowing/include/itkConfidenceConnectedImageFilter.hxx +++ b/Modules/Segmentation/RegionGrowing/include/itkConfidenceConnectedImageFilter.hxx @@ -69,14 +69,6 @@ ConfidenceConnectedImageFilter::AddSeed(const IndexTy this->Modified(); } -template -auto -ConfidenceConnectedImageFilter::GetSeeds() const -> const SeedsContainerType & -{ - itkDebugMacro("returning Seeds"); - return this->m_Seeds; -} - template void ConfidenceConnectedImageFilter::PrintSelf(std::ostream & os, Indent indent) const diff --git a/Modules/Segmentation/RegionGrowing/include/itkConnectedThresholdImageFilter.h b/Modules/Segmentation/RegionGrowing/include/itkConnectedThresholdImageFilter.h index b7da78c114d..a12100e3a44 100644 --- a/Modules/Segmentation/RegionGrowing/include/itkConnectedThresholdImageFilter.h +++ b/Modules/Segmentation/RegionGrowing/include/itkConnectedThresholdImageFilter.h @@ -89,6 +89,7 @@ class ITK_TEMPLATE_EXPORT ConnectedThresholdImageFilter : public ImageToImageFil using InputImagePixelType = typename InputImageType::PixelType; using IndexType = typename InputImageType::IndexType; using SeedContainerType = std::vector; + using SeedsContainerType = SeedContainerType; using SizeType = typename InputImageType::SizeType; using OutputImageType = TOutputImage; @@ -110,9 +111,11 @@ class ITK_TEMPLATE_EXPORT ConnectedThresholdImageFilter : public ImageToImageFil void ClearSeeds(); - /** Method to access seed container. */ - virtual const SeedContainerType & - GetSeeds() const; + /** Set/Get the seed container. */ + /** @ITKStartGrouping */ + itkSetMacro(Seeds, SeedsContainerType); + itkGetConstReferenceMacro(Seeds, SeedsContainerType); + /** @ITKEndGrouping */ /** Set/Get value to replace thresholded pixels. Pixels that lie * * within Lower and Upper (inclusive) will be replaced with this diff --git a/Modules/Segmentation/RegionGrowing/include/itkConnectedThresholdImageFilter.hxx b/Modules/Segmentation/RegionGrowing/include/itkConnectedThresholdImageFilter.hxx index fc1d9825780..e7c17bb4d18 100644 --- a/Modules/Segmentation/RegionGrowing/include/itkConnectedThresholdImageFilter.hxx +++ b/Modules/Segmentation/RegionGrowing/include/itkConnectedThresholdImageFilter.hxx @@ -69,13 +69,6 @@ ConnectedThresholdImageFilter::ClearSeeds() } } -template -auto -ConnectedThresholdImageFilter::GetSeeds() const -> const SeedContainerType & -{ - return this->m_Seeds; -} - template void ConnectedThresholdImageFilter::GenerateInputRequestedRegion() diff --git a/Modules/Segmentation/RegionGrowing/include/itkIsolatedConnectedImageFilter.h b/Modules/Segmentation/RegionGrowing/include/itkIsolatedConnectedImageFilter.h index 6d563f0e7de..4310d297b9c 100644 --- a/Modules/Segmentation/RegionGrowing/include/itkIsolatedConnectedImageFilter.h +++ b/Modules/Segmentation/RegionGrowing/include/itkIsolatedConnectedImageFilter.h @@ -144,10 +144,10 @@ class ITK_TEMPLATE_EXPORT IsolatedConnectedImageFilter : public ImageToImageFilt /** Method to access seed container */ /** @ITKStartGrouping */ - virtual const SeedsContainerType & - GetSeeds1() const; - virtual const SeedsContainerType & - GetSeeds2() const; + itkSetMacro(Seeds1, SeedsContainerType); + itkGetConstReferenceMacro(Seeds1, SeedsContainerType); + itkSetMacro(Seeds2, SeedsContainerType); + itkGetConstReferenceMacro(Seeds2, SeedsContainerType); /** @ITKEndGrouping */ /** Set/Get the limit on the lower threshold value. The default is * the NonpositiveMin() for the InputPixelType. */ diff --git a/Modules/Segmentation/RegionGrowing/include/itkIsolatedConnectedImageFilter.hxx b/Modules/Segmentation/RegionGrowing/include/itkIsolatedConnectedImageFilter.hxx index 9f8792ca6d4..d668794fd50 100644 --- a/Modules/Segmentation/RegionGrowing/include/itkIsolatedConnectedImageFilter.hxx +++ b/Modules/Segmentation/RegionGrowing/include/itkIsolatedConnectedImageFilter.hxx @@ -137,22 +137,6 @@ IsolatedConnectedImageFilter::ClearSeeds2() } } -template -auto -IsolatedConnectedImageFilter::GetSeeds1() const -> const SeedsContainerType & -{ - itkDebugMacro("returning Seeds1"); - return this->m_Seeds1; -} - -template -auto -IsolatedConnectedImageFilter::GetSeeds2() const -> const SeedsContainerType & -{ - itkDebugMacro("returning Seeds2"); - return this->m_Seeds2; -} - template void IsolatedConnectedImageFilter::GenerateData() diff --git a/Modules/Segmentation/RegionGrowing/include/itkNeighborhoodConnectedImageFilter.h b/Modules/Segmentation/RegionGrowing/include/itkNeighborhoodConnectedImageFilter.h index 4049de080cd..1516fb49bc0 100644 --- a/Modules/Segmentation/RegionGrowing/include/itkNeighborhoodConnectedImageFilter.h +++ b/Modules/Segmentation/RegionGrowing/include/itkNeighborhoodConnectedImageFilter.h @@ -58,6 +58,8 @@ class ITK_TEMPLATE_EXPORT NeighborhoodConnectedImageFilter : public ImageToImage using IndexType = typename InputImageType::IndexType; using InputImageSizeType = typename InputImageType::SizeType; + using SeedsContainerType = std::vector; + using OutputImageType = TOutputImage; using OutputImagePointer = typename OutputImageType::Pointer; using OutputImageRegionType = typename OutputImageType::RegionType; @@ -78,6 +80,12 @@ class ITK_TEMPLATE_EXPORT NeighborhoodConnectedImageFilter : public ImageToImage void AddSeed(const IndexType & seed); + /** Set/Get the seed container. */ + /** @ITKStartGrouping */ + itkSetMacro(Seeds, SeedsContainerType); + itkGetConstReferenceMacro(Seeds, SeedsContainerType); + /** @ITKEndGrouping */ + /** Set/Get the lower threshold. The default is 0. */ /** @ITKStartGrouping */ itkSetMacro(Lower, InputImagePixelType); @@ -115,7 +123,7 @@ class ITK_TEMPLATE_EXPORT NeighborhoodConnectedImageFilter : public ImageToImage protected: NeighborhoodConnectedImageFilter(); ~NeighborhoodConnectedImageFilter() override = default; - std::vector m_Seeds{}; + SeedsContainerType m_Seeds{}; InputImagePixelType m_Lower{}; InputImagePixelType m_Upper{}; diff --git a/Modules/Segmentation/RegionGrowing/include/itkVectorConfidenceConnectedImageFilter.h b/Modules/Segmentation/RegionGrowing/include/itkVectorConfidenceConnectedImageFilter.h index ce9a5e0d485..28b3e206b97 100644 --- a/Modules/Segmentation/RegionGrowing/include/itkVectorConfidenceConnectedImageFilter.h +++ b/Modules/Segmentation/RegionGrowing/include/itkVectorConfidenceConnectedImageFilter.h @@ -140,9 +140,11 @@ class ITK_TEMPLATE_EXPORT VectorConfidenceConnectedImageFilter : public ImageToI const CovarianceMatrixType & GetCovariance() const; - /** Method to access seed container */ - virtual const SeedsContainerType & - GetSeeds() const; + /** Set/Get the seed container. */ + /** @ITKStartGrouping */ + itkSetMacro(Seeds, SeedsContainerType); + itkGetConstReferenceMacro(Seeds, SeedsContainerType); + /** @ITKEndGrouping */ itkConceptMacro(OutputEqualityComparableCheck, (Concept::EqualityComparable)); itkConceptMacro(InputHasNumericTraitsCheck, (Concept::HasNumericTraits)); diff --git a/Modules/Segmentation/RegionGrowing/include/itkVectorConfidenceConnectedImageFilter.hxx b/Modules/Segmentation/RegionGrowing/include/itkVectorConfidenceConnectedImageFilter.hxx index 24d08b51b1f..1e4bc5d7758 100644 --- a/Modules/Segmentation/RegionGrowing/include/itkVectorConfidenceConnectedImageFilter.hxx +++ b/Modules/Segmentation/RegionGrowing/include/itkVectorConfidenceConnectedImageFilter.hxx @@ -352,14 +352,6 @@ VectorConfidenceConnectedImageFilter::GetMean() const return m_ThresholdFunction->GetMean(); } -template -auto -VectorConfidenceConnectedImageFilter::GetSeeds() const -> const SeedsContainerType & -{ - itkDebugMacro("returning Seeds"); - return this->m_Seeds; -} - } // end namespace itk #endif diff --git a/Modules/Segmentation/RegionGrowing/test/itkConfidenceConnectedImageFilterTest.cxx b/Modules/Segmentation/RegionGrowing/test/itkConfidenceConnectedImageFilterTest.cxx index 1a26b004a13..3f49aa75462 100644 --- a/Modules/Segmentation/RegionGrowing/test/itkConfidenceConnectedImageFilterTest.cxx +++ b/Modules/Segmentation/RegionGrowing/test/itkConfidenceConnectedImageFilterTest.cxx @@ -102,6 +102,22 @@ itkConfidenceConnectedImageFilterTest(int argc, char * argv[]) // Exercise AddSeed() method filter->AddSeed(seed); + // Exercise SetSeeds/GetSeeds container interface + const FilterType::SeedsContainerType seeds = filter->GetSeeds(); + filter->ClearSeeds(); + if (!filter->GetSeeds().empty()) + { + std::cerr << "Test FAILED!" << std::endl; + std::cerr << "Seed container not empty after ClearSeeds." << std::endl; + return EXIT_FAILURE; + } + filter->SetSeeds(seeds); + if (filter->GetSeeds() != seeds) + { + std::cerr << "Test FAILED!" << std::endl; + std::cerr << "Seed container from GetSeeds does not match SetSeeds input." << std::endl; + return EXIT_FAILURE; + } return EXIT_SUCCESS; } diff --git a/Modules/Segmentation/RegionGrowing/test/itkConnectedThresholdImageFilterTest.cxx b/Modules/Segmentation/RegionGrowing/test/itkConnectedThresholdImageFilterTest.cxx index cfdcd87c1cc..28ba82b16dc 100644 --- a/Modules/Segmentation/RegionGrowing/test/itkConnectedThresholdImageFilterTest.cxx +++ b/Modules/Segmentation/RegionGrowing/test/itkConnectedThresholdImageFilterTest.cxx @@ -79,6 +79,18 @@ itkConnectedThresholdImageFilterTest(int argc, char * argv[]) return EXIT_FAILURE; } + // Exercise SetSeeds/GetSeeds container interface using SeedsContainerType alias + connectedThresholdFilter->AddSeed(seed); + const ConnectedThresholdImageFilterType::SeedsContainerType seeds = connectedThresholdFilter->GetSeeds(); + connectedThresholdFilter->ClearSeeds(); + connectedThresholdFilter->SetSeeds(seeds); + if (connectedThresholdFilter->GetSeeds() != seeds) + { + std::cerr << "Test FAILED !" << std::endl; + std::cerr << "Seed container from GetSeeds does not match SetSeeds input." << std::endl; + return EXIT_FAILURE; + } + connectedThresholdFilter->SetSeed(seed); diff --git a/Modules/Segmentation/RegionGrowing/test/itkIsolatedConnectedImageFilterTest.cxx b/Modules/Segmentation/RegionGrowing/test/itkIsolatedConnectedImageFilterTest.cxx index 0643668801b..cb0f3c1c474 100644 --- a/Modules/Segmentation/RegionGrowing/test/itkIsolatedConnectedImageFilterTest.cxx +++ b/Modules/Segmentation/RegionGrowing/test/itkIsolatedConnectedImageFilterTest.cxx @@ -75,6 +75,29 @@ itkIsolatedConnectedImageFilterTest(int argc, char * argv[]) filter->AddSeed2(seed1); } + // Exercise the seed-container accessors. Round-trip the populated + // containers through SetSeeds/GetSeeds, leaving the filter unchanged. + const FilterType::SeedsContainerType seeds1 = filter->GetSeeds1(); + const FilterType::SeedsContainerType seeds2 = filter->GetSeeds2(); + + filter->ClearSeeds1(); + filter->ClearSeeds2(); + if (!filter->GetSeeds1().empty() || !filter->GetSeeds2().empty()) + { + std::cerr << "Test failed!" << std::endl; + std::cerr << "Seed containers were not cleared by ClearSeeds." << std::endl; + return EXIT_FAILURE; + } + + filter->SetSeeds1(seeds1); + filter->SetSeeds2(seeds2); + if (filter->GetSeeds1() != seeds1 || filter->GetSeeds2() != seeds2) + { + std::cerr << "Test failed!" << std::endl; + std::cerr << "Seed containers retrieved by GetSeeds do not match those set by SetSeeds." << std::endl; + return EXIT_FAILURE; + } + // The min and max values for a .png image constexpr FilterType::InputImagePixelType lower{ 0 }; filter->SetLower(lower); diff --git a/Modules/Segmentation/RegionGrowing/test/itkNeighborhoodConnectedImageFilterTest.cxx b/Modules/Segmentation/RegionGrowing/test/itkNeighborhoodConnectedImageFilterTest.cxx index 273400fccc5..d037877e899 100644 --- a/Modules/Segmentation/RegionGrowing/test/itkNeighborhoodConnectedImageFilterTest.cxx +++ b/Modules/Segmentation/RegionGrowing/test/itkNeighborhoodConnectedImageFilterTest.cxx @@ -83,5 +83,22 @@ itkNeighborhoodConnectedImageFilterTest(int argc, char * argv[]) writer->SetFileName(argv[2]); writer->Update(); + // Exercise SetSeeds/GetSeeds container interface + const FilterType::SeedsContainerType seeds = filter->GetSeeds(); + filter->ClearSeeds(); + if (!filter->GetSeeds().empty()) + { + std::cerr << "Test FAILED!" << std::endl; + std::cerr << "Seed container not empty after ClearSeeds." << std::endl; + return EXIT_FAILURE; + } + filter->SetSeeds(seeds); + if (filter->GetSeeds() != seeds) + { + std::cerr << "Test FAILED!" << std::endl; + std::cerr << "Seed container from GetSeeds does not match SetSeeds input." << std::endl; + return EXIT_FAILURE; + } + return EXIT_SUCCESS; } diff --git a/Modules/Segmentation/RegionGrowing/test/itkVectorConfidenceConnectedImageFilterTest.cxx b/Modules/Segmentation/RegionGrowing/test/itkVectorConfidenceConnectedImageFilterTest.cxx index 9ad24b5af45..06868a4fbae 100644 --- a/Modules/Segmentation/RegionGrowing/test/itkVectorConfidenceConnectedImageFilterTest.cxx +++ b/Modules/Segmentation/RegionGrowing/test/itkVectorConfidenceConnectedImageFilterTest.cxx @@ -104,6 +104,23 @@ itkVectorConfidenceConnectedImageFilterTest(int argc, char * argv[]) writer->SetFileName(argv[2]); writer->Update(); + // Exercise SetSeeds/GetSeeds container interface + const FilterType::SeedsContainerType seeds = filter->GetSeeds(); + filter->ClearSeeds(); + if (!filter->GetSeeds().empty()) + { + std::cerr << "Test FAILED!" << std::endl; + std::cerr << "Seed container not empty after ClearSeeds." << std::endl; + return EXIT_FAILURE; + } + filter->SetSeeds(seeds); + if (filter->GetSeeds() != seeds) + { + std::cerr << "Test FAILED!" << std::endl; + std::cerr << "Seed container from GetSeeds does not match SetSeeds input." << std::endl; + return EXIT_FAILURE; + } + // Exercise SetSeed() method filter->SetSeed(seed1);