From 9e48494ecc1e4655bd6c25b34bb5c53c80c30d7a Mon Sep 17 00:00:00 2001
From: Wim van Aarle <wimvanaarle@gmail.com>
Date: Tue, 24 Feb 2015 15:17:38 +0100
Subject: fixed get_geometry for fanflat_vec

---
 matlab/mex/astra_mex_data2d_c.cpp |  4 +--
 matlab/mex/mexHelpFunctions.cpp   | 72 +++++++++++++++++++++------------------
 test_geometry.m                   | 18 ++++++++++
 3 files changed, 59 insertions(+), 35 deletions(-)

diff --git a/matlab/mex/astra_mex_data2d_c.cpp b/matlab/mex/astra_mex_data2d_c.cpp
index b219179..bd70e1b 100644
--- a/matlab/mex/astra_mex_data2d_c.cpp
+++ b/matlab/mex/astra_mex_data2d_c.cpp
@@ -373,7 +373,7 @@ void astra_mex_data2d_store(int nlhs, mxArray* plhs[], int nrhs, const mxArray*
  */
 void astra_mex_data2d_get_geometry(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[])
 { 
-	// step1: input
+	// parse input
 	if (nrhs < 2) {
 		mexErrMsgTxt("Not enough arguments.  See the help document for a detailed argument list. \n");
 		return;
@@ -384,7 +384,7 @@ void astra_mex_data2d_get_geometry(int nlhs, mxArray* plhs[], int nrhs, const mx
 	}
 	int iDataID = (int)(mxGetScalar(prhs[1]));
 
-	// step2: get data object
+	// fetch data object
 	CFloat32Data2D* pDataObject = astra::CData2DManager::getSingleton().get(iDataID);
 	if (!pDataObject || !pDataObject->isInitialized()) {
 		mexErrMsgTxt("Data object not found or not initialized properly.\n");
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<std::string, mxArray*> 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<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);
-		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<astra::CFanFlatProjectionGeometry2D*>(_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<astra::CSparseMatrixProjectionGeometry2D*>(_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);
diff --git a/test_geometry.m b/test_geometry.m
index d8facc3..f846d52 100644
--- a/test_geometry.m
+++ b/test_geometry.m
@@ -11,14 +11,32 @@ S = I > 0.5;
 vol_geom2d = astra_create_vol_geom(d,d);
 vol_geom3d = astra_create_vol_geom(d,d,d);
 
+proj_geom_parallel = astra_create_proj_geom('parallel', 1, 64, 1:180);
+proj_geom_fanflat = astra_create_proj_geom('fanflat', 1, 64, 1:180, 0, 2000);
+proj_geom_fanflat_vec = astra_geom_2vec(proj_geom_fanflat);
 
 %% create data objects
 vol2d_id = astra_mex_data2d('create', '-vol', vol_geom2d, 0);
 vol3d_id = astra_mex_data3d('create', '-vol', vol_geom3d, 0);
 
+proj_parallel_id = astra_mex_data2d('create', '-sino', proj_geom_parallel, 0);
+proj_fanflat_id = astra_mex_data2d('create', '-sino', proj_geom_fanflat, 0);
+proj_fanflatvec_id = astra_mex_data2d('create', '-sino', proj_geom_fanflat_vec, 0);
+
+
 %% get geometries
 vol_geom2d_new = astra_mex_data2d('get_geometry', vol2d_id);
 vol_geom3d_new = astra_mex_data3d('get_geometry', vol3d_id);
 
+proj_geom_parallel_new = astra_mex_data2d('get_geometry', proj_parallel_id);
+proj_geom_fanflat_new = astra_mex_data2d('get_geometry', proj_fanflat_id);
+proj_geom_fanflat_vec_new = astra_mex_data2d('get_geometry', proj_fanflatvec_id);
+
+proj_geom_fanflat_vec
+proj_geom_fanflat_vec_new
+
+proj_geom_fanflat_vec.Vectors(110,:)
+proj_geom_fanflat_vec_new.Vectors(110,:)
 
+%%
 astra_clear;
\ No newline at end of file
-- 
cgit v1.2.3