21 #include <itkSampleToHistogramFilter.h>
22 #include <vtkDataArray.h>
23 #include <vtkPointData.h>
24 #include <vtkUnstructuredGrid.h>
29 : m_UGHistogram(HistogramType::
New()), m_InvMaxFrequency(1)
37 return m_UGHistogram->GetBinMax(0, m_UGHistogram->GetSize(0) - 1);
48 listSample->SetMeasurementVectorSize(1);
50 MeasurementVectorType v;
52 MeasurementVectorType lowerBound;
53 MeasurementVectorType upperBound;
56 HistogramType::SizeType size(1);
59 data = vtkUGrid->GetPointData()->GetScalars();
64 listSample->Resize(1);
66 listSample->PushBack(v);
69 size.Fill(numberOfBins);
73 listSample->Resize(data->GetNumberOfTuples());
74 for (vtkIdType i = 0; i < data->GetNumberOfTuples(); ++i)
76 v[0] = data->GetComponent(i, 0);
78 listSample->PushBack(v);
81 vtkIdType numberOfTuples = data->GetNumberOfTuples();
83 if (numberOfTuples < 1000)
85 else if (numberOfTuples < 30000)
87 else if (numberOfTuples < 100000)
92 size.Fill(numberOfBins);
95 data->GetRange(range);
96 lowerBound[0] = range[0];
97 upperBound[0] = range[1];
100 typedef itk::Statistics::SampleToHistogramFilter<ListSampleType, HistogramType> FilterType;
103 FilterType::HistogramMeasurementVectorType binMin(1);
104 FilterType::HistogramMeasurementVectorType binMax(1);
106 binMin[0] = lowerBound[0];
107 binMax[0] = upperBound[0];
109 histoFilter->SetInput(listSample);
110 histoFilter->SetHistogramSize(size);
111 histoFilter->SetHistogramBinMinimum(binMin);
112 histoFilter->SetHistogramBinMaximum(binMax);
113 histoFilter->Update();
115 m_UGHistogram = histoFilter->GetOutput();
117 m_BinSize = (
GetMax() -
GetMin()) / (
double)numberOfBins;
119 m_Mins = m_UGHistogram->GetMins();
120 m_Maxs = m_UGHistogram->GetMaxs();
122 HistogramType::AbsoluteFrequencyType maxFrequency = 0;
123 HistogramType::SizeValueType histoSize = m_UGHistogram->GetSize(0);
124 for (HistogramType::SizeValueType i = 0; i < histoSize; ++i)
126 HistogramType::AbsoluteFrequencyType f = m_UGHistogram->GetFrequency(i);
127 if (f > maxFrequency)
136 m_InvMaxFrequency = 1.0 / log((
double)maxFrequency);
146 HistogramType::AbsoluteFrequencyType maxf = 0;
147 for (
double pos = start; pos < end; pos += m_BinSize)
149 HistogramType::AbsoluteFrequencyType f = m_UGHistogram->GetFrequency(m_UGHistogram->GetIndex(pos));
154 return log(static_cast<double>(maxf)) * m_InvMaxFrequency;
itk::SmartPointer< Self > Pointer
virtual double GetMax() const override
Returns the maximum value of the histogram.
Base of all data objects.
DataCollection - Class to facilitate loading/accessing structured data.
virtual vtkUnstructuredGrid * GetVtkUnstructuredGrid(unsigned int t=0)
SimpleUnstructuredGridHistogram()
virtual void ComputeFromBaseData(BaseData *source) override
Creates a new histogram out the source.
virtual double GetMin() const override
Returns the minimal value of the histogram.
Class for storing unstructured grids (vtkUnstructuredGrid)
virtual float GetRelativeBin(double start, double end) const override
TODO: (What should this method do?)
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.