Macros | Typedefs | Functions
mmclab.cpp File Reference

mex function for MMCLAB More...

#include <stdio.h>
#include <string.h>
#include <time.h>
#include <exception>
#include "mex.h"
#include "mmc_const.h"
#include "mmc_mesh.h"
#include "mmc_host.h"
#include "mmc_tictoc.h"
#include "mmc_raytrace.h"
Include dependency graph for mmclab.cpp:

Macros

#define GET_1ST_FIELD(x, y)   if(strcmp(name,#y)==0) {double *val=mxGetPr(item);x->y=val[0];printf("mmc.%s=%g;\n",#y,(float)(x->y));}
 Macro to read the 1st scalar cfg member.
 
#define GET_ONE_FIELD(x, y)   else GET_1ST_FIELD(x,y)
 Macro to read one scalar cfg member.
 
#define GET_VEC3_FIELD(u, v)
 Macro to read one 3-element vector member of cfg. More...
 
#define GET_VEC34_FIELD(u, v)
 Macro to read one 3- or 4-element vector member of cfg. More...
 
#define GET_VEC4_FIELD(u, v)
 Macro to read one 4-element vector member of cfg. More...
 
#define SET_GPU_INFO(output, id, v)   mxSetField(output,id,#v,mxCreateDoubleScalar(gpuinfo[i].v));
 
#define ABS(a)   ((a)<0?-(a):(a))
 
#define MAX(a, b)   ((a)>(b)?(a):(b))
 
#define MEXERROR(a)   mcx_error(999,a,__FILE__,__LINE__)
 

Typedefs

typedef mwSize dimtype
 

Functions

void mmc_set_field (const mxArray *root, const mxArray *item, int idx, mcconfig *cfg, tetmesh *mesh)
 MATLAB type alias for integer type to use for array sizes and dimensions. More...
 
void mmc_validate_config (mcconfig *cfg, tetmesh *mesh)
 Validate all input fields, and warn incompatible inputs. More...
 
void mmclab_usage ()
 Print a brief help information if nothing is provided.
 
void mexFunction (int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
 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 simuation parameters and data. More...
 
int mmc_throw_exception (const int id, const char *msg, const char *filename, const int linenum)
 Error reporting function in the mex function, equivallent to mcx_error in binary mode. More...
 
void mcx_matlab_flush ()
 Force matlab refresh the command window to print all buffered messages.
 

Detailed Description

mex function for MMCLAB

Macro Definition Documentation

◆ GET_VEC34_FIELD

#define GET_VEC34_FIELD (   u,
 
)
Value:
else if(strcmp(name,#v)==0) {double *val=mxGetPr(item);u->v.x=val[0];u->v.y=val[1];u->v.z=val[2];if(mxGetNumberOfElements(item)==4) u->v.w=val[3];\
printf("mmc.%s=[%g %g %g %g];\n",#v,(float)(u->v.x),(float)(u->v.y),(float)(u->v.z),(float)(u->v.w));}

Macro to read one 3- or 4-element vector member of cfg.

◆ GET_VEC3_FIELD

#define GET_VEC3_FIELD (   u,
 
)
Value:
else if(strcmp(name,#v)==0) {double *val=mxGetPr(item);u->v.x=val[0];u->v.y=val[1];u->v.z=val[2];\
printf("mmc.%s=[%g %g %g];\n",#v,(float)(u->v.x),(float)(u->v.y),(float)(u->v.z));}

Macro to read one 3-element vector member of cfg.

◆ GET_VEC4_FIELD

#define GET_VEC4_FIELD (   u,
 
)
Value:
else if(strcmp(name,#v)==0) {double *val=mxGetPr(item);u->v.x=val[0];u->v.y=val[1];u->v.z=val[2];u->v.w=val[3];\
printf("mmc.%s=[%g %g %g %g];\n",#v,(float)(u->v.x),(float)(u->v.y),(float)(u->v.z),(float)(u->v.w));}

Macro to read one 4-element vector member of cfg.

Macro to output GPU parameters as field

Function Documentation

◆ mexFunction()

void mexFunction ( int  nlhs,
mxArray *  plhs[],
int  nrhs,
const mxArray *  prhs[] 
)

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 simuation parameters and data.

If no input is given for this function, it prints help information and return.

If a single string is passed, and if this string is 'gpuinfo', this function returns the list of GPUs on this host and return.

If a structure is passed to this function, a simulation will be launched.

Find out information about input and output.

The function can return 1-3 outputs (i.e. the LHS)

Loop over each element of the struct if it is an array, each element is a simulation

Enclose all simulation calls inside a try/catch construct for exception handling

Initialize cfg with default values first

Read each struct element from input and set value to the cfg configuration

Overwite the output flags using the number of output present

save fluence rate to the 1st output if present

save detected photon data to the 2nd output if present

save detected photon seeds to the 3rd output if present

Validate all input fields, and warn incompatible inputs

Clear up simulation data structures by calling the destructors

if the 2nd output presents, output the detected photon partialpath data

save diffuse reflectance

Here is the call graph for this function:

◆ mmc_set_field()

void mmc_set_field ( const mxArray *  root,
const mxArray *  item,
int  idx,
mcconfig cfg,
tetmesh mesh 
)

MATLAB type alias for integer type to use for array sizes and dimensions.

Function to parse one subfield of the input structure.

This function reads in all necessary information from the cfg input structure. it can handle single scalar inputs, short vectors (3-4 elem), strings and arrays.

Parameters
[in]rootthe cfg input data structure
[in]itemthe current element of the cfg input data structure
[in]idxthe index of the current element (starting from 0)
[out]cfgthe simulation configuration structure to store all input read from the parameters
[out]meshthe mesh data structure

◆ mmc_throw_exception()

int mmc_throw_exception ( const int  id,
const char *  msg,
const char *  filename,
const int  linenum 
)

Error reporting function in the mex function, equivallent to mcx_error in binary mode.

Parameters
[in]ida single integer for the types of the error
[in]msgthe error message string
[in]filenamethe unit file name where this error is raised
[in]linenumthe line number in the file where this error is raised

◆ mmc_validate_config()

void mmc_validate_config ( mcconfig cfg,
tetmesh mesh 
)

Validate all input fields, and warn incompatible inputs.

Perform self-checking and raise exceptions or warnings when input error is detected

Parameters
[in,out]cfgthe simulation configuration structure
[out]meshthe mesh data structure