summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--python/astra/PyIncludes.pxd2
-rw-r--r--python/astra/experimental.pyx84
-rw-r--r--samples/python/s018_experimental_multires.py84
3 files changed, 170 insertions, 0 deletions
diff --git a/python/astra/PyIncludes.pxd b/python/astra/PyIncludes.pxd
index 35dea5f..e9e2bdb 100644
--- a/python/astra/PyIncludes.pxd
+++ b/python/astra/PyIncludes.pxd
@@ -224,6 +224,7 @@ cdef extern from "astra/Float32VolumeData3DMemory.h" namespace "astra":
int getRowCount()
int getColCount()
int getSliceCount()
+ bool isInitialized()
@@ -255,6 +256,7 @@ cdef extern from "astra/Float32ProjectionData3DMemory.h" namespace "astra":
int getDetectorColCount()
int getDetectorRowCount()
int getAngleCount()
+ bool isInitialized()
cdef extern from "astra/Float32Data3D.h" namespace "astra":
cdef cppclass CFloat32Data3D:
diff --git a/python/astra/experimental.pyx b/python/astra/experimental.pyx
new file mode 100644
index 0000000..da27504
--- /dev/null
+++ b/python/astra/experimental.pyx
@@ -0,0 +1,84 @@
+#-----------------------------------------------------------------------
+# Copyright: 2010-2015, iMinds-Vision Lab, University of Antwerp
+# 2014-2015, CWI, Amsterdam
+#
+# Contact: astra@uantwerpen.be
+# Website: http://sf.net/projects/astra-toolbox
+#
+# This file is part of the ASTRA Toolbox.
+#
+#
+# The ASTRA Toolbox is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# The ASTRA Toolbox is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with the ASTRA Toolbox. If not, see <http://www.gnu.org/licenses/>.
+#
+#-----------------------------------------------------------------------
+
+# distutils: language = c++
+# distutils: libraries = astra
+
+include "config.pxi"
+
+import six
+from .PyIncludes cimport *
+from libcpp.vector cimport vector
+
+cdef extern from "astra/CompositeGeometryManager.h" namespace "astra":
+ cdef cppclass CCompositeGeometryManager:
+ bool doFP(CProjector3D *, vector[CFloat32VolumeData3DMemory *], vector[CFloat32ProjectionData3DMemory *])
+ bool doBP(CProjector3D *, vector[CFloat32VolumeData3DMemory *], vector[CFloat32ProjectionData3DMemory *])
+
+cdef extern from *:
+ CFloat32VolumeData3DMemory * dynamic_cast_vol_mem "dynamic_cast<astra::CFloat32VolumeData3DMemory*>" (CFloat32Data3D * ) except NULL
+ CFloat32ProjectionData3DMemory * dynamic_cast_proj_mem "dynamic_cast<astra::CFloat32ProjectionData3DMemory*>" (CFloat32Data3D * ) except NULL
+
+cimport PyProjector3DManager
+from .PyProjector3DManager cimport CProjector3DManager
+cimport PyData3DManager
+from .PyData3DManager cimport CData3DManager
+
+cdef CProjector3DManager * manProj = <CProjector3DManager * >PyProjector3DManager.getSingletonPtr()
+cdef CData3DManager * man3d = <CData3DManager * >PyData3DManager.getSingletonPtr()
+
+def do_composite(projector_id, vol_ids, proj_ids, t):
+ cdef vector[CFloat32VolumeData3DMemory *] vol
+ cdef CFloat32VolumeData3DMemory * pVolObject
+ cdef CFloat32ProjectionData3DMemory * pProjObject
+ for v in vol_ids:
+ pVolObject = dynamic_cast_vol_mem(man3d.get(v))
+ if pVolObject == NULL:
+ raise Exception("Data object not found")
+ if not pVolObject.isInitialized():
+ raise Exception("Data object not initialized properly")
+ vol.push_back(pVolObject)
+ cdef vector[CFloat32ProjectionData3DMemory *] proj
+ for v in proj_ids:
+ pProjObject = dynamic_cast_proj_mem(man3d.get(v))
+ if pProjObject == NULL:
+ raise Exception("Data object not found")
+ if not pProjObject.isInitialized():
+ raise Exception("Data object not initialized properly")
+ proj.push_back(pProjObject)
+ cdef CCompositeGeometryManager m
+ cdef CProjector3D * projector = manProj.get(projector_id) # may be NULL
+ if t == "FP":
+ if not m.doFP(projector, vol, proj):
+ raise Exception("Failed to perform FP")
+ else:
+ if not m.doBP(projector, vol, proj):
+ raise Exception("Failed to perform BP")
+
+def do_composite_FP(projector_id, vol_ids, proj_ids):
+ do_composite(projector_id, vol_ids, proj_ids, "FP")
+
+def do_composite_BP(projector_id, vol_ids, proj_ids):
+ do_composite(projector_id, vol_ids, proj_ids, "BP")
diff --git a/samples/python/s018_experimental_multires.py b/samples/python/s018_experimental_multires.py
new file mode 100644
index 0000000..cf38e53
--- /dev/null
+++ b/samples/python/s018_experimental_multires.py
@@ -0,0 +1,84 @@
+#-----------------------------------------------------------------------
+#Copyright 2013 Centrum Wiskunde & Informatica, Amsterdam
+#
+#Author: Daniel M. Pelt
+#Contact: D.M.Pelt@cwi.nl
+#Website: http://dmpelt.github.io/pyastratoolbox/
+#
+#
+#This file is part of the Python interface to the
+#All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA Toolbox").
+#
+#The Python interface to the ASTRA Toolbox is free software: you can redistribute it and/or modify
+#it under the terms of the GNU General Public License as published by
+#the Free Software Foundation, either version 3 of the License, or
+#(at your option) any later version.
+#
+#The Python interface to the ASTRA Toolbox is distributed in the hope that it will be useful,
+#but WITHOUT ANY WARRANTY; without even the implied warranty of
+#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+#GNU General Public License for more details.
+#
+#You should have received a copy of the GNU General Public License
+#along with the Python interface to the ASTRA Toolbox. If not, see <http://www.gnu.org/licenses/>.
+#
+#-----------------------------------------------------------------------
+
+import astra
+import numpy as np
+from astra.experimental import do_composite_FP
+
+astra.log.setOutputScreen(astra.log.STDERR, astra.log.DEBUG)
+
+# low res part (voxels of 4x4x4)
+vol_geom1 = astra.create_vol_geom(32, 16, 32, -64, 0, -64, 64, -64, 64)
+
+# high res part (voxels of 1x1x1)
+vol_geom2 = astra.create_vol_geom(128, 64, 128, 0, 64, -64, 64, -64, 64)
+
+
+# Split the output in two parts as well, for demonstration purposes
+angles1 = np.linspace(0, np.pi/2, 90, False)
+angles2 = np.linspace(np.pi/2, np.pi, 90, False)
+proj_geom1 = astra.create_proj_geom('parallel3d', 1.0, 1.0, 128, 192, angles1)
+proj_geom2 = astra.create_proj_geom('parallel3d', 1.0, 1.0, 128, 192, angles2)
+
+# Create a simple hollow cube phantom
+cube1 = np.zeros((32,32,16))
+cube1[4:28,4:28,4:16] = 1
+
+cube2 = np.zeros((128,128,64))
+cube2[16:112,16:112,0:112] = 1
+cube2[33:97,33:97,4:28] = 0
+
+vol1 = astra.data3d.create('-vol', vol_geom1, cube1)
+vol2 = astra.data3d.create('-vol', vol_geom2, cube2)
+
+proj1 = astra.data3d.create('-proj3d', proj_geom1, 0)
+proj2 = astra.data3d.create('-proj3d', proj_geom2, 0)
+
+# The actual geometries don't matter for this composite FP/BP case
+projector = astra.create_projector('cuda3d', proj_geom1, vol_geom1)
+
+do_composite_FP(projector, [vol1, vol2], [proj1, proj2])
+
+proj_data1 = astra.data3d.get(proj1)
+proj_data2 = astra.data3d.get(proj2)
+
+# Display a single projection image
+import pylab
+pylab.gray()
+pylab.figure(1)
+pylab.imshow(proj_data1[:,0,:])
+pylab.figure(2)
+pylab.imshow(proj_data2[:,0,:])
+pylab.show()
+
+
+# Clean up. Note that GPU memory is tied up in the algorithm object,
+# and main RAM in the data objects.
+astra.data3d.delete(vol1)
+astra.data3d.delete(vol2)
+astra.data3d.delete(proj1)
+astra.data3d.delete(proj2)
+astra.projector3d.delete(projector)