HBITMAP DPlot_GetBitmapEx(int DocNum, int cx, int cy, DPLOT_PLOTMETRICS *DPM);
Parameters
Return Values
|
Remarks
Palette information is not returned, so this function does not work particularly well with 256 (or fewer) color displays.
Example usage in demo programs:
Visual Basic 6: |
\btest\btest2 |
Visual C 5/6: |
\c\msvc\ctest2 |
Visual Basic .NET: |
\vbnet\Project2.NET |
Visual C#: |
\csharp\test2 |
DPLOT_PLOTMETRICS
There are 2 versions of this structure available in DPLOTLIB.DLL version 2.1.0.6 and later. The newer version uses double-precision (8 byte) floating point values, and data is passed from DPlot to DPLOTLIB.DLL in its native format. Using the old version of the structure, data is passed as character strings to DPLOTLIB.DLL and translated there to single-precision (4 byte) floating point. In general the old format is sufficient for most needs. However, if you use a date and time scale on the X axis, or if your data otherwise consists of large numbers with a relatively small difference between the low and high values, the new version should be used. To ensure that the end user has the needed version of DPlot or DPlot Jr, your application should call DPlot_MinVersion(2,1,4,0).
Example programs distributed with DPLOTLIB.DLL and DPlot Jr all use the new version of this structure.
New Version, requires DPLOTLIB.DLL version 2.1.0.6 or later, and DPlot or DPlot Junior version 2.1.4 or later.
In C:
typedef struct tagDPLOT_PLOTMETRICS
{
DWORD size; // size of this structure; should be set by the caller
int hll; // horizontal and
int vll; // vertical coordinates of the lower left corner of
// the plot, in pixels
int hur; // horizontal and
int vur; // vertical coordinates of the upper right corner of
// the plot, in pixels
int dummy; // not used; only for member alignment
double xlo; // value of X at the left plot extent
double ylo; // value of Y at the bottom plot extent
double xhi; // value of X at the right plot extent
double yhi; // value of Y at the top plot extent
double stretch[3]; // scale factors for X, Y, and Z w/ 3D plots
double scale; // scale factor for projection of 3D points
double azimuth; // view angles for 3D views, radians
double elevation;
double ylo2; // Y extents of 2nd Y axis, if any
double yhi2;
} DPLOT_PLOTMETRICS
In Visual Basic:
Type DPLOT_PLOTMETRICS
size As Long ' size of this structure
hll As Long ' horizontal and
vll As Long ' vertical coordinates of the lower left corner of
' the plot, in pixels
hur As Long ' horizontal and
vur As Long ' vertical coordinates of the upper right corner of
' the plot, in pixels
dummy As Long ' not used; only for member alignment
xlo As Double ' value of X at the left plot extent
ylo As Double ' value of Y at the bottom plot extent
xhi As Double ' value of X at the right plot extent
yhi As Double ' value of Y at the top plot extent
stretch(3) As Double ' scale factors for X, Y, and Z w/ 3D plots
scale As Double ' scale factor for projection of 3D points
azimuth As Double ' view angles for 3D views, radians
elevation As Double
ylo2 As Double ' Y extents of 2nd Y axis, if any
yhi2 As Double
End Type
Old Version. Works with any version of DPLOTLIB.DLL and DPlot or DPlot Jr.
In C:
typedef struct tagDPLOT_PLOTMETRICS
{
DWORD size; // size of this structure; should be set by the caller
int hll; // horizontal and
int vll; // vertical coordinates of the lower left corner of
// the plot, in pixels
int hur; // horizontal and
int vur; // vertical coordinates of the upper right corner of
// the plot, in pixels
float xlo; // value of X at the left plot extent
float ylo; // value of Y at the bottom plot extent
float xhi; // value of X at the right plot extent
float yhi; // value of Y at the top plot extent
float stretch[3]; // scale factors for X, Y, and Z w/ 3D plots
float scale; // scale factor for projection of 3D points
float azimuth; // view angles for 3D views, radians
float elevation;
float ylo2; // Y extents of 2nd Y axis, if any
float yhi2;
} DPLOT_PLOTMETRICS
In Visual Basic:
Type DPLOT_PLOTMETRICS
size As Long ' size of this structure
hll As Long ' horizontal and
vll As Long ' vertical coordinates of the lower left corner of
' the plot, in pixels
hur As Long ' horizontal and
vur As Long ' vertical coordinates of the upper right corner of
' the plot, in pixels
xlo As Single ' value of X at the left plot extent
ylo As Single ' value of Y at the bottom plot extent
xhi As Single ' value of X at the right plot extent
yhi As Single ' value of Y at the top plot extent
stretch(3) As Single ' scale factors for X, Y, and Z w/ 3D plots
scale As Single ' scale factor for projection of 3D points
azimuth As Single ' view angles for 3D views, radians
elevation As Single
ylo2 As Single ' Y extents of 2nd Y axis, if any
yhi2 As Single
End Type
Using DPLOT_PLOTMETRICS
The information returned in this structure can be used to translate pixel coordinates (mouse position, for example) into X,Y coordinates in data space. The btest2 Visual Basic and ctest2 C demos illustrate this functionality for linear scales. Translating pixels to X and Y for various scaling types is described below in Visual Basic terminology. In all cases, x and y are the pixel coordinates of interest (0,0 is at the upper left corner of the bitmap), wx and wy are the translated X and Y values; DPM is the DPLOT_PLOTMETRICS structure returned by DPlot_GetBitmapEx. Reverse scaling probability plots is outside the scope of this documentation.
Linear X:
wx = DPM.xlo + (x - DPM.hll) * (DPM.xhi - DPM.xlo) /(DPM.hur - DPM.hll)
Linear Y:
wy = DPM.ylo + (y - DPM.vll) * (DPM.yhi - DPM.ylo) / (DPM.vur - DPM.vll)
Logarithmic X:
wx = DPM.xlo * (DPM.xhi/DPM.xlo) ^ ( (x-DPM.hll)/(DPM.hur-DPM.hll) )
Logarithmic Y:
wy = DPM.ylo * (DPM.yhi/DPM.ylo) ^ ( (y-DPM.vll)/(DPM.vur-DPM.vll) )
Polar coordinates:
xp = ( x - ( DPM.hll +DPM.hur )/2. ) * 2.0 * _
( DPM.yhi - DPM.ylo ) / ( DPM.hur - DPM.hll ) + DPM.ylo
yp = ( y - ( DPM.vll +DPM.vur )/2. ) * 2.0 * _
( DPM.yhi - DPM.ylo ) / ( DPM.vur - DPM.vll ) + DPM.ylo
If xp = 0 Then
If yp < 0 Then
alpha = -90
Else
alpha = 90
End If
Elseif xp < 0 then
alpha = atn(yp/xp) * 180. / PI - 180.
Else
alpha = atn(yp/xp) * 180. / PI
End If
If alpha < 0. Then
alpha = 360 + alpha
End If
radius = sqr(xp^2 + yp^2)
Triangle plot:
wy = 100 * (DPM.vll-y) / (DPM.vll-DPM.vur)
wx = 100 * ( (x-DPM.hll) - 0.01*wy*(DPM.vll-DPM.vur)*0.5773502691896) / _
(DPM.hur-DPM.hll)
N185 Hydraulic scale:
wx = ( (x - DPM.hll) * (DPM.xhi^1.85 - DPM.xlo^1.85) / _
(DPM.hur-DPM.hll) + DPM.xlo^1.85 )^(1.0/1.85)
Getting pixel values for projected 3D points
This procedure might be useful if you want to draw your own symbols or other graphics on a bitmap of a 3D projection returned by DPlot. The following example is in Visual Basic:
Dim DPM As DPLOT_PLOTMETRICS
Dim ct(3) As Double
Dim st(3) As Double
Private Sub AngleTransforms()
Dim roll As Double
Dim yaw As Double
If (DPM.azimuth = PI / 2) Then
ct(2) = 0
st(2) = 1
ElseIf (DPM.azimuth = 3 * PI / 2) Then
ct(2) = 0
st(2) = -1
Else
ct(2) = Cos(DPM.azimuth)
st(2) = Sin(DPM.azimuth)
End If
roll = DPM.elevation * st(2)
yaw = 1.5 * PI + DPM.elevation * ct(2)
' Find angles from midpoint to viewpoint:
ct(0) = Cos(yaw)
st(0) = Sin(yaw)
ct(1) = Cos(roll)
st(1) = Sin(roll)
' Force roll angle to keep vertical lines vertical
If (ct(2) <> 0 And st(0) <> 0) Then
st(1) = -st(2) * ct(0) / (ct(2) * st(0))
If (Abs(st(1)) >= 1) Then
If (st(1) < 0) Then
st(1) = -1
Else
st(1) = 1
End If
Else
ct(1) = Sqr(1 - st(1) * st(1))
End If
End If
End Sub
Private Sub Transform3D(Xin As Double, Yin As Double, Zin As Double, pt As POINTAPI)
Dim X, Y, Z As Double
Dim xa, xb, ya, yb, za, zb As Double
Dim h As Double ' Horizontal projection
Dim v As Double ' Vertical projection
Dim d As Double ' Depth into screen
' "stretch" coordinates. These values correspond to the X, Y, and Z scale factors
' on DPlot's Contour Options dialog.
X = Xin * DPM.stretch(0)
Y = Yin * DPM.stretch(1)
Z = Zin * DPM.stretch(2)
' 3D to 2D transformation
' yaw
xa = ct(0) * X - st(0) * Z
ya = Y
za = st(0) * X + ct(0) * Z
' roll
xb = ct(1) * xa + st(1) * ya
yb = ct(1) * ya - st(1) * xa
zb = za
' azimuth
h = -ct(2) * yb - st(2) * zb
v = xb
d = ct(2) * zb - st(2) * yb
' Now scale h and v to the output:
pt.X = DPM.hll + DPM.scale * (h - DPM.xlo)
pt.Y = DPM.vur + DPM.scale * (DPM.yhi - v)
End Sub
Private Sub DoStuff()
Dim X As Double
Dim Y As Double
Dim Z As Double
Dim pt As POINTAPI
PI = 4# * Atn(1#)
'
' Get a bitmap using DPlot_GetBitmapEx
'
Call AngleTransforms
'
' Get X, Y, Z from text boxes, whatever...
'
Call Transform3D(X, Y, Z, pt)
End Sub
Page url: http://www.dplot.com/lib/index.htm?dplot_getbitmapex.htm