⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chapter10volumerender1.pro

📁 IDL可视化分析与应用的源代码
💻 PRO
📖 第 1 页 / 共 5 页
字号:
; Chapter10VolumeRender1.pro

function Chapter10VolumeRender1TableNames, wild, full_filenames
full_filenames = findfile( $
    demo_filepath(wild, SUBDIR=['examples','demo','demodata']) )
case !version.os of
    'vms': sep = "."
    'Win32': sep = "\"
    'MacOS' : sep = ":"
    else: sep = "/"
    endcase

if STRLEN(wild) gt 1 then begin
    splat_pos = STRPOS(wild, '*')
    if splat_pos gt -1 then $
        clipped_wild = STRMID(wild, splat_pos + 1, 1000)
    end

result = strarr(N_ELEMENTS(full_filenames))
for i=0,N_ELEMENTS(result)-1 do begin
;
;   Assign to 'result' the un-qualified filenames that matched 'wild'.
;
    if (!VERSION.OS_FAMILY eq 'vms') then begin
        result[i] = full_filenames[i]
        bracketPos = RSTRPOS(result[i],']')
        if (bracketPos GE 0) then $
            result[i] = strmid( $
                result[i], $
                bracketPos + 1, $
                STRLEN(result[i]) - bracketPos-1 $
                )
        semicolonPos = STRPOS(result[i],';')
        if (semicolonPos GE 0) then $
            result[i] = strmid( $
                result[i], $
                0, $
                semicolonPos $
                )
        end $
    else begin
        temp = STRTOK(full_filenames[i], sep, /EXTRACT)
        result[i] = temp[N_ELEMENTS(temp) - 1]
        end

    if N_ELEMENTS(clipped_wild) gt 0 then begin
;
;       Reduce 'result' to be the part of the filename masked
;       by the '*' in 'wild' (and any characters preceding '*').
;
        result[i] = STRMID(  result[i], 0, STRPOS( $
                STRUPCASE(result[i]),  STRUPCASE(clipped_wild)) )
        end
;
    end

return, STRLOWCASE(result)
end
;
;----------------------------------------------------------------------------
;
; PURPOSE  Set the color or opacity table.
;
pro Chapter10VolumeRender1SetTable, $
    rVolume, $       ; IN: volume object
    table_type, $    ; IN: 0=color, 1= opacity
    filename, $      ; IN: where to read the table from.
    MULTI_VOLUME=multi_volume ; IN: (optional). Integer.  Enumerate which
                     ;  volume of a multi-volume is to be set.
COMPILE_OPT idl2, hidden

success = 0b
;
;Read the table(color or opacity).
;
GET_LUN, lun
newTable = BYTARR(256,3)

ON_IOERROR, bail_out
OPENR, lun, filename
READU, lun, newTable
CLOSE, lun
FREE_LUN,lun
if N_ELEMENTS(multi_volume) eq 0 then $
    multi_volume = 0

case table_type of
    0 : case multi_volume of ; color
            0: rVolume->SetProperty, RGB_TABLE0=newTable
            1: rVolume->SetProperty, RGB_TABLE1=newTable
            else: MESSAGE, 'Illegal MULTI_VOLUME value.'
        endcase
    1 : case multi_volume of ; opacity
            0: rVolume->SetProperty, OPACITY_TABLE0=newTable
            1: rVolume->SetProperty, OPACITY_TABLE1=newTable
            else: MESSAGE, 'Illegal MULTI_VOLUME value.'
        endcase
endcase
success = 1b
bail_out:
if not success then begin
    FREE_LUN, lun
    help, filename
    print, !error_state.msg
    end
end       ;    of Chapter10VolumeRender1SetTable
;
;----------------------------------------------------------------------------
function Chapter10VolumeRender1LoadVolume, volume_name, rParentModel

GET_LUN,lun ; Get a logical unit number.

case volume_name of

    'Brain': begin
;
;       Read the brain data.
;
        restore, demo_filepath('mri.sav', $ ; vol0
            SUBDIR=['examples','demo','demodata'])

        restore, demo_filepath('pet.sav', $ ; vol1
            SUBDIR=['examples','demo','demodata'])

        volume_select = 1 ; do dual volume rendering
        zc = 1.0
        end
;
    'Cloud': begin
