int itkOrthogonalSwath2DPathFilterTest(int, char*[])
{
typedef InPathType::VertexType VertexType;
typedef InPathType::OffsetType OffsetType;
typedef InPathType::InputType InPathInputType;
typedef ImageType::IndexType IndexType;
typedef ImageType::SizeType SizeType;
std::cout << "Making a square Path with v0 at (24,24) -> (24,104) -> (104,104) -> (104,24)" << std::endl;
InPathType::Pointer inPath;
VertexType v;
inPath = InPathType::New();
v.Fill(24);
inPath->AddVertex(v);
v[0]=24;
v[1]=104;
inPath->AddVertex(v);
v.Fill(104);
inPath->AddVertex(v);
v[0]=104;
v[1]=24;
inPath->AddVertex(v);
v.Fill(24);
inPath->AddVertex(v);
PathFilter1Type::Pointer pathFilter1 = PathFilter1Type::New();
pathFilter1->SetInput(inPath);
PathFilter2Type::Pointer pathFilter2 = PathFilter2Type::New();
pathFilter2->SetInput(pathFilter1->GetOutput());
pathFilter2->SetNumberOfHarmonics(7);
std::cout << "Making a 64x64 black square centered in a 128x128 white image"<<std::endl;
ImageType::Pointer inImage = ImageType::New();
IndexType start;
start[0]=0;
start[1]=0;
ImageType::SizeType size;
size[0]=128;
size[1]=128;
ImageType::RegionType region;
region.SetSize(size);
region.SetIndex(start);
inImage->SetRegions(region);
double spacing[ ImageType::ImageDimension ];
spacing[0]=1.0;
spacing[1]=1.0;
inImage->SetSpacing(spacing);
inImage->Allocate();
ImageItType it( inImage, inImage->GetRequestedRegion() );
IndexType pixelIndex;
while( !it.IsAtEnd() )
{
pixelIndex = it.GetIndex();
if( pixelIndex[0] >= int(size[0]/4) && pixelIndex[0] < int(size[0]*3/4) &&
pixelIndex[1] >= int(size[1]/4) && pixelIndex[1] < int(size[1]*3/4) )
it.Set(0);
else
it.Set(255);
++it;
}
CastFilterType::Pointer castFilter = CastFilterType::New();
castFilter->SetInput( inImage );
castFilter->SetOutputMinimum(0);
castFilter->SetOutputMaximum(1.0);
SmoothFilterType::Pointer smoothFilter = SmoothFilterType::New();
smoothFilter->SetInput( castFilter->GetOutput() );
double gaussianVariance = 1.0;
double maxError = 0.9;
smoothFilter->SetUseImageSpacingOff();
smoothFilter->SetVariance( gaussianVariance );
smoothFilter->SetMaximumError( maxError );
SwathFilterType::Pointer swathFilter = SwathFilterType::New();
swathFilter->SetImageInput( smoothFilter->GetOutput() );
swathFilter->SetPathInput( pathFilter2->GetOutput() );
size[0]=512;
size[1]=16*2+1;
swathFilter->SetSize(size);
MeritFilterType::Pointer meritFilter = MeritFilterType::New();
meritFilter->SetInput( swathFilter->GetOutput() );
meritFilter->SetOrder( 1 );
meritFilter->SetDirection( 1 );
std::cerr << "Creating the test filter" << std::endl;
TestFilterType::Pointer testFilter = TestFilterType::New();
std::cerr << "Setting up the test filter" << std::endl;
testFilter->SetPathInput(pathFilter2->GetOutput());
testFilter->SetImageInput(meritFilter->GetOutput());
OutputPathType::Pointer outPath = testFilter->GetOutput();
std::cerr << "Setting up the output path image" << std::endl;
Output1FilterType::Pointer output1Filter = Output1FilterType::New();
Output2FilterType::Pointer output2Filter = Output2FilterType::New();
size[0]=128;
size[1]=128;
output1Filter->SetSize(size);
output2Filter->SetSize(size);
output1Filter->SetPathValue(255);
output2Filter->SetPathValue(255);
output1Filter->SetInput( testFilter->GetPathInput() );
output2Filter->SetInput( testFilter->GetOutput() );
ImageType::Pointer inPathImage = output1Filter->GetOutput();
ImageType::Pointer outImage = output2Filter->GetOutput();
Output3FilterType::Pointer output3Filter = Output3FilterType::New();
output3Filter->SetInput( meritFilter->GetOutput() );
output3Filter->SetOutputMinimum(0);
output3Filter->SetOutputMaximum(255);
ImageType::Pointer swathMeritImage = output3Filter->GetOutput();
std::cerr << testFilter << std::endl;
std::cerr << "Running the Pipeline: ";
outImage->Update();
std::cerr << "[DONE]" << std::endl;
return EXIT_SUCCESS;
}