16 #ifndef __vtkITKTransformConverter_h 17 #define __vtkITKTransformConverter_h 22 #include <vtkImageData.h> 23 #include <vtkPoints.h> 24 #include <vtkThinPlateSplineTransform.h> 25 #include <vtkTransform.h> 28 #include <itkAffineTransform.h> 29 #include <itkBSplineDeformableTransform.h> 30 #include <itkBSplineTransform.h> 31 #include <itkCompositeTransform.h> 32 #include <itkCompositeTransformIOHelper.h> 33 #include <itkDisplacementFieldTransform.h> 34 #include <itkIdentityTransform.h> 35 #include <itkTransformFileWriter.h> 36 #include <itkTransformFileReader.h> 37 #include <itkImageFileReader.h> 38 #include <itkImageFileWriter.h> 39 #include <itkTranslationTransform.h> 40 #include <itkScaleTransform.h> 41 #include <itkTransformFactory.h> 42 #include <itkThinPlateSplineKernelTransform.h> 66 static vtkAbstractTransform*
CreateVTKTransformFromITK(vtkObject* loggerObject,
typename itk::TransformBaseTemplate<T>::Pointer transformItk);
78 itk::Object::Pointer& secondaryTransformItk,
int preferITKv3CompatibleTransforms,
bool initialize =
true);
89 static bool SetVTKLinearTransformFromITK(vtkObject* loggerObject, vtkMatrix4x4* transformVtk_RAS,
typename itk::TransformBaseTemplate<T>::Pointer transformItk_LPS);
90 static bool SetITKLinearTransformFromVTK(vtkObject* loggerObject, itk::Object::Pointer& transformItk_LPS, vtkMatrix4x4* transformVtk_RAS);
100 static bool SetVTKThinPlateSplineTransformFromITK(vtkObject* loggerObject, vtkThinPlateSplineTransform* transformVtk_RAS,
typename itk::TransformBaseTemplate<T>::Pointer transformItk_LPS);
102 vtkThinPlateSplineTransform* transformVtk_RAS,
bool initialize =
true);
110 template <
typename T>
static bool SetITKv3BSplineFromVTKGeneric(vtkObject* loggerObject,
typename itk::Transform<T,VTKDimension,VTKDimension>::Pointer& warpTransformItk,
typename itk::Transform<T,VTKDimension,VTKDimension>::Pointer& bulkTransformItk,
vtkOrientedBSplineTransform* bsplineVtk,
bool alwaysAddBulkTransform);
118 itk::TransformFactory<InverseDisplacementFieldTransformFloatType>::RegisterTransform();
119 itk::TransformFactory<InverseDisplacementFieldTransformDoubleType>::RegisterTransform();
121 itk::TransformFactory<InverseBSplineTransformFloatITKv3Type>::RegisterTransform();
122 itk::TransformFactory<InverseBSplineTransformFloatITKv4Type>::RegisterTransform();
123 itk::TransformFactory<InverseBSplineTransformDoubleITKv3Type>::RegisterTransform();
124 itk::TransformFactory<InverseBSplineTransformDoubleITKv4Type>::RegisterTransform();
126 itk::TransformFactory<InverseThinPlateSplineTransformFloatType>::RegisterTransform();
127 itk::TransformFactory<InverseThinPlateSplineTransformDoubleType>::RegisterTransform();
129 typedef itk::ThinPlateSplineKernelTransform<float,3> ThinPlateSplineTransformFloatType;
133 itk::TransformFactory<ThinPlateSplineTransformFloatType>::RegisterTransform();
134 itk::TransformFactory<ThinPlateSplineTransformDoubleType>::RegisterTransform();
141 vtkMatrix4x4* transformVtk_RAS,
142 typename itk::TransformBaseTemplate<T>::Pointer transformItk_LPS)
145 typedef itk::MatrixOffsetTransformBase<T,D,D> LinearTransformType;
146 typedef itk::ScaleTransform<T, D> ScaleTransformType;
147 typedef itk::TranslationTransform<T, D> TranslateTransformType;
149 vtkSmartPointer<vtkMatrix4x4> transformVtk_LPS = vtkSmartPointer<vtkMatrix4x4>::New();
151 bool convertedToVtkMatrix=
false;
153 std::string itkTransformClassName = transformItk_LPS->GetNameOfClass();
172 if (itkTransformClassName.find(
"AffineTransform" ) != std::string::npos ||
173 itkTransformClassName ==
"MatrixOffsetTransformBase" ||
174 itkTransformClassName ==
"Rigid3DTransform" ||
175 itkTransformClassName ==
"Euler3DTransform" ||
176 itkTransformClassName ==
"CenteredEuler3DTransform" ||
177 itkTransformClassName ==
"QuaternionRigidTransform" ||
178 itkTransformClassName ==
"VersorTransform" ||
179 itkTransformClassName ==
"VersorRigid3DTransform" ||
180 itkTransformClassName ==
"ScaleSkewVersor3DTransform" ||
181 itkTransformClassName ==
"ScaleVersor3DTransform" ||
182 itkTransformClassName ==
"Similarity3DTransform" ||
183 itkTransformClassName ==
"ScaleTransform" ||
184 itkTransformClassName ==
"ScaleLogarithmicTransform")
186 typename LinearTransformType::Pointer dlt
187 =
static_cast<LinearTransformType*
>( transformItk_LPS.GetPointer() );
188 convertedToVtkMatrix=
true;
189 for (
unsigned int i=0; i < D; i++)
191 for (
unsigned int j=0; j < D; j++)
193 transformVtk_LPS->SetElement(i, j, dlt->GetMatrix()[i][j]);
195 transformVtk_LPS->SetElement(i, D, dlt->GetOffset()[i]);
200 if (itkTransformClassName ==
"IdentityTransform")
203 convertedToVtkMatrix=
true;
207 if (itkTransformClassName ==
"ScaleTransform")
209 typename ScaleTransformType::Pointer dst
210 =
static_cast<ScaleTransformType*
>( transformItk_LPS.GetPointer() );
211 convertedToVtkMatrix=
true;
212 for (
unsigned int i=0; i < D; i++)
214 transformVtk_LPS->SetElement(i, i, dst->GetScale()[i]);
219 if (itkTransformClassName ==
"TranslationTransform")
221 typename TranslateTransformType::Pointer dtt
222 =
static_cast<TranslateTransformType*
>( transformItk_LPS.GetPointer());
223 convertedToVtkMatrix=
true;
224 for (
unsigned int i=0; i < D; i++)
226 transformVtk_LPS->SetElement(i, D, dtt->GetOffset()[i]);
235 vtkSmartPointer<vtkMatrix4x4> lps2ras = vtkSmartPointer<vtkMatrix4x4>::New();
236 lps2ras->SetElement(0,0,-1);
237 lps2ras->SetElement(1,1,-1);
238 vtkMatrix4x4* ras2lps = lps2ras;
240 vtkMatrix4x4::Multiply4x4(lps2ras, transformVtk_LPS, transformVtk_LPS);
241 vtkMatrix4x4::Multiply4x4(transformVtk_LPS, ras2lps, transformVtk_RAS);
243 return convertedToVtkMatrix;
251 if (transformVtk_RAS==NULL)
253 vtkErrorWithObjectMacro(loggerObject,
"vtkITKTransformConverter::SetITKLinearTransformFromVTK failed: invalid input transform");
257 vtkSmartPointer<vtkMatrix4x4> lps2ras = vtkSmartPointer<vtkMatrix4x4>::New();
258 lps2ras->SetElement(0,0,-1);
259 lps2ras->SetElement(1,1,-1);
260 vtkMatrix4x4* ras2lps = lps2ras;
266 vtkSmartPointer<vtkMatrix4x4> vtkmat = vtkSmartPointer<vtkMatrix4x4>::New();
268 vtkMatrix4x4::Multiply4x4(ras2lps, transformVtk_RAS, vtkmat);
269 vtkMatrix4x4::Multiply4x4(vtkmat, lps2ras, vtkmat);
271 typedef AffineTransformType::MatrixType MatrixType;
272 typedef AffineTransformType::OutputVectorType OffsetType;
275 OffsetType itkoffset;
281 itkmat[i][j] = vtkmat->GetElement(i, j);
283 itkoffset[i] = vtkmat->GetElement(i, VTKDimension);
286 AffineTransformType::Pointer affine = AffineTransformType::New();
287 affine->SetMatrix(itkmat);
288 affine->SetOffset(itkoffset);
290 transformItk_LPS = affine;
297 static double identity[16] = {1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1};
300 for (i = 0; i < 4; i++)
302 for (j = 0; j < 4; j++)
304 if (matrix->GetElement(i,j) != identity[4*i+j])
314 template <
typename BSplineTransformType>
316 vtkObject* loggerObject,
318 typename itk::TransformBaseTemplate<typename BSplineTransformType::ScalarType>::Pointer warpTransformItk)
323 typedef typename BSplineTransformType::ScalarType T;
324 if (bsplineVtk==NULL)
326 vtkErrorWithObjectMacro(loggerObject,
"vtkMRMLTransformStorageNode::SetVTKBSplineFromITKv4 failed: bsplineVtk is invalid");
329 bool isDoublePrecisionInput=
true;
330 if (
sizeof(T)==
sizeof(
float))
332 isDoublePrecisionInput=
false;
334 else if (
sizeof(T)==
sizeof(
double))
336 isDoublePrecisionInput=
true;
340 vtkErrorWithObjectMacro(loggerObject,
"Unsupported scalar type in BSpline transform file (only float and double are supported)");
344 typename BSplineTransformType::Pointer bsplineItk = BSplineTransformType::New();
345 std::string warpTransformItkName = warpTransformItk->GetNameOfClass();
346 std::string requestedWarpTransformItkName = bsplineItk->GetNameOfClass();
347 if (warpTransformItkName != requestedWarpTransformItkName)
351 if (warpTransformItk->GetOutputSpaceDimension() !=
VTKDimension)
353 vtkErrorWithObjectMacro(loggerObject,
"Unsupported number of dimensions in BSpline transform file (expected = " 354 <<
VTKDimension <<
", actual = " << warpTransformItk->GetOutputSpaceDimension() <<
")");
357 bsplineItk =
static_cast< BSplineTransformType*
>( warpTransformItk.GetPointer() );
365 const typename BSplineTransformType::CoefficientImageArray coefficientImages =
366 bsplineItk->GetCoefficientImages();
370 typename BSplineTransformType::MeshSizeType meshSize =
371 coefficientImages[0]->GetLargestPossibleRegion().GetSize();
374 typename BSplineTransformType::OriginType origin =
375 coefficientImages[0]->GetOrigin();
378 typename BSplineTransformType::SpacingType spacing =
379 coefficientImages[0]->GetSpacing();
382 typename BSplineTransformType::DirectionType direction =
383 coefficientImages[0]->GetDirection();
385 vtkNew<vtkMatrix4x4> gridDirectionMatrix_LPS;
388 for (
unsigned int column=0; column<
VTKDimension; column++)
390 gridDirectionMatrix_LPS->SetElement(row,column,direction[row][column]);
395 bsplineVtk->SetBorderModeToZero();
397 vtkNew<vtkImageData> bsplineCoefficients;
399 bsplineCoefficients->SetExtent(0, meshSize[0]-1, 0, meshSize[1]-1, 0, meshSize[2]-1);
400 bsplineCoefficients->SetSpacing(spacing[0], spacing[1], spacing[2]);
403 vtkNew<vtkMatrix4x4> lpsToRas;
404 lpsToRas->SetElement(0,0,-1);
405 lpsToRas->SetElement(1,1,-1);
407 vtkNew<vtkMatrix4x4> rasToLps;
408 rasToLps->SetElement(0,0,-1);
409 rasToLps->SetElement(1,1,-1);
411 vtkNew<vtkMatrix4x4> gridDirectionMatrix_RAS;
412 vtkMatrix4x4::Multiply4x4(
413 lpsToRas.GetPointer(),
414 gridDirectionMatrix_LPS.GetPointer(),
415 gridDirectionMatrix_RAS.GetPointer());
419 double gridOrigin_RAS[3]={-origin[0], -origin[1], origin[2]};
420 bsplineCoefficients->SetOrigin(gridOrigin_RAS);
422 int bsplineCoefficientsScalarType=VTK_FLOAT;
423 if (isDoublePrecisionInput)
425 bsplineCoefficientsScalarType=VTK_DOUBLE;
428 bsplineCoefficients->AllocateScalars(bsplineCoefficientsScalarType, 3);
430 const unsigned int expectedNumberOfVectors = meshSize[0]*meshSize[1]*meshSize[2];
431 const unsigned int expectedNumberOfParameters = expectedNumberOfVectors*
VTKDimension;
432 const unsigned int actualNumberOfParameters = bsplineItk->GetNumberOfParameters();
434 if( actualNumberOfParameters != expectedNumberOfParameters )
436 vtkErrorWithObjectMacro(loggerObject,
"Mismatch in number of BSpline parameters in the transform file and the MRML node");
439 const T* itkBSplineParams_LPS =
static_cast<const T*
>(bsplineItk->GetParameters().data_block());
440 T* vtkBSplineParams_RAS=
static_cast<T*
>(bsplineCoefficients->GetScalarPointer());
441 for (
unsigned int i=0; i<expectedNumberOfVectors; i++)
443 *(vtkBSplineParams_RAS++) = - (*(itkBSplineParams_LPS ));
444 *(vtkBSplineParams_RAS++) = - (*(itkBSplineParams_LPS+expectedNumberOfVectors ));
445 *(vtkBSplineParams_RAS++) = (*(itkBSplineParams_LPS+expectedNumberOfVectors*2));
446 itkBSplineParams_LPS++;
448 bsplineVtk->SetCoefficientData(bsplineCoefficients.GetPointer());
457 typename itk::TransformBaseTemplate<T>::Pointer warpTransformItk,
typename itk::TransformBaseTemplate<T>::Pointer bulkTransformItk)
459 if (bsplineVtk==NULL)
461 vtkErrorWithObjectMacro(loggerObject,
"vtkMRMLTransformStorageNode::SetVTKBSplineFromITK failed: bsplineVtk is invalid");
465 bool inverse =
false;
477 vtkDebugWithObjectMacro(loggerObject,
"Not an ITKv3 BSpline transform");
482 if( bulkTransformItk )
484 std::string bulkTransformItkTransformName = bulkTransformItk->GetNameOfClass();
486 typedef itk::AffineTransform<T,3> BulkTransformType;
488 if (bulkTransformItkTransformName ==
"AffineTransform")
490 BulkTransformType* bulkItkAffine =
static_cast<BulkTransformType*
> (bulkTransformItk.GetPointer());
491 vtkNew<vtkMatrix4x4> bulkMatrix_LPS;
496 bulkMatrix_LPS->SetElement(i,j, bulkItkAffine->GetMatrix()[i][j]);
498 bulkMatrix_LPS->SetElement(i,VTKDimension, bulkItkAffine->GetOffset()[i]);
500 vtkNew<vtkMatrix4x4> lpsToRas;
501 lpsToRas->SetElement(0,0,-1);
502 lpsToRas->SetElement(1,1,-1);
503 vtkNew<vtkMatrix4x4> rasToLps;
504 rasToLps->SetElement(0,0,-1);
505 rasToLps->SetElement(1,1,-1);
506 vtkNew<vtkMatrix4x4> bulkMatrix_RAS;
507 vtkMatrix4x4::Multiply4x4(lpsToRas.GetPointer(), bulkMatrix_LPS.GetPointer(), bulkMatrix_RAS.GetPointer());
508 vtkMatrix4x4::Multiply4x4(bulkMatrix_RAS.GetPointer(), rasToLps.GetPointer(), bulkMatrix_RAS.GetPointer());
511 else if (bulkTransformItkTransformName ==
"IdentityTransform")
517 vtkErrorWithObjectMacro(loggerObject,
"Cannot read the 2nd transform in BSplineTransform (expected AffineTransform_double_3_3 or IdentityTransform)" );
524 bsplineVtk->Inverse();
535 bool inverse =
false;
547 vtkDebugWithObjectMacro(loggerObject,
"Not an ITKv4 BSpline transform");
552 bsplineVtk->Inverse();
559 typename itk::Transform< typename BSplineTransformType::ScalarType,VTKDimension,VTKDimension>::Pointer& warpTransformItk,
vtkOrientedBSplineTransform* bsplineVtk)
561 typedef typename BSplineTransformType::ScalarType T;
562 if (bsplineVtk==NULL)
564 vtkErrorWithObjectMacro(loggerObject,
"vtkMRMLTransformStorageNode::SetITKBSplineFromVTK failed: bsplineVtk is invalid");
567 vtkImageData* bsplineCoefficients_RAS=bsplineVtk->GetCoefficientData();
568 if (bsplineCoefficients_RAS==NULL)
570 vtkErrorWithObjectMacro(loggerObject,
"Cannot write BSpline transform to file: coefficients are not specified");
574 typename BSplineTransformType::Pointer bsplineItk = BSplineTransformType::New();
575 warpTransformItk = bsplineItk;
582 #if defined(ITK_FIXED_PARAMETERS_ARE_DOUBLE) // After 4.8.1 583 typename BSplineTransformType::FixedParametersType transformFixedParamsItk;
585 typename BSplineTransformType::ParametersType transformFixedParamsItk;
588 transformFixedParamsItk.SetSize(numberOfFixedParameters);
590 int *gridExtent=bsplineCoefficients_RAS->GetExtent();
591 int gridSize[3]={gridExtent[1]-gridExtent[0]+1, gridExtent[3]-gridExtent[2]+1, gridExtent[5]-gridExtent[4]+1};
592 transformFixedParamsItk[0]=gridSize[0];
593 transformFixedParamsItk[1]=gridSize[1];
594 transformFixedParamsItk[2]=gridSize[2];
596 double* gridOrigin_RAS=bsplineCoefficients_RAS->GetOrigin();
597 double gridOrigin_LPS[3]={-gridOrigin_RAS[0], -gridOrigin_RAS[1], gridOrigin_RAS[2]};
598 transformFixedParamsItk[3]=gridOrigin_LPS[0];
599 transformFixedParamsItk[4]=gridOrigin_LPS[1];
600 transformFixedParamsItk[5]=gridOrigin_LPS[2];
602 double* gridSpacing=bsplineCoefficients_RAS->GetSpacing();
603 transformFixedParamsItk[6]=gridSpacing[0];
604 transformFixedParamsItk[7]=gridSpacing[1];
605 transformFixedParamsItk[8]=gridSpacing[2];
607 vtkNew<vtkMatrix4x4> gridDirectionMatrix_RAS;
612 vtkNew<vtkMatrix4x4> lpsToRas;
613 lpsToRas->SetElement(0,0,-1);
614 lpsToRas->SetElement(1,1,-1);
615 vtkNew<vtkMatrix4x4> rasToLps;
616 rasToLps->SetElement(0,0,-1);
617 rasToLps->SetElement(1,1,-1);
618 vtkNew<vtkMatrix4x4> gridDirectionMatrix_LPS;
619 vtkMatrix4x4::Multiply4x4(rasToLps.GetPointer(), gridDirectionMatrix_RAS.GetPointer(), gridDirectionMatrix_LPS.GetPointer());
623 for (
unsigned int column=0; column<
VTKDimension; column++)
625 transformFixedParamsItk[fpIndex++]=gridDirectionMatrix_LPS->GetElement(row,column);
629 bsplineItk->SetFixedParameters(transformFixedParamsItk);
633 const unsigned int expectedNumberOfVectors = gridSize[0]*gridSize[1]*gridSize[2];
634 const unsigned int expectedNumberOfParameters = expectedNumberOfVectors*
VTKDimension;
635 if( bsplineItk->GetNumberOfParameters() != expectedNumberOfParameters )
637 vtkErrorWithObjectMacro(loggerObject,
"Mismatch in number of BSpline parameters in the ITK transform and the VTK transform");
641 typename BSplineTransformType::ParametersType transformParamsItk(expectedNumberOfParameters);
642 T* itkBSplineParams_LPS =
static_cast<T*
>(transformParamsItk.data_block());
643 T* vtkBSplineParams_RAS=
static_cast<T*
>(bsplineCoefficients_RAS->GetScalarPointer());
644 double coefficientScale = bsplineVtk->GetDisplacementScale();
645 for (
unsigned int i=0; i<expectedNumberOfVectors; i++)
647 *(itkBSplineParams_LPS ) = -coefficientScale * (*(vtkBSplineParams_RAS++));
648 *(itkBSplineParams_LPS+expectedNumberOfVectors ) = -coefficientScale * (*(vtkBSplineParams_RAS++));
649 *(itkBSplineParams_LPS+expectedNumberOfVectors*2) = coefficientScale * (*(vtkBSplineParams_RAS++));
650 itkBSplineParams_LPS++;
653 bsplineItk->SetParameters(transformParamsItk);
659 typename itk::Transform<T,VTKDimension,VTKDimension>::Pointer& warpTransformItk,
660 typename itk::Transform<T,VTKDimension,VTKDimension>::Pointer& bulkTransformItk,
663 if (bsplineVtk==NULL)
665 vtkErrorWithObjectMacro(loggerObject,
"vtkMRMLTransformStorageNode::SetITKBSplineFromVTK failed: bsplineVtk is invalid");
669 bsplineVtk->Update();
670 bool itkTransformSetSuccessfully =
false;
671 if (bsplineVtk->GetInverseFlag())
673 itkTransformSetSuccessfully = SetITKBSplineParametersFromVTKGeneric< itk::InverseBSplineDeformableTransform< T, VTKDimension, VTKDimension > >(loggerObject, warpTransformItk, bsplineVtk);
677 itkTransformSetSuccessfully = SetITKBSplineParametersFromVTKGeneric< itk::BSplineDeformableTransform< T, VTKDimension, VTKDimension > >(loggerObject, warpTransformItk, bsplineVtk);
679 if (!itkTransformSetSuccessfully)
681 vtkErrorWithObjectMacro(loggerObject,
"vtkMRMLTransformStorageNode::SetITKBSplineFromVTK failed: cannot determine BSpline parameters");
686 if (bulkMatrix_RAS || alwaysAddBulkTransform)
688 vtkNew<vtkMatrix4x4> lpsToRas;
689 lpsToRas->SetElement(0,0,-1);
690 lpsToRas->SetElement(1,1,-1);
691 vtkNew<vtkMatrix4x4> rasToLps;
692 rasToLps->SetElement(0,0,-1);
693 rasToLps->SetElement(1,1,-1);
694 vtkNew<vtkMatrix4x4> bulkMatrix_LPS;
697 if (bulkMatrix_RAS!=NULL)
699 vtkMatrix4x4::Multiply4x4(rasToLps.GetPointer(), bulkMatrix_RAS, bulkMatrix_LPS.GetPointer());
700 vtkMatrix4x4::Multiply4x4(bulkMatrix_LPS.GetPointer(), lpsToRas.GetPointer(), bulkMatrix_LPS.GetPointer());
702 typedef itk::AffineTransform<T,VTKDimension> BulkTransformType;
703 typename BulkTransformType::Pointer affineItk = BulkTransformType::New();
704 bulkTransformItk = affineItk;
706 typename BulkTransformType::MatrixType affineMatrix;
707 typename BulkTransformType::OffsetType affineOffset;
712 affineMatrix[i][j]=bulkMatrix_LPS->GetElement(i,j);
714 affineOffset[i]=bulkMatrix_LPS->GetElement(i,VTKDimension);
717 affineItk->SetMatrix(affineMatrix);
718 affineItk->SetOffset(affineOffset);
722 bulkTransformItk=NULL;
730 typename itk::Transform<T,VTKDimension,VTKDimension>::Pointer& warpTransformItk,
734 bsplineVtk->Update();
735 bool itkTransformSetSuccessfully =
false;
736 if (bsplineVtk->GetInverseFlag())
738 itkTransformSetSuccessfully = SetITKBSplineParametersFromVTKGeneric< itk::InverseBSplineTransform< T, VTKDimension, VTKDimension > >(loggerObject, warpTransformItk, bsplineVtk);
742 itkTransformSetSuccessfully = SetITKBSplineParametersFromVTKGeneric< itk::BSplineTransform< T, VTKDimension, VTKDimension > >(loggerObject, warpTransformItk, bsplineVtk);
744 if (!itkTransformSetSuccessfully)
746 vtkErrorWithObjectMacro(loggerObject,
"vtkMRMLTransformStorageNode::SetITKv4BSplineFromVTKGeneric failed: cannot determine BSpline parameters");
756 if (bsplineVtk==NULL)
758 vtkErrorWithObjectMacro(loggerObject,
"Cannot retrieve BSpline transform from node");
762 vtkImageData* bsplineCoefficients=bsplineVtk->GetCoefficientData();
764 if (bsplineCoefficients==NULL)
766 vtkErrorWithObjectMacro(loggerObject,
"Cannot write BSpline transform to file: coefficients are not specified");
770 if (bsplineCoefficients->GetScalarType()==VTK_FLOAT)
772 typedef itk::Transform<float, VTKDimension, VTKDimension > ITKTransformType;
773 ITKTransformType::Pointer floatWarpTransformItk;
774 ITKTransformType::Pointer floatBulkTransformItk;
775 if (!SetITKv3BSplineFromVTKGeneric<float>(loggerObject, floatWarpTransformItk, floatBulkTransformItk, bsplineVtk, alwaysAddBulkTransform))
777 vtkErrorWithObjectMacro(loggerObject,
"Cannot write BSpline transform to file");
780 warpTransformItk = floatWarpTransformItk.GetPointer();
781 bulkTransformItk = floatBulkTransformItk.GetPointer();
783 else if (bsplineCoefficients->GetScalarType()==VTK_DOUBLE)
785 typedef itk::Transform<double, VTKDimension, VTKDimension > ITKTransformType;
786 ITKTransformType::Pointer doubleWarpTransformItk;
787 ITKTransformType::Pointer doubleBulkTransformItk;
788 if (!SetITKv3BSplineFromVTKGeneric<double>(loggerObject, doubleWarpTransformItk, doubleBulkTransformItk, bsplineVtk, alwaysAddBulkTransform))
790 vtkErrorWithObjectMacro(loggerObject,
"Cannot write BSpline transform to file");
793 warpTransformItk = doubleWarpTransformItk;
794 bulkTransformItk = doubleBulkTransformItk;
798 vtkErrorWithObjectMacro(loggerObject,
"Cannot write BSpline transform to file: only float and double coefficient types are supported");
808 if (bsplineVtk==NULL)
810 vtkErrorWithObjectMacro(loggerObject,
"Cannot retrieve BSpline transform from node");
814 vtkImageData* bsplineCoefficients=bsplineVtk->GetCoefficientData();
816 if (bsplineCoefficients==NULL)
818 vtkErrorWithObjectMacro(loggerObject,
"Cannot write BSpline transform to file: coefficients are not specified");
822 if (bsplineCoefficients->GetScalarType()==VTK_FLOAT)
824 typedef itk::Transform<float, VTKDimension, VTKDimension > ITKTransformType;
825 ITKTransformType::Pointer floatWarpTransformItk;
826 if (!SetITKv4BSplineFromVTKGeneric<float>(loggerObject, floatWarpTransformItk, bsplineVtk))
828 vtkErrorWithObjectMacro(loggerObject,
"Cannot write BSpline transform to file");
831 warpTransformItk = floatWarpTransformItk.GetPointer();
833 else if (bsplineCoefficients->GetScalarType()==VTK_DOUBLE)
835 typedef itk::Transform<double, VTKDimension, VTKDimension > ITKTransformType;
836 ITKTransformType::Pointer doubleWarpTransformItk;
837 if (!SetITKv4BSplineFromVTKGeneric<double>(loggerObject, doubleWarpTransformItk, bsplineVtk))
839 vtkErrorWithObjectMacro(loggerObject,
"Cannot write BSpline transform to file");
842 warpTransformItk = doubleWarpTransformItk;
846 vtkErrorWithObjectMacro(loggerObject,
"Cannot write BSpline transform to file: only float and double coefficient types are supported");
857 typedef itk::DisplacementFieldTransform< T, 3 > DisplacementFieldTransformType;
860 if (!transformItk_LPS)
862 vtkErrorWithObjectMacro(loggerObject,
"Cannot set VTK oriented grid transform from ITK: the input transform is NULL");
865 if (transformItk_LPS->GetOutputSpaceDimension() !=
VTKDimension)
867 vtkErrorWithObjectMacro(loggerObject,
"Unsupported number of dimensions in oriented grid transform file (expected = " 868 <<
VTKDimension <<
", actual = " << transformItk_LPS->GetOutputSpaceDimension() <<
")");
872 std::string transformItkClassName = transformItk_LPS->GetNameOfClass();
874 bool inverse =
false;
875 typename DisplacementFieldTransformType::DisplacementFieldType* gridImageItk_Lps = NULL;
876 if (transformItkClassName ==
"InverseDisplacementFieldTransform")
878 DisplacementFieldTransformType* inverseDisplacementFieldTransform =
static_cast<InverseDisplacementFieldTransformType*
>( transformItk_LPS.GetPointer() );
880 gridImageItk_Lps = inverseDisplacementFieldTransform->GetDisplacementField();
882 else if (transformItkClassName ==
"DisplacementFieldTransform")
884 DisplacementFieldTransformType* displacementFieldTransform =
static_cast<DisplacementFieldTransformType*
>( transformItk_LPS.GetPointer() );
886 gridImageItk_Lps = displacementFieldTransform->GetDisplacementField();
890 vtkDebugWithObjectMacro(loggerObject,
"Not a grid transform");
893 if (!SetVTKOrientedGridTransformFromITKImage<T>(loggerObject, transformVtk_RAS, gridImageItk_Lps))
899 transformVtk_RAS->Inverse();
907 GridImageDoubleType::Pointer gridImageItk_Lps;
910 vtkErrorWithObjectMacro(loggerObject,
"vtkITKTransformConverter::SetITKOrientedGridTransformFromVTK failed: input transform is invalid");
914 transformVtk_RAS->Update();
915 if (transformVtk_RAS->GetInverseFlag())
918 gridTransformItk->SetDisplacementField(gridImageItk_Lps);
919 transformItk_LPS = gridTransformItk;
923 DisplacementFieldTransformDoubleType::Pointer gridTransformItk = DisplacementFieldTransformDoubleType::New();
924 gridTransformItk->SetDisplacementField(gridImageItk_Lps);
925 transformItk_LPS = gridTransformItk;
934 typedef itk::DisplacementFieldTransform< T, 3 > DisplacementFieldTransformType;
935 typedef typename DisplacementFieldTransformType::DisplacementFieldType GridImageType;
937 vtkNew<vtkImageData> gridImage_Ras;
940 gridImage_Ras->SetOrigin( -gridImage_Lps->GetOrigin()[0], -gridImage_Lps->GetOrigin()[1], gridImage_Lps->GetOrigin()[2] );
943 gridImage_Ras->SetSpacing( gridImage_Lps->GetSpacing()[0], gridImage_Lps->GetSpacing()[1], gridImage_Lps->GetSpacing()[2] );
946 vtkNew<vtkMatrix4x4> gridDirectionMatrix_LPS;
949 for (
unsigned int column=0; column<
VTKDimension; column++)
951 gridDirectionMatrix_LPS->SetElement(row,column,gridImage_Lps->GetDirection()(row,column));
954 vtkNew<vtkMatrix4x4> lpsToRas;
955 lpsToRas->SetElement(0,0,-1);
956 lpsToRas->SetElement(1,1,-1);
957 vtkNew<vtkMatrix4x4> gridDirectionMatrix_RAS;
958 vtkMatrix4x4::Multiply4x4(lpsToRas.GetPointer(), gridDirectionMatrix_LPS.GetPointer(), gridDirectionMatrix_RAS.GetPointer());
962 typename GridImageType::SizeType size = gridImage_Lps->GetBufferedRegion().GetSize();
963 gridImage_Ras->SetDimensions( size[0], size[1], size[2] );
964 unsigned int numberOfScalarComponents = GridImageType::PixelType::Dimension;
965 if (numberOfScalarComponents!=VTKDimension)
967 vtkErrorWithObjectMacro(loggerObject,
"Cannot load grid transform: the input displacement field expected to contain " 968 << VTKDimension <<
" components but it actually contains " << numberOfScalarComponents );
971 gridImage_Ras->AllocateScalars(VTK_DOUBLE, 3);
973 double* displacementVectors_Ras =
reinterpret_cast<double*
>(gridImage_Ras->GetScalarPointer());
974 itk::ImageRegionConstIterator<GridImageType> inputIt(gridImage_Lps, gridImage_Lps->GetRequestedRegion());
976 while( !inputIt.IsAtEnd() )
978 typename GridImageType::PixelType displacementVectorLps=inputIt.Get();
979 *(displacementVectors_Ras++) = -displacementVectorLps[0];
980 *(displacementVectors_Ras++) = -displacementVectorLps[1];
981 *(displacementVectors_Ras++) = displacementVectorLps[2];
985 grid_Ras->SetDisplacementGridData( gridImage_Ras.GetPointer() );
988 grid_Ras->SetInterpolationModeToCubic();
998 vtkErrorWithObjectMacro(loggerObject,
"Cannot save grid transform: the input vtkOrientedGridTransform is invalid");
1005 vtkImageData* gridImage_Ras = grid_Ras->GetDisplacementGrid();
1006 if (gridImage_Ras==NULL)
1008 vtkErrorWithObjectMacro(loggerObject,
"Cannot save grid transform: the input vtkOrientedGridTransform does not contain a valid displacement grid");
1011 if (gridImage_Ras->GetNumberOfScalarComponents() !=
static_cast<int>(
VTKDimension))
1013 vtkErrorWithObjectMacro(loggerObject,
"Cannot save grid transform: the input vtkOrientedGridTransform expected to contain " 1014 <<
VTKDimension <<
" components but it actually contains " << gridImage_Ras->GetNumberOfScalarComponents() );
1018 gridImage_Lps = GridImageDoubleType::New();
1021 double* origin_Ras = gridImage_Ras->GetOrigin();
1022 double origin_Lps[3] = { -origin_Ras[0], -origin_Ras[1], origin_Ras[2] };
1023 gridImage_Lps->SetOrigin( origin_Lps );
1026 double* spacing = gridImage_Ras->GetSpacing();
1028 gridImage_Lps->SetSpacing( spacing );
1031 vtkNew<vtkMatrix4x4> gridDirectionMatrix_Ras;
1036 vtkNew<vtkMatrix4x4> rasToLps;
1037 rasToLps->SetElement(0,0,-1);
1038 rasToLps->SetElement(1,1,-1);
1039 vtkNew<vtkMatrix4x4> gridDirectionMatrix_Lps;
1040 vtkMatrix4x4::Multiply4x4(rasToLps.GetPointer(), gridDirectionMatrix_Ras.GetPointer(), gridDirectionMatrix_Lps.GetPointer());
1041 GridImageDoubleType::DirectionType gridDirectionMatrixItk_Lps;
1044 for (
unsigned int column=0; column<
VTKDimension; column++)
1046 gridDirectionMatrixItk_Lps(row,column) = gridDirectionMatrix_Lps->GetElement(row,column);
1049 gridImage_Lps->SetDirection(gridDirectionMatrixItk_Lps);
1052 GridImageDoubleType::IndexType start;
1053 start[0] = start[1] = start[2] = 0;
1054 int* Nijk = gridImage_Ras->GetDimensions();
1055 GridImageDoubleType::SizeType size;
1056 size[0] = Nijk[0]; size[1] = Nijk[1]; size[2] = Nijk[2];
1057 GridImageDoubleType::RegionType region;
1058 region.SetSize( size );
1059 region.SetIndex( start );
1060 gridImage_Lps->SetRegions( region );
1061 gridImage_Lps->Allocate();
1062 itk::ImageRegionIterator<GridImageDoubleType> gridImageIt_Lps(gridImage_Lps, region);
1063 gridImageIt_Lps.GoToBegin();
1064 GridImageDoubleType::PixelType displacementVectorLps;
1065 double displacementScale = grid_Ras->GetDisplacementScale();
1066 double displacementShift = grid_Ras->GetDisplacementShift();
1068 if (gridImage_Ras->GetScalarType()==VTK_DOUBLE)
1070 double* displacementVectors_Ras =
reinterpret_cast<double*
>(gridImage_Ras->GetScalarPointer());
1071 while( !gridImageIt_Lps.IsAtEnd() )
1073 displacementVectorLps[0] = -( displacementScale * (*(displacementVectors_Ras++)) + displacementShift );
1074 displacementVectorLps[1] = -( displacementScale * (*(displacementVectors_Ras++)) + displacementShift );
1075 displacementVectorLps[2] = ( displacementScale * (*(displacementVectors_Ras++)) + displacementShift );
1076 gridImageIt_Lps.Set(displacementVectorLps);
1080 else if (gridImage_Ras->GetScalarType()==VTK_FLOAT)
1082 float* displacementVectors_Ras =
reinterpret_cast<float*
>(gridImage_Ras->GetScalarPointer());
1083 while( !gridImageIt_Lps.IsAtEnd() )
1085 displacementVectorLps[0] = -( displacementScale * (*(displacementVectors_Ras++)) + displacementShift );
1086 displacementVectorLps[1] = -( displacementScale * (*(displacementVectors_Ras++)) + displacementShift );
1087 displacementVectorLps[2] = ( displacementScale * (*(displacementVectors_Ras++)) + displacementShift );
1088 gridImageIt_Lps.Set(displacementVectorLps);
1094 vtkErrorWithObjectMacro(loggerObject,
"Cannot save grid transform: only float and double scalar types are supported");
1101 template<
typename T>
1104 typedef itk::ThinPlateSplineKernelTransform<T,3> ThinPlateSplineTransformType;
1107 if (transformVtk_RAS==NULL)
1109 vtkErrorWithObjectMacro(loggerObject,
"Cannot set VTK thin-plate spline transform from ITK: the output vtkThinPlateSplineTransform is invalid");
1113 if (!transformItk_LPS)
1115 vtkErrorWithObjectMacro(loggerObject,
"Cannot set VTK thin-plate spline transform from ITK: the input transform is NULL");
1119 if (transformItk_LPS->GetOutputSpaceDimension() !=
VTKDimension)
1121 vtkErrorWithObjectMacro(loggerObject,
"Unsupported number of dimensions in thin-plate spline transform file (expected = " 1122 <<
VTKDimension <<
", actual = " << transformItk_LPS->GetOutputSpaceDimension() <<
")");
1126 std::string transformItkClassName = transformItk_LPS->GetNameOfClass();
1128 bool inverse =
false;
1129 typename ThinPlateSplineTransformType::PointSetType::Pointer sourceLandmarksItk_Lps;
1130 typename ThinPlateSplineTransformType::PointSetType::Pointer targetLandmarksItk_Lps;
1131 if (transformItkClassName ==
"InverseThinPlateSplineKernelTransform")
1133 ThinPlateSplineTransformType* inverseTpsTransform =
static_cast<InverseThinPlateSplineTransformType*
>( transformItk_LPS.GetPointer() );
1135 sourceLandmarksItk_Lps = inverseTpsTransform->GetSourceLandmarks();
1136 targetLandmarksItk_Lps = inverseTpsTransform->GetTargetLandmarks();
1138 else if (transformItkClassName ==
"ThinPlateSplineKernelTransform")
1140 ThinPlateSplineTransformType* tpsTransform =
static_cast<ThinPlateSplineTransformType*
>( transformItk_LPS.GetPointer() );
1142 sourceLandmarksItk_Lps = tpsTransform->GetSourceLandmarks();
1143 targetLandmarksItk_Lps = tpsTransform->GetTargetLandmarks();
1147 vtkDebugWithObjectMacro(loggerObject,
"Not a ThinPlateSpline transform");
1151 vtkNew<vtkPoints> sourceLandmarksVtk_Ras;
1152 unsigned int numberOfSourceLandmarks = sourceLandmarksItk_Lps->GetNumberOfPoints();
1153 for(
unsigned int i = 0; i < numberOfSourceLandmarks; i++)
1155 typename ThinPlateSplineTransformType::InputPointType pointItk_Lps;
1156 bool pointExists = sourceLandmarksItk_Lps->GetPoint(i, &pointItk_Lps);
1161 double pointVtk_Ras[3]={0};
1162 pointVtk_Ras[0] = -pointItk_Lps[0];
1163 pointVtk_Ras[1] = -pointItk_Lps[1];
1164 pointVtk_Ras[2] = pointItk_Lps[2];
1165 sourceLandmarksVtk_Ras->InsertNextPoint(pointVtk_Ras);
1168 vtkNew<vtkPoints> targetLandmarksVtk_Ras;
1169 unsigned int numberOfTargetLandmarks = targetLandmarksItk_Lps->GetNumberOfPoints();
1170 for(
unsigned int i = 0; i < numberOfTargetLandmarks; i++)
1172 typename ThinPlateSplineTransformType::InputPointType pointItk_Lps;
1173 bool pointExists = targetLandmarksItk_Lps->GetPoint(i, &pointItk_Lps);
1178 double pointVtk_Ras[3]={0};
1179 pointVtk_Ras[0] = -pointItk_Lps[0];
1180 pointVtk_Ras[1] = -pointItk_Lps[1];
1181 pointVtk_Ras[2] = pointItk_Lps[2];
1182 targetLandmarksVtk_Ras->InsertNextPoint(pointVtk_Ras);
1185 transformVtk_RAS->SetBasisToR();
1186 transformVtk_RAS->SetSourceLandmarks(sourceLandmarksVtk_Ras.GetPointer());
1187 transformVtk_RAS->SetTargetLandmarks(targetLandmarksVtk_Ras.GetPointer());
1191 transformVtk_RAS->Inverse();
1198 itk::Object::Pointer& transformItk_LPS, vtkThinPlateSplineTransform* transformVtk_RAS,
bool initialize )
1200 if (transformVtk_RAS==NULL)
1202 vtkErrorWithObjectMacro(loggerObject,
"Cannot set ITK thin-plate spline transform from VTK: the intput vtkThinPlateSplineTransform is invalid");
1207 transformVtk_RAS->Update();
1209 if (transformVtk_RAS->GetBasis()!=VTK_RBF_R)
1211 vtkErrorWithObjectMacro(loggerObject,
"Cannot set ITK thin-plate spline transform from VTK: basis function must be R." 1212 " Call SetBasisToR() method of the vtkThinPlateSplineTransform object before attempting to write it to file.");
1216 ThinPlateSplineTransformDoubleType::PointSetType::Pointer sourceLandmarksItk_Lps = ThinPlateSplineTransformDoubleType::PointSetType::New();
1217 vtkPoints* sourceLandmarksVtk_Ras=transformVtk_RAS->GetSourceLandmarks();
1218 if (sourceLandmarksVtk_Ras!=NULL)
1220 for (
int i=0; i<sourceLandmarksVtk_Ras->GetNumberOfPoints(); i++)
1222 double posVtk_Ras[3]={0};
1223 sourceLandmarksVtk_Ras->GetPoint(i, posVtk_Ras);
1224 ThinPlateSplineTransformDoubleType::InputPointType posItk_Lps;
1225 posItk_Lps[0] = -posVtk_Ras[0];
1226 posItk_Lps[1] = -posVtk_Ras[1];
1227 posItk_Lps[2] = posVtk_Ras[2];
1228 sourceLandmarksItk_Lps->GetPoints()->InsertElement(i,posItk_Lps);
1231 ThinPlateSplineTransformDoubleType::PointSetType::Pointer targetLandmarksItk_Lps = ThinPlateSplineTransformDoubleType::PointSetType::New();
1232 vtkPoints* targetLandmarksVtk_Ras=transformVtk_RAS->GetTargetLandmarks();
1233 if (targetLandmarksVtk_Ras!=NULL)
1235 for (
int i=0; i<targetLandmarksVtk_Ras->GetNumberOfPoints(); i++)
1237 double posVtk_Ras[3]={0};
1238 targetLandmarksVtk_Ras->GetPoint(i, posVtk_Ras);
1239 ThinPlateSplineTransformDoubleType::InputPointType posItk_Lps;
1240 posItk_Lps[0] = -posVtk_Ras[0];
1241 posItk_Lps[1] = -posVtk_Ras[1];
1242 posItk_Lps[2] = posVtk_Ras[2];
1243 targetLandmarksItk_Lps->GetPoints()->InsertElement(i,posItk_Lps);
1247 if (transformVtk_RAS->GetInverseFlag())
1250 tpsTransformItk->SetSourceLandmarks(sourceLandmarksItk_Lps);
1251 tpsTransformItk->SetTargetLandmarks(targetLandmarksItk_Lps);
1254 tpsTransformItk->ComputeWMatrix();
1256 transformItk_LPS = tpsTransformItk;
1260 ThinPlateSplineTransformDoubleType::Pointer tpsTransformItk = ThinPlateSplineTransformDoubleType::New();
1261 tpsTransformItk->SetSourceLandmarks(sourceLandmarksItk_Lps);
1262 tpsTransformItk->SetTargetLandmarks(targetLandmarksItk_Lps);
1265 tpsTransformItk->ComputeWMatrix();
1267 transformItk_LPS = tpsTransformItk;
1274 template <
typename T>
1276 vtkObject* loggerObject,
1277 typename itk::TransformBaseTemplate<T>::Pointer transformItk)
1279 bool conversionSuccess =
false;
1282 vtkNew<vtkMatrix4x4> transformMatrixVtk;
1283 conversionSuccess = SetVTKLinearTransformFromITK<T>(loggerObject, transformMatrixVtk.GetPointer(), transformItk);
1284 std::cout <<
"CreateVTKTransformFromITK - SetVTKLinearTransformFromITK conversionSuccess:" << conversionSuccess << std::endl;
1285 if (conversionSuccess)
1287 vtkNew<vtkTransform> linearTransformVtk;
1288 linearTransformVtk->SetMatrix(transformMatrixVtk.GetPointer());
1289 linearTransformVtk->Register(NULL);
1290 return linearTransformVtk.GetPointer();
1293 vtkNew<vtkOrientedGridTransform> gridTransformVtk;
1294 conversionSuccess = SetVTKOrientedGridTransformFromITK<T>(loggerObject, gridTransformVtk.GetPointer(), transformItk);
1295 if (conversionSuccess)
1297 gridTransformVtk->Register(NULL);
1298 return gridTransformVtk.GetPointer();
1301 vtkNew<vtkOrientedBSplineTransform> bsplineTransformVtk;
1302 conversionSuccess = SetVTKBSplineFromITKv4Generic<T>(loggerObject, bsplineTransformVtk.GetPointer(), transformItk);
1303 if (conversionSuccess)
1305 bsplineTransformVtk->Register(NULL);
1306 return bsplineTransformVtk.GetPointer();
1309 vtkNew<vtkThinPlateSplineTransform> tpsTransformVtk;
1310 conversionSuccess = SetVTKThinPlateSplineTransformFromITK<T>(loggerObject, tpsTransformVtk.GetPointer(), transformItk);
1311 if (conversionSuccess)
1313 tpsTransformVtk->Register(NULL);
1314 return tpsTransformVtk.GetPointer();
1322 vtkAbstractTransform* transformVtk, itk::Object::Pointer& secondaryTransformItk,
int preferITKv3CompatibleTransforms,
bool initialize )
1324 typedef itk::CompositeTransform< double > CompositeTransformType;
1326 if (transformVtk==NULL)
1328 vtkErrorWithObjectMacro(loggerObject,
"CreateITKTransformFromVTK failed: invalid VTK transform");
1331 vtkNew<vtkCollection> transformList;
1333 if (transformList->GetNumberOfItems()==0)
1336 vtkNew<vtkTransform> identity;
1337 transformList->AddItem(identity.GetPointer());
1340 itk::Object::Pointer primaryTransformItk;
1341 if (transformList->GetNumberOfItems()==1)
1344 vtkObject* singleTransformVtk = transformList->GetItemAsObject(0);
1346 if (vtkHomogeneousTransform::SafeDownCast(singleTransformVtk))
1348 vtkHomogeneousTransform* linearTransformVtk = vtkHomogeneousTransform::SafeDownCast(singleTransformVtk);
1349 vtkMatrix4x4* transformMatrix = linearTransformVtk->GetMatrix();
1355 return primaryTransformItk;
1362 if (preferITKv3CompatibleTransforms || (bulkMatrix!=NULL && !
IsIdentityMatrix(bulkMatrix)))
1364 if (!
SetITKv3BSplineFromVTK(loggerObject, primaryTransformItk, secondaryTransformItk, bsplineTransformVtk, preferITKv3CompatibleTransforms))
1369 return primaryTransformItk;
1378 return primaryTransformItk;
1390 return primaryTransformItk;
1393 else if (vtkThinPlateSplineTransform::SafeDownCast(singleTransformVtk))
1395 vtkThinPlateSplineTransform* tpsTransformVtk = vtkThinPlateSplineTransform::SafeDownCast(singleTransformVtk);
1401 return primaryTransformItk;
1405 if (singleTransformVtk==NULL)
1407 vtkErrorWithObjectMacro(loggerObject,
"vtkITKTransformConverter::CreateITKTransformFromVTK failed: invalid input transform");
1410 vtkErrorWithObjectMacro(loggerObject,
"vtkITKTransformConverter::CreateITKTransformFromVTK failed: conversion of transform type "<<singleTransformVtk->GetClassName()<<
" is not supported");
1418 CompositeTransformType::Pointer compositeTransformItk = CompositeTransformType::New();
1419 primaryTransformItk = compositeTransformItk;
1421 for (
int transformIndex = transformList->GetNumberOfItems()-1; transformIndex>=0; --transformIndex)
1423 vtkAbstractTransform* singleTransformVtk = vtkAbstractTransform::SafeDownCast(transformList->GetItemAsObject(transformIndex));
1424 itk::Object::Pointer secondaryTransformItk;
1428 itk::Object::Pointer singleTransformItk =
CreateITKTransformFromVTK(loggerObject, singleTransformVtk, secondaryTransformItk,
false );
1429 if (secondaryTransformItk.IsNotNull())
1431 vtkErrorWithObjectMacro(loggerObject,
"vtkITKTransformConverter::CreateITKTransformFromVTK failed: composite transforms cannot contain legacy transforms (that contains secondary transforms). Do not harden transforms on legacy ITK transforms to avoid this error.");
1435 if (singleTransformItk.IsNull()
1436 || std::string(singleTransformItk->GetNameOfClass()).find(
"Transform") == std::string::npos)
1438 vtkErrorWithObjectMacro(loggerObject,
"vtkITKTransformConverter::CreateITKTransformFromVTK failed: invalid element found while trying to create a composite transform");
1441 CompositeTransformType::TransformType::Pointer singleTransformItkTypeChecked =
static_cast< CompositeTransformType::TransformType*
>( singleTransformItk.GetPointer() );
1442 compositeTransformItk->AddTransform(singleTransformItkTypeChecked.GetPointer());
1444 return primaryTransformItk;
1449 #endif // __vtkITKTransformConverter_h
itk::AffineTransform< TransformRealType, 3 > AffineTransformType