<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'>
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.<br>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.<br>So thanks to confirm that a shallow copy was the reason of my first problem.<br>Now please help a little bit more to fix this one:<br><br> // since pass data makes shallow copies, make a deep copy of the normals<br> vtkFloatArray *normals = vtkFloatArray::New();<br> normals->DeepCopy(input->GetPointData()->GetNormals());<br><br> float *coords = normals->GetPointer(0);<br><br> for (int i=0 ; i<output->GetNumberOfPoints() ; i++,coords+=3)<br> *coords = 0;<br><br> output->GetPointData()->AddArray(normals);<br><br>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...<br><br><hr id="stopSpelling">From: biddisco@cscs.ch<br>To: stan1313@hotmail.fr; paraview@paraview.org<br>Date: Wed, 6 Oct 2010 15:24:13 +0200<br>Subject: RE: [Paraview] PassData() question<br><br>
<meta http-equiv="Content-Type" content="text/html; charset=unicode">
<meta name="Generator" content="Microsoft SafeHTML">
<style>
.ExternalClass p.ecxMsoNormal, .ExternalClass li.ecxMsoNormal, .ExternalClass div.ecxMsoNormal
{margin-bottom:.0001pt;font-size:12.0pt;font-family:'Times New Roman','serif';}
.ExternalClass a:link, .ExternalClass span.ecxMsoHyperlink
{color:blue;text-decoration:underline;}
.ExternalClass a:visited, .ExternalClass span.ecxMsoHyperlinkFollowed
{color:purple;text-decoration:underline;}
.ExternalClass p
{margin-right:0cm;margin-left:0cm;font-size:12.0pt;font-family:'Times New Roman','serif';}
.ExternalClass span.ecxEmailStyle18
{font-family:'Calibri','sans-serif';color:#1F497D;}
.ExternalClass .ecxMsoChpDefault
{font-size:10.0pt;}
@page WordSection1
{size:612.0pt 792.0pt;}
.ExternalClass div.ecxWordSection1
{page:WordSection1;}
</style>
<div class="ecxWordSection1">
<p class="ecxMsoNormal"><span style="font-size: 11pt; font-family: 'Calibri','sans-serif'; color: rgb(31, 73, 125);">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</span></p>
<p class="ecxMsoNormal"><span style="font-size: 11pt; font-family: 'Calibri','sans-serif'; color: rgb(31, 73, 125);"> </span></p>
<p class="ecxMsoNormal"><span style="font-size: 11pt; font-family: 'Calibri','sans-serif'; color: rgb(31, 73, 125);">Deepcopy the normals from input to output, then overwrite them.
Now you have different arrays for in and out.</span></p>
<p class="ecxMsoNormal"><span style="font-size: 11pt; font-family: 'Calibri','sans-serif'; color: rgb(31, 73, 125);"> </span></p>
<p class="ecxMsoNormal"><span style="font-size: 11pt; font-family: 'Calibri','sans-serif'; color: rgb(31, 73, 125);">this is a very common mistake and your students will learn a great
deal about how the pipeline operates. And hopefully you will too!</span></p>
<p class="ecxMsoNormal"><span style="font-size: 11pt; font-family: 'Calibri','sans-serif'; color: rgb(31, 73, 125);"> </span></p>
<p class="ecxMsoNormal"><span style="font-size: 11pt; font-family: 'Calibri','sans-serif'; color: rgb(31, 73, 125);">JB</span></p>
<p class="ecxMsoNormal"><span style="font-size: 11pt; font-family: 'Calibri','sans-serif'; color: rgb(31, 73, 125);"> </span></p>
<div>
<div style="border-right: medium none; border-width: 1pt medium medium; border-style: solid none none; border-color: rgb(181, 196, 223) -moz-use-text-color -moz-use-text-color; padding: 3pt 0cm 0cm;">
<p class="ecxMsoNormal"><b><span style="font-size: 10pt; font-family: 'Tahoma','sans-serif';" lang="EN-US">From:</span></b><span style="font-size: 10pt; font-family: 'Tahoma','sans-serif';" lang="EN-US"> paraview-bounces@paraview.org
[mailto:paraview-bounces@paraview.org] <b>On Behalf Of </b>Fred Fred<br>
<b>Sent:</b> 06 October 2010 14:48<br>
<b>To:</b> paraview@paraview.org<br>
<b>Subject:</b> [Paraview] PassData() question</span></p>
</div>
</div>
<p class="ecxMsoNormal"> </p>
<p class="ecxMsoNormal" style="margin-bottom: 12pt;"><span style="font-size: 10pt; font-family: 'Tahoma','sans-serif';">Hello,<br>
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!<br>
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.<br>
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.<br>
So where is the problem and how should I do it?<br>
<br>
int vtkPbPassData::RequestData(<br>
vtkInformation *vtkNotUsed(request),<br>
vtkInformationVector **inputVector,<br>
vtkInformationVector *outputVector)<br>
{<br>
// get the info objects<br>
vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);<br>
vtkInformation *outInfo = outputVector->GetInformationObject(0);<br>
<br>
// get the input and output<br>
vtkPolyData *input = vtkPolyData::SafeDownCast(<br>
inInfo->Get(vtkDataObject::DATA_OBJECT()));<br>
vtkPolyData *output = vtkPolyData::SafeDownCast(<br>
outInfo->Get(vtkDataObject::DATA_OBJECT()));<br>
<br>
// pass all associated data to output dataset<br>
output->CopyStructure(input);<br>
output->GetPointData()->PassData(input->GetPointData());<br>
output->GetFieldData()->PassData(input->GetFieldData());<br>
<br>
// modify the normals<br>
vtkPointData *pd = output->GetPointData();<br>
if (pd ==NULL) {<br>
vtkErrorMacro(<<"No point data");<br>
return 1;<br>
}<br>
vtkFloatArray *norms = (vtkFloatArray *)pd->GetNormals();<br>
if (norms == NULL) {<br>
vtkErrorMacro(<<"Normals must be defined for this
filter to work");<br>
return 1;<br>
}<br>
float *coords = norms->GetPointer(0);<br>
<br>
for (int i=0 ; i<output->GetNumberOfPoints() ; i++,coords+=3)<br>
*coords = 0;<br>
<br>
return 1;<br>
}</span></p>
</div>                                            </body>
</html>