From 71d27819b1b046109b5c70e3bd112f436e96a545 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Mon, 23 Oct 2017 12:14:28 +0200 Subject: Support 2d/3d in astra.algorithm.get_res_norm --- python/astra/PyIncludes.pxd | 4 ++++ python/astra/algorithm_c.pyx | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/python/astra/PyIncludes.pxd b/python/astra/PyIncludes.pxd index c091963..512b82f 100644 --- a/python/astra/PyIncludes.pxd +++ b/python/astra/PyIncludes.pxd @@ -152,6 +152,10 @@ cdef extern from "astra/ReconstructionAlgorithm2D.h" namespace "astra": cdef cppclass CReconstructionAlgorithm2D: bool getResidualNorm(float32&) +cdef extern from "astra/ReconstructionAlgorithm3D.h" namespace "astra": + cdef cppclass CReconstructionAlgorithm3D: + bool getResidualNorm(float32&) + cdef extern from "astra/Projector2D.h" namespace "astra": cdef cppclass CProjector2D: bool isInitialized() diff --git a/python/astra/algorithm_c.pyx b/python/astra/algorithm_c.pyx index 9ed0634..161fe98 100644 --- a/python/astra/algorithm_c.pyx +++ b/python/astra/algorithm_c.pyx @@ -44,7 +44,8 @@ from .utils import wrap_from_bytes cdef CAlgorithmManager * manAlg = PyAlgorithmManager.getSingletonPtr() cdef extern from *: - CReconstructionAlgorithm2D * dynamic_cast_recAlg "dynamic_cast" (CAlgorithm * ) except NULL + CReconstructionAlgorithm2D * dynamic_cast_recAlg2D "dynamic_cast" (CAlgorithm * ) + CReconstructionAlgorithm3D * dynamic_cast_recAlg3D "dynamic_cast" (CAlgorithm * ) def create(config): @@ -79,12 +80,18 @@ def run(i, iterations=0): def get_res_norm(i): cdef CReconstructionAlgorithm2D * pAlg2D + cdef CReconstructionAlgorithm3D * pAlg3D cdef CAlgorithm * alg = getAlg(i) cdef float32 res = 0.0 - pAlg2D = dynamic_cast_recAlg(alg) - if pAlg2D == NULL: - raise Exception("Operation not supported.") - if not pAlg2D.getResidualNorm(res): + pAlg2D = dynamic_cast_recAlg2D(alg) + pAlg3D = dynamic_cast_recAlg3D(alg) + if pAlg2D != NULL: + if not pAlg2D.getResidualNorm(res): + raise Exception("Operation not supported.") + elif pAlg3D != NULL: + if not pAlg3D.getResidualNorm(res): + raise Exception("Operation not supported.") + else: raise Exception("Operation not supported.") return res -- cgit v1.2.3