From: Simon Rit Date: Thu, 19 Apr 2012 12:38:27 +0000 (+0200) Subject: Merge branch 'master' of git.creatis.insa-lyon.fr:clitk X-Git-Tag: v1.3.0~50^2^2 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=99a4e52ce46e7018a46e94ad4925858165463c1d;hp=ed41ccf46c1311c68d1cf4f0de95d17c07491af8;p=clitk.git Merge branch 'master' of git.creatis.insa-lyon.fr:clitk --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 4cd0dc9..0c65b28 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,3 +23,4 @@ ADD_SUBDIRECTORY(${CLITK_SOURCE_DIR}/common ${PROJECT_BINARY_DIR}/common) ADD_SUBDIRECTORY(${CLITK_SOURCE_DIR}/tools ${PROJECT_BINARY_DIR}/tools) ADD_SUBDIRECTORY(${CLITK_SOURCE_DIR}/segmentation ${PROJECT_BINARY_DIR}/segmentation) ADD_SUBDIRECTORY(${CLITK_SOURCE_DIR}/registration ${PROJECT_BINARY_DIR}/registration) +ADD_SUBDIRECTORY(${CLITK_SOURCE_DIR}/scripts ${PROJECT_BINARY_DIR}/scripts) diff --git a/cmake/build_opt.cmake b/cmake/build_opt.cmake index a8f10ee..d7c60aa 100644 --- a/cmake/build_opt.cmake +++ b/cmake/build_opt.cmake @@ -34,21 +34,3 @@ IF(BUILD_TESTING) ADD_SUBDIRECTORY(${CLITK_SOURCE_DIR}/tests ${PROJECT_BINARY_DIR}/tests) ENDIF(BUILD_TESTING) -#========================================================= -# Install scripts when running make install -SET(SCRIPTS - ${CLITK_SOURCE_DIR}/scripts/calculate_motion_amplitude.sh - ${CLITK_SOURCE_DIR}/scripts/midp_common.sh - ${CLITK_SOURCE_DIR}/scripts/registration.sh - ${CLITK_SOURCE_DIR}/scripts/create_midP.sh - ${CLITK_SOURCE_DIR}/scripts/create_midP-2.0.sh - ${CLITK_SOURCE_DIR}/scripts/create_mhd_4D.sh - ${CLITK_SOURCE_DIR}/scripts/create_mhd_4D_pattern.sh - ${CLITK_SOURCE_DIR}/scripts/create_midP_masks.sh - ${CLITK_SOURCE_DIR}/scripts/create_midP_masks-2.0.sh - ${CLITK_SOURCE_DIR}/scripts/pts_to_landmarks.sh - ${CLITK_SOURCE_DIR}/scripts/create_mhd_3D.sh - ${CLITK_SOURCE_DIR}/scripts/dicom_info.sh -) - -INSTALL (FILES ${SCRIPTS} DESTINATION bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE) 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/scripts/CMakeLists.txt b/scripts/CMakeLists.txt new file mode 100644 index 0000000..41ace96 --- /dev/null +++ b/scripts/CMakeLists.txt @@ -0,0 +1,19 @@ +#========================================================= +# Install scripts when running make install +SET(SCRIPTS + ${CLITK_SOURCE_DIR}/scripts/calculate_motion_amplitude.sh + ${CLITK_SOURCE_DIR}/scripts/calculate_contour_stats.sh + ${CLITK_SOURCE_DIR}/scripts/midp_common.sh + ${CLITK_SOURCE_DIR}/scripts/registration.sh + ${CLITK_SOURCE_DIR}/scripts/create_midP.sh + ${CLITK_SOURCE_DIR}/scripts/create_midP-2.0.sh + ${CLITK_SOURCE_DIR}/scripts/create_mhd_4D.sh + ${CLITK_SOURCE_DIR}/scripts/create_mhd_4D_pattern.sh + ${CLITK_SOURCE_DIR}/scripts/create_midP_masks.sh + ${CLITK_SOURCE_DIR}/scripts/create_midP_masks-2.0.sh + ${CLITK_SOURCE_DIR}/scripts/pts_to_landmarks.sh + ${CLITK_SOURCE_DIR}/scripts/create_mhd_3D.sh + ${CLITK_SOURCE_DIR}/scripts/dicom_info.sh +) + +INSTALL (FILES ${SCRIPTS} DESTINATION bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE) diff --git a/scripts/calculate_contour_stats.sh b/scripts/calculate_contour_stats.sh new file mode 100755 index 0000000..b15caa8 --- /dev/null +++ b/scripts/calculate_contour_stats.sh @@ -0,0 +1,121 @@ +#! /bin/bash +x + +select_contour_gui() +{ + local roi_list=$@ + roi=`zenity --list --title="Available Contours" --column="Please choose a contour:" $roi_list` + case $? in + 0) + if [ -z $roi ] + then + zenity --warning --text="You must choose one contour." + select_contour $roi_list + else + rtstruct_roi_name=$roi + fi;; + 1) + if zenity --question --text="Do you really wish to quit?" + then + exit + else + select_contour $roi_list + fi;; + -1) + zenity --error --text="Unexpected error. Please relaunch the application." + exit;; + esac +} + +select_contour() +{ + local roi_list=$@ + echo "Available Contours:" + for r in $roi_list; do + echo $r + done + + echo "Please choose a contour number:" + read rtstruct_roi_number +} + +select_roi() +{ + rtstruct_roi_name_list=( `clitkDicomInfo ${rtstruct_file} | grep "3006|0026" | cut -d '[' -f 4 | sed 's/| V 3006|0026[LO] [ROI Name] \|]//'` ) + rtstruct_roi_number_list=( `clitkDicomInfo ${rtstruct_file} | grep "3006|0022" | cut -d '[' -f 4 | sed 's/| V 3006|0026[LO] [ROI Number] \|]//'` ) + rtstruct_roi_list=( ) + for i in $(seq 0 1 $(( ${#rtstruct_roi_name_list[@]} - 1 ))); do + rtstruct_roi_list[$i]=${rtstruct_roi_number_list[$i]}:${rtstruct_roi_name_list[$i]} + done + + if [ $gui_mode = 1 ]; then + select_contour_gui ${rtstruct_roi_list[@]} + rtstruct_roi=`echo ${rtstruct_roi_name} | cut -d ':' -f 1` + rtstruct_roi_name=`echo ${rtstruct_roi_name} | cut -d ':' -f 2` + else + select_contour ${rtstruct_roi_list[@]} + rtstruct_roi=$rtstruct_roi_number + rtstruct_roi_name=${rtstruct_roi_name_list[$(( $rtstruct_roi_number - 1))]} + fi +} + +############# main + +if echo $* | grep "\-h"; then + echo Usage: calculate_motion_amplitude.sh { RTSTRUCT_FILE REFERENCE_IMAGE | --gui } + + exit 0 +fi + + +rtstruct_roi=0 + +if echo $* | grep "\-\-gui" > /dev/null 2>&1; then + if [ $# != 1 ]; then + echo Invalid arguments. Type \'`basename $0` -h\' for help + exit -1 + fi + + gui_mode=1 + rtstruct_file=`zenity --file-selection --title="Select RT Struct file."` + select_roi + rtstruct_ref_image=`zenity --file-selection --title="Select Reference Image."` +else + if [ $# != 2 ]; then + echo Invalid arguments. Type \'`basename $0` -h\' for help + exit -1 + fi + + gui_mode=0 + rtstruct_file=$1 + rtstruct_ref_image=$2 + select_roi +fi + + +#echo "Processing \"${rtstruct_roi_list[$roi_struct]}\"..." +# create ROI mask from rtstruct +roi_mask=roi_${rtstruct_roi_name}.mhd +clitkDicomRTStruct2Image -i ${rtstruct_file} -o ${roi_mask} -j ${rtstruct_ref_image} -r ${rtstruct_roi} 2> /tmp/err.txt +if cat /tmp/err.txt | grep -q "No ROI"; then + echo Invalid contour number. + exit -3 +fi + +# guarantees the same sampling for roi mask and vector image +roi_mask2=resampled_${roi_mask} +clitkResampleImage -i ${roi_mask} -o ${roi_mask2} --like ${rtstruct_ref_image} + +# calculate stats +clitkImageStatistics -i ${rtstruct_ref_image} -m ${roi_mask2} --verbose 2> /dev/null | tail -n 8 > /tmp/result.txt + +if [ $gui_mode = 1 ]; then + cat /tmp/result.txt | zenity --text-info --title "Restuls for \"${rtstruct_roi_name}\"" +else + echo "Restuls for \"${rtstruct_roi_name}\"" + cat /tmp/result.txt +fi + +rm `basename $roi_mask .mhd`.{mhd,raw} +rm `basename $roi_mask2 .mhd`.{mhd,raw} +rm /tmp/err.txt +rm /tmp/result.txt 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; diff --git a/vv/vvSlicer.cxx b/vv/vvSlicer.cxx index d2a6ba7..714d3d9 100644 --- a/vv/vvSlicer.cxx +++ b/vv/vvSlicer.cxx @@ -1241,8 +1241,14 @@ double vvSlicer::GetScalarComponentAsDouble(vtkImageData *image, double X, doubl //---------------------------------------------------------------------------- void vvSlicer::Render() { - if (this->GetWindowLevel()->GetLookupTable() && !this->mOverlay && !this->mFusion) { + if (this->mFusion) { + legend->SetLookupTable(this->GetFusionMapper()->GetLookupTable()); + legend->UseOpacityOn(); + legend->SetVisibility(1); + } + else if (this->GetWindowLevel()->GetLookupTable()) {// && !this->mOverlay && !this->mFusion) { legend->SetLookupTable(this->GetWindowLevel()->GetLookupTable()); + legend->UseOpacityOff(); legend->SetVisibility(1); } else legend->SetVisibility(0); diff --git a/vv/vvSlicerManager.cxx b/vv/vvSlicerManager.cxx index d9ed42e..2373aba 100644 --- a/vv/vvSlicerManager.cxx +++ b/vv/vvSlicerManager.cxx @@ -1236,15 +1236,17 @@ void vvSlicerManager::SetColorMap(int colormap) double v[4]; // set color table transparency + double alpha_range=(double)mFusionThresOpacity/10; double range_end = frange[0] + (double)mFusionThresOpacity*(frange[1] - frange[0])/100; - double curr_value = frange[0]; + double curr_value = fusRange[0]; int nvalues = fusLUT->GetNumberOfTableValues(); - //for (double i = frange[0]; i <= alpha_range_end; i++) { for (double i = 0; curr_value < range_end; i++) { fusLUT->GetTableValue(i, v); v[3] = 0; + //if (curr_value >= -alpha_range && curr_value <= alpha_range) v[3] = pow(fabs(curr_value/alpha_range),2); + //else v[3] = 1; fusLUT->SetTableValue(i, v); - curr_value += (frange[1] - frange[0])/nvalues; + curr_value += (fusRange[1] - fusRange[0])/nvalues; } } for ( unsigned int i = 0; i < mSlicers.size(); i++) {