I've just been fighting with a small piece of code based around some calls to vtkPoints's GetPoint method.<br><br>The code:<br><br clear="all"><div style="margin-left: 40px;"><span style="font-family: courier new,monospace;">
double *p1, *p2;<br> for(i=0; i<newPts->GetNumberOfPoints()-1; i++) {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> p1=newPts->GetPoint(i);
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> for(j=i+1; j<newPts->GetNumberOfPoints(); j++) {</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> p2=newPts->GetPoint(j);<br> // compute distance from p1 to p2<br style="font-family: courier new,monospace;"></span><span style="font-family: courier new,monospace;">
</span><span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> }<br><br style="font-family: courier new,monospace;">
</span></div>Seems like this should work just fine, but p1 changes when I request p2. It seems that the 2 calls return the exact same pointer address in memory, so previous calls change with new ones. Simply switching to this:
<br><span style="font-family: courier new,monospace;"> double p1[3], p2[3];<br>
for(i=0; i<newPts->GetNumberOfPoints()-1; i++) {</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> newPts->GetPoint(i, p1);</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> for(j=i+1; j<newPts->GetNumberOfPoints(); j++) {</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> newPts->GetPoint(j, p2);<br>
// compute distance from p1 to p2<br style="font-family: courier new,monospace;">
</span><span style="font-family: courier new,monospace;"></span><span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> }<br>
</span>Works just fine. With a bit of research I see that vtkPoints is just a wrapper around a vtkFloatArray, which uses an internal pointer array named "Tuple" to do this. It's listed as not "Thread Safe", but it seems it's far more than that.. It's basically Volatile, with the value changing at any time. Is this by-design or is this a bug?
<br>-- <br>----------------------------------------<br>Randall Hand<br>Visualization Scientist<br>ERDC MSRC-ITL