Skip to content

Commit ee2970b

Browse files
committed
Use intersect_with_plane() from newest vedo instead of the backported function
1 parent af71f8c commit ee2970b

File tree

2 files changed

+7
-44
lines changed

2 files changed

+7
-44
lines changed

brainglobe_heatmap/plane.py

+4-44
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,8 @@
1-
from typing import Dict, List
1+
from typing import Dict, List, Self
22

33
import numpy as np
44
import vedo as vd
5-
import vtkmodules.all as vtk
65
from brainrender.actor import Actor
7-
from vtkmodules.vtkFiltersCore import vtkPolyDataPlaneCutter
8-
9-
np.float = float # for compatibility with old vedo
10-
vtk.vtkLogger.SetStderrVerbosity(vtk.vtkLogger.VERBOSITY_OFF)
11-
12-
13-
# from vedo 2023.4.6
14-
def intersect_with_plane(mesh: vd.Mesh, origin=(0, 0, 0), normal=(1, 0, 0)):
15-
"""
16-
Intersect this Mesh with a plane to return a set of lines.
17-
18-
Example:
19-
```python
20-
from vedo import *
21-
sph = Sphere()
22-
mi = sph.clone().intersect_with_plane().join()
23-
print(mi.lines())
24-
show(sph, mi, axes=1).close()
25-
```
26-
![](https://vedo.embl.es/images/feats/intersect_plane.png)
27-
"""
28-
plane = vtk.vtkPlane()
29-
plane.SetOrigin(origin)
30-
plane.SetNormal(normal)
31-
32-
cutter = vtkPolyDataPlaneCutter()
33-
cutter.SetInputData(mesh.dataset)
34-
cutter.SetPlane(plane)
35-
cutter.InterpolateAttributesOn()
36-
cutter.ComputeNormalsOff()
37-
cutter.Update()
38-
39-
msh = vd.Mesh(cutter.GetOutput(), "k", 1).lighting("off")
40-
msh.properties.SetLineWidth(3)
41-
msh.name = "PlaneIntersection"
42-
return msh
43-
446

457
class Plane:
468
def __init__(
@@ -57,7 +19,7 @@ def __init__(
5719
self.M = np.vstack([u, v]).T
5820

5921
@staticmethod
60-
def from_norm(origin: np.ndarray, norm: np.ndarray) -> vd.Plane:
22+
def from_norm(origin: np.ndarray, norm: np.ndarray) -> Self:
6123
u = np.zeros(3)
6224
m = np.where(norm != 0)[0][0] # orientation can't be all-zeros
6325
n = (m + 1) % 3
@@ -95,10 +57,8 @@ def P3toP2(self, ps):
9557
return (ps - self.center) @ self.M
9658

9759
def intersectWith(self, mesh: vd.Mesh):
98-
# mesh.intersect_with_plane(
99-
# origin=self.center, normal=self.normal) in newer vedo
100-
return intersect_with_plane(
101-
mesh, origin=self.center, normal=self.normal
60+
return mesh.intersect_with_plane(
61+
origin=self.center, normal=self.normal
10262
)
10363

10464
# for Slicer.get_structures_slice_coords()

brainglobe_heatmap/slicer.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
from typing import Dict, List, Optional, Union
22

33
import numpy as np
4+
import vtkmodules.all as vtk
45
from brainrender.actor import Actor
56
from brainrender.scene import Scene
67

78
from brainglobe_heatmap.plane import Plane
89

10+
vtk.vtkLogger.SetStderrVerbosity(vtk.vtkLogger.VERBOSITY_OFF)
11+
912

1013
def get_ax_idx(orientation: str) -> int:
1114
"""

0 commit comments

Comments
 (0)