<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]-->
<style>
<!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p
{mso-style-priority:99;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
p.ecxmsonormal, li.ecxmsonormal, div.ecxmsonormal
{mso-style-name:ecxmsonormal;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
p.ecxmsochpdefault, li.ecxmsochpdefault, div.ecxmsochpdefault
{mso-style-name:ecxmsochpdefault;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
span.ecxmsohyperlink
{mso-style-name:ecxmsohyperlink;}
span.ecxmsohyperlinkfollowed
{mso-style-name:ecxmsohyperlinkfollowed;}
span.ecxemailstyle18
{mso-style-name:ecxemailstyle18;}
p.ecxmsonormal1, li.ecxmsonormal1, div.ecxmsonormal1
{mso-style-name:ecxmsonormal1;
mso-margin-top-alt:auto;
margin-right:0cm;
margin-bottom:0cm;
margin-left:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
span.ecxmsohyperlink1
{mso-style-name:ecxmsohyperlink1;
color:blue;
text-decoration:underline;}
span.ecxmsohyperlinkfollowed1
{mso-style-name:ecxmsohyperlinkfollowed1;
color:purple;
text-decoration:underline;}
span.ecxemailstyle181
{mso-style-name:ecxemailstyle181;
font-family:"Calibri","sans-serif";
color:#1F497D;}
p.ecxmsochpdefault1, li.ecxmsochpdefault1, div.ecxmsochpdefault1
{mso-style-name:ecxmsochpdefault1;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:10.0pt;
font-family:"Times New Roman","serif";}
span.EmailStyle28
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
-->
</style>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang=EN-GB link=blue vlink=purple>
<div class=WordSection1>
<p class=MsoNormal style='margin-bottom:12.0pt'><span style='font-size:10.0pt;
font-family:"Tahoma","sans-serif";color:#1F497D'>></span><span
style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> // since pass
data makes shallow copies, make a deep copy of the normals<br>
<span style='color:#1F497D'>></span> vtkFloatArray *normals =
vtkFloatArray::New();<br>
<span style='color:#1F497D'>></span>
normals->DeepCopy(input->GetPointData()->GetNormals());<span
style='color:#1F497D'><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-bottom:12.0pt'><span style='font-size:11.0pt;
font-family:"Calibri","sans-serif";color:#1F497D'>one thing ... what if the
normals are double precision? use this<o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><b><span style='font-family:
"Courier New"'>vtkDataArray *inNormals = input->GetPointData()->GetNormals()<o:p></o:p></span></b></p>
<p class=MsoNormal style='text-autospace:none'><b><span style='font-family:
"Courier New"'>vtkDataArray *normals = inNormals->NewInstance();<o:p></o:p></span></b></p>
<p class=MsoNormal style='text-autospace:none'><b><span style='font-family:
"Courier New"'>normals->DeepCopy(inNormals);<o:p></o:p></span></b></p>
<p class=MsoNormal style='text-autospace:none'><b><span style='font-family:
"Courier New"'><o:p> </o:p></span></b></p>
<p class=MsoNormal style='text-autospace:none'><b><span style='font-family:
"Courier New"'>then <o:p></o:p></span></b></p>
<p class=MsoNormal style='text-autospace:none'><b><span style='font-family:
"Courier New"'>for (vtkIdType i=0; i<N; i++) <o:p></o:p></span></b></p>
<p class=MsoNormal style='text-autospace:none'><b><span style='font-family:
"Courier New"'> double n[3];<o:p></o:p></span></b></p>
<p class=MsoNormal style='text-autospace:none'><b><span style='font-family:
"Courier New"'> normals->GetTuple(i,n);<o:p></o:p></span></b></p>
<p class=MsoNormal style='text-autospace:none'><b><span style='font-family:
"Courier New"'> n[0] = 0.0;<o:p></o:p></span></b></p>
<p class=MsoNormal style='text-autospace:none'><b><span style='font-family:
"Courier New"'> normals->SetValue(i,n);<o:p></o:p></span></b></p>
<p class=MsoNormal style='text-autospace:none'><b><span style='font-family:
"Courier New"'>}<o:p></o:p></span></b></p>
<p class=MsoNormal style='text-autospace:none'><b><span style='font-family:
"Courier New"'><o:p> </o:p></span></b></p>
<p class=MsoNormal style='text-autospace:none'><b><span style='font-family:
"Courier New"'>finally<o:p></o:p></span></b></p>
<p class=MsoNormal style='text-autospace:none'><b><span style='font-family:
"Courier New"'><o:p> </o:p></span></b></p>
<p class=MsoNormal style='text-autospace:none'><b><span style='font-family:
"Courier New"'> output->GetPointData()->SetNormals(normals);<o:p></o:p></span></b></p>
<p class=MsoNormal style='text-autospace:none'><b><span style='font-family:
"Courier New"'><o:p> </o:p></span></b></p>
<p class=MsoNormal style='text-autospace:none'><b><span style='font-family:
"Courier New"'>I wrote this from memory, so it surely contains mistakes.
Hopefully it’ll work<o:p></o:p></span></b></p>
<p class=MsoNormal style='text-autospace:none'><b><span style='font-family:
"Courier New"'><o:p> </o:p></span></b></p>
<p class=MsoNormal style='text-autospace:none'><b><span style='font-family:
"Courier New"'>JB<o:p></o:p></span></b></p>
<p class=MsoNormal style='margin-bottom:12.0pt'><span style='font-size:10.0pt;
font-family:"Tahoma","sans-serif"'><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...<o:p></o:p></span></p>
<div class=MsoNormal align=center style='text-align:center'><span
style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>
<hr size=2 width="100%" align=center id=stopSpelling>
</span></div>
<p class=MsoNormal style='margin-bottom:12.0pt'><span style='font-size:10.0pt;
font-family:"Tahoma","sans-serif"'>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<o:p></o:p></span></p>
<div>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>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><span style='font-size:10.0pt;
font-family:"Tahoma","sans-serif"'><o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'> </span><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'><o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Deepcopy the normals from input to output, then overwrite them.
Now you have different arrays for in and out.</span><span style='font-size:
10.0pt;font-family:"Tahoma","sans-serif"'><o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'> </span><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'><o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>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><span
style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'><o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'> </span><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'><o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>JB</span><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'><o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'> </span><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'><o:p></o:p></span></p>
<div>
<div style='border:none;border-top:solid windowtext 1.0pt;padding:3.0pt 0cm 0cm 0cm;
border-color:-moz-use-text-color -moz-use-text-color'>
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
"Tahoma","sans-serif"'>From:</span></b><span lang=EN-US style='font-size:10.0pt;
font-family:"Tahoma","sans-serif"'> 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><span style='font-size:
10.0pt;font-family:"Tahoma","sans-serif"'><o:p></o:p></span></p>
</div>
</div>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> <o:p></o:p></span></p>
<p class=MsoNormal style='margin-bottom:12.0pt'><span style='font-size:10.0pt;
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>
}<o:p></o:p></span></p>
</div>
</div>
</body>
</html>