diff --git a/Modules/MitkAlgorithmsExt/mitkSimpleHistogram.h b/Modules/MitkAlgorithmsExt/mitkSimpleHistogram.h index 7143c0c21d..9bb2dd1acc 100644 --- a/Modules/MitkAlgorithmsExt/mitkSimpleHistogram.h +++ b/Modules/MitkAlgorithmsExt/mitkSimpleHistogram.h @@ -1,174 +1,174 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITKSIMPLEHISTOGRAM_H #define MITKSIMPLEHISTOGRAM_H #ifndef __itkHistogram_h #include #endif #include "MitkAlgorithmsExtExports.h" #include #include #include #include namespace mitk { //##Documentation //## @brief Abstract superclass for histograms with double values. //## Classes which are deriving from this class can be cached //## in the same way. class MitkAlgorithmsExt_EXPORT SimpleHistogram { public: /** @brief Returns the minimal value of the histogram. */ virtual double GetMin() const = 0; /** @brief Returns the maximum value of the histogram. */ virtual double GetMax() const = 0; /** @brief Creates a new histogram out the source. */ virtual void ComputeFromBaseData( BaseData* source ) = 0; /** @brief TODO: (What should this method do?)*/ virtual float GetRelativeBin( double start, double end ) const = 0; }; class MitkAlgorithmsExt_EXPORT SimpleImageHistogram : public SimpleHistogram { public: typedef itk::Statistics::Histogram HistogramType; SimpleImageHistogram() { valid=false; histogram=0; } ~SimpleImageHistogram() { if(histogram) delete histogram; } /** @return Returns if the current histogram is valid, false if not. */ bool GetValid(); typedef itk::Image CTImage; typedef itk::ImageRegionIterator< CTImage > CTIteratorType; typedef itk::ImageRegionIteratorWithIndex< CTImage > CTIteratorIndexType; typedef itk::Image BinImage; typedef itk::ImageRegionIterator< BinImage > BinIteratorType; typedef itk::ImageRegionIteratorWithIndex< BinImage > BinIteratorIndexType; typedef unsigned long CountType; protected: CountType *histogram; bool valid; int first; int last; int min; int max; CountType highest; double invLogHighest; public: double GetMin() const { if(!valid) return 0; return min; } double GetMax() const { if(!valid) return 1; return max; } /** @brief Creates a new histogram out the source which must be an image. Method does nothing if the image is invalid, NULL, etc.. */ void ComputeFromBaseData( BaseData* source ); float GetRelativeBin( double start, double end ) const; }; class MitkAlgorithmsExt_EXPORT SimpleHistogramCache { public: static const unsigned int maxCacheSize = 64; - class Element + class MitkAlgorithmsExt_EXPORT Element { public: mitk::WeakPointer baseData; itk::TimeStamp m_LastUpdateTime; virtual ~Element(); virtual void ComputeFromBaseData(BaseData* baseData) = 0; virtual SimpleHistogram* GetHistogram() = 0; }; typedef std::list CacheContainer; CacheContainer cache; SimpleHistogramCache() { } ~SimpleHistogramCache() { TrimCache(true); } SimpleHistogram *operator[](BaseData::Pointer sp_BaseData); protected: void TrimCache(bool full=false) { unsigned int targetSize = full?0:maxCacheSize; while(cache.size()>targetSize) { delete cache.back(); cache.pop_back(); } } }; } #endif // MITKSIMPLEHISTOGRAM_H