Skip to content

Commit

Permalink
ENH: Fix hardening of warping transforms on labelmap volumes
Browse files Browse the repository at this point in the history
Labelmap volumes must be resampled using nearest neighbor interpolation.
  • Loading branch information
fbordignon authored and lassoan committed May 5, 2022
1 parent 5b87a6a commit 704c46f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
8 changes: 8 additions & 0 deletions Libs/MRML/Core/vtkMRMLLabelMapVolumeNode.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,11 @@ void vtkMRMLLabelMapVolumeNode::CreateDefaultDisplayNodes()
dispNode->SetDefaultColorMap();
this->SetAndObserveDisplayNodeID(dispNode->GetID());
}

//----------------------------------------------------------------------------
int vtkMRMLLabelMapVolumeNode::GetResamplingInterpolationMode()
{
// Labelmap volumes must be resampled using nearest neighbor method to avoid
// introducing new label values at boundaries.
return VTK_NEAREST_INTERPOLATION;
}
2 changes: 2 additions & 0 deletions Libs/MRML/Core/vtkMRMLLabelMapVolumeNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class VTK_MRML_EXPORT vtkMRMLLabelMapVolumeNode : public vtkMRMLScalarVolumeNode
~vtkMRMLLabelMapVolumeNode() override;
vtkMRMLLabelMapVolumeNode(const vtkMRMLLabelMapVolumeNode&);
void operator=(const vtkMRMLLabelMapVolumeNode&);

int GetResamplingInterpolationMode() override;
};

#endif
21 changes: 20 additions & 1 deletion Libs/MRML/Core/vtkMRMLVolumeNode.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,19 @@ void vtkMRMLVolumeNode::ApplyNonLinearTransform(vtkAbstractTransform* transform)
}

reslice->SetInputConnection(this->ImageDataConnection);
reslice->SetInterpolationModeToLinear();

// GetResamplingInterpolationMode does not use VTK_RESLICE... constants because it is an implementation
// detail that currently vtkImageReslice is used for resampling.
int resamplingMode = this->GetResamplingInterpolationMode();
switch (resamplingMode)
{
case VTK_NEAREST_INTERPOLATION: reslice->SetInterpolationModeToNearestNeighbor(); break;
case VTK_LINEAR_INTERPOLATION: reslice->SetInterpolationModeToLinear(); break;
case VTK_CUBIC_INTERPOLATION: reslice->SetInterpolationModeToCubic(); break;
default:
vtkErrorMacro("ApplyNonLinearTransform: invalid interpolation mode: " << this->GetResamplingInterpolationMode());
}

double backgroundColor[4] = { 0, 0, 0, 0 };
for (int i = 0; i < 4; i++)
{
Expand Down Expand Up @@ -1106,6 +1118,13 @@ void vtkMRMLVolumeNode::ApplyNonLinearTransform(vtkAbstractTransform* transform)
this->EndModify(wasModified);
}

//---------------------------------------------------------------------------
int vtkMRMLVolumeNode::GetResamplingInterpolationMode()
{
// By default linear interpolation is used for all volumes.
return VTK_LINEAR_INTERPOLATION;
}

//---------------------------------------------------------------------------
void vtkMRMLVolumeNode::ShiftImageDataExtentToZeroStart()
{
Expand Down
4 changes: 4 additions & 0 deletions Libs/MRML/Core/vtkMRMLVolumeNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ class VTK_MRML_EXPORT vtkMRMLVolumeNode : public vtkMRMLDisplayableNode
/// If useParentTransform is false then parent transform is ignored.
void GetCenterPositionRAS(double* centerPositionRAS, bool useParentTransform=true);

/// Returns the interpolation algorithm that should be used for resampling the volume.
/// The value is one of VTK_NEAREST_INTERPOLATION, VTK_LINEAR_INTERPOLATION, or VTK_CUBIC_INTERPOLATION.
virtual int GetResamplingInterpolationMode();

/// these are unit length direction cosines
double IJKToRASDirections[3][3];

Expand Down

0 comments on commit 704c46f

Please sign in to comment.