Search code examples
python3dvtkcolormap

Color a mesh by height and width


enter image description hereI am trying to color an object based on the width of this later.

Thank you

I tried to inspire myself from this code But this later is for the height. And I want to set a color map based on the width for each z-slice, like the figure below


Solution

  • Using vedo:

    pip install -U git+https://github.com/marcomusy/vedo.git
    

    then (ignore printouts)

    from vedo import *
    
    m = Mesh("airways_no_labels.stl").decimate(0.1)
    pts = m.points()
    
    lns=[]
    for z in pts[:,2]:
        ln = m.intersect_with_plane([0,0,z], [0,0,1])
        if ln.npoints:
            lns.append(ln.average_size())
        else:
            lns.append(0.0)
            
    m.cmap("RdYlGn", lns, vmin=15).add_scalarbar(size=(50,400))
    show(m, axes=1, size=(700,1200), elevation=-90)
    

    enter image description here