From 3f5e4b145c22d2dd512d584cd71bd4ae60c08a49 Mon Sep 17 00:00:00 2001 From: Wim van Aarle Date: Tue, 24 Feb 2015 14:54:11 +0100 Subject: added get_geometry for 3d volume objects --- matlab/mex/astra_mex_data3d_c.cpp | 82 +++++++++++++++++++-------------------- matlab/mex/mexHelpFunctions.cpp | 41 ++++++++++++++------ matlab/mex/mexHelpFunctions.h | 6 +++ 3 files changed, 76 insertions(+), 53 deletions(-) (limited to 'matlab/mex') 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(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(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(pDataObject); + // plhs[0] = createProjectionGeometryStruct(pDataObject2->getGeometry()); + mexErrMsgTxt("Not implemented yet. \n"); + } + else if (pDataObject->getType() == CFloat32Data3D::VOLUME) { + CFloat32VolumeData3DMemory* pDataObject2 = dynamic_cast(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 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 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 mGeometryInfo; + + mGeometryInfo["GridColCount"] = mxCreateDoubleScalar(_pVolGeom->getGridColCount()); + mGeometryInfo["GridRowCount"] = mxCreateDoubleScalar(_pVolGeom->getGridRowCount()); + mGeometryInfo["GridSliceCount"] = mxCreateDoubleScalar(_pVolGeom->getGridRowCount()); + + std::map 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); -- cgit v1.2.3