|
| 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 | +#include "itkGridImageSource.h" |
| 19 | +#include "itkImageFileReader.h" |
| 20 | +#include "itkImageFileWriter.h" |
| 21 | +#include "itkSimpleFilterWatcher.h" |
| 22 | +#include "itkTestingMacros.h" |
| 23 | + |
| 24 | + |
| 25 | +int |
| 26 | +itkGridImageSourceTest2(int argc, char * argv[]) |
| 27 | +{ |
| 28 | + if (argc != 3) |
| 29 | + { |
| 30 | + std::cout << "Usage: " << itkNameOfTestExecutableMacro(argv) |
| 31 | + << " inputImage" |
| 32 | + << " outputImage" << std::endl; |
| 33 | + return EXIT_FAILURE; |
| 34 | + } |
| 35 | + const char * inputImageFile = argv[1]; |
| 36 | + const char * outputImageFile = argv[2]; |
| 37 | + |
| 38 | + |
| 39 | + constexpr unsigned int ImageDimension = 3; |
| 40 | + using PixelType = uint8_t; |
| 41 | + |
| 42 | + using ImageType = itk::Image<PixelType, ImageDimension>; |
| 43 | + |
| 44 | + // Instantiate the filter |
| 45 | + using GridSourceType = itk::GridImageSource<ImageType>; |
| 46 | + auto gridImage = GridSourceType::New(); |
| 47 | + |
| 48 | + ITK_EXERCISE_BASIC_OBJECT_METHODS(gridImage, GridImageSource, GenerateImageSource); |
| 49 | + |
| 50 | + ImageType::Pointer inputImage = itk::ReadImage<ImageType>(inputImageFile); |
| 51 | + |
| 52 | + gridImage->SetReferenceImage(inputImage); |
| 53 | + gridImage->UseReferenceImageOn(); |
| 54 | + |
| 55 | + itk::SimpleFilterWatcher watcher(gridImage, "GridImageSource"); |
| 56 | + |
| 57 | + ITK_TRY_EXPECT_NO_EXCEPTION(gridImage->Update()); |
| 58 | + |
| 59 | + using WriterType = itk::ImageFileWriter<ImageType>; |
| 60 | + auto writer = WriterType::New(); |
| 61 | + writer->SetFileName(outputImageFile); |
| 62 | + writer->SetInput(gridImage->GetOutput()); |
| 63 | + |
| 64 | + ITK_TRY_EXPECT_NO_EXCEPTION(writer->Update()); |
| 65 | + |
| 66 | + std::cout << "Test finished" << std::endl; |
| 67 | + return EXIT_SUCCESS; |
| 68 | +} |
0 commit comments