BRL-CAD
photonmap.c File Reference
#include "common.h"
#include <limits.h>
#include <stdlib.h>
#include <time.h>
#include "bu/parallel.h"
#include "photonmap.h"
Include dependency graph for photonmap.c:

Go to the source code of this file.

Functions

int FindMedian (struct Photon *List, int Num, int Axis)
 
void BuildTree (struct Photon *EList, int ESize, struct PNode *Root)
 
void LocatePhotons (struct PhotonSearch *Search, struct PNode *Root)
 
void Store (point_t Pos, vect_t Dir, vect_t Normal, int map)
 
void SpecularReflect (vect_t normal, vect_t rdir)
 
void DiffuseReflect (vect_t normal, vect_t rdir)
 
int Refract (vect_t I, vect_t N, fastf_t n1, fastf_t n2)
 
int CheckMaterial (char *cmp, char *MS)
 
void GetMaterial (char *MS, vect_t spec, fastf_t *refi, fastf_t *transmit)
 
int PHit (struct application *ap, struct partition *PartHeadp, struct seg *finished_segs)
 
int HitRef (struct application *ap, struct partition *PartHeadp, struct seg *finished_segs)
 
int PMiss (struct application *ap)
 
void ScalePhotonPower (int map)
 
void EmitImportonsRandom (struct application *ap, point_t eye_pos)
 
void EmitPhotonsRandom (struct application *ap, double ScaleIndirect)
 
void SanityCheck (struct PNode *Root, int LR)
 
fastf_t GaussFilter (fastf_t dist, fastf_t rad)
 
fastf_t ConeFilter (fastf_t dist, fastf_t rad)
 
void GetEstimate (vect_t irrad, point_t pos, vect_t normal, fastf_t rad, int np, int map, double max_rad, int centog, int min_np)
 
int ICHit (struct application *ap, struct partition *PartHeadp, struct seg *finished_segs)
 
int ICMiss (struct application *ap)
 
void Polar2Euclidian (vect_t Dir, vect_t Normal, double Theta, double Phi)
 
void Irradiance (int pid, struct Photon *P, struct application *ap)
 
void BuildIrradianceCache (int pid, struct PNode *Node, struct application *ap)
 
void IrradianceThread (int pid, void *arg)
 
void Initialize (int MAP, int MapSize)
 
int LoadFile (char *pmfile)
 
void WritePhotons (struct PNode *Root, FILE *FH)
 
void WritePhotonFile (char *pmfile)
 
void BuildPhotonMap (struct application *ap, point_t eye_pos, int cpus, int width, int height, int Hypersample, int GlobalPhotons, double CausticsPercent, int Rays, double AngularTolerance, int RandomSeed, int ImportanceMapping, int IrradianceHypersampling, int VisualizeIrradiance, double ScaleIndirect, char pmfile[255])
 
void Swap (struct PSN *a, struct PSN *b)
 
void HeapUp (struct PhotonSearch *S, int ind)
 
void HeapDown (struct PhotonSearch *S, int ind)
 
fastf_t Dist (point_t a, point_t b)
 
void IrradianceEstimate (struct application *ap, vect_t irrad, point_t pos, vect_t normal)
 

Variables

int PM_Activated
 
int PM_Visualize
 
struct PhotonMap * PMap [PM_MAPS]
 
struct Photon * Emit [PM_MAPS]
 
struct Photon CurPh
 
vect_t BBMin
 
vect_t BBMax
 
int Depth
 
int PType
 
int PInit
 
int EPL
 
int EPS [PM_MAPS]
 
int ICSize
 
double ScaleFactor
 
struct IrradCache * IC
 
char * Map
 
int GPM_IH
 
int GPM_WIDTH
 
int GPM_HEIGHT
 
int GPM_RAYS
 
double GPM_ATOL
 
struct resource GPM_RTAB [MAX_PSW]
 
int HitG
 
int HitB
 

Detailed Description

Implementation of Photon Mapping

Definition in file photonmap.c.

Function Documentation

int FindMedian ( struct Photon *  List,
int  Num,
int  Axis 
)

Definition at line 71 of file photonmap.c.

References Max, and Min.

