Skip to content

Commit bac09b0

Browse files
committed
ENH: FlatStructuringElement and ShapedNeighborhoodIterator Interop
Allow interoperability of FlatStructuringElement and ShapedNeighborhoodIterator to allow compilation of the following code: using SE2Type = itk::FlatStructuringElement<2>; SE2Type::RadiusType r2 = SE2Type::RadiusType::Filled(5); SE2Type k2 = SE2Type::Ball(r2); itk::ShapedNeighborhoodIterator<TImage> iterator(r2, image, image->GetBufferedRegion()); iterator.CreateActiveListFromNeighborhood(k2); // this now compiles
1 parent 26c95ba commit bac09b0

4 files changed

+26
-4
lines changed

Modules/Core/Common/include/itkConstShapedNeighborhoodIterator.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,15 @@ class ITK_TEMPLATE_EXPORT ConstShapedNeighborhoodIterator : private Neighborhood
374374
/** Add non-zero neighborhood offsets to the active list. The
375375
* radius of the neighborhood must match the radius of the shaped
376376
* iterator */
377+
template <typename TNeighborPixel>
377378
void
378-
CreateActiveListFromNeighborhood(const NeighborhoodType &);
379+
CreateActiveListFromNeighborhood(const Neighborhood<TNeighborPixel, Self::Dimension> &);
380+
void
381+
CreateActiveListFromNeighborhood(const NeighborhoodType & neighborhood)
382+
{
383+
// just delegate to the templated version
384+
this->CreateActiveListFromNeighborhood<PixelType>(neighborhood);
385+
}
379386

380387
/** Reimplements the operator++ method so that only active pixel locations
381388
* are updated. */

Modules/Core/Common/include/itkConstShapedNeighborhoodIterator.hxx

+4-3
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,19 @@ ConstShapedNeighborhoodIterator<TImage, TBoundaryCondition>::DeactivateIndex(Nei
113113
}
114114

115115
template <typename TImage, typename TBoundaryCondition>
116+
template <typename TNeighborPixel>
116117
void
117118
ConstShapedNeighborhoodIterator<TImage, TBoundaryCondition>::CreateActiveListFromNeighborhood(
118-
const NeighborhoodType & neighborhood)
119+
const Neighborhood<TNeighborPixel, Self::Dimension> & neighborhood)
119120
{
120121
if (this->GetRadius() != neighborhood.GetRadius())
121122
{
122123
itkGenericExceptionMacro("Radius of shaped iterator(" << this->GetRadius()
123124
<< ") does not equal radius of neighborhood("
124125
<< neighborhood.GetRadius() << ')');
125126
}
126-
typename NeighborhoodType::ConstIterator nit;
127-
NeighborIndexType idx = 0;
127+
typename Neighborhood<TNeighborPixel, Self::Dimension>::ConstIterator nit;
128+
NeighborIndexType idx = 0;
128129
for (nit = neighborhood.Begin(); nit != neighborhood.End(); ++nit, ++idx)
129130
{
130131
if (*nit)

Modules/Core/Common/itk-module.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ itk_module(
2727
ITKTestKernel
2828
ITKMesh
2929
ITKImageIntensity
30+
ITKMathematicalMorphology
3031
ITKIOImageBase
3132
DESCRIPTION
3233
"${DOCUMENTATION}")

Modules/Core/Common/test/itkShapedNeighborhoodIteratorTest.cxx

+13
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "itkNeighborhoodIteratorTestCommon.hxx"
2020
#include "itkShapedNeighborhoodIterator.h"
21+
#include "itkFlatStructuringElement.h"
2122

2223
int
2324
itkShapedNeighborhoodIteratorTest(int, char *[])
@@ -191,6 +192,18 @@ itkShapedNeighborhoodIteratorTest(int, char *[])
191192
}
192193
std::cout << it.GetPixel(off) << std::endl;
193194

195+
println("Testing interoperability with FlatStructuringElement");
196+
using StructuringElementType = itk::FlatStructuringElement<4>;
197+
const StructuringElementType::RadiusType radius2 = StructuringElementType::RadiusType::Filled(2);
198+
const StructuringElementType kernel = StructuringElementType::Cross(radius2);
199+
itk::ShapedNeighborhoodIterator<TestImageType> iterator(radius2, img, img->GetBufferedRegion());
200+
iterator.CreateActiveListFromNeighborhood(kernel);
201+
iterator.SetLocation(loc);
202+
for (ci = iterator.Begin(); ci != iterator.End(); ++ci)
203+
{
204+
std::cout << ci.GetNeighborhoodIndex() << " -> " << ci.GetNeighborhoodOffset() << " = " << ci.Get() << std::endl;
205+
}
206+
194207
println("testing operator=");
195208
itk::ShapedNeighborhoodIterator<TestImageType> oeIt;
196209
oeIt = it;

0 commit comments

Comments
 (0)