Basic vector math and mesh operations. More...
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_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_createdualmesh (tetmesh *mesh, mcconfig *cfg) |
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_loadnode (tetmesh *mesh, mcconfig *cfg) |
Load node file 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_loadroi (tetmesh *mesh, mcconfig *cfg) |
Load edge/node/face roi for implicit MMC. More... | |
void | mesh_loadelem (tetmesh *mesh, mcconfig *cfg) |
Load element 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_loadfaceneighbor (tetmesh *mesh, mcconfig *cfg) |
Load face-neightbor element list 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... | |
void | tracer_init (raytracer *tracer, tetmesh *pmesh, char methodid) |
Initialize a data structure storing all pre-computed ray-tracing related data. More... | |
void | tracer_prep (raytracer *tracer, mcconfig *cfg) |
Preparing for the ray-tracing calculations. More... | |
void | tracer_build (raytracer *tracer) |
Pre-computed ray-tracing related data. 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... | |
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... | |
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... | |
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... | |
Variables | |
char | pathsep = '/' |
const int | out [4][3] = {{0, 3, 1}, {3, 2, 1}, {0, 2, 3}, {0, 1, 2}} |
Tetrahedron faces, in counter-clock-wise orders, represented using local node indices. More... | |
const int | facemap [] = {2, 0, 1, 3} |
The local index of the node with an opposite face to the i-th face defined in nc[][]. More... | |
const int | ifacemap [] = {1, 2, 0, 3} |
Inverse mapping between the local index of the node and the corresponding opposite face in nc[]'s order. More... | |
const int | faceorder [] = {1, 3, 2, 0, -1} |
Index mapping from the i-th face-neighbors (facenb) to the face defined in nc[][]. More... | |
const int | ifaceorder [] = {3, 0, 2, 1} |
Index mapping from the i-th face defined in nc[][] to the face-neighbor (facenb) face orders. More... | |
Basic vector math and mesh operations.
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
[in] | g | anisotropy g |
[out] | dir | current ray direction vector |
[out] | ran | random number generator states |
[out] | ran0 | additional random number generator states |
[out] | cfg | the simulation configuration |
[out] | pmom | buffer to store momentum transfer data if needed |
void mesh_clear | ( | tetmesh * | mesh | ) |
Clearing the mesh data structure.
Destructor of the mesh data structure, delete all dynamically allocated members
void mesh_error | ( | const char * | msg, |
const char * | file, | ||
const int | linenum | ||
) |
Error-handling in mesh operations.
[in] | msg | the error message string |
[in] | file | the unit file name where this error is raised |
[in] | linenum | the line number in the file where this error is raised |
void mesh_filenames | ( | const char * | format, |
char * | foutput, | ||
mcconfig * | cfg | ||
) |
Construct a full mesh file name using cfg session and root path.
[in] | format | a format string to form the file name |
[in] | foutput | pointer to the output string buffer |
[in] | cfg | the simulation configuration structure |
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.
[out] | detmap | buffer points to the output detector data array |
[in] | ppath | buffer points to the detected photon data (partial-path, det id, etc) |
[in] | count | how many photons are detected |
[in] | cfg | the simulation configuration |
[in] | mesh | the mesh object |
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.
[in] | photonid | index of the detected photon |
[in] | colcount | how many 4-byte records per detected photon |
[in] | ppath | buffer points to the detected photon data (partial-path, det id, etc) |
[in] | cfg | the simulation configuration |
double mesh_getreff | ( | double | n_in, |
double | n_out | ||
) |
Compute the effective reflection coefficient Reff.
[in] | n_in | refractive index of the diffusive medium |
[in] | n_out | refractive index of the non-diffusive medium |
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/
[out] | tracer | the ray-tracer data structure |
[in] | pmesh | the mesh object |
[in] | methodid | the ray-tracing algorithm to be used |
void mesh_init | ( | tetmesh * | mesh | ) |
Initializing the mesh data structure with default values.
Constructor of the mesh object, initializing all field to default values
Loading user-specified mesh data.
Loading node, element etc from files into memory
Load element file and initialize the related mesh properties.
[in] | mesh | the mesh object |
[in] | cfg | the simulation configuration structure |
Load tet element volume file and initialize the related mesh properties.
[in] | mesh | the mesh object |
[in] | cfg | the simulation configuration structure |
Load face-neightbor element list and initialize the related mesh properties.
[in] | mesh | the mesh object |
[in] | cfg | the simulation configuration structure |
Load optical property file and initialize the related mesh properties.
[in] | mesh | the mesh object |
[in] | cfg | the simulation configuration structure |
Load node file and initialize the related mesh properties.
[in] | mesh | the mesh object |
[in] | cfg | the simulation configuration structure |
Load edge/node/face roi for implicit MMC.
[in] | mesh | the mesh object |
[in] | cfg | the simulation configuration structure |
Load previously saved photon seeds from an .mch file for replay.
[in] | mesh | the mesh object |
[in] | cfg | the simulation configuration structure |
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
[in] | mesh | the mesh object |
[in] | cfg | the simulation configuration |
[in] | Eabsorb | total absorbed energy from ray-tracing accummulation |
[in] | Etotal | total launched energy, equal to photon number if not pattern-source |
mesh->med[mesh->type[i]].n;
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
[in] | detmap | buffer points to the output detector data array |
[in] | cfg | the simulation configuration |
void mesh_savedetphoton | ( | float * | ppath, |
void * | seeds, | ||
int | count, | ||
int | seedbyte, | ||
mcconfig * | cfg | ||
) |
Save detected photon data into an .mch history file.
[in] | ppath | buffer points to the detected photon data (partial-path, det id, etc) |
[in] | seeds | buffer points to the detected photon seeds |
[in] | count | how many photons are detected |
[in] | seedbyte | how many bytes per detected photon seed |
[in] | cfg | the simulation configuration |
Save the fluence output to a file.
[in] | mesh | the mesh object |
[in] | cfg | the simulation configuration |
Identify wide-field source and detector-related elements (type=-1 for source, type=-2 for det)
[in] | mesh | the mesh object |
[in] | cfg | the simulation configuration structure |
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
[out] | tracer | the ray-tracer data structure |
void tracer_clear | ( | raytracer * | tracer | ) |
Clear the ray-tracing data structure.
Deconstructor of the ray-tracing data structure
[out] | tracer | the ray-tracer data structure |
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
[out] | tracer | the ray-tracer data structure |
[in] | pmesh | the mesh object |
[in] | methodid | the ray-tracing algorithm to be used |
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.
[out] | tracer | the ray-tracer data structure |
[in] | cfg | the simulation configuration structure |
const int facemap[] = {2, 0, 1, 3} |
The local index of the node with an opposite face to the i-th face defined in nc[][].
nc[i] <-> node[facemap[i]] the 1st face of this tet, i.e. nc[0]={3,0,1}, is opposite to the 3rd node the 2nd face of this tet, i.e. nc[1]={3,1,2}, is opposite to the 1st node etc.
const int faceorder[] = {1, 3, 2, 0, -1} |
Index mapping from the i-th face-neighbors (facenb) to the face defined in nc[][].
facenb[i] <-> nc[faceorder[i]] the 1st tet neighbor shares the 2nd face of this tet, i.e. nc[1]={3,1,2} the 2nd tet neighbor shares the 4th face of this tet, i.e. nc[3]={1,0,2} etc.
const int ifacemap[] = {1, 2, 0, 3} |
Inverse mapping between the local index of the node and the corresponding opposite face in nc[]'s order.
nc[ifacemap[i]] <-> node[i] the 1st node of this tet is in opposite to the 2nd face, i.e. nc[1]={3,1,2} the 2nd node of this tet is in opposite to the 3rd face, i.e. nc[1]={2,0,3} etc.
const int ifaceorder[] = {3, 0, 2, 1} |
Index mapping from the i-th face defined in nc[][] to the face-neighbor (facenb) face orders.
nc[ifaceorder[i]] <-> facenb[i] nc[0], made of nodes {3,0,1}, is the face connecting to the 4th neighbor (facenb[3]), nc[1], made of nodes {3,1,2}, is the face connecting to the 1st neighbor (facenb[0]), etc.
const int out[4][3] = {{0, 3, 1}, {3, 2, 1}, {0, 2, 3}, {0, 1, 2}} |
Tetrahedron faces, in counter-clock-wise orders, represented using local node indices.
node-connectivity, i.e. nc[4] points to the 4 facets of a tetrahedron, with each triangular face made of 3 nodes. The numbers [0-4] are the local node indices (starting from 0). The order of the nodes are in counter-clock-wise orders.
char pathsep = '/' |
path separator on Linux/Unix/OSX