From ecfb65a05b8ed5171ad65173581d5fe328926995 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Tue, 23 Jun 2020 13:46:35 +0200 Subject: Add python astra.experimental.direct_FP3D/BP3D --- python/astra/experimental.pyx | 54 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'python/astra/experimental.pyx') diff --git a/python/astra/experimental.pyx b/python/astra/experimental.pyx index 8f8e47d..25ecb24 100644 --- a/python/astra/experimental.pyx +++ b/python/astra/experimental.pyx @@ -121,3 +121,57 @@ IF HAVE_CUDA==True: cdef CProjector3D * projector = manProj.get(projector_id) # may be NULL if not m.doFDK(projector, pVolObject, pProjObject, False, NULL, MODE_ADD): raise Exception("Failed to perform FDK") + + cimport utils + from .utils cimport linkVolFromGeometry, linkProjFromGeometry + + def direct_FPBP3D(projector_id, vol, proj, t): + cdef CProjector3D * projector = manProj.get(projector_id) + if projector == NULL: + raise Exception("Projector not found") + cdef CVolumeGeometry3D *pGeometry = projector.getVolumeGeometry() + cdef CProjectionGeometry3D *ppGeometry = projector.getProjectionGeometry() + cdef CFloat32VolumeData3D * pVol = linkVolFromGeometry(pGeometry, vol) + cdef CFloat32ProjectionData3D * pProj = linkProjFromGeometry(ppGeometry, proj) + cdef vector[CFloat32VolumeData3D *] vols + cdef vector[CFloat32ProjectionData3D *] projs + vols.push_back(pVol) + projs.push_back(pProj) + cdef CCompositeGeometryManager m + try: + if t == "FP": + if not m.doFP(projector, vols, projs, MODE_SET): + raise Exception("Failed to perform FP") + elif t == "BP": + if not m.doBP(projector, vols, projs, MODE_SET): + raise Exception("Failed to perform BP") + else: + raise RuntimeError("internal error: wrong op type") + finally: + del pVol + del pProj + + def direct_FP3D(projector_id, vol, proj): + """Perform a 3D forward projection with pre-allocated input/output. + + :param projector_id: A 3D projector object handle + :type datatype: :class:`int` + :param vol: The input data, as either a numpy array, or a GPULink object + :type datatype: :class:`numpy.ndarray` or :class:`astra.data3d.GPULink` + :param proj: The pre-allocated output data, either numpy array or GPULink + :type datatype: :class:`numpy.ndarray` or :class:`astra.data3d.GPULink` + """ + direct_FPBP3D(projector_id, vol, proj, "FP") + + def direct_BP3D(projector_id, vol, proj): + """Perform a 3D back projection with pre-allocated input/output. + + :param projector_id: A 3D projector object handle + :type datatype: :class:`int` + :param vol: The input data, as either a numpy array, or a GPULink object + :type datatype: :class:`numpy.ndarray` or :class:`astra.data3d.GPULink` + :param proj: The pre-allocated output data, either numpy array or GPULink + :type datatype: :class:`numpy.ndarray` or :class:`astra.data3d.GPULink` + """ + direct_FPBP3D(projector_id, vol, proj, "BP") + -- cgit v1.2.3 From 492c0211608fa756ba6642ff7ae3b479765a955b Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Tue, 23 Jun 2020 15:19:06 +0200 Subject: Check numpy array type --- python/astra/experimental.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'python/astra/experimental.pyx') diff --git a/python/astra/experimental.pyx b/python/astra/experimental.pyx index 25ecb24..c76fcbe 100644 --- a/python/astra/experimental.pyx +++ b/python/astra/experimental.pyx @@ -168,9 +168,9 @@ IF HAVE_CUDA==True: :param projector_id: A 3D projector object handle :type datatype: :class:`int` - :param vol: The input data, as either a numpy array, or a GPULink object + :param vol: The pre-allocated output data, as either a numpy array, or a GPULink object :type datatype: :class:`numpy.ndarray` or :class:`astra.data3d.GPULink` - :param proj: The pre-allocated output data, either numpy array or GPULink + :param proj: The input data, either numpy array or GPULink :type datatype: :class:`numpy.ndarray` or :class:`astra.data3d.GPULink` """ direct_FPBP3D(projector_id, vol, proj, "BP") -- cgit v1.2.3 From 7213c6ae82c0e447ccec804f74226e6ceb8d45f8 Mon Sep 17 00:00:00 2001 From: Allard Hendriksen Date: Tue, 23 Jun 2020 15:54:56 +0200 Subject: Add mode parameter to direct_FPBP3D This change allows additive forward and backprojections. --- python/astra/experimental.pyx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'python/astra/experimental.pyx') diff --git a/python/astra/experimental.pyx b/python/astra/experimental.pyx index c76fcbe..0c40a82 100644 --- a/python/astra/experimental.pyx +++ b/python/astra/experimental.pyx @@ -125,7 +125,7 @@ IF HAVE_CUDA==True: cimport utils from .utils cimport linkVolFromGeometry, linkProjFromGeometry - def direct_FPBP3D(projector_id, vol, proj, t): + def direct_FPBP3D(projector_id, vol, proj, mode, t): cdef CProjector3D * projector = manProj.get(projector_id) if projector == NULL: raise Exception("Projector not found") @@ -140,10 +140,10 @@ IF HAVE_CUDA==True: cdef CCompositeGeometryManager m try: if t == "FP": - if not m.doFP(projector, vols, projs, MODE_SET): + if not m.doFP(projector, vols, projs, mode): raise Exception("Failed to perform FP") elif t == "BP": - if not m.doBP(projector, vols, projs, MODE_SET): + if not m.doBP(projector, vols, projs, mode): raise Exception("Failed to perform BP") else: raise RuntimeError("internal error: wrong op type") @@ -161,7 +161,7 @@ IF HAVE_CUDA==True: :param proj: The pre-allocated output data, either numpy array or GPULink :type datatype: :class:`numpy.ndarray` or :class:`astra.data3d.GPULink` """ - direct_FPBP3D(projector_id, vol, proj, "FP") + direct_FPBP3D(projector_id, vol, proj, MODE_SET, "FP") def direct_BP3D(projector_id, vol, proj): """Perform a 3D back projection with pre-allocated input/output. @@ -173,5 +173,4 @@ IF HAVE_CUDA==True: :param proj: The input data, either numpy array or GPULink :type datatype: :class:`numpy.ndarray` or :class:`astra.data3d.GPULink` """ - direct_FPBP3D(projector_id, vol, proj, "BP") - + direct_FPBP3D(projector_id, vol, proj, MODE_SET, "BP") -- cgit v1.2.3 From 69ab4daf439164eb37203b69b0cca3efe4c2232e Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Thu, 2 Jul 2020 15:55:14 +0200 Subject: Add error check --- python/astra/experimental.pyx | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'python/astra/experimental.pyx') diff --git a/python/astra/experimental.pyx b/python/astra/experimental.pyx index 0c40a82..08d907d 100644 --- a/python/astra/experimental.pyx +++ b/python/astra/experimental.pyx @@ -65,6 +65,8 @@ IF HAVE_CUDA==True: cdef CData3DManager * man3d = PyData3DManager.getSingletonPtr() def do_composite(projector_id, vol_ids, proj_ids, mode, t): + if mode != MODE_ADD and mode != MODE_SET: + raise RuntimeError("internal error: wrong composite mode") cdef vector[CFloat32VolumeData3D *] vol cdef CFloat32VolumeData3D * pVolObject cdef CFloat32ProjectionData3D * pProjObject @@ -126,6 +128,8 @@ IF HAVE_CUDA==True: from .utils cimport linkVolFromGeometry, linkProjFromGeometry def direct_FPBP3D(projector_id, vol, proj, mode, t): + if mode != MODE_ADD and mode != MODE_SET: + raise RuntimeError("internal error: wrong composite mode") cdef CProjector3D * projector = manProj.get(projector_id) if projector == NULL: raise Exception("Projector not found") -- cgit v1.2.3