[Paraview] PassData() question

Biddiscombe, John A. biddisco at cscs.ch
Wed Oct 6 16:32:42 EDT 2010


>  // since pass data makes shallow copies, make a deep copy of the normals
>  vtkFloatArray *normals = vtkFloatArray::New();
>  normals->DeepCopy(input->GetPointData()->GetNormals());
one thing ... what if the normals are double precision? use this
vtkDataArray *inNormals = input->GetPointData()->GetNormals()
vtkDataArray *normals = inNormals->NewInstance();
normals->DeepCopy(inNormals);

then
for (vtkIdType i=0; i<N; i++)
     double n[3];
     normals->GetTuple(i,n);
     n[0] = 0.0;
     normals->SetValue(i,n);
}

finally

 output->GetPointData()->SetNormals(normals);

I wrote this from memory, so it surely contains mistakes. Hopefully it'll work

JB


  float *coords = normals->GetPointer(0);

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

  output->GetPointData()->AddArray(normals);

As far as I read in the VTK doc, adding an array with the same name as an existing one will replace it by the new one, so I expected that "normals" would replace the existing array of normals, but I am probably wrong...
________________________________
From: biddisco at cscs.ch
To: stan1313 at hotmail.fr; paraview at paraview.org
Date: Wed, 6 Oct 2010 15:24:13 +0200
Subject: RE: [Paraview] PassData() question
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/2aed937d/attachment.htm>


More information about the ParaView mailing list