As i am starting to build some basic plotting methods for 3D visualization with VTK for some Data-Visualization, i ran over the following issue:
My Dataset is usually about the Size ob 200e6-1000e6 Datapoints (Sensor Values) with its corresponding coordinates, points, (X,Y,Z). My Visualization method works fine, but there is at least one Bottleneck. Beside the rest of the code, the schown example with the 2 for loops, is the most time consuming part of the whole method.
I am not happy with adding the Coordinates (points, numpy(n,3) ) and Sensor Values (intensity, numpy(n,1) ) via foor loops to the VTK Objects
The spicific code example:
vtkpoints = vtk.vtkPoints() # https://vtk.org/doc/nightly/html/classvtkPoints.html
vtkpoints.SetNumberOfPoints(self.points.shape[0])
# Bottleneck - Faster way?
self.start = time.time()
for i in range(self.points.shape[0]):
vtkpoints.SetPoint(i, self.points[i])
self.vtkpoly = vtk.vtkPolyData() # https://vtk.org/doc/nightly/html/classvtkPolyData.html
self.vtkpoly.SetPoints(vtkpoints)
self.elapsed_time_normal = (time.time() - self.start)
print(f" AddPoints took : {self.elapsed_time_normal}")
# Bottleneck - Faster way?
vtkcells = vtk.vtkCellArray() # https://vtk.org/doc/nightly/html/classvtkCellArray.html
self.start = time.time()
for i in range(self.points.shape[0]):
vtkcells.InsertNextCell(1)
vtkcells.InsertCellPoint(i)
map(vtkcells.InsertNextCell(1),self.points)
self.elapsed_time_normal = (time.time() - self.start)
print(f" AddCells took : {self.elapsed_time_normal}")
# Inserts Cells to vtkpoly
self.vtkpoly.SetVerts(vtkcells)
Times:
- Convert DataFrame took: 6.499739646911621
- AddPoints took : 58.41245102882385b
- AddCells took : 48.29743027687073
- LookUpTable took : 0.7522616386413574
All Input Data is of type int, its basicly a Dataframe converted to vtknumpy objects by numpy_to_vtk method.
I am very happy, if someone has an idea of speeding this up.
BR Bastian