[vtkusers] vtkPoints 'GetPoint' method

Randall Hand randall.hand at gmail.com
Tue Jul 25 11:52:28 EDT 2006

I've just been fighting with a small piece of code based around some calls
to vtkPoints's GetPoint method.

The code:

    double *p1, *p2;
    for(i=0; i<newPts->GetNumberOfPoints()-1; i++) {
        for(j=i+1; j<newPts->GetNumberOfPoints(); j++) {
            // compute distance from p1 to p2

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:
    double p1[3], p2[3];
    for(i=0; i<newPts->GetNumberOfPoints()-1; i++) {
        newPts->GetPoint(i, p1);
        for(j=i+1; j<newPts->GetNumberOfPoints(); j++) {
            newPts->GetPoint(j, p2);
            // compute distance from p1 to p2
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?
Randall Hand
Visualization Scientist
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20060725/18a9b0b3/attachment.htm>

More information about the vtkusers mailing list