Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <vtkUnstructuredGrid.h>
00019
00020 #include <vtkPointData.h>
00021 #include <vtkCellData.h>
00022 #include <vtkIdList.h>
00023
00024 #include "mitkUnstructuredGridHistogram.h"
00025
00026
00027
00028 mitk::UnstructuredGridHistogram::~UnstructuredGridHistogram()
00029 {
00030 }
00031
00032 void mitk::UnstructuredGridHistogram::Initialize(mitk::UnstructuredGrid* ugrid)
00033 {
00034
00035 const int numBins = 20;
00036
00037 vtkUnstructuredGrid* vtkUGrid = ugrid->GetVtkUnstructuredGrid();
00038
00039 double* range = vtkUGrid->GetScalarRange();
00040
00041 SizeType size;
00042 MeasurementVectorType lowerBound;
00043 MeasurementVectorType upperBound;
00044
00045 size.Fill(numBins);
00046 lowerBound[0] = range[0];
00047 upperBound[0] = range[1];
00048 double length = upperBound[0] - lowerBound[0];
00049
00050 this->Superclass::Initialize(size, lowerBound, upperBound);
00051
00052 vtkDataArray* data;
00053 if (m_UsePointData) data = vtkUGrid->GetPointData()->GetScalars();
00054 else data = vtkUGrid->GetCellData()->GetScalars();
00055
00056 if (data == 0) return;
00057
00058 if (m_UsePointData)
00059 {
00060 vtkIdList* cellIds = vtkIdList::New();
00061 for (vtkIdType pointId = 0; pointId < vtkUGrid->GetNumberOfPoints(); pointId++) {
00062 vtkUGrid->GetPointCells(pointId, cellIds);
00063 double numIds = (double)cellIds->GetNumberOfIds();
00064 double scalar = data->GetComponent(pointId, 0);
00065
00066 int bin = numBins - 1;
00067 if (scalar != upperBound[0])
00068 bin = (int)(((double)numBins)*(scalar-lowerBound[0])/length);
00069
00070 this->IncreaseFrequency(bin, scalar/numIds);
00071 cellIds->Reset();
00072 }
00073 cellIds->Delete();
00074 }
00075 else
00076 {
00077 for (vtkIdType cellId = 0; cellId < vtkUGrid->GetNumberOfCells(); cellId++) {
00078 double scalar = data->GetComponent(cellId, 0);
00079
00080 int bin = numBins - 1;
00081 if (scalar != upperBound[0])
00082 bin = (int)(((double)numBins)*(scalar-lowerBound[0])/length);
00083
00084 this->IncreaseFrequency(bin, scalar);
00085 }
00086 }
00087 }