From 065d9c6a18f2b8eececc608ce850a9a308ca6356 Mon Sep 17 00:00:00 2001
From: Wim van Aarle <wimvanaarle@gmail.com>
Date: Wed, 25 Feb 2015 16:46:09 +0100
Subject: get_geometry now uses XML config object (for volumes)

---
 matlab/mex/astra_mex_data2d_c.cpp |   4 +-
 matlab/mex/astra_mex_data3d_c.cpp |   2 +-
 matlab/mex/mexHelpFunctions.cpp   | 107 ++++++++++++++++++++++++++------------
 matlab/mex/mexHelpFunctions.h     |   5 +-
 4 files changed, 80 insertions(+), 38 deletions(-)

(limited to 'matlab/mex')

diff --git a/matlab/mex/astra_mex_data2d_c.cpp b/matlab/mex/astra_mex_data2d_c.cpp
index bd70e1b..d07a13a 100644
--- a/matlab/mex/astra_mex_data2d_c.cpp
+++ b/matlab/mex/astra_mex_data2d_c.cpp
@@ -399,7 +399,9 @@ void astra_mex_data2d_get_geometry(int nlhs, mxArray* plhs[], int nrhs, const mx
 		}
 		else if (pDataObject->getType() == CFloat32Data2D::VOLUME) {
 			CFloat32VolumeData2D* pDataObject2 = dynamic_cast<CFloat32VolumeData2D*>(pDataObject);
-			plhs[0] = createVolumeGeometryStruct(pDataObject2->getGeometry());
+			plhs[0] = config2struct(pDataObject2->getGeometry()->getConfiguration());
+			// mexErrMsgTxt(pDataObject2->getGeometry()->getConfiguration()->self->toString().c_str());
+			// plhs[0] = createVolumeGeometryStruct(pDataObject2->getGeometry());
 		}
 	}
 }
diff --git a/matlab/mex/astra_mex_data3d_c.cpp b/matlab/mex/astra_mex_data3d_c.cpp
index 84bc0a4..5abdf50 100644
--- a/matlab/mex/astra_mex_data3d_c.cpp
+++ b/matlab/mex/astra_mex_data3d_c.cpp
@@ -300,7 +300,7 @@ void astra_mex_data3d_get_geometry(int nlhs, mxArray* plhs[], int nrhs, const mx
 		}
 		else if (pDataObject->getType() == CFloat32Data3D::VOLUME) {
 			CFloat32VolumeData3DMemory* pDataObject2 = dynamic_cast<CFloat32VolumeData3DMemory*>(pDataObject);
-			plhs[0] = createVolumeGeometryStruct(pDataObject2->getGeometry());
+			plhs[0] = config2struct(pDataObject2->getGeometry()->getConfiguration());
 		}
 	}
 
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<std::string, mxArray*> mGeometryInfo;
+// mxArray* createVolumeGeometryStruct(astra::CVolumeGeometry2D* _pVolGeom)
+// {
+// 	std::map<std::string, mxArray*> mGeometryInfo;
 
-	mGeometryInfo["GridColCount"] = mxCreateDoubleScalar(_pVolGeom->getGridColCount());
-	mGeometryInfo["GridRowCount"] = mxCreateDoubleScalar(_pVolGeom->getGridRowCount());
+// 	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());
+// 	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);
+// 	mGeometryInfo["option"] = buildStruct(mGeometryOptions);
 
-	return buildStruct(mGeometryInfo);
-}
+// 	return buildStruct(mGeometryInfo);
+// }
 
 //-----------------------------------------------------------------------------------------
 // create 3D volume geometry struct
-mxArray* createVolumeGeometryStruct(astra::CVolumeGeometry3D* _pVolGeom)
-{
-	std::map<std::string, mxArray*> mGeometryInfo;
+// 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());
+// 	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());
+// 	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);
+// 	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<std::string, mxArray*> mList; 
+	std::map<std::string, mxArray*> mList;
+	std::map<std::string, mxArray*> mOptions;
 
 	// type_attribute
 	if (node->hasAttribute("type")) {
@@ -736,11 +759,22 @@ mxArray* XMLNode2struct(astra::XMLNode* node)
 	list<XMLNode*> nodes = node->getNodes();
 	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
-		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);
diff --git a/matlab/mex/mexHelpFunctions.h b/matlab/mex/mexHelpFunctions.h
index 8b65a04..f8a7d48 100644
--- a/matlab/mex/mexHelpFunctions.h
+++ b/matlab/mex/mexHelpFunctions.h
@@ -74,11 +74,12 @@ astra::CVolumeGeometry2D* parseVolumeGeometryStruct(const mxArray*);
 mxArray* createProjectionGeometryStruct(astra::CProjectionGeometry2D*);
 mxArray* createProjectionGeometryStruct(astra::CProjectionGeometry3D*);
 
-mxArray* createVolumeGeometryStruct(astra::CVolumeGeometry2D* _pReconGeom);
-mxArray* createVolumeGeometryStruct(astra::CVolumeGeometry3D* _pReconGeom);
+// mxArray* createVolumeGeometryStruct(astra::CVolumeGeometry2D* _pReconGeom);
+// mxArray* createVolumeGeometryStruct(astra::CVolumeGeometry3D* _pReconGeom);
 
 astra::XMLDocument* struct2XML(string rootname, const mxArray* pStruct);
 
+mxArray* config2struct(astra::Config* cfg);
 mxArray* XML2struct(astra::XMLDocument* xml);
 mxArray* XMLNode2struct(astra::XMLNode* xml);
 
-- 
cgit v1.2.3