From 9284f78523ef4469d086d04c1bcd791ce00575d1 Mon Sep 17 00:00:00 2001 From: schaerer Date: Tue, 9 Feb 2010 10:27:54 +0000 Subject: [PATCH] cleanup / better handling of errors --- common/clitkImageCommon.cxx | 12 ++++++++++-- common/clitkImageCommon.h | 2 +- common/clitkTransformUtilities.h | 2 +- common/{ => old}/clitkIOCommon.cxx | 14 +++++++++++--- common/{ => old}/clitkIOCommon.h | 0 common/{ => old}/clitkIOCommon.txx | 0 fast_make.sh | 5 +++-- itk/clitkForwardWarpImageFilter.h | 2 +- itk/clitkForwardWarpImageFilter.txx | 2 +- itk/clitkGenericInterpolator.h | 2 +- itk/clitkGenericVectorInterpolator.h | 2 +- itk/clitkInvertVFFilter.h | 2 +- tools/clitkSignalFilter.cxx | 2 +- tools/clitkSignalMeanPositionTracking.cxx | 2 +- tools/clitkVFMerge.cxx | 2 +- tools/clitkZeroVF.cxx | 2 +- tools/clitkZeroVFGenericFilter.h | 2 +- vv/vvMainWindow.cxx | 6 +++--- vv/vvQProgressDialogITKCommand.cxx | 2 +- 19 files changed, 40 insertions(+), 23 deletions(-) rename common/{ => old}/clitkIOCommon.cxx (94%) rename common/{ => old}/clitkIOCommon.h (100%) rename common/{ => old}/clitkIOCommon.txx (100%) diff --git a/common/clitkImageCommon.cxx b/common/clitkImageCommon.cxx index 056df94..cc21199 100644 --- a/common/clitkImageCommon.cxx +++ b/common/clitkImageCommon.cxx @@ -78,10 +78,18 @@ gdcm::File * clitk::readDicomHeader(const std::string & filename, //-------------------------------------------------------------------- //-------------------------------------------------------------------- -itk::ImageIOBase::Pointer clitk::readImageHeader(const std::string & filename) { +itk::ImageIOBase::Pointer clitk::readImageHeader(const std::string & filename, bool exit_on_error) { itk::ImageIOBase::Pointer reader = itk::ImageIOFactory::CreateImageIO(filename.c_str(), itk::ImageIOFactory::ReadMode); - if (!reader) return NULL; + if (!reader) { + if (exit_on_error) //default behavior for tools who don't handle the problem + { + std::cerr << "Error reading file " << filename << ", exiting immediately" << std::endl; + std::exit(-1); + } + else + return NULL; + } reader->SetFileName(filename); reader->ReadImageInformation(); return reader; diff --git a/common/clitkImageCommon.h b/common/clitkImageCommon.h index 53e1be6..87d01de 100644 --- a/common/clitkImageCommon.h +++ b/common/clitkImageCommon.h @@ -56,7 +56,7 @@ namespace clitk { //-------------------------------------------------------------------- // Read/print image header - itk::ImageIOBase::Pointer readImageHeader(const std::string & filename); + itk::ImageIOBase::Pointer readImageHeader(const std::string & filename,bool exit_on_error=true); void printImageHeader(itk::ImageIOBase::Pointer header, std::ostream & os, const int level=0); //-------------------------------------------------------------------- diff --git a/common/clitkTransformUtilities.h b/common/clitkTransformUtilities.h index c8d100c..8a23f9b 100644 --- a/common/clitkTransformUtilities.h +++ b/common/clitkTransformUtilities.h @@ -4,7 +4,7 @@ #include "itkMatrix.h" #include "itkArray.h" #include "itkPoint.h" -#include "clitkIOCommon.h" +#include "clitkImageCommon.h" #include "clitkCommon.h" diff --git a/common/clitkIOCommon.cxx b/common/old/clitkIOCommon.cxx similarity index 94% rename from common/clitkIOCommon.cxx rename to common/old/clitkIOCommon.cxx index 16ec361..be69d37 100644 --- a/common/clitkIOCommon.cxx +++ b/common/old/clitkIOCommon.cxx @@ -28,7 +28,8 @@ PURPOSE. See the above copyright notices for more information. =================================================*/ // clitk include -#include "clitkIOCommon.h" +#include "clitkImageCommon.h" +#include //==================================================================== // Open a file for reading @@ -66,10 +67,17 @@ gdcm::File * clitk::readDicomHeader(const std::string & filename, //==================================================================== //==================================================================== -itk::ImageIOBase::Pointer clitk::readImageHeader(const std::string & filename) { +itk::ImageIOBase::Pointer clitk::readImageHeader(const std::string & filename, bool exit_on_error) { itk::ImageIOBase::Pointer reader = itk::ImageIOFactory::CreateImageIO(filename.c_str(), itk::ImageIOFactory::ReadMode); - if (!reader) return NULL; + if (!reader) + if (exit_on_error) //default behavior for tools who don't handle the problem + { + std::cerr "Error reading file " << filename << ", exiting immediately" << std::endl; + std::exit(-1); + } + else + return NULL; reader->SetFileName(filename); reader->ReadImageInformation(); return reader; diff --git a/common/clitkIOCommon.h b/common/old/clitkIOCommon.h similarity index 100% rename from common/clitkIOCommon.h rename to common/old/clitkIOCommon.h diff --git a/common/clitkIOCommon.txx b/common/old/clitkIOCommon.txx similarity index 100% rename from common/clitkIOCommon.txx rename to common/old/clitkIOCommon.txx diff --git a/fast_make.sh b/fast_make.sh index 471562c..9309c87 100755 --- a/fast_make.sh +++ b/fast_make.sh @@ -29,8 +29,9 @@ else #use all the available computing power by default cpus=$(( $(cat /proc/cpuinfo | grep -c ^processor) + 0 )) fi -make -j ${cpus} $@ & -make_pid=$(jobs -p %make) +nice -n12 ionice -c3 make -j ${cpus} $@ & +make_pid=$(jobs -p %nice) + #watch memory use to avoid crashes while ps $make_pid >>/dev/null do diff --git a/itk/clitkForwardWarpImageFilter.h b/itk/clitkForwardWarpImageFilter.h index a02c9e5..86b3330 100644 --- a/itk/clitkForwardWarpImageFilter.h +++ b/itk/clitkForwardWarpImageFilter.h @@ -2,7 +2,7 @@ #define __clitkForwardWarpImageFilter_h //clitk include -#include "clitkIOCommon.h" +#include "clitkImageCommon.h" //itk include #include "itkImageToImageFilter.h" diff --git a/itk/clitkForwardWarpImageFilter.txx b/itk/clitkForwardWarpImageFilter.txx index 9ea647e..165fe4f 100644 --- a/itk/clitkForwardWarpImageFilter.txx +++ b/itk/clitkForwardWarpImageFilter.txx @@ -2,7 +2,7 @@ #define __clitkForwardWarpImageFilter_txx #include "clitkForwardWarpImageFilter.h" -#include "clitkIOCommon.h" +#include "clitkImageCommon.h" // Put the helper classes in an anonymous namespace so that it is not // exposed to the user diff --git a/itk/clitkGenericInterpolator.h b/itk/clitkGenericInterpolator.h index 4ce15f6..d9adde9 100644 --- a/itk/clitkGenericInterpolator.h +++ b/itk/clitkGenericInterpolator.h @@ -2,7 +2,7 @@ #define __clitkGenericInterpolator_h //clitk include -#include "clitkIOCommon.h" +#include "clitkImageCommon.h" //itk include #include "itkNearestNeighborInterpolateImageFunction.h" diff --git a/itk/clitkGenericVectorInterpolator.h b/itk/clitkGenericVectorInterpolator.h index ffb7171..afeeb67 100644 --- a/itk/clitkGenericVectorInterpolator.h +++ b/itk/clitkGenericVectorInterpolator.h @@ -2,7 +2,7 @@ #define __clitkGenericVectorInterpolator_h //clitk include -#include "clitkIOCommon.h" +#include "clitkImageCommon.h" //itk include #include "itkVectorNearestNeighborInterpolateImageFunction.h" diff --git a/itk/clitkInvertVFFilter.h b/itk/clitkInvertVFFilter.h index 039dc91..947f157 100644 --- a/itk/clitkInvertVFFilter.h +++ b/itk/clitkInvertVFFilter.h @@ -2,7 +2,7 @@ #define __clitkInvertVFFilter_h //clitk include -#include "clitkIOCommon.h" +#include "clitkImageCommon.h" #include "itkImageToImageFilter.h" #include "itkImage.h" diff --git a/tools/clitkSignalFilter.cxx b/tools/clitkSignalFilter.cxx index 0ac3db4..0a833f3 100644 --- a/tools/clitkSignalFilter.cxx +++ b/tools/clitkSignalFilter.cxx @@ -28,7 +28,7 @@ #include "clitkSignalFilter_ggo.h" #include "clitkSignal.h" #include "clitkIO.h" -#include "clitkIOCommon.h" +#include "clitkImageCommon.h" int main(int argc, char * argv[]) { diff --git a/tools/clitkSignalMeanPositionTracking.cxx b/tools/clitkSignalMeanPositionTracking.cxx index ae6a5ec..e63e929 100644 --- a/tools/clitkSignalMeanPositionTracking.cxx +++ b/tools/clitkSignalMeanPositionTracking.cxx @@ -28,7 +28,7 @@ #include "clitkSignalMeanPositionTracking_ggo.h" #include "clitkSignalMeanPositionFilter.h" #include "clitkIO.h" -#include "clitkIOCommon.h" +#include "clitkImageCommon.h" int main(int argc, char * argv[]) { diff --git a/tools/clitkVFMerge.cxx b/tools/clitkVFMerge.cxx index fa0a75e..f8c072b 100644 --- a/tools/clitkVFMerge.cxx +++ b/tools/clitkVFMerge.cxx @@ -14,7 +14,7 @@ // clitk include #include "clitkVFMerge_ggo.h" #include "clitkIO.h" -#include "clitkIOCommon.h" +#include "clitkImageCommon.h" // itk include //#include "itkReadTransform.h" diff --git a/tools/clitkZeroVF.cxx b/tools/clitkZeroVF.cxx index ab1dc89..50a91e9 100644 --- a/tools/clitkZeroVF.cxx +++ b/tools/clitkZeroVF.cxx @@ -14,7 +14,7 @@ // clitk include #include "clitkZeroVF_ggo.h" #include "clitkIO.h" -#include "clitkIOCommon.h" +#include "clitkImageCommon.h" #include "clitkZeroVFGenericFilter.h" int main( int argc, char *argv[] ) diff --git a/tools/clitkZeroVFGenericFilter.h b/tools/clitkZeroVFGenericFilter.h index 8bde1ed..ba894cd 100644 --- a/tools/clitkZeroVFGenericFilter.h +++ b/tools/clitkZeroVFGenericFilter.h @@ -2,7 +2,7 @@ #define __clitkZeroVFGenericFilter_h //clitk include -#include "clitkIOCommon.h" +#include "clitkImageCommon.h" #include "clitkImageCommon.h" //itk include diff --git a/vv/vvMainWindow.cxx b/vv/vvMainWindow.cxx index 5473980..c252b6f 100644 --- a/vv/vvMainWindow.cxx +++ b/vv/vvMainWindow.cxx @@ -3,8 +3,8 @@ Program: vv Module: $RCSfile: vvMainWindow.cxx,v $ Language: C++ - Date: $Date: 2010/02/07 12:00:59 $ - Version: $Revision: 1.9 $ + Date: $Date: 2010/02/09 10:28:07 $ + Version: $Revision: 1.10 $ Author : Pierre Seroul (pierre.seroul@gmail.com) Copyright (C) 200COLUMN_IMAGE_NAME @@ -39,7 +39,7 @@ #include "vvProgressDialog.h" #include "vvQDicomSeriesSelector.h" #include "vvSlicerManager.h" -#include "clitkIOCommon.h" +#include "clitkImageCommon.h" #include "vvSlicer.h" #include "vvInteractorStyleNavigator.h" #include "vvImageWriter.h" diff --git a/vv/vvQProgressDialogITKCommand.cxx b/vv/vvQProgressDialogITKCommand.cxx index 089775c..44fe910 100644 --- a/vv/vvQProgressDialogITKCommand.cxx +++ b/vv/vvQProgressDialogITKCommand.cxx @@ -24,7 +24,7 @@ along with this program. If not, see . #ifndef VVQPROGRESSDIALOGITKCOMMAND_CXX #define VVQPROGRESSDIALOGITKCOMMAND_CXX -#include "clitkIOCommon.h" +#include "clitkImageCommon.h" #include "vvQProgressDialogITKCommand.h" //==================================================================== -- 2.47.1