From: Vivien Delmon Date: Wed, 18 Apr 2012 16:08:33 +0000 (+0200) Subject: Merge branch 'master' of tux.creatis.insa-lyon.fr:clitk X-Git-Tag: v1.3.0~52 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=5b295ccf11ca86439090302e4f8836c7118ffcc3;hp=1d97c744a9d7726cbd8c64ee22b17d10c3820d3e;p=clitk.git Merge branch 'master' of tux.creatis.insa-lyon.fr:clitk --- diff --git a/common/clitkTransformUtilities.cxx b/common/clitkTransformUtilities.cxx index 069fc70..ef210d7 100644 --- a/common/clitkTransformUtilities.cxx +++ b/common/clitkTransformUtilities.cxx @@ -21,6 +21,22 @@ namespace clitk { +//-------------------------------------------------------------------- +template < > +itk::Matrix +GetForwardAffineMatrix<2>(itk::Array transformParameters) +{ + return GetForwardAffineMatrix2D(transformParameters); +} + +//-------------------------------------------------------------------- +template < > +itk::Matrix +GetForwardAffineMatrix<3>(itk::Array transformParameters) +{ + return GetForwardAffineMatrix3D(transformParameters); +} + //-------------------------------------------------------------------- template < > itk::Matrix @@ -37,4 +53,18 @@ GetBackwardAffineMatrix<3>(itk::Array transformParameters) return GetBackwardAffineMatrix3D(transformParameters); } +//-------------------------------------------------------------------- +template <> +itk::Matrix GetRotationMatrix<2>(itk::Array rotationParameters) +{ + return GetRotationMatrix2D(rotationParameters); +} + +//-------------------------------------------------------------------- +template <> +itk::Matrix GetRotationMatrix<3>(itk::Array rotationParameters) +{ + return GetRotationMatrix3D(rotationParameters); +} + } diff --git a/common/clitkTransformUtilities.h b/common/clitkTransformUtilities.h index a6fdd8c..3bdf220 100644 --- a/common/clitkTransformUtilities.h +++ b/common/clitkTransformUtilities.h @@ -32,12 +32,15 @@ namespace clitk //============================================================================ itk::Matrix GetForwardAffineMatrix2D(itk::Array transformParameters); itk::Matrix GetForwardAffineMatrix3D(itk::Array transformParameters); + template itk::Matrix GetForwardAffineMatrix(itk::Array transformParameters); itk::Matrix GetBackwardAffineMatrix2D(itk::Array transformParameters); itk::Matrix GetBackwardAffineMatrix3D(itk::Array transformParameters); template itk::Matrix GetBackwardAffineMatrix(itk::Array transformParameters); itk::Matrix GetRotationMatrix3D(itk::Array rotationParameters); + itk::Matrix GetRotationMatrix2D(itk::Array rotationParameters); + template itk::Matrix GetRotationMatrix(itk::Array rotationParameters); itk::Point GetRotatedPoint3D(itk::Array rotationParameters, itk::Point input); itk::Matrix GetCenteredRotationMatrix3D(itk::Array rotationParameters,itk::Point centerOfRotation); // itk::Matrix GetComposedMatrix3D(itk::Matrix firstTransform, itk::Matrix secondTransform); @@ -166,9 +169,17 @@ namespace clitk matrix[2][2]= cos(rotationParameters[0])*cos(rotationParameters[1]); return matrix; } - - - + + inline itk::Matrix GetRotationMatrix2D(itk::Array rotationParameters) + { + itk::Matrix matrix; + matrix[0][0] = cos(rotationParameters[0]); + matrix[1][0] = sin(rotationParameters[0]); + matrix[0][1] = -matrix[1][0]; + matrix[1][1] = matrix[0][0]; + return matrix; + } + //======================================================================================== inline itk::Point GetRotatedPoint3D(itk::Array rotationParameters, itk::Point input) { diff --git a/tools/clitkAffineTransform.ggo b/tools/clitkAffineTransform.ggo index 8eeb3fc..131ff8e 100644 --- a/tools/clitkAffineTransform.ggo +++ b/tools/clitkAffineTransform.ggo @@ -17,6 +17,8 @@ option "size" - "New output size if different from input" int no multiple option "spacing" - "New output spacing if different from input" double no multiple option "origin" - "New output origin if different from input" double no multiple option "matrix" m "Affine matrix (homogene) filename" string no +option "rotate" r "Rotation to apply (radians)" double no multiple +option "translate" t "Translation to apply (mm)" double no multiple option "pad" - "Edge padding value" double no default="0.0" section "Interpolation" diff --git a/tools/clitkAffineTransformGenericFilter.txx b/tools/clitkAffineTransformGenericFilter.txx index ef81fe2..ec9db09 100644 --- a/tools/clitkAffineTransformGenericFilter.txx +++ b/tools/clitkAffineTransformGenericFilter.txx @@ -135,16 +135,50 @@ AffineTransformGenericFilter::UpdateWithDimAndPixelType() // Matrix typename itk::Matrix matrix; - if (m_ArgsInfo.matrix_given) { - matrix= clitk::ReadMatrix(m_ArgsInfo.matrix_arg); - if (m_Verbose) std::cout<<"Reading the matrix..."< transformParameters(2 * Dimension); + int pos = 0; + if (Dimension == 2) + transformParameters[pos++] = m_ArgsInfo.rotate_arg[0]; + else + for (unsigned int i = 0; i < 3; i++) + transformParameters[pos++] = m_ArgsInfo.rotate_arg[i]; + for (unsigned int i = 0; i < Dimension && i < 3; i++) + transformParameters[pos++] = m_ArgsInfo.translate_arg[i]; + if (Dimension == 4) + { + matrix.SetIdentity(); + itk::Matrix tmp = GetForwardAffineMatrix3D(transformParameters); + for (unsigned int i = 0; i < 3; ++i) + for (unsigned int j = 0; j < 3; ++j) + matrix[i][j] = tmp[i][j]; + for (unsigned int i = 0; i < 3; ++i) + matrix[i][4] = tmp[i][3]; + } + else + matrix = GetForwardAffineMatrix(transformParameters); + } + else + { + if (m_ArgsInfo.matrix_given) + { + matrix= clitk::ReadMatrix(m_ArgsInfo.matrix_arg); + if (m_Verbose) std::cout << "Reading the matrix..." << std::endl; + } + else + matrix.SetIdentity(); } - if (m_Verbose) std::cout<<"Using the following matrix:"< rotationMatrix=clitk::GetRotationalPartMatrix(matrix); - typename itk::Vector translationPart= clitk::GetTranslationPartMatrix(matrix); + if (m_Verbose) + std::cout << "Using the following matrix:" << std::endl + << matrix << std::endl; + typename itk::Matrix rotationMatrix = clitk::GetRotationalPartMatrix(matrix); + typename itk::Vector translationPart = clitk::GetTranslationPartMatrix(matrix); // Transform typedef itk::AffineTransform AffineTransformType; @@ -284,14 +318,50 @@ void AffineTransformGenericFilter::UpdateWithDimAndVectorType() // Matrix typename itk::Matrix matrix; - if (m_ArgsInfo.matrix_given) - matrix= clitk::ReadMatrix(m_ArgsInfo.matrix_arg); + if (m_ArgsInfo.rotate_given || m_ArgsInfo.translate_given) + { + if (m_ArgsInfo.matrix_given) + { + std::cerr << "You must use either rotate/translate or matrix options" << std::cout; + return; + } + itk::Array transformParameters(2 * Dimension); + int pos = 0; + if (Dimension == 2) + transformParameters[pos++] = m_ArgsInfo.rotate_arg[0]; + else + for (unsigned int i = 0; i < 3; i++) + transformParameters[pos++] = m_ArgsInfo.rotate_arg[i]; + for (unsigned int i = 0; i < Dimension && i < 3; i++) + transformParameters[pos++] = m_ArgsInfo.translate_arg[i]; + if (Dimension == 4) + { + matrix.SetIdentity(); + itk::Matrix tmp = GetForwardAffineMatrix3D(transformParameters); + for (unsigned int i = 0; i < 3; ++i) + for (unsigned int j = 0; j < 3; ++j) + matrix[i][j] = tmp[i][j]; + for (unsigned int i = 0; i < 3; ++i) + matrix[i][4] = tmp[i][3]; + } + else + matrix = GetForwardAffineMatrix(transformParameters); + } else - matrix.SetIdentity(); - if (m_Verbose) std::cout<<"Using the following matrix:"< rotationMatrix=clitk::GetRotationalPartMatrix(matrix); - typename itk::Vector translationPart= clitk::GetTranslationPartMatrix(matrix); + { + if (m_ArgsInfo.matrix_given) + { + matrix= clitk::ReadMatrix(m_ArgsInfo.matrix_arg); + if (m_Verbose) std::cout << "Reading the matrix..." << std::endl; + } + else + matrix.SetIdentity(); + } + if (m_Verbose) + std::cout << "Using the following matrix:" << std::endl + << matrix << std::endl; + typename itk::Matrix rotationMatrix = clitk::GetRotationalPartMatrix(matrix); + typename itk::Vector translationPart = clitk::GetTranslationPartMatrix(matrix); // Transform typedef itk::AffineTransform AffineTransformType;