- matrix.SetIdentity();
- }
- if (m_Verbose)
- std::cout << "Using the following matrix:" << std::endl
- << matrix << std::endl;
- typename itk::Matrix<double, Dimension, Dimension> rotationMatrix = clitk::GetRotationalPartMatrix(matrix);
- typename itk::Vector<double, Dimension> translationPart = clitk::GetTranslationPartMatrix(matrix);
-
- // Transform
- typedef itk::AffineTransform<double, Dimension> AffineTransformType;
- typename AffineTransformType::Pointer affineTransform=AffineTransformType::New();
- affineTransform->SetMatrix(rotationMatrix);
- affineTransform->SetTranslation(translationPart);
-
- // Interp
- typedef clitk::GenericInterpolator<args_info_type, InputImageType, double> GenericInterpolatorType;
- typename GenericInterpolatorType::Pointer genericInterpolator=GenericInterpolatorType::New();
- genericInterpolator->SetArgsInfo(m_ArgsInfo);
-
- // Properties
- if (m_ArgsInfo.like_given) {
- typename InputReaderType::Pointer likeReader=InputReaderType::New();
- likeReader->SetFileName(m_ArgsInfo.like_arg);
- likeReader->Update();
- resampler->SetOutputParametersFromImage(likeReader->GetOutput());
- } else if(m_ArgsInfo.transform_grid_flag) {
- typename itk::Matrix<double, Dimension+1, Dimension+1> invMatrix( matrix.GetInverse() );
- typename itk::Matrix<double, Dimension, Dimension> invRotMatrix( clitk::GetRotationalPartMatrix(invMatrix) );
- typename itk::Vector<double,Dimension> invTrans = clitk::GetTranslationPartMatrix(invMatrix);
-
- // Spacing is influenced by affine transform matrix and input direction
- typename InputImageType::SpacingType outputSpacing;
- outputSpacing = invRotMatrix *
- input->GetDirection() *
- input->GetSpacing();
-
- // Origin is influenced by translation but not by input direction
- typename InputImageType::PointType outputOrigin;
- outputOrigin = invRotMatrix *
- input->GetOrigin() +
- invTrans;
-
- // Size is influenced by affine transform matrix and input direction
- // Size is converted to double, transformed and converted back to size type.
- vnl_vector<double> vnlOutputSize(Dimension);
- for(unsigned int i=0; i< Dimension; i++) {
- vnlOutputSize[i] = input->GetLargestPossibleRegion().GetSize()[i];
- }
- vnlOutputSize = invRotMatrix *
- input->GetDirection().GetVnlMatrix() *
- vnlOutputSize;
- typename OutputImageType::SizeType outputSize;
- for(unsigned int i=0; i< Dimension; i++) {
- // If the size is negative, we have a flip and we must modify
- // the origin and the spacing accordingly.
- if(vnlOutputSize[i]<0.) {
- vnlOutputSize[i] *= -1.;
- outputOrigin[i] = outputOrigin[i] + outputSpacing[i] * (vnlOutputSize[i]-1);
- outputSpacing[i] *= -1.;
+ {
+ if (m_ArgsInfo.matrix_given)
+ {
+ matrix= clitk::ReadMatrix<Dimension>(m_ArgsInfo.matrix_arg);
+ if (m_Verbose) std::cout << "Reading the matrix..." << std::endl;
+ }
+ else {
+ if (m_ArgsInfo.elastix_given) {
+ std::string filename(m_ArgsInfo.elastix_arg);
+ matrix = createMatrixFromElastixFile<Dimension>(filename, m_Verbose);
+ }
+ else
+ matrix.SetIdentity();
+ }
+ }
+ if (m_Verbose)
+ std::cout << "Using the following matrix:" << std::endl
+ << matrix << std::endl;
+ typename itk::Matrix<double, Dimension, Dimension> rotationMatrix = clitk::GetRotationalPartMatrix(matrix);
+ typename itk::Vector<double, Dimension> translationPart = clitk::GetTranslationPartMatrix(matrix);
+
+ // Transform
+ typedef itk::AffineTransform<double, Dimension> AffineTransformType;
+ typename AffineTransformType::Pointer affineTransform=AffineTransformType::New();
+ affineTransform->SetMatrix(rotationMatrix);
+ affineTransform->SetTranslation(translationPart);
+
+ // Interp
+ typedef clitk::GenericInterpolator<args_info_type, InputImageType, double> GenericInterpolatorType;
+ typename GenericInterpolatorType::Pointer genericInterpolator=GenericInterpolatorType::New();
+ genericInterpolator->SetArgsInfo(m_ArgsInfo);
+
+ // Properties
+ if (m_ArgsInfo.like_given) {
+ typename InputReaderType::Pointer likeReader=InputReaderType::New();
+ likeReader->SetFileName(m_ArgsInfo.like_arg);
+ likeReader->Update();
+ resampler->SetOutputParametersFromImage(likeReader->GetOutput());
+ resampler->SetOutputDirection(likeReader->GetOutput()->GetDirection());
+ } else if(m_ArgsInfo.transform_grid_flag) {
+ typename itk::Matrix<double, Dimension+1, Dimension+1> invMatrix( matrix.GetInverse() );
+ typename itk::Matrix<double, Dimension, Dimension> invRotMatrix( clitk::GetRotationalPartMatrix(invMatrix) );
+ typename itk::Vector<double,Dimension> invTrans = clitk::GetTranslationPartMatrix(invMatrix);
+
+ // Display warning
+ if (m_ArgsInfo.spacing_given)
+ std::cout << "Warning --spacing ignored (because --transform_grid_flag)" << std::endl;
+ if (m_ArgsInfo.origin_given)
+ std::cout << "Warning --origin ignored (because --transform_grid_flag)" << std::endl;
+
+ // Spacing is influenced by affine transform matrix and input direction
+ typename InputImageType::SpacingType outputSpacing;
+ outputSpacing = invRotMatrix *
+ input->GetDirection() *
+ input->GetSpacing();
+
+ // Origin is influenced by translation but not by input direction
+ typename InputImageType::PointType outputOrigin;
+ outputOrigin = invRotMatrix *
+ input->GetOrigin() +
+ invTrans;
+
+ // Size is influenced by affine transform matrix and input direction
+ // Size is converted to double, transformed and converted back to size type.
+ vnl_vector<double> vnlOutputSize(Dimension);
+ for(unsigned int i=0; i< Dimension; i++) {
+ vnlOutputSize[i] = input->GetLargestPossibleRegion().GetSize()[i];