summaryrefslogtreecommitdiffstats
path: root/python/astra/data3d_c.pyx
diff options
context:
space:
mode:
authorWillem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl>2020-06-23 11:40:26 +0200
committerWillem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl>2020-07-02 15:54:12 +0200
commitb8bf069f375424fd303ad6e594412583633c1110 (patch)
treeb3cfcf3f67c35b7d2cf121993a20dcd6bda9f580 /python/astra/data3d_c.pyx
parent82fc179f39ed6da308b0f229769f899570a1d9ea (diff)
downloadastra-b8bf069f375424fd303ad6e594412583633c1110.tar.gz
astra-b8bf069f375424fd303ad6e594412583633c1110.tar.bz2
astra-b8bf069f375424fd303ad6e594412583633c1110.tar.xz
astra-b8bf069f375424fd303ad6e594412583633c1110.zip
Refactor cython data3d object creation to prepare
Diffstat (limited to 'python/astra/data3d_c.pyx')
-rw-r--r--python/astra/data3d_c.pyx38
1 files changed, 5 insertions, 33 deletions
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 = <CData3DManager * >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 = <CFloat32CustomMemory*> new CFloat32CustomPython(data)
- pDataObject3D = <CFloat32Data3D * > new CFloat32VolumeData3DMemory(pGeometry, pCustom)
- elif isinstance(data, GPULink):
- IF HAVE_CUDA==True:
- s = geom_size(geometry)
- hnd = wrapHandle(<float*>PyLong_AsVoidPtr(data.ptr), data.x, data.y, data.z, data.pitch/4)
- pDataObject3D = <CFloat32Data3D * > 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 = <CFloat32Data3D * > 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 = <CFloat32CustomMemory*> new CFloat32CustomPython(data)
- pDataObject3D = <CFloat32Data3D * > new CFloat32ProjectionData3DMemory(ppGeometry, pCustom)
- elif isinstance(data, GPULink):
- IF HAVE_CUDA==True:
- s = geom_size(geometry)
- hnd = wrapHandle(<float*>PyLong_AsVoidPtr(data.ptr), data.x, data.y, data.z, data.pitch/4)
- pDataObject3D = <CFloat32Data3D * > 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 = <CFloat32Data3DMemory * > new CFloat32ProjectionData3DMemory(ppGeometry)
+ pDataObject3D = new CFloat32ProjectionData3DMemory(ppGeometry)
del ppGeometry
del cfg
else: