[Paraview] PassData() question

Biddiscombe, John A. biddisco at cscs.ch
Wed Oct 6 09:24:13 EDT 2010


You have shallow copied the point normals from the input to the output. Then overwritten them in the output. And therefore have overwritten them in the input too. so of course they look the same. Passdata just passes the array pointers using a shallow copy

Deepcopy the normals from input to output, then overwrite them. Now you have different arrays for in and out.

this is a very common mistake and your students will learn a great deal about how the pipeline operates. And hopefully you will too!

JB

From: paraview-bounces at paraview.org [mailto:paraview-bounces at paraview.org] On Behalf Of Fred Fred
Sent: 06 October 2010 14:48
To: paraview at paraview.org
Subject: [Paraview] PassData() question

Hello,
I was just showing to my students how to write a very basic filter, for them to concentrate on the different steps rather than on the algorithm itself but... my example did not work!
The filter was supposed just to withdraw the X components of the normal of a PolyData and the students were asked to show a cylinder before and after the filter so as to compare the shading.
Looking at the code of the PassData() function, it seems that it really copies everything but when I apply my filter, the shading is modified both in the output and the input.
So where is the problem and how should I do it?

int vtkPbPassData::RequestData(
  vtkInformation *vtkNotUsed(request),
  vtkInformationVector **inputVector,
  vtkInformationVector *outputVector)
{
  // get the info objects
  vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
  vtkInformation *outInfo = outputVector->GetInformationObject(0);

  // get the input and output
  vtkPolyData *input = vtkPolyData::SafeDownCast(
    inInfo->Get(vtkDataObject::DATA_OBJECT()));
  vtkPolyData *output = vtkPolyData::SafeDownCast(
    outInfo->Get(vtkDataObject::DATA_OBJECT()));

  // pass all associated data to output dataset
  output->CopyStructure(input);
  output->GetPointData()->PassData(input->GetPointData());
  output->GetFieldData()->PassData(input->GetFieldData());

  // modify the normals
  vtkPointData *pd = output->GetPointData();
  if (pd ==NULL) {
    vtkErrorMacro(<<"No point data");
    return 1;
  }
  vtkFloatArray *norms = (vtkFloatArray *)pd->GetNormals();
  if (norms == NULL) {
    vtkErrorMacro(<<"Normals must be defined for this filter to work");
    return 1;
  }
  float *coords = norms->GetPointer(0);

  for (int i=0 ; i<output->GetNumberOfPoints() ; i++,coords+=3)
    *coords = 0;

  return 1;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.paraview.org/pipermail/paraview/attachments/20101006/134facca/attachment-0001.htm>


More information about the ParaView mailing list