diff options
author | Wim van Aarle <wimvanaarle@gmail.com> | 2015-02-26 13:47:59 +0100 |
---|---|---|
committer | Wim van Aarle <wimvanaarle@gmail.com> | 2015-02-26 13:47:59 +0100 |
commit | cca150841cd1de4f3b4d24c1188263b9623bc511 (patch) | |
tree | dca9846737f33fd9173a53231bd0bec566fb6bb3 | |
parent | 065d9c6a18f2b8eececc608ce850a9a308ca6356 (diff) | |
download | astra-cca150841cd1de4f3b4d24c1188263b9623bc511.tar.gz astra-cca150841cd1de4f3b4d24c1188263b9623bc511.tar.bz2 astra-cca150841cd1de4f3b4d24c1188263b9623bc511.tar.xz astra-cca150841cd1de4f3b4d24c1188263b9623bc511.zip |
get_geometry now uses XML config object (for projections)
25 files changed, 328 insertions, 274 deletions
diff --git a/include/astra/ConeProjectionGeometry3D.h b/include/astra/ConeProjectionGeometry3D.h index 2a0474d..6257f7e 100644 --- a/include/astra/ConeProjectionGeometry3D.h +++ b/include/astra/ConeProjectionGeometry3D.h @@ -148,6 +148,12 @@ public: */ virtual bool isEqual(const CProjectionGeometry3D*) const; + /** Get all settings in a Config object. + * + * @return Configuration Object. + */ + virtual Config* getConfiguration() const; + /** Returns true if the type of geometry defined in this class is the one specified in _sType. * * @param _sType geometry type to compare to. diff --git a/include/astra/ConeVecProjectionGeometry3D.h b/include/astra/ConeVecProjectionGeometry3D.h index 68a80ef..0330066 100644 --- a/include/astra/ConeVecProjectionGeometry3D.h +++ b/include/astra/ConeVecProjectionGeometry3D.h @@ -128,6 +128,12 @@ public: */ virtual bool isEqual(const CProjectionGeometry3D*) const; + /** Get all settings in a Config object. + * + * @return Configuration Object. + */ + virtual Config* getConfiguration() const; + /** Returns true if the type of geometry defined in this class is the one specified in _sType. * * @param _sType geometry type to compare to. diff --git a/include/astra/FanFlatProjectionGeometry2D.h b/include/astra/FanFlatProjectionGeometry2D.h index 8f22c35..180fe68 100644 --- a/include/astra/FanFlatProjectionGeometry2D.h +++ b/include/astra/FanFlatProjectionGeometry2D.h @@ -140,6 +140,12 @@ public: */ virtual bool isOfType(const std::string& _sType); + /** Get all settings in a Config object. + * + * @return Configuration Object. + */ + virtual Config* getConfiguration() const; + /** Return true if this geometry instance is the same as the one specified. * * @return true if this geometry instance is the same as the one specified. diff --git a/include/astra/FanFlatVecProjectionGeometry2D.h b/include/astra/FanFlatVecProjectionGeometry2D.h index 85c994f..825bcbc 100644 --- a/include/astra/FanFlatVecProjectionGeometry2D.h +++ b/include/astra/FanFlatVecProjectionGeometry2D.h @@ -126,6 +126,13 @@ public: */ virtual bool isEqual(CProjectionGeometry2D*) const; + /** Get all settings in a Config object. + * + * @return Configuration Object. + */ + virtual Config* getConfiguration() const; + + /** Get the value for t and theta, based upon the row and column index. * * @param _iRow row index diff --git a/include/astra/ParallelProjectionGeometry2D.h b/include/astra/ParallelProjectionGeometry2D.h index ed9d228..2f7d36f 100644 --- a/include/astra/ParallelProjectionGeometry2D.h +++ b/include/astra/ParallelProjectionGeometry2D.h @@ -136,6 +136,12 @@ public: */ virtual bool isOfType(const std::string& _sType); + /** Get all settings in a Config object. + * + * @return Configuration Object. + */ + virtual Config* getConfiguration() const; + /** * Returns a vector describing the direction of a ray belonging to a certain detector, * the direction is the same for all detectors in one projection diff --git a/include/astra/ParallelProjectionGeometry3D.h b/include/astra/ParallelProjectionGeometry3D.h index da60617..aa93a29 100644 --- a/include/astra/ParallelProjectionGeometry3D.h +++ b/include/astra/ParallelProjectionGeometry3D.h @@ -129,6 +129,12 @@ public: */ virtual bool isEqual(const CProjectionGeometry3D*) const; + /** Get all settings in a Config object. + * + * @return Configuration Object. + */ + virtual Config* getConfiguration() const; + /** Returns true if the type of geometry defined in this class is the one specified in _sType. * * @param _sType geometry type to compare to. diff --git a/include/astra/ParallelVecProjectionGeometry3D.h b/include/astra/ParallelVecProjectionGeometry3D.h index fbc2112..f3ed949 100644 --- a/include/astra/ParallelVecProjectionGeometry3D.h +++ b/include/astra/ParallelVecProjectionGeometry3D.h @@ -128,6 +128,12 @@ public: */ virtual bool isEqual(const CProjectionGeometry3D*) const; + /** Get all settings in a Config object. + * + * @return Configuration Object. + */ + virtual Config* getConfiguration() const; + /** Returns true if the type of geometry defined in this class is the one specified in _sType. * * @param _sType geometry type to compare to. diff --git a/include/astra/ProjectionGeometry2D.h b/include/astra/ProjectionGeometry2D.h index 303ca0a..b8324e2 100644 --- a/include/astra/ProjectionGeometry2D.h +++ b/include/astra/ProjectionGeometry2D.h @@ -157,6 +157,12 @@ public: */ virtual bool isEqual(CProjectionGeometry2D*) const = 0; + /** Get all settings in a Config object. + * + * @return Configuration Object. + */ + virtual Config* getConfiguration() const = 0; + /** Get the number of projection angles. * * @return Number of projection angles diff --git a/include/astra/ProjectionGeometry3D.h b/include/astra/ProjectionGeometry3D.h index 41b1cb7..b6e63a8 100644 --- a/include/astra/ProjectionGeometry3D.h +++ b/include/astra/ProjectionGeometry3D.h @@ -187,6 +187,12 @@ public: */ virtual bool isEqual(const CProjectionGeometry3D *) const = 0; + /** Get all settings in a Config object. + * + * @return Configuration Object. + */ + virtual Config* getConfiguration() const = 0; + /** Get the number of projections. * * @return Number of projections diff --git a/include/astra/SparseMatrixProjectionGeometry2D.h b/include/astra/SparseMatrixProjectionGeometry2D.h index 36964be..d56f95e 100644 --- a/include/astra/SparseMatrixProjectionGeometry2D.h +++ b/include/astra/SparseMatrixProjectionGeometry2D.h @@ -103,7 +103,6 @@ public: * @param _pMatrix Pointer to a CSparseMatrix. The caller is responsible for keeping this matrix valid until it is no longer required. * @return initialization successful? */ - bool setMatrix(CSparseMatrix* _pMatrix); /** Get a pointer to the associated sparse matrix. @@ -128,6 +127,13 @@ public: */ virtual bool isOfType(const std::string& _sType); + /** Get all settings in a Config object. + * + * @return Configuration Object. + */ + virtual Config* getConfiguration() const; + + /** * Returns a vector describing the direction of a ray belonging to a certain detector * diff --git a/matlab/mex/astra_mex_data2d_c.cpp b/matlab/mex/astra_mex_data2d_c.cpp index d07a13a..03d3807 100644 --- a/matlab/mex/astra_mex_data2d_c.cpp +++ b/matlab/mex/astra_mex_data2d_c.cpp @@ -395,13 +395,11 @@ void astra_mex_data2d_get_geometry(int nlhs, mxArray* plhs[], int nrhs, const mx if (1 <= nlhs) { if (pDataObject->getType() == CFloat32Data2D::PROJECTION) { CFloat32ProjectionData2D* pDataObject2 = dynamic_cast<CFloat32ProjectionData2D*>(pDataObject); - plhs[0] = createProjectionGeometryStruct(pDataObject2->getGeometry()); + plhs[0] = configToStruct(pDataObject2->getGeometry()->getConfiguration()); } else if (pDataObject->getType() == CFloat32Data2D::VOLUME) { CFloat32VolumeData2D* pDataObject2 = dynamic_cast<CFloat32VolumeData2D*>(pDataObject); - plhs[0] = config2struct(pDataObject2->getGeometry()->getConfiguration()); - // mexErrMsgTxt(pDataObject2->getGeometry()->getConfiguration()->self->toString().c_str()); - // plhs[0] = createVolumeGeometryStruct(pDataObject2->getGeometry()); + plhs[0] = configToStruct(pDataObject2->getGeometry()->getConfiguration()); } } } diff --git a/matlab/mex/astra_mex_data3d_c.cpp b/matlab/mex/astra_mex_data3d_c.cpp index 5abdf50..64c013d 100644 --- a/matlab/mex/astra_mex_data3d_c.cpp +++ b/matlab/mex/astra_mex_data3d_c.cpp @@ -296,11 +296,12 @@ void astra_mex_data3d_get_geometry(int nlhs, mxArray* plhs[], int nrhs, const mx if (1 <= nlhs) { if (pDataObject->getType() == CFloat32Data3D::PROJECTION) { CFloat32ProjectionData3DMemory* pDataObject2 = dynamic_cast<CFloat32ProjectionData3DMemory*>(pDataObject); - plhs[0] = createProjectionGeometryStruct(pDataObject2->getGeometry()); + plhs[0] = configToStruct(pDataObject2->getGeometry()->getConfiguration()); + } else if (pDataObject->getType() == CFloat32Data3D::VOLUME) { CFloat32VolumeData3DMemory* pDataObject2 = dynamic_cast<CFloat32VolumeData3DMemory*>(pDataObject); - plhs[0] = config2struct(pDataObject2->getGeometry()->getConfiguration()); + plhs[0] = configToStruct(pDataObject2->getGeometry()->getConfiguration()); } } diff --git a/matlab/mex/astra_mex_projector3d_c.cpp b/matlab/mex/astra_mex_projector3d_c.cpp index 95b3e0f..b2f6b02 100644 --- a/matlab/mex/astra_mex_projector3d_c.cpp +++ b/matlab/mex/astra_mex_projector3d_c.cpp @@ -136,7 +136,7 @@ void astra_mex_projector3d_get_projection_geometry(int nlhs, mxArray* plhs[], in // step3: get projection_geometry and turn it into a MATLAB struct if (1 <= nlhs) { - plhs[0] = createProjectionGeometryStruct(pProjector->getProjectionGeometry()); + plhs[0] = configToStruct(pProjector->getProjectionGeometry()->getConfiguration()); } } @@ -162,7 +162,7 @@ void astra_mex_projector3d_get_volume_geometry(int nlhs, mxArray* plhs[], int nr // step3: get projection_geometry and turn it into a MATLAB struct if (1 <= nlhs) { - plhs[0] = createVolumeGeometryStruct(pProjector->getVolumeGeometry()); + plhs[0] = configToStruct(pProjector->getVolumeGeometry()->getConfiguration()); } } diff --git a/matlab/mex/astra_mex_projector_c.cpp b/matlab/mex/astra_mex_projector_c.cpp index de73f07..4793020 100644 --- a/matlab/mex/astra_mex_projector_c.cpp +++ b/matlab/mex/astra_mex_projector_c.cpp @@ -162,7 +162,7 @@ void astra_mex_projector_projection_geometry(int nlhs, mxArray* plhs[], int nrhs // step3: get projection_geometry and turn it into a MATLAB struct if (1 <= nlhs) { - plhs[0] = createProjectionGeometryStruct(pProjector->getProjectionGeometry()); + plhs[0] = configToStruct(pProjector->getProjectionGeometry()->getConfiguration()); } } @@ -191,7 +191,8 @@ void astra_mex_projector_volume_geometry(int nlhs, mxArray* plhs[], int nrhs, co // step3: get projection_geometry and turn it into a MATLAB struct if (1 <= nlhs) { - plhs[0] = createVolumeGeometryStruct(pProjector->getVolumeGeometry()); + plhs[0] = configToStruct(pProjector->getVolumeGeometry()->getConfiguration()); + } } 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 <algorithm> +#include <boost/lexical_cast.hpp> +#include <boost/algorithm/string.hpp> +#include <boost/algorithm/string/split.hpp> +#include <boost/algorithm/string/classification.hpp> + #include "astra/SparseMatrixProjectionGeometry2D.h" #include "astra/FanFlatVecProjectionGeometry2D.h" #include "astra/AstraObjectManager.h" @@ -207,188 +213,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<std::string, mxArray*> 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<astra::CFanFlatProjectionGeometry2D*>(_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<astra::CFanFlatVecProjectionGeometry2D*>(_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<astra::CSparseMatrixProjectionGeometry2D*>(_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<std::string, mxArray*> 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<astra::CParallelVecProjectionGeometry3D*>(_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<astra::CConeProjectionGeometry3D*>(_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<astra::CConeVecProjectionGeometry3D*>(_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<std::string, mxArray*> mGeometryInfo; - -// mGeometryInfo["GridColCount"] = mxCreateDoubleScalar(_pVolGeom->getGridColCount()); -// mGeometryInfo["GridRowCount"] = 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()); - -// mGeometryInfo["option"] = buildStruct(mGeometryOptions); - -// 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) @@ -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<std::string> row_strings; + std::vector<std::string> 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<float32>(col_strings[col]); + } + } + return pMatrix; + } + + // vector + if (input.find(',') != std::string::npos) { + + // split + std::vector<std::string> 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<float32>(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<std::string, mxArray*> mList; @@ -760,30 +599,19 @@ mxArray* XMLNode2struct(astra::XMLNode* node) for (list<XMLNode*>::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); diff --git a/matlab/mex/mexHelpFunctions.h b/matlab/mex/mexHelpFunctions.h index f8a7d48..6c80f8c 100644 --- a/matlab/mex/mexHelpFunctions.h +++ b/matlab/mex/mexHelpFunctions.h @@ -71,17 +71,13 @@ mxArray* anyToMxArray(boost::any _any); astra::CProjectionGeometry2D* parseProjectionGeometryStruct(const mxArray*); astra::CVolumeGeometry2D* parseVolumeGeometryStruct(const mxArray*); -mxArray* createProjectionGeometryStruct(astra::CProjectionGeometry2D*); -mxArray* createProjectionGeometryStruct(astra::CProjectionGeometry3D*); - -// mxArray* createVolumeGeometryStruct(astra::CVolumeGeometry2D* _pReconGeom); -// mxArray* createVolumeGeometryStruct(astra::CVolumeGeometry3D* _pReconGeom); - astra::XMLDocument* struct2XML(string rootname, const mxArray* pStruct); -mxArray* config2struct(astra::Config* cfg); +mxArray* configToStruct(astra::Config* cfg); mxArray* XML2struct(astra::XMLDocument* xml); mxArray* XMLNode2struct(astra::XMLNode* xml); +mxArray* stringToMxArray(std::string input); + void get3DMatrixDims(const mxArray* x, mwSize *dims); diff --git a/src/ConeProjectionGeometry3D.cpp b/src/ConeProjectionGeometry3D.cpp index e6999df..50f2c8f 100644 --- a/src/ConeProjectionGeometry3D.cpp +++ b/src/ConeProjectionGeometry3D.cpp @@ -197,6 +197,24 @@ void CConeProjectionGeometry3D::toXML(XMLNode* _sNode) const _sNode->addChildNode("DistanceOriginDetector", m_fOriginDetectorDistance); _sNode->addChildNode("DistanceOriginSource", m_fOriginSourceDistance); } + +//---------------------------------------------------------------------------------------- +// Get the configuration object +Config* CConeProjectionGeometry3D::getConfiguration() const +{ + Config* cfg = new Config(); + cfg->initialize("ProjectionGeometry3D"); + cfg->self->addAttribute("type", "cone"); + cfg->self->addChildNode("DetectorSpacingX", m_fDetectorSpacingX); + cfg->self->addChildNode("DetectorSpacingY", m_fDetectorSpacingY); + cfg->self->addChildNode("DetectorRowCount", m_iDetectorRowCount); + cfg->self->addChildNode("DetectorColCount", m_iDetectorColCount); + cfg->self->addChildNode("DistanceOriginDetector", m_fOriginDetectorDistance); + cfg->self->addChildNode("DistanceOriginSource", m_fOriginSourceDistance); + cfg->self->addChildNode("ProjectionAngles", m_pfProjectionAngles, m_iProjectionAngleCount); + return cfg; +} + //---------------------------------------------------------------------------------------- CVector3D CConeProjectionGeometry3D::getProjectionDirection(int _iProjectionIndex, int _iDetectorIndex) const diff --git a/src/ConeVecProjectionGeometry3D.cpp b/src/ConeVecProjectionGeometry3D.cpp index 3c32527..4f58188 100644 --- a/src/ConeVecProjectionGeometry3D.cpp +++ b/src/ConeVecProjectionGeometry3D.cpp @@ -210,6 +210,39 @@ void CConeVecProjectionGeometry3D::toXML(XMLNode* _sNode) const // TODO: //_sNode->addChildNode("ProjectionAngles", m_pfProjectionAngles, m_iProjectionAngleCount); } +//---------------------------------------------------------------------------------------- +// Get the configuration object +Config* CConeVecProjectionGeometry3D::getConfiguration() const +{ + Config* cfg = new Config(); + cfg->initialize("ProjectionGeometry3D"); + + cfg->self->addAttribute("type", "cone"); + cfg->self->addChildNode("DetectorRowCount", m_iDetectorRowCount); + cfg->self->addChildNode("DetectorColCount", m_iDetectorColCount); + + std::string vectors = ""; + for (int i = 0; i < m_iProjectionAngleCount; ++i) { + SConeProjection& p = m_pProjectionAngles[i]; + vectors += boost::lexical_cast<string>(p.fSrcX) + ","; + vectors += boost::lexical_cast<string>(p.fSrcY) + ","; + vectors += boost::lexical_cast<string>(p.fSrcZ) + ","; + vectors += boost::lexical_cast<string>(p.fDetSX + 0.5f*m_iDetectorRowCount*p.fDetUX + 0.5f*m_iDetectorColCount*p.fDetVX) + ","; + vectors += boost::lexical_cast<string>(p.fDetSY + 0.5f*m_iDetectorRowCount*p.fDetUY + 0.5f*m_iDetectorColCount*p.fDetVY) + ","; + vectors += boost::lexical_cast<string>(p.fDetSZ + 0.5f*m_iDetectorRowCount*p.fDetUZ + 0.5f*m_iDetectorColCount*p.fDetVZ) + ","; + vectors += boost::lexical_cast<string>(p.fDetUX) + ","; + vectors += boost::lexical_cast<string>(p.fDetUY) + ","; + vectors += boost::lexical_cast<string>(p.fDetUZ) + ","; + vectors += boost::lexical_cast<string>(p.fDetVX) + ","; + vectors += boost::lexical_cast<string>(p.fDetVY) + ","; + vectors += boost::lexical_cast<string>(p.fDetVZ); + if (i < m_iProjectionAngleCount-1) vectors += ';'; + } + cfg->self->addChildNode("Vectors", vectors); + + return cfg; +} +//---------------------------------------------------------------------------------------- CVector3D CConeVecProjectionGeometry3D::getProjectionDirection(int _iProjectionIndex, int _iDetectorIndex) const { diff --git a/src/FanFlatProjectionGeometry2D.cpp b/src/FanFlatProjectionGeometry2D.cpp index bfc7fa9..d757f18 100644 --- a/src/FanFlatProjectionGeometry2D.cpp +++ b/src/FanFlatProjectionGeometry2D.cpp @@ -204,6 +204,20 @@ CVector3D CFanFlatProjectionGeometry2D::getProjectionDirection(int _iProjectionI } //---------------------------------------------------------------------------------------- +// Get the configuration object +Config* CFanFlatProjectionGeometry2D::getConfiguration() const +{ + Config* cfg = new Config(); + cfg->initialize("ProjectionGeometry2D"); + cfg->self->addAttribute("type", "fanflat"); + cfg->self->addChildNode("DetectorCount", getDetectorCount()); + cfg->self->addChildNode("DetectorWidth", getDetectorWidth()); + cfg->self->addChildNode("DistanceOriginSource", getOriginSourceDistance()); + cfg->self->addChildNode("DistanceOriginDetector", getOriginDetectorDistance()); + cfg->self->addChildNode("ProjectionAngles", m_pfProjectionAngles, m_iProjectionAngleCount); + return cfg; +} +//---------------------------------------------------------------------------------------- } // namespace astra diff --git a/src/FanFlatVecProjectionGeometry2D.cpp b/src/FanFlatVecProjectionGeometry2D.cpp index 77f9db7..9c7b596 100644 --- a/src/FanFlatVecProjectionGeometry2D.cpp +++ b/src/FanFlatVecProjectionGeometry2D.cpp @@ -194,7 +194,7 @@ bool CFanFlatVecProjectionGeometry2D::isEqual(CProjectionGeometry2D* _pGeom2) co // Is of type bool CFanFlatVecProjectionGeometry2D::isOfType(const std::string& _sType) { - return (_sType == "fanflat_vec"); + return (_sType == "fanflat_vec"); } //---------------------------------------------------------------------------------------- @@ -227,6 +227,28 @@ bool CFanFlatVecProjectionGeometry2D::_check() //---------------------------------------------------------------------------------------- +// Get the configuration object +Config* CFanFlatVecProjectionGeometry2D::getConfiguration() const +{ + Config* cfg = new Config(); + cfg->initialize("ProjectionGeometry2D"); + cfg->self->addAttribute("type", "fanflat_vec"); + cfg->self->addChildNode("DetectorCount", getDetectorCount()); + std::string vectors = ""; + for (int i = 0; i < m_iProjectionAngleCount; ++i) { + SFanProjection& p = m_pProjectionAngles[i]; + vectors += boost::lexical_cast<string>(p.fSrcX) + ","; + vectors += boost::lexical_cast<string>(p.fSrcY) + ","; + vectors += boost::lexical_cast<string>(p.fDetSX + 0.5f * m_iDetectorCount * p.fDetUX) + ","; + vectors += boost::lexical_cast<string>(p.fDetSY + 0.5f * m_iDetectorCount * p.fDetUY) + ","; + vectors += boost::lexical_cast<string>(p.fDetUX) + ","; + vectors += boost::lexical_cast<string>(p.fDetUY); + if (i < m_iProjectionAngleCount-1) vectors += ';'; + } + cfg->self->addChildNode("Vectors", vectors); + return cfg; +} +//---------------------------------------------------------------------------------------- } // namespace astra diff --git a/src/ParallelProjectionGeometry2D.cpp b/src/ParallelProjectionGeometry2D.cpp index 8f8faa4..cac8f30 100644 --- a/src/ParallelProjectionGeometry2D.cpp +++ b/src/ParallelProjectionGeometry2D.cpp @@ -27,6 +27,7 @@ $Id$ */ #include "astra/ParallelProjectionGeometry2D.h" +#include <boost/lexical_cast.hpp> #include <cstring> @@ -168,6 +169,19 @@ bool CParallelProjectionGeometry2D::isOfType(const std::string& _sType) { return (_sType == "parallel"); } + +//---------------------------------------------------------------------------------------- +// Get the configuration object +Config* CParallelProjectionGeometry2D::getConfiguration() const +{ + Config* cfg = new Config(); + cfg->initialize("ProjectionGeometry2D"); + cfg->self->addAttribute("type", "parallel"); + cfg->self->addChildNode("DetectorCount", getDetectorCount()); + cfg->self->addChildNode("DetectorWidth", getDetectorWidth()); + cfg->self->addChildNode("ProjectionAngles", m_pfProjectionAngles, m_iProjectionAngleCount); + return cfg; +} //---------------------------------------------------------------------------------------- CVector3D CParallelProjectionGeometry2D::getProjectionDirection(int _iProjectionIndex, int _iDetectorIndex /* = 0 */) diff --git a/src/ParallelProjectionGeometry3D.cpp b/src/ParallelProjectionGeometry3D.cpp index 7130d71..d47a4bb 100644 --- a/src/ParallelProjectionGeometry3D.cpp +++ b/src/ParallelProjectionGeometry3D.cpp @@ -27,6 +27,7 @@ $Id$ */ #include "astra/ParallelProjectionGeometry3D.h" +#include <boost/lexical_cast.hpp> #include <cstring> @@ -168,6 +169,22 @@ void CParallelProjectionGeometry3D::toXML(XMLNode* _sNode) const _sNode->addChildNode("ProjectionAngles", m_pfProjectionAngles, m_iProjectionAngleCount); } +//---------------------------------------------------------------------------------------- +// Get the configuration object +Config* CParallelProjectionGeometry3D::getConfiguration() const +{ + Config* cfg = new Config(); + cfg->initialize("ProjectionGeometry3D"); + cfg->self->addAttribute("type", "parallel3d"); + cfg->self->addChildNode("DetectorRowCount", m_iDetectorRowCount); + cfg->self->addChildNode("DetectorColCount", m_iDetectorColCount); + cfg->self->addChildNode("DetectorSpacingX", m_fDetectorSpacingX); + cfg->self->addChildNode("DetectorSpacingY", m_fDetectorSpacingY); + cfg->self->addChildNode("ProjectionAngles", m_pfProjectionAngles, m_iProjectionAngleCount); + return cfg; +} +//---------------------------------------------------------------------------------------- + CVector3D CParallelProjectionGeometry3D::getProjectionDirection(int _iProjectionIndex, int _iDetectorIndex) const { float fTheta = m_pfProjectionAngles[_iProjectionIndex]; diff --git a/src/ParallelVecProjectionGeometry3D.cpp b/src/ParallelVecProjectionGeometry3D.cpp index 17f00a4..0f39c4a 100644 --- a/src/ParallelVecProjectionGeometry3D.cpp +++ b/src/ParallelVecProjectionGeometry3D.cpp @@ -211,6 +211,40 @@ void CParallelVecProjectionGeometry3D::toXML(XMLNode* _sNode) const //_sNode->addChildNode("ProjectionAngles", m_pfProjectionAngles, m_iProjectionAngleCount); } +//---------------------------------------------------------------------------------------- +// Get the configuration object +Config* CParallelVecProjectionGeometry3D::getConfiguration() const +{ + Config* cfg = new Config(); + cfg->initialize("ProjectionGeometry3D"); + + cfg->self->addAttribute("type", "parallel3d"); + cfg->self->addChildNode("DetectorRowCount", m_iDetectorRowCount); + cfg->self->addChildNode("DetectorColCount", m_iDetectorColCount); + + std::string vectors = ""; + for (int i = 0; i < m_iProjectionAngleCount; ++i) { + SPar3DProjection& p = m_pProjectionAngles[i]; + vectors += boost::lexical_cast<string>(p.fRayX) + ","; + vectors += boost::lexical_cast<string>(p.fRayY) + ","; + vectors += boost::lexical_cast<string>(p.fRayZ) + ","; + vectors += boost::lexical_cast<string>(p.fDetSX + 0.5f*m_iDetectorRowCount*p.fDetUX + 0.5f*m_iDetectorColCount*p.fDetVX) + ","; + vectors += boost::lexical_cast<string>(p.fDetSY + 0.5f*m_iDetectorRowCount*p.fDetUY + 0.5f*m_iDetectorColCount*p.fDetVY) + ","; + vectors += boost::lexical_cast<string>(p.fDetSZ + 0.5f*m_iDetectorRowCount*p.fDetUZ + 0.5f*m_iDetectorColCount*p.fDetVZ) + ","; + vectors += boost::lexical_cast<string>(p.fDetUX) + ","; + vectors += boost::lexical_cast<string>(p.fDetUY) + ","; + vectors += boost::lexical_cast<string>(p.fDetUZ) + ","; + vectors += boost::lexical_cast<string>(p.fDetVX) + ","; + vectors += boost::lexical_cast<string>(p.fDetVY) + ","; + vectors += boost::lexical_cast<string>(p.fDetVZ); + if (i < m_iProjectionAngleCount-1) vectors += ';'; + } + cfg->self->addChildNode("Vectors", vectors); + + return cfg; +} +//---------------------------------------------------------------------------------------- + CVector3D CParallelVecProjectionGeometry3D::getProjectionDirection(int _iProjectionIndex, int _iDetectorIndex) const { const SPar3DProjection& p = m_pProjectionAngles[_iProjectionIndex]; diff --git a/src/SparseMatrixProjectionGeometry2D.cpp b/src/SparseMatrixProjectionGeometry2D.cpp index 7f14d9d..86357d2 100644 --- a/src/SparseMatrixProjectionGeometry2D.cpp +++ b/src/SparseMatrixProjectionGeometry2D.cpp @@ -189,7 +189,20 @@ bool CSparseMatrixProjectionGeometry2D::isOfType(const std::string& _sType) return (_sType == "sparse_matrix"); } //---------------------------------------------------------------------------------------- +// Get the configuration object +Config* CSparseMatrixProjectionGeometry2D::getConfiguration() const +{ + Config* cfg = new Config(); + cfg->initialize("ProjectionGeometry2D"); + cfg->self->addAttribute("type", "sparse matrix"); + cfg->self->addChildNode("DetectorCount", getDetectorCount()); + cfg->self->addChildNode("DetectorWidth", getDetectorWidth()); + cfg->self->addChildNode("ProjectionAngles", m_pfProjectionAngles, m_iProjectionAngleCount); + cfg->self->addChildNode("MatrixID", CMatrixManager::getSingleton().getIndex(m_pMatrix)); + return cfg; +} +//---------------------------------------------------------------------------------------- CVector3D CSparseMatrixProjectionGeometry2D::getProjectionDirection(int _iProjectionIndex, int _iDetectorIndex) { CVector3D vOutput(0.0f, 0.0f, 0.0f); diff --git a/src/XMLNode.cpp b/src/XMLNode.cpp index a5b6796..4b2bdf4 100644 --- a/src/XMLNode.cpp +++ b/src/XMLNode.cpp @@ -448,13 +448,11 @@ void XMLNode::setContent(float32 _fValue) // Set content - LIST void XMLNode::setContent(float32* pfList, int _iSize) { - addAttribute("listsize", _iSize); - for (int i = 0; i < _iSize; i++) { - XMLNode* item = addChildNode("ListItem"); - item->addAttribute("index", i); - item->addAttribute("value",pfList[i]); - delete item; + std::string str = (_iSize > 0) ? boost::lexical_cast<std::string>(pfList[0]) : ""; + for (int i = 1; i < _iSize; i++) { + str += "," + boost::lexical_cast<std::string>(pfList[i]); } + setContent(str); } //----------------------------------------------------------------------------- |