Referenced by BuildTree().

void BuildTree ( struct Photon *  EList,
int  ESize,
struct PNode *  Root 
)

Definition at line 94 of file photonmap.c.

References BU_ALLOC, bu_calloc(), bu_free(), FindMedian(), Max, and Min.

Referenced by BuildPhotonMap(), and LoadFile().

Here is the call graph for this function:

void LocatePhotons ( struct PhotonSearch *  Search,
struct PNode *  Root 
)

Definition at line 176 of file photonmap.c.

References Dist(), and GPM_ATOL.

Referenced by GetEstimate(), IrradianceEstimate(), and Store().

Here is the call graph for this function:

void Store ( point_t  Pos,
vect_t  Dir,
vect_t  Normal,
int  map 
)

Definition at line 228 of file photonmap.c.

References bu_calloc(), bu_free(), CurPh, Emit, HitB, HitG, LocatePhotons(), PMap, and ScaleFactor.

Referenced by PHit().

Here is the call graph for this function:

void SpecularReflect ( vect_t  normal,
vect_t  rdir 
)

Definition at line 288 of file photonmap.c.

Referenced by PHit().

void DiffuseReflect ( vect_t  normal,
vect_t  rdir 
)

Definition at line 307 of file photonmap.c.

References drand48().

Referenced by PHit().

Here is the call graph for this function:

int Refract ( vect_t  I,
vect_t  N,
fastf_t  n1,
fastf_t  n2 
)

Definition at line 327 of file photonmap.c.

Referenced by HitRef(), and PHit().

int CheckMaterial ( char *  cmp,
char *  MS 
)

Definition at line 350 of file photonmap.c.

Referenced by GetMaterial(), and PHit().

void GetMaterial ( char *  MS,
vect_t  spec,
fastf_t refi,
fastf_t transmit 
)

Definition at line 367 of file photonmap.c.

References BU_GET, bu_log(), BU_PUT, bu_struct_parse(), bu_vls_free(), BU_VLS_INIT_ZERO, bu_vls_printf(), CheckMaterial(), phong_parse, and PL_MAGIC.

Referenced by HitRef(), and PHit().

Here is the call graph for this function:

int PHit ( struct application ap,
struct partition PartHeadp,
struct seg finished_segs 
)
int HitRef ( struct application ap,
struct partition PartHeadp,
struct seg finished_segs 
)

Definition at line 455 of file photonmap.c.

References application::a_hit, application::a_onehit, application::a_ray, bu_log(), Depth, GetMaterial(), hit::hit_dist, mater_info::ma_shader, PHit(), partition::pt_forw, partition::pt_inflip, partition::pt_inhit, partition::pt_inseg, partition::pt_outhit, partition::pt_regionp, xray::r_dir, xray::r_pt, Refract(), region::reg_mater, RT_HIT_NORMAL, rt_shootray(), and seg::seg_stp.

Referenced by PHit().

Here is the call graph for this function:

int PMiss ( struct application ap)

Definition at line 691 of file photonmap.c.

Referenced by BuildPhotonMap().

void ScalePhotonPower ( int  map)

Definition at line 703 of file photonmap.c.

References Emit, EPS, PMap, and ScaleFactor.

Referenced by BuildPhotonMap().

void EmitImportonsRandom ( struct application ap,
point_t  eye_pos 
)

Definition at line 717 of file photonmap.c.

References application::a_ray, CurPh, Depth, drand48(), PMap, PType, xray::r_dir, xray::r_pt, and rt_shootray().

Referenced by BuildPhotonMap().

Here is the call graph for this function:

void EmitPhotonsRandom ( struct application ap,
double  ScaleIndirect 
)

Definition at line 755 of file photonmap.c.

References application::a_ray, BU_LIST_FOR, CurPh, Depth, drand48(), EPL, EPS, LightHead, PMap, PType, xray::r_dir, xray::r_pt, and rt_shootray().

Referenced by BuildPhotonMap().

Here is the call graph for this function:

void SanityCheck ( struct PNode *  Root,
int  LR 
)

Definition at line 814 of file photonmap.c.

References bu_log().

Here is the call graph for this function:

