Classes | Macros | Typedefs | Functions
mmc_mesh.h File Reference

Definition of basic mesh data structures and inline vector operations. More...

#include <stdio.h>
#include <math.h>
#include "mmc_utils.h"
#include "mmc_rand_posix.c"
Include dependency graph for mmc_mesh.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  MMC_mesh
 Basic FEM mesh data structrure. More...
 
struct  MMC_raytracer
 Ray-tracer data structrure for pre-computed data. More...
 

Macros

#define MMC_UNDEFINED   (3.40282347e+38F)
 
#define ID_UNDEFINED   0x7FFFFFFF
 
#define R_RAND_MAX   (1.f/RAND_MAX)
 
#define TWO_PI   (M_PI*2.0)
 
#define EPS   1e-6f
 
#define LOG_MT_MAX   22.1807097779182f
 
#define R_MIN_MUS   1e9f
 
#define R_C0   3.335640951981520e-12f
 
#define DELTA_MUA   1e-4f
 
#define VERY_BIG   1e30f
 
#define MIN(a, b)   ((a)<(b)?(a):(b))
 
#define MAX(a, b)   ((a)>(b)?(a):(b))
 
#define MESH_ERROR(a)   mesh_error((a),__FILE__,__LINE__)
 

Typedefs

typedef struct MMC_mesh tetmesh
 
typedef struct MMC_raytracer raytracer
 

Functions

void mesh_init (tetmesh *mesh)
 Initializing the mesh data structure with default values. More...
 
void mesh_init_from_cfg (tetmesh *mesh, mcconfig *cfg)
 Loading user-specified mesh data. More...
 
void mesh_loadnode (tetmesh *mesh, mcconfig *cfg)
 Load node file and initialize the related mesh properties. More...
 
void mesh_loadelem (tetmesh *mesh, mcconfig *cfg)
 Load element file and initialize the related mesh properties. More...
 
void mesh_loadfaceneighbor (tetmesh *mesh, mcconfig *cfg)
 Load face-neightbor element list and initialize the related mesh properties. More...
 
void mesh_loadmedia (tetmesh *mesh, mcconfig *cfg)
 Load optical property file and initialize the related mesh properties. More...
 
void mesh_loadelemvol (tetmesh *mesh, mcconfig *cfg)
 Load tet element volume file and initialize the related mesh properties. More...
 
void mesh_loadseedfile (tetmesh *mesh, mcconfig *cfg)
 Load previously saved photon seeds from an .mch file for replay. More...
 
void mesh_clear (tetmesh *mesh)
 Clearing the mesh data structure. More...
 
float mesh_normalize (tetmesh *mesh, mcconfig *cfg, float Eabsorb, float Etotal, int pair)
 Function to normalize the fluence and remove influence from photon number and volume. More...
 
void mesh_build (tetmesh *mesh)
 
void mesh_error (const char *msg, const char *file, const int linenum)
 Error-handling in mesh operations. More...
 
void mesh_filenames (const char *format, char *foutput, mcconfig *cfg)
 Construct a full mesh file name using cfg session and root path. More...
 
void mesh_saveweight (tetmesh *mesh, mcconfig *cfg, int isref)
 Save the fluence output to a file. More...
 
void mesh_savedetphoton (float *ppath, void *seeds, int count, int seedbyte, mcconfig *cfg)
 Save detected photon data into an .mch history file. More...
 
void mesh_getdetimage (float *detmap, float *ppath, int count, mcconfig *cfg, tetmesh *mesh)
 Save binned detected photon data over an area-detector as time-resolved 2D images. More...
 
void mesh_savedetimage (float *detmap, mcconfig *cfg)
 Save binned detected photon data over an area-detector. More...
 
float mesh_getdetweight (int photonid, int colcount, float *ppath, mcconfig *cfg)
 Recompute the detected photon weight from the partial-pathlengths. More...
 
void mesh_srcdetelem (tetmesh *mesh, mcconfig *cfg)
 Identify wide-field source and detector-related elements (type=-1 for source, type=-2 for det) More...
 
void mesh_createdualmesh (tetmesh *mesh, mcconfig *cfg)
 
void mesh_loadroi (tetmesh *mesh, mcconfig *cfg)
 Load edge/node/face roi for implicit MMC. More...
 
double mesh_getreff_approx (double n_in, double n_out)
 Compute the effective reflection coefficient Reff using approximated formula. More...
 
double mesh_getreff (double n_in, double n_out)
 Compute the effective reflection coefficient Reff. More...
 
void tracer_init (raytracer *tracer, tetmesh *mesh, char methodid)
 Initialize a data structure storing all pre-computed ray-tracing related data. More...
 
void tracer_build (raytracer *tracer)
 Pre-computed ray-tracing related data. More...
 
