Skip to content

Commit

Permalink
test if media prop count is less than max label
Browse files Browse the repository at this point in the history
  • Loading branch information
fangq committed Aug 15, 2020
1 parent 407a75d commit 2afab4a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/mcx_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
* Short command line options
* If a short command line option is '-' that means it only has long/verbose option.
* Array terminates with '\0'.
* Currently un-used options: cCjJNoQy0-9
*/

const char shortopt[]={'h','i','f','n','t','T','s','a','g','b','-','z','u','H','P',
Expand Down Expand Up @@ -1225,6 +1226,14 @@ void mcx_prepdomain(char *filename, Config *cfg){
}
}
}
if(cfg->vol && cfg->mediabyte <= 4){
unsigned int fieldlen=cfg->dim.x*cfg->dim.y*cfg->dim.z;
unsigned int maxlabel=0;
for(uint i=0;i<fieldlen;i++)
maxlabel=MAX(maxlabel,(cfg->vol[i]&MED_MASK));
if(cfg->medianum<=maxlabel)
MCX_ERROR(-4,"input media optical properties are less than the labels in the volume");
}
for(int i=0;i<MAX_DEVICE;i++)
if(cfg->deviceid[i]=='0')
cfg->deviceid[i]='\0';
Expand Down Expand Up @@ -1578,7 +1587,7 @@ int mcx_loadjson(cJSON *root, Config *cfg){
cfg->dim.y=val->child->next->valueint;
cfg->dim.z=val->child->next->next->valueint;
}else{
if(!Shapes && cfg->extrajson==NULL)
if(!Shapes && (!(cfg->extrajson && cfg->extrajson[0]=='_')) )
MCX_ERROR(-1,"You must specify the dimension of the volume");
}
val=FIND_JSON_OBJ("Step","Domain.Step",Domain);
Expand Down Expand Up @@ -1859,7 +1868,11 @@ int mcx_loadjson(cJSON *root, Config *cfg){
if(Shapes){
if(!FIND_JSON_OBJ("_ArraySize_","Volume._ArraySize_",Shapes) && !cfg->shapedata)
cfg->shapedata=cJSON_Print(Shapes);

if(cfg->extrajson && cfg->extrajson[0]=='_'){
if(cfg->shapedata)
free(cfg->shapedata);
cfg->shapedata=cJSON_Print(Shapes);
}
if(FIND_JSON_OBJ("_ArrayZipData_","Volume._ArrayZipData_",Shapes)){
int ndim;
char *type=NULL, *buf=NULL;
Expand All @@ -1876,7 +1889,7 @@ int mcx_loadjson(cJSON *root, Config *cfg){
MCX_ERROR(status,mcx_last_shapeerror());
}
}
}else if(cfg->extrajson==NULL){
}else if(!(cfg->extrajson && cfg->extrajson[0]=='_')){
MCX_ERROR(-1,"You must either define Domain.VolumeFile, or define a Shapes section");
}
}else if(Shapes){
Expand Down Expand Up @@ -3029,13 +3042,18 @@ void mcx_parsecmd(int argc, char* argv[], Config *cfg){
if(cfg->extrajson){
cJSON *jroot = cJSON_Parse(cfg->extrajson);
if(jroot){
cfg->extrajson[0]='_';
mcx_loadjson(jroot,cfg);
cJSON_Delete(jroot);
}else{
MCX_ERROR(-1,"invalid json fragment following --json");
}
}
}
if(cfg->isdumpjson==3){
mcx_savejdata(cfg->jsonfile, cfg);
exit(0);
}
}

/**
Expand Down
8 changes: 8 additions & 0 deletions src/mcxlab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,14 @@ void mcx_validate_config(Config *cfg){
cfg->prop[i].g=1.f;
}
}
if(cfg->vol && cfg->mediabyte <= 4){
unsigned int fieldlen=cfg->dim.x*cfg->dim.y*cfg->dim.z;
unsigned int maxlabel=0;
for(uint i=0;i<fieldlen;i++)
maxlabel=MAX(maxlabel,(cfg->vol[i]&MED_MASK));
if(cfg->medianum<=maxlabel)
mexErrMsgTxt("input media optical properties are less than the labels in the volume");
}
if(cfg->unitinmm!=1.f){
cfg->steps.x=cfg->unitinmm; cfg->steps.y=cfg->unitinmm; cfg->steps.z=cfg->unitinmm;
for(i=1;i<cfg->medianum;i++){
Expand Down

0 comments on commit 2afab4a

Please sign in to comment.