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/mexHelpFunctions.cpp | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) (limited to 'matlab/mex/mexHelpFunctions.cpp') 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) -- cgit v1.2.3 From 9e48494ecc1e4655bd6c25b34bb5c53c80c30d7a Mon Sep 17 00:00:00 2001 From: Wim van Aarle Date: Tue, 24 Feb 2015 15:17:38 +0100 Subject: fixed get_geometry for fanflat_vec --- matlab/mex/mexHelpFunctions.cpp | 72 ++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 33 deletions(-) (limited to 'matlab/mex/mexHelpFunctions.cpp') diff --git a/matlab/mex/mexHelpFunctions.cpp b/matlab/mex/mexHelpFunctions.cpp index 9b65e77..63d2003 100644 --- a/matlab/mex/mexHelpFunctions.cpp +++ b/matlab/mex/mexHelpFunctions.cpp @@ -213,61 +213,67 @@ mxArray* createProjectionGeometryStruct(astra::CProjectionGeometry2D* _pProjGeom // temporary map to store the data for the MATLAB struct std::map mGeometryInfo; - // detectorCount - mGeometryInfo["DetectorCount"] = mxCreateDoubleScalar(_pProjGeom->getDetectorCount()); - - if (!_pProjGeom->isOfType("fanflat_vec")) { - // detectorWidth + // parallel beam + if (_pProjGeom->isOfType("parallel")) { + mGeometryInfo["type"] = mxCreateString("parallel"); + mGeometryInfo["DetectorCount"] = mxCreateDoubleScalar(_pProjGeom->getDetectorCount()); mGeometryInfo["DetectorWidth"] = mxCreateDoubleScalar(_pProjGeom->getDetectorWidth()); - // pfProjectionAngles mxArray* pAngles = mxCreateDoubleMatrix(1, _pProjGeom->getProjectionAngleCount(), mxREAL); double* out = mxGetPr(pAngles); for (int i = 0; i < _pProjGeom->getProjectionAngleCount(); i++) { out[i] = _pProjGeom->getProjectionAngle(i); } - mGeometryInfo["ProjectionAngles"] = pAngles; + mGeometryInfo["ProjectionAngles"] = pAngles; } - else { + + // fanflat + else if (_pProjGeom->isOfType("fanflat")) { + astra::CFanFlatProjectionGeometry2D* pFanFlatGeom = dynamic_cast(_pProjGeom); + + mGeometryInfo["type"] = mxCreateString("fanflat"); + mGeometryInfo["DetectorCount"] = mxCreateDoubleScalar(_pProjGeom->getDetectorCount()); + mGeometryInfo["DetectorWidth"] = mxCreateDoubleScalar(_pProjGeom->getDetectorWidth()); + mGeometryInfo["DistanceOriginSource"] = mxCreateDoubleScalar(pFanFlatGeom->getOriginSourceDistance()); + mGeometryInfo["DistanceOriginDetector"] = mxCreateDoubleScalar(pFanFlatGeom->getOriginDetectorDistance()); + + mxArray* pAngles = mxCreateDoubleMatrix(1, pFanFlatGeom->getProjectionAngleCount(), mxREAL); + double* out = mxGetPr(pAngles); + for (int i = 0; i < pFanFlatGeom->getProjectionAngleCount(); i++) { + out[i] = pFanFlatGeom->getProjectionAngle(i); + } + mGeometryInfo["ProjectionAngles"] = pAngles; + } + + // fanflat_vec + else if (_pProjGeom->isOfType("fanflat_vec")) { astra::CFanFlatVecProjectionGeometry2D* pVecGeom = dynamic_cast(_pProjGeom); - mxArray* pVectors = mxCreateDoubleMatrix(1, pVecGeom->getProjectionAngleCount()*6, mxREAL); + + mGeometryInfo["type"] = mxCreateString("fanflat_vec"); + mGeometryInfo["DetectorCount"] = mxCreateDoubleScalar(pVecGeom->getDetectorCount()); + + mxArray* pVectors = mxCreateDoubleMatrix(pVecGeom->getProjectionAngleCount(), 6, mxREAL); double* out = mxGetPr(pVectors); int iDetCount = pVecGeom->getDetectorCount(); + int iAngleCount = pVecGeom->getProjectionAngleCount(); for (int i = 0; i < pVecGeom->getProjectionAngleCount(); i++) { const SFanProjection* p = &pVecGeom->getProjectionVectors()[i]; - out[6*i + 0] = p->fSrcX; - out[6*i + 1] = p->fSrcY; - out[6*i + 2] = p->fDetSX + 0.5f*iDetCount*p->fDetUX; - out[6*i + 3] = p->fDetSY + 0.5f*iDetCount*p->fDetUY; - out[6*i + 4] = p->fDetUX; - out[6*i + 5] = p->fDetUY; + out[0*iAngleCount + i] = p->fSrcX; + out[1*iAngleCount + i] = p->fSrcY; + out[2*iAngleCount + i] = p->fDetSX + 0.5f*iDetCount*p->fDetUX; + out[3*iAngleCount + i] = p->fDetSY + 0.5f*iDetCount*p->fDetUY; + out[4*iAngleCount + i] = p->fDetUX; + out[5*iAngleCount + i] = p->fDetUY; } mGeometryInfo["Vectors"] = pVectors; } - // parallel specific options - if (_pProjGeom->isOfType("parallel")) { - // type - mGeometryInfo["type"] = mxCreateString("parallel"); - } - // fanflat specific options - else if (_pProjGeom->isOfType("fanflat")) { - astra::CFanFlatProjectionGeometry2D* pFanFlatGeom = dynamic_cast(_pProjGeom); - // detectorCount - mGeometryInfo["DistanceOriginSource"] = mxCreateDoubleScalar(pFanFlatGeom->getOriginSourceDistance()); - // detectorWidth - mGeometryInfo["DistanceOriginDetector"] = mxCreateDoubleScalar(pFanFlatGeom->getOriginDetectorDistance()); - // type - mGeometryInfo["type"] = mxCreateString("fanflat"); - } + // sparse_matrix else if (_pProjGeom->isOfType("sparse_matrix")) { astra::CSparseMatrixProjectionGeometry2D* pSparseMatrixGeom = dynamic_cast(_pProjGeom); mGeometryInfo["type"] = mxCreateString("sparse_matrix"); mGeometryInfo["MatrixID"] = mxCreateDoubleScalar(CMatrixManager::getSingleton().getIndex(pSparseMatrixGeom->getMatrix())); } - else if(_pProjGeom->isOfType("fanflat_vec")) { - mGeometryInfo["type"] = mxCreateString("fanflat_vec"); - } // build and return the MATLAB struct return buildStruct(mGeometryInfo); -- cgit v1.2.3 From 569515f3e20ef3b3c2c4a777f38f45dc67e6f9b6 Mon Sep 17 00:00:00 2001 From: Wim van Aarle Date: Tue, 24 Feb 2015 16:46:39 +0100 Subject: added get_geometry for 3d projection data objects --- matlab/mex/mexHelpFunctions.cpp | 117 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 113 insertions(+), 4 deletions(-) (limited to 'matlab/mex/mexHelpFunctions.cpp') diff --git a/matlab/mex/mexHelpFunctions.cpp b/matlab/mex/mexHelpFunctions.cpp index 63d2003..654f5c6 100644 --- a/matlab/mex/mexHelpFunctions.cpp +++ b/matlab/mex/mexHelpFunctions.cpp @@ -207,7 +207,7 @@ astra::CProjectionGeometry2D* parseProjectionGeometryStruct(const mxArray* prhs) } //----------------------------------------------------------------------------------------- -// create projection geometry data +// create 2D projection geometry struct mxArray* createProjectionGeometryStruct(astra::CProjectionGeometry2D* _pProjGeom) { // temporary map to store the data for the MATLAB struct @@ -224,7 +224,7 @@ mxArray* createProjectionGeometryStruct(astra::CProjectionGeometry2D* _pProjGeom for (int i = 0; i < _pProjGeom->getProjectionAngleCount(); i++) { out[i] = _pProjGeom->getProjectionAngle(i); } - mGeometryInfo["ProjectionAngles"] = pAngles; + mGeometryInfo["ProjectionAngles"] = pAngles; } // fanflat @@ -242,7 +242,7 @@ mxArray* createProjectionGeometryStruct(astra::CProjectionGeometry2D* _pProjGeom for (int i = 0; i < pFanFlatGeom->getProjectionAngleCount(); i++) { out[i] = pFanFlatGeom->getProjectionAngle(i); } - mGeometryInfo["ProjectionAngles"] = pAngles; + mGeometryInfo["ProjectionAngles"] = pAngles; } // fanflat_vec @@ -263,7 +263,7 @@ mxArray* createProjectionGeometryStruct(astra::CProjectionGeometry2D* _pProjGeom out[2*iAngleCount + i] = p->fDetSX + 0.5f*iDetCount*p->fDetUX; out[3*iAngleCount + i] = p->fDetSY + 0.5f*iDetCount*p->fDetUY; out[4*iAngleCount + i] = p->fDetUX; - out[5*iAngleCount + i] = p->fDetUY; + out[5*iAngleCount + i] = p->fDetUY; } mGeometryInfo["Vectors"] = pVectors; } @@ -279,6 +279,115 @@ mxArray* createProjectionGeometryStruct(astra::CProjectionGeometry2D* _pProjGeom return buildStruct(mGeometryInfo); } +//----------------------------------------------------------------------------------------- +// create 3D projection geometry struct +mxArray* createProjectionGeometryStruct(astra::CProjectionGeometry3D* _pProjGeom) +{ + // temporary map to store the data for the MATLAB struct + std::map mGeometryInfo; + + // parallel beam + if (_pProjGeom->isOfType("parallel3d")) { + mGeometryInfo["type"] = mxCreateString("parallel3d"); + mGeometryInfo["DetectorRowCount"] = mxCreateDoubleScalar(_pProjGeom->getDetectorRowCount()); + mGeometryInfo["DetectorColCount"] = mxCreateDoubleScalar(_pProjGeom->getDetectorColCount()); + mGeometryInfo["DetectorSpacingX"] = mxCreateDoubleScalar(_pProjGeom->getDetectorSpacingX()); + mGeometryInfo["DetectorSpacingY"] = mxCreateDoubleScalar(_pProjGeom->getDetectorSpacingY()); + + mxArray* pAngles = mxCreateDoubleMatrix(1, _pProjGeom->getProjectionCount(), mxREAL); + double* out = mxGetPr(pAngles); + for (int i = 0; i < _pProjGeom->getProjectionCount(); i++) { + out[i] = _pProjGeom->getProjectionAngle(i); + } + mGeometryInfo["ProjectionAngles"] = pAngles; + } + + // parallel beam vector + if (_pProjGeom->isOfType("parallel3d_vec")) { + astra::CParallelVecProjectionGeometry3D* pVecGeom = dynamic_cast(_pProjGeom); + + mGeometryInfo["type"] = mxCreateString("parallel3d_vec"); + mGeometryInfo["DetectorRowCount"] = mxCreateDoubleScalar(pVecGeom->getDetectorRowCount()); + mGeometryInfo["DetectorColCount"] = mxCreateDoubleScalar(pVecGeom->getDetectorColCount()); + + mxArray* pVectors = mxCreateDoubleMatrix(pVecGeom->getProjectionCount(), 12, mxREAL); + double* out = mxGetPr(pVectors); + int iDetRowCount = pVecGeom->getDetectorRowCount(); + int iDetColCount = pVecGeom->getDetectorColCount(); + int iAngleCount = pVecGeom->getProjectionCount(); + for (int i = 0; i < pVecGeom->getProjectionCount(); i++) { + const SPar3DProjection* p = &pVecGeom->getProjectionVectors()[i]; + out[ 0*iAngleCount + i] = p->fRayX; + out[ 1*iAngleCount + i] = p->fRayY; + out[ 2*iAngleCount + i] = p->fRayZ; + out[ 3*iAngleCount + i] = p->fDetSX + 0.5f*iDetRowCount*p->fDetUX + 0.5f*iDetColCount*p->fDetVX; + out[ 4*iAngleCount + i] = p->fDetSY + 0.5f*iDetRowCount*p->fDetUY + 0.5f*iDetColCount*p->fDetVY; + out[ 5*iAngleCount + i] = p->fDetSZ + 0.5f*iDetRowCount*p->fDetUZ + 0.5f*iDetColCount*p->fDetVZ; + out[ 6*iAngleCount + i] = p->fDetUX; + out[ 7*iAngleCount + i] = p->fDetUY; + out[ 8*iAngleCount + i] = p->fDetUZ; + out[ 9*iAngleCount + i] = p->fDetVX; + out[10*iAngleCount + i] = p->fDetVY; + out[11*iAngleCount + i] = p->fDetVZ; + } + mGeometryInfo["Vectors"] = pVectors; + } + + // cone beam + else if (_pProjGeom->isOfType("cone")) { + astra::CConeProjectionGeometry3D* pConeGeom = dynamic_cast(_pProjGeom); + + mGeometryInfo["type"] = mxCreateString("cone"); + mGeometryInfo["DetectorRowCount"] = mxCreateDoubleScalar(pConeGeom->getDetectorRowCount()); + mGeometryInfo["DetectorColCount"] = mxCreateDoubleScalar(pConeGeom->getDetectorColCount()); + mGeometryInfo["DetectorSpacingX"] = mxCreateDoubleScalar(pConeGeom->getDetectorSpacingX()); + mGeometryInfo["DetectorSpacingY"] = mxCreateDoubleScalar(pConeGeom->getDetectorSpacingY()); + mGeometryInfo["DistanceOriginSource"] = mxCreateDoubleScalar(pConeGeom->getOriginSourceDistance()); + mGeometryInfo["DistanceOriginDetector"] = mxCreateDoubleScalar(pConeGeom->getOriginDetectorDistance()); + + mxArray* pAngles = mxCreateDoubleMatrix(1, pConeGeom->getProjectionCount(), mxREAL); + double* out = mxGetPr(pAngles); + for (int i = 0; i < pConeGeom->getProjectionCount(); i++) { + out[i] = pConeGeom->getProjectionAngle(i); + } + mGeometryInfo["ProjectionAngles"] = pAngles; + } + + // cone beam vector + else if (_pProjGeom->isOfType("cone_vec")) { + astra::CConeVecProjectionGeometry3D* pConeVecGeom = dynamic_cast(_pProjGeom); + + mGeometryInfo["type"] = mxCreateString("cone_vec"); + mGeometryInfo["DetectorRowCount"] = mxCreateDoubleScalar(pConeVecGeom->getDetectorRowCount()); + mGeometryInfo["DetectorColCount"] = mxCreateDoubleScalar(pConeVecGeom->getDetectorColCount()); + + mxArray* pVectors = mxCreateDoubleMatrix(pConeVecGeom->getProjectionCount(), 12, mxREAL); + double* out = mxGetPr(pVectors); + int iDetRowCount = pConeVecGeom->getDetectorRowCount(); + int iDetColCount = pConeVecGeom->getDetectorColCount(); + int iAngleCount = pConeVecGeom->getProjectionCount(); + for (int i = 0; i < pConeVecGeom->getProjectionCount(); i++) { + const SConeProjection* p = &pConeVecGeom->getProjectionVectors()[i]; + out[ 0*iAngleCount + i] = p->fSrcX; + out[ 1*iAngleCount + i] = p->fSrcY; + out[ 2*iAngleCount + i] = p->fSrcZ; + out[ 3*iAngleCount + i] = p->fDetSX + 0.5f*iDetRowCount*p->fDetUX + 0.5f*iDetColCount*p->fDetVX; + out[ 4*iAngleCount + i] = p->fDetSY + 0.5f*iDetRowCount*p->fDetUY + 0.5f*iDetColCount*p->fDetVY; + out[ 5*iAngleCount + i] = p->fDetSZ + 0.5f*iDetRowCount*p->fDetUZ + 0.5f*iDetColCount*p->fDetVZ; + out[ 6*iAngleCount + i] = p->fDetUX; + out[ 7*iAngleCount + i] = p->fDetUY; + out[ 8*iAngleCount + i] = p->fDetUZ; + out[ 9*iAngleCount + i] = p->fDetVX; + out[10*iAngleCount + i] = p->fDetVY; + out[11*iAngleCount + i] = p->fDetVZ; + } + mGeometryInfo["Vectors"] = pVectors; + } + + // build and return the MATLAB struct + return buildStruct(mGeometryInfo); +} + //----------------------------------------------------------------------------------------- // parse reconstruction geometry data astra::CVolumeGeometry2D* parseVolumeGeometryStruct(const mxArray* prhs) -- cgit v1.2.3 From 065d9c6a18f2b8eececc608ce850a9a308ca6356 Mon Sep 17 00:00:00 2001 From: Wim van Aarle Date: Wed, 25 Feb 2015 16:46:09 +0100 Subject: get_geometry now uses XML config object (for volumes) --- matlab/mex/mexHelpFunctions.cpp | 107 +++++++++++++++++++++++++++------------- 1 file changed, 73 insertions(+), 34 deletions(-) (limited to 'matlab/mex/mexHelpFunctions.cpp') diff --git a/matlab/mex/mexHelpFunctions.cpp b/matlab/mex/mexHelpFunctions.cpp index 654f5c6..b57f27f 100644 --- a/matlab/mex/mexHelpFunctions.cpp +++ b/matlab/mex/mexHelpFunctions.cpp @@ -447,46 +447,46 @@ astra::CVolumeGeometry2D* parseVolumeGeometryStruct(const mxArray* prhs) //----------------------------------------------------------------------------------------- // create 2D volume geometry struct -mxArray* createVolumeGeometryStruct(astra::CVolumeGeometry2D* _pVolGeom) -{ - std::map mGeometryInfo; +// mxArray* createVolumeGeometryStruct(astra::CVolumeGeometry2D* _pVolGeom) +// { +// std::map mGeometryInfo; - mGeometryInfo["GridColCount"] = mxCreateDoubleScalar(_pVolGeom->getGridColCount()); - mGeometryInfo["GridRowCount"] = mxCreateDoubleScalar(_pVolGeom->getGridRowCount()); +// mGeometryInfo["GridColCount"] = mxCreateDoubleScalar(_pVolGeom->getGridColCount()); +// mGeometryInfo["GridRowCount"] = 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()); +// std::map mGeometryOptions; +// mGeometryOptions["WindowMinX"] = mxCreateDoubleScalar(_pVolGeom->getWindowMinX()); +// mGeometryOptions["WindowMaxX"] = mxCreateDoubleScalar(_pVolGeom->getWindowMaxX()); +// mGeometryOptions["WindowMinY"] = mxCreateDoubleScalar(_pVolGeom->getWindowMinY()); +// mGeometryOptions["WindowMaxY"] = mxCreateDoubleScalar(_pVolGeom->getWindowMaxY()); - mGeometryInfo["option"] = buildStruct(mGeometryOptions); +// mGeometryInfo["option"] = buildStruct(mGeometryOptions); - return buildStruct(mGeometryInfo); -} +// return buildStruct(mGeometryInfo); +// } //----------------------------------------------------------------------------------------- // create 3D volume geometry struct -mxArray* createVolumeGeometryStruct(astra::CVolumeGeometry3D* _pVolGeom) -{ - std::map mGeometryInfo; +// mxArray* createVolumeGeometryStruct(astra::CVolumeGeometry3D* _pVolGeom) +// { +// std::map mGeometryInfo; - mGeometryInfo["GridColCount"] = mxCreateDoubleScalar(_pVolGeom->getGridColCount()); - mGeometryInfo["GridRowCount"] = mxCreateDoubleScalar(_pVolGeom->getGridRowCount()); - mGeometryInfo["GridSliceCount"] = mxCreateDoubleScalar(_pVolGeom->getGridRowCount()); +// 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()); +// 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); +// mGeometryInfo["option"] = buildStruct(mGeometryOptions); - return buildStruct(mGeometryInfo); -} +// return buildStruct(mGeometryInfo); +// } //----------------------------------------------------------------------------------------- string matlab2string(const mxArray* pField) @@ -714,6 +714,12 @@ bool mex_is_scalar(const mxArray* pInput) return (mxIsNumeric(pInput) && mxGetM(pInput)*mxGetN(pInput) == 1); } +//----------------------------------------------------------------------------------------- +mxArray* config2struct(astra::Config* cfg) +{ + return XMLNode2struct(cfg->self); +} + //----------------------------------------------------------------------------------------- mxArray* XML2struct(astra::XMLDocument* xml) { @@ -724,9 +730,26 @@ mxArray* XML2struct(astra::XMLDocument* xml) } //----------------------------------------------------------------------------------------- +mxArray* XMLNode2option(astra::XMLNode* node) +{ + char* end; + double content = ::strtod(node->getAttribute("value").c_str(), &end); + bool isnumber = !*end; + + // float + if (isnumber) { + return mxCreateDoubleScalar(content); + } + // string + else { + return mxCreateString(node->getAttribute("value").c_str()); + } +} + mxArray* XMLNode2struct(astra::XMLNode* node) { - std::map mList; + std::map mList; + std::map mOptions; // type_attribute if (node->hasAttribute("type")) { @@ -736,11 +759,22 @@ mxArray* XMLNode2struct(astra::XMLNode* node) list nodes = node->getNodes(); for (list::iterator it = nodes.begin(); it != nodes.end(); it++) { XMLNode* subnode = (*it); + + char* end; + double content = ::strtod(subnode->getContent().c_str(), &end); + bool isnumber = !*end; + + // option + if (subnode->getName() == "Option") { + mOptions[subnode->getAttribute("key")] = XMLNode2option(subnode); + } // list - if (subnode->hasAttribute("listsize")) { - cout << "lkmdsqldqsjkl" << endl; - cout << " " << node->getContentNumericalArray().size() << endl; - mList[subnode->getName()] = vectorToMxArray(node->getContentNumericalArray()); + // else if (subnode->hasAttribute("listsize")) { + // mList[subnode->getName()] = vectorToMxArray(node->getContentNumericalArray()); + // } + // float + else if (isnumber) { + mList[subnode->getName()] = mxCreateDoubleScalar(content); } // string else { @@ -749,9 +783,14 @@ mxArray* XMLNode2struct(astra::XMLNode* node) delete subnode; } + mList["options"] = buildStruct(mOptions); return buildStruct(mList); } + + + + void get3DMatrixDims(const mxArray* x, mwSize *dims) { const mwSize* mdims = mxGetDimensions(x); -- cgit v1.2.3 From cca150841cd1de4f3b4d24c1188263b9623bc511 Mon Sep 17 00:00:00 2001 From: Wim van Aarle Date: Thu, 26 Feb 2015 13:47:59 +0100 Subject: get_geometry now uses XML config object (for projections) --- matlab/mex/mexHelpFunctions.cpp | 332 ++++++++++------------------------------ 1 file changed, 83 insertions(+), 249 deletions(-) (limited to 'matlab/mex/mexHelpFunctions.cpp') diff --git a/matlab/mex/mexHelpFunctions.cpp b/matlab/mex/mexHelpFunctions.cpp index b57f27f..c25123a 100644 --- a/matlab/mex/mexHelpFunctions.cpp +++ b/matlab/mex/mexHelpFunctions.cpp @@ -32,6 +32,12 @@ $Id$ */ #include "mexHelpFunctions.h" +#include +#include +#include +#include +#include + #include "astra/SparseMatrixProjectionGeometry2D.h" #include "astra/FanFlatVecProjectionGeometry2D.h" #include "astra/AstraObjectManager.h" @@ -206,188 +212,6 @@ astra::CProjectionGeometry2D* parseProjectionGeometryStruct(const mxArray* prhs) } } -//----------------------------------------------------------------------------------------- -// create 2D projection geometry struct -mxArray* createProjectionGeometryStruct(astra::CProjectionGeometry2D* _pProjGeom) -{ - // temporary map to store the data for the MATLAB struct - std::map mGeometryInfo; - - // parallel beam - if (_pProjGeom->isOfType("parallel")) { - mGeometryInfo["type"] = mxCreateString("parallel"); - mGeometryInfo["DetectorCount"] = mxCreateDoubleScalar(_pProjGeom->getDetectorCount()); - mGeometryInfo["DetectorWidth"] = mxCreateDoubleScalar(_pProjGeom->getDetectorWidth()); - - mxArray* pAngles = mxCreateDoubleMatrix(1, _pProjGeom->getProjectionAngleCount(), mxREAL); - double* out = mxGetPr(pAngles); - for (int i = 0; i < _pProjGeom->getProjectionAngleCount(); i++) { - out[i] = _pProjGeom->getProjectionAngle(i); - } - mGeometryInfo["ProjectionAngles"] = pAngles; - } - - // fanflat - else if (_pProjGeom->isOfType("fanflat")) { - astra::CFanFlatProjectionGeometry2D* pFanFlatGeom = dynamic_cast(_pProjGeom); - - mGeometryInfo["type"] = mxCreateString("fanflat"); - mGeometryInfo["DetectorCount"] = mxCreateDoubleScalar(_pProjGeom->getDetectorCount()); - mGeometryInfo["DetectorWidth"] = mxCreateDoubleScalar(_pProjGeom->getDetectorWidth()); - mGeometryInfo["DistanceOriginSource"] = mxCreateDoubleScalar(pFanFlatGeom->getOriginSourceDistance()); - mGeometryInfo["DistanceOriginDetector"] = mxCreateDoubleScalar(pFanFlatGeom->getOriginDetectorDistance()); - - mxArray* pAngles = mxCreateDoubleMatrix(1, pFanFlatGeom->getProjectionAngleCount(), mxREAL); - double* out = mxGetPr(pAngles); - for (int i = 0; i < pFanFlatGeom->getProjectionAngleCount(); i++) { - out[i] = pFanFlatGeom->getProjectionAngle(i); - } - mGeometryInfo["ProjectionAngles"] = pAngles; - } - - // fanflat_vec - else if (_pProjGeom->isOfType("fanflat_vec")) { - astra::CFanFlatVecProjectionGeometry2D* pVecGeom = dynamic_cast(_pProjGeom); - - mGeometryInfo["type"] = mxCreateString("fanflat_vec"); - mGeometryInfo["DetectorCount"] = mxCreateDoubleScalar(pVecGeom->getDetectorCount()); - - mxArray* pVectors = mxCreateDoubleMatrix(pVecGeom->getProjectionAngleCount(), 6, mxREAL); - double* out = mxGetPr(pVectors); - int iDetCount = pVecGeom->getDetectorCount(); - int iAngleCount = pVecGeom->getProjectionAngleCount(); - for (int i = 0; i < pVecGeom->getProjectionAngleCount(); i++) { - const SFanProjection* p = &pVecGeom->getProjectionVectors()[i]; - out[0*iAngleCount + i] = p->fSrcX; - out[1*iAngleCount + i] = p->fSrcY; - out[2*iAngleCount + i] = p->fDetSX + 0.5f*iDetCount*p->fDetUX; - out[3*iAngleCount + i] = p->fDetSY + 0.5f*iDetCount*p->fDetUY; - out[4*iAngleCount + i] = p->fDetUX; - out[5*iAngleCount + i] = p->fDetUY; - } - mGeometryInfo["Vectors"] = pVectors; - } - - // sparse_matrix - else if (_pProjGeom->isOfType("sparse_matrix")) { - astra::CSparseMatrixProjectionGeometry2D* pSparseMatrixGeom = dynamic_cast(_pProjGeom); - mGeometryInfo["type"] = mxCreateString("sparse_matrix"); - mGeometryInfo["MatrixID"] = mxCreateDoubleScalar(CMatrixManager::getSingleton().getIndex(pSparseMatrixGeom->getMatrix())); - } - - // build and return the MATLAB struct - return buildStruct(mGeometryInfo); -} - -//----------------------------------------------------------------------------------------- -// create 3D projection geometry struct -mxArray* createProjectionGeometryStruct(astra::CProjectionGeometry3D* _pProjGeom) -{ - // temporary map to store the data for the MATLAB struct - std::map mGeometryInfo; - - // parallel beam - if (_pProjGeom->isOfType("parallel3d")) { - mGeometryInfo["type"] = mxCreateString("parallel3d"); - mGeometryInfo["DetectorRowCount"] = mxCreateDoubleScalar(_pProjGeom->getDetectorRowCount()); - mGeometryInfo["DetectorColCount"] = mxCreateDoubleScalar(_pProjGeom->getDetectorColCount()); - mGeometryInfo["DetectorSpacingX"] = mxCreateDoubleScalar(_pProjGeom->getDetectorSpacingX()); - mGeometryInfo["DetectorSpacingY"] = mxCreateDoubleScalar(_pProjGeom->getDetectorSpacingY()); - - mxArray* pAngles = mxCreateDoubleMatrix(1, _pProjGeom->getProjectionCount(), mxREAL); - double* out = mxGetPr(pAngles); - for (int i = 0; i < _pProjGeom->getProjectionCount(); i++) { - out[i] = _pProjGeom->getProjectionAngle(i); - } - mGeometryInfo["ProjectionAngles"] = pAngles; - } - - // parallel beam vector - if (_pProjGeom->isOfType("parallel3d_vec")) { - astra::CParallelVecProjectionGeometry3D* pVecGeom = dynamic_cast(_pProjGeom); - - mGeometryInfo["type"] = mxCreateString("parallel3d_vec"); - mGeometryInfo["DetectorRowCount"] = mxCreateDoubleScalar(pVecGeom->getDetectorRowCount()); - mGeometryInfo["DetectorColCount"] = mxCreateDoubleScalar(pVecGeom->getDetectorColCount()); - - mxArray* pVectors = mxCreateDoubleMatrix(pVecGeom->getProjectionCount(), 12, mxREAL); - double* out = mxGetPr(pVectors); - int iDetRowCount = pVecGeom->getDetectorRowCount(); - int iDetColCount = pVecGeom->getDetectorColCount(); - int iAngleCount = pVecGeom->getProjectionCount(); - for (int i = 0; i < pVecGeom->getProjectionCount(); i++) { - const SPar3DProjection* p = &pVecGeom->getProjectionVectors()[i]; - out[ 0*iAngleCount + i] = p->fRayX; - out[ 1*iAngleCount + i] = p->fRayY; - out[ 2*iAngleCount + i] = p->fRayZ; - out[ 3*iAngleCount + i] = p->fDetSX + 0.5f*iDetRowCount*p->fDetUX + 0.5f*iDetColCount*p->fDetVX; - out[ 4*iAngleCount + i] = p->fDetSY + 0.5f*iDetRowCount*p->fDetUY + 0.5f*iDetColCount*p->fDetVY; - out[ 5*iAngleCount + i] = p->fDetSZ + 0.5f*iDetRowCount*p->fDetUZ + 0.5f*iDetColCount*p->fDetVZ; - out[ 6*iAngleCount + i] = p->fDetUX; - out[ 7*iAngleCount + i] = p->fDetUY; - out[ 8*iAngleCount + i] = p->fDetUZ; - out[ 9*iAngleCount + i] = p->fDetVX; - out[10*iAngleCount + i] = p->fDetVY; - out[11*iAngleCount + i] = p->fDetVZ; - } - mGeometryInfo["Vectors"] = pVectors; - } - - // cone beam - else if (_pProjGeom->isOfType("cone")) { - astra::CConeProjectionGeometry3D* pConeGeom = dynamic_cast(_pProjGeom); - - mGeometryInfo["type"] = mxCreateString("cone"); - mGeometryInfo["DetectorRowCount"] = mxCreateDoubleScalar(pConeGeom->getDetectorRowCount()); - mGeometryInfo["DetectorColCount"] = mxCreateDoubleScalar(pConeGeom->getDetectorColCount()); - mGeometryInfo["DetectorSpacingX"] = mxCreateDoubleScalar(pConeGeom->getDetectorSpacingX()); - mGeometryInfo["DetectorSpacingY"] = mxCreateDoubleScalar(pConeGeom->getDetectorSpacingY()); - mGeometryInfo["DistanceOriginSource"] = mxCreateDoubleScalar(pConeGeom->getOriginSourceDistance()); - mGeometryInfo["DistanceOriginDetector"] = mxCreateDoubleScalar(pConeGeom->getOriginDetectorDistance()); - - mxArray* pAngles = mxCreateDoubleMatrix(1, pConeGeom->getProjectionCount(), mxREAL); - double* out = mxGetPr(pAngles); - for (int i = 0; i < pConeGeom->getProjectionCount(); i++) { - out[i] = pConeGeom->getProjectionAngle(i); - } - mGeometryInfo["ProjectionAngles"] = pAngles; - } - - // cone beam vector - else if (_pProjGeom->isOfType("cone_vec")) { - astra::CConeVecProjectionGeometry3D* pConeVecGeom = dynamic_cast(_pProjGeom); - - mGeometryInfo["type"] = mxCreateString("cone_vec"); - mGeometryInfo["DetectorRowCount"] = mxCreateDoubleScalar(pConeVecGeom->getDetectorRowCount()); - mGeometryInfo["DetectorColCount"] = mxCreateDoubleScalar(pConeVecGeom->getDetectorColCount()); - - mxArray* pVectors = mxCreateDoubleMatrix(pConeVecGeom->getProjectionCount(), 12, mxREAL); - double* out = mxGetPr(pVectors); - int iDetRowCount = pConeVecGeom->getDetectorRowCount(); - int iDetColCount = pConeVecGeom->getDetectorColCount(); - int iAngleCount = pConeVecGeom->getProjectionCount(); - for (int i = 0; i < pConeVecGeom->getProjectionCount(); i++) { - const SConeProjection* p = &pConeVecGeom->getProjectionVectors()[i]; - out[ 0*iAngleCount + i] = p->fSrcX; - out[ 1*iAngleCount + i] = p->fSrcY; - out[ 2*iAngleCount + i] = p->fSrcZ; - out[ 3*iAngleCount + i] = p->fDetSX + 0.5f*iDetRowCount*p->fDetUX + 0.5f*iDetColCount*p->fDetVX; - out[ 4*iAngleCount + i] = p->fDetSY + 0.5f*iDetRowCount*p->fDetUY + 0.5f*iDetColCount*p->fDetVY; - out[ 5*iAngleCount + i] = p->fDetSZ + 0.5f*iDetRowCount*p->fDetUZ + 0.5f*iDetColCount*p->fDetVZ; - out[ 6*iAngleCount + i] = p->fDetUX; - out[ 7*iAngleCount + i] = p->fDetUY; - out[ 8*iAngleCount + i] = p->fDetUZ; - out[ 9*iAngleCount + i] = p->fDetVX; - out[10*iAngleCount + i] = p->fDetVY; - out[11*iAngleCount + i] = p->fDetVZ; - } - mGeometryInfo["Vectors"] = pVectors; - } - - // build and return the MATLAB struct - return buildStruct(mGeometryInfo); -} - //----------------------------------------------------------------------------------------- // parse reconstruction geometry data astra::CVolumeGeometry2D* parseVolumeGeometryStruct(const mxArray* prhs) @@ -445,48 +269,6 @@ astra::CVolumeGeometry2D* parseVolumeGeometryStruct(const mxArray* prhs) fWindowMaxX, fWindowMaxY); } -//----------------------------------------------------------------------------------------- -// create 2D volume geometry struct -// mxArray* createVolumeGeometryStruct(astra::CVolumeGeometry2D* _pVolGeom) -// { -// std::map mGeometryInfo; - -// mGeometryInfo["GridColCount"] = mxCreateDoubleScalar(_pVolGeom->getGridColCount()); -// mGeometryInfo["GridRowCount"] = 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()); - -// mGeometryInfo["option"] = buildStruct(mGeometryOptions); - -// 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) @@ -640,7 +422,6 @@ XMLDocument* struct2XML(string rootname, const mxArray* pStruct) // read the struct bool ret = readStruct(rootnode, pStruct); - //doc->getRootNode()->print(); delete rootnode; if (!ret) { @@ -714,8 +495,21 @@ bool mex_is_scalar(const mxArray* pInput) return (mxIsNumeric(pInput) && mxGetM(pInput)*mxGetN(pInput) == 1); } + + + + + + + + + + + + + //----------------------------------------------------------------------------------------- -mxArray* config2struct(astra::Config* cfg) +mxArray* configToStruct(astra::Config* cfg) { return XMLNode2struct(cfg->self); } @@ -730,22 +524,67 @@ mxArray* XML2struct(astra::XMLDocument* xml) } //----------------------------------------------------------------------------------------- -mxArray* XMLNode2option(astra::XMLNode* node) +mxArray* stringToMxArray(std::string input) { + // matrix + if (input.find(';') != std::string::npos) { + + // split rows + std::vector row_strings; + std::vector col_strings; + boost::split(row_strings, input, boost::is_any_of(";")); + boost::split(col_strings, row_strings[0], boost::is_any_of(",")); + + // get dimensions + int rows = row_strings.size(); + int cols = col_strings.size(); + + // init matrix + mxArray* pMatrix = mxCreateDoubleMatrix(rows, cols, mxREAL); + double* out = mxGetPr(pMatrix); + + // loop elements + for (unsigned int row = 0; row < rows; row++) { + boost::split(col_strings, row_strings[row], boost::is_any_of(",")); + // check size + for (unsigned int col = 0; col < col_strings.size(); col++) { + out[col*rows + row] = boost::lexical_cast(col_strings[col]); + } + } + return pMatrix; + } + + // vector + if (input.find(',') != std::string::npos) { + + // split + std::vector items; + boost::split(items, input, boost::is_any_of(",")); + + // init matrix + mxArray* pVector = mxCreateDoubleMatrix(1, items.size(), mxREAL); + double* out = mxGetPr(pVector); + + // loop elements + for (unsigned int i = 0; i < items.size(); i++) { + out[i] = boost::lexical_cast(items[i]); + } + return pVector; + } + + // number char* end; - double content = ::strtod(node->getAttribute("value").c_str(), &end); + double content = ::strtod(input.c_str(), &end); bool isnumber = !*end; - - // float if (isnumber) { return mxCreateDoubleScalar(content); } + // string - else { - return mxCreateString(node->getAttribute("value").c_str()); - } + return mxCreateString(input.c_str()); } +//----------------------------------------------------------------------------------------- mxArray* XMLNode2struct(astra::XMLNode* node) { std::map mList; @@ -760,30 +599,19 @@ mxArray* XMLNode2struct(astra::XMLNode* node) for (list::iterator it = nodes.begin(); it != nodes.end(); it++) { XMLNode* subnode = (*it); - char* end; - double content = ::strtod(subnode->getContent().c_str(), &end); - bool isnumber = !*end; - // option if (subnode->getName() == "Option") { - mOptions[subnode->getAttribute("key")] = XMLNode2option(subnode); - } - // list - // else if (subnode->hasAttribute("listsize")) { - // mList[subnode->getName()] = vectorToMxArray(node->getContentNumericalArray()); - // } - // float - else if (isnumber) { - mList[subnode->getName()] = mxCreateDoubleScalar(content); + mOptions[subnode->getAttribute("key")] = stringToMxArray(subnode->getAttribute("value")); } - // string + + // regular content else { - mList[subnode->getName()] = mxCreateString(subnode->getContent().c_str()); + mList[subnode->getName()] = stringToMxArray(subnode->getContent()); } delete subnode; } - mList["options"] = buildStruct(mOptions); + if (mOptions.size() > 0) mList["options"] = buildStruct(mOptions); return buildStruct(mList); } @@ -791,6 +619,12 @@ mxArray* XMLNode2struct(astra::XMLNode* node) + + + + + +//----------------------------------------------------------------------------------------- void get3DMatrixDims(const mxArray* x, mwSize *dims) { const mwSize* mdims = mxGetDimensions(x); -- cgit v1.2.3 From 169e912d2633cda7ffc234e78afba1b096e122ea Mon Sep 17 00:00:00 2001 From: Wim van Aarle Date: Thu, 26 Feb 2015 16:11:38 +0100 Subject: code cleanup --- matlab/mex/mexHelpFunctions.cpp | 601 ++++++++++++++-------------------------- 1 file changed, 205 insertions(+), 396 deletions(-) (limited to 'matlab/mex/mexHelpFunctions.cpp') diff --git a/matlab/mex/mexHelpFunctions.cpp b/matlab/mex/mexHelpFunctions.cpp index c25123a..c0ac711 100644 --- a/matlab/mex/mexHelpFunctions.cpp +++ b/matlab/mex/mexHelpFunctions.cpp @@ -38,307 +38,154 @@ $Id$ #include #include -#include "astra/SparseMatrixProjectionGeometry2D.h" -#include "astra/FanFlatVecProjectionGeometry2D.h" -#include "astra/AstraObjectManager.h" - using namespace std; using namespace astra; //----------------------------------------------------------------------------------------- // get string from matlab -std::string mex_util_get_string(const mxArray* pInput) +string mexToString(const mxArray* pInput) { - if (!mxIsChar(pInput)) { - return ""; + // is string? + if (mxIsChar(pInput)) { + mwSize iLength = mxGetNumberOfElements(pInput) + 1; + char* buf = new char[iLength]; + mxGetString(pInput, buf, iLength); + std::string res = std::string(buf); + delete[] buf; + return res; } - mwSize iLength = mxGetNumberOfElements(pInput) + 1; - char* buf = new char[iLength]; - mxGetString(pInput, buf, iLength); - std::string res = std::string(buf); - delete[] buf; - return res; + + // is scalar? + if (mxIsNumeric(pInput) && mxGetM(pInput)*mxGetN(pInput) == 1) { + return boost::lexical_cast(mxGetScalar(pInput)); + } + + return ""; } //----------------------------------------------------------------------------------------- -// is option -bool isOption(std::list lOptions, std::string sOption) +// return true if the argument is a scalar +bool mexIsScalar(const mxArray* pInput) { - return std::find(lOptions.begin(), lOptions.end(), sOption) != lOptions.end(); + return (mxIsNumeric(pInput) && mxGetM(pInput)*mxGetN(pInput) == 1); } //----------------------------------------------------------------------------------------- -// turn a matlab struct into a c++ map -std::map parseStruct(const mxArray* pInput) +void get3DMatrixDims(const mxArray* x, mwSize *dims) { - std::map res; - - // check type - if (!mxIsStruct(pInput)) { - mexErrMsgTxt("Input must be a struct."); - return res; + const mwSize* mdims = mxGetDimensions(x); + mwSize dimCount = mxGetNumberOfDimensions(x); + if (dimCount == 1) { + dims[0] = mdims[0]; + dims[1] = 1; + dims[2] = 1; + } else if (dimCount == 2) { + dims[0] = mdims[0]; + dims[1] = mdims[1]; + dims[2] = 1; + } else if (dimCount == 3) { + dims[0] = mdims[0]; + dims[1] = mdims[1]; + dims[2] = mdims[2]; + } else { + dims[0] = 0; + dims[1] = 0; + dims[2] = 0; } +} + + + + - // get field names - int nfields = mxGetNumberOfFields(pInput); - for (int i = 0; i < nfields; i++) { - std::string sFieldName = std::string(mxGetFieldNameByNumber(pInput, i)); - res[sFieldName] = mxGetFieldByNumber(pInput,0,i); - } - return res; -} //----------------------------------------------------------------------------------------- -// turn a c++ map into a matlab struct -mxArray* buildStruct(std::map mInput) +// turn an std vector object to an mxArray +mxArray* vectorToMxArray(std::vector mInput) { - mwSize dims[2] = {1, 1}; - mxArray* res = mxCreateStructArray(2,dims,0,0); - - for (std::map::iterator it = mInput.begin(); it != mInput.end(); it++) { - mxAddField(res, (*it).first.c_str()); - mxSetField(res, 0, (*it).first.c_str(), (*it).second); + mxArray* res = mxCreateDoubleMatrix(1, mInput.size(), mxREAL); + double* pdData = mxGetPr(res); + for (unsigned int i = 0; i < mInput.size(); i++) { + pdData[i] = mInput[i]; } return res; } //----------------------------------------------------------------------------------------- -// parse projection geometry data -astra::CProjectionGeometry2D* parseProjectionGeometryStruct(const mxArray* prhs) +// turn a vector> object to an mxArray +mxArray* vector2DToMxArray(std::vector > mInput) { - // parse struct - std::map mStruct = parseStruct(prhs); - - // create projection geometry object - string type = mex_util_get_string(mStruct["type"]); - if (type == "parallel") { - - // detector_width - float32 fDetWidth = 1.0f; - mxArray* tmp = mStruct["detector_width"]; - if (tmp != NULL) { - fDetWidth = (float32)(mxGetScalar(tmp)); - } - - // detector_count - int iDetCount = 100; - tmp = mStruct["detector_count"]; - if (tmp != NULL) { - iDetCount = (int)(mxGetScalar(tmp)); - } - - // angles - float32* pfAngles; - int iAngleCount; - tmp = mStruct["projection_angles"]; - if (tmp != NULL) { - double* angleValues = mxGetPr(tmp); - iAngleCount = mxGetN(tmp) * mxGetM(tmp); - pfAngles = new float32[iAngleCount]; - for (int i = 0; i < iAngleCount; i++) { - pfAngles[i] = angleValues[i]; - } - } else { - mexErrMsgTxt("'angles' not specified, error."); - return NULL; - } - - // create projection geometry - return new astra::CParallelProjectionGeometry2D(iAngleCount, // number of projections - iDetCount, // number of detectors - fDetWidth, // width of the detectors - pfAngles); // angles array - } - - else if (type == "fanflat") { - - // detector_width - float32 fDetWidth = 1.0f; - mxArray* tmp = mStruct["detector_width"]; - if (tmp != NULL) { - fDetWidth = (float32)(mxGetScalar(tmp)); - } - - // detector_count - int iDetCount = 100; - tmp = mStruct["detector_count"]; - if (tmp != NULL) { - iDetCount = (int)(mxGetScalar(tmp)); - } - - // angles - float32* pfAngles; - int iAngleCount; - tmp = mStruct["projection_angles"]; - if (tmp != NULL) { - double* angleValues = mxGetPr(tmp); - iAngleCount = mxGetN(tmp) * mxGetM(tmp); - pfAngles = new float32[iAngleCount]; - for (int i = 0; i < iAngleCount; i++) { - pfAngles[i] = angleValues[i]; - } - } else { - mexErrMsgTxt("'angles' not specified, error."); - return NULL; - } - - // origin_source_dist - int iDistOriginSource = 100; - tmp = mStruct["origin_source_dist"]; - if (tmp != NULL) { - iDistOriginSource = (int)(mxGetScalar(tmp)); - } + unsigned int sizex = mInput.size(); + if (sizex == 0) return mxCreateString("empty"); + unsigned int sizey = mInput[0].size(); - // origin_det_dist - int iDistOriginDet = 100; - tmp = mStruct["origin_det_dist"]; - if (tmp != NULL) { - iDistOriginDet = (int)(mxGetScalar(tmp)); + mxArray* res = mxCreateDoubleMatrix(sizex, sizey, mxREAL); + double* pdData = mxGetPr(res); + for (unsigned int i = 0; i < sizex; i++) { + for (unsigned int j = 0; j < sizey && j < mInput[i].size(); j++) { + pdData[j*sizex+i] = mInput[i][j]; } - - // create projection geometry - return new astra::CFanFlatProjectionGeometry2D(iAngleCount, // number of projections - iDetCount, // number of detectors - fDetWidth, // width of the detectors - pfAngles, // angles array - iDistOriginSource, // distance origin source - iDistOriginDet); // distance origin detector - } - - else { - mexPrintf("Only parallel and fanflat projection geometry implemented."); - return NULL; } + return res; } //----------------------------------------------------------------------------------------- -// parse reconstruction geometry data -astra::CVolumeGeometry2D* parseVolumeGeometryStruct(const mxArray* prhs) +// turn a boost::any object to an mxArray +mxArray* anyToMxArray(boost::any _any) { - // parse struct - std::map mStruct = parseStruct(prhs); - - std::map mOptions = parseStruct(mStruct["option"]); - - // GridColCount - int iWindowColCount = 128; - mxArray* tmp = mStruct["GridColCount"]; - if (tmp != NULL) { - iWindowColCount = (int)(mxGetScalar(tmp)); - } - - // GridRowCount - int iWindowRowCount = 128; - tmp = mStruct["GridRowCount"]; - if (tmp != NULL) { - iWindowRowCount = (int)(mxGetScalar(tmp)); + if (_any.type() == typeid(std::string)) { + std::string str = boost::any_cast(_any); + return mxCreateString(str.c_str()); } - - // WindowMinX - float32 fWindowMinX = - iWindowColCount / 2; - tmp = mOptions["WindowMinX"]; - if (tmp != NULL) { - fWindowMinX = (float32)(mxGetScalar(tmp)); - } - - // WindowMaxX - float32 fWindowMaxX = iWindowColCount / 2; - tmp = mOptions["WindowMaxX"]; - if (tmp != NULL) { - fWindowMaxX = (float32)(mxGetScalar(tmp)); - } - - // WindowMinY - float32 fWindowMinY = - iWindowRowCount / 2; - tmp = mOptions["WindowMinY"]; - if (tmp != NULL) { - fWindowMinY = (float32)(mxGetScalar(tmp)); - } - - // WindowMaxX - float32 fWindowMaxY = iWindowRowCount / 2; - tmp = mOptions["WindowMaxY"]; - if (tmp != NULL) { - fWindowMaxY = (float32)(mxGetScalar(tmp)); - } - - // create and return reconstruction geometry - return new astra::CVolumeGeometry2D(iWindowColCount, iWindowRowCount, - fWindowMinX, fWindowMinY, - fWindowMaxX, fWindowMaxY); + if (_any.type() == typeid(int)) { + return mxCreateDoubleScalar(boost::any_cast(_any)); + } + if (_any.type() == typeid(float32)) { + return mxCreateDoubleScalar(boost::any_cast(_any)); + } + if (_any.type() == typeid(std::vector)) { + return vectorToMxArray(boost::any_cast >(_any)); + } + if (_any.type() == typeid(std::vector >)) { + return vector2DToMxArray(boost::any_cast > >(_any)); + } + return NULL; } -//----------------------------------------------------------------------------------------- -string matlab2string(const mxArray* pField) -{ - // is string? - if (mxIsChar(pField)) { - return mex_util_get_string(pField); - } - // is scalar? - if (mxIsNumeric(pField) && mxGetM(pField)*mxGetN(pField) == 1) { - return boost::lexical_cast(mxGetScalar(pField)); - } - return ""; -} + + + + //----------------------------------------------------------------------------------------- -// Options struct to xml node -bool readOptions(XMLNode* node, const mxArray* pOptionStruct) +// turn a MATLAB struct into a Config object +Config* structToConfig(string rootname, const mxArray* pStruct) { - // loop all fields - int nfields = mxGetNumberOfFields(pOptionStruct); - for (int i = 0; i < nfields; i++) { - std::string sFieldName = std::string(mxGetFieldNameByNumber(pOptionStruct, i)); - const mxArray* pField = mxGetFieldByNumber(pOptionStruct, 0, i); + if (!mxIsStruct(pStruct)) { + mexErrMsgTxt("Input must be a struct."); + return NULL; + } - if (node->hasOption(sFieldName)) { - mexErrMsgTxt("Duplicate option"); - return false; - } - - // string or scalar - if (mxIsChar(pField) || mex_is_scalar(pField)) { - string sValue = matlab2string(pField); - node->addOption(sFieldName, sValue); - } else - // numerical array - if (mxIsNumeric(pField) && mxGetM(pField)*mxGetN(pField) > 1) { - if (!mxIsDouble(pField)) { - mexErrMsgTxt("Numeric input must be double."); - return false; - } + // create the document + Config* cfg = new Config(); + cfg->initialize(rootname); - XMLNode* listbase = node->addChildNode("Option"); - listbase->addAttribute("key", sFieldName); - listbase->addAttribute("listsize", mxGetM(pField)*mxGetN(pField)); - double* pdValues = mxGetPr(pField); - int index = 0; - for (unsigned int row = 0; row < mxGetM(pField); row++) { - for (unsigned int col = 0; col < mxGetN(pField); col++) { - XMLNode* item = listbase->addChildNode("ListItem"); - item->addAttribute("index", index); - item->addAttribute("value", pdValues[col*mxGetM(pField)+row]); - index++; - delete item; - } - } - delete listbase; - } else { - mexErrMsgTxt("Unsupported option type"); - return false; - } + // read the struct + bool ret = structToXMLNode(cfg->self, pStruct); + if (!ret) { + delete cfg; + mexErrMsgTxt("Error parsing struct."); + return NULL; } - return true; + return cfg; } //----------------------------------------------------------------------------------------- -// struct to xml node -bool readStruct(XMLNode* root, const mxArray* pStruct) +bool structToXMLNode(XMLNode* node, const mxArray* pStruct) { // loop all fields int nfields = mxGetNumberOfFields(pStruct); @@ -350,27 +197,27 @@ bool readStruct(XMLNode* root, const mxArray* pStruct) // string if (mxIsChar(pField)) { - string sValue = matlab2string(pField); + string sValue = mexToString(pField); if (sFieldName == "type") { - root->addAttribute("type", sValue); + node->addAttribute("type", sValue); } else { - delete root->addChildNode(sFieldName, sValue); + delete node->addChildNode(sFieldName, sValue); } } // scalar - if (mex_is_scalar(pField)) { - string sValue = matlab2string(pField); - delete root->addChildNode(sFieldName, sValue); + else if (mxIsNumeric(pField) && mxGetM(pField)*mxGetN(pField) == 1) { + string sValue = mexToString(pField); + delete node->addChildNode(sFieldName, sValue); } // numerical array - if (mxIsNumeric(pField) && mxGetM(pField)*mxGetN(pField) > 1) { + else if (mxIsNumeric(pField) && mxGetM(pField)*mxGetN(pField) > 1) { if (!mxIsDouble(pField)) { mexErrMsgTxt("Numeric input must be double."); return false; } - XMLNode* listbase = root->addChildNode(sFieldName); + XMLNode* listbase = node->addChildNode(sFieldName); listbase->addAttribute("listsize", mxGetM(pField)*mxGetN(pField)); double* pdValues = mxGetPr(pField); int index = 0; @@ -386,16 +233,15 @@ bool readStruct(XMLNode* root, const mxArray* pStruct) delete listbase; } - // not castable to a single string - if (mxIsStruct(pField)) { + else if (mxIsStruct(pField)) { if (sFieldName == "options" || sFieldName == "option" || sFieldName == "Options" || sFieldName == "Option") { - bool ret = readOptions(root, pField); + bool ret = optionsToXMLNode(node, pField); if (!ret) return false; } else { - XMLNode* newNode = root->addChildNode(sFieldName); - bool ret = readStruct(newNode, pField); + XMLNode* newNode = node->addChildNode(sFieldName); + bool ret = structToXMLNode(newNode, pField); delete newNode; if (!ret) return false; @@ -406,93 +252,74 @@ bool readStruct(XMLNode* root, const mxArray* pStruct) return true; } - //----------------------------------------------------------------------------------------- -// turn a MATLAB struct into an XML Document -XMLDocument* struct2XML(string rootname, const mxArray* pStruct) +// Options struct to xml node +bool optionsToXMLNode(XMLNode* node, const mxArray* pOptionStruct) { - if (!mxIsStruct(pStruct)) { - mexErrMsgTxt("Input must be a struct."); - return NULL; - } - - // create the document - XMLDocument* doc = XMLDocument::createDocument(rootname); - XMLNode* rootnode = doc->getRootNode(); - - // read the struct - bool ret = readStruct(rootnode, pStruct); - delete rootnode; - - if (!ret) { - delete doc; - doc = 0; - } - - return doc; -} - - - + // loop all fields + int nfields = mxGetNumberOfFields(pOptionStruct); + for (int i = 0; i < nfields; i++) { + std::string sFieldName = std::string(mxGetFieldNameByNumber(pOptionStruct, i)); + const mxArray* pField = mxGetFieldByNumber(pOptionStruct, 0, i); + if (node->hasOption(sFieldName)) { + mexErrMsgTxt("Duplicate option"); + return false; + } + + // string or scalar + if (mxIsChar(pField) || mexIsScalar(pField)) { + string sValue = mexToString(pField); + node->addOption(sFieldName, sValue); + } + // numerical array + else if (mxIsNumeric(pField) && mxGetM(pField)*mxGetN(pField) > 1) { + if (!mxIsDouble(pField)) { + mexErrMsgTxt("Numeric input must be double."); + return false; + } -//----------------------------------------------------------------------------------------- -// turn an std vector object to an mxArray -mxArray* vectorToMxArray(std::vector mInput) -{ - mxArray* res = mxCreateDoubleMatrix(1, mInput.size(), mxREAL); - double* pdData = mxGetPr(res); - for (unsigned int i = 0; i < mInput.size(); i++) { - pdData[i] = mInput[i]; + XMLNode* listbase = node->addChildNode("Option"); + listbase->addAttribute("key", sFieldName); + listbase->addAttribute("listsize", mxGetM(pField)*mxGetN(pField)); + double* pdValues = mxGetPr(pField); + int index = 0; + for (unsigned int row = 0; row < mxGetM(pField); row++) { + for (unsigned int col = 0; col < mxGetN(pField); col++) { + XMLNode* item = listbase->addChildNode("ListItem"); + item->addAttribute("index", index); + item->addAttribute("value", pdValues[col*mxGetM(pField)+row]); + index++; + delete item; + } + } + delete listbase; + } else { + mexErrMsgTxt("Unsupported option type"); + return false; + } } - return res; + return true; } - //----------------------------------------------------------------------------------------- -// turn a vector> object to an mxArray -mxArray* vector2DToMxArray(std::vector > mInput) +// turn a matlab struct into a c++ map +std::map parseStruct(const mxArray* pInput) { - unsigned int sizex = mInput.size(); - if (sizex == 0) return mxCreateString("empty"); - unsigned int sizey = mInput[0].size(); + std::map res; - mxArray* res = mxCreateDoubleMatrix(sizex, sizey, mxREAL); - double* pdData = mxGetPr(res); - for (unsigned int i = 0; i < sizex; i++) { - for (unsigned int j = 0; j < sizey && j < mInput[i].size(); j++) { - pdData[j*sizex+i] = mInput[i][j]; - } + // check type + if (!mxIsStruct(pInput)) { + mexErrMsgTxt("Input must be a struct."); + return res; } - return res; -} -//----------------------------------------------------------------------------------------- -// turn a boost::any object to an mxArray -mxArray* anyToMxArray(boost::any _any) -{ - if (_any.type() == typeid(std::string)) { - std::string str = boost::any_cast(_any); - return mxCreateString(str.c_str()); - } - if (_any.type() == typeid(int)) { - return mxCreateDoubleScalar(boost::any_cast(_any)); - } - if (_any.type() == typeid(float32)) { - return mxCreateDoubleScalar(boost::any_cast(_any)); - } - if (_any.type() == typeid(std::vector)) { - return vectorToMxArray(boost::any_cast >(_any)); - } - if (_any.type() == typeid(std::vector >)) { - return vector2DToMxArray(boost::any_cast > >(_any)); + // get field names + int nfields = mxGetNumberOfFields(pInput); + for (int i = 0; i < nfields; i++) { + std::string sFieldName = std::string(mxGetFieldNameByNumber(pInput, i)); + res[sFieldName] = mxGetFieldByNumber(pInput,0,i); } - return NULL; -} -//----------------------------------------------------------------------------------------- -// return true ig the argument is a scalar -bool mex_is_scalar(const mxArray* pInput) -{ - return (mxIsNumeric(pInput) && mxGetM(pInput)*mxGetN(pInput) == 1); + return res; } @@ -509,18 +336,41 @@ bool mex_is_scalar(const mxArray* pInput) //----------------------------------------------------------------------------------------- +// turn a Config object into a MATLAB struct mxArray* configToStruct(astra::Config* cfg) { - return XMLNode2struct(cfg->self); + return XMLNodeToStruct(cfg->self); } //----------------------------------------------------------------------------------------- -mxArray* XML2struct(astra::XMLDocument* xml) +mxArray* XMLNodeToStruct(astra::XMLNode* node) { - XMLNode* node = xml->getRootNode(); - mxArray* str = XMLNode2struct(xml->getRootNode()); - delete node; - return str; + std::map mList; + std::map mOptions; + + // type_attribute + if (node->hasAttribute("type")) { + mList["type"] = mxCreateString(node->getAttribute("type").c_str()); + } + + list nodes = node->getNodes(); + for (list::iterator it = nodes.begin(); it != nodes.end(); it++) { + XMLNode* subnode = (*it); + + // option + if (subnode->getName() == "Option") { + mOptions[subnode->getAttribute("key")] = stringToMxArray(subnode->getAttribute("value")); + } + + // regular content + else { + mList[subnode->getName()] = stringToMxArray(subnode->getContent()); + } + delete subnode; + } + + if (mOptions.size() > 0) mList["options"] = buildStruct(mOptions); + return buildStruct(mList); } //----------------------------------------------------------------------------------------- @@ -583,36 +433,18 @@ mxArray* stringToMxArray(std::string input) // string return mxCreateString(input.c_str()); } - //----------------------------------------------------------------------------------------- -mxArray* XMLNode2struct(astra::XMLNode* node) +// turn a c++ map into a matlab struct +mxArray* buildStruct(std::map mInput) { - std::map mList; - std::map mOptions; - - // type_attribute - if (node->hasAttribute("type")) { - mList["type"] = mxCreateString(node->getAttribute("type").c_str()); - } - - list nodes = node->getNodes(); - for (list::iterator it = nodes.begin(); it != nodes.end(); it++) { - XMLNode* subnode = (*it); - - // option - if (subnode->getName() == "Option") { - mOptions[subnode->getAttribute("key")] = stringToMxArray(subnode->getAttribute("value")); - } - - // regular content - else { - mList[subnode->getName()] = stringToMxArray(subnode->getContent()); - } - delete subnode; + mwSize dims[2] = {1, 1}; + mxArray* res = mxCreateStructArray(2,dims,0,0); + + for (std::map::iterator it = mInput.begin(); it != mInput.end(); it++) { + mxAddField(res, (*it).first.c_str()); + mxSetField(res, 0, (*it).first.c_str(), (*it).second); } - - if (mOptions.size() > 0) mList["options"] = buildStruct(mOptions); - return buildStruct(mList); + return res; } @@ -624,26 +456,3 @@ mxArray* XMLNode2struct(astra::XMLNode* node) -//----------------------------------------------------------------------------------------- -void get3DMatrixDims(const mxArray* x, mwSize *dims) -{ - const mwSize* mdims = mxGetDimensions(x); - mwSize dimCount = mxGetNumberOfDimensions(x); - if (dimCount == 1) { - dims[0] = mdims[0]; - dims[1] = 1; - dims[2] = 1; - } else if (dimCount == 2) { - dims[0] = mdims[0]; - dims[1] = mdims[1]; - dims[2] = 1; - } else if (dimCount == 3) { - dims[0] = mdims[0]; - dims[1] = mdims[1]; - dims[2] = mdims[2]; - } else { - dims[0] = 0; - dims[1] = 0; - dims[2] = 0; - } -} -- cgit v1.2.3