fastf_t GaussFilter ( fastf_t  dist,
fastf_t  rad 
)

Definition at line 826 of file photonmap.c.

Referenced by GetEstimate().

fastf_t ConeFilter ( fastf_t  dist,
fastf_t  rad 
)

Definition at line 833 of file photonmap.c.

void GetEstimate ( vect_t  irrad,
point_t  pos,
vect_t  normal,
fastf_t  rad,
int  np,
int  map,
double  max_rad,
int  centog,
int  min_np 
)

Definition at line 840 of file photonmap.c.

References bu_calloc(), bu_free(), GaussFilter(), LocatePhotons(), M_PI, PMap, and ScaleFactor.

Referenced by ICHit(), and IrradianceEstimate().

Here is the call graph for this function:

int ICHit ( struct application ap,
struct partition PartHeadp,
struct seg finished_segs 
)

Definition at line 958 of file photonmap.c.

References application::a_purpose, application::a_ray, GetEstimate(), hit::hit_dist, PMap, partition::pt_forw, partition::pt_inflip, partition::pt_inhit, partition::pt_inseg, xray::r_dir, xray::r_pt, RT_HIT_NORMAL, ScaleFactor, and seg::seg_stp.

Referenced by BuildPhotonMap().

Here is the call graph for this function:

int ICMiss ( struct application ap)

Definition at line 985 of file photonmap.c.

Referenced by BuildPhotonMap().

void Polar2Euclidian ( vect_t  Dir,
vect_t  Normal,
double  Theta,
double  Phi 
)

Definition at line 998 of file photonmap.c.

Referenced by Irradiance().

void Irradiance ( int  pid,
struct Photon *  P,
struct application ap 
)

Definition at line 1019 of file photonmap.c.

References application::a_hit, application::a_logoverlap, application::a_miss, application::a_purpose, application::a_ray, application::a_resource, application::a_rt_i, BU_ALLOC, bu_free(), drand48(), GPM_RAYS, GPM_RTAB, M, N, Polar2Euclidian(), xray::r_dir, xray::r_pt, RT_APPLICATION_INIT, and rt_shootray().

Referenced by BuildIrradianceCache().

Here is the call graph for this function:

void BuildIrradianceCache ( int  pid,
struct PNode *  Node,
struct application ap 
)

Definition at line 1078 of file photonmap.c.

References bu_log(), bu_semaphore_acquire(), bu_semaphore_release(), ICSize, Irradiance(), and PMap.

Referenced by IrradianceThread().

Here is the call graph for this function:

void IrradianceThread ( int  pid,
void *  arg 
)

Definition at line 1131 of file photonmap.c.

References BuildIrradianceCache(), PMap, and time().

Referenced by BuildPhotonMap().

Here is the call graph for this function:

void Initialize ( int  MAP,
int  MapSize 
)

Definition at line 1147 of file photonmap.c.

References BU_ALLOC, Emit, and PMap.

Referenced by BuildPhotonMap(), and LoadFile().

int LoadFile ( char *  pmfile)

Definition at line 1162 of file photonmap.c.

References bu_log(), BuildTree(), Emit, Initialize(), PMap, and ScaleFactor.

Referenced by BuildPhotonMap().

Here is the call graph for this function:

void WritePhotons ( struct PNode *  Root,
FILE *  FH 
)

Definition at line 1264 of file photonmap.c.

References bu_log().

Referenced by WritePhotonFile().

Here is the call graph for this function:

void WritePhotonFile ( char *  pmfile)

Definition at line 1279 of file photonmap.c.

References bu_log(), PMap, ScaleFactor, and WritePhotons().

Referenced by BuildPhotonMap().

Here is the call graph for this function:

void BuildPhotonMap ( struct application ap,
point_t  eye_pos,
int  cpus,
int  width,
int  height,
int  Hypersample,
int  GlobalPhotons,
double  CausticsPercent,
int  Rays,
double  AngularTolerance,
int  RandomSeed,
int  ImportanceMapping,
int  IrradianceHypersampling,
int  VisualizeIrradiance,
double  ScaleIndirect,
char  pmfile[255] 
)
void Swap ( struct PSN *  a,
struct PSN *  b 
)

