summaryrefslogtreecommitdiffstats
path: root/python/astra/data3d_c.pyx
diff options
context:
space:
mode:
authorWillem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl>2015-04-10 14:29:27 +0200
committerWillem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl>2015-04-10 14:31:50 +0200
commite2c87a5e259c847772c733eefb1b291b2a5b1a6e (patch)
tree3c53bffdea10a5dfbf0d4042095b2d9a5a3d0baa /python/astra/data3d_c.pyx
parent57625dc219e5987b09bb6d88fe4040144bb6def3 (diff)
downloadastra-e2c87a5e259c847772c733eefb1b291b2a5b1a6e.tar.gz
astra-e2c87a5e259c847772c733eefb1b291b2a5b1a6e.tar.bz2
astra-e2c87a5e259c847772c733eefb1b291b2a5b1a6e.tar.xz
astra-e2c87a5e259c847772c733eefb1b291b2a5b1a6e.zip
Add python data3d.change_geometry
Diffstat (limited to 'python/astra/data3d_c.pyx')
-rw-r--r--python/astra/data3d_c.pyx55
1 files changed, 55 insertions, 0 deletions
diff --git a/python/astra/data3d_c.pyx b/python/astra/data3d_c.pyx
index 4b069f7..48af032 100644
--- a/python/astra/data3d_c.pyx
+++ b/python/astra/data3d_c.pyx
@@ -122,6 +122,61 @@ def get_geometry(i):
raise Exception("Not a known data object")
return geom
+def change_geometry(i, geom):
+ cdef CFloat32Data3DMemory * pDataObject = dynamic_cast_mem(getObject(i))
+ cdef CFloat32ProjectionData3DMemory * pDataObject2
+ cdef CFloat32VolumeData3DMemory * pDataObject3
+ if pDataObject.getType() == THREEPROJECTION:
+ pDataObject2 = <CFloat32ProjectionData3DMemory * >pDataObject
+ # TODO: Reduce code duplication here
+ cfg = utils.dictToConfig(six.b('ProjectionGeometry'), geom)
+ tpe = wrap_from_bytes(cfg.self.getAttribute(six.b('type')))
+ if (tpe == "parallel3d"):
+ ppGeometry = <CProjectionGeometry3D*> new CParallelProjectionGeometry3D();
+ elif (tpe == "parallel3d_vec"):
+ ppGeometry = <CProjectionGeometry3D*> new CParallelVecProjectionGeometry3D();
+ elif (tpe == "cone"):
+ ppGeometry = <CProjectionGeometry3D*> new CConeProjectionGeometry3D();
+ elif (tpe == "cone_vec"):
+ ppGeometry = <CProjectionGeometry3D*> new CConeVecProjectionGeometry3D();
+ else:
+ raise Exception("Invalid geometry type.")
+ if not ppGeometry.initialize(cfg[0]):
+ del cfg
+ del ppGeometry
+ raise Exception('Geometry class not initialized.')
+ del cfg
+ if (ppGeometry.getDetectorColCount() != pDataObject2.getDetectorColCount() or \
+ ppGeometry.getProjectionCount() != pDataObject2.getAngleCount() or \
+ ppGeometry.getDetectorRowCount() != pDataObject2.getDetectorRowCount()):
+ del ppGeometry
+ raise Exception(
+ "The dimensions of the data do not match those specified in the geometry.")
+ pDataObject2.changeGeometry(ppGeometry)
+ del ppGeometry
+
+ elif pDataObject.getType() == THREEVOLUME:
+ pDataObject3 = <CFloat32VolumeData3DMemory * >pDataObject
+ cfg = utils.dictToConfig(six.b('VolumeGeometry'), geom)
+ pGeometry = new CVolumeGeometry3D()
+ if not pGeometry.initialize(cfg[0]):
+ del cfg
+ del pGeometry
+ raise Exception('Geometry class not initialized.')
+ del cfg
+ if (pGeometry.getGridColCount() != pDataObject3.getColCount() or \
+ pGeometry.getGridRowCount() != pDataObject3.getRowCount() or \
+ pGeometry.getGridSliceCount() != pDataObject3.getSliceCount()):
+ del pGeometry
+ raise Exception(
+ "The dimensions of the data do not match those specified in the geometry.")
+ pDataObject3.changeGeometry(pGeometry)
+ del pGeometry
+
+ else:
+ raise Exception("Not a known data object")
+
+
cdef fillDataObject(CFloat32Data3DMemory * obj, data):
if data is None:
fillDataObjectScalar(obj, 0)