In Python plugin I use the code below to create 3D polydata from reqular 2D grid with holes (NoData values) but it’s works too slow. Maybe should I use some other data type or processing instead?
# Define points and triangles for mesh
vtk_points = vtkPoints()
vtk_cells = vtkCellArray()
# Build the meshgrid manually
count = 0
# iterate array
for j in range(0,len(ys)-2):
for i in range(0,len(xs)-2):
# check area
if not mask[j,i] or not mask[j+1,i] or not mask[j,i+1] or not mask[j+1,i+1]:
continue
# Triangle 1
vtk_points.InsertNextPoint(xs[i], ys[j], values[j,i])
vtk_points.InsertNextPoint(xs[i], ys[j+1], values[j+1,i])
vtk_points.InsertNextPoint(xs[i+1], ys[j], values[j,i+1])
triangle = vtkTriangle()
triangle.GetPointIds().SetId(0, count)
triangle.GetPointIds().SetId(1, count + 1)
triangle.GetPointIds().SetId(2, count + 2)
vtk_cells.InsertNextCell(triangle)
# Triangle 2
vtk_points.InsertNextPoint(xs[i], ys[j+1], values[j+1,i])
vtk_points.InsertNextPoint(xs[i+1], ys[j+1], values[j+1,i+1])
vtk_points.InsertNextPoint(xs[i+1], ys[j], values[j,i+1])
triangle = vtkTriangle()
triangle.GetPointIds().SetId(0, count + 3)
triangle.GetPointIds().SetId(1, count + 4)
triangle.GetPointIds().SetId(2, count + 5)
vtk_cells.InsertNextCell(triangle)
count += 6
# Create a polydata object
trianglePolyData = vtkPolyData()
# Add the geometry and topology to the polydata
trianglePolyData.SetPoints(vtk_points)
#trianglePolyData.GetPointData().SetScalars(colors)
trianglePolyData.SetPolys(vtk_cells)
For now, I don’t know more optimal way to get produce this visualization. Is it the optimal datatype for the task? We have Z coordinate in the mesh geometries and as the separate attribute - could we exclude it but still have the ability for mesh coloring by Z coordinate? Could we save additional attribute like to country name by more optimal way (for now it’s saved separately for every cell as I see)?
Hi,
I am trying to learn what is efficient and I came across this https://vtk.org/Wiki/VTK/Tutorials/DataArrays
It mainly deals with the loss of performances related to the generic API.
From what I have read but not tested in the source code, using iterator + a second class to parallelize with multithreading seems the way to go (I am currently looking at ParaView-v5.7.0/VTK/Imaging/Core/vtkImageBlend.cxx).