void tracer_prep (raytracer *tracer, mcconfig *cfg)
 Preparing for the ray-tracing calculations. More...
 
void tracer_clear (raytracer *tracer)
 Clear the ray-tracing data structure. More...
 
float mc_next_scatter (float g, float3 *dir, RandType *ran, RandType *ran0, mcconfig *cfg, float *pmom)
 Performing one scattering event of the photon. More...
 

Detailed Description

Definition of basic mesh data structures and inline vector operations.

Function Documentation

◆ mc_next_scatter()

float mc_next_scatter ( float  g,
float3 dir,
RandType *  ran,
RandType *  ran0,
mcconfig cfg,
float *  pmom 
)

Performing one scattering event of the photon.

This function updates the direction of the photon by performing a scattering calculation

Parameters
[in]ganisotropy g
[out]dircurrent ray direction vector
[out]ranrandom number generator states
[out]ran0additional random number generator states
[out]cfgthe simulation configuration
[out]pmombuffer to store momentum transfer data if needed

◆ mesh_clear()

void mesh_clear ( tetmesh mesh)

Clearing the mesh data structure.

Destructor of the mesh data structure, delete all dynamically allocated members

◆ mesh_error()

void mesh_error ( const char *  msg,
const char *  file,
const int  linenum 
)

Error-handling in mesh operations.

Parameters
[in]msgthe error message string
[in]filethe unit file name where this error is raised
[in]linenumthe line number in the file where this error is raised
Here is the call graph for this function:

◆ mesh_filenames()

void mesh_filenames ( const char *  format,
char *  foutput,
mcconfig cfg 
)

Construct a full mesh file name using cfg session and root path.

Parameters
[in]formata format string to form the file name
[in]foutputpointer to the output string buffer
[in]cfgthe simulation configuration structure

◆ mesh_getdetimage()

void mesh_getdetimage ( float *  detmap,
float *  ppath,
int  count,
mcconfig cfg,
tetmesh mesh 
)

Save binned detected photon data over an area-detector as time-resolved 2D images.

When an area detector is used (such as a CCD), storing all detected photons can generate a huge output file. This can be mitigated by accumulate the data first to a rasterized detector grid, and then save only the integrated data.

Parameters
[out]detmapbuffer points to the output detector data array
[in]ppathbuffer points to the detected photon data (partial-path, det id, etc)
[in]counthow many photons are detected
[in]cfgthe simulation configuration
[in]meshthe mesh object

◆ mesh_getdetweight()

float mesh_getdetweight ( int  photonid,
int  colcount,
float *  ppath,
mcconfig cfg 
)

Recompute the detected photon weight from the partial-pathlengths.

This function currently does not consider the final transmission coeff before the photon being detected.

Parameters
[in]photonidindex of the detected photon
[in]colcounthow many 4-byte records per detected photon
[in]ppathbuffer points to the detected photon data (partial-path, det id, etc)
[in]cfgthe simulation configuration

◆ mesh_getreff()

double mesh_getreff ( double  n_in,
double  n_out 
)

Compute the effective reflection coefficient Reff.

Parameters
[in]n_inrefractive index of the diffusive medium
[in]n_outrefractive index of the non-diffusive medium

◆ mesh_getreff_approx()

double mesh_getreff_approx ( double  n_in,
double  n_out 
)

Compute the effective reflection coefficient Reff using approximated formula.

accuracy is limited see https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4482362/

Parameters
[out]tracerthe ray-tracer data structure
[in]pmeshthe mesh object
[in]methodidthe ray-tracing algorithm to be used

◆ mesh_init()

void mesh_init ( tetmesh mesh)

Initializing the mesh data structure with default values.

Constructor of the mesh object, initializing all field to default values

◆ mesh_init_from_cfg()

void mesh_init_from_cfg ( tetmesh mesh,
mcconfig cfg 
)

Loading user-specified mesh data.

Loading node, element etc from files into memory

Here is the call graph for this function:

◆ mesh_loadelem()

void mesh_loadelem ( tetmesh mesh,
mcconfig cfg 
)

Load element file and initialize the related mesh properties.

Parameters
[in]meshthe mesh object
[in]cfgthe simulation configuration structure
Here is the call graph for this function:

◆ mesh_loadelemvol()

void mesh_loadelemvol ( tetmesh mesh,
mcconfig cfg 
)

Load tet element volume file and initialize the related mesh properties.

Parameters
[in]meshthe mesh object
[in]cfgthe simulation configuration structure
Here is the call graph for this function:

◆ mesh_loadfaceneighbor()

void mesh_loadfaceneighbor ( tetmesh mesh,
mcconfig cfg 
)

Load face-neightbor element list and initialize the related mesh properties.

Parameters
[in]meshthe mesh object
[in]cfgthe simulation configuration structure
Here is the call graph for this function:

