Exemple #1
0
    def load(self, file, args=None):

        if self.base_ref != None:
            self.base_ref = None
            teem.nrrdNix(self._ctypesobj)
            self._ctypesobj = teem.nrrdNew()

        teem.nrrdLoad(self._ctypesobj, file, args)
        self.base_ref = None
        self._init = True
Exemple #2
0
    def load(self, file, args=None):

        if self.base_ref != None:
            self.base_ref = None
            teem.nrrdNix(self._ctypesobj)
            self._ctypesobj = teem.nrrdNew()

        teem.nrrdLoad(self._ctypesobj, file, args)
        self.base_ref = None
        self._init = True
Exemple #3
0
    def fromNDArray(self, array):

        if self.base_ref != None:
            self.base_ref = None
            teem.nrrdNix(self._ctypesobj)
            self._ctypesobj = teem.nrrdNew()

        try:
            cTy, teemTy = ndarrayGetTypes(array)
        except Exception as err:
            print err
            return

        c_type_p = ctypes.POINTER(cTy)
        if (array.flags.f_contiguous):  # memory shared with array
            array_p = array.ctypes.data_as(c_type_p)
            dims = list(array.shape)
            sizes = (ctypes.c_size_t * teem.NRRD_DIM_MAX)(*dims)
            teem.nrrdWrap_nva(self._ctypesobj, array_p, teemTy,
                              ctypes.c_uint(array.ndim), sizes)
            self.base_ref = array
        elif (array.flags.c_contiguous):  # memory shared with array
            array_p = array.ctypes.data_as(c_type_p)
            dims = list(reversed(array.shape))
            sizes = (ctypes.c_size_t * teem.NRRD_DIM_MAX)(*dims)
            teem.nrrdWrap_nva(self._ctypesobj, array_p, teemTy,
                              ctypes.c_uint(array.ndim), sizes)
            self.base_ref = array
        else:  # must make c_contiguous -- memory not shared with array, transfer full control to teem
            arr = numpy.ascontiguousarray(array, dtype=array.dtype.type)
            array_p = arr.ctypes.data_as(c_type_p)
            dims = list(reversed(arr.shape))
            nrrd_tmp = teem.nrrdNew()
            sizes = (ctypes.c_size_t * teem.NRRD_DIM_MAX)(*dims)
            teem.nrrdWrap_nva(nrrd_tmp, array_p, teemTy,
                              ctypes.c_uint(array.ndim), sizes)
            teem.nrrdCopy(self._ctypesobj,
                          nrrd_tmp)  # this call hangs with fmob-ch4.nrrd
            teem.nrrdNix(nrrd_tmp)
            self.base_ref = None
        self._init = True

        if isinstance(array, ExtendedArray):
            if not array.base_ref is None:  # means there is some Nrrd file sharing it's memory with the array
                teem.nrrdAxisInfoCopy(self._ctypesobj,
                                      array.base_ref._ctypesobj, None,
                                      teem.NRRD_AXIS_INFO_SIZE_BIT)
Exemple #4
0
    def fromNDArray(self, array):

        if self.base_ref != None:
            self.base_ref = None
            teem.nrrdNix(self._ctypesobj)
            self._ctypesobj = teem.nrrdNew()

        try:
            cTy, teemTy = ndarrayGetTypes(array)
        except Exception as err:
            print err
            return

        c_type_p = ctypes.POINTER(cTy)
        if array.flags.f_contiguous:  # memory shared with array
            array_p = array.ctypes.data_as(c_type_p)
            dims = list(array.shape)
            sizes = (ctypes.c_size_t * teem.NRRD_DIM_MAX)(*dims)
            teem.nrrdWrap_nva(self._ctypesobj, array_p, teemTy, ctypes.c_uint(array.ndim), sizes)
            self.base_ref = array
        elif array.flags.c_contiguous:  # memory shared with array
            array_p = array.ctypes.data_as(c_type_p)
            dims = list(reversed(array.shape))
            sizes = (ctypes.c_size_t * teem.NRRD_DIM_MAX)(*dims)
            teem.nrrdWrap_nva(self._ctypesobj, array_p, teemTy, ctypes.c_uint(array.ndim), sizes)
            self.base_ref = array
        else:  # must make c_contiguous -- memory not shared with array, transfer full control to teem
            arr = numpy.ascontiguousarray(array, dtype=array.dtype.type)
            array_p = arr.ctypes.data_as(c_type_p)
            dims = list(reversed(arr.shape))
            nrrd_tmp = teem.nrrdNew()
            sizes = (ctypes.c_size_t * teem.NRRD_DIM_MAX)(*dims)
            teem.nrrdWrap_nva(nrrd_tmp, array_p, teemTy, ctypes.c_uint(array.ndim), sizes)
            teem.nrrdCopy(self._ctypesobj, nrrd_tmp)  # this call hangs with fmob-ch4.nrrd
            teem.nrrdNix(nrrd_tmp)
            self.base_ref = None
        self._init = True

        if isinstance(array, ExtendedArray):
            if not array.base_ref is None:  # means there is some Nrrd file sharing it's memory with the array
                teem.nrrdAxisInfoCopy(self._ctypesobj, array.base_ref._ctypesobj, None, teem.NRRD_AXIS_INFO_SIZE_BIT)