; docformat = 'rst' ;+ ; This is an example program to demonstrate how to create a hidden surface plot ; with Coyote Graphics routines. ; ; :Categories: ; Graphics ; ; :Examples: ; Save the program as "hidden_surface_plot.pro" and run it like this:: ; IDL> .RUN hidden_surface_plot ; ; :Author: ; FANNING SOFTWARE CONSULTING:: ; David W. Fanning ; 1645 Sheely Drive ; Fort Collins, CO 80526 USA ; Phone: 970-221-0438 ; E-mail: david@idlcoyote.com ; Coyote's Guide to IDL Programming: http://www.idlcoyote.com ; ; :History: ; Change History:: ; Written, 27 January 2013 by David W. Fanning. ; ; :Copyright: ; Copyright (c) 2013, Fanning Software Consulting, Inc. ;- PRO Hidden_Surface_Plot ; Set up variables for the plot. Normally, these values would be ; passed into the program as positional and keyword parameters. peak = Shift(Dist(20,16), 10, 8) peak = Exp( -(peak / 5.0)^2) saddle = Shift(peak,6,0) + Shift(peak,-6, 0) / 2 ; Open a display window. cgDisplay, 640, 512 ; It is essential to position axes in the Z-buffer with the POSITION keyword ; because there is a difference in character size in the Z-graphics buffer, which ; can move axes as you move back and forth from one graphics device to another. position = [0.125, 0.1, 0.9, 0.9, 0.1, 1.0] ; For this example, we will use the Z-buffer as an 8-bit device that uses index color mode. ; Go into the Z-buffer and set it up. thisDevice = !D.Name Set_Plot, 'Z' Device, Set_Resolution=[640, 512], Z_Buffer=1, Decomposed=0, Set_Pixel_Depth=8 ; Load the colors we are going to use for the two surfaces. cgLoadCT, 1, NColors=100, Bottom=1 cgLoadCT, 3, NColors=100, Bottom=101 black = cgColor('black', 253) white = cgColor('white', 254) ; Draw the first surface, using the first 100 colors. Do not draw the surface axes. ; We will do this later outside the Z-buffer. Set_Shading, Values=[1,100] Shade_Surf, peak, ZRange=[0.0, 1.2], Color=black, Background=white, $ Position=position, XStyle=4, YStyle=4, ZStyle=4 ; Draw the second surface, using the next 100 colors. Set_Shading, Values=[101,200] Shade_Surf, saddle, ZRange=[0.0, 1.2], /NoErase, Color=black, $ Position=position, XStyle=4, YStyle=4, ZStyle=4 ; Get the current color vectors and take a snapshot of the Z-buffer window. TVLCT, r, g, b, /Get snapshot = TVRD() ; Now return to the current device and display the hidden surface as an image and add ; the axes to it. Set_Plot, thisDevice cgImage, snapshot charsizeFactor = (!D.Name EQ 'PS') ? 2.0 : 1.5 cgSurf, peak, /NoData, /NoErase, ZRange=[0,1.2], Position=position, $ Charsize=cgdefcharsize()*charsizeFactor, $ XTitle='X Title', YTitle='Y Title', ZTitle='Z Title' END ;***************************************************************** ; This main program shows how to call the program and produce ; various types of output. ; Display the plot in a graphics window. Hidden_Surface_Plot ; Display the plot in a resizeable graphics window. cgWindow, 'Hidden_Surface_Plot', WTitle='Hidden Surface Plot in a Resizeable Graphics Window' ; Create a PostScript file. cgPS_Open, 'hidden_surface_plot.ps' Hidden_Surface_Plot cgPS_Close ; Create a PNG file with a width of 600 pixels. cgPS2Raster, 'hidden_surface_plot.ps', /PNG, Width=600 END