📄 dicomviewerimage__define.pro
字号:
;
; CLASS - DicomViewerImage
;
; SUPERCLASSES - IDLgrImage
;
; PURPOSE - Displaying a dicom image.
;
; METHODS:
; Init - lifecycle method
; Cleanup - lifecycle method
; GetContext - Obtain reasonable context menu items and indicate
; grayed out items (sensitivity).
; DefaultZoom - Return reasonable default viewplane rectangle to
; display image.
; GetCurrentView - If this image is contained in a view the view
; object reference is returned.
; ContextEvent - Take appropriate action based on a menu selection.
;
; Import - This method will read from an IDLffDicomEx object and
; populate the fields needed for correct display of
; images.
;
; DefaultWL - Set a default window level for 16-bit image.
;
; GetProperty - Return a current property value.
;
; SetProperty - Set a property value.
;
; Modification History - 17 May 2004, Written, Atle Borsholm
; April 2005 : Added MONOCHROME1 case to Import
; method. DSA
;
;----------------------------------------------------------------------
;----------------------------------------------------------------------
; IDLffDICOMEx::GetValueDefault
;+
; A quick way to add functionality to an existing class. Rather than
; subclass IDLffDICOMEx to add this one little method, extend the class
; for this session by adding the method directly.
;
; @returns A default value if the requested tag is not in the file.
;
; @param tag {in}{type=string} The requested DICOM tag.
; @param def {in}{type=any} The default to return if the tag is not present.
;-
function IDLffDICOMEx::GetValueDefault, tag, def
if self->QueryValue(tag) ne 2 then return, def else return, self->GetValue(tag)
end
;
; Lifecycle methods:
;
;----------------------------------------------------------------------
; DicomViewerImage::Init
;+
; @returns True (1) if the object is successfully created.
;
; @keyword _REF_EXTRA {in}{type=any} Keywords given are applied to the
; superclass (IDLgrImage).
;-
function DicomViewerImage::Init, _REF_EXTRA=extra
res = self->IDLgrImage::Init(_EXTRA=extra)
self.orig = ptr_new(/ALLOCATE_HEAP)
return, res
end
;----------------------------------------------------------------------
; DicomViewerImage::Cleanup
;+
; Free any memory used by this object.
;-
pro DicomViewerImage::Cleanup
ptr_free, self.orig
self->IDLgrImage::Cleanup
end
;
; Public Methods:
;
;----------------------------------------------------------------------
; DicomViewerImage::GetContext
;+
; Get current settings for context sensitive menu items. This returns
; the items on the image popup menu and they are used to adjust the
; application menu and toolbar accordingly.
;
; @keyword MENU {out}{type=string vector} Menu item names.
; @keyword ARG {out}{type=string vector} Internal menu names (see UVALUES).
; @keyword SENSITIVE {out}{type=byte vector} True (1) is corresponding menu
; is currently sensitive, otherwise false (0).
; @keyword COUNT {out}{type=scalar} Number of menu items.
;-
pro DicomViewerImage::GetContext, MENU=menu, ARG=arg, SENSITIVE=sensitive, COUNT=count
count = 9 ;; number of menu items
; Return the menu item text
if arg_present(menu) then begin ;; insert & on windows
amp = (!version.os_family eq 'unix')?'':'&'
menu = [amp+'Open with iImage','Reset '+amp+'Zoom (left click and drag to zoom)','Reset '+amp+'Windowlevel',$
'Windowlevel to '+amp+'current frame','Open multiframe with i'+amp+'Volume', $
amp+'Next Frame',amp+'Previous Frame', 'Start/stop '+amp+'animate frames (Cine)', $
amp+'Anonymize Selected File']
endif
; Return the internal menu item names
if arg_present(arg) then arg=['iimage','resetzoom','windowlevel',$
'wl_frame','ivolumemf','next','previous','cine', $
'anonymize']
; Return a vector indicating which menu items are currently sensitive.
if arg_present(sensitive) then begin
sensitive=bytarr(count)+1b
if (self.nframes le 1) then sensitive[[3,4,7]]=0b
if self.nframes eq 0 then sensitive[0:8] = 0b
; Gray out resetzoom if zoom is out
self->GetProperty, DIMENSIONS=dim
view = self->GetCurrentView()
view->GetProperty, VIEWPLANE_RECT=zoom
if array_equal(zoom, [0,0,dim]) then sensitive[1]=0b
; Gray out reset windowlevel if it is needed
if self.wl_type && array_equal(self.win_level,self.win_dcm) then sensitive[2]=0b
; Gray out next/previous
if (self.nframes eq 1) then sensitive[5:6]=0b $
else if (self.currentframe eq 0) then sensitive[6]=0b $
else if (self.currentframe eq self.nframes-1) then sensitive[5]=0b
endif
end
;----------------------------------------------------------------------
; DicomViewerImage::DefaultZoom
;+
; @returns The default viewplane rect.
;-
function DicomViewerImage::DefaultZoom
self->GetProperty, DIMENSIONS=dim
return, (max(dim)-[dim,0,0])*[-.5,-.5,1,1]
end
;----------------------------------------------------------------------
; DicomViewerImage::GetCurrentView
;+
; @returns The current View object reference.
;-
function DicomViewerImage::GetCurrentView
obj = self.parent
while obj_valid(obj) do begin
if obj_isa(obj,'idlgrview') then break
obj->GetProperty, PARENT=obj
endwhile
return, obj
end
;----------------------------------------------------------------------
; DicomViewerImage::ContextEvent
;+
; Process a context menu event.
;
; @param arg {in}{type=string} Internal menu item name.
;-
pro DicomViewerImage::ContextEvent, arg
case arg of
'iimage': begin
iimage, REFORM(REVERSE((*self.orig)[*,*,*,self.currentframe],$
(self.planar) ? 2 : 3 ))
end
'resetzoom': begin
view = self->GetCurrentView()
if ~obj_valid(view) then return
view->SetProperty, VIEWPLANE_RECT=self->DefaultZoom()
end
'windowlevel': begin
self->DefaultWL
self->SetProperty, FRAME=self.currentframe
end
'wl_frame': begin
mini = min((*self.orig)[*,*,*,self.currentframe], MAX=maxi)
self.win_level = [DOUBLE(maxi)+mini,maxi-mini]/2
self->SetProperty, frame=self.currentframe
end
'ivolumemf': ivolume, bytscl(REFORM(*self.orig))
'next': self->SetProperty, frame= ++self.currentframe
'previous': self->SetProperty, frame= --self.currentframe
'cine': begin
self.currentframe = (self.currentframe+1) mod self.nframes
self->SetProperty, frame=self.currentframe
end
else:
endcase
end
;----------------------------------------------------------------------
; DicomViewerImage::Import
;+
; Read a DICOM file and extract the tags necessary to display the
; images within it.
;
; @param o {in}{type=IDLffDICOMEx object reference} The file to display.
;-
pro DicomViewerImage::Import, o
self.samples = o->GetValueDefault('0028,0002',1)
self.photo = o->GetValueDefault('0028,0004','')
self.planar = o->GetValueDefault('0028,0006',0)
self.nframes = o->GetValueDefault('0028,0008',1)
self.rows = o->GetValueDefault('0028,0010',0)
self.cols = o->GetValueDefault('0028,0011',0)
self.bitsalloc = o->GetValueDefault('0028,0100',8)
self.pixelrep = o->GetValueDefault('0028,0103',0)
; Reset currentframe
self.currentframe = 0
; File rescale slope and intercept and window level and width factors
self.rescale = DOUBLE([(o->GetValueDefault('0028,1052',0))[0], (o->GetValueDefault('0028,1053',1))[0]])
self.win_dcm = DOUBLE([(o->GetValueDefault('0028,1050',0))[0], (o->GetValueDefault('0028,1051',0))[0]])
; Read in the pixeldata
if o->QueryValue('7fe0,0010') ne 2 then return
data = o->GetPixelData(/ORDER)
n=n_elements(data)
; Calculate dimensions
if (self.planar eq 1) && (self.samples GT 1) then begin ;; plane interleave
dims = [self.cols,self.rows,self.samples,self.nframes]
self->setproperty, INTERLEAVE=2
endif else begin ;; pixel interleave
self.planar = 0
dims = [self.samples,self.cols,self.rows,self.nframes]
self->setproperty, INTERLEAVE=0
endelse
; Find expected datatype
case self.bitsalloc/8 of
1: type = 1 ; byte
2: type = 12-10*self.pixelrep ; unsigned or signed short
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -