| 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 <string> |
| 19 |
#include "itkImage.h" |
| 20 |
#include "itkImageFileReader.h" |
| 21 |
#include "itkViewImage.h" |
| 22 |
|
| 23 |
/** |
| 24 |
* App to run ViewImage in an image file. |
| 25 |
* |
| 26 |
* This file is added to the TestDriver but it is not a regression test (no add_test). |
| 27 |
* It can be used for developers to fast visualize images with: |
| 28 |
* |
| 29 |
* ITK-build/bin/ITKVtkGlueTestDriver runViewImage /path/to/image.xxx \ |
| 30 |
* [title] [win_width] [win_height] |
| 31 |
* |
| 32 |
* \sa itk::ViewImage |
| 33 |
*/ |
| 34 |
int |
| 35 |
runViewImage(int argc, char * argv[]) |
| 36 |
{ |
| 37 |
if (argc < 2 || argc == 4 || argc > 5) |
| 38 |
{ |
| 39 |
std::cerr << "Usage: " << argv[0] << " inputImage [title] [win_size_x win_size_y] " << std::endl; |
| 40 |
return EXIT_FAILURE; |
| 41 |
} |
| 42 |
// Defaults |
| 43 |
std::string winTitle = "itkViewImage"; |
| 44 |
size_t winWidth = 600; |
| 45 |
size_t winHeight = 600; |
| 46 |
if (argc >= 3) |
| 47 |
{ |
| 48 |
winTitle = argv[2]; |
| 49 |
} |
| 50 |
if (argc == 5) |
| 51 |
{ |
| 52 |
winWidth = std::stoi(argv[3]); |
| 53 |
winHeight = std::stoi(argv[4]); |
| 54 |
} |
| 55 |
const std::string inputImage = argv[1]; |
| 56 |
|
| 57 |
constexpr unsigned int dimension = 3; |
| 58 |
using PixelType = float; |
| 59 |
using ImageType = itk::Image<PixelType, dimension>; |
| 60 |
using ReaderType = itk::ImageFileReader<ImageType>; |
| 61 |
auto reader = ReaderType::New(); |
| 62 |
reader->SetFileName(inputImage); |
| 63 |
reader->Update(); |
| 64 |
|
| 65 |
itk::ViewImage<ImageType>::View(reader->GetOutput(), winTitle, winWidth, winHeight); |
| 66 |
|
| 67 |
return EXIT_SUCCESS; |
| 68 |
} |