summaryrefslogtreecommitdiffstats
path: root/matlab
diff options
context:
space:
mode:
authorDaniel M. Pelt <D.M.Pelt@cwi.nl>2015-03-13 17:12:42 +0100
committerDaniel M. Pelt <D.M.Pelt@cwi.nl>2015-03-13 17:12:42 +0100
commitf21700e00e81538d5510973a51b8ae97fb4a24dd (patch)
treed1dcd07f2a29243e279fe2915c5db7814e99ea13 /matlab
parente4614cf09b90cc9a0e38d370bb090a11f3877b33 (diff)
downloadastra-f21700e00e81538d5510973a51b8ae97fb4a24dd.tar.gz
astra-f21700e00e81538d5510973a51b8ae97fb4a24dd.tar.bz2
astra-f21700e00e81538d5510973a51b8ae97fb4a24dd.tar.xz
astra-f21700e00e81538d5510973a51b8ae97fb4a24dd.zip
Enable logging to Matlab window using callback function
Also introduces a mex initialize function that is called at the first invocation of any mex method.
Diffstat (limited to 'matlab')
-rw-r--r--matlab/mex/astra_mex.cpp3
-rw-r--r--matlab/mex/astra_mex_algorithm_c.cpp3
-rw-r--r--matlab/mex/astra_mex_c.cpp3
-rw-r--r--matlab/mex/astra_mex_data2d_c.cpp3
-rw-r--r--matlab/mex/astra_mex_data3d_c.cpp3
-rw-r--r--matlab/mex/astra_mex_log_c.cpp3
-rw-r--r--matlab/mex/astra_mex_matrix_c.cpp3
-rw-r--r--matlab/mex/astra_mex_projector3d_c.cpp3
-rw-r--r--matlab/mex/astra_mex_projector_c.cpp3
-rw-r--r--matlab/mex/mexInitFunctions.cpp24
-rw-r--r--matlab/mex/mexInitFunctions.h6
11 files changed, 57 insertions, 0 deletions
diff --git a/matlab/mex/astra_mex.cpp b/matlab/mex/astra_mex.cpp
index 0eb5662..4bf42dd 100644
--- a/matlab/mex/astra_mex.cpp
+++ b/matlab/mex/astra_mex.cpp
@@ -28,6 +28,7 @@ $Id$
#include <mex.h>
#include "mexHelpFunctions.h"
+#include "mexInitFunctions.h"
#include "astra/Globals.h"
@@ -104,6 +105,8 @@ void mexFunction(int nlhs, mxArray* plhs[],
return;
}
+ initASTRAMex();
+
// SWITCH (MODE)
if (sMode == std::string("version")) {
astra_mex_version(nlhs, plhs, nrhs, prhs);
diff --git a/matlab/mex/astra_mex_algorithm_c.cpp b/matlab/mex/astra_mex_algorithm_c.cpp
index 669af8c..e4afa63 100644
--- a/matlab/mex/astra_mex_algorithm_c.cpp
+++ b/matlab/mex/astra_mex_algorithm_c.cpp
@@ -32,6 +32,7 @@ $Id$
*/
#include <mex.h>
#include "mexHelpFunctions.h"
+#include "mexInitFunctions.h"
#include "astra/Globals.h"
#define USE_MATLAB_UNDOCUMENTED
@@ -325,6 +326,8 @@ void mexFunction(int nlhs, mxArray* plhs[],
return;
}
+ initASTRAMex();
+
// SWITCH (MODE)
if (sMode == "create") {
astra_mex_algorithm_create(nlhs, plhs, nrhs, prhs);
diff --git a/matlab/mex/astra_mex_c.cpp b/matlab/mex/astra_mex_c.cpp
index 760bd51..4a331f5 100644
--- a/matlab/mex/astra_mex_c.cpp
+++ b/matlab/mex/astra_mex_c.cpp
@@ -33,6 +33,7 @@ $Id$
#include <mex.h>
#include "mexHelpFunctions.h"
+#include "mexInitFunctions.h"
#include "astra/Globals.h"
@@ -128,6 +129,8 @@ void mexFunction(int nlhs, mxArray* plhs[],
return;
}
+ initASTRAMex();
+
// SWITCH (MODE)
if (sMode == std::string("version")) {
astra_mex_version(nlhs, plhs, nrhs, prhs);
diff --git a/matlab/mex/astra_mex_data2d_c.cpp b/matlab/mex/astra_mex_data2d_c.cpp
index 5f79e98..9576896 100644
--- a/matlab/mex/astra_mex_data2d_c.cpp
+++ b/matlab/mex/astra_mex_data2d_c.cpp
@@ -32,6 +32,7 @@ $Id$
*/
#include <mex.h>
#include "mexHelpFunctions.h"
+#include "mexInitFunctions.h"
#include <list>
@@ -635,6 +636,8 @@ void mexFunction(int nlhs, mxArray* plhs[],
return;
}
+ initASTRAMex();
+
// SWITCH (MODE)
if (sMode == std::string("get")) {
astra_mex_data2d_get(nlhs, plhs, nrhs, prhs);
diff --git a/matlab/mex/astra_mex_data3d_c.cpp b/matlab/mex/astra_mex_data3d_c.cpp
index 0a3f85d..32b0ba7 100644
--- a/matlab/mex/astra_mex_data3d_c.cpp
+++ b/matlab/mex/astra_mex_data3d_c.cpp
@@ -32,6 +32,7 @@ $Id$
*/
#include <mex.h>
#include "mexHelpFunctions.h"
+#include "mexInitFunctions.h"
#include "mexCopyDataHelpFunctions.h"
#include "mexDataManagerHelpFunctions.h"
@@ -371,6 +372,8 @@ void mexFunction(int nlhs, mxArray* plhs[],
return;
}
+ initASTRAMex();
+
// 3D data
if (sMode == std::string("create")) {
astra_mex_data3d_create(nlhs, plhs, nrhs, prhs);
diff --git a/matlab/mex/astra_mex_log_c.cpp b/matlab/mex/astra_mex_log_c.cpp
index 14ae391..79fe3d5 100644
--- a/matlab/mex/astra_mex_log_c.cpp
+++ b/matlab/mex/astra_mex_log_c.cpp
@@ -32,6 +32,7 @@ $Id$
*/
#include <mex.h>
#include "mexHelpFunctions.h"
+#include "mexInitFunctions.h"
#include "astra/Logging.h"
@@ -278,6 +279,8 @@ void mexFunction(int nlhs, mxArray* plhs[],
return;
}
+ initASTRAMex();
+
// SWITCH (MODE)
if (sMode == "debug") {
astra_mex_log_debug(nlhs, plhs, nrhs, prhs);
diff --git a/matlab/mex/astra_mex_matrix_c.cpp b/matlab/mex/astra_mex_matrix_c.cpp
index 01ad08b..aa31383 100644
--- a/matlab/mex/astra_mex_matrix_c.cpp
+++ b/matlab/mex/astra_mex_matrix_c.cpp
@@ -32,6 +32,7 @@ $Id$
*/
#include <mex.h>
#include "mexHelpFunctions.h"
+#include "mexInitFunctions.h"
#include <list>
@@ -412,6 +413,8 @@ void mexFunction(int nlhs, mxArray* plhs[],
return;
}
+ initASTRAMex();
+
// SWITCH (MODE)
if (sMode == std::string("get")) {
astra_mex_matrix_get(nlhs, plhs, nrhs, prhs);
diff --git a/matlab/mex/astra_mex_projector3d_c.cpp b/matlab/mex/astra_mex_projector3d_c.cpp
index 5381cf6..c3b547f 100644
--- a/matlab/mex/astra_mex_projector3d_c.cpp
+++ b/matlab/mex/astra_mex_projector3d_c.cpp
@@ -33,6 +33,7 @@ $Id$
#include <mex.h>
#include "mexHelpFunctions.h"
+#include "mexInitFunctions.h"
#include "astra/Globals.h"
@@ -403,6 +404,8 @@ void mexFunction(int nlhs, mxArray* plhs[],
return;
}
+ initASTRAMex();
+
// SWITCH (MODE)
if (sMode == "create") {
astra_mex_projector3d_create(nlhs, plhs, nrhs, prhs);
diff --git a/matlab/mex/astra_mex_projector_c.cpp b/matlab/mex/astra_mex_projector_c.cpp
index 58cd953..204ba8e 100644
--- a/matlab/mex/astra_mex_projector_c.cpp
+++ b/matlab/mex/astra_mex_projector_c.cpp
@@ -34,6 +34,7 @@ $Id$
#include <mex.h>
#include "mexHelpFunctions.h"
+#include "mexInitFunctions.h"
#include "astra/AstraObjectManager.h"
#include "astra/Projector2D.h"
@@ -476,6 +477,8 @@ void mexFunction(int nlhs, mxArray* plhs[],
return;
}
+ initASTRAMex();
+
// SWITCH (MODE)
if (sMode == "create") {
astra_mex_projector_create(nlhs, plhs, nrhs, prhs);
diff --git a/matlab/mex/mexInitFunctions.cpp b/matlab/mex/mexInitFunctions.cpp
new file mode 100644
index 0000000..d8a50d7
--- /dev/null
+++ b/matlab/mex/mexInitFunctions.cpp
@@ -0,0 +1,24 @@
+#include <mex.h>
+#include "astra/Logging.h"
+
+bool mexIsInitialized=false;
+
+/**
+ * Callback to print log message to Matlab window.
+ *
+ */
+void logCallBack(const char *msg, size_t len){
+ mexPrintf(msg);
+}
+
+/**
+ * Initialize mex functions.
+ *
+ */
+void initASTRAMex(){
+ if(mexIsInitialized) return;
+ if(!astra::CLogger::setCallbackScreen(&logCallBack)){
+ mexErrMsgTxt("Error initializing mex functions.");
+ }
+ mexIsInitialized=true;
+}
diff --git a/matlab/mex/mexInitFunctions.h b/matlab/mex/mexInitFunctions.h
new file mode 100644
index 0000000..f16e9c9
--- /dev/null
+++ b/matlab/mex/mexInitFunctions.h
@@ -0,0 +1,6 @@
+#ifndef _INC_ASTRA_MEX_INITFUNCTIONS
+#define _INC_ASTRA_MEX_INITFUNCTIONS
+
+void initASTRAMex();
+
+#endif \ No newline at end of file