summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWim van Aarle <wimvanaarle@gmail.com>2015-02-24 14:54:11 +0100
committerWim van Aarle <wimvanaarle@gmail.com>2015-02-24 14:54:11 +0100
commit3f5e4b145c22d2dd512d584cd71bd4ae60c08a49 (patch)
treefd5bde6240e9189090b73e0be097fc653a3e9648
parentf619aba4543de6b9a4fe6fb63b6f1840ef509846 (diff)
downloadastra-3f5e4b145c22d2dd512d584cd71bd4ae60c08a49.tar.gz
astra-3f5e4b145c22d2dd512d584cd71bd4ae60c08a49.tar.bz2
astra-3f5e4b145c22d2dd512d584cd71bd4ae60c08a49.tar.xz
astra-3f5e4b145c22d2dd512d584cd71bd4ae60c08a49.zip
added get_geometry for 3d volume objects
-rw-r--r--matlab/mex/astra_mex_data3d_c.cpp82
-rw-r--r--matlab/mex/mexHelpFunctions.cpp41
-rw-r--r--matlab/mex/mexHelpFunctions.h6
-rw-r--r--test_geometry.m24
4 files changed, 100 insertions, 53 deletions
diff --git a/matlab/mex/astra_mex_data3d_c.cpp b/matlab/mex/astra_mex_data3d_c.cpp
index 35a7512..47316f5 100644
--- a/matlab/mex/astra_mex_data3d_c.cpp
+++ b/matlab/mex/astra_mex_data3d_c.cpp
@@ -266,48 +266,46 @@ void astra_mex_data3d_dimensions(int nlhs, mxArray* plhs[], int nrhs, const mxAr
}
//-----------------------------------------------------------------------------------------
-/**
- * [geom] = astra_mex_data3d('geometry', id);
+/** geom = astra_mex_data3d('get_geometry', id);
+ *
+ * Fetch the geometry of a 3d data object stored in the astra-library.
+ * id: identifier of the 3d data object as stored in the astra-library.
+ * geom: MATLAB-struct containing information about the used geometry.
*/
-void astra_mex_data3d_geometry(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[])
+void astra_mex_data3d_get_geometry(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[])
{
- //// Get input
- //if (nrhs < 2) {
- // mexErrMsgTxt("Not enough arguments. See the help document for a detailed argument list. \n");
- // return;
- //}
- //int iDid = (int)(mxGetScalar(prhs[1]));
-
- //// Get data object
- //CFloat32Data3D* pData = CData3DManager::getSingleton().get(iDid);
- //if (!pData) {
- // mexErrMsgTxt("DataObject not valid. \n");
- // return;
- //}
-
- //// Projection Data
- //if (pData->getType() == CFloat32Data3D::PROJECTION) {
- // CFloat32ProjectionData3D* pData2 = dynamic_cast<CFloat32ProjectionData3D*>(pData);
- // CProjectionGeometry3D* pProjGeom = pData2->getGeometry();
- // XMLDocument* config = pProjGeom->toXML();
-
- // if (1 <= nlhs) {
- // plhs[0] = XML2struct(config);
- // }
- //}
- //// Volume Data
- //else if (pData->getType() == CFloat32Data3D::VOLUME) {
- //// CFloat32VolumeData3D* pData2 = dynamic_cast<CFloat32VolumeData3D*>(pData);
- //// CVolumeGeometry2D* pVolGeom = pData2->getGeometry2D(iSliceNr);
- //// if (1 <= nlhs) {
- //// plhs[0] = createVolumeGeometryStruct(pVolGeom);
- //// }
- //}
- //// Error
- //else {
- // mexErrMsgTxt("Type not valid. \n");
- // return;
- //}
+ // parse input
+ if (nrhs < 2) {
+ mexErrMsgTxt("Not enough arguments. See the help document for a detailed argument list. \n");
+ return;
+ }
+ if (!mxIsDouble(prhs[1])) {
+ mexErrMsgTxt("Identifier should be a scalar value. \n");
+ return;
+ }
+ int iDataID = (int)(mxGetScalar(prhs[1]));
+
+ // fetch data object
+ CFloat32Data3D* pDataObject = astra::CData3DManager::getSingleton().get(iDataID);
+ if (!pDataObject || !pDataObject->isInitialized()) {
+ mexErrMsgTxt("Data object not found or not initialized properly.\n");
+ return;
+ }
+
+ // create output
+ if (1 <= nlhs) {
+ if (pDataObject->getType() == CFloat32Data3D::PROJECTION) {
+ // CFloat32ProjectionData2D* pDataObject2 = dynamic_cast<CFloat32ProjectionData2D*>(pDataObject);
+ // plhs[0] = createProjectionGeometryStruct(pDataObject2->getGeometry());
+ mexErrMsgTxt("Not implemented yet. \n");
+ }
+ else if (pDataObject->getType() == CFloat32Data3D::VOLUME) {
+ CFloat32VolumeData3DMemory* pDataObject2 = dynamic_cast<CFloat32VolumeData3DMemory*>(pDataObject);
+ plhs[0] = createVolumeGeometryStruct(pDataObject2->getGeometry());
+ }
+ }
+
+
}
//-----------------------------------------------------------------------------------------
@@ -395,8 +393,8 @@ void mexFunction(int nlhs, mxArray* plhs[],
astra_mex_data3d_info(nlhs, plhs, nrhs, prhs);
} else if (sMode == std::string("dimensions")) {
astra_mex_data3d_dimensions(nlhs, plhs, nrhs, prhs);
- } else if (sMode == std::string("geometry")) {
- astra_mex_data3d_geometry(nlhs, plhs, nrhs, prhs);
+ } else if (sMode == std::string("get_geometry")) {
+ astra_mex_data3d_get_geometry(nlhs, plhs, nrhs, prhs);
} else {
printHelp();
}
diff --git a/matlab/mex/mexHelpFunctions.cpp b/matlab/mex/mexHelpFunctions.cpp
index e919dd9..9b65e77 100644
--- a/matlab/mex/mexHelpFunctions.cpp
+++ b/matlab/mex/mexHelpFunctions.cpp
@@ -331,28 +331,47 @@ astra::CVolumeGeometry2D* parseVolumeGeometryStruct(const mxArray* prhs)
}
//-----------------------------------------------------------------------------------------
-// create reconstruction geometry data
-mxArray* createVolumeGeometryStruct(astra::CVolumeGeometry2D* _pReconGeom)
+// create 2D volume geometry struct
+mxArray* createVolumeGeometryStruct(astra::CVolumeGeometry2D* _pVolGeom)
{
- // temporary map to store the data for the MATLAB struct
std::map<std::string, mxArray*> mGeometryInfo;
- // fill up map
- mGeometryInfo["GridColCount"] = mxCreateDoubleScalar(_pReconGeom->getGridColCount());
- mGeometryInfo["GridRowCount"] = mxCreateDoubleScalar(_pReconGeom->getGridRowCount());
+ mGeometryInfo["GridColCount"] = mxCreateDoubleScalar(_pVolGeom->getGridColCount());
+ mGeometryInfo["GridRowCount"] = mxCreateDoubleScalar(_pVolGeom->getGridRowCount());
std::map<std::string, mxArray*> mGeometryOptions;
- mGeometryOptions["WindowMinX"] = mxCreateDoubleScalar(_pReconGeom->getWindowMinX());
- mGeometryOptions["WindowMaxX"] = mxCreateDoubleScalar(_pReconGeom->getWindowMaxX());
- mGeometryOptions["WindowMinY"] = mxCreateDoubleScalar(_pReconGeom->getWindowMinY());
- mGeometryOptions["WindowMaxY"] = mxCreateDoubleScalar(_pReconGeom->getWindowMaxY());
+ mGeometryOptions["WindowMinX"] = mxCreateDoubleScalar(_pVolGeom->getWindowMinX());
+ mGeometryOptions["WindowMaxX"] = mxCreateDoubleScalar(_pVolGeom->getWindowMaxX());
+ mGeometryOptions["WindowMinY"] = mxCreateDoubleScalar(_pVolGeom->getWindowMinY());
+ mGeometryOptions["WindowMaxY"] = mxCreateDoubleScalar(_pVolGeom->getWindowMaxY());
mGeometryInfo["option"] = buildStruct(mGeometryOptions);
- // build and return the MATLAB struct
return buildStruct(mGeometryInfo);
}
+//-----------------------------------------------------------------------------------------
+// create 3D volume geometry struct
+mxArray* createVolumeGeometryStruct(astra::CVolumeGeometry3D* _pVolGeom)
+{
+ std::map<std::string, mxArray*> mGeometryInfo;
+
+ mGeometryInfo["GridColCount"] = mxCreateDoubleScalar(_pVolGeom->getGridColCount());
+ mGeometryInfo["GridRowCount"] = mxCreateDoubleScalar(_pVolGeom->getGridRowCount());
+ mGeometryInfo["GridSliceCount"] = mxCreateDoubleScalar(_pVolGeom->getGridRowCount());
+
+ std::map<std::string, mxArray*> mGeometryOptions;
+ mGeometryOptions["WindowMinX"] = mxCreateDoubleScalar(_pVolGeom->getWindowMinX());
+ mGeometryOptions["WindowMaxX"] = mxCreateDoubleScalar(_pVolGeom->getWindowMaxX());
+ mGeometryOptions["WindowMinY"] = mxCreateDoubleScalar(_pVolGeom->getWindowMinY());
+ mGeometryOptions["WindowMaxY"] = mxCreateDoubleScalar(_pVolGeom->getWindowMaxY());
+ mGeometryOptions["WindowMinZ"] = mxCreateDoubleScalar(_pVolGeom->getWindowMinZ());
+ mGeometryOptions["WindowMaxZ"] = mxCreateDoubleScalar(_pVolGeom->getWindowMaxZ());
+
+ mGeometryInfo["option"] = buildStruct(mGeometryOptions);
+
+ return buildStruct(mGeometryInfo);
+}
//-----------------------------------------------------------------------------------------
string matlab2string(const mxArray* pField)
diff --git a/matlab/mex/mexHelpFunctions.h b/matlab/mex/mexHelpFunctions.h
index 84372ba..ae8acac 100644
--- a/matlab/mex/mexHelpFunctions.h
+++ b/matlab/mex/mexHelpFunctions.h
@@ -47,6 +47,9 @@ $Id$
#include "astra/FanFlatProjectionGeometry2D.h"
#include "astra/VolumeGeometry2D.h"
+#include "astra/VolumeGeometry3D.h"
+
+
#include "astra/XMLDocument.h"
#include "astra/XMLNode.h"
@@ -63,8 +66,11 @@ mxArray* anyToMxArray(boost::any _any);
astra::CProjectionGeometry2D* parseProjectionGeometryStruct(const mxArray*);
mxArray* createProjectionGeometryStruct(astra::CProjectionGeometry2D*);
+
astra::CVolumeGeometry2D* parseVolumeGeometryStruct(const mxArray*);
+
mxArray* createVolumeGeometryStruct(astra::CVolumeGeometry2D* _pReconGeom);
+mxArray* createVolumeGeometryStruct(astra::CVolumeGeometry3D* _pReconGeom);
astra::XMLDocument* struct2XML(string rootname, const mxArray* pStruct);
diff --git a/test_geometry.m b/test_geometry.m
new file mode 100644
index 0000000..d8facc3
--- /dev/null
+++ b/test_geometry.m
@@ -0,0 +1,24 @@
+
+addpath(genpath('bin/'));
+addpath(genpath('matlab/'));
+
+%load('phantom3d');
+d = 256;
+I = ones(d,d,d);
+S = I > 0.5;
+
+%% create geometries
+vol_geom2d = astra_create_vol_geom(d,d);
+vol_geom3d = astra_create_vol_geom(d,d,d);
+
+
+%% create data objects
+vol2d_id = astra_mex_data2d('create', '-vol', vol_geom2d, 0);
+vol3d_id = astra_mex_data3d('create', '-vol', vol_geom3d, 0);
+
+%% get geometries
+vol_geom2d_new = astra_mex_data2d('get_geometry', vol2d_id);
+vol_geom3d_new = astra_mex_data3d('get_geometry', vol3d_id);
+
+
+astra_clear; \ No newline at end of file