[Paraview] PassData() question
Fred Fred
stan1313 at hotmail.fr
Wed Oct 6 15:51:25 EDT 2010
Of course I suspected that a shallow copy was performed, and I explained
to my students that it was to save memory and avoid duplicated of
information in the pipeline, but when I looked at the code of the PassData() method, it was not clear if "arrayIndex = this->AddArray(dsa->GetAbstractArray(i));" actually performed a shallow copy or not.
So I tried to do a deep copy but I surely made a mistake since nothing happen and finally I decided to ask you concerning the first issue.
So thanks to confirm that a shallow copy was the reason of my first problem.
Now please help a little bit more to fix this one:
// since pass data makes shallow copies, make a deep copy of the normals
vtkFloatArray *normals = vtkFloatArray::New();
normals->DeepCopy(input->GetPointData()->GetNormals());
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/6ee1d0f4/attachment-0001.htm>
More information about the ParaView
mailing list