Macros | Functions | Variables
mmc_raytrace.c File Reference

Core unit for mash-based photon transport using ray tracing algorithms. More...

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include "mmc_raytrace.h"
Include dependency graph for mmc_raytrace.c:

Macros

#define F32N(a)   ((a) & 0x80000000)
 
#define F32P(a)   ((a) ^ 0x80000000)
 

Functions

void interppos (float3 *w, float3 *p1, float3 *p2, float3 *p3, float3 *pout)
 function to linearly interpolate between 3 3D points (p1,p2,p3) using weight (w) More...
 
void getinterp (float w1, float w2, float w3, float3 *p1, float3 *p2, float3 *p3, float3 *pout)
 function to linearly interpolate between 3 3D points (p1,p2,p3) using scalar weight (w) More...
 
void fixphoton (float3 *p, float3 *nodes, int *ee)
 Function to deal with ray-edge/ray-vertex intersections. More...
 
float plucker_raytet (ray *r, raytracer *tracer, mcconfig *cfg, visitor *visit)
 Plucker-coordinate based ray-tracer to advance photon by one step. More...
 
float havel_raytet (ray *r, raytracer *tracer, mcconfig *cfg, visitor *visit)
 
float badouel_raytet (ray *r, raytracer *tracer, mcconfig *cfg, visitor *visit)
 
float branchless_badouel_raytet (ray *r, raytracer *tracer, mcconfig *cfg, visitor *visit)
 
void onephoton (size_t id, raytracer *tracer, tetmesh *mesh, mcconfig *cfg, RandType *ran, RandType *ran0, visitor *visit)
 The core Monte Carlo function simulating a single photon (!!!Important!!!) More...
 
float reflectrayroi (mcconfig *cfg, float3 *c0, float3 *ph, raytracer *tracer, int *eid, int *inroi, RandType *ran, int roitype, int roiidx, int refeid)
 Calculate the reflection/transmission of a ray at the ROI surface. More...
 
float reflectray (mcconfig *cfg, float3 *c0, raytracer *tracer, int *oldeid, int *eid, int faceid, RandType *ran, int inroi)
 Calculate the reflection/transmission of a ray at an interface. More...
 
void launchphoton (mcconfig *cfg, ray *r, tetmesh *mesh, RandType *ran, RandType *ran0)
 Launch a new photon. More...
 
void albedoweight (ray *r, tetmesh *mesh, mcconfig *cfg, visitor *visit)
 Deal with absorption using MCML-like algorithm (albedo-weight MC) More...
 
void visitor_init (mcconfig *cfg, visitor *visit)
 
void visitor_clear (visitor *visit)
 
void updateroi (int immctype, ray *r, tetmesh *mesh)
 

Variables

const int e2n [6][2] = {{0, 1}, {0, 2}, {0, 3}, {1, 2}, {1, 3}, {2, 3}}
 
const int fc [4][3] = {{0, 4, 2}, {3, 5, 4}, {2, 5, 1}, {1, 3, 0}}
 Tetrahedron face edge indices. More...
 
const int nc [4][3] = {{3, 0, 1}, {3, 1, 2}, {2, 0, 3}, {1, 0, 2}}
 Tetrahedron faces, in clock-wise orders, represented using local node indices. More...
 
const int out [4][3]
 Tetrahedron faces, in counter-clock-wise orders, represented using local node indices. More...
 
const int facemap [4]
 The local index of the node with an opposite face to the i-th face defined in nc[][]. More...
 
const int ifacemap [4]
 Inverse mapping between the local index of the node and the corresponding opposite face in nc[]'s order. More...
 
const int faceorder [5]
 Index mapping from the i-th face-neighbors (facenb) to the face defined in nc[][]. More...
 
const int ifaceorder [4]
 Index mapping from the i-th face defined in nc[][] to the face-neighbor (facenb) face orders. More...
 
const char maskmap [16] = {4, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3}
 A mapping from SSE4 mask output to the face index.
 

Detailed Description

Core unit for mash-based photon transport using ray tracing algorithms.

Macro Definition Documentation

◆ F32N

#define F32N (   a)    ((a) & 0x80000000)

< Macro to enable SSE4 based ray-tracers Macro to test if a floating point is negative

◆ F32P

#define F32P (   a)    ((a) ^ 0x80000000)

Macro to test if a floating point is positive

Function Documentation

◆ albedoweight()

void albedoweight ( ray r,
tetmesh mesh,
mcconfig cfg,
visitor visit 
)

Deal with absorption using MCML-like algorithm (albedo-weight MC)

This function performs MCML-like absorption calculations

Parameters
[in,out]rthe current ray
[in]meshthe mesh data structure
[in,out]cfgsimulation configuration structure
[out]visitstatistics counters of this thread

◆ fixphoton()

void fixphoton ( float3 p,
float3 nodes,
int *  ee 
)

Function to deal with ray-edge/ray-vertex intersections.

when a photon is crossing a vertex or edge, (slightly) pull the photon toward the center of the element and try again

Parameters
[in,out]pcurrent photon position
[in]nodespointer to the 4 nodes of the tet
[in]eeindices of the 4 nodes ee=elem[eid]

◆ getinterp()

void getinterp ( float  w1,
float  w2,
float  w3,
float3 p1,
float3 p2,
float3 p3,
float3 pout 
)
inline

function to linearly interpolate between 3 3D points (p1,p2,p3) using scalar weight (w)

