From 14d6a55438749d14c04f32539b5bc76c6e0b97c8 Mon Sep 17 00:00:00 2001 From: David Sarrut Date: Mon, 8 Jul 2013 11:01:00 +0200 Subject: [PATCH] Add tool to convert Elastix param into matrix file --- tools/CMakeLists.txt | 6 ++++++ tools/clitkAffineTransformGenericFilter.h | 15 ++++++++------- tools/clitkAffineTransformGenericFilter.txx | 10 +++++----- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 1db0dcc..77f12f9 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -108,6 +108,12 @@ IF (CLITK_BUILD_TOOLS) TARGET_LINK_LIBRARIES(clitkAffineTransform clitkCommon ) SET(TOOLS_INSTALL ${TOOLS_INSTALL} clitkAffineTransform) + WRAP_GGO(clitkElastixTransformToMatrix_GGO_C clitkElastixTransformToMatrix.ggo) + ADD_EXECUTABLE(clitkElastixTransformToMatrix clitkElastixTransformToMatrix.cxx ${clitkElastixTransformToMatrix_GGO_C}) + TARGET_LINK_LIBRARIES(clitkElastixTransformToMatrix clitkCommon ) + SET(TOOLS_INSTALL ${TOOLS_INSTALL} clitkElastixTransformToMatrix) + + WRAP_GGO(clitkSetBackground_GGO_C clitkSetBackground.ggo) ADD_EXECUTABLE(clitkSetBackground clitkSetBackground.cxx clitkSetBackgroundGenericFilter.cxx ${clitkSetBackground_GGO_C}) TARGET_LINK_LIBRARIES(clitkSetBackground clitkCommon) diff --git a/tools/clitkAffineTransformGenericFilter.h b/tools/clitkAffineTransformGenericFilter.h index 6cd2a91..3950632 100644 --- a/tools/clitkAffineTransformGenericFilter.h +++ b/tools/clitkAffineTransformGenericFilter.h @@ -87,6 +87,11 @@ namespace clitk //---------------------------------------- void Update(); + template + static + typename itk::Matrix + createMatrixFromElastixFile(std::vector & filename, bool verbose=true); + protected: //---------------------------------------- @@ -103,13 +108,9 @@ namespace clitk template void UpdateWithDimAndPixelType(); template void UpdateWithDimAndVectorType(); - template - typename itk::Matrix - createMatrixFromElastixFile(std::vector & filename); - - bool GetElastixValueFromTag(std::ifstream & is, std::string tag, std::string & value); - void GetValuesFromValue(const std::string & s, - std::vector & values); + static bool GetElastixValueFromTag(std::ifstream & is, std::string tag, std::string & value); + static void GetValuesFromValue(const std::string & s, + std::vector & values); //---------------------------------------- // Data members diff --git a/tools/clitkAffineTransformGenericFilter.txx b/tools/clitkAffineTransformGenericFilter.txx index d3cd19e..03cf862 100644 --- a/tools/clitkAffineTransformGenericFilter.txx +++ b/tools/clitkAffineTransformGenericFilter.txx @@ -183,7 +183,7 @@ namespace clitk if (m_ArgsInfo.elastix_given) { std::vector s; for(uint i=0; i(s); + matrix = createMatrixFromElastixFile(s, m_Verbose); } else matrix.SetIdentity(); @@ -497,7 +497,7 @@ namespace clitk template template typename itk::Matrix - AffineTransformGenericFilter::createMatrixFromElastixFile(std::vector & filename) + AffineTransformGenericFilter::createMatrixFromElastixFile(std::vector & filename, bool verbose) { if (Dimension != 3) { FATAL("Only 3D yet" << std::endl); @@ -509,7 +509,7 @@ namespace clitk for(uint j=0; jSetParameters(p); - if (m_Verbose) { + if (verbose) { std::cout << "Rotation (deg) : " << rad2deg(p[0]) << " " << rad2deg(p[1]) << " " << rad2deg(p[2]) << std::endl; std::cout << "Center of rot (phy) : " << p[3] << " " << p[4] << " " << p[5] << std::endl; std::cout << "Translation (phy) : " << p[6] << " " << p[7] << " " << p[8] << std::endl; @@ -562,7 +562,7 @@ namespace clitk // Compose with previous if needed if (j!=0) { mat->Compose(previous); - if (m_Verbose) { + if (verbose) { std::cout << "Composed rotation (deg) : " << rad2deg(mat->GetAngleX()) << " " << rad2deg(mat->GetAngleY()) << " " << rad2deg(mat->GetAngleZ()) << std::endl; std::cout << "Composed center of rot (phy) : " << mat->GetCenter() << std::endl; std::cout << "Compsoed translation (phy) : " << mat->GetTranslation() << std::endl; -- 2.47.1