| 1 |
rschregle |
1.1 |
/* |
| 2 |
|
|
================================================================== |
| 3 |
|
|
In-core kd-tree for photon map |
| 4 |
|
|
|
| 5 |
|
|
Roland Schregle (roland.schregle@{hslu.ch, gmail.com}) |
| 6 |
|
|
(c) Fraunhofer Institute for Solar Energy Systems, |
| 7 |
|
|
(c) Lucerne University of Applied Sciences and Arts, |
| 8 |
|
|
supported by the Swiss National Science Foundation (SNSF, #147053) |
| 9 |
|
|
================================================================== |
| 10 |
|
|
|
| 11 |
greg |
1.3 |
$Id: pmapkdt.h,v 1.2 2020/04/08 15:14:21 rschregle Exp $ |
| 12 |
rschregle |
1.1 |
*/ |
| 13 |
|
|
|
| 14 |
|
|
|
| 15 |
|
|
#ifndef PMAPKDT_H |
| 16 |
|
|
#define PMAPKDT_H |
| 17 |
|
|
|
| 18 |
|
|
/* #include <stdio.h> |
| 19 |
|
|
#include "fvect.h" */ |
| 20 |
|
|
#include "pmapdata.h" |
| 21 |
|
|
|
| 22 |
greg |
1.3 |
#ifdef __cplusplus |
| 23 |
|
|
extern "C" { |
| 24 |
|
|
#endif |
| 25 |
rschregle |
1.1 |
|
| 26 |
|
|
/* Forward declarations to break dependency loop with pmapdata.h */ |
| 27 |
|
|
struct PhotonMap; |
| 28 |
|
|
|
| 29 |
|
|
/* k-d tree as linear array of photons */ |
| 30 |
|
|
typedef struct { |
| 31 |
|
|
Photon *nodes; /* k-d tree as linear array */ |
| 32 |
|
|
} PhotonKdTree; |
| 33 |
|
|
|
| 34 |
|
|
typedef PhotonKdTree PhotonStorage; |
| 35 |
|
|
typedef Photon* PhotonIdx; |
| 36 |
|
|
|
| 37 |
|
|
/* Priority queue node for kd-tree lookups */ |
| 38 |
|
|
typedef struct { |
| 39 |
|
|
PhotonIdx idx; /* Pointer to photon */ |
| 40 |
|
|
float dist2; /* Photon's SQUARED distance to query point */ |
| 41 |
|
|
} kdT_SearchQueueNode; |
| 42 |
|
|
|
| 43 |
|
|
typedef struct { |
| 44 |
|
|
kdT_SearchQueueNode *node; |
| 45 |
|
|
unsigned len, tail; |
| 46 |
|
|
} kdT_SearchQueue; |
| 47 |
|
|
|
| 48 |
|
|
typedef kdT_SearchQueueNode PhotonSearchQueueNode; |
| 49 |
|
|
typedef kdT_SearchQueue PhotonSearchQueue; |
| 50 |
|
|
|
| 51 |
|
|
|
| 52 |
|
|
|
| 53 |
|
|
void kdT_Null (PhotonKdTree *kdt); |
| 54 |
|
|
/* Initialise kd-tree prior to storing photons */ |
| 55 |
|
|
|
| 56 |
|
|
void kdT_BuildPhotonMap (struct PhotonMap *pmap); |
| 57 |
|
|
/* Build a balanced kd-tree pmap -> store from photons in unsorted |
| 58 |
|
|
* heapfile pmap -> heap to guarantee logarithmic search times. The heap |
| 59 |
|
|
* is destroyed on return. */ |
| 60 |
|
|
|
| 61 |
|
|
int kdT_SavePhotons (const struct PhotonMap *pmap, FILE *out); |
| 62 |
|
|
/* Save photons in kd-tree to file. Return -1 on error, else 0 */ |
| 63 |
|
|
|
| 64 |
|
|
int kdT_LoadPhotons (struct PhotonMap *pmap, FILE *in); |
| 65 |
|
|
/* Load photons in kd-tree from file. Return -1 on error, else 0 */ |
| 66 |
|
|
|
| 67 |
|
|
void kdT_InitFindPhotons (struct PhotonMap *pmap); |
| 68 |
|
|
/* Initialise NN search queue prior to calling kdT_FindPhotons() */ |
| 69 |
|
|
|
| 70 |
rschregle |
1.2 |
int kdT_FindPhotons (struct PhotonMap* pmap, const FVECT pos, |
| 71 |
|
|
const FVECT norm); |
| 72 |
rschregle |
1.1 |
/* Locate pmap -> squeue.len nearest photons to pos with similar normal |
| 73 |
|
|
* (NULL for volume photons) and return in search queue pmap -> squeue, |
| 74 |
rschregle |
1.2 |
* starting with the further photon at pmap -> squeue.node. Return -1 |
| 75 |
|
|
* if none found, else 0. */ |
| 76 |
rschregle |
1.1 |
|
| 77 |
rschregle |
1.2 |
int kdT_Find1Photon (struct PhotonMap* pmap, const FVECT pos, |
| 78 |
|
|
const FVECT norm, Photon *photon); |
| 79 |
|
|
/* Locate single nearest photon to pos with similar normal. Return -1 |
| 80 |
|
|
* if none found, else 0. */ |
| 81 |
rschregle |
1.1 |
|
| 82 |
|
|
int kdT_GetPhoton (const struct PhotonMap *pmap, PhotonIdx idx, |
| 83 |
|
|
Photon *photon); |
| 84 |
rschregle |
1.2 |
/* Retrieve photon referenced by idx from kd-tree and return -1 on |
| 85 |
|
|
* error, else 0. */ |
| 86 |
rschregle |
1.1 |
|
| 87 |
|
|
Photon *kdT_GetNearestPhoton (const PhotonSearchQueue *squeue, |
| 88 |
|
|
PhotonIdx idx); |
| 89 |
|
|
/* Retrieve photon from NN search queue after OOC_FindPhotons() */ |
| 90 |
|
|
|
| 91 |
|
|
PhotonIdx kdT_FirstPhoton (const struct PhotonMap* pmap); |
| 92 |
|
|
/* Return pointer to first photon in kd-Tree */ |
| 93 |
|
|
|
| 94 |
|
|
void kdT_Delete (PhotonKdTree *kdt); |
| 95 |
|
|
/* Self-destruct */ |
| 96 |
|
|
|
| 97 |
greg |
1.3 |
#ifdef __cplusplus |
| 98 |
|
|
} |
| 99 |
|
|
#endif |
| 100 |
|
|
|
| 101 |
rschregle |
1.1 |
#endif |