summaryrefslogtreecommitdiffstats
path: root/python/astra/data3d_c.pyx
diff options
context:
space:
mode:
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 f2c6e26..84472c1 100644
--- a/python/astra/data3d_c.pyx
+++ b/python/astra/data3d_c.pyx
@@ -139,6 +139,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)