當前位置: 首頁>>代碼示例>>Python>>正文


Python Dataset.values方法代碼示例

本文整理匯總了Python中dicom.dataset.Dataset.values方法的典型用法代碼示例。如果您正苦於以下問題:Python Dataset.values方法的具體用法?Python Dataset.values怎麽用?Python Dataset.values使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在dicom.dataset.Dataset的用法示例。


在下文中一共展示了Dataset.values方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from dicom.dataset import Dataset [as 別名]
# 或者: from dicom.dataset.Dataset import values [as 別名]
class DIMSEMessage:

    def __init__(self):
        self.CommandSet = None
        self.EncodedDataSet = None
        self.DataSet = None
        self.encoded_command_set = ''
        self.ID = id

        self.ts = ImplicitVRLittleEndian  # imposed by standard.
        if self.__class__ != DIMSEMessage:
            self.CommandSet = Dataset()
            for ii in self.CommandFields:
                self.CommandSet.add_new(ii[1], ii[2], '')

    def Encode(self, id, maxpdulength):
        """Returns the encoded message as a series of P-DATA service
        parameter objects"""
        self.ID = id
        pdatas = []
        encoded_command_set = dsutils.encode(
            self.CommandSet, self.ts.is_implicit_VR, self.ts.is_little_endian)

        # fragment command set
        pdvs = fragment(maxpdulength, encoded_command_set)
        assert ''.join(pdvs) == encoded_command_set
        for ii in pdvs[:-1]:
            # send only one pdv per pdata primitive
            pdata = P_DATA_ServiceParameters()
            # not last command fragment
            pdata.PresentationDataValueList = [[self.ID, pack('b', 1) + ii]]
            pdatas.append(pdata)
        # last command fragment
        pdata = P_DATA_ServiceParameters()
        # last command fragment
        pdata.PresentationDataValueList = [[self.ID, pack('b', 3) + pdvs[-1]]]
        pdatas.append(pdata)

        # fragment data set
        #if self.__dict__.has_key('DataSet') and self.DataSet:
        if 'DataSet' in self.__dict__ and self.DataSet is not None:
            pdvs = fragment(maxpdulength, self.DataSet)
            assert ''.join(pdvs) == self.DataSet
            for ii in pdvs[:-1]:
                pdata = P_DATA_ServiceParameters()
                # not last data fragment
                pdata.PresentationDataValueList = [
                    [self.ID, pack('b', 0) + ii]]
                pdatas.append(pdata)
            pdata = P_DATA_ServiceParameters()
            # last data fragment
            pdata.PresentationDataValueList = [
                [self.ID, pack('b', 2) + pdvs[-1]]]
            pdatas.append(pdata)

        return pdatas

    def Decode(self, pdata):
        """Constructs itself receiving a series of P-DATA primitives.
        Returns True when complete, False otherwise."""
        if pdata.__class__ != P_DATA_ServiceParameters:
            # not a pdata
            return False
        if pdata is None:
            return False
        ii = pdata
        for vv in ii.PresentationDataValueList:
            # must be able to read P-DATA with several PDVs
            self.ID = vv[0]
            if unpack('b', vv[1][0])[0] in (1, 3):
                logger.debug("  command fragment %s", self.ID)
                self.encoded_command_set += vv[1][1:]
                if unpack('b', vv[1][0])[0] == 3:
                    logger.debug("  last command fragment %s", self.ID)
                    self.CommandSet = dsutils.decode(
                        self.encoded_command_set, self.ts.is_implicit_VR,
                        self.ts.is_little_endian)
                    self.__class__ = MessageType[
                        self.CommandSet[(0x0000, 0x0100)].value]
                    if self.CommandSet[(0x0000, 0x0800)].value == 0x0101:
                        # response: no dataset
                        return True
            elif unpack('b', vv[1][0])[0] in (0, 2):
                if self.DataSet is None:
                    self.DataSet = ''
                self.DataSet += vv[1][1:]
                logger.debug("  data fragment %s", self.ID)
                if unpack('b', vv[1][0])[0] == 2:
                    logger.debug("  last data fragment %s", self.ID)
                    return True
            else:
                raise "Error"

        return False

    def SetLength(self):
        # compute length
        l = 0
        for ii in self.CommandSet.values()[1:]:
            l += len(dsutils.encode_element(ii,
#.........這裏部分代碼省略.........
開發者ID:suever,項目名稱:pynetdicom,代碼行數:103,代碼來源:DIMSEmessages.py


注:本文中的dicom.dataset.Dataset.values方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。