Receive image spacing from image messages#87
Conversation
|
@lassoan is this somehow related to Slicer storing spacing info in MRML (or something like that? I remember it wasn't stored in the vtkImageData) |
|
Right, I thought so. If the spacing is set both on the image data and in the ijk to ras, there will be a compounding effect. This PR will have to have an accompanying PR in there to properly manage the spacing on the vtkImageData. @lassoan is it as simple as: volumeNode->SetIJKToRASMatrix(imageDevice->GetContent().transform);
volumeNode->SetAndObserveImageData(imageDevice->GetContent().image);
volumeNode->Modified();becomes volumeNode->SetIJKToRASMatrix(imageDevice->GetContent().transform);
volumeNode->SetAndObserveImageData(imageDevice->GetContent().image);
volumeNode->GetImageData()->SetSpacing(1.0, 1.0, 1.0); // IGTL device sets spacing in image data, do not duplicate with IJKtoRAS
volumeNode->Modified();? |
|
@olevs could you also add in setting of the origin as well? I can't send edits to your PR float spacing[3]; // spacing (mm/pixel)
float origin[3]; // origin (mm)
int svsize[3]; // sub-volume size
int svoffset[3]; // sub-volume offset
int scalarType; // VTK scalar type
int numComponents; // number of scalar components
int endian;
scalarType = IGTLToVTKScalarType( imgMsg->GetScalarType() );
endian = imgMsg->GetEndian();
imgMsg->GetDimensions(size);
imgMsg->GetSpacing(spacing);
imgMsg->GetOrigin(origin);
numComponents = imgMsg->GetNumComponents();
imgMsg->GetSubVolume(svsize, svoffset);
// check if the IGTL data fits to the current MRML node
int sizeInNode[3]={0,0,0};
int scalarTypeInNode=VTK_VOID;
int numComponentsInNode=0;
if (imageData.GetPointer()!=NULL)
{
imageData->GetDimensions(sizeInNode);
scalarTypeInNode = imageData->GetScalarType();
numComponentsInNode = imageData->GetNumberOfScalarComponents();
}
if (imageData.GetPointer()==NULL
|| sizeInNode[0] != size[0] || sizeInNode[1] != size[1] || sizeInNode[2] != size[2]
|| scalarType != scalarTypeInNode
|| numComponentsInNode != numComponents)
{
imageData = vtkSmartPointer<vtkImageData>::New();
dest->image = imageData;
imageData->SetDimensions(size[0], size[1], size[2]);
imageData->SetExtent(0, size[0]-1, 0, size[1]-1, 0, size[2]-1);
imageData->SetOrigin(origin[0], origin[1], origin[2]);
imageData->SetSpacing(spacing[0], spacing[1], spacing[2]); |
And if you detect VTK9 is used then you could set image directions, too. |
|
@lassoan I don't have the time or setup to test/verify image directions and VTK 9. If we should do it now, that probably needs to be done in a separate pull request by someone else? |
* Receive image spacing from image messages * Receive origin from image messages
Current solution throws away spacing of incoming image messages and sets spacing to (1, 1, 1). The incoming values should be kept.