threshold_algorithm.h

Go to the documentation of this file.
00001 //--------------------------------------------------
00010 //--------------------------------------------------
00011 
00012 #ifndef THRESHOLD_ALGORITHM_H__
00013 #define THRESHOLD_ALGORITHM_H__
00014 
00015 #include "../algorithm.h"
00016 #include "threshold_configuration.h"
00017 
00018 #include <itkImageRegionIterator.h>
00019 
00020 
00021 namespace imedgine
00022 {
00023 
00024 //--------------------------------------------------
00035 //--------------------------------------------------
00036 
00037   class ThresholdAlgorithm: public Algorithm
00038   {
00039   public:
00040 
00041     //--------------------------------------------------
00044 
00045     ThresholdAlgorithm();
00046 
00047 
00048     //--------------------------------------------------
00051 
00052     virtual ~ThresholdAlgorithm();
00053 
00054     //--------------------------------------------------
00059 
00060     virtual void run();
00061     
00062   protected:
00063 
00064     //--------------------------------------------------
00067 
00068     ThresholdAlgorithm(ThresholdAlgorithm const& src);
00069     
00070     //--------------------------------------------------
00074 
00075     template <class DatasetPointerType>
00076     void applyAlgorithm(DatasetPointerType dataset); 
00077     
00078     //--------------------------------------------------
00080     
00081     imedgine::dataset_key_type dataset_key_;
00082 
00083   private:
00084     
00085   //----------------------------------------
00088 
00089     ThresholdAlgorithm& operator = (ThresholdAlgorithm const& src);
00090 
00091   }; // class ThresholdAlgorithm
00092   
00093   //--------------------------------------------------
00094   
00095   template <class DatasetPointerType>
00096       void ThresholdAlgorithm::applyAlgorithm(DatasetPointerType dataset)
00097   {
00098     ThresholdConfiguration* config = 
00099         dynamic_cast<ThresholdConfiguration*>(configuration_.get());
00100     
00101     if (config == 0)
00102     {
00103       return;
00104     }
00105     
00106     typedef typename DatasetPointerType::ObjectType DatasetType;
00107     typedef typename DatasetType::PixelType pixel_value_type;
00108     
00109     pixel_value_type lower_bound = 
00110         static_cast<pixel_value_type>(config->getLowerBound());
00111     pixel_value_type upper_bound = 
00112         static_cast<pixel_value_type>(config->getUpperBound());
00113     pixel_value_type default_pixel_value = 
00114         static_cast<pixel_value_type>(config->getDefaultPixelValue());
00115     
00116     std::cout << "lower bound: " << (unsigned int)lower_bound << std::endl
00117         << "upper bound: " << (unsigned int)upper_bound << std::endl;
00118     
00119     typedef itk::ImageRegionIterator<DatasetType> iterator_type;
00120     
00121     iterator_type dataset_iter(
00122         dataset, dataset->GetLargestPossibleRegion());
00123     
00124     for (dataset_iter.GoToBegin(); !dataset_iter.IsAtEnd(); ++dataset_iter)
00125     {
00126       if ((dataset_iter.Value() > upper_bound) ||
00127             (dataset_iter.Value() < lower_bound))
00128       {
00129         dataset_iter.Value() = default_pixel_value;
00130       }  
00131     }
00132     
00133     emit datasetChangedSignal(dataset_key_);
00134   }
00135 
00136 } // namespace imedgine
00137   
00138 #endif // THRESHOLD_ALGORITHM_H__
00139 

Generated on Sun Aug 13 18:19:37 2006 for iMEDgine by  doxygen 1.4.6