[vtkusers] vtkPoints.SetPoints bug?

Fahlgren, Eric eric.fahlgren at smith-nephew.com
Sun Nov 25 09:39:42 EST 2018


I've just been testing with my build of VTK 8.1.2 built with VS 2017 using Python 3.7.1 on Windows 10 and came across this bad behavior when resetting the values of a vtkPoints object.

tl;dr Using SetPoint fails to update the bounds on the vtkPoints object and anything that subsequently uses the points object (a vtkPolyData in my case) draws incorrectly.  This worked in 8.0...

Here's a small script that shows the problem.  Is anyone else seeing this, or maybe it's my build???

#!/bin/env python

import vtk

nPts = 5
points = vtk.vtkPoints()
points.SetNumberOfPoints(nPts * 2)

for i in range(nPts):
    id = i*2
    points.SetPoint(id+0, 0, 0, 0)
    points.SetPoint(id+1, 0, 0, 0)
print('Initial values:\n', points)

for i in range(nPts):
    id = i*2
    x = y = z = float(i)
    points.SetPoint(id+0, x,   y,   z)
    points.SetPoint(id+1, x+1, y+2, z+3)
print('After setting them to non-zero, bad bounds:\n', points)

print('Point data:')
for i in range(nPts):
    id = i*2
    print(id, points.GetPoint(id), points.GetPoint(id+1))

print('Bounds:\n', points.GetBounds())

points.ComputeBounds()
print('Bounds after re-computing:\n', points.GetBounds())

points.SetNumberOfPoints(0)
for i in range(nPts):
    x = y = z = float(i)
    points.InsertNextPoint(x,   y,   z)
    points.InsertNextPoint(x+1, y+2, z+3)
print('After reallocation, now they are fine:\n', points)


Which gives this output:

Initial values:
vtkPoints (000001FE00289E00)
  Debug: Off
  Modified Time: 80
  Reference Count: 1
  RenderDepth: 0
  Registered Events: (none)
  Data: 000001FE7FD059E0
  Data Array Name: Points
  Number Of Points: 10
  Bounds:
    Xmin,Xmax: (0, 0)
    Ymin,Ymax: (0, 0)
    Zmin,Zmax: (0, 0)


After setting them to non-zero, bad bounds:
vtkPoints (000001FE00289E00)
  Debug: Off
  Modified Time: 80
  Reference Count: 1
  RenderDepth: 0
  Registered Events: (none)
  Data: 000001FE7FD059E0
  Data Array Name: Points
  Number Of Points: 10
  Bounds:
    Xmin,Xmax: (0, 0)
    Ymin,Ymax: (0, 0)
    Zmin,Zmax: (0, 0)


Point data:
0 (0.0, 0.0, 0.0) (1.0, 2.0, 3.0)
2 (1.0, 1.0, 1.0) (2.0, 3.0, 4.0)
4 (2.0, 2.0, 2.0) (3.0, 4.0, 5.0)
6 (3.0, 3.0, 3.0) (4.0, 5.0, 6.0)
8 (4.0, 4.0, 4.0) (5.0, 6.0, 7.0)

Bounds:
(0.0, 0.0, 0.0, 0.0, 0.0, 0.0)

Bounds after re-computing:
(0.0, 0.0, 0.0, 0.0, 0.0, 0.0)

After reallocation, now they are fine:
vtkPoints (000001FE00289E00)
  Debug: Off
  Modified Time: 87
  Reference Count: 1
  RenderDepth: 0
  Registered Events: (none)
  Data: 000001FE7FD059E0
  Data Array Name: Points
  Number Of Points: 10
  Bounds:
    Xmin,Xmax: (0, 5)
    Ymin,Ymax: (0, 6)
    Zmin,Zmax: (0, 7)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20181125/db4d2a69/attachment.html>


More information about the vtkusers mailing list