- //compute the distance
- typename ImageType::Pointer distanceMap = ImageType::New();
- distanceMap->SetRegions(smallRegion);
- distanceMap->SetOrigin(input1->GetOrigin());
- distanceMap->SetSpacing(input1->GetSpacing());
- distanceMap->Allocate();
- distanceMap->FillBuffer(0.0);
- //distanceMap->SetPixel(it.GetIndex(),1.0);
-
- typedef itk::ApproximateSignedDistanceMapImageFilter< ImageType, ImageType > ApproximateSignedDistanceMapImageFilterType;
- typename ApproximateSignedDistanceMapImageFilterType::Pointer approximateSignedDistanceMapImageFilter = ApproximateSignedDistanceMapImageFilterType::New();
- approximateSignedDistanceMapImageFilter->SetInput(distanceMap);
- approximateSignedDistanceMapImageFilter->SetInsideValue(1.0);
- approximateSignedDistanceMapImageFilter->SetOutsideValue(0.0);
- approximateSignedDistanceMapImageFilter->GetOutput()->SetRequestedRegion(smallRegion);
- approximateSignedDistanceMapImageFilter->Update();
+ //compute the distance, ie. translate and crop the global one
+ typedef itk::TranslationTransform<double, 3> TranslationTransformType;
+ typename TranslationTransformType::Pointer transform = TranslationTransformType::New();
+ typename TranslationTransformType::OutputVectorType translation;
+ translation[0] = -startRegion[0]*input1->GetSpacing()[0];
+ translation[1] = -startRegion[1]*input1->GetSpacing()[1];
+ translation[2] = -startRegion[2]*input1->GetSpacing()[2];
+ transform->Translate(translation);
+ typedef itk::ResampleImageFilter<ImageType, ImageType> ResampleImageFilterType;
+ typename ResampleImageFilterType::Pointer resampleFilter = ResampleImageFilterType::New();
+ resampleFilter->SetTransform(transform.GetPointer());
+ resampleFilter->SetInput(distanceMapImageFilter->GetOutput());
+ resampleFilter->SetOutputOrigin(distanceMapImageFilter->GetOutput()->GetOrigin());
+ resampleFilter->SetOutputSpacing(distanceMapImageFilter->GetOutput()->GetSpacing());
+ resampleFilter->SetSize(input2->GetLargestPossibleRegion().GetSize());
+ resampleFilter->GetOutput()->SetRequestedRegion(smallRegion);
+ resampleFilter->Update();