ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/pmapkdt.h
Revision: 1.3
Committed: Tue Sep 17 16:36:05 2024 UTC (7 months, 2 weeks ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +8 -2 lines
Log Message:
chore: Added extern "C" to headers to avoid C++ name mangling

File Contents

# Content
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 $Id: pmapkdt.h,v 1.2 2020/04/08 15:14:21 rschregle Exp $
12 */
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 #ifdef __cplusplus
23 extern "C" {
24 #endif
25
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 int kdT_FindPhotons (struct PhotonMap* pmap, const FVECT pos,
71 const FVECT norm);
72 /* Locate pmap -> squeue.len nearest photons to pos with similar normal
73 * (NULL for volume photons) and return in search queue pmap -> squeue,
74 * starting with the further photon at pmap -> squeue.node. Return -1
75 * if none found, else 0. */
76
77 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
82 int kdT_GetPhoton (const struct PhotonMap *pmap, PhotonIdx idx,
83 Photon *photon);
84 /* Retrieve photon referenced by idx from kd-tree and return -1 on
85 * error, else 0. */
86
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 #ifdef __cplusplus
98 }
99 #endif
100
101 #endif