pout=p1*w1+p2*w2+p3*w3

Parameters
[in]w1weight for p1
[in]w2weight for p2
[in]w3weight for p3
[in]p11st point
[in]p22nd point
[in]p33rd point
[out]poutoutput 3D position

◆ havel_raytet()

float havel_raytet ( ray r,
raytracer tracer,
mcconfig cfg,
visitor visit 
)

Havel, Badouel and Branch-less Badouel-based SSE4 ray-tracer require to compile with SSE4 only. Give an error if not compiled with SSE.

◆ interppos()

void interppos ( float3 w,
float3 p1,
float3 p2,
float3 p3,
float3 pout 
)
inline

function to linearly interpolate between 3 3D points (p1,p2,p3) using weight (w)

pout=p1*w1+p2*w2+p3*w3

Parameters
[in]wweight vector
[in]p11st point
[in]p22nd point
[in]p33rd point
[out]poutoutput 3D position

◆ launchphoton()

void launchphoton ( mcconfig cfg,
ray r,
tetmesh mesh,
RandType *  ran,
RandType *  ran0 
)

Launch a new photon.

This function launch a new photon using one of the dozen supported source forms.

Parameters
[in,out]cfgsimulation configuration structure
[in,out]rthe current ray
[in]meshthe mesh data structure
[in,out]ranthe random number generator states
[in,out]ran0the additional random number generator states
Here is the call graph for this function:

◆ onephoton()

void onephoton ( size_t  id,
raytracer tracer,
tetmesh mesh,
mcconfig cfg,
RandType *  ran,
RandType *  ran0,
visitor visit 
)

The core Monte Carlo function simulating a single photon (!!!Important!!!)

This is the core Monte Carlo simulation function. It simulates the life-time of a single photon packet, from launching to termination.

Parameters
[in]idthe linear index of the current photon, starting from 0.
[in]tracerthe ray-tracer aux data structure
[in]meshthe mesh data structure
[in,out]ranthe random number generator states
[in,out]ran0the additional random number generator states
[in,out]cfgsimulation configuration structure
[out]visitstatistics counters of this thread

◆ plucker_raytet()

float plucker_raytet ( ray r,
raytracer tracer,
mcconfig cfg,
visitor visit 
)

Plucker-coordinate based ray-tracer to advance photon by one step.

this function uses Plucker-coordinate based ray-triangle intersection tests to advance photon by one step, see Fang2010.

Parameters
[in,out]rthe current ray
[in]tracerthe ray-tracer aux data structure
[in]cfgsimulation configuration structure
[out]visitstatistics counters of this thread

◆ reflectray()

float reflectray ( mcconfig cfg,
float3 c0,
raytracer tracer,
int *  oldeid,
int *  eid,
int  faceid,
RandType *  ran,
int  inroi 
)

Calculate the reflection/transmission of a ray at an interface.

This function handles the reflection and transmission events at an interface where the refractive indices mismatch.

Parameters
[in,out]cfgsimulation configuration structure
[in]c0the current direction vector of the ray
[in]tracerthe ray-tracer aux data structure
[in]oldeidthe index of the element the photon moves away from
[in]eidthe index of the element the photon about to move into
[in]faceidindex of the face through which the photon reflects/transmits
[in,out]ranthe random number generator states

◆ reflectrayroi()

float reflectrayroi ( mcconfig cfg,
float3 c0,
float3 ph,
raytracer tracer,
int *  eid,
int *  inroi,
RandType *  ran,
int  roitype,
int  roiidx,
int  refeid 
)

Calculate the reflection/transmission of a ray at the ROI surface.

This function handles the reflection and transmission events at the roi surface wall where the refractive indices mismatch.

Parameters
[in]c0the current direction vector of the ray
[in]uthe current direction vector of the edge
[in]phhitting position at the edgeroi
[in]E0any point on the edge
[in]tracerthe ray-tracer aux data structure
[in]eidthe index of the CURRENT element
[in,out]ranthe random number generator states

Variable Documentation

◆ e2n

const int e2n[6][2] = {{0, 1}, {0, 2}, {0, 3}, {1, 2}, {1, 3}, {2, 3}}

from edge index to node index

◆ facemap

const int facemap[4]

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.

◆ faceorder

const int faceorder[5]

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.

◆ fc

const int fc[4][3] = {{0, 4, 2}, {3, 5, 4}, {2, 5, 1}, {1, 3, 0}}

Tetrahedron face edge indices.

fc[4] points to the 4 facets of a tetrahedron, with each triangular face made of 3 directed edges. The numbers [0-5] are the local indices of the edge, defined by 0:[0->1], 1:[0->2], 2: [0->3], 3:[1->2], 4:[1->3], 5:[2->3] where the pair in [] are the local nodes forming the edge

◆ ifacemap

const int ifacemap[4]

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.

◆ ifaceorder

const int ifaceorder[4]

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.

◆ nc

const int nc[4][3] = {{3, 0, 1}, {3, 1, 2}, {2, 0, 3}, {1, 0, 2}}

Tetrahedron faces, in 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 clock-wise orders.

◆ out

const int out[4][3]

Tetrahedron faces, in counter-clock-wise orders, represented using local node indices.

out is like nc[] but with counter-clock-wise orientation. this makes the normal vec of each face pointing outwards.defined in mmc_mesh.c, node orders for each face, in counter-clock-wise orders

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.