ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkSampleToHistogramFilter.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkSampleToHistogramFilter_h
00019 #define __itkSampleToHistogramFilter_h
00020 
00021 #include "itkMacro.h"
00022 #include "itkProcessObject.h"
00023 #include "itkMeasurementVectorTraits.h"
00024 #include "itkSimpleDataObjectDecorator.h"
00025 
00026 itkDeclareExceptionMacro( SampleToHistogramFilterException, ExceptionObject, "Histogram-related Exception");
00027 itkDeclareExceptionMacro( MissingHistogramSizeInput, SampleToHistogramFilterException, "Histogram Size input is missing");
00028 itkDeclareExceptionMacro( MissingHistogramMarginalScaleInput, SampleToHistogramFilterException, "Histogram marginal scale input is missing");
00029 itkDeclareExceptionMacro( NullSizeHistogramInputMeasurementVectorSize, SampleToHistogramFilterException, "Input sample MeasurementVectorSize is zero");
00030 itkDeclareExceptionMacro( MissingHistogramBinMaximumInput, SampleToHistogramFilterException, "Histogram Bin Maximum input is missing");
00031 itkDeclareExceptionMacro( MissingHistogramBinMinimumInput, SampleToHistogramFilterException, "Histogram Bin Minimum input is missing");
00032 itkDeclareExceptionMacro( HistogramWrongNumberOfComponents, SampleToHistogramFilterException, "Histogram has wrong number of components");
00033 
00034 namespace itk
00035 {
00036 namespace Statistics
00037 {
00038 
00054 template< class TSample, class THistogram >
00055 class ITK_EXPORT SampleToHistogramFilter:public ProcessObject
00056 {
00057 public:
00059   typedef SampleToHistogramFilter    Self;
00060   typedef ProcessObject              Superclass;
00061   typedef SmartPointer< Self >       Pointer;
00062   typedef SmartPointer< const Self > ConstPointer;
00063 
00065   itkTypeMacro(SampleToHistogramFilter, ProcessObject);
00066 
00068   itkNewMacro(Self);
00069 
00071   typedef TSample                                       SampleType;
00072   typedef THistogram                                    HistogramType;
00073   typedef typename SampleType::MeasurementVectorType    MeasurementVectorType;
00074   typedef typename MeasurementVectorType::ValueType     MeasurementType;
00075   typedef typename HistogramType::SizeType              HistogramSizeType;
00076   typedef typename HistogramType::MeasurementType       HistogramMeasurementType;
00077   typedef typename HistogramType::MeasurementVectorType HistogramMeasurementVectorType;
00078 
00080   typedef typename Superclass::DataObjectPointer DataObjectPointer;
00081 
00082   using Superclass::SetInput;
00083 
00085   virtual void SetInput(const SampleType *sample);
00086 
00087   virtual const SampleType * GetInput() const;
00088 
00090   const HistogramType  * GetOutput() const;
00091 
00093   typedef SimpleDataObjectDecorator<
00094     HistogramSizeType > InputHistogramSizeObjectType;
00095 
00097   typedef SimpleDataObjectDecorator<
00098     HistogramMeasurementType > InputHistogramMeasurementObjectType;
00099 
00102   typedef SimpleDataObjectDecorator<
00103     HistogramMeasurementVectorType > InputHistogramMeasurementVectorObjectType;
00104 
00106   typedef SimpleDataObjectDecorator< bool > InputBooleanObjectType;
00107 
00114   itkSetGetDecoratedInputMacro(HistogramSize, HistogramSizeType);
00115 
00119   itkSetGetDecoratedInputMacro(MarginalScale, HistogramMeasurementType);
00120 
00123   itkSetGetDecoratedInputMacro(HistogramBinMinimum, HistogramMeasurementVectorType);
00124   itkSetGetDecoratedInputMacro(HistogramBinMaximum, HistogramMeasurementVectorType);
00126 
00130   itkSetGetDecoratedInputMacro(AutoMinimumMaximum, bool);
00131 
00134   virtual void GraftOutput(DataObject *output);
00135 
00136 protected:
00137   SampleToHistogramFilter();
00138   virtual ~SampleToHistogramFilter();
00139 
00140   void PrintSelf(std::ostream & os, Indent indent) const;
00141 
00148   typedef ProcessObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType;
00149   using Superclass::MakeOutput;
00150   virtual DataObjectPointer MakeOutput(DataObjectPointerArraySizeType idx);
00152 
00153   // Where the histogram is actually computed
00154   virtual void GenerateData();
00155 
00156 private:
00157   SampleToHistogramFilter(const Self &); //purposely not implemented
00158   void operator=(const Self &);          //purposely not implemented
00159 
00161   HistogramMeasurementType SafeAssign(MeasurementType from) const
00162   {
00163     if(NumericTraits<HistogramMeasurementType>::is_integer)
00164       {
00165       MeasurementType fromMax = static_cast<MeasurementType>
00166         (NumericTraits<HistogramMeasurementType>::max());
00167       MeasurementType fromMin = static_cast<MeasurementType>
00168         (NumericTraits<HistogramMeasurementType>::min());
00170 
00171       if (from >= fromMax)
00172         {
00173         return NumericTraits<HistogramMeasurementType>::max();
00174         }
00175       else if (from <= fromMin)
00176         {
00177         return NumericTraits<HistogramMeasurementType>::min();
00178         }
00179       }
00180     return static_cast<HistogramMeasurementType>(from);
00181   }
00182 
00183 };                                       // end of class
00184 } // end of namespace Statistics
00185 } // end of namespace itk
00186 
00187 #ifndef ITK_MANUAL_INSTANTIATION
00188 #include "itkSampleToHistogramFilter.hxx"
00189 #endif
00190 
00191 #endif
00192