forked from InsightSoftwareConsortium/ITK
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: add test to reproduce SimpleITK issue InsightSoftwareConsortium#…
- Loading branch information
Showing
2 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
Modules/Filtering/ImageGrid/test/itkComposeImageFilterGTest.cxx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/*========================================================================= | ||
* | ||
* 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. | ||
* | ||
*=========================================================================*/ | ||
|
||
// The header file to be tested: | ||
#include "itkComposeImageFilter.h" | ||
#include "itkVectorIndexSelectionCastImageFilter.h" | ||
#include "itkMinimumMaximumImageCalculator.h" | ||
#include "itkExtractImageFilter.h" | ||
#include "itkPasteImageFilter.h" | ||
|
||
|
||
#include "itkImage.h" | ||
|
||
// Google Test header file: | ||
#include <gtest/gtest.h> | ||
|
||
// Standard C++ header files: | ||
#include <limits> | ||
#include <random> | ||
|
||
|
||
TEST(ComposeImageFilter, simpleitk_2220) | ||
{ | ||
// Test case for SimpleITK issue #2220 | ||
// Reported data corruption with 4G compose on Windows system | ||
|
||
|
||
const unsigned int size = 400; | ||
const unsigned int nchannels = 100; | ||
using ImageType = itk::Image<unsigned char, 3>; | ||
using VectorImageType = itk::VectorImage<unsigned char, 3>; | ||
std::vector<ImageType::Pointer> images; | ||
|
||
for (unsigned int i = 0; i < nchannels; ++i) | ||
{ | ||
auto image = ImageType::New(); | ||
ImageType::RegionType region; | ||
ImageType::SizeType imageSize = { { size, size, size } }; | ||
region.SetSize(imageSize); | ||
image->SetRegions(region); | ||
image->Allocate(); | ||
image->FillBuffer(0); | ||
|
||
using PasteFilterType = itk::PasteImageFilter<ImageType>; | ||
PasteFilterType::Pointer paster = PasteFilterType::New(); | ||
ImageType::IndexType destinationIndex = { { 0, 0, static_cast<int>(i) } }; | ||
ImageType::SizeType sourceSize = { { size, size, 1 } }; | ||
paster->SetConstant(1); | ||
paster->SetSourceRegion(sourceSize); | ||
paster->SetDestinationImage(image); | ||
paster->SetDestinationIndex(destinationIndex); | ||
paster->Update(); | ||
image = paster->GetOutput(); | ||
images.push_back(image); | ||
} | ||
|
||
using ComposeFilterType = itk::ComposeImageFilter<ImageType>; | ||
ComposeFilterType::Pointer composeFilter = ComposeFilterType::New(); | ||
for (auto &image : images) | ||
{ | ||
composeFilter->SetInput(image); | ||
} | ||
composeFilter->Update(); | ||
VectorImageType::Pointer img = composeFilter->GetOutput(); | ||
std::cout << "Compose filter executed." << std::endl; | ||
|
||
for (unsigned int i = 0; i < nchannels; ++i) | ||
{ | ||
itk::IndexValueType z = i; | ||
for (itk::IndexValueType y = 0; y < size; ++y) | ||
{ | ||
for (itk::IndexValueType x = 0; x < size; ++x) | ||
{ | ||
itk::Index<3> idx = { { x, y, z } }; | ||
|
||
auto pixel = img->GetPixel(idx); | ||
EXPECT_EQ(pixel[i], 1) << "compose filter: problem with component " << i << " at index " << idx; | ||
} | ||
} | ||
} | ||
|
||
} |