/*========================================================================= Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: main.cxx,v $ Language: C++ Date: $Date: 2006/01/15 04:28:36 $ Version: $Revision: 1.12 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "itkImage.h" #include "itkImageFileReader.h" #include "itkImageFileWriter.h" #include "itkImageSliceIteratorWithIndex.h" #include "itkOrthogonalBisectImageFilter.h" #include "itkSphereSpatialFunction.h" #include "itkFloodFilledSpatialFunctionConditionalIterator.h" #include "itkImageRegionIterator.h" int main(int ac, char *av[]) { // This program will bisect an input image with parameters specified by the user. if(ac < 7) { std::cerr << "Missing Parameters!!!" << std::endl; std::cerr << "Usage: " << av[0]; std::cerr << " InputImage OutputImage1 OutputImage2 Output1FillIntensity" << " Output2FillIntensity OrthogonalDirection [BisectSlice]" << std::endl; return EXIT_FAILURE; } // The image dimension. Eventhough imageDimension is set to 3, a 2D image can still be used. const unsigned int imageDimension = 3; // Image typedefs. typedef unsigned char PixelType; typedef itk::Image ImageType; // Initialize the image reader. typedef itk::ImageFileReader ImageReaderType; ImageReaderType::Pointer imageReader = ImageReaderType::New(); // Initialize the image writer. typedef itk::ImageFileWriter FileWriterType; FileWriterType::Pointer fileWriter = FileWriterType::New(); // Initialize the OrthogonalBisectImageFilter. typedef itk::OrthogonalBisectImageFilter FilterType; FilterType::Pointer filter = FilterType::New(); imageReader->SetFileName(av[1]); imageReader->Update(); // Instantiate input image and set to output of image reader. ImageType::Pointer inputImage = ImageType::New(); inputImage = imageReader->GetOutput(); /*******************************************************/ // Begin set parameters of OrthogonalBisectImageFilter /*******************************************************/ std::string orthogonalDirection = std::string(av[6]); // x, y, or z filter->SetInput(inputImage); // Set the input image filter->SetOrthogonalDirection(orthogonalDirection); // Set the bisect index. If an argument was not given, set it to the middle along the OrthogonalDirection. if(ac > 7) filter->SetBisectIndex(std::atoi(av[7])); else { // If a bisect index was not specified, set to the middle. if(orthogonalDirection == std::string("x")) filter->SetBisectIndex((int)(0.5 * inputImage->GetLargestPossibleRegion().GetSize()[0] - 1)); else if(orthogonalDirection == std::string("y")) filter->SetBisectIndex((int)(0.5 * inputImage->GetLargestPossibleRegion().GetSize()[1] - 1)); else if(orthogonalDirection == std::string("z")) filter->SetBisectIndex((int)(0.5 * inputImage->GetLargestPossibleRegion().GetSize()[2] - 1)); } // Set the output image fill intensities. filter->SetOutput1FillIntensity(std::atoi(av[4])); filter->SetOutput2FillIntensity(std::atoi(av[5])); /*******************************************************/ // End set parameters of OrthogonalBisectImageFilter /*******************************************************/ // Try and update the filter. If that fails, throw an exception. try { filter->Update(); } catch(itk::ExceptionObject & e) { std::cerr << "Exception detected: " << e.GetDescription(); return EXIT_FAILURE; } // Print the member variables of the filter. std::cerr << filter << std::endl; // Save the output images to disk. fileWriter->SetInput(filter->GetOutput(0)); fileWriter->SetFileName(av[2]); fileWriter->Update(); fileWriter->SetInput(filter->GetOutput(1)); fileWriter->SetFileName(av[3]); fileWriter->Update(); return EXIT_SUCCESS; }