raytraverse helper functions written in c++
helper function for draw.from_pdf
pdf (np.array) – array of doubles with weights to check against threshold
threshold (float) – value used to determine the number of indices to return
lb (float, optional) – values below threshold * lb will be excluded from candidates (lb must be in (0,1)
ub (float, optional) – values above threshold * ub will have indices written to bidx
candidates (np.array) – array of candidate indices
bidx (np.array) – array of definitely included indices
nsampc (int) – the number of draws that should be selected from the candidates
interpolate luminance values associated with query results from scipy.cKDTree.query. Finds closest point and then locates vertices of enclosing triangle from this point. returns 0 in cases where the query provides no results, so the distance_upper_bound must be set appropriately. :param dest_vec: destination vectors to interpolate to, shape (N, 3) :type dest_vec: np.array :param errs: distances between src and destination (row matches dest_vec, column is sorted ascending), shape (N, # of queries) :type errs: np.array :param idxs: query result, index row in src_vec close to dest_vec, shape (N, # of queries) :type idxs: np.array :param src_vec: vectors of src_kd, shape (N, 3) :type src_vec: np.array :param src_lum: luminance values for src_kd, shape (src_vec.shape[0], srcn) :type src_lum: np.array :param err: distance below which closest sample is used directly :type err: float, optional
arrout – destination luminances shape (N, srcn)
np.array
Bases: pybind11_builtins.pybind11_object
singleton interface to the Radiance rtrace executable.
See the rtrace man page for a full description of the programs functionality. Instance is initialized with a list of arguments similar to the command line tool, but with several differences:
no -f format specifier, input and output is always a numpy array.
no -h option.
no -x/-y options, shape output data as necessary with np.reshape
no -P/-PP modes
an additional -c N option repeats each input N times and averages the result. Make sure that uncorrelated sampling is used (-U+, default)
the default output is -oz, z is an additional output specifier that yields a single photopic brightness per input ray.
no s/m/M/t/T/~ allowed as output specifiers
Examples
basic usage:
from raytraverse.crenderer import cRtrace
instance = cRtrace.get_instance()
instance.initialize(["rtrace", ...]) #Note: do not include octree at end!
instance.load_scene("scene.oct")
# ...
# define 'rays' as a numpy array of shape (N, 6)
# ...
lum = instance(rays)
cRtrace can also update the output specification and/or the settings without reloading the scene geometry:
instance.update_ospec("L") # to query ray distance
instance.initialize("rtrace -ab 0 -lr 1".split()) # note this begins with default arguments, it is not additive with previous settings!
raylength = instance(rays)
but if you are loading new geometry, the instance should be reset:
instance.reset()
instance.initialize(["rtrace", ...])
instance.load_scene("scene2.oct")
by loading a scene without light sources, sources can be dynamically loaded and unloaded without a reset:
instance.reset()
instance.initialize(["rtrace", ...])
instance.load_scene("scene_no_sources.oct")
instance.load_source("sky.rad")
skylum = instance(rays)
instance.load_source("sun.rad") # this unloads sky.rad and loads sun.rad
sunlum = instance(rays)
instance.load_source("sky.rad", 0) # using the optional freesrc, keep the sun loaded
totallum = instance(rays)
if np.allclose(skylum + sunlum, totallum, atol=.03): # depending on rendering settings / scene complexity
print("light is additive!)
Notes
the cRcontrib instance is best managed from a seperate class that handles argument generation. See raytraverse.renderer.Rtrace
run renderer for a set of rays
vecs (np.array) – shape (N, 6) origin + direction vectors
values – shape (N, M) result array, M depends on output specification
np.array
returns (instantiating if necessary) pointer to Renderer instance.
return list of sources in model
ncomp – number of components renderer will return, or -1 on failure.
int
arglist (a sequence of strings) must be a member of calling instance and persist for duration of program
arglist (list) – a sequence of arguments to initialize renderer. must be a member of calling instance and persist for duration of program
nproc – number of processors renderer initialized with or -1 if initialization failed.
int
load scene file to renderer
octee (str) – path to octree file.
arglist (a sequence of strings) must be a member of calling instance and persist for duration of program
updates private srcobj parameter for default removing all sources
srcname (str) – path to file with source definition.
freesrc (int, optional) – number of previous sources to unload (unloads from end of object list only safe if removing sources loaded by this function. If negative removes all sources loaded by this function.
reset renderer state, must be called before loading an new scene or changing rendering parameters
update output values request
vs (str) – output specification string (see rtrace manpage option -o)
ncomp – number of components renderer will return, or -1 on failure.
int
Bases: pybind11_builtins.pybind11_object
singleton interface to the Radiance rcontrib executable.
See the rcontrib man page for a full description of the programs functionality. Instance is initialized with a list of arguments similar to the command line tool, but with several differences:
no -o option. All output is written to a memory buffer returned as a Numpy array
no -f format specifier, input and output is always a numpy array.
no -r option.
no -h option.
the -c option repeats and accumulates input rays rather than accumulating input.
an additional flag -Z outputs a single brightness value (photopic) rather than 3-color channels. this is True by default.
Examples
basic usage:
from raytraverse.crenderer import cRcontrib
instance = cRcontrib.get_instance()
instance.initialize(["rcontrib", "-n", "8", ..., "-m", "mod"]) #Note: do not include octree at end!
instance.load_scene("scene.oct")
# ...
# define 'rays' as a numpy array of shape (N, 6)
# ...
contributions = instance(rays)
Subsequent calls can be made to the instance, but if either the settings or scene are changed:
instance.reset()
instance.initialize(["rcontrib", "-n", "8", ..., "-m", "mod2"])
instance.load_scene("scene2.oct")
Notes
the cRcontrib instance is best managed from a seperate class that handles argument generation. See raytraverse.renderer.Rcontrib
run renderer for a set of rays
vecs (np.array) – shape (N, 6) origin + direction vectors
values – shape (N, M) result array, M depends on output specification
np.array
returns (instantiating if necessary) pointer to Renderer instance.
arglist (a sequence of strings) must be a member of calling instance and persist for duration of program
arglist (list) – a sequence of arguments to initialize renderer. must be a member of calling instance and persist for duration of program
nproc – number of processors renderer initialized with or -1 if initialization failed.
int
load scene file to renderer
octee (str) – path to octree file.
reset renderer state, must be called before loading an new scene or changing rendering parameters