]> Creatis software - clitk.git/commitdiff
almost finished the work on multiple components
authorschaerer <schaerer>
Tue, 9 Feb 2010 14:19:24 +0000 (14:19 +0000)
committerschaerer <schaerer>
Tue, 9 Feb 2010 14:19:24 +0000 (14:19 +0000)
common/clitkCommonGenericFilter.h
common/clitkImageToImageGenericFilter.cxx
common/clitkImageToImageGenericFilter.h
common/clitkImageToImageGenericFilter.txx
fast_make.sh
filters/clitkSplitImageGenericFilter.cxx
vv/vvToolBase.h

index a1bb8a353d59debfc6c3adc9c0592ca802427389..4826263dc65faf6318620272f9ae95bd6120f095 100644 (file)
@@ -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 <joel.schaerer@creatis.insa-lyon.fr>
              David Sarrut <david.sarrut@creatis.insa-lyon.fr>
 
@@ -65,7 +65,8 @@ namespace clitk {
   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) {
@@ -75,7 +76,6 @@ namespace clitk {
     }
     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);
@@ -83,7 +83,6 @@ namespace clitk {
     /// 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);
index 0465b9b7879074047eb0eb0a5b3e02bb2059dcf0..835ab03e5ccdb6e8f0bb67b5c395ff409aab6119 100644 (file)
@@ -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<std::string> & filenames) {
     mInputFilenames=filenames;
@@ -146,42 +135,6 @@ void clitk::ImageToImageGenericFilterBase::SetInputVVImages (std::vector<vvImage
 //--------------------------------------------------------------------
 
 
-
-//--------------------------------------------------------------------
-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();
@@ -189,42 +142,14 @@ void clitk::ImageToImageGenericFilterBase::PrintAvailableImageTypes() {
 //--------------------------------------------------------------------
 
 
-//--------------------------------------------------------------------
-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);
 }
 //--------------------------------------------------------------------
index 64ac2396869e1ed462b1bbe5c63fe2d9651ddafa..caf25f6ec931596ff6a56c721b1dca201131f524 100644 (file)
@@ -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 <joel.schaerer@creatis.insa-lyon.fr>
              David Sarrut <david.sarrut@creatis.insa-lyon.fr>
 
@@ -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<class ImageType> 
@@ -116,11 +114,6 @@ namespace clitk {
     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;
@@ -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
index 253d421d0f4bfd37112f06fd63cc5134cb1a6cc0..f68ff21ee9ed6525e27e01095ca320644b44c442 100644 (file)
@@ -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 <joel.schaerer@creatis.insa-lyon.fr>
              David Sarrut <david.sarrut@creatis.insa-lyon.fr>
 
@@ -82,4 +82,38 @@ bool clitk::ImageToImageGenericFilter<FilterType>::Update() {
   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();
+}
+//--------------------------------------------------------------------
 
index 9309c87faaa5dfe660dd17662685d4be2b24860e..249ca5e0935abba525ac93275dec368de69e2303 100755 (executable)
@@ -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
index f0dba703f59f68a216542e46567e5a2cedf9bd50..9dbfd70582eabdadc4ed3d06f18f70b22c625711 100644 (file)
@@ -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);
 }
 //--------------------------------------------------------------------
index dc62849a32c209ff6ef619e5c9f343ecbe8602a4..9e371f5172b1eabcc86bc52f8d1a15f22eda037d 100644 (file)
@@ -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<ToolType>::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;