Пример #1
0
    def GetArray(self):
        input = self.__export.GetInput()
        type = input.GetScalarType()
        extent = input.GetWholeExtent()
        numComponents = input.GetNumberOfScalarComponents()
        dim = (extent[5] - extent[4] + 1, extent[3] - extent[2] + 1, extent[1] - extent[0] + 1)
        if numComponents > 1:
            dim = dim + (numComponents,)
        size = dim[0] * dim[1] * dim[2] * numComponents * self.__sizeDict[type]

        imString = np.zeros((size,), np.uint8).tostring()
        self.__export.Export(imString)

        imArray = np.fromstring(imString, self.__typeDict[type])
        imArray = np.reshape(imArray, dim)

        # convert unsigned short to int to avoid sign issues
        if type == VTK_UNSIGNED_SHORT and self.__ConvertUnsignedShortToInt:
            imArray = umath.bitwise_and(imArray.astype(np.int32), 0xFFFF)
        #            imArray = imArray.astype( np.int32 ) & 0xffff

        # just to remind myself of the dangers of memory management
        del imString

        return imArray
Пример #2
0
    def GetArray(self):
        input = self.__export.GetInput()
        type = input.GetScalarType()
        extent = input.GetExtent()
        numComponents = input.GetNumberOfScalarComponents()
        dim = (extent[5] - extent[4] + 1, extent[3] - extent[2] + 1,
               extent[1] - extent[0] + 1)
        if (numComponents > 1):
            dim = dim + (numComponents, )
        size = dim[0] * dim[1] * dim[2] * numComponents * self.__sizeDict[type]

        imString = np.zeros((size, ), np.uint8).tostring()
        self.__export.Export(imString)

        imArray = np.fromstring(imString, self.__typeDict[type])
        imArray = np.reshape(imArray, dim)

        # convert unsigned short to int to avoid sign issues
        if (type == VTK_UNSIGNED_SHORT and self.__ConvertUnsignedShortToInt):
            imArray = umath.bitwise_and(imArray.astype(np.int32), 0xffff)


#            imArray = imArray.astype( np.int32 ) & 0xffff

# just to remind myself of the dangers of memory management
        del imString

        return imArray
Пример #3
0
    def GetArray(self):
        self.__export.Update()
        input = self.__export.GetInput()
        extent = input.GetExtent()
        type = input.GetScalarType()
        numComponents = input.GetNumberOfScalarComponents()
        dim = (extent[5] - extent[4] + 1, extent[3] - extent[2] + 1, extent[1] - extent[0] + 1)
        if numComponents > 1:
            dim = dim + (numComponents,)

        imArray = numpy.zeros(dim, self.__typeDict[type])
        self.__export.Export(imArray)

        # convert unsigned short to int to avoid sign issues
        if type == VTK_UNSIGNED_SHORT and self.__ConvertUnsignedShortToInt:
            imArray = umath.bitwise_and(imArray.astype("i"), 0xFFFF)

        return imArray
Пример #4
0
    def GetArray(self):
        self.__export.Update()
        input = self.__export.GetInput()
        extent = input.GetExtent()
        type = input.GetScalarType()
        numComponents = input.GetNumberOfScalarComponents()
        dim = (extent[5] - extent[4] + 1, extent[3] - extent[2] + 1,
               extent[1] - extent[0] + 1)
        if (numComponents > 1):
            dim = dim + (numComponents, )

        imArray = numpy.zeros(dim, self.__typeDict[type])
        self.__export.Export(imArray)

        # convert unsigned short to int to avoid sign issues
        if (type == VTK_UNSIGNED_SHORT and self.__ConvertUnsignedShortToInt):
            imArray = umath.bitwise_and(imArray.astype('i'), 0xffff)

        return imArray