File: itkListSampleToHistogramGenerator.h

package info (click to toggle)
insighttoolkit 3.18.0-5
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 110,432 kB
  • ctags: 74,559
  • sloc: cpp: 412,627; ansic: 196,210; fortran: 28,000; python: 3,852; tcl: 2,005; sh: 1,186; java: 583; makefile: 458; csh: 220; perl: 193; xml: 20
file content (196 lines) | stat: -rwxr-xr-x 7,471 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    $RCSfile: itkListSampleToHistogramGenerator.h,v $
  Language:  C++
  Date:      $Date: 2009-08-11 01:31:57 $
  Version:   $Revision: 1.16 $

  Copyright (c) Insight Software Consortium. All rights reserved.
  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#ifndef __itkListSampleToHistogramGenerator_h
#define __itkListSampleToHistogramGenerator_h

#include "itkObject.h"
#include "itkListSampleBase.h"
#include "itkHistogram.h"
#include "itkStatisticsAlgorithm.h"
#include "itkDenseFrequencyContainer.h"
#include "itkNumericTraits.h"

namespace itk {
namespace Statistics {

/** \class ListSampleToHistogramGenerator
 *  \brief Generates a Histogram using the data from the ListSample object
 *
 * This class is templated over the type of ListSample (which is a subclass of
 * ListSampleBase class), the type of measurement values in the histogram, and
 * The type of the frequency container that will be used to store frequency 
 * in the result histogram.
 *
 * User should plug in the input list sample and specify the number of bins
 * along each dimension. For example, if a measurement vector of 
 * the input list sample has three components, the histogram will be three 
 * dimensional histogram. So, the SetNumberOfBins() function will accepts 
 * itk::Size object with three components.
 * 
 * The upper bound and lower bound of the histogram will be automatically 
 * determined by the FindSampleBound funtion in itkStatisticsAlgorithm.h & 
 * .txx. The histogram object's upper bound will be slightly bigger than
 * the uppper bound from the FindSampleBound to include the maximum values
 * in the Histogram object. To extend the upper bound of the histogram. this
 * class internally uses the intervals between two bins and the marginal scale
 * constant that you can set using the SetMarginalScale(float) funtion. 
 * The default marginal scale constant value is 100, which means that the 
 * upper bound of Histogram will be upper bound of the list sample + 
 * (bin interval) / 100 ( = marginal scale). 
 *
 * The result histogram has equi-size bins along each axes.
 *
 * NOTE: The second template argument, THistogramMeasurement should be
 * floating-point type (float or double). 
 *
 * <b> Recent API changes </b>
 * The class is templated over the list sample, the frequency measurement 
 * precision, the length of each measurement vector and optionally over the
 * type of frequency container.
 * 
 * \sa Histogram, ListSampleBase, FindSampleBound 
 */
template< class TListSample, 
          class THistogramMeasurement,  
          class TFrequencyContainer = DenseFrequencyContainer, 
          unsigned int TMeasurementVectorLength = 1 >
class ITK_EXPORT ListSampleToHistogramGenerator :
    public Object
{
public:
  /** Standard typedefs */
  typedef ListSampleToHistogramGenerator Self;
  typedef Object                         Superclass;
  typedef SmartPointer<Self>             Pointer;
  typedef SmartPointer<const Self>       ConstPointer;
  
  /** Run-time type information (and related methods). */
  itkTypeMacro(ListSampleToHistogramGenerator, Object);
  
  /** Method for creation through the object factory. */
  itkNewMacro(Self);

  /** the number of components in a measurement vector */
  itkStaticConstMacro(MeasurementVectorSize, unsigned int,
                      TMeasurementVectorLength);

  /** Type needed for defining the limits of the histogram bins */
  typedef typename NumericTraits< THistogramMeasurement >::RealType 
                                                 HistogramMeasurementRealType;

  typedef Histogram< HistogramMeasurementRealType, 
                     itkGetStaticConstMacro(MeasurementVectorSize),
                     TFrequencyContainer > HistogramType;

  typedef typename HistogramType::SizeType               HistogramSizeType;
  typedef typename HistogramType::MeasurementVectorType  MeasurementVectorType;

  /** plug in the ListSample object */
  void SetListSample(const TListSample* list)
    { 
    // Throw exception if the length of measurement vectors in the list is not
    // equal to the dimension of the histogram.
    if( list->GetMeasurementVectorSize() != MeasurementVectorSize )
      {
      itkExceptionMacro(<< "Length of measurement vectors in the list sample is "
        << list->GetMeasurementVectorSize() << " but histogram dimension is "
        << MeasurementVectorSize);
      }
    m_List = list; 
    }

  void SetMarginalScale(float scale)
  { m_MarginalScale = scale; }

  void SetNumberOfBins(HistogramSizeType sizes)
  { m_Sizes = sizes; }

  const HistogramType* GetOutput() const
  { return m_Histogram; }

  void Update() 
  { this->GenerateData(); }

  itkSetMacro(AutoMinMax,bool);
  itkGetConstReferenceMacro(AutoMinMax,bool);

  void SetHistogramMin(const MeasurementVectorType & histogramMin)
    {
    m_HistogramMin = histogramMin;
    m_AutoMinMax = false;
    
    // Sanity check.. Check to see that container m_HistogramMin has the same
    // length as the length of measurement vectors in the list sample. And the
    // same length as the container over which the list sample is instantiated,
    // if fixed.
    MeasurementVectorTraits::Assert(m_HistogramMin, MeasurementVectorSize, 
        "Length Mismatch: ListSampleToHistogramGenerator::SetHistogramMin");
    if( m_List )
      {
      if( m_List->GetMeasurementVectorSize() != MeasurementVectorSize )
        {
        itkExceptionMacro( << "Length Mismatch: ListSampleToHistogramGenerator::SetHistogramMin" );
        }
      }
    }

  void SetHistogramMax(const MeasurementVectorType & histogramMax)
    {
    m_HistogramMax = histogramMax;
    m_AutoMinMax = false;
    
    // Sanity check.. Check to see that container m_HistogramMax has the same
    // length as the length of measurement vectors in the list sample. And the
    // same length as the container over which the list sample is instantiated,
    // if fixed.
    MeasurementVectorTraits::Assert(m_HistogramMax, MeasurementVectorSize, 
        "Length Mismatch: ListSampleToHistogramGenerator::SetHistogramMin");
    if( m_List )
      {
      if( m_List->GetMeasurementVectorSize() != MeasurementVectorSize )
        {
        itkExceptionMacro( << "Length Mismatch: ListSampleToHistogramGenerator::SetHistogramMin" );
        }
      }
    }


protected:
  ListSampleToHistogramGenerator();
  virtual ~ListSampleToHistogramGenerator() {}
  void GenerateData();
  void PrintSelf(std::ostream& os, Indent indent) const;

private:
  const TListSample*              m_List;
  typename HistogramType::Pointer m_Histogram;
  HistogramSizeType               m_Sizes;
  float                           m_MarginalScale;
  MeasurementVectorType           m_HistogramMin;
  MeasurementVectorType           m_HistogramMax;
  bool                            m_AutoMinMax;

}; // end of class

} // end of namespace Statistics 
} // end of namespace itk 

#ifndef ITK_MANUAL_INSTANTIATION
#include "itkListSampleToHistogramGenerator.txx"
#endif

#endif