◆ mesh_loadmedia()

void mesh_loadmedia ( tetmesh mesh,
mcconfig cfg 
)

Load optical property file and initialize the related mesh properties.

Parameters
[in]meshthe mesh object
[in]cfgthe simulation configuration structure
Here is the call graph for this function:

◆ mesh_loadnode()

void mesh_loadnode ( tetmesh mesh,
mcconfig cfg 
)

Load node file and initialize the related mesh properties.

Parameters
[in]meshthe mesh object
[in]cfgthe simulation configuration structure
Here is the call graph for this function:

◆ mesh_loadroi()

void mesh_loadroi ( tetmesh mesh,
mcconfig cfg 
)

Load edge/node/face roi for implicit MMC.

Parameters
[in]meshthe mesh object
[in]cfgthe simulation configuration structure
Here is the call graph for this function:

◆ mesh_loadseedfile()

void mesh_loadseedfile ( tetmesh mesh,
mcconfig cfg 
)

Load previously saved photon seeds from an .mch file for replay.

Parameters
[in]meshthe mesh object
[in]cfgthe simulation configuration structure

◆ mesh_normalize()

float mesh_normalize ( tetmesh mesh,
mcconfig cfg,
float  Eabsorb,
float  Etotal,
int  pair 
)

Function to normalize the fluence and remove influence from photon number and volume.

This function outputs the Green's function from the raw simulation data. This needs to divide the total simulated photon energy, normalize the volumes of each node/elem, and consider the length unit and time-gates

Parameters
[in]meshthe mesh object
[in]cfgthe simulation configuration
[in]Eabsorbtotal absorbed energy from ray-tracing accummulation
[in]Etotaltotal launched energy, equal to photon number if not pattern-source

mesh->med[mesh->type[i]].n;

◆ mesh_savedetimage()

void mesh_savedetimage ( float *  detmap,
mcconfig cfg 
)

Save binned detected photon data over an area-detector.

function for saving binned detected photon data into time-resolved 2D images

Parameters
[in]detmapbuffer points to the output detector data array
[in]cfgthe simulation configuration

◆ mesh_savedetphoton()

void mesh_savedetphoton ( float *  ppath,
void *  seeds,
int  count,
int  seedbyte,
mcconfig cfg 
)

Save detected photon data into an .mch history file.

Parameters
[in]ppathbuffer points to the detected photon data (partial-path, det id, etc)
[in]seedsbuffer points to the detected photon seeds
[in]counthow many photons are detected
[in]seedbytehow many bytes per detected photon seed
[in]cfgthe simulation configuration

◆ mesh_saveweight()

void mesh_saveweight ( tetmesh mesh,
mcconfig cfg,
int  isref 
)

Save the fluence output to a file.

Parameters
[in]meshthe mesh object
[in]cfgthe simulation configuration

◆ mesh_srcdetelem()

void mesh_srcdetelem ( tetmesh mesh,
mcconfig cfg 
)

Identify wide-field source and detector-related elements (type=-1 for source, type=-2 for det)

Parameters
[in]meshthe mesh object
[in]cfgthe simulation configuration structure

◆ tracer_build()

void tracer_build ( raytracer tracer)

Pre-computed ray-tracing related data.

the pre-computed ray-tracing data include d: the vector of the 6 edges: edge[i]=[ni1,ni2]: d[i]=ni2 - ni1 m: the cross-product of the end-nodes of the 6-edges: edge[i]=[ni1,ni2]: m[i]=ni1 x ni2 n: the normal vector of the 4 facets, pointing outwards

Parameters
[out]tracerthe ray-tracer data structure

◆ tracer_clear()

void tracer_clear ( raytracer tracer)

Clear the ray-tracing data structure.

Deconstructor of the ray-tracing data structure

Parameters
[out]tracerthe ray-tracer data structure

◆ tracer_init()

void tracer_init ( raytracer tracer,
tetmesh pmesh,
char  methodid 
)

Initialize a data structure storing all pre-computed ray-tracing related data.

the pre-computed ray-tracing data include d: the vector of the 6 edges m: the cross-product of the end-nodes of the 6-edges n1 x n2 n: the normal vector of the 4 facets, pointing outwards

Parameters
[out]tracerthe ray-tracer data structure
[in]pmeshthe mesh object
[in]methodidthe ray-tracing algorithm to be used
Here is the call graph for this function:

◆ tracer_prep()

void tracer_prep ( raytracer tracer,
mcconfig cfg 
)

Preparing for the ray-tracing calculations.

This function build the ray-tracing precomputed data and test if the initial element (e0) encloses the photon launch position.

Parameters
[out]tracerthe ray-tracer data structure
[in]cfgthe simulation configuration structure
Here is the call graph for this function: