Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F91004999
pmapcontrib.h
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Nov 6, 20:43
Size
11 KB
Mime Type
text/x-Algol68
Expires
Fri, Nov 8, 20:43 (1 d, 22 h)
Engine
blob
Format
Raw Data
Handle
22178015
Attached To
R10977 RADIANCE Photon Map
pmapcontrib.h
View Options
/* RCSid $Id: pmapcontrib.h,v 2.5 2016/05/17 17:39:47 rschregle Exp $ */
/*
=========================================================================
Photon map routines for precomputed light source contributions; these
routines interface to mkpmap and rcontrib.
Roland Schregle (roland.schregle@{hslu.ch, gmail.com})
(c) Lucerne University of Applied Sciences and Arts,
supported by the Swiss National Science Foundation
(SNSF #147053, "Daylight Redirecting Components",
SNSF #179067, "Light Fields for Spatio-Temporal Glare Assessment")
=========================================================================
$Id: pmapcontrib.h,v 2.5 2016/05/17 17:39:47 rschregle Exp $
*/
#ifndef _PMAPCONTRIB_H
#define _PMAPCONTRIB_H
#ifdef PMAP_OOC
#define PMAP_CONTRIB
#include "pmapdata.h"
#include "wavelet2.h"
#include "mrgbe.h"
#ifndef MAXPROCESS
#include "rcontrib.h"
#endif
#ifndef MAXMODLIST
/* Max number of contributing sources */
#define MAXMODLIST 1024
#endif
/* Maximum empty bin ratio; if the fraction of bins containing no
contributions (= zero photon flux) lies above this value, a warning
is issued, indicating potential bias. */
#define PMAP_CONTRIB_WARNZEROBINS
#define PMAP_CONTRIB_MAXZEROBINS 0.5
/* Filename templates for per-modifier contrib photon maps and wavelet
coeffs; these are held in a separate subdirectory PMAP_CONTRIB_DIR */
#define PMAP_CONTRIB_DIR "%s.rc"
#define PMAP_CONTRIB_FILE "%s/%s.pm"
#define PMAP_CONTRIB_WAVELETFILE "%s/%s.wvt"
/* Precompute logarithmic contributions
!!! WARNING: DO NOT USE WITH WAVELET_EXTEND_GRAD[1,2], as this
!!! assumes _linear_ input to the wavelet transform!!! */
#define PMAP_CONTRIB_LOG
#if defined(PMAP_CONTRIB_LOG) && ( \
WAVELET_EXTEND_MODE == WAVELET_EXTEND_GRAD1 || \
WAVELET_EXTEND_MODE == WAVELET_EXTEND_GRAD2 \
)
#warning Wavelet xform boundary extension mode assumes linear \
input, but log encoding is enabled -- expect boundary artefacts!
#endif
/* Contrib value based on above (log or linear) */
#ifdef PMAP_CONTRIB_LOG
/* TODO: HOW DO WE RELIABLY HANDLE ZEROS IN LOG MODE ??? :^o */
#define PMAP_CONTRIB_VAL(c) ((c) > FTINY ? log(c) : 0)
#define PMAP_CONTRIB_IVAL(c) (fabs(c) > FTINY ? exp(c) : 0)
#else
#define PMAP_CONTRIB_VAL(c) (c)
#define PMAP_CONTRIB_IVAL(c) (c)
#endif
/* The following variables can be specified to override the orientation
of the Shirley-Chiu mapping (see also disk2square.cal).
We use the built-in functions in disk2square.c for efficiency and
in order to not depend on an external function file. These variables
merely mimic the function file interace.
RHS : right-hand-coordinate system (-1 for left-hand)
rNx, rNy, rNz : surface normal
Ux, Uy, Uz : up vector (defines phi = 0) */
#define PMAP_CONTRIB_SCRHS "RHS"
#define PMAP_CONTRIB_SCNORMX "rNx"
#define PMAP_CONTRIB_SCNORMY "rNy"
#define PMAP_CONTRIB_SCNORMZ "rNz"
#define PMAP_CONTRIB_SCUPX "Ux"
#define PMAP_CONTRIB_SCUPY "Uy"
#define PMAP_CONTRIB_SCUPZ "Uz"
/* XXX/TODO: rNz is NEGATED compared to rcontrib's convention!
Fix in ray2bin() ??? */
#define PMAP_CONTRIB_SCDEFAULTS ( \
"RHS=1; rNx=0; rNy=0; rNz=-1; Ux=0; Uy=1; Uz=0;" \
)
/* Template for common binning parameters passed to rcontrib */
#define PMAP_CONTRIB_RCPARAMS0 ( \
"-f disk2square.cal " PMAP_CONTRIB_SCDEFAULTS \
)
/* Template for per-modifier binning parameters passed to rcontrib */
#define PMAP_CONTRIB_RCMODPARAMS ( \
"-p SCdim %d -b scbin -bn %d -m %s " \
)
/* Maximum number of mRGBE encodable wavelet coefficients */
#define PMAP_CONTRIB_MAXCOEFFS (mRGBE_DATAMAX + 1)
/* Size of a set of encoded coefficients in wavelet file (in bytes)
* per photon. This is a function of the number of (mRGBE encoded)
* compressed detail coefficients nComp, their mRGBE range, and the
* number of (uncompressed) approximation coefficients.
* NOTE: the coefficient range minimum is omitted from the mRGBE
* range if nComp == 1, since it is implicitly zero! */
#define PMAP_CONTRIB_ENCSIZE(nComp) ((nComp) * sizeof(mRGBE) + \
(WAVELET_PADD2_NUMAPPROX + 1 + ((nComp) > 1)) * sizeof(COLR) \
)
/* Serialise 2D coordinates (x,y) in (dim x dim) Shirley-Chiu
square to 1D index. Returns -1 if coordinates invalid */
#define PMAP_CONTRIB_XY2LIN(dim, x, y) ( \
(x) < 0 || (y) < 0 ? -1 : (x) * (dim) + (y) \
)
/* Deserialise 1D index idx to 2D coordinates (x,y) in (dim x dim)
Shirley-Chiu square. Returns -1 if bin invalid */
#define PMAP_CONTRIB_LIN2X(dim, idx) ((idx) < 0 ? -1 : (idx) / (dim))
#define PMAP_CONTRIB_LIN2Y(dim, idx) ((idx) < 0 ? -1 : (idx) % (dim))
/* HACK: Get/set sign of float f by (ab)using bit 0 in char c */
#define PMAP_CONTRIB_SET_RGBE32_SGN(c, f) ((c) & 0xfe | ((f) < 0))
#define PMAP_CONTRIB_GET_RGBE32_SGN(c, f) (((c) & 1) ? -(f) : (f))
/* Condition for binned contributions */
#define PMAP_CONTRIB_BINNING(pmap) (isContribChildPmap(pmap) && \
pmap -> preCompContrib && \
((PreComputedContrib*)pmap -> preCompContrib) -> nBins > 1 \
)
/* Struct for wavelet coeff thresholding; saves original coeff index */
typedef
struct
{
WAVELET_COEFF
*
coeff
;
unsigned
idx
;
}
PreComputedContribCoeff
;
typedef
struct
{
char
*
waveletFname
;
FILE
*
waveletFile
;
WaveletMatrix2
waveletMatrix
,
tWaveletMatrix
;
/* Wavelet coeff compression/encoding buffer */
PreComputedContribCoeff
*
compressedCoeffs
;
mRGBERange
mrgbeRange
;
mRGBE
*
mrgbeCoeffs
;
unsigned
scDim
,
nBins
,
coeffDim
,
nCoeffs
,
nCompressedCoeffs
,
nNonZeroCoeffs
;
unsigned
long
contribSize
;
OOC_Cache
*
cache
;
/* Shared memory mapping to update numPhotons in multiproc. mode */
unsigned
long
*
numPhotonsShm
;
int
shmFile
;
char
shmFname
[
PMAP_TMPFNLEN
];
#ifdef PMAP_CONTRIB_BINHISTO
unsigned
long
*
binHisto
,
sumZero
,
minZero
,
maxZero
;
#endif
}
PreComputedContrib
;
/* The following are convenient placeholders interfacing to mkpmap
and rcontrib. They can be externally set via initPmapContribTab()
and referenced within the contrib pmap modules. These variables
can then be safely ignored by rtrace/rpict/rvu, without annoying
linking errors. */
/* Global pointer to rcontrib's contribution binning LUT */
extern
LUTAB
*
pmapContribTab
;
/* Contribution/coefficient mode flag */
extern
int
*
pmapContribMode
;
MODCONT
*
addContribModifier
(
LUTAB
*
contribTab
,
unsigned
*
numContribs
,
char
*
mod
,
char
*
binParm
,
int
binCnt
);
/* Add light source modifier mod to contribution lookup table
contribsTab, and update numContribs. Return initialised
contribution data for this modifier. */
void
addContribModfile
(
LUTAB
*
contribTab
,
unsigned
*
numContribs
,
char
*
modFile
,
char
*
binParm
,
int
binCnt
);
/* Add light source modifiers from file modFile to contribution lookup
* table contribTab, and update numContribs. */
void
freePreCompContribNode
(
void
*
p
);
/* Clean up precomputed contribution LUT entry */
void
initPmapContribTab
(
LUTAB
*
contribTab
,
int
*
contribMode
);
/* Set contribution table and contrib/coeff mode flag
(interface to rcmain.c, see also pmapContribTab above) */
void
initPmapContrib
(
PhotonMap
*
pmap
);
/* Initialise contribution photon map and check modifiers.
NOTE: pmapContribTab must be set before via initPmapContribTab() */
PhotonContribSourceIdx
newPhotonContribSource
(
PhotonMap
*
pmap
,
const
RAY
*
contribSrcRay
,
FILE
*
contribSrcHeap
);
/* Add contribution source ray for emitted contribution photon and save
* light source index and binned direction. The current contribution
* source is stored in pmap -> lastContribSrc. If the previous
* contribution source spawned photons (i.e. has srcIdx >= 0), it's
* appended to contribSrcHeap. If contribSrcRay == NULL, the current
* contribution source is still flushed, but no new source is set.
* Returns updated contribution source counter pmap -> numContribSrc. */
PhotonContribSourceIdx
buildContribSources
(
PhotonMap
*
pmap
,
FILE
**
contribSrcHeap
,
char
**
contribSrcHeapFname
,
PhotonContribSourceIdx
*
contribSrcOfs
,
unsigned
numHeaps
);
/* Consolidate per-subprocess contribution sources heaps into array
* pmap -> contribSrc. Returns offset for contribution source index
* linearisation in pmap -> numContribSrc. The heap files in
* contribSrcHeap are closed on return. */
void
initPreComputedContrib
(
PreComputedContrib
*
preCompContrib
);
/* Initialise precomputed contribution container in photon map */
void
preComputeContrib
(
PhotonMap
*
pmap
,
unsigned
numProc
);
/* Precompute contributions for a random subset of (finalGather *
pmap -> numPhotons) photons, and init the per-modifier precomputed
contribution photon maps in LUT pmap -> preCompContribTab,
discarding the original photons. */
void
distribPhotonContrib
(
PhotonMap
*
pmap
,
LUTAB
*
contribTab
,
unsigned
numContribs
,
int
*
contribMode
,
unsigned
numProc
);
/* Emit photons with binned light source contributions, precompute
their contributions and build photon map */
int
buildPreCompContribPmap
(
const
LUENT
*
preCompContribNode
,
void
*
p
);
/* Build per-modifier precomputed photon map. Returns 0 on success. */
void
saveContribPhotonMap
(
const
PhotonMap
*
pmap
,
const
char
*
fname
,
int
argc
,
char
**
argv
);
/* Save contribution pmap and its per-modifier precomputed children */
void
loadContribPhotonMap
(
PhotonMap
*
pmap
,
const
char
*
fname
);
/* Load contribution pmap and its per-modifier precomputed children */
void
getPreCompPhotonContrib
(
PhotonMap
*
pmap
,
RAY
*
ray
,
COLOR
totalContrib
);
/* Get precomputed light source contributions at ray -> rop for all
specified modifiers and accumulate them in pmapContribTab (which
maps to rcontrib's binning LUT). Also return total precomputed
contribs. */
#endif
#endif
Event Timeline
Log In to Comment