Dear All,<br><br><br>could someone explain to me how I can extract a scalar component from a multicomponent array using vtkImageExtractComponents ?<br>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: <br>
<br> double range[2];<br> vtkImageExtractComponents *myImgComp = vtkImageExtractComponents::New ();<br> myImgComp->AddInput (inputMultivariateField);<br> myImgComp->SetComponents (idx);<br> myImgComp->Update ();<br>
<br> myImgComp->GetOutput ()->GetScalarRange (range);<br> vtkDataArray *myArray = inputMultivariateField->GetPointData ()->GetScalars (); <br>// myArray->GetRange (range, idx);<br> <br> cout<<"##Range for field "<<idx<<": ("<<range[0]<<", "<<range[1]<<")"<<endl;<br>
<br> vtkImageShiftScale* shifter = vtkImageShiftScale::New();<br> shifter->SetShift(-1.0*range[0]);<br> shifter->SetScale(255.0/(range[1]-range[0]));<br> shifter->SetOutputScalarTypeToUnsignedChar();<br> shifter->SetInput (myImgComp->GetOutput ());<br>
shifter->ReleaseDataFlagOff();<br> shifter->Update();<br><br> vtkDataArray *myChangedComp = shifter->GetOutput ()->GetPointData ()->GetScalars (); <br><br> int nrTuples = myChangedComp->GetNumberOfTuples ();<br>
int nrComp = myArray->GetNumberOfComponents ();<br> double tupN[nrComp], tup;<br><br> for (vtkIdType i = 0; i < nrTuples; i++)<br> {<br> myArray->GetTuple (i, tupN);<br> tup = myChangedComp->GetTuple1 (i);<br>
tupN[idx] = tup;<br> myArray->SetTuple (i, tupN);<br> }<br><br> inputMultivariateField->GetPointData ()->SetScalars (myArray);<br><br>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?<br>
<br>Thanks!<br>Adrian<br clear="all"><br>-- <br>---------------------------------------------------<br>Adrian Albert<br>School of Engineering and Science<br>Jacobs University Bremen<br>Germany<br>Tel.: 00494212003258