vedo icon indicating copy to clipboard operation
vedo copied to clipboard

How to calculate the intersection point between line and mask

Open zhang-qiang-github opened this issue 4 years ago • 3 comments

If there is a line and a mask, how can I obtain the intersection point?

For example:

mask = np.zeros([300, 300, 50]) mask[:, :, 10:30] = 1

Then, the line is:

p1 = [100, 100, -1] p2 = [100, 100, 1]

The intersection point should be: [100, 100, 10] and [100, 100, 29].

zhang-qiang-github avatar Feb 10 '21 07:02 zhang-qiang-github

Try:

from vedo import *
import numpy as np

mask = np.zeros([300, 200, 50])
mask[:, :, 10:30] = 1

p1 = [-100, 100, -100]
p2 = [100, 100, 200]

line = Line(p1,p2).c('r').lw(9)

vol = Volume(mask)
vbox = vol.box().wireframe(False).lw(1)

pts = vbox.intersectWithLine(p1,p2)
print(pts)

show(vbox, line, Points(pts, r=20).c('green'), axes=1)
Screenshot 2021-02-10 at 16 35 30

marcomusy avatar Feb 10 '21 15:02 marcomusy

PS: sorry I probably misunderstood.. if you want the boundary hits, where the line hits non-zero voxels you might use

vbox = vol.isosurface(1)
# or 
vbox = vol.legosurface(0.9,1.1)

marcomusy avatar Feb 10 '21 16:02 marcomusy

@marcomusy Thank you for your kindly reply. I indeed need the boundary hits.

Sometime, the mask is very thin. For example:

image

Thus, the vol.isosurface(1) will not return a closed surface, and the boundary hits will contain only one point. But, I need two hit points.

zhang-qiang-github avatar Feb 15 '21 02:02 zhang-qiang-github