📄 anonymizer__define.pro
字号:
;
; CLASS - Anonymizer
;
; SUPERCLASS - None
;
; PURPOSE - For anonymizing DICOM files.
;
; METHODS:
; Anonymize - Create anonymized copy of current DICOM file.
;
; Check_VR_Value - Determines if value can be used to represent
; a specific value representation.
;
; Cleanup - Lifecycle method.
;
; Define_Tags - Adds/Removes tags from the list of tags to be
; anonymized.
;
; Get_Default_VR_Value - Retrives the default value for a given
; value representation.
;
; Get_Dicom_Value_String - Returns the value from the current
; DICOM file for a given attribute tag.
;
; GetProperty - Return a current property value.
;
; Init - Lifecycle method
;
; Make_Structure - Creates a structure from a string array
; containing standard DICOM attribute tags.
;
; Query_Wizard - Checks to see if wizard is currently active.
;
; Reset - Resets output tag values to the Anonymizer defaults.
;
; Restore_Preferences - Restores user preferences saved from a
; previous session.
;
; Save_Preferences - Saves the current preferences to be used in
; the future.
;
; Set_VR_Value - Modifies default tag values per VR (Value
; Representation)
;
; SetProperty - Set a property value.
;
; Wizard - Start the Anonymizer wizard.
;
; Modification History - June 2005, Written: Daryl Atencio
;
;*********************************************************************
;*********************************************************************
; Anonymizer::Anonymize
;+
;
; Uses current Anonymizer settings (DYNAMIC_TAGS and
; STATIC_TAGS) to create an anonymized Dicom file.
;
; @returns The name (Including path) of the anonymized
; file. Returns '' otherwise.
;
; @keyword WIZARD {in}{type=boolean} Set this keyword to
; launch the anonymization wizard.
;
;-
function anonymizer::anonymize, $
wizard = wizard
; Has ODICOM been initialized?
if ~obj_valid(self.odicom) then $
return, ''
if keyword_set(wizard) && ~self.no_block then begin
; Launch the anonymizer wizard.
self -> wizard, /from_anonymize
; Object was destroyed while wizard was active:
if ~obj_valid(self) then $
return, ''
if ~self.wizard_cont then $
return, ''
self.wizard_cont = 0
endif
for f = 1, 2 do begin
; F = 1 : Dynamic Tags
; F = 2 : Static Tags
for i = 0, n_elements(*self.(f))-1 do begin
err = 0
catch, err
if err ne 0 then begin
catch, /cancel
continue
endif
; Write the information from the Static/Dynamic structre
; to the Dicom file.
if (*self.(f))[i].flag gt 0+self.value_only then begin
vr = self.odicom -> getvr((*self.(f))[i].tag)
self.odicom -> setvalue, (*self.(f))[i].tag, vr, $
(*self.(f))[i].value
endif
endfor
endfor
; Commit changes.
self.odicom -> commit
self.odicom -> getproperty, sop_instance_uid = uid
; Output filename:
anon_file = self.outdir + self.outfile_prefix + $
uid + self.outfile_extension
; Rename the output file.
file_move, self.tempfile, anon_file
; Return the name of the output file.
return, anon_file
end
;*********************************************************************
; Anonymizer::Check_VR_Value
;+
;
; Determines whether a value can be used to represent a
; specific value representation.
;
; @returns 1 if VAL can be converted to the type specified
; by a keyword input and 0 otherwise
;
; @param VAL {in}{type=any}
;
; @keyword BYTE_VAL {out}{type=byte} Returns byte representation of VAL.
; @keyword DOUBLE_VAL {out}{type=double} Returns double representation
; of VAL
; @keyword FLOAT_VAL {out}{type=float} Returns float represenations of
; VAL
; @keyword INT_VAL {out}{type=integer} Returns integer represenations
; of VAL
; @keyword LONG_VAL {out}{type=long integer} Returns long integer
; represenations of VAL
; @keyword STRING_VAL {out}{type=string} Returns string represenations
; of VAL
; @keyword UINT_VAL {out}{type=unsigned integer} Returns integer
; represenations of VAL
; @keyword ULONG_VAL {out}{type=unsigned long integer} Returns unsigned
; long integer represenations of VAL
;
; @private
;-
function anonymizer::check_vr_value, val, $
byte_val = bv, $
double_val = dv, $
float_val = fv, $
int_val = iv, $
long_val = lv, $
string_val = sv, $
uint_val = uiv, $
ulong_val = ulv
err = 0
catch, err
if err ne 0 then begin
catch, /cancel
return, 0
endif
if arg_present(bv) then $
bv = byte(val)
if arg_present(dv) then $
dv = double(val)
if arg_present(fv) then $
fv = float(val)
if arg_present(iv) then $
iv = fix(val)
if arg_present(lv) then $
lv = long(val)
if arg_present(sv) then $
sv = string(val)
if arg_present(uiv) then $
uiv = uint(val)
if arg_present(ulv) then $
ulv = ulong(val)
return, 1
end
;*********************************************************************
; Anonymizer::Cleanup
;+
;
; Free any memory used by this object.
;
;-
pro anonymizer::cleanup
if obj_valid(self.odicom) then $
obj_destroy, self.odicom
if obj_valid(self.wizard) then begin
obj_destroy, self.wizard
endif
ptr_free, self.static_tags, $
self.dynamic_tags
end
;*********************************************************************
; Anonymizer::Define_Tags
;+
;
; Used to add/remove tags from the list of attribute tags to be anonymized.
;
; @param TAGS {in}{type=string} Tags to be added/removed from the
; anonymizer.
;
; @keyword NO_WIZARD_UPDATE {in}{type=boolean} If this keyword is set,
; the wizard will not update according to the changes made
; by this method.
; @keyword REMOVE {in}{type=boolean} Set to True (1) to remove TAGS from
; the list to be anonymized. Set to False (0) to add TAGS
; to the list of tags to be anonymized.
;
;
;-
pro anonymizer::define_tags, tags, $
remove = remove, $
no_wizard_update = nw
; No file specified?
if ~obj_valid(self.odicom) then $
return
nt = n_elements(tags)
; No tags?
if nt lt 1 then $
return
remove = keyword_set(remove)
case size(tags, /type) of
7: if ~remove then begin
tags = self->make_structure(tags)
endif
8: begin
if ~array_equal(strlowcase(tag_names(tags[0])), $
['desc','tag','value','flag']) then $
return
if remove then $
tags = tags.tag $
else begin
tags = tags[uniq(tags.tag, sort(tags.tag))]
nt = n_elements(tags)
for i = 0, nt-1 do begin
err = 0
catch, err
if err ne 0 then begin
catch, /cancel
help, /last
continue
endif
tags[i].flag = self.odicom -> queryvalue((tags[i]).tag)
if (tags[i].flag ge 1) then $
tags[i].desc = self.odicom -> getdescription((tags[i]).tag) $
else $
tags[i].desc = ''
endfor
endelse
end
else: return
endcase
if remove then begin
; Removing tags...
nd = n_elements(*self.dynamic_tags)
; No dynamic tags defined
if nd eq 0 then $
return
ind = bytarr(nd)+1
for i = 0, nt-1 do begin
w = where((*self.dynamic_tags).tag eq tags[i])
if w[0] ne -1 then $
ind[w] = 0
endfor
ti = total(ind)
if ti lt nd then begin
if ti eq 0 then begin
ptr_free, self.dynamic_tags
self.dynamic_tags = ptr_new(/allocate)
endif else begin
*self.dynamic_tags = (*self.dynamic_tags)[where(ind)]
endelse
endif
; Remove tags from wizard if active:
if ~keyword_set(nw) then $
if (self.wizard->query_wizard_dialog()) then $
for i = 0, n_elements(tags)-1 do $
self.wizard -> remove_tag_base, tags[i]
endif else begin
; Adding tags...
; Check STATIC_TAGS...
ind = bytarr(nt)+1
for i = 0, nt-1 do begin
w = (where((*self.static_tags).tag eq (tags[i]).tag))[0]
if w ne -1 then begin
ind[i] = 0
(*self.static_tags)[w].value = tags[i].value
endif
endfor
; Remove static elements from TAGS
w = where(ind)
if w[0] eq -1 then $
return
tags = tags[w]
; Check DYNAMIC_TAGS
if n_elements(*self.dynamic_tags) gt 0 then begin
nt = n_elements(tags)
ind = bytarr(nt)+1
for i = 0, nt-1 do begin
w = (where((*self.dynamic_tags).tag eq tags[i].tag))[0]
if w ne -1 then begin
ind[i] = 0
(*self.dynamic_tags)[w].value = tags[i].value
endif
endfor
w = where(ind)
if w[0] eq -1 then $
return
*self.dynamic_tags = [*self.dynamic_tags, tags[w]]
endif else begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -