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

📄 anonymizer__define.pro

📁 DICOM viewer - this software is used to view a set of DICOM images.
💻 PRO
📖 第 1 页 / 共 4 页
字号:

            *self.dynamic_tags = tags

        endelse

    ; Update the 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 -> add_tag, tags[i]

    endelse

end




;*********************************************************************
; Anonymizer::Get_Default_VR_Value
;+
;
; Retrieves the default value for a specified value representation
;
; @returns The current default value for a specific tag.
;
; @param TAG {in}{type=string} A string of the form "gggg,eeee",
;        where gggg and eeee represent the group and element
;        number respectively, for the attribute for which the
;        default is being returned.
;
;-
function anonymizer::get_default_vr_value, tag

    err = 0
    catch, err
    if err ne 0 then begin

        catch, /cancel
        return, ''

    endif

    vr = self.odicom -> getvr(tag)

    case strlowcase(vr) of

        'ae': return, self.attribute_values.ae
        'as': return, self.attribute_values.as
        'at': return, self.attribute_values.at
        'cs': return, self.attribute_values.cs
        'da': return, self.attribute_values.da
        'dl': return, self.attribute_values.dl
        'ds': return, self.attribute_values.ds
        'dt': return, self.attribute_values.dt
        'fl': return, self.attribute_values.fl
        'fd': return, self.attribute_values.fd
        'is': return, self.attribute_values.is
        'lo': return, self.attribute_values.lo
        'lt': return, self.attribute_values._lt
        'ob': return, self.attribute_values.ob
        'of': return, self.attribute_values._of
        'ow': return, self.attribute_values.ow
        'pn': return, self.attribute_values.pn
        'sh': return, self.attribute_values.sh
        'sl': return, self.attribute_values.sl
;                'sq':
        'ss': return, self.attribute_values.ss
        'st': return, self.attribute_values.st
        'tm': return, self.attribute_values.tm
;                'ui':
        'ul': return, self.attribute_values.ul
        'un': return, self.attribute_values.un
        'us': return, self.attribute_values.us
        'ut': return, self.attribute_values.ut
        else: return, 'AAAAnonymous'

    endcase

end




;*********************************************************************
; Anonymizer::Get_Dicom_Value_String
;+
;
; Retrieves the value for a specified tag in the current
; DICOM file.  If this tag is not defined in the file, ''
; is returned.
;
; @returns A string containing the value for a specified tag
;          in the DICOM file.  Returns '' otherwise.
;
; @param TAG {in}{type=string} A scalar string of the form
;        "gggg,eeee", where gggg and eeee represent the group
;        and element number respectively, for the attribute
;        for which the value is being returned.
;
;-
function anonymizer::get_dicom_value_string, tag

    if n_elements(tag) lt 1 then return, ''
    tag = tag[0]

    err = 0
    catch, err
    if err ne 0 then begin

        message, 'Invalid DICOM Attribute Tag : ' + $
            strtrim(tag,2), /continue
        return, ''

    endif

    if self.odicom->queryvalue(tag) eq 2 then $
        return, string(self.odicom -> getvalue(tag)) $
    else $
        return, ''

end




;*********************************************************************
; Anonymizer::GetProperty
;+
;
; Returns the current value of an object property.
;
; @keyword ATTRIBUTE_VALUES {out}{type=structure} Current default attribute
;          values.
; @keyword DYNAMIC_TAGS {out}{type=structure} Dynamic tags to be anonymized.
; @keyword OUTDIR {out}{type=string} Output directory for anonymized file.
; @keyword OUTFILE_EXTENSION {out}{type=string} Output file extension
;          for anonymized file.
; @keyword OUTFILE_PREFIX {out}{type=string} Output file prefix for
;          anonymized file.
; @keyword STATIC_TAGS {out}{type=structure} Static tags to be anonymized.
; @keyword VALUE_ONLY {out}{type=byte} Determines what tags get written to
;          the anonymized file.  If VALUE_ONLY is set to 1 only attribute
;          tags that exist and are defined in the original file are written
;          to the anonymized file.  If VALUE_ONLY is set to 0, then all tags
;          that exist in the orignal file are written to the anonymized file.
;
;-
pro anonymizer::getproperty, $
    dynamic_tags = dtags, $
    static_tags = stags, $
    attribute_values = av, $
    outdir = outdir, $
    outfile_extension = ofe, $
    outfile_prefix = ofp, $
    value_only = vo

    if arg_present(stags) then $
        stags = *(self.static_tags)

    if arg_present(dtags) then begin

        if n_elements(*self.dynamic_tags) gt 0 then $
            dtags = *self.dynamic_tags $
        else $
            dtags = ''

    endif

    if arg_present(av) then $
        av = self.attribute_values

    if arg_present(outdir) then $
        outdir = self.outdir

    if arg_present(ofe) then $
        ofe = self.outfile_extension

    if arg_present(ofp) then $
        ofp = self.outfile_prefix

    if arg_present(vo) then $
        vo = self.value_only

end




;*********************************************************************
; Anonymizer::Init
;+
;
; @returns True (1) if the object is successfully created and
;          False (0) otherwise.
;
; @param FILE {in}{type=string} Dicom file to be anonymized.
;
; @keyword FROM_APPLICATION {in}{type=boolean} Anonymizer was launched
;          from an application.
; @keyword NO_BLOCK {in}{type=boolean} Set to 0 to have the Anonymizer
;          Wizard block.  Set to 1 for no blocking.
; @keyword VALUE_ONLY {in}{type=byte} Sets the VALUE_ONLY field of
;          the class structure.  If VALUE_ONLY is set to 1 only attribute
;          tags that exist and are defined in the original file are written
;          to the anonymized file.  If VALUE_ONLY is set to 0, then all tags
;          that exist in the orignal file are written to the anonymized file.
;-

function anonymizer::init, file, $
    value_only = val_only, $
    from_application = fa, $
    no_block = nb

    authordirname = 'rsi'
    authordesc = 'Research Systems, Inc.'
    appdirname = 'anonymizer'
    appdesc = 'Anonymizes DICOM files.'
    appreadmetext = ['Author: rsi', $
        'Anonymizer application preferences are stored in this directory']
    appreadmeversion = 1
    dir = app_user_dir(authordirname, authordesc, appdirname, $
        appdesc, appreadmetext, appreadmeversion)

    self.pref_file = dir + path_sep() + 'anonymizer_prefs.dat'

    self.value_only = keyword_set(val_only)
    cd, c = d & self.outdir = d + path_sep()

    self.static_tags = ptr_new(/allocate)
    self.dynamic_tags = ptr_new(/allocate)

    self.default_att_values = {attribute_values, $
                               'Anonymous', $
                                '00', $
                                [0u,0], $
                                'ANONYMOUS', $
                                '19000101', $
                                '----------------', $
                                '19000101000000', $
                                !values.f_nan, $
                                !values.d_nan, $
                                '------------', $
                                'Anonymous', $
                                'Anonymous', $
                                0b, $
                                !values.f_nan, $
                                0, $
                                'Anonymous', $
                                'Anonymous', $
                                0l, $
                                0, $
                                'Anonymous', $
                                '000000', $
                                0ul, $
                                0b, $
                                0u, $
                                'Anonymous'}

    self.no_block = keyword_set(nb)

    self.wizard = obj_new('awizard', self, $
        user_pref = self->restore_preferences(), $
        no_block = keyword_set(nb), $
        from_application = keyword_set(fa))

    if n_elements(file) gt 0 then $
        self -> setproperty, file = file

    self.wizard_cont = 0

    return, 1

end




;*********************************************************************
; Anonymizer::Make_Structure
;+
;
; Creates a structure to be used by Anonymizer from a scalar string or
; a string array containing attribute tags.
;
; @param S {in}{type=string} Scalar string or string array from which
;           the anonymizer structure is created.
;
; @private
;
;-

function anonymizer::make_structure, s
; Creates a structure from a string array

    compile_opt hidden

    s = s[uniq(s, sort(s))]

    ns = n_elements(s)

    if ns lt 1 then $
        return, ''

    str = {desc:'', tag:'', value:'', flag:1b}
    tag_structures = replicate(str,ns)

    for i = 0, ns-1 do begin

        err = 0
        catch, err
        if err ne 0 then begin

            tag_structures[i].flag = 0
            catch, /cancel
            message, 'Invalid DICOM Attribute Tag : ' + $
                strtrim(tag_structures[i].tag,2), /cont
            continue

        endif

        tag_structures[i].tag = s[i]
        tag_structures[i].flag = self.odicom -> queryvalue(s[i])

        if (tag_structures[i].flag ge 1) then begin

            tag_structures[i].desc = self.odicom -> getdescription(s[i])
            tag_structures[i].value = self -> $
                get_default_vr_value(tag_structures[i].tag)

        endif else $
            tag_structures[i].desc = ''

    endfor

    return, tag_structures

end




;*********************************************************************
; Anonymizer::Query_Wizard
;+
;
; Returns 1 if the Anonymizer Wizard is currently active and 0 otherwise.
;
; @ returns 1 if the Anonymizer Wizard is currently active and 0 otherwise.
;
;-

function anonymizer::query_wizard

    return, self.wizard -> query_wizard_dialog()

end




;*********************************************************************
; Anonymizer::Reset
;+
;
; Resets the Anonymizer values to the default values.
;
; @keyword ALL {in}{type=boolean} Reset all fields.
; @keyword DEFAULT_VALUES {in}{type=boolean} Set default values for each
;          value representation to the Anonymizer defaults.
; @keyword DYNAMIC_TAGS {in}{type=boolean} Update Anonymizer's
;          dynamic tags to use default values.
; @keyword OUTFILE_EXTENSION {in}{type=boolean} Sets the output file's
;          extension to ".dcm"
; @keyword OUTFILE_PREFIX {in}{type=boolean} Sets the output file's
;          prefix to "".
; @keyword STATIC_TAGS {in}{type=boolean} Update Anonymizer's static
;          tags.
;
;-

pro anonymizer::reset, $
    static_tags = st, $
    default_values = dv, $
    dynamic_tags = dyv, $
    outfile_extension = ofe, $
    outfile_prefix = ofp, $
    all = all

    if keyword_set(all) then begin

        ofe = (ofp = (st = (dv = (dyv = 1))))
        self.wizard -> setproperty, user_preferences = 0

    endif

    if keyword_set(dv) then $
        self.attribute_values = self.default_att_values

    if keyword_set(ofe) then $
        self.outfile_prefix = ''

    if keyword_set(ofp) then $
        self.outfile_extension = '.dcm'

    if keyword_set(st) then begin

        ptr_free, self.static_tags

        tags = [ $
            '0008,0012', $ ; Instance Creation Date
            '0008,0020', $ ; Study Date
            '0008,0021', $ ; Series Date
            '0008,0022', $ ; Acquisition Date
            '0008,0023', $ ; Content Date
            '0008,0024', $ ; Overlay Date
            '0008,0025', $ ; Curve Date
            '0008,002A', $ ; Aquisition DateTime
            '0008,0080', $ ; Institution Name
            '0008,0081', $ ; Institution Address

⌨️ 快捷键说明

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