3421
Example of How to Add an Axis to a Surface Object
This is a continuation of the Help Article ‘A Simple Surface Object Example’. This example will show you how to create a simple surface object that has an X, Y, and Z axis.
Discussion:
This is an example of how to extend a basic Surface Object. We are going to add the axis to our Surface.
As you can see, in addition to our original surface object you just need to add this segment of code, to get your axis:
; add X, Y and Z axis to your surface
; use the DIRECTION keyword, to set the direction of the axis
; set the LOCATION keyword to the minimum value except for the Z axis
; set the Z axis at y-max (so that it doesn't block the view of the surface).
oXaxis = OBJ_NEW('IDLgrAxis', DIRECTION=0, RANGE=xr, $
XCOORD_CONV=xs, YCOORD_CONV=ys, ZCOORD_CONV=zs, $
LOCATION=[xr[0], yr[0], zr[0]] )
oYaxis = OBJ_NEW('IDLgrAxis', DIRECTION=1, RANGE=yr, $
XCOORD_CONV=xs, YCOORD_CONV=ys, ZCOORD_CONV=zs, $
LOCATION=[xr[0], yr[0], zr[0]] )
oZaxis = OBJ_NEW('IDLgrAxis', DIRECTION=2, RANGE=zr, $
XCOORD_CONV=xs, YCOORD_CONV=ys, ZCOORD_CONV=zs, $
LOCATION=[xr[0], yr[1], zr[0]] )
NOTE: code to be added to this segment is in BOLD
; add the surface and the axis to the model, and the model to the view
oModel->add, oSurface
oModel->Add, oXaxis
oModel->Add, oYaxis
oModel->Add, oZaxis
oView->Add, oModel
; rotate for better view of your surface and axis
oModel->rotate, [1, 0, 0], -90
oModel->rotate, [0, 1, 0], 30
oModel->rotate, [1, 0, 0], 30
Example:
PRO mySurface2
; create data
data = dist(100)
; create your model, your view, and your surface
oModel = obj_new('IDLgrModel')
oView = obj_new('IDLgrView')
oSurface = obj_new('IDLgrSurface', data, STYLE=1, $
SHADING=0, COLOR = [0, 0, 255])
; add axis to your surface
oSurface->GetProperty, XRANGE=xr, YRANGE=yr, ZRANGE=zr
; Calculating normalized conversion factors and shifting
; -.5 in every direction
; Keep in mind that your view default coordinate system
; is [-1,-1], [1, 1]
xs = NORM_COORD(xr)
xs[0] = xs[0] - 0.5
ys = NORM_COORD(yr)
ys[0] = ys[0] - 0.5
zs = NORM_COORD(zr)
zs[0] = zs[0] - 0.5
oSurface->SetProperty, XCOORD_CONV=xs, YCOORD_CONV=ys, ZCOORD_CONV=zs
oXaxis = OBJ_NEW('IDLgrAxis', DIRECTION=0, RANGE=xr, $
XCOORD_CONV=xs, YCOORD_CONV=ys, ZCOORD_CONV=zs, $
LOCATION=[xr[0], yr[0], zr[0]])
oYaxis = OBJ_NEW('IDLgrAxis', DIRECTION=1, RANGE=yr, $
XCOORD_CONV=xs, YCOORD_CONV=ys, ZCOORD_CONV=zs, $
LOCATION=[xr[0], yr[0], zr[0]])
oZaxis = OBJ_NEW('IDLgrAxis', DIRECTION=2, RANGE=zr, $
XCOORD_CONV=xs, YCOORD_CONV=ys, ZCOORD_CONV=zs, $
LOCATION=[xr[0], yr[1], zr[0]])
; add the surface to the model, and the model to the view
oModel->add, oSurface
oModel->Add, oXaxis
oModel->Add, oYaxis
oModel->Add, oZaxis
oView->Add, oModel
; rotate for better view of your surface
oModel->rotate, [1, 0, 0], -90
oModel->rotate, [0, 1, 0], 30
oModel->rotate, [1, 0, 0], 30
; create a window and draw the view of your Surface object
oWindow = obj_new('IDLgrWindow')
oWindow->Draw, oView
end