I have a regular gridded heightmap (terrain) that I converted into a VtkPolyData using VtkDelaunay2D. When rendering it, I set a light source at a particular location. Is there a way to retrieve the values for the shadows at each gridpoint in my terrain? if so what would be the best way?
I’ve never used shadows in VTK (often not needed for scientific visualization), but I believe VTK uses a hardware accelerated solution. That is: shadow data is generated and stays within the graphics card. Assuming such scenario, getting shadow information certainly involves VTK picking (to get world coordinates from render window pixel coordinates and vice-versa) and querying OpenGL for framebuffer RGB values of a given pixel. This seems a bit farfetching depending on your objective. So, may I ask for what do you need it? I mean, I’ve seen people wanting to use shadows as a way to compute gradients along a particular azimuth. Once, a person wanted to use shadows to plan the placement of transmitters. You name it. They wanted to reuse a well tested algorithm but ended up with complicated and fragile solutions. There are better, robust and scalable solutions optimally designed for those problems.
Thank you Paulo,
I am actually interested in using it as a way to calculate quickly visibility! That is, anywhere that is illuminated by the light source would be visible from this location. In fact, I wanted to use the shader solution to generate this output quickly (if that makes sense).
Well, that’s the same problem of the transmitter guy. I’m not a shader specialist, but I don’t think it’s possible to use shaders to query fragment (pixel) RGB values. Operations such as addition are performed with alpha blending and not with something like
red := red + 0.5;. You have to query OpenGL for the framebuffer pixel content (I believe there is a method in
vtkRenderWindow for that). After that, you need to decide based on RGB values. It may work, but I consider it fragile. IMO, you’re better off with a viewshed algorithm. You can either implement it yourself or use some library. Viewshed algorithms are the sort of thing typically found in GIS libraries. As you are working with Python, certainly there is some package out there with a good viewshed algorithm implementation.
all the best,