Hi @marcomusy,
I am trying to use your library to visualize data from thermal comfort studies. I have several manikins like the one shown below and I intend to color individual polygons based on the amount of thermal radiation incident on them (as shown in the screencapture in the second picture)


The part about loading the geometry is super simple due to the methods in your vtkPlotter class. I could not find a way to interact with the individual faces of the obj through any of the methods. I also tried to understand the methods and attributes available at runtime through the debugger in Pycharm but could not get much far. Any suggestions?
Thanks,
Sarith
Hi
I'm adding now this functionality and let you know asap
M
@marcomusy Thanks. Please let me know if I can help out in any way. I just got started with VTK but I do have some experience in Python and data visualization.
please have a look at examples/mesh_coloring.py

This is pretty incredible!!
I just ran your example file with some of my manikins and it works great..

..and just for fun, I tried a more complex model (with nearly 100,000 surfaces and missing geometry) and that loads too!

I think this library could be used to visualize a whole lot of building science data in 3D.
cc: @mostaphaRoudsari
Thanks,
keep in mind you can control the scalarbar to have it horizontal e.i.:
vp.addScalarBar(man3, horizontal=True)
@marcomusy Thanks for the tip. Which API do you to refer to for Python-specifc functionality within VTK? I have come across an API and documentation for the C++ version, however, it appears that not all the classes and methods have been ported over to the Python version.
I typically use the latest version of vtk (8.1 as it comes in anaconda) so I guess all the c++ methods are ported to python, older vtk versions might not have the latest features. I don't think that there is anything like a specific python api for reference...
If you load any mesh at command line you should be able to get a message of which version you are running, e.g.:
./plotter.py anymesh.obj
I don't think that there is anything like a specific python api for reference...
That's the case with most libraries ported to Python, except PyQT. Anyway, thank you for getting this project started. I will circle back in case I come up with more "interesting" queries.
vtk documentation is not very good..
if you have any other questions/query don't hesitate to ask,
cheers
M
code:
from vtkplotter import *
import numpy as np
sc = load('scan_c.obj')
data_label = np.load('scan_labels.npy').reshape(-1)
sc.pointColors(data_label, alpha=1, mode='scalars')
show(sc, Text('seg', c='k'), bg='w', interactive=True)
question:
1,2: Shown in OpenFlipper and vtkplotter, difference caused by ?interpolation???
3,4: How to color a single element(vertex or face) without interpolation?

PS: In scan.obj, only v and vt are stored, but f indexes to vn. It can be opened in meshlab and OpenFlipper, exception handling should be done, can you handle such abnormal data?
PS: How to set transparent background?
Hi @LogWell please pull the latest commit and try the following:
from vtkplotter import load, show, colors
import numpy as np
sc = load('scan_c.obj')
data_label = np.load('scan_labels.npy').reshape(-1)
# Optionally build a lookup table of colors:
# scalar, color
lut = colors.makeLUT([( 0, 'pink'),
( 1, 'green'),
( 3, 'yellow'),
],
N=4, # specify total nr. of colors
)
sc.pointColors(data_label, cmap=lut).addScalarBar()
#sc.mapPointsToCells() # this would translate point data to cell data
# avoid interpolating cell colors:
sc.mapper.InterpolateScalarsBeforeMappingOff()
show(sc, bg='w')

PS: In scan.obj, only v and vt are stored, but f indexes to vn. It can be opened in meshlab and OpenFlipper, exception handling should be done, can you handle such abnormal data?
Unfortunately vtk seems unable to handle this faulty data..
PS: How to set transparent background?
from vtkplotter import settings
settings.screenshotTransparentBackground = True
NOTE: The red dot in the leftmost yellow circle in the previous image may be caused by abnormal data scan.obj , correct as shown in fig_1, same as in vtkplotter.
Q:
colors.makeLUT. I'm a little confused about setting the correct color in fig_3.
from vtkplotter import load, show, makeLUT, Points
import numpy as np
sc = load('/home/musy/downloads/scan/scan_c.obj')
data_label = np.load('/home/musy/downloads/scan/scan_labels.npy').reshape(-1)
# build a lookup table of colors:
# scalar, color
lut = makeLUT([( 0, 'red'),
( 1, 'green'),
( 3, 'gold'),
],
N=4, # specify total nr. of colors
)
sc.pointColors(data_label, cmap=lut).addScalarBar()
# avoid interpolating cell colors:
sc.mapper.InterpolateScalarsBeforeMappingOff()
pts = Points(sc.coordinates()).pointColors(data_label, cmap=lut)
show(sc, pts, N=2, bg='w')

Let me know if you can reproduce the above figure.
In fact, there are four labels in total(maybe more). The current obj file only contains three of them (label 2 may represent skirt).
For a batch of data, I can map 0,1,2,3 to four colors, and then color it according to the label information.
@LogWell
I realized that my first try at fixing this was not great.. :) I modified the makeLUT() function, so the above now becomes:
from vtkplotter import load, show, makeLUT, Points
import numpy as np
sc = load('/home/musy/downloads/scan/scan_c.obj')
data_label = np.load('/home/musy/downloads/scan/scan_labels.npy').reshape(-1)
# build a lookup table of colors:
# scalar, color alpha
lut = makeLUT([( 0, 'red' ),
( 1, 'green', 0.5),
( 3, 'gold' ),
],
interpolate=False,
)
sc.pointColors(data_label, cmap=lut).addScalarBar()
# avoid interpolating cell colors:
sc.mapper.InterpolateScalarsBeforeMappingOff()
pts = Points(sc.coordinates()).pointColors(data_label, cmap=lut)
show(sc, pts, N=2, bg='w')
this also includes setting opacities if a 3rd element is given in the list.
Hope this works for you.
Hi, marcomusy~
The result seems strange after I subdivided the mesh. It looks a little bit like a flip from the inside view, but the normal of faces are correct in meshlab.
How to solve this problem?
Hi @LogWell
this looks related to a transparency problem in vtk.. though I must say I don't understand exactly why that happens.. This works for me:
from vtkplotter import *
settings.useDepthPeeling = True
m = load('00000.obj').texture('registered_tex_1_m.png')
m.show(axes=4)
@marcomusy How to render a mesh like this(you can distinguish between inside and outside):



various possibilities..:
if the points are projectable onto a plane (which seems to be the case) you can discard the existing triangles and recreate a new mesh with delaunay2D
or
try to recreate it with recoSurface()
besides
you can use clean(tol=0.01) to preprocess and reduce the points and/or use smoothMLS2D() to make the surface smoother.
finally - once you have the mesh - you can color the outside and inside differently with color() and backColor()