From c324c54e19ace253a5a8f318a0c44cb771cf50c6 Mon Sep 17 00:00:00 2001 From: schaerer Date: Tue, 9 Feb 2010 14:19:24 +0000 Subject: [PATCH] almost finished the work on multiple components --- common/clitkCommonGenericFilter.h | 9 +- common/clitkImageToImageGenericFilter.cxx | 81 +------------ common/clitkImageToImageGenericFilter.h | 22 ++-- common/clitkImageToImageGenericFilter.txx | 38 ++++++- fast_make.sh | 133 +++++++++++----------- filters/clitkSplitImageGenericFilter.cxx | 2 +- vv/vvToolBase.h | 9 +- 7 files changed, 126 insertions(+), 168 deletions(-) diff --git a/common/clitkCommonGenericFilter.h b/common/clitkCommonGenericFilter.h index a1bb8a3..4826263 100644 --- a/common/clitkCommonGenericFilter.h +++ b/common/clitkCommonGenericFilter.h @@ -3,8 +3,8 @@ Program: clitk Module: $RCSfile: clitkCommonGenericFilter.h,v $ Language: C++ - Date: $Date: 2010/02/08 15:45:17 $ - Version: $Revision: 1.2 $ + Date: $Date: 2010/02/09 14:19:28 $ + Version: $Revision: 1.3 $ Author : Joel Schaerer David Sarrut @@ -65,7 +65,8 @@ namespace clitk { public: typedef std::map*> MapOfPixelTypeToFunctionType; typedef std::map MapOfImageComponentsToFunctionType; - std::map mMapOfImageTypeToFunction; + typedef std::map MapOfImageDimensionToFunctionType; + MapOfImageDimensionToFunctionType mMapOfImageTypeToFunction; ImageTypesManager(FilterType * f) { mFilter = f; } virtual void DoIt(int dim, int ncomp, std::string pixelname) { @@ -75,7 +76,6 @@ namespace clitk { } template void AddNewDimensionAndPixelType() { - mFilter->AddImageType(Dim, GetTypeAsString()); typedef itk::Image,Dim> InputImageType; mMapOfImageTypeToFunction[Dim][NComp][ GetTypeAsString() ] = new GenericFilterFunctorWithDimAndPixelType(mFilter); @@ -83,7 +83,6 @@ namespace clitk { /// Specialization for NComp == 1 template void AddNewDimensionAndPixelType() { - mFilter->AddImageType(Dim, GetTypeAsString()); typedef itk::Image InputImageType; mMapOfImageTypeToFunction[Dim][1][ GetTypeAsString() ] = new GenericFilterFunctorWithDimAndPixelType(mFilter); diff --git a/common/clitkImageToImageGenericFilter.cxx b/common/clitkImageToImageGenericFilter.cxx index 0465b9b..835ab03 100644 --- a/common/clitkImageToImageGenericFilter.cxx +++ b/common/clitkImageToImageGenericFilter.cxx @@ -5,22 +5,11 @@ clitk::ImageToImageGenericFilterBase::ImageToImageGenericFilterBase(std::string n) :mIOVerbose(false) { mFilterName = n; - mListOfAllowedDimensions.clear(); - mListOfAllowedPixelTypes.clear(); mFailOnImageTypeError = true; } //-------------------------------------------------------------------- -//-------------------------------------------------------------------- -void clitk::ImageToImageGenericFilterBase::AddImageType(unsigned int d, std::string p) { - - mListOfAllowedDimensions.insert(d); - mListOfAllowedPixelTypes.insert(p); -} -//-------------------------------------------------------------------- - - //-------------------------------------------------------------------- void clitk::ImageToImageGenericFilterBase::SetInputFilenames(const std::vector & filenames) { mInputFilenames=filenames; @@ -146,42 +135,6 @@ void clitk::ImageToImageGenericFilterBase::SetInputVVImages (std::vector manages "; - for(std::set::const_iterator i=mListOfAllowedDimensions.begin(); - i!=mListOfAllowedDimensions.end(); i++) { - oss << *i << "D "; - } - oss << "images, with pixel types: "; - for(std::set::const_iterator i=mListOfAllowedPixelTypes.begin(); - i!=mListOfAllowedPixelTypes.end(); i++) { - oss << *i << " "; - } - oss << std::endl; - return oss.str(); -} -//-------------------------------------------------------------------- - - //-------------------------------------------------------------------- void clitk::ImageToImageGenericFilterBase::ImageTypeError() { std::cerr << "**Error** The filter <" << mFilterName << "> is not available for " << mDim << "D images with pixel=" - << mPixelTypeName << "." << std::endl; - std::cerr << "**Error** Allowed image dim: \t"; - for(std::set::const_iterator i=mListOfAllowedDimensions.begin(); - i!=mListOfAllowedDimensions.end(); i++) { - std::cerr << *i << "D "; - } - std::cerr << std::endl << "**Error** Allowed pixel types: \t"; - for(std::set::const_iterator i=mListOfAllowedPixelTypes.begin(); - i!=mListOfAllowedPixelTypes.end(); i++) { - std::cerr << *i << " "; - } - std::cerr << std::endl; + << mPixelTypeName << " and " + << mNbOfComponents << " component." << std::endl; + std::cerr << GetAvailableImageTypes(); exit(0); } //-------------------------------------------------------------------- diff --git a/common/clitkImageToImageGenericFilter.h b/common/clitkImageToImageGenericFilter.h index 64ac239..caf25f6 100644 --- a/common/clitkImageToImageGenericFilter.h +++ b/common/clitkImageToImageGenericFilter.h @@ -3,8 +3,8 @@ Program: clitk Module: $RCSfile: clitkImageToImageGenericFilter.h,v $ Language: C++ - Date: $Date: 2010/02/08 15:45:17 $ - Version: $Revision: 1.5 $ + Date: $Date: 2010/02/09 14:19:28 $ + Version: $Revision: 1.6 $ Author : Joel Schaerer David Sarrut @@ -85,16 +85,14 @@ namespace clitk { // Information on available image types void PrintAvailableImageTypes(); - std::string GetAvailableImageTypes(); - bool CheckDimension(unsigned int d); - bool CheckPixelType(std::string pt); + virtual std::string GetAvailableImageTypes() = 0; + + virtual bool CheckImageType(unsigned int dim,unsigned int ncomp, std::string pixeltype) = 0; + virtual bool CheckImageType() = 0; // Main function to call for using the filter. virtual bool Update() = 0; - // Use internally only (TO PUT PROTECTED !!!) - void AddImageType(unsigned int d, std::string p); - protected: /// Call this function to dispatch an output towards the correct sink template @@ -116,11 +114,6 @@ namespace clitk { std::vector mInputVVImages; std::vector mOutputVVImages; - std::set mListOfAllowedPixelTypes; - std::set mListOfAllowedDimensions; - bool CheckImageType(); - bool CheckDimension(); - bool CheckPixelType(); void ImageTypeError(); void SetImageTypeError(); bool mFailOnImageTypeError; @@ -142,6 +135,9 @@ namespace clitk { // Main function to call for using the filter. virtual bool Update(); + virtual bool CheckImageType(unsigned int dim,unsigned int ncomp, std::string pixeltype); + virtual bool CheckImageType(); + virtual std::string GetAvailableImageTypes(); protected: // Object that will manage the list of templatized function for diff --git a/common/clitkImageToImageGenericFilter.txx b/common/clitkImageToImageGenericFilter.txx index 253d421..f68ff21 100644 --- a/common/clitkImageToImageGenericFilter.txx +++ b/common/clitkImageToImageGenericFilter.txx @@ -3,8 +3,8 @@ Program: vv Module: $RCSfile: clitkImageToImageGenericFilter.txx,v $ Language: C++ - Date: $Date: 2010/02/08 15:45:17 $ - Version: $Revision: 1.2 $ + Date: $Date: 2010/02/09 14:19:28 $ + Version: $Revision: 1.3 $ Author : Joel Schaerer David Sarrut @@ -82,4 +82,38 @@ bool clitk::ImageToImageGenericFilter::Update() { return true; } //-------------------------------------------------------------------- +template +bool clitk::ImageToImageGenericFilter::CheckImageType(unsigned int dim,unsigned int ncomp, std::string pixeltype) +{ + return static_cast(mImageTypesManager->mMapOfImageTypeToFunction[dim][ncomp][pixeltype]); +} + +template +bool clitk::ImageToImageGenericFilter::CheckImageType() +{ + return static_cast(mImageTypesManager->mMapOfImageTypeToFunction[mDim][mNbOfComponents][mPixelTypeName]); +} + +template +std::string clitk::ImageToImageGenericFilter::GetAvailableImageTypes() { + std::ostringstream oss; + oss << "The filter <" << mFilterName << "> manages:" << std::endl; + + typedef typename ImageTypesManager::MapOfImageComponentsToFunctionType::const_iterator MCompItType; + typedef typename ImageTypesManager::MapOfImageDimensionToFunctionType::const_iterator MDimItType; + typedef typename ImageTypesManager::MapOfPixelTypeToFunctionType::const_iterator MPixelItType; + for (MDimItType i=mImageTypesManager->mMapOfImageTypeToFunction.begin(); + i!=mImageTypesManager->mMapOfImageTypeToFunction.end(); + i++) { + for (MCompItType j=(*i).second.begin(); j!= (*i).second.end(); j++) { + for (MPixelItType k=(*j).second.begin(); k!= (*j).second.end(); k++) { + oss << "Dim: " << (*i).first + << ", Components: " << (*j).first + << ", Type: " << (*k).first << std::endl; + } + } + } + return oss.str(); +} +//-------------------------------------------------------------------- diff --git a/fast_make.sh b/fast_make.sh index 9309c87..249ca5e 100755 --- a/fast_make.sh +++ b/fast_make.sh @@ -1,70 +1,73 @@ #!/bin/bash vv_dir=$(dirname $(readlink -e $(which $0))) -echo vv directory: $vv_dir +echo clitk3 directory: $vv_dir cd ${vv_dir}/build -function handle_exit -{ - rm mem_use 2>>/dev/null - killall -s SIGCONT make - killall make - killall cc1plus - echo "Terminated, exiting..." - echo - echo - exit -} +nice -n 19 ionice -c3 make -j4 #is this good enough? -trap handle_exit SIGINT -available_mem=$(cat /proc/meminfo | grep MemTotal | grep -o [0-9]*) -if [ -a "memory_exhausted_lock" ] -then - echo "Running in memory conservation mode..." - max_cpp_process_mem_use=1600000 - cpus=$(( $available_mem / $max_cpp_process_mem_use )) - echo "Using $cpus cpu(s) should be safe..." - sleep 1 - make -j${cpus} -else #use all the available computing power by default - cpus=$(( $(cat /proc/cpuinfo | grep -c ^processor) + 0 )) -fi - -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 - if [ x"$(ps aux | grep cc1plus | grep -v grep | wc -l)" != x0 ] - then - ps ax -o vsize,comm | grep cc1plus | grep -o "\<[0-9]*\>" > mem_use - used_mem=$(awk 'BEGIN {sum=0;} {sum+=$1;} END {print sum;}' mem_use) - if (( "$used_mem"> ($available_mem - 300) )) - then - touch memory_exhausted_lock - echo "Stopping due to exagerated memory use ( $used_mem )" - handle_exit - elif (( "$used_mem"> ($available_mem/2) )) - then - if [ x$high_mem != xtrue ] - then - echo "Warning, high memory use, not spawning any more compilation jobs... ( $used_mem )" - killall -s SIGSTOP make - killall -s SIGCONT cc1plus - high_mem="true" - date_mem=$(date +%s) - fi - echo mem $used_mem / $available_mem - elif [ x$high_mem = xtrue ] && (( $(date +%s) > ( $date_mem + 5 ) )) - then - echo "Memory use back to normal" - high_mem="" - killall -s SIGCONT make - fi - rm mem_use - fi - sleep 1 -done -rm memory_exhausted_lock 2>>/dev/null -echo Done! -echo +# +#function handle_exit +#{ +# rm mem_use 2>>/dev/null +# killall -s SIGCONT make +# killall make +# killall cc1plus +# echo "Terminated, exiting..." +# echo +# echo +# exit +#} +# +#trap handle_exit SIGINT +#available_mem=$(cat /proc/meminfo | grep MemTotal | grep -o [0-9]*) +#if [ -a "memory_exhausted_lock" ] +#then +# echo "Running in memory conservation mode..." +# max_cpp_process_mem_use=1600000 +# cpus=$(( $available_mem / $max_cpp_process_mem_use )) +# echo "Using $cpus cpu(s) should be safe..." +# sleep 1 +# make -j${cpus} +#else #use all the available computing power by default +# cpus=$(( $(cat /proc/cpuinfo | grep -c ^processor) + 0 )) +#fi +# +#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 +# if [ x"$(ps aux | grep cc1plus | grep -v grep | wc -l)" != x0 ] +# then +# ps ax -o vsize,comm | grep cc1plus | grep -o "\<[0-9]*\>" > mem_use +# used_mem=$(awk 'BEGIN {sum=0;} {sum+=$1;} END {print sum;}' mem_use) +# if (( "$used_mem"> ($available_mem - 300) )) +# then +# touch memory_exhausted_lock +# echo "Stopping due to exagerated memory use ( $used_mem )" +# handle_exit +# elif (( "$used_mem"> ($available_mem/2) )) +# then +# if [ x$high_mem != xtrue ] +# then +# echo "Warning, high memory use, not spawning any more compilation jobs... ( $used_mem )" +# killall -s SIGSTOP make +# killall -s SIGCONT cc1plus +# high_mem="true" +# date_mem=$(date +%s) +# fi +# echo mem $used_mem / $available_mem +# elif [ x$high_mem = xtrue ] && (( $(date +%s) > ( $date_mem + 5 ) )) +# then +# echo "Memory use back to normal" +# high_mem="" +# killall -s SIGCONT make +# fi +# rm mem_use +# fi +# sleep 1 +#done +#rm memory_exhausted_lock 2>>/dev/null +#echo Done! +#echo diff --git a/filters/clitkSplitImageGenericFilter.cxx b/filters/clitkSplitImageGenericFilter.cxx index f0dba70..9dbfd70 100644 --- a/filters/clitkSplitImageGenericFilter.cxx +++ b/filters/clitkSplitImageGenericFilter.cxx @@ -39,7 +39,7 @@ void clitk::SplitImageGenericFilter::InitializeImageType() { ADD_IMAGE_TYPE(Dim, unsigned char); ADD_IMAGE_TYPE(Dim, short); ADD_IMAGE_TYPE(Dim, int); - //ADD_IMAGE_TYPE(Dim, float); + ADD_IMAGE_TYPE(Dim, float); ADD_VEC_IMAGE_TYPE(Dim, 3,float); } //-------------------------------------------------------------------- diff --git a/vv/vvToolBase.h b/vv/vvToolBase.h index dc62849..9e371f5 100644 --- a/vv/vvToolBase.h +++ b/vv/vvToolBase.h @@ -3,8 +3,8 @@ Program: vv Module: $RCSfile: vvToolBase.h,v $ Language: C++ - Date: $Date: 2010/01/29 13:54:37 $ - Version: $Revision: 1.1 $ + Date: $Date: 2010/02/09 14:19:32 $ + Version: $Revision: 1.2 $ Author : David Sarrut (david.sarrut@creatis.insa-lyon.fr) Copyright (C) 2008 @@ -117,8 +117,9 @@ void vvToolBase::InitializeListOfInputImages() { vvImage * image = mSlicerManagers[i]->GetImage(); - if ((mFilter->CheckDimension(image->GetNumberOfDimensions()) && - mFilter->CheckPixelType(image->GetScalarTypeAsString()))) { + if (mFilter->CheckImageType(image->GetNumberOfDimensions(), + image->GetNumberOfScalarComponents(), + image->GetScalarTypeAsString())) { mSlicerManagersCompatible.push_back(mSlicerManagers[i]); if (mCurrentIndex == i) { mCurrentIndex = mSlicerManagersCompatible.size()-1; -- 2.49.0