summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWillem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl>2017-10-26 11:01:36 +0200
committerWillem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl>2017-10-26 11:02:30 +0200
commit642977e9d613d673fbf46e11cb92b6785fe02cc6 (patch)
tree412b068a78bfa8707624b56da114a5c36fb8662a
parent42b5e731a9ac6c3aa4751cee2c09758d58d18427 (diff)
downloadastra-642977e9d613d673fbf46e11cb92b6785fe02cc6.tar.gz
astra-642977e9d613d673fbf46e11cb92b6785fe02cc6.tar.bz2
astra-642977e9d613d673fbf46e11cb92b6785fe02cc6.tar.xz
astra-642977e9d613d673fbf46e11cb92b6785fe02cc6.zip
Fix usage of cython except
-rw-r--r--python/astra/data3d_c.pyx20
1 files changed, 13 insertions, 7 deletions
diff --git a/python/astra/data3d_c.pyx b/python/astra/data3d_c.pyx
index 78ed620..0717ca0 100644
--- a/python/astra/data3d_c.pyx
+++ b/python/astra/data3d_c.pyx
@@ -60,7 +60,13 @@ cdef extern from "Python.h":
cdef CData3DManager * man3d = <CData3DManager * >PyData3DManager.getSingletonPtr()
cdef extern from *:
- CFloat32Data3DMemory * dynamic_cast_mem "dynamic_cast<astra::CFloat32Data3DMemory*>" (CFloat32Data3D * ) except NULL
+ CFloat32Data3DMemory * dynamic_cast_mem "dynamic_cast<astra::CFloat32Data3DMemory*>" (CFloat32Data3D * )
+
+cdef CFloat32Data3DMemory * dynamic_cast_mem_safe(CFloat32Data3D *obj) except NULL:
+ cdef CFloat32Data3DMemory *ret = dynamic_cast_mem(obj)
+ if not ret:
+ raise RuntimeError("Not a memory 3D data object")
+ return ret
cdef extern from "CFloat32CustomPython.h":
cdef cppclass CFloat32CustomPython:
@@ -154,12 +160,12 @@ def create(datatype,geometry,data=None, link=False):
raise RuntimeError("Couldn't initialize data object.")
if not link:
- fillDataObject(dynamic_cast_mem(pDataObject3D), data)
+ fillDataObject(dynamic_cast_mem_safe(pDataObject3D), data)
return man3d.store(<CFloat32Data3D*>pDataObject3D)
def get_geometry(i):
- cdef CFloat32Data3DMemory * pDataObject = dynamic_cast_mem(getObject(i))
+ cdef CFloat32Data3DMemory * pDataObject = dynamic_cast_mem_safe(getObject(i))
cdef CFloat32ProjectionData3DMemory * pDataObject2
cdef CFloat32VolumeData3DMemory * pDataObject3
if pDataObject.getType() == THREEPROJECTION:
@@ -173,7 +179,7 @@ def get_geometry(i):
return geom
def change_geometry(i, geom):
- cdef CFloat32Data3DMemory * pDataObject = dynamic_cast_mem(getObject(i))
+ cdef CFloat32Data3DMemory * pDataObject = dynamic_cast_mem_safe(getObject(i))
cdef CFloat32ProjectionData3DMemory * pDataObject2
cdef CFloat32VolumeData3DMemory * pDataObject3
if pDataObject.getType() == THREEPROJECTION:
@@ -262,7 +268,7 @@ cdef CFloat32Data3D * getObject(i) except NULL:
@cython.boundscheck(False)
@cython.wraparound(False)
def get(i):
- cdef CFloat32Data3DMemory * pDataObject = dynamic_cast_mem(getObject(i))
+ cdef CFloat32Data3DMemory * pDataObject = dynamic_cast_mem_safe(getObject(i))
outArr = np.empty((pDataObject.getDepth(),pDataObject.getHeight(), pDataObject.getWidth()),dtype=np.float32,order='C')
cdef float [:,:,::1] mView = outArr
cdef float [:,:,::1] cView = <float[:outArr.shape[0],:outArr.shape[1],:outArr.shape[2]]> pDataObject.getData3D()[0][0]
@@ -270,7 +276,7 @@ def get(i):
return outArr
def get_shared(i):
- cdef CFloat32Data3DMemory * pDataObject = dynamic_cast_mem(getObject(i))
+ cdef CFloat32Data3DMemory * pDataObject = dynamic_cast_mem_safe(getObject(i))
outArr = np.empty((pDataObject.getDepth(),pDataObject.getHeight(), pDataObject.getWidth()),dtype=np.float32,order='C')
cdef np.npy_intp shape[3]
shape[0] = <np.npy_intp> pDataObject.getDepth()
@@ -283,7 +289,7 @@ def get_single(i):
def store(i,data):
cdef CFloat32Data3D * pDataObject = getObject(i)
- fillDataObject(dynamic_cast_mem(pDataObject), data)
+ fillDataObject(dynamic_cast_mem_safe(pDataObject), data)
def dimensions(i):
cdef CFloat32Data3D * pDataObject = getObject(i)