diff --git a/Modules/Core/Common/include/itkImageAlgorithm.hxx b/Modules/Core/Common/include/itkImageAlgorithm.hxx index 94fcb4925a9..9a44b4e9796 100644 --- a/Modules/Core/Common/include/itkImageAlgorithm.hxx +++ b/Modules/Core/Common/include/itkImageAlgorithm.hxx @@ -53,8 +53,8 @@ ImageAlgorithm::ReferenceCopy(const InputImageType * inIma return; } - ImageRegionConstIterator it(inImage, inRegion); - ImageRegionIterator ot(outImage, outRegion); + ImageRegionConstIterator it(inImage, inRegion); + ImageRegionIterator ot(outImage, outRegion); while (!it.IsAtEnd()) { diff --git a/Modules/Filtering/RLEImage/test/CMakeLists.txt b/Modules/Filtering/RLEImage/test/CMakeLists.txt index 4a142680227..d148853ba79 100644 --- a/Modules/Filtering/RLEImage/test/CMakeLists.txt +++ b/Modules/Filtering/RLEImage/test/CMakeLists.txt @@ -16,6 +16,10 @@ set( createtestdriver( RLEImage "${RLEImage-Test_LIBRARIES}" "${RLEImageTests}" ) +set(RLEImageGTests itkRLEImageAlgorithmCopyGTest.cxx) + +creategoogletestdriver(RLEImage "${RLEImage-Test_LIBRARIES}" "${RLEImageGTests}") + add_executable( runFromIDE manualTest.cxx diff --git a/Modules/Filtering/RLEImage/test/itkRLEImageAlgorithmCopyGTest.cxx b/Modules/Filtering/RLEImage/test/itkRLEImageAlgorithmCopyGTest.cxx new file mode 100644 index 00000000000..3b229fbb240 --- /dev/null +++ b/Modules/Filtering/RLEImage/test/itkRLEImageAlgorithmCopyGTest.cxx @@ -0,0 +1,84 @@ +/*========================================================================= + * + * Copyright NumFOCUS + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *=========================================================================*/ + +#include "itkImageAlgorithm.h" +#include "itkRLEImage.h" + +#include + +// Locks in correct iterator deduction in ImageAlgorithm::Copy when the +// source or destination is a partially-specialized Image-like template. +namespace +{ +constexpr unsigned int Dimension = 3; +using PixelType = short; +using RLEType = itk::RLEImage; +using ImageType = itk::Image; + +RLEType::RegionType +MakeRegion() +{ + RLEType::SizeType size = { { 4, 4, 4 } }; + RLEType::IndexType start = { { 0, 0, 0 } }; + return RLEType::RegionType{ start, size }; +} +} // namespace + +TEST(RLEImageAlgorithmCopy, FromRLEToImage) +{ + const auto region = MakeRegion(); + + auto rle = RLEType::New(); + rle->SetRegions(region); + rle->Allocate(); + rle->FillBuffer(7); + + auto dst = ImageType::New(); + dst->SetRegions(region); + dst->Allocate(); + dst->FillBuffer(0); + + itk::ImageAlgorithm::Copy(rle.GetPointer(), dst.GetPointer(), region, region); + + for (itk::ImageRegionConstIterator it(dst, region); !it.IsAtEnd(); ++it) + { + ASSERT_EQ(it.Get(), 7) << "Mismatch at " << it.GetIndex(); + } +} + +TEST(RLEImageAlgorithmCopy, FromImageToRLE) +{ + const auto region = MakeRegion(); + + auto src = ImageType::New(); + src->SetRegions(region); + src->Allocate(); + src->FillBuffer(11); + + auto rleDst = RLEType::New(); + rleDst->SetRegions(region); + rleDst->Allocate(); + rleDst->FillBuffer(0); + + itk::ImageAlgorithm::Copy(src.GetPointer(), rleDst.GetPointer(), region, region); + + for (itk::ImageRegionConstIterator it(rleDst, region); !it.IsAtEnd(); ++it) + { + ASSERT_EQ(it.Get(), 11) << "Mismatch at " << it.GetIndex(); + } +} diff --git a/Modules/IO/VTK/test/itkVTIImageIOReadWriteTest.cxx b/Modules/IO/VTK/test/itkVTIImageIOReadWriteTest.cxx index 7bb22e43d7e..dd9fb617c58 100644 --- a/Modules/IO/VTK/test/itkVTIImageIOReadWriteTest.cxx +++ b/Modules/IO/VTK/test/itkVTIImageIOReadWriteTest.cxx @@ -89,7 +89,7 @@ itkVTIImageIOReadWriteTest(int argc, char * argv[]) reader->SetFileName(inputImage); ITK_TRY_EXPECT_NO_EXCEPTION(reader->UpdateOutputInformation()); - auto imageIO = reader->GetImageIO(); + auto imageIO = reader->GetModifiableImageIO(); imageIO->SetFileName(inputImage); ITK_TRY_EXPECT_NO_EXCEPTION(imageIO->ReadImageInformation());