[vtkusers] Applying transform to volume
P B
chose29 at hotmail.com
Wed Aug 13 12:48:50 EDT 2008
Hi,
sorry for another post on the same subject, I have added my source code at the end of this message, if it could help someone to give me advice,
Thanks again,
Regards
Pascale
From: chose29 at hotmail.comTo: vtkusers at vtk.orgDate: Wed, 13 Aug 2008 11:15:59 -0400Subject: [vtkusers] Applying transform to volume
Hi, I've been using vtkThinPlateSplineTransform and have been successful to get a result applied to landmarks, but have a question for transforming a volume. First, is there a way to force connectivity between points in a volume? More specifically this is what I have done and where is my problem: - I created a thin plate spline transform with source points (from an MR volume) and target points (from a CT volume).- To apply the transformation to the points, I used vtkTransformPolyDataFilter and specified a vtkPolyData structure with positions (vtkPoints) and connectivity (using vtkCellArray).- The resulting displacement for the source points is valid and they are now moved to the target points. I want to apply this exact transformation to a volume that contains only intensities. I can use vtkImageReslice and specify the transform from vtkThinPlateSplineTransform but the volume intensities do not seem to move exactly as the landmarks do and I wonder if the problem might not be the connectivity that is not respected in the final displacement. I cannot use vtkTransformPolyDataFilter with a volume image. Does anyone have an idea what I could do to specify a connectivity constraint? I have another question regarding inverse. In some examples (but not all) on the web, I see that the transform is inversed before using reslice. In what situation does the inverse need to be used?Thanks in advance for you help!Pascale
vtkThinPlateSplineTransform * TPSTransfo = vtkThinPlateSplineTransform::New();
vtkGeneralTransform * TPSGeneralTransfo = vtkGeneralTransform::New ();
vtkPolyData * InPolyData = vtkPolyData::New();
vtkImageReslice * reslice = vtkImageReslice::New();
/*
see example : /Hybrid/Testing/Tcl/TestThinPlateWarp3D.tcl -
*/
TPSTransfo->SetBasisToR(); // data is in 3D
TPSTransfo->SetSourceLandmarks(Points[ModalityTwo]);
TPSTransfo->SetTargetLandmarks(Points[ModalityOne]);
TPSTransfo->Modified();
TPSTransfo->Update();
TPSGeneralTransfo->SetInput (TPSTransfo);
TPSGeneralTransfo->Update();
vtkTransformPolyDataFilter *TransformPoints = vtkTransformPolyDataFilter::New();
InPolyData->SetPoints(Points[ModalityTwo]); // modify points from MR to fit CT
// create connectivity between points
vtkCellArray * TriangleCells = ConstructCellArray();
InPolyData->Allocate(TriangleCells->GetNumberOfCells());
InPolyData->SetPolys(TriangleCells);
InPolyData->Update();
TransformPoints->SetInput(InPolyData);
TransformPoints->SetTransform(TPSGeneralTransfo);
TransformPoints->Update();
// up to here works ok, mr landmarks are moved to their corresponding ct point match (tested output)
vtkPolyData * Result = TransformPoints->GetOutput();
vtkPoints * ResultPoints = Result->GetPoints();
OutputPointsSet(ResultPoints);
// transform volume according to TPS found
VTKTransform VTKTransfo;
vtkImageData * Volume = NULL;
if( mUseGrid == TRUE )
{
Volume = VTKTransfo.CreateGridVolume(mMRVolume);
}
else
{
Volume = VTKTransfo.Local2VTK(mMRVolume);
}
// transform volume using reslice
reslice->SetInput(Volume);
//******* Not sure what to use here.
// TPSGeneralTransfo->Inverse(); <- should it be used here? Why is it used in certain situations?
reslice->SetResliceTransform(TPSGeneralTransfo);
//reslice->SetResliceTransform(TransformPoints->GetTransform());
reslice->SetInterpolationModeToCubic();
SbVec3f Space; Spacing->GetPixelSpacing(mMRVolume, Space);
reslice->SetOutputSpacing(Space[0], Space[1], Space[2]);
for( i=0; i<3; i++ )
VoxPos[i] = 0;
Transfo.voxel2world(mMRVolume, VoxPos, WorldPos);
reslice->SetOutputOrigin(WorldPos[0], WorldPos[1], WorldPos[2]);
reslice->Update();
DebugIm = VTKTransfo.Vtk2Local(reslice->GetOutput(), mMRVolume);
TPSTransfo->Delete();
TPSGeneralTransfo->Delete();
InPolyData->DeleteCells();
InPolyData->Delete();
reslice->Delete();
return DebugIm;
_________________________________________________________________
If you like crossword puzzles, then you'll love Flexicon, a game which combines four overlapping crossword puzzles into one!
http://g.msn.ca/ca55/208
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20080813/829d777a/attachment.htm>
More information about the vtkusers
mailing list