From b8bf069f375424fd303ad6e594412583633c1110 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Tue, 23 Jun 2020 11:40:26 +0200 Subject: Refactor cython data3d object creation to prepare --- python/astra/data3d_c.pyx | 38 +++++--------------------------------- 1 file changed, 5 insertions(+), 33 deletions(-) (limited to 'python/astra/data3d_c.pyx') diff --git a/python/astra/data3d_c.pyx b/python/astra/data3d_c.pyx index 4c8aa62..a1b9138 100644 --- a/python/astra/data3d_c.pyx +++ b/python/astra/data3d_c.pyx @@ -44,6 +44,7 @@ from .PyXMLDocument cimport XMLDocument cimport utils from .utils import wrap_from_bytes +from .utils cimport linkVolFromGeometry, linkProjFromGeometry from .pythonutils import geom_size, GPULink @@ -53,9 +54,6 @@ from six.moves import reduce include "config.pxi" -cdef extern from "Python.h": - void* PyLong_AsVoidPtr(object) - cdef CData3DManager * man3d = PyData3DManager.getSingletonPtr() @@ -68,16 +66,12 @@ cdef CFloat32Data3DMemory * dynamic_cast_mem_safe(CFloat32Data3D *obj) except NU raise RuntimeError("Not a memory 3D data object") return ret -cdef extern from "CFloat32CustomPython.h": - cdef cppclass CFloat32CustomPython: - CFloat32CustomPython(arrIn) def create(datatype,geometry,data=None, link=False): cdef Config *cfg cdef CVolumeGeometry3D * pGeometry cdef CProjectionGeometry3D * ppGeometry cdef CFloat32Data3D * pDataObject3D - cdef CConeProjectionGeometry3D* pppGeometry cdef CFloat32CustomMemory * pCustom = NULL IF HAVE_CUDA==True: cdef MemHandle3D hnd @@ -101,20 +95,9 @@ def create(datatype,geometry,data=None, link=False): del pGeometry raise RuntimeError('Geometry class not initialized.') if link: - if isinstance(data, np.ndarray): - pCustom = new CFloat32CustomPython(data) - pDataObject3D = new CFloat32VolumeData3DMemory(pGeometry, pCustom) - elif isinstance(data, GPULink): - IF HAVE_CUDA==True: - s = geom_size(geometry) - hnd = wrapHandle(PyLong_AsVoidPtr(data.ptr), data.x, data.y, data.z, data.pitch/4) - pDataObject3D = new CFloat32VolumeData3DGPU(pGeometry, hnd) - ELSE: - raise NotImplementedError("CUDA support is not enabled in ASTRA") - else: - raise TypeError("data should be a numpy.ndarray or a GPULink object") + pDataObject3D = linkVolFromGeometry(pGeometry, data) else: - pDataObject3D = new CFloat32VolumeData3DMemory(pGeometry) + pDataObject3D = new CFloat32VolumeData3DMemory(pGeometry) del cfg del pGeometry elif datatype == '-sino' or datatype == '-proj3d' or datatype == '-sinocone': @@ -136,20 +119,9 @@ def create(datatype,geometry,data=None, link=False): del ppGeometry raise RuntimeError('Geometry class not initialized.') if link: - if isinstance(data, np.ndarray): - pCustom = new CFloat32CustomPython(data) - pDataObject3D = new CFloat32ProjectionData3DMemory(ppGeometry, pCustom) - elif isinstance(data, GPULink): - IF HAVE_CUDA==True: - s = geom_size(geometry) - hnd = wrapHandle(PyLong_AsVoidPtr(data.ptr), data.x, data.y, data.z, data.pitch/4) - pDataObject3D = new CFloat32ProjectionData3DGPU(ppGeometry, hnd) - ELSE: - raise NotImplementedError("CUDA support is not enabled in ASTRA") - else: - raise TypeError("data should be a numpy.ndarray or a GPULink object") + pDataObject3D = linkProjFromGeometry(ppGeometry, data) else: - pDataObject3D = new CFloat32ProjectionData3DMemory(ppGeometry) + pDataObject3D = new CFloat32ProjectionData3DMemory(ppGeometry) del ppGeometry del cfg else: -- cgit v1.2.3