summaryrefslogtreecommitdiffstats
path: root/matlab/mex
diff options
context:
space:
mode:
Diffstat (limited to 'matlab/mex')
-rw-r--r--matlab/mex/astra_mex_algorithm_c.cpp2
-rw-r--r--matlab/mex/astra_mex_c.cpp4
-rw-r--r--matlab/mex/astra_mex_data2d_c.cpp4
-rw-r--r--matlab/mex/astra_mex_data3d_c.cpp2
-rw-r--r--matlab/mex/astra_mex_log_c.cpp8
-rw-r--r--matlab/mex/astra_mex_projector3d_c.cpp8
-rw-r--r--matlab/mex/astra_mex_projector_c.cpp9
-rw-r--r--matlab/mex/mexDataManagerHelpFunctions.cpp2
-rw-r--r--matlab/mex/mexHelpFunctions.cpp72
-rw-r--r--matlab/mex/mexHelpFunctions.h6
-rw-r--r--matlab/mex/mexInitFunctions.cpp2
11 files changed, 53 insertions, 66 deletions
diff --git a/matlab/mex/astra_mex_algorithm_c.cpp b/matlab/mex/astra_mex_algorithm_c.cpp
index e4afa63..ec7aa72 100644
--- a/matlab/mex/astra_mex_algorithm_c.cpp
+++ b/matlab/mex/astra_mex_algorithm_c.cpp
@@ -81,7 +81,7 @@ void astra_mex_algorithm_create(int nlhs, mxArray* plhs[], int nrhs, const mxArr
// turn MATLAB struct to an XML-based Config object
Config* cfg = structToConfig("Algorithm", prhs[1]);
- CAlgorithm* pAlg = CAlgorithmFactory::getSingleton().create(cfg->self->getAttribute("type"));
+ CAlgorithm* pAlg = CAlgorithmFactory::getSingleton().create(cfg->self.getAttribute("type"));
if (!pAlg) {
delete cfg;
mexErrMsgTxt("Unknown algorithm. \n");
diff --git a/matlab/mex/astra_mex_c.cpp b/matlab/mex/astra_mex_c.cpp
index 4a331f5..a9b9654 100644
--- a/matlab/mex/astra_mex_c.cpp
+++ b/matlab/mex/astra_mex_c.cpp
@@ -36,9 +36,9 @@ $Id$
#include "mexInitFunctions.h"
#include "astra/Globals.h"
-
+#ifdef ASTRA_CUDA
#include "../cuda/2d/darthelper.h"
-
+#endif
using namespace std;
using namespace astra;
diff --git a/matlab/mex/astra_mex_data2d_c.cpp b/matlab/mex/astra_mex_data2d_c.cpp
index 9576896..909d229 100644
--- a/matlab/mex/astra_mex_data2d_c.cpp
+++ b/matlab/mex/astra_mex_data2d_c.cpp
@@ -149,7 +149,7 @@ void astra_mex_data2d_create(int& nlhs, mxArray* plhs[], int& nrhs, const mxArra
Config* cfg = structToConfig("ProjectionGeometry", prhs[2]);
// FIXME: Change how the base class is created. (This is duplicated
// in 'change_geometry' and Projector2D.cpp.)
- std::string type = cfg->self->getAttribute("type");
+ std::string type = cfg->self.getAttribute("type");
CProjectionGeometry2D* pGeometry;
if (type == "sparse_matrix") {
pGeometry = new CSparseMatrixProjectionGeometry2D();
@@ -438,7 +438,7 @@ void astra_mex_data2d_change_geometry(int nlhs, mxArray* plhs[], int nrhs, const
Config* cfg = structToConfig("ProjectionGeometry2D", prhs[2]);
// FIXME: Change how the base class is created. (This is duplicated
// in 'create' and Projector2D.cpp.)
- std::string type = cfg->self->getAttribute("type");
+ std::string type = cfg->self.getAttribute("type");
CProjectionGeometry2D* pGeometry;
if (type == "sparse_matrix") {
pGeometry = new CSparseMatrixProjectionGeometry2D();
diff --git a/matlab/mex/astra_mex_data3d_c.cpp b/matlab/mex/astra_mex_data3d_c.cpp
index 6096adc..fe4ce37 100644
--- a/matlab/mex/astra_mex_data3d_c.cpp
+++ b/matlab/mex/astra_mex_data3d_c.cpp
@@ -346,7 +346,7 @@ void astra_mex_data3d_change_geometry(int nlhs, mxArray* plhs[], int nrhs, const
astra::Config* cfg = structToConfig("ProjectionGeometry3D", geometry);
// FIXME: Change how the base class is created. (This is duplicated
// in Projector3D.cpp.)
- std::string type = cfg->self->getAttribute("type");
+ std::string type = cfg->self.getAttribute("type");
astra::CProjectionGeometry3D* pGeometry = 0;
if (type == "parallel3d") {
pGeometry = new astra::CParallelProjectionGeometry3D();
diff --git a/matlab/mex/astra_mex_log_c.cpp b/matlab/mex/astra_mex_log_c.cpp
index ea4621e..905612c 100644
--- a/matlab/mex/astra_mex_log_c.cpp
+++ b/matlab/mex/astra_mex_log_c.cpp
@@ -55,7 +55,7 @@ void astra_mex_log_debug(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prh
string filename = mexToString(prhs[1]);
int linenumber = (int)mxGetScalar(prhs[2]);
string message = mexToString(prhs[3]);
- astra::CLogger::debug(filename.c_str(),linenumber,message.c_str());
+ astra::CLogger::debug(filename.c_str(),linenumber,"%s",message.c_str());
}
//-----------------------------------------------------------------------------------------
@@ -75,7 +75,7 @@ void astra_mex_log_info(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs
string filename = mexToString(prhs[1]);
int linenumber = (int)mxGetScalar(prhs[2]);
string message = mexToString(prhs[3]);
- astra::CLogger::info(filename.c_str(),linenumber,message.c_str());
+ astra::CLogger::info(filename.c_str(),linenumber,"%s",message.c_str());
}
//-----------------------------------------------------------------------------------------
@@ -95,7 +95,7 @@ void astra_mex_log_warn(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs
string filename = mexToString(prhs[1]);
int linenumber = (int)mxGetScalar(prhs[2]);
string message = mexToString(prhs[3]);
- astra::CLogger::warn(filename.c_str(),linenumber,message.c_str());
+ astra::CLogger::warn(filename.c_str(),linenumber,"%s",message.c_str());
}
//-----------------------------------------------------------------------------------------
@@ -115,7 +115,7 @@ void astra_mex_log_error(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prh
string filename = mexToString(prhs[1]);
int linenumber = (int)mxGetScalar(prhs[2]);
string message = mexToString(prhs[3]);
- astra::CLogger::error(filename.c_str(),linenumber,message.c_str());
+ astra::CLogger::error(filename.c_str(),linenumber,"%s",message.c_str());
}
//-----------------------------------------------------------------------------------------
diff --git a/matlab/mex/astra_mex_projector3d_c.cpp b/matlab/mex/astra_mex_projector3d_c.cpp
index c3b547f..e25802c 100644
--- a/matlab/mex/astra_mex_projector3d_c.cpp
+++ b/matlab/mex/astra_mex_projector3d_c.cpp
@@ -137,7 +137,9 @@ 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] = configToStruct(pProjector->getProjectionGeometry()->getConfiguration());
+ Config *cfg = pProjector->getProjectionGeometry()->getConfiguration();
+ plhs[0] = configToStruct(cfg);
+ delete cfg;
}
}
@@ -163,7 +165,9 @@ 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] = configToStruct(pProjector->getVolumeGeometry()->getConfiguration());
+ Config *cfg = pProjector->getVolumeGeometry()->getConfiguration();
+ plhs[0] = configToStruct(cfg);
+ delete cfg;
}
}
diff --git a/matlab/mex/astra_mex_projector_c.cpp b/matlab/mex/astra_mex_projector_c.cpp
index 204ba8e..bf701af 100644
--- a/matlab/mex/astra_mex_projector_c.cpp
+++ b/matlab/mex/astra_mex_projector_c.cpp
@@ -160,7 +160,9 @@ 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] = configToStruct(pProjector->getProjectionGeometry()->getConfiguration());
+ Config *cfg = pProjector->getProjectionGeometry()->getConfiguration();
+ plhs[0] = configToStruct(cfg);
+ delete cfg;
}
}
@@ -189,8 +191,9 @@ 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] = configToStruct(pProjector->getVolumeGeometry()->getConfiguration());
-
+ Config *cfg = pProjector->getVolumeGeometry()->getConfiguration();
+ plhs[0] = configToStruct(cfg);
+ delete cfg;
}
}
diff --git a/matlab/mex/mexDataManagerHelpFunctions.cpp b/matlab/mex/mexDataManagerHelpFunctions.cpp
index d482428..1794abb 100644
--- a/matlab/mex/mexDataManagerHelpFunctions.cpp
+++ b/matlab/mex/mexDataManagerHelpFunctions.cpp
@@ -285,7 +285,7 @@ allocateDataObject(const std::string & sDataType,
astra::Config* cfg = structToConfig("ProjectionGeometry3D", geometry);
// FIXME: Change how the base class is created. (This is duplicated
// in Projector3D.cpp.)
- std::string type = cfg->self->getAttribute("type");
+ std::string type = cfg->self.getAttribute("type");
astra::CProjectionGeometry3D* pGeometry = 0;
if (type == "parallel3d") {
pGeometry = new astra::CParallelProjectionGeometry3D();
diff --git a/matlab/mex/mexHelpFunctions.cpp b/matlab/mex/mexHelpFunctions.cpp
index c0ac711..58e84d2 100644
--- a/matlab/mex/mexHelpFunctions.cpp
+++ b/matlab/mex/mexHelpFunctions.cpp
@@ -185,7 +185,7 @@ Config* structToConfig(string rootname, const mxArray* pStruct)
}
//-----------------------------------------------------------------------------------------
-bool structToXMLNode(XMLNode* node, const mxArray* pStruct)
+bool structToXMLNode(XMLNode node, const mxArray* pStruct)
{
// loop all fields
int nfields = mxGetNumberOfFields(pStruct);
@@ -199,16 +199,16 @@ bool structToXMLNode(XMLNode* node, const mxArray* pStruct)
if (mxIsChar(pField)) {
string sValue = mexToString(pField);
if (sFieldName == "type") {
- node->addAttribute("type", sValue);
+ node.addAttribute("type", sValue);
} else {
- delete node->addChildNode(sFieldName, sValue);
+ node.addChildNode(sFieldName, sValue);
}
}
// scalar
else if (mxIsNumeric(pField) && mxGetM(pField)*mxGetN(pField) == 1) {
string sValue = mexToString(pField);
- delete node->addChildNode(sFieldName, sValue);
+ node.addChildNode(sFieldName, sValue);
}
// numerical array
@@ -217,20 +217,9 @@ bool structToXMLNode(XMLNode* node, const mxArray* pStruct)
mexErrMsgTxt("Numeric input must be double.");
return false;
}
- XMLNode* listbase = node->addChildNode(sFieldName);
- listbase->addAttribute("listsize", mxGetM(pField)*mxGetN(pField));
+ XMLNode listbase = node.addChildNode(sFieldName);
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;
+ listbase.setContent(pdValues, mxGetN(pField), mxGetM(pField), true);
}
// not castable to a single string
@@ -240,9 +229,8 @@ bool structToXMLNode(XMLNode* node, const mxArray* pStruct)
if (!ret)
return false;
} else {
- XMLNode* newNode = node->addChildNode(sFieldName);
+ XMLNode newNode = node.addChildNode(sFieldName);
bool ret = structToXMLNode(newNode, pField);
- delete newNode;
if (!ret)
return false;
}
@@ -254,7 +242,7 @@ bool structToXMLNode(XMLNode* node, const mxArray* pStruct)
}
//-----------------------------------------------------------------------------------------
// Options struct to xml node
-bool optionsToXMLNode(XMLNode* node, const mxArray* pOptionStruct)
+bool optionsToXMLNode(XMLNode node, const mxArray* pOptionStruct)
{
// loop all fields
int nfields = mxGetNumberOfFields(pOptionStruct);
@@ -262,7 +250,7 @@ bool optionsToXMLNode(XMLNode* node, const mxArray* pOptionStruct)
std::string sFieldName = std::string(mxGetFieldNameByNumber(pOptionStruct, i));
const mxArray* pField = mxGetFieldByNumber(pOptionStruct, 0, i);
- if (node->hasOption(sFieldName)) {
+ if (node.hasOption(sFieldName)) {
mexErrMsgTxt("Duplicate option");
return false;
}
@@ -270,7 +258,7 @@ bool optionsToXMLNode(XMLNode* node, const mxArray* pOptionStruct)
// string or scalar
if (mxIsChar(pField) || mexIsScalar(pField)) {
string sValue = mexToString(pField);
- node->addOption(sFieldName, sValue);
+ node.addOption(sFieldName, sValue);
}
// numerical array
else if (mxIsNumeric(pField) && mxGetM(pField)*mxGetN(pField) > 1) {
@@ -279,21 +267,10 @@ bool optionsToXMLNode(XMLNode* node, const mxArray* pOptionStruct)
return false;
}
- XMLNode* listbase = node->addChildNode("Option");
- listbase->addAttribute("key", sFieldName);
- listbase->addAttribute("listsize", mxGetM(pField)*mxGetN(pField));
+ XMLNode listbase = node.addChildNode("Option");
+ listbase.addAttribute("key", sFieldName);
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;
+ listbase.setContent(pdValues, mxGetN(pField), mxGetM(pField), true);
} else {
mexErrMsgTxt("Unsupported option type");
return false;
@@ -343,30 +320,33 @@ mxArray* configToStruct(astra::Config* cfg)
}
//-----------------------------------------------------------------------------------------
-mxArray* XMLNodeToStruct(astra::XMLNode* node)
+mxArray* XMLNodeToStruct(astra::XMLNode node)
{
std::map<std::string, mxArray*> mList;
std::map<std::string, mxArray*> mOptions;
// type_attribute
- if (node->hasAttribute("type")) {
- mList["type"] = mxCreateString(node->getAttribute("type").c_str());
+ if (node.hasAttribute("type")) {
+ mList["type"] = mxCreateString(node.getAttribute("type").c_str());
}
- list<XMLNode*> nodes = node->getNodes();
- for (list<XMLNode*>::iterator it = nodes.begin(); it != nodes.end(); it++) {
- XMLNode* subnode = (*it);
+ list<XMLNode> nodes = node.getNodes();
+ for (list<XMLNode>::iterator it = nodes.begin(); it != nodes.end(); it++) {
+ XMLNode subnode = (*it);
// option
- if (subnode->getName() == "Option") {
- mOptions[subnode->getAttribute("key")] = stringToMxArray(subnode->getAttribute("value"));
+ if (subnode.getName() == "Option") {
+ if(subnode.hasAttribute("value")){
+ mOptions[subnode.getAttribute("key")] = stringToMxArray(subnode.getAttribute("value"));
+ }else{
+ mOptions[subnode.getAttribute("key")] = stringToMxArray(subnode.getContent());
+ }
}
// regular content
else {
- mList[subnode->getName()] = stringToMxArray(subnode->getContent());
+ mList[subnode.getName()] = stringToMxArray(subnode.getContent());
}
- delete subnode;
}
if (mOptions.size() > 0) mList["options"] = buildStruct(mOptions);
diff --git a/matlab/mex/mexHelpFunctions.h b/matlab/mex/mexHelpFunctions.h
index f9ffcf2..3ac5bd8 100644
--- a/matlab/mex/mexHelpFunctions.h
+++ b/matlab/mex/mexHelpFunctions.h
@@ -58,13 +58,13 @@ mxArray* anyToMxArray(boost::any _any);
// turn a MATLAB struct into a Config object
astra::Config* structToConfig(string rootname, const mxArray* pStruct);
-bool structToXMLNode(astra::XMLNode* node, const mxArray* pStruct);
-bool optionsToXMLNode(astra::XMLNode* node, const mxArray* pOptionStruct);
+bool structToXMLNode(astra::XMLNode node, const mxArray* pStruct);
+bool optionsToXMLNode(astra::XMLNode node, const mxArray* pOptionStruct);
std::map<std::string, mxArray*> parseStruct(const mxArray* pInput);
// turn a Config object into a MATLAB struct
mxArray* configToStruct(astra::Config* cfg);
-mxArray* XMLNodeToStruct(astra::XMLNode* xml);
+mxArray* XMLNodeToStruct(astra::XMLNode xml);
mxArray* stringToMxArray(std::string input);
mxArray* buildStruct(std::map<std::string, mxArray*> mInput);
diff --git a/matlab/mex/mexInitFunctions.cpp b/matlab/mex/mexInitFunctions.cpp
index d8a50d7..89a31a1 100644
--- a/matlab/mex/mexInitFunctions.cpp
+++ b/matlab/mex/mexInitFunctions.cpp
@@ -8,7 +8,7 @@ bool mexIsInitialized=false;
*
*/
void logCallBack(const char *msg, size_t len){
- mexPrintf(msg);
+ mexPrintf("%s",msg);
}
/**