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 <joel.schaerer@creatis.insa-lyon.fr>
David Sarrut <david.sarrut@creatis.insa-lyon.fr>
public:
typedef std::map<std::string, GenericFilterFunctorBase<FilterType>*> MapOfPixelTypeToFunctionType;
typedef std::map<unsigned int, MapOfPixelTypeToFunctionType> MapOfImageComponentsToFunctionType;
- std::map<unsigned int, MapOfImageComponentsToFunctionType> mMapOfImageTypeToFunction;
+ typedef std::map<unsigned int, MapOfImageComponentsToFunctionType> MapOfImageDimensionToFunctionType;
+ MapOfImageDimensionToFunctionType mMapOfImageTypeToFunction;
ImageTypesManager(FilterType * f) { mFilter = f; }
virtual void DoIt(int dim, int ncomp, std::string pixelname) {
}
template<unsigned int Dim, unsigned int NComp, class PixelType>
void AddNewDimensionAndPixelType() {
- mFilter->AddImageType(Dim, GetTypeAsString<PixelType>());
typedef itk::Image<itk::Vector<PixelType,NComp>,Dim> InputImageType;
mMapOfImageTypeToFunction[Dim][NComp][ GetTypeAsString<PixelType>() ] =
new GenericFilterFunctorWithDimAndPixelType<FilterType, InputImageType>(mFilter);
/// Specialization for NComp == 1
template<unsigned int Dim, class PixelType>
void AddNewDimensionAndPixelType() {
- mFilter->AddImageType(Dim, GetTypeAsString<PixelType>());
typedef itk::Image<PixelType,Dim> InputImageType;
mMapOfImageTypeToFunction[Dim][1][ GetTypeAsString<PixelType>() ] =
new GenericFilterFunctorWithDimAndPixelType<FilterType, InputImageType>(mFilter);
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<std::string> & filenames) {
mInputFilenames=filenames;
//--------------------------------------------------------------------
-
-//--------------------------------------------------------------------
-bool clitk::ImageToImageGenericFilterBase::CheckImageType() {
- return (CheckDimension() && CheckPixelType());
-}
-//--------------------------------------------------------------------
-
-
-//--------------------------------------------------------------------
-bool clitk::ImageToImageGenericFilterBase::CheckDimension(unsigned int d) {
- return (mListOfAllowedDimensions.find(d) != mListOfAllowedDimensions.end());
-}
-//--------------------------------------------------------------------
-
-
-//--------------------------------------------------------------------
-bool clitk::ImageToImageGenericFilterBase::CheckPixelType(std::string pt) {
- return (mListOfAllowedPixelTypes.find(pt) != mListOfAllowedPixelTypes.end());
-}
-//--------------------------------------------------------------------
-
-
-//--------------------------------------------------------------------
-bool clitk::ImageToImageGenericFilterBase::CheckDimension() {
- return CheckDimension(mDim);
-}
-//--------------------------------------------------------------------
-
-
-//--------------------------------------------------------------------
-bool clitk::ImageToImageGenericFilterBase::CheckPixelType() {
- return CheckPixelType(mPixelTypeName);
-}
-//--------------------------------------------------------------------
-
-
//--------------------------------------------------------------------
void clitk::ImageToImageGenericFilterBase::PrintAvailableImageTypes() {
std::cout << GetAvailableImageTypes();
//--------------------------------------------------------------------
-//--------------------------------------------------------------------
-std::string clitk::ImageToImageGenericFilterBase::GetAvailableImageTypes() {
- std::ostringstream oss;
- oss << "The filter <" << mFilterName << "> manages ";
- for(std::set<unsigned int>::const_iterator i=mListOfAllowedDimensions.begin();
- i!=mListOfAllowedDimensions.end(); i++) {
- oss << *i << "D ";
- }
- oss << "images, with pixel types: ";
- for(std::set<std::string>::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<unsigned int>::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<std::string>::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);
}
//--------------------------------------------------------------------
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 <joel.schaerer@creatis.insa-lyon.fr>
David Sarrut <david.sarrut@creatis.insa-lyon.fr>
// 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<class ImageType>
std::vector<vvImage::Pointer> mInputVVImages;
std::vector<vvImage::Pointer> mOutputVVImages;
- std::set<std::string> mListOfAllowedPixelTypes;
- std::set<unsigned int> mListOfAllowedDimensions;
- bool CheckImageType();
- bool CheckDimension();
- bool CheckPixelType();
void ImageTypeError();
void SetImageTypeError();
bool mFailOnImageTypeError;
// 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
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 <joel.schaerer@creatis.insa-lyon.fr>
David Sarrut <david.sarrut@creatis.insa-lyon.fr>
return true;
}
//--------------------------------------------------------------------
+template<class FilterType>
+bool clitk::ImageToImageGenericFilter<FilterType>::CheckImageType(unsigned int dim,unsigned int ncomp, std::string pixeltype)
+{
+ return static_cast<bool>(mImageTypesManager->mMapOfImageTypeToFunction[dim][ncomp][pixeltype]);
+}
+
+template<class FilterType>
+bool clitk::ImageToImageGenericFilter<FilterType>::CheckImageType()
+{
+ return static_cast<bool>(mImageTypesManager->mMapOfImageTypeToFunction[mDim][mNbOfComponents][mPixelTypeName]);
+}
+
+template<class FilterType>
+std::string clitk::ImageToImageGenericFilter<FilterType>::GetAvailableImageTypes() {
+ std::ostringstream oss;
+ oss << "The filter <" << mFilterName << "> manages:" << std::endl;
+
+ typedef typename ImageTypesManager<FilterType>::MapOfImageComponentsToFunctionType::const_iterator MCompItType;
+ typedef typename ImageTypesManager<FilterType>::MapOfImageDimensionToFunctionType::const_iterator MDimItType;
+ typedef typename ImageTypesManager<FilterType>::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();
+}
+//--------------------------------------------------------------------
#!/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
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);
}
//--------------------------------------------------------------------
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
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;