itkwidgets
itkwidgets copied to clipboard
geometris overlay display overextents to the wrong slices
hi, as shown in the gif, the cube geometries overextent to the slices beyond its original range.
ps: notice on y+z plane, it's extented to the direction larger than supposed to, while on x plane, it's extented to slices smaller than supposed to.

minimum code to replicate:
# helper functions
import vtk
def pts_to_cube(pos, radius=2):
"""
covert pos to cube (vtkPolyData) for visulization
"""
# x = array of 8 3-tuples of float representing the vertices of a cube:
pts = [(0.0, 0.0, 0.0), (1.0, 0.0, 0.0), (1.0, 1.0, 0.0), (0.0, 1.0, 0.0),
(0.0, 0.0, 1.0), (1.0, 0.0, 1.0), (1.0, 1.0, 1.0), (0.0, 1.0, 1.0)]
pts = [np.array(pt)*radius * 2 + pos - radius for pt in pts]
faces = [(0, 1, 2, 3), (4, 5, 6, 7), (0, 1, 5, 4),
(1, 2, 6, 5), (2, 3, 7, 6), (3, 0, 4, 7)]
return np_to_polydata(pts, faces)
def np_to_polydata(pts, faces):
"""
convert np.points (+ faces) to vtk.polydata
"""
polyData = vtk.vtkPolyData()
numberOfPoints = len(pts)
points = vtk.vtkPoints()
for x, y, z in pts:
points.InsertNextPoint(x, y, z)
polyData.SetPoints(points)
polys = vtk.vtkCellArray()
for indices in faces:
polys.InsertNextCell(len(indices))
for ind in indices:
polys.InsertCellPoint(ind)
polyData.SetPolys(polys)
return polyData
# actual jupyter codes
import numpy as np
from itkwidgets import view
img_size = 32
pts_num = 3
img = np.zeros([img_size]*3)
pts_list = (np.random.random((pts_num, 3))*img_size).astype(int)
img[tuple(pts_list[:, ::-1].T)] = 1
cubes = [pts_to_cube(pts) for pts in pts_list]
view(img, geometries=cubes)
https://github.com/Kitware/vtk-js/issues/1553
no, this is not what i reported here. The cube becomes infinite height pipe (in the direction of viewing plane) on 2d planes
@qianyizhang We could add a Cutter in a plane in front of the image plane.