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=5c5fc58e0cbdcec1c9fdd19ec786912cb38d1722;p=clitk.git Merge branch 'master' of tux.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/cmake/dependencies.cmake b/cmake/dependencies.cmake index ebf076f..0654697 100644 --- a/cmake/dependencies.cmake +++ b/cmake/dependencies.cmake @@ -13,7 +13,7 @@ ENDIF(ITK_FOUND) FIND_PACKAGE(VTK REQUIRED) IF(VTK_FOUND) INCLUDE("${VTK_USE_FILE}") - IF(VTK_VERSION VERSION_LESS 5.6.0) + IF(VTK_VERSION VERSION_LESS 5.8.0) SET ( VTK_LIBRARIES vtkCommon vtkRendering @@ -23,8 +23,13 @@ IF(VTK_FOUND) vtkWidgets vtkImaging vtkHybrid - vtkQVTK ) + ENDIF(VTK_VERSION VERSION_LESS 5.8.0) + IF(VTK_VERSION VERSION_LESS 5.6.0) + SET ( VTK_LIBRARIES + ${VTK_LIBRARIES} + vtkQVTK + ) ENDIF(VTK_VERSION VERSION_LESS 5.6.0) ELSE(VTK_FOUND) MESSAGE(FATAL_ERROR "Please set VTK_DIR.") 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/vv/vvImageContour.cxx b/vv/vvImageContour.cxx index e89f84b..8136248 100644 --- a/vv/vvImageContour.cxx +++ b/vv/vvImageContour.cxx @@ -160,7 +160,7 @@ void vvImageContour::SetDepth(double d) int orientation = ComputeCurrentOrientation(); position[orientation] = -mDepth; - for(uint i=0; iSetPosition(position); } //------------------------------------------------------------------------------ diff --git a/vv/vvMainWindow.cxx b/vv/vvMainWindow.cxx index bbbb2d8..303ab3a 100644 --- a/vv/vvMainWindow.cxx +++ b/vv/vvMainWindow.cxx @@ -2779,19 +2779,19 @@ void vvMainWindow::SaveScreenshot(QVTKWidget *widget) w2i->Update(); vtkImageData *image = w2i->GetOutput(); - const char *ext = fileName.toStdString().c_str() + strlen(fileName.toStdString().c_str()) - 4; + std::string ext(itksys::SystemTools::GetFilenameLastExtension(fileName.toStdString())); // Image vtkImageWriter *imgwriter = NULL; - if (!strcmp(ext, ".bmp")) + if (ext==".bmp") imgwriter = vtkBMPWriter::New(); - else if (!strcmp(ext, ".tif")) + else if (ext==".tif") imgwriter = vtkTIFFWriter::New(); - else if (!strcmp(ext, ".ppm")) + else if (ext==".ppm") imgwriter = vtkPNMWriter::New(); - else if (!strcmp(ext, ".png")) + else if (ext==".png") imgwriter = vtkPNGWriter::New(); - else if (!strcmp(ext, ".jpg")) + else if (ext==".jpg") imgwriter = vtkJPEGWriter::New(); // Snapshot image if not null @@ -2805,7 +2805,7 @@ void vvMainWindow::SaveScreenshot(QVTKWidget *widget) // Video vtkGenericMovieWriter *vidwriter = NULL; #if CLITK_EXPERIMENTAL == 1 - if (!strcmp(ext, ".gif")) { + if (ext==".gif") { vvAnimatedGIFWriter *gif = vvAnimatedGIFWriter::New(); vidwriter = gif; @@ -2824,7 +2824,7 @@ void vvMainWindow::SaveScreenshot(QVTKWidget *widget) } #endif #ifdef VTK_USE_VIDEO_FOR_WINDOWS - if (!strcmp(ext, ".avi")) { + if (ext==".avi") { vtkAVIWriter *mpg = vtkAVIWriter::New(); vidwriter = mpg; mpg->SetQuality(2); @@ -2837,7 +2837,7 @@ void vvMainWindow::SaveScreenshot(QVTKWidget *widget) } #endif #ifdef VTK_USE_FFMPEG_ENCODER - if (!strcmp(ext, ".avi")) { + if (ext==".avi") { vtkFFMPEGWriter *mpg = vtkFFMPEGWriter::New(); vidwriter = mpg; mpg->SetQuality(2); @@ -2851,7 +2851,7 @@ void vvMainWindow::SaveScreenshot(QVTKWidget *widget) } #endif #ifdef VTK_USE_MPEG2_ENCODER - if (!strcmp(ext, ".mpg")) { + if (ext==".mpg") { vtkMPEG2Writer *mpg = vtkMPEG2Writer::New(); vidwriter = mpg; } diff --git a/vv/vvSlicer.cxx b/vv/vvSlicer.cxx index 92cb268..714d3d9 100644 --- a/vv/vvSlicer.cxx +++ b/vv/vvSlicer.cxx @@ -817,10 +817,12 @@ void vvSlicer::UpdateDisplayExtent() // Local copy of extent int w_ext[6]; - copyExtent(GetExtent(), w_ext); + int* ext = GetExtent(); + copyExtent(ext, w_ext); // Set slice value - w_ext[ this->SliceOrientation*2 ] = this->Slice; - w_ext[ this->SliceOrientation*2+1 ] = this->Slice; + int s = this->Slice > ext[this->SliceOrientation*2+1] ? ext[this->SliceOrientation*2 + 1] : this->Slice; + w_ext[ this->SliceOrientation*2 ] = s; + w_ext[ this->SliceOrientation*2+1 ] = s; // Image actor this->ImageActor->SetDisplayExtent(w_ext); @@ -929,7 +931,8 @@ void vvSlicer::ConvertImageToImageDisplayExtent(vtkImageData *sourceImage, const dExtents[i] = (dExtents[i]- targetImage->GetOrigin()[i/2]) / targetImage->GetSpacing()[i/2]; // Round to nearest - targetExtent[i] = itk::Math::Round(dExtents[i]); + //targetExtent[i] = itk::Math::Round(dExtents[i]); + targetExtent[i] = itk::Math::Floor(dExtents[i]); } } //---------------------------------------------------------------------------- @@ -1238,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++) {