[vtkusers] vtkImageExtractComponents
Adrian Albert
a.albert at jacobs-university.de
Sun Apr 20 06:04:21 EDT 2008
Dear All,
could someone explain to me how I can extract a scalar component from a
multicomponent array using vtkImageExtractComponents ?
I have an vtkStructuredPoints with M scalar components defined over the same
grid, and I would like to apply some scaling using vtkShiftScale to only
several of these components. What I am doing right now is:
double range[2];
vtkImageExtractComponents *myImgComp = vtkImageExtractComponents::New ();
myImgComp->AddInput (inputMultivariateField);
myImgComp->SetComponents (idx);
myImgComp->Update ();
myImgComp->GetOutput ()->GetScalarRange (range);
vtkDataArray *myArray = inputMultivariateField->GetPointData
()->GetScalars ();
// myArray->GetRange (range, idx);
cout<<"##Range for field "<<idx<<": ("<<range[0]<<",
"<<range[1]<<")"<<endl;
vtkImageShiftScale* shifter = vtkImageShiftScale::New();
shifter->SetShift(-1.0*range[0]);
shifter->SetScale(255.0/(range[1]-range[0]));
shifter->SetOutputScalarTypeToUnsignedChar();
shifter->SetInput (myImgComp->GetOutput ());
shifter->ReleaseDataFlagOff();
shifter->Update();
vtkDataArray *myChangedComp = shifter->GetOutput ()->GetPointData
()->GetScalars ();
int nrTuples = myChangedComp->GetNumberOfTuples ();
int nrComp = myArray->GetNumberOfComponents ();
double tupN[nrComp], tup;
for (vtkIdType i = 0; i < nrTuples; i++)
{
myArray->GetTuple (i, tupN);
tup = myChangedComp->GetTuple1 (i);
tupN[idx] = tup;
myArray->SetTuple (i, tupN);
}
inputMultivariateField->GetPointData ()->SetScalars (myArray);
So I'm extracting one component (which vtkImageExtractComponents copies in a
separate vtkImageData object), and then work on the scalars directly. Is
there another simpler way of doing this?
Thanks!
Adrian
--
---------------------------------------------------
Adrian Albert
School of Engineering and Science
Jacobs University Bremen
Germany
Tel.: 00494212003258
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20080420/dbed72d7/attachment-0001.htm>
More information about the vtkusers
mailing list