fresnel.util

Overview

fresnel.util.array

Map internal fresnel buffers as numpy.ndarray objects.

fresnel.util.convex_polyhedron_from_vertices

Convert convex polyhedron vertices to data structures that fresnel can draw.

fresnel.util.image_array

Map internal image buffers as numpy.ndarray objects.

Details

Utilities.

class fresnel.util.array(buf, geom)

Map internal fresnel buffers as numpy.ndarray objects.

fresnel.util.array provides a python interface to access internal data of memory buffers stored and managed by fresnel. You can access a fresnel.util.array as if it were a numpy.ndarray (with limited operations). Below, slice is a slice or array indexing mechanic that numpy understands.

Writing

Write to an array with array[slice] = v where v is numpy.ndarray, list, or scalar value to broadcast. When v is a contiguous numpy.ndarray of the same data type, the data is copied directly from v into the internal buffer. Otherwise, it is converted to a numpy.ndarray before copying.

Reading

Read from an array with v = array[slice]. This returns a copy of the data as a numpy.ndarray each time it is called.

shape

Dimensions of the array.

Type

tuple

dtype

Numpy data type

fresnel.util.convex_polyhedron_from_vertices(vertices)

Convert convex polyhedron vertices to data structures that fresnel can draw.

Parameters

vertices (numpy.ndarray or array_like) – (Nx3 : float64) - The vertices of the polyhedron.

Returns

A dict containing the information used to draw the polyhedron. The dict contains the keys face_origin, face_normal, face_color, and radius.

The dictionary can be used directly to draw a polyhedron from its vertices:

scene = fresnel.Scene()
polyhedron = fresnel.util.convex_polyhedron_from_vertices(vertices)
geometry = fresnel.geometry.ConvexPolyhedron(scene,
                                             polyhedron,
                                             position=[0, 0, 0],
                                             orientation=[1, 0, 0, 0])
class fresnel.util.image_array(buf, geom)

Map internal image buffers as numpy.ndarray objects.

Inherits from array and provides all of its functionality, plus some additional convenience methods specific to working with images. Images are represented as WxHx4 numpy.ndarray of uint8 values in RGBA format.

When a image_array is the result of an image in a Jupyter notebook cell, Jupyter will display the image.