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

Definition of the core ray-tracing functions. More...

#include "mmc_mesh.h"
#include "mmc_utils.h"
Include dependency graph for mmc_raytrace.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  MMC_ray
 Data structure associated with the current photon/ray. More...
 
struct  MMC_visitor
 A structure that accumulates the statistics about the simulation. More...
 

Macros

#define MAX_TRIAL   3
 
#define FIX_PHOTON   1e-3f
 

Typedefs

typedef struct MMC_ray ray
 
typedef struct MMC_visitor visitor
 

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...
 
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...
 
void launchphoton (mcconfig *cfg, ray *r, tetmesh *mesh, RandType *ran, RandType *ran0)
 Launch a new photon. 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...
 
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...
 
void save_scatter_events (ray *r, tetmesh *mesh, mcconfig *cfg, visitor *visit)
 
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)
 
void traceroi (ray *r, raytracer *tracer, int roitype, int doinit)
 
void compute_distances_to_edge (ray *r, raytracer *tracer, int *ee, int edgeid, float d2d[2], float3 p2d[2], int *hitstatus)
 
void compute_distances_to_node (ray *r, raytracer *tracer, int *ee, int index, float nr, float3 **center, int *hitstatus)
 
float ray_cylinder_intersect (ray *r, int index, float d2d[2], float3 p2d[2], int hitstatus)
 
float ray_sphere_intersect (ray *r, int index, float3 *center, float nr, int hitstatus)
 
float ray_face_intersect (ray *r, raytracer *tracer, int *ee, int index, int baseid, int eid, int *hitstatus)
 

Detailed Description

Definition of the core ray-tracing functions.

Macro Definition Documentation

◆ FIX_PHOTON

#define FIX_PHOTON   1e-3f

offset to the ray to avoid edge/vertex

◆ MAX_TRIAL

#define MAX_TRIAL   3

number of fixes when a photon hits an edge/vertex

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

◆ 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

◆ 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