gmt
gmt copied to clipboard
WIP Implement use of PS command shfill into grdview (and maybe elsewhere)
Description of proposed changes
As discussed in Oslo, the PostScript shfill command (first introduced in PostScript 3 in 1999) would be quite useful for draping surfaces as in grdview. The biggest advantages would be:
- Shorter code
- Automatic colour interpolation between the colours defined on the vertices (we can now only use a constant colour for each defined triangle).
There may be some other opportunities as well, like plotting 3D spheres or ellipses.
Regarding shfill implementation in grdview, I have come to the following observations based on reading the PostScript Language Reference Manual, third edition, pp. 261-287
- One way to implement it is by "type 5 shading", i.e. using a pseudorectangular lattice. This would be relatively straightforward, since we are anyway mapping a rectangular grid of vertices, but it would not work when that grid includes holes (NaNs). Afaik grdview now moves around those, since a NaN for the z-coordinate cannot be mapped onto the plot. A NaN value for the draped grid would simply lead to it being assigned the appropriate NaN colour, so that would still work, although the automatic colour interpolation would become a mess.
- The second way of implementation is by "type 4 shading", i.e. using a freeform series of triangles. This implementation is closer to the current one in grdview, but will be a bit more complex to implement.
- Either way, the input can be encoded as binary (we would probably then run it through compression and ascii-encoding as we do images), which can also provide quite some savings in size. I would still first implement it through ascii arrays though to see how well it works.
- One thing that we cannot port from the current implementation, is the opportunity to plot both a surface (draped grid) and a mesh (outline of the grid rectangles). So there would be no equivalent to -Qsm. That means we would probably need to remain supporting the original implementation with option -Qs while introducing a new option e.g. -Qf to use
shfill. There would be no way to combine a surface plotted and filled usingshfillwith a mesh.
Reminders
- [ ] Make sure that your code follows our style. Use the other functions/files as a basis.
- [ ] Add tests for new features or tests that would have caught the bug that you're fixing.
- [ ] Describe changes to function behavior and arguments in a comment below the function declaration.
- [ ] If adding new functionality, add a detailed description to the documentation and/or an example.