From 6346ecd767fd606df197a567d6594cff06e419b3 Mon Sep 17 00:00:00 2001 From: Qianqian Fang Date: Sun, 10 Nov 2024 22:25:42 -0500 Subject: [PATCH] [bug] fix mmclab compilation error --- examples/meshtest/mesh0.inp | 2 +- examples/meshtest/mesh0.json | 2 +- examples/meshtest/mesh1.inp | 2 +- examples/meshtest/mesh1.json | 2 +- examples/meshtest/mesh2.inp | 2 +- examples/meshtest/mesh2.json | 2 +- examples/meshtest/run_test.sh | 6 +++--- matlab/savemmcmesh.m | 6 +++++- src/mmc_utils.c | 6 ++++-- src/mmclab.cpp | 4 +++- 10 files changed, 21 insertions(+), 13 deletions(-) diff --git a/examples/meshtest/mesh0.inp b/examples/meshtest/mesh0.inp index 187bbc0a..3ae1d2c0 100644 --- a/examples/meshtest/mesh0.inp +++ b/examples/meshtest/mesh0.inp @@ -4,7 +4,7 @@ 0. 0. 1. # initial directional vector 0.e+00 5.e-09 1e-10 # time-gates(s): start, end, step mesh0 # volume ('uchar' format) -8 # index of elem that encloses the source +3 # index of elem that encloses the source 4 1 # detector number and radius (mm) 30.0 20.0 0.0 # detector 1 position (mm) 30.0 40.0 0.0 # ... diff --git a/examples/meshtest/mesh0.json b/examples/meshtest/mesh0.json index 4bc4fa15..97a006ad 100644 --- a/examples/meshtest/mesh0.json +++ b/examples/meshtest/mesh0.json @@ -1,7 +1,7 @@ { "Mesh": { "MeshID": "mesh0", - "InitElem": 8 + "InitElem": 3 }, "Session": { "Photons": 1000000, diff --git a/examples/meshtest/mesh1.inp b/examples/meshtest/mesh1.inp index 5708140f..1a03ff6d 100644 --- a/examples/meshtest/mesh1.inp +++ b/examples/meshtest/mesh1.inp @@ -4,7 +4,7 @@ 0. 0. 1. # initial directional vector 0.e+00 5.e-09 1.e-10 # time-gates(s): start, end, step mesh1 # volume ('uchar' format) -3 # index of elem that encloses the source +5 # index of elem that encloses the source 4 1 # detector number and radius (mm) 30.0 20.0 0.0 # detector 1 position (mm) 30.0 40.0 0.0 # ... diff --git a/examples/meshtest/mesh1.json b/examples/meshtest/mesh1.json index ce02e1ae..508d6feb 100644 --- a/examples/meshtest/mesh1.json +++ b/examples/meshtest/mesh1.json @@ -1,7 +1,7 @@ { "Mesh": { "MeshID": "mesh1", - "InitElem": 3 + "InitElem": 5 }, "Session": { "Photons": 1000000, diff --git a/examples/meshtest/mesh2.inp b/examples/meshtest/mesh2.inp index f94079d7..553920be 100644 --- a/examples/meshtest/mesh2.inp +++ b/examples/meshtest/mesh2.inp @@ -4,7 +4,7 @@ 0. 0. 1. # initial directional vector 0.e+00 5.e-09 1.e-10 # time-gates(s): start, end, step mesh2 # volume ('uchar' format) -8 # index of elem that encloses the source +7 # index of elem that encloses the source 4 1 # detector number and radius (mm) 30.0 20.0 0.0 # detector 1 position (mm) 30.0 40.0 0.0 # ... diff --git a/examples/meshtest/mesh2.json b/examples/meshtest/mesh2.json index 95039e4c..6188e2d5 100644 --- a/examples/meshtest/mesh2.json +++ b/examples/meshtest/mesh2.json @@ -1,7 +1,7 @@ { "Mesh": { "MeshID": "mesh2", - "InitElem": 8 + "InitElem": 7 }, "Session": { "Photons": 1000000, diff --git a/examples/meshtest/run_test.sh b/examples/meshtest/run_test.sh index c45a512a..3d7762d1 100755 --- a/examples/meshtest/run_test.sh +++ b/examples/meshtest/run_test.sh @@ -1,6 +1,6 @@ #!/bin/sh -time ../../bin/mmc -f mesh0.inp -s mesh0 -n 30000000 -b 0 -l -D TP -time ../../bin/mmc -f mesh1.inp -s mesh1 -n 30000000 -b 0 -l -D TP -time ../../bin/mmc -f mesh2.inp -s mesh2 -n 30000000 -b 0 -l -D TP +time ../../bin/mmc -f mesh0.inp -s mesh0 -n 30000000 -b 0 -D TP $@ +time ../../bin/mmc -f mesh1.inp -s mesh1 -n 30000000 -b 0 -D TP $@ +time ../../bin/mmc -f mesh2.inp -s mesh2 -n 30000000 -b 0 -D TP $@ diff --git a/matlab/savemmcmesh.m b/matlab/savemmcmesh.m index c0757a1f..818451b8 100644 --- a/matlab/savemmcmesh.m +++ b/matlab/savemmcmesh.m @@ -27,7 +27,11 @@ function savemmcmesh(key, node, elem, varargin) % License: GPLv3, see http://mcx.sf.net/mmc/ for details % -opt = varargin2struct(varargin{:}); +if(~isempty(varargin) && ischar(varargin{1})) + opt = varargin2struct(varargin{:}); +else + opt = struct; +end if (nargin < 5 || isempty(jsonopt('evol', [], opt))) evol = elemvolume(node, elem(:, 1:4)); diff --git a/src/mmc_utils.c b/src/mmc_utils.c index 58a69dd0..66128886 100644 --- a/src/mmc_utils.c +++ b/src/mmc_utils.c @@ -2241,9 +2241,9 @@ void mcx_savejdata(char* filename, mcconfig* cfg) { /* save "Shapes" constructs, containing InitElem, MeshNode, MeshElem, and MeshROI */ cJSON_AddItemToObject(root, "Shapes", obj = cJSON_CreateObject()); - if (cfg->meshtag[0]) { + if (cfg->meshtag[0] && cfg->nodenum == 0) { cJSON_AddStringToObject(obj, "MeshID", cfg->meshtag); - } else { + } else if (cfg->nodenum && cfg->elemnum) { uint dims[2] = {0}; cJSON_AddItemToObject(obj, "MeshNode", sub = cJSON_CreateObject()); @@ -2273,6 +2273,8 @@ void mcx_savejdata(char* filename, mcconfig* cfg) { MMC_ERROR(-10, "saving mesh ROI data to JSON failed"); } } + } else { + MMC_ERROR(-10, "incomplete mesh data"); } cJSON_AddNumberToObject(obj, "InitElem", cfg->e0); diff --git a/src/mmclab.cpp b/src/mmclab.cpp index 3d75fe88..84a917b4 100644 --- a/src/mmclab.cpp +++ b/src/mmclab.cpp @@ -87,6 +87,8 @@ void mmc_set_field(const mxArray* root, const mxArray* item, int idx, mcconfig* void mmc_validate_config(mcconfig* cfg, tetmesh* mesh); void mmclab_usage(); +extern const char debugflag[]; + /** @brief Mex function for the MMC host function for MATLAB/Octave * This is the master function to interface all MMC features inside MATLAB. * In MMCLAB, all inputs are read from the cfg structure, which contains all @@ -729,7 +731,7 @@ void mmc_set_field(const mxArray* root, const mxArray* item, int idx, mcconfig* mexWarnMsgTxt("not enough space. string is truncated."); } - cfg->debuglevel = mcx_parsedebugopt(buf); + cfg->debuglevel = mcx_parsedebugopt(buf, debugflag); printf("mmc.debuglevel='%s';\n", buf); } else if (strcmp(name, "srctype") == 0) { int len = mxGetNumberOfElements(item);