int main( int argc, char ** argv )
{
if ( argc < 4 )
{
std::cerr << "Missing parameters. " << std::endl;
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0]
<< " outputImageFile startX startY"
<< std::endl;
return -1;
}
typedef float PixelType;
FastMarchingFilterType::Pointer fastMarching = FastMarchingFilterType::New();
typedef FastMarchingFilterType::NodeContainer NodeContainer;
typedef FastMarchingFilterType::NodeType NodeType;
NodeContainer::Pointer seeds = NodeContainer::New();
ImageType::IndexType seedPosition;
seedPosition[0] = 128;
seedPosition[1] = 128;
const double initialDistance = 1.0;
NodeType node;
const double seedValue = - initialDistance;
ImageType::SizeType size = {{256, 256}};
node.SetValue( seedValue );
node.SetIndex( seedPosition );
seeds->Initialize();
seeds->InsertElement( 0, node );
fastMarching->SetTrialPoints( seeds );
fastMarching->SetSpeedConstant( 1.0 );
noise->SetSize(size.m_Size);
noise->SetMin(-.7);
noise->SetMax(.8);
adder->SetInput1(noise->GetOutput());
adder->SetInput2(fastMarching->GetOutput());
try
{
fastMarching->SetOutputSize( size );
fastMarching->Update();
adder->Update();
}
{
std::cerr << "Exception caught !" << std::endl;
std::cerr << excep << std::endl;
}
ImageType::Pointer input = adder->GetOutput();
ImageType::IndexType index;
index[0] = ::atoi(argv[2]);
index[1] = ::atoi(argv[3]);
NeighborhoodIteratorType::RadiusType radius;
radius.Fill(1);
NeighborhoodIteratorType it(radius, input, input->GetRequestedRegion());
it.SetLocation(index);
bool flag = true;
while ( flag == true )
{
NeighborhoodIteratorType::OffsetType nextMove;
nextMove.Fill(0);
flag = false;
PixelType min = it.GetCenterPixel();
for (unsigned i = 0; i < it.Size(); i++)
{
if ( it.GetPixel(i) < min )
{
min = it.GetPixel(i);
nextMove = it.GetOffset(i);
flag = true;
}
}
it.SetCenterPixel( 255.0 );
it += nextMove;
}
typedef unsigned char WritePixelType;
WriteImageType > RescaleFilterType;
RescaleFilterType::Pointer rescaler = RescaleFilterType::New();
rescaler->SetOutputMinimum( 0 );
rescaler->SetOutputMaximum( 255 );
rescaler->SetInput( input );
WriterType::Pointer writer = WriterType::New();
writer->SetFileName( argv[1] );
writer->SetInput( rescaler->GetOutput() );
try
{
writer->Update();
}
{
std::cout << "ExceptionObject caught !" << std::endl;
std::cout << err << std::endl;
return -1;
}
return 0;
}