Definition at line 1501 of file photonmap.c.

Referenced by HeapDown(), and HeapUp().

void HeapUp ( struct PhotonSearch *  S,
int  ind 
)

Definition at line 1526 of file photonmap.c.

References Swap().

Here is the call graph for this function:

void HeapDown ( struct PhotonSearch *  S,
int  ind 
)

Definition at line 1550 of file photonmap.c.

References Swap().

Here is the call graph for this function:

fastf_t Dist ( point_t  a,
point_t  b 
)

Definition at line 1570 of file photonmap.c.

Referenced by LocatePhotons().

void IrradianceEstimate ( struct application ap,
vect_t  irrad,
point_t  pos,
vect_t  normal 
)

Definition at line 1577 of file photonmap.c.

References application::a_x, application::a_y, bu_calloc(), bu_free(), bu_realloc(), GetEstimate(), GPM_IH, GPM_WIDTH, IC, LocatePhotons(), PMap, and ScaleFactor.

Referenced by phong_render().

Here is the call graph for this function:

Variable Documentation

int PM_Activated

Definition at line 43 of file photonmap.c.

Referenced by light_render(), and phong_render().

int PM_Visualize

Definition at line 44 of file photonmap.c.

Referenced by BuildPhotonMap(), and phong_render().

struct Photon* Emit[PM_MAPS]

Definition at line 47 of file photonmap.c.

Referenced by BuildPhotonMap(), Initialize(), LoadFile(), ScalePhotonPower(), and Store().

struct Photon CurPh

Definition at line 48 of file photonmap.c.

Referenced by EmitImportonsRandom(), EmitPhotonsRandom(), PHit(), and Store().

vect_t BBMin

Definition at line 49 of file photonmap.c.

Referenced by BuildPhotonMap(), and PHit().

vect_t BBMax

Definition at line 50 of file photonmap.c.

Referenced by BuildPhotonMap(), and PHit().

int Depth

Definition at line 51 of file photonmap.c.

Referenced by EmitImportonsRandom(), EmitPhotonsRandom(), HitRef(), and PHit().

int PType

Definition at line 52 of file photonmap.c.

Referenced by EmitImportonsRandom(), EmitPhotonsRandom(), and PHit().

int PInit

Definition at line 53 of file photonmap.c.

Referenced by BuildPhotonMap(), and PHit().

int EPL

Definition at line 54 of file photonmap.c.

Referenced by BuildPhotonMap(), and EmitPhotonsRandom().

int EPS[PM_MAPS]

Definition at line 55 of file photonmap.c.

Referenced by BuildPhotonMap(), EmitPhotonsRandom(), and ScalePhotonPower().

int ICSize

Definition at line 56 of file photonmap.c.

Referenced by BuildIrradianceCache(), and BuildPhotonMap().

double ScaleFactor
struct IrradCache* IC

Definition at line 58 of file photonmap.c.

Referenced by BuildPhotonMap(), and IrradianceEstimate().

char* Map

Definition at line 59 of file photonmap.c.

Referenced by BuildPhotonMap().

int GPM_IH

Definition at line 60 of file photonmap.c.

Referenced by BuildPhotonMap(), and IrradianceEstimate().

int GPM_WIDTH

Definition at line 61 of file photonmap.c.

Referenced by BuildPhotonMap(), and IrradianceEstimate().

int GPM_HEIGHT

Definition at line 62 of file photonmap.c.

Referenced by BuildPhotonMap().

int GPM_RAYS

Definition at line 63 of file photonmap.c.

Referenced by BuildPhotonMap(), and Irradiance().

double GPM_ATOL

Definition at line 64 of file photonmap.c.

Referenced by BuildPhotonMap(), and LocatePhotons().

struct resource GPM_RTAB[MAX_PSW]

Definition at line 65 of file photonmap.c.

Referenced by BuildPhotonMap(), and Irradiance().

int HitG

Definition at line 66 of file photonmap.c.

Referenced by BuildPhotonMap(), and Store().

int HitB

Definition at line 66 of file photonmap.c.

Referenced by BuildPhotonMap(), and Store().