|
| 1 | +/*========================================================================= |
| 2 | + * |
| 3 | + * Copyright NumFOCUS |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * https://www.apache.org/licenses/LICENSE-2.0.txt |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + * |
| 17 | + *=========================================================================*/ |
| 18 | + |
| 19 | +#include "itkImageFileReader.h" |
| 20 | +#include "itkImageFileWriter.h" |
| 21 | +#include "itkTestingMacros.h" |
| 22 | + |
| 23 | + |
| 24 | +int |
| 25 | +itkNiftiLargeImageRegionReadTest(int argc, char * argv[]) |
| 26 | +{ |
| 27 | + |
| 28 | + if (argc != 2) |
| 29 | + { |
| 30 | + std::cerr << "Missing arguments" << std::endl; |
| 31 | + std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv) << " outputFileName" << std::endl; |
| 32 | + return EXIT_FAILURE; |
| 33 | + } |
| 34 | + |
| 35 | + |
| 36 | + constexpr int Dimension = 3; |
| 37 | + using PixelType = unsigned short; |
| 38 | + |
| 39 | + using ImageType = itk::Image<PixelType, Dimension>; |
| 40 | + |
| 41 | + // Create a large image |
| 42 | + ImageType::SizeType size = { { 1034, 1034, 1020 } }; |
| 43 | + ImageType::RegionType region; |
| 44 | + region.SetSize(size); |
| 45 | + |
| 46 | + auto image = ImageType::New(); |
| 47 | + image->SetRegions(region); |
| 48 | + image->Allocate(true); |
| 49 | + |
| 50 | + const std::string fname{ argv[1] }; |
| 51 | + itk::WriteImage(image, fname); |
| 52 | + |
| 53 | + |
| 54 | + using ReaderType = itk::ImageFileReader<ImageType>; |
| 55 | + auto reader = ReaderType::New(); |
| 56 | + |
| 57 | + reader->SetFileName(fname); |
| 58 | + |
| 59 | + // Ensure that a sufficiently large subregion, requiring allocating a pixel buffer larger than INT_MAX bytes, can be |
| 60 | + // read, as nifti_clib did not support reading such large subregions previously. |
| 61 | + region.SetSize({ { 1029, 1029, 1017 } }); |
| 62 | + reader->GetOutput()->SetRequestedRegion(region); |
| 63 | + |
| 64 | + ITK_TRY_EXPECT_NO_EXCEPTION(reader->Update()); |
| 65 | + |
| 66 | + const auto output = reader->GetOutput(); |
| 67 | + ITK_TEST_EXPECT_TRUE(output != nullptr); |
| 68 | + ITK_TEST_EXPECT_TRUE(output->GetBufferedRegion() == region); |
| 69 | + |
| 70 | + |
| 71 | + std::cout << "Test finished." << std::endl; |
| 72 | + return EXIT_SUCCESS; |
| 73 | +} |
0 commit comments