1
- from typing import Dict , List
1
+ from typing import Dict , List , Self
2
2
3
3
import numpy as np
4
4
import vedo as vd
5
- import vtkmodules .all as vtk
6
5
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
- 
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
-
44
6
45
7
class Plane :
46
8
def __init__ (
@@ -57,7 +19,7 @@ def __init__(
57
19
self .M = np .vstack ([u , v ]).T
58
20
59
21
@staticmethod
60
- def from_norm (origin : np .ndarray , norm : np .ndarray ) -> vd . Plane :
22
+ def from_norm (origin : np .ndarray , norm : np .ndarray ) -> Self :
61
23
u = np .zeros (3 )
62
24
m = np .where (norm != 0 )[0 ][0 ] # orientation can't be all-zeros
63
25
n = (m + 1 ) % 3
@@ -95,10 +57,8 @@ def P3toP2(self, ps):
95
57
return (ps - self .center ) @ self .M
96
58
97
59
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
102
62
)
103
63
104
64
# for Slicer.get_structures_slice_coords()
0 commit comments