danielepanozzo / gp-old

67 stars 13 forks source link

libigl grayscale colormap #37

Closed majia67 closed 6 years ago

majia67 commented 6 years ago

Is it possible for libigl to generate a color map for a scalar function in gray scale?

jiangzhongshi commented 6 years ago

It's not implemented natively, but it is possible. The easiest thing to do is scale your scalar to (0,1), say S and use a colormap as R=G=B=S.

If you want some fancier things done, you can refer to the source code here https://github.com/libigl/libigl/blob/master/include/igl/colormap.cpp and plugin the colorscales encoding from https://matplotlib.org/tutorials/colors/colormaps.html

majia67 commented 6 years ago

@jiangzhongshi Thank you for your reply! How could I specify a colormap as R=G=B=S in libigl? I looked at the "colormap" function in libigl and it seems like all colormap types are predefined.

jiangzhongshi commented 6 years ago

For this simple case, you don't need to use colormap function (you can modify it nonetheless).

Just set

MatrixXd C;
C.col(0) = S;
C.col(1) = S;
C.col(2) = S;

And this is the color matrix you want (be sure to scale S to 0-1 beforehand)

majia67 commented 6 years ago

Wow! I'm stupid. Thanks a lot!