int main(
int argc,
char* argv[])
{
if (argc < 4)
{
std::cout << argv[0] << " <input vector filename> <input image name> <output vector filename> " << std::endl;
return EXIT_FAILURE;
}
const char* inVectorName = argv[1];
const char* inImageName = argv[2];
const char* outVectorName = argv[3];
using Type = double;
ImageReaderType::Pointer imageReader = ImageReaderType::New();
imageReader->SetFileName(inImageName);
imageReader->UpdateOutputInformation();
FilterType::Pointer filter = FilterType::New();
TypedRegion region;
TypedRegion::SizeType size;
TypedRegion::IndexType index;
size[0] = imageReader->GetOutput()->GetLargestPossibleRegion().GetSize()[0] * imageReader->GetOutput()->GetSignedSpacing()[0];
size[1] = imageReader->GetOutput()->GetLargestPossibleRegion().GetSize()[1] * imageReader->GetOutput()->GetSignedSpacing()[1];
index[0] = imageReader->GetOutput()->GetOrigin()[0] - 0.5 * imageReader->GetOutput()->GetSignedSpacing()[0];
index[1] = imageReader->GetOutput()->GetOrigin()[1] - 0.5 * imageReader->GetOutput()->GetSignedSpacing()[1];
region.SetSize(size);
region.SetOrigin(index);
region.SetRegionProjection(imageReader->GetOutput()->GetProjectionRef());
region.SetImageMetadata(imageReader->GetOutput()->GetImageMetadata());
filter->SetRegion(region);
VectorDataFileReaderType::Pointer reader = VectorDataFileReaderType::New();
VectorDataWriterType::Pointer writer = VectorDataWriterType::New();
reader->SetFileName(inVectorName);
writer->SetFileName(outVectorName);
filter->SetInput(reader->GetOutput());
writer->SetInput(filter->GetOutput());
writer->Update();
return EXIT_SUCCESS;
}