[vtkusers] Histogram of a data array?
John Biddiscombe
jbiddiscombe at skippingmouse.co.uk
Mon Jun 3 17:02:59 EDT 2002
> I would like to calculate a histogram of some scalar data that is
> associated with a vtkUnstructuredGrid dataset. How do I convert my
> vtkDataArray into vtkImageData (single component) so that I can use
> vtkImageAccumulate to calculate the histogram? I think it should be
> something like this, but not sure how to convert the data array:
Assuming you are only interested in the histogram and know that the
topological information is lost,
> vtkDataArray *data = ug->GetPointData()->GetScalars();
>
> // ?? vtkDataArrayToImageDataFilter ??
> vtkDataArrayToImageDataFilter *imageData;
> imageData->SetInput(data);
try this...
vtkImageData *dummyHolder = vtkImageData::New();
int N = data->GetNumberOfTuples();
\\ create a one dimensional image with N tuples
dummyHolder->SetDimensions(N,1,1);
dummyHolder->GetPointData()->SetScalars(data);
> vtkImageAccumulate *histogram;
histogram->SetInput(dummyHolder);
You may need to fiddle with a few other parameters, but the above ought to
do the right thing
JB
More information about the vtkusers
mailing list