0

I am trying to plot 3d point data in vtk by looping through a really large array (size ~ 6e6 x 3). The array shape is (~2000 x 1) with each element containing an array roughly (~3000 x 3)

I used this link as a starting point to plot:

stackoverflow - update live pointcloud data in vtk python

I run into problems when trying looping through my array however. This is how I'm plotting the array:

#pcl is an array ~ size (2000,1) containing arrays that are ~ size (3000, 3)

# for x in range(len(pcl)):  # takes a long time to render output
for x in range(0,10):        # this line renders the first 10 elements
    for point in pcl[x]:
        pointCloud.addPoint(point[:3])

How can I go about rendering all the elements in the array in a more efficient way? Ideally it would look like a video playback.

Thank you!

yvette
  • 1
  • 2

1 Answers1

0

Problem is in the addPoint method you use.

To improve performances, you should not call InsertNextXXX methods. Instead SetNumberOfXXX and then SetXXX with the index.

You should have something like that:

def addPoint(self, idx, point):
...
  self.vtkPoints.SetPoint(idx, point[:])
  self.vtkDepth.SetValue(idx, point[2])
...

def clearPoints(self):
  self.vtkPoints = vtk.vtkPoints()
  self.vtkPoints.SetNumberOfPoints(nbOfPts)
  self.vtkDepth = vtk.vtkDoubleArray()
  self.vtkDepth.SetNumberOfTuples(nbOfTuples)
...
Nico Vuaille
  • 2,310
  • 1
  • 6
  • 14