Repository: InsightSoftwareConsortium/ITK (language: python)

Issue:
Document that Iterator(image, region) constructors of "ImageFrequency" initialize at the begin, add GTest unit test
- Follow-up to pull request #4815

- Note: `FrequencyImageRegionIteratorWithIndex` and `FrequencyImageRegionConstIteratorWithIndex` are excluded from this pull request, because they do not yet compile. (As is observed by #4828)

STYLE: Remove unused "itkFrequencyImageRegion*IteratorWithIndex.h" files
Both `FrequencyImageRegionIteratorWithIndex` and `FrequencyImageRegionConstIteratorWithIndex` appear unused and untested. Attempts to use them would trigger compile errors.

An attempt to use `FrequencyImageRegionIteratorWithIndex` triggered:

    error C3210: 'ImageRegionIteratorWithIndex<itk::Image<int,2> >': a member using-declaration can only be applied to a base class member

An attempt to use `FrequencyImageRegionConstIteratorWithIndex` triggered:

    error C2679: binary '=': no operator found which takes a right-hand operand of type 'const itk::Point<T,3>' (or there is no acceptable conversion)

This commit removes their header files. It also removes the suggestion to use `FrequencyImageRegionIteratorWithIndex` from the documentation of UnaryFrequencyDomainFilter.


Discussion / hints:
/azp run ITK.Linux.Python
@phcerdan Sorry Pablo 🤷 but if those iterators don't compile and don't have any test, I think it's better not to have them in the main branch!
@phcerdan  Thanks for your very quick response, Pablo!

> They are used in the IsotropicWavelets module. We should move the tests from there here.

Sorry, but how can they possibly be used when they cannot compile at all? Even the very first revision of those two iterators (six years ago, e16d0bc4eec7b3ee7ab63c3469077d54390df5c6) would have those compile errors, as far as I can see. 

The other six iterator types from Modules/Filtering/ImageFrequency compile fine, it's just these two. So I suspect that these two are not really necessary. 🤷 
Thanks @N-Dekker, I am out of office and away from keyboard to give a detailed answer about the history of the filters. But if you don't want to work on a fix, let me do it when I am back.

Thanks
> But if you don't want to work on a fix, let me do it when I am back.

OK, thanks Pablo. Rather than just a quick-fix of those compile errors, I hope you can add a test that will show the usefulness of those two iterators.

- By the way, I encountered those compile errors when I was busy writing a unit test for pull request #4827, testing that `Iterator(image, region)` yields an iterator at the begin of the region. This test passed well for the other six ImageFrequency iterator types. Please have a look, if you still have time!


Fix patch:
diff --git a/Modules/Filtering/ImageFrequency/include/itkFrequencyImageRegionConstIteratorWithIndex.h b/Modules/Filtering/ImageFrequency/include/itkFrequencyImageRegionConstIteratorWithIndex.h
index 24228150094..3ba2120eb4a 100644
--- a/Modules/Filtering/ImageFrequency/include/itkFrequencyImageRegionConstIteratorWithIndex.h
+++ b/Modules/Filtering/ImageFrequency/include/itkFrequencyImageRegionConstIteratorWithIndex.h
@@ -174,8 +174,11 @@ class ITK_TEMPLATE_EXPORT FrequencyImageRegionConstIteratorWithIndex : public Im
   void
   Init()
   {
-    this->m_FrequencyOrigin = this->m_Image->GetOrigin();
-    this->m_FrequencySpacing = this->m_Image->GetSpacing();
+    for (unsigned int dim = 0; dim < ImageType::ImageDimension; ++dim)
+    {
+      this->m_FrequencyOrigin[dim] = this->m_Image->GetOrigin()[dim];
+      this->m_FrequencySpacing[dim] = this->m_Image->GetSpacing()[dim];
+    }
   }
 
   FrequencyType m_FrequencyOrigin;
diff --git a/Modules/Filtering/ImageFrequency/include/itkFrequencyImageRegionIteratorWithIndex.h b/Modules/Filtering/ImageFrequency/include/itkFrequencyImageRegionIteratorWithIndex.h
index 3b3c6f01b4a..d4a0c72f67b 100644
--- a/Modules/Filtering/ImageFrequency/include/itkFrequencyImageRegionIteratorWithIndex.h
+++ b/Modules/Filtering/ImageFrequency/include/itkFrequencyImageRegionIteratorWithIndex.h
@@ -67,7 +67,7 @@ class ITK_TEMPLATE_EXPORT FrequencyImageRegionIteratorWithIndex
 public:
   /** Standard class type alias. */
   using Self = FrequencyImageRegionIteratorWithIndex;
-  using Superclass = ImageRegionIteratorWithIndex<TImage>;
+  using Superclass = FrequencyImageRegionConstIteratorWithIndex<TImage>;
 
   /** Types inherited from the Superclass */
   using typename Superclass::IndexType;


Test patch:
diff --git a/Modules/Filtering/ImageFrequency/test/itkFrequencyIteratorsGTest.cxx b/Modules/Filtering/ImageFrequency/test/itkFrequencyIteratorsGTest.cxx
index 58de2552b1e..533f0036926 100644
--- a/Modules/Filtering/ImageFrequency/test/itkFrequencyIteratorsGTest.cxx
+++ b/Modules/Filtering/ImageFrequency/test/itkFrequencyIteratorsGTest.cxx
@@ -26,6 +26,8 @@
 #include "itkHalfHermitianToRealInverseFFTImageFilter.h"
 #include "itkFFTShiftImageFilter.h"
 #include "itkFrequencyBandImageFilter.h" // Simplest of frequency filters for testing
+#include "itkFrequencyImageRegionConstIteratorWithIndex.h"
+#include "itkFrequencyImageRegionIteratorWithIndex.h"
 #include "itkFrequencyFFTLayoutImageRegionConstIteratorWithIndex.h"
 #include "itkFrequencyFFTLayoutImageRegionIteratorWithIndex.h"
 #include "itkFrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex.h"
@@ -264,7 +266,9 @@ compareAllTypesOfIterators(typename TImageType::Pointer image, double difference
 // Checks that an iterator that is just constructed by `IteratorType(image, region)` is at the begin.
 TEST_F(FrequencyIterators, AreConstructedAtBegin)
 {
-  CheckIteratorsConstructedAtBegin<itk::FrequencyFFTLayoutImageRegionConstIteratorWithIndex,
+  CheckIteratorsConstructedAtBegin<itk::FrequencyImageRegionConstIteratorWithIndex,
+                                   itk::FrequencyImageRegionIteratorWithIndex,
+                                   itk::FrequencyFFTLayoutImageRegionConstIteratorWithIndex,
                                    itk::FrequencyFFTLayoutImageRegionIteratorWithIndex,
                                    itk::FrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex,
                                    itk::FrequencyHalfHermitianFFTLayoutImageRegionIteratorWithIndex,