#include "vtkRenderWindowInteractor.h"
int main( int argc, char* argv[] )
{
if( argc != 3 )
{
std::cerr << "Missing Arguments" << std::endl;
std::cerr << argv[0] << std::endl;
std::cerr << "<Input Image> <Interactive (0 or 1)>" << std::endl;
return EXIT_FAILURE;
}
const unsigned int Dimension = 2;
typedef unsigned char InputPixelType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( argv[1] );
InputImageType::Pointer input = reader->GetOutput();
typedef float LevelSetPixelType;
typedef LevelSetType::OutputType LevelSetOutputType;
typedef LevelSetType::OutputRealType LevelSetRealType;
OtsuFilterType::Pointer otsu = OtsuFilterType::New();
otsu->SetInput( input );
otsu->SetNumberOfHistogramBins( 256 );
otsu->SetNumberOfThresholds( 1 );
RescaleType::Pointer rescaler = RescaleType::New();
rescaler->SetInput( otsu->GetOutput() );
rescaler->SetOutputMinimum( 0 );
rescaler->SetOutputMaximum( 1 );
LevelSetType > BinaryImageToLevelSetType;
BinaryImageToLevelSetType::Pointer adaptor = BinaryImageToLevelSetType::New();
adaptor->SetInputImage( rescaler->GetOutput() );
adaptor->Initialize();
LevelSetType::Pointer levelSet = adaptor->GetLevelSet();
VisualizationType::Pointer visualizer = VisualizationType::New();
visualizer->SetInputImage( input );
visualizer->SetLevelSet( levelSet );
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow( visualizer->GetRenderWindow() );
try
{
visualizer->Update();
}
{
std::cerr << "Error: " << error << std::endl;
return EXIT_FAILURE;
}
bool interactive = ( atoi( argv[2] ) != 0 );
if( interactive )
{
renderWindowInteractor->Start();
}
return EXIT_SUCCESS;
}