diff --git a/Modules/Core/SpatialObjects/include/itkSpatialObjectToImageFilter.h b/Modules/Core/SpatialObjects/include/itkSpatialObjectToImageFilter.h index 71a97d8d657..7ff7889d449 100644 --- a/Modules/Core/SpatialObjects/include/itkSpatialObjectToImageFilter.h +++ b/Modules/Core/SpatialObjects/include/itkSpatialObjectToImageFilter.h @@ -50,6 +50,7 @@ class ITK_TEMPLATE_EXPORT SpatialObjectToImageFilter : public ImageSource; using OutputImageType = TOutputImage; + using IndexType = typename OutputImageType::IndexType; using SizeType = typename OutputImageType::SizeType; using PointType = typename OutputImageType::PointType; using OutputImagePointer = typename OutputImageType::Pointer; @@ -100,6 +101,7 @@ class ITK_TEMPLATE_EXPORT SpatialObjectToImageFilter : public ImageSourceSetOrigin(refImage->GetOrigin()); this->SetSpacing(refImage->GetSpacing()); this->SetDirection(refImage->GetDirection()); + this->SetIndex(refImage->GetLargestPossibleRegion().GetIndex()); this->SetSize(refImage->GetLargestPossibleRegion().GetSize()); } @@ -161,6 +163,12 @@ class ITK_TEMPLATE_EXPORT SpatialObjectToImageFilter : public ImageSource::SpatialObjectToIm this->SetNumberOfRequiredInputs(1); m_ChildrenDepth = TInputSpatialObject::MaximumDepth; m_Size.Fill(0); + m_Index.Fill(0); m_Direction.SetIdentity(); for (unsigned int i = 0; i < OutputImageDimension; ++i) @@ -285,8 +286,6 @@ SpatialObjectToImageFilter::GenerateData() InputObject->GetFamilyBoundingBoxInWorldSpace()->GetMinimum()[i]); } - typename OutputImageType::IndexType index; - index.Fill(0); typename OutputImageType::RegionType region; // If the size of the output has been explicitly specified, the filter @@ -312,7 +311,27 @@ SpatialObjectToImageFilter::GenerateData() { region.SetSize(size); } - region.SetIndex(index); + + IndexType index; + index.Fill(0); + specified = false; + for (i = 0; i < OutputImageDimension; ++i) + { + if (m_Index[i] != 0) + { + specified = true; + break; + } + } + + if (specified) + { + region.SetIndex(m_Index); + } + else + { + region.SetIndex(index); + } OutputImage->SetLargestPossibleRegion(region); // OutputImage->SetBufferedRegion(region); // set the region @@ -379,6 +398,7 @@ SpatialObjectToImageFilter::PrintSelf(std::os { Superclass::PrintSelf(os, indent); os << indent << "Size : " << m_Size << std::endl; + os << indent << "Index : " << m_Index << std::endl; os << indent << "Children depth : " << m_ChildrenDepth << std::endl; os << indent << "Inside Value : " << m_InsideValue << std::endl; os << indent << "Outside Value : " << m_OutsideValue << std::endl;