InsightSoftwareConsortium / InsightSoftwareConsortium/itkwidgets
geometris overlay display overextents to the wrong slices
- Dominant language
- Python
- Stars
- 624
- Forks
- 83
- PR merge metrics
- No merged PRs in 30d
Description
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:
```python
# 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)
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.