;
;       Read the Electron Cloud data.
;
        vol0 = BYTARR(64, 64, 64)
        OPENR, lun, /XDR, demo_filepath('hipiph.dat', $
            SUBDIR=['examples','demo','demodata'])
        READU, lun, vol0

        CLOSE, lun

        volume_select = 0 ; don't do dual volume rendering
        zc = 1.0
        end
;
    endcase
;
;Create the volume object.
;
FREE_LUN,lun
;

i = SIZE(vol0)
m = i[1] > i[2] > (i[3] * zc)
sx = 1.0 / m            ; scale x.
sy = 1.0 / m            ; scale y.
sz =(1.0 / m) * zc      ; scale z.
ox = -i[1] * sx * 0.5   ; offset x.
oy = -i[2] * sy * 0.5   ; offset y.
oz = -i[3] * sz * 0.5   ; offset z.

rVolume = OBJ_NEW('IDLgrVolume', vol0, xcoord_conv=[ox, sx], $
         ycoord_conv=[oy, sy], zcoord_conv=[oz, sz], /NO_COPY, NAME=volume_name)
if N_ELEMENTS(vol1) gt 0 then rVolume->SetProperty, DATA1=vol1

rVolume->SetProperty, HINT=2 ; Use multiple CPUs, if we can.
rVolume->SetProperty, /ZERO_OPACITY_SKIP, HIDE=1
rVolume->SetProperty, /ZBUFFER, VOLUME_SELECT=volume_select
rParentModel->Add, rVolume

if (volume_name eq 'Heart') then begin
    rVolume->SetProperty, AMBIENT=[130,130,130]
    endif
;
;Return the volume object.
;
RETURN, rVolume

end         ;  Chapter10VolumeRender1LoadVolume
;----------------------------------------------------------------------------
;
; PURPOSE  Invoke draw method for our application's IDLgrWindow.
;
pro Chapter10VolumeRender1Draw, state, QUALITY=quality

if state.suppress_draws then RETURN

if N_ELEMENTS(quality) eq 0 then begin
    state.rWindow->GetProperty, QUALITY=quality
end else begin
    state.rWindow->SetProperty, QUALITY=quality
end
case quality of
    0: begin
        if state.cur eq 1 then begin ; Probability Cloud
;
;           Show the colored wire box in place of the volume.
;
            state.rVolumeArray[1]->SetProperty, HIDE=1
            state.rPartialBox->SetProperty, HIDE=0
            state.rRedSpoke->SetProperty, HIDE=0
            state.rGreenSpoke->SetProperty, HIDE=0
            state.rBlueSpoke->SetProperty, HIDE=0
            state.rOtherObjectArray[0]->GetProperty, HIDE=wire_box_hidden
            state.rOtherObjectArray[0]->SetProperty, HIDE=1
            end

        state.rView->Add, state.rToysModel
        state.rWindow->Draw, state.rView
        state.rView->Remove, state.rToysModel

        if state.cur eq 1 then begin ; Probability Cloud
;
;           Restore the volume in place of the colored wire box.
;
            state.rVolumeArray[1]->SetProperty, HIDE=0
            state.rPartialBox->SetProperty, HIDE=1
            state.rRedSpoke->SetProperty, HIDE=1
            state.rGreenSpoke->SetProperty, HIDE=1
            state.rBlueSpoke->SetProperty, HIDE=1
            state.rOtherObjectArray[0]->SetProperty, HIDE=wire_box_hidden
            end
        end
    1: begin
        tic = systime(1)
        WIDGET_CONTROL, state.wBase, SENSITIVE=0
        WIDGET_CONTROL, /HOURGLASS

        state.rView->Add, state.rToysModel, POSITION=0
        state.rWindow->Draw, state.rView, /CREATE_INSTANCE
        state.rView->Remove, state.rToysModel

        state.an_instance_exists = 1b ; true from now on.

        state.rTransparentView->Add, state.rToysModel
        state.rWindow->Draw, state.rTransparentView, /DRAW_INSTANCE
        state.rTransparentView->Remove, state.rToysModel
;       print, systime(1) - tic, ' Seconds'
        end
    2: begin
        tic = systime(1)
        WIDGET_CONTROL, state.wBase, SENSITIVE=0
        WIDGET_CONTROL, /HOURGLASS

        state.rView->Add, state.rToysModel, POSITION=0
        state.rWindow->Draw, state.rView, /CREATE_INSTANCE
        state.rView->Remove, state.rToysModel

        state.an_instance_exists = 1b ; true from now on.

        state.rWindow->Draw, state.rTransparentView, /DRAW_INSTANCE
;       print, systime(1) - tic, ' Seconds'
        end
    endcase
;
;
state.cursor_stale = 0b ; 3D grapics cursor appearance is up to date.
WIDGET_CONTROL, state.wBase, SENSITIVE=1

end
;----------------------------------------------------------------------------
;
; PURPOSE  Refresh our applications's IDLgrWindow
;
pro Chapter10VolumeRender1Refresh, state

COMPILE_OPT idl2, hidden

state.rWindow->GetProperty, QUALITY=quality
if state.an_instance_exists then $
    case quality of
        0: Chapter10VolumeRender1Draw, state, QUALITY=quality
        1: begin
            state.rTransparentView->Add, state.rToysModel, POSITION=0
            state.rWindow->Draw, state.rTransparentView, /DRAW_INSTANCE
            state.rTransparentView->Remove, state.rToysModel
            end
        2: state.rWindow->Draw, state.rTransparentView, /DRAW_INSTANCE
        endcase $
else $
    Chapter10VolumeRender1Draw, state, QUALITY=quality

end
;----------------------------------------------------------------------------
;
; PURPOSE  Toggle the buton state between off and on.
;
function Chapter10VolumeRender1ToggleState, $
    widgetID         ; IN: button widget identifer.

COMPILE_OPT idl2, hidden

WIDGET_CONTROL, widgetID, GET_VALUE=name

s = STRPOS(name,'(off)')
if (s NE -1) then begin
    STRPUT, name, '(on )', s
    ret = 1
    end $
else begin
    s = STRPOS(name,'(on )')
    STRPUT, name, '(off)', s
    ret = 0
    end

WIDGET_CONTROL, widgetID, SET_VALUE=name
RETURN, ret
end

;----------------------------------------------------------------------------
;
; PURPOSE  Handle GUI events.
;
pro Chapter10VolumeRender1Event, $
    event              ; IN: event structure.

COMPILE_OPT idl2, hidden

WIDGET_CONTROL, event.top, GET_UVALUE=pState

demo_record, event, $
    FILENAME=(*pState).record_to_filename, $
    CW=[ $
        (*pState).wQuality, $
        (*pState).wVolBGroup, $
        (*pState).wAutoRenderButton, $
        (*pState).wLightButton $
        ]

if (TAG_NAMES(event, /STRUCTURE_NAME) eq  $
    'WIDGET_KILL_REQUEST') then begin
    WIDGET_CONTROL, event.top, /DESTROY
    RETURN
    endif
;
;Get the event user value.
;
WIDGET_CONTROL, event.id, GET_UVALUE=uval
;
;Branch to the correct event user value.
;
case uval of
    'HOTKEY' : begin ; Left Mouse-Button Mode.
        case STRUPCASE(event.ch) of
            'U': begin ; unconstrained rotation
                (*pState).lmb_scale = 0
                (*pState).rModelArray[0]->SetProperty, CONSTRAIN=0
                (*pState).rModelArray[1]->SetProperty, CONSTRAIN=0
                WIDGET_CONTROL, (*pState).wLMBMode, SET_DROPLIST_SELECT=0
                end
            'X': begin
                (*pState).lmb_scale = 0
                (*pState).axis = 0
                (*pState).rModelArray[0]->SetProperty, AXIS=0, /CONSTRAIN
                (*pState).rModelArray[1]->SetProperty, AXIS=0, /CONSTRAIN
                WIDGET_CONTROL, (*pState).wLMBMode, SET_DROPLIST_SELECT=1
                end
            'Y': begin
                (*pState).lmb_scale = 0
                (*pState).axis = 1
                (*pState).rModelArray[0]->SetProperty, AXIS=1, /CONSTRAIN
                (*pState).rModelArray[1]->SetProperty, AXIS=1, /CONSTRAIN
                WIDGET_CONTROL, (*pState).wLMBMode, SET_DROPLIST_SELECT=2
                end
            'Z': begin

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -