EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
Classes | Namespaces | Enumerations | Functions | Variables
EBGeometry_Render.hpp File Reference

A renderer for looking at shapes: Camera, Settings, Image and Renderer, in namespace Render. More...

#include <atomic>
#include <cstdint>
#include <string>
#include <vector>
#include "EBGeometry_Array.hpp"
#include "EBGeometry_BoundingVolumes.hpp"
#include "EBGeometry_Expr.hpp"
#include "EBGeometry_GPU.hpp"
#include "EBGeometry_Ray.hpp"
#include "EBGeometry_RegionSettings.hpp"
#include "EBGeometry_Vec.hpp"
#include "EBGeometry_RenderImplem.hpp"
Include dependency graph for EBGeometry_Render.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  EBGeometry::Render::Camera< T >
 A camera orbiting a target point. More...
 
struct  EBGeometry::Render::Settings< T >
 What to render and how. A plain value; every field has a default. More...
 
struct  EBGeometry::Render::Image
 An image: width x height pixels, row by row from the top, each 0xRRGGBBAA. More...
 
struct  EBGeometry::Render::Stats
 What a render saw. More...
 
struct  EBGeometry::Render::PixelResult
 What PixelQuery computes for one pixel. More...
 
struct  EBGeometry::Render::RenderDetail::StoredPixel
 A pixel as a render stores it: PixelResult without the object, which is stored apart and only when asked for (Settings::m_recordPrimitives), so that a frame writes and copies 8 bytes per pixel. More...
 
struct  EBGeometry::Render::RenderDetail::CameraView< T >
 What every pixel needs from the camera, worked out once per frame: the eye, the view's axes and the field of view's slope. More...
 
struct  EBGeometry::Render::PixelQuery< T, S >
 One pixel of a rendered image in the shaded view: the functor that Renderer runs once per pixel index, on the host or through GPU::parallelFor(), for ViewMode::Shaded with nothing hidden or filled. More...
 
class  EBGeometry::Render::Renderer< T >
 Renders shapes into images. More...
 

Namespaces

namespace  EBGeometry
 Namespace containing all of EBGeometry's functionality.
 

Enumerations

enum class  EBGeometry::Render::ColorBy : uint8_t { Uniform , Primitive , Normal }
 How surfaces are colored. More...
 
enum class  EBGeometry::Render::ViewMode : uint8_t {
  Shaded , Depth , XRay , CostHit ,
  CostCrossing
}
 What a render shows at each pixel. More...
 
enum class  EBGeometry::Render::CostUnit : uint8_t { None , Nanoseconds , Cycles }
 What the costs of a cost view count (Stats::m_costLow, Stats::m_costHigh). More...
 
enum class  EBGeometry::Render::Backdrop : uint8_t { Sky , Plain , Gradient , Vignette }
 What is drawn behind the shape, where a camera ray hits nothing (Settings::m_backdrop). More...
 
enum class  EBGeometry::Render::FloorStyle : uint8_t {
  Checker , Grid , Plain , ShadowOnly ,
  Mirror
}
 How the floor under the shape is drawn, when there is one (Settings::m_floor, Settings::m_floorStyle). More...
 
enum class  EBGeometry::Render::Look : uint8_t {
  Sky , Dark , Gradient , ShadowOnly ,
  LightGrid , Studio , Mirror , DarkGrid ,
  Blueprint
}
 Named combinations of the backdrop and the floor (see setLook()). More...
 
enum class  EBGeometry::Render::View : uint8_t {
  Front , Back , Right , Left ,
  Top , Bottom , Default
}
 A direction to look at a box from, for Camera::fit(): along the axes of the plane perpendicular to the up axis (with the default up axis +y, Front looks from +z and Right from +x), or along the up axis. More...
 

Functions

const char * EBGeometry::Render::lookName (Look a_look) noexcept
 A look's name, as the .ebg view block writes it: "sky", "dark", "gradient", "shadow_only", "light_grid", "studio", "mirror", "dark_grid" or "blueprint".
 
template<class T >
void EBGeometry::Render::setLook (Settings< T > &a_settings, Look a_look) noexcept
 Set the backdrop and the floor to a named look.
 
template<class T >
std::string EBGeometry::Render::toCode (const Camera< T > &a_camera, const Settings< T > &a_settings)
 A camera and settings as C++ statements that recreate them, for pasting a view found by hand (in Render::view(), key C prints them) into a program.
 
bool EBGeometry::Render::writeImage (const Image &a_image, const std::string &a_filename)
 Write an image to a file, as binary PPM (P6: 8 bits per channel, no alpha), which most image programs read.
 
double EBGeometry::Render::costPlace (const Stats &a_stats, double a_cost) noexcept
 Where a cost sits on a cost view's color scale: 0 at a_stats.m_costLow, 1 at a_stats.m_costHigh, on the log scale the frame's pixels were colored on, clamped to [0, 1]. With costColor(), what a colorbar matching the image needs.
 
uint32_t EBGeometry::Render::costColor (double a_place) noexcept
 The color a cost view gives a place on its scale, dark (0) to bright (1), as it colors the pixels.
 

Variables

template<class S >
constexpr bool EBGeometry::Render::primitivesAreFaces = false
 Whether a shape's primitives (HitT::m_primitive) are the faces of one object rather than objects: true for the mesh SDFs, whose primitive is a face of the mesh; false for every other shape: a Tape (whose primitives are its leaves), a fused composition and an analytic shape (one object, primitive 0), and a BVH union (a BVHUnion names its members, a BVHSmoothUnion 0).
 
template<class T >
constexpr bool EBGeometry::Render::primitivesAreFaces< FlatMeshSDF< T > > = true
 See primitivesAreFaces.
 
template<class T , size_t K>
constexpr bool EBGeometry::Render::primitivesAreFaces< MeshSDF< T, K > > = true
 See primitivesAreFaces.
 
template<class T , size_t K, size_t W>
constexpr bool EBGeometry::Render::primitivesAreFaces< TriMeshSDF< T, K, W > > = true
 See primitivesAreFaces.
 
constexpr uint8_t EBGeometry::Render::NumLooks = 9
 How many looks there are (Look's values are 0 to NumLooks - 1).
 

Detailed Description

A renderer for looking at shapes: Camera, Settings, Image and Renderer, in namespace Render.

Renders any shape (see isShape) into an image held in memory, by finding where each camera ray first crosses the surface (firstHit()) and shading it: diffuse and specular light from one direction, light from the sky, soft shadows and ambient occlusion, a floor under the shape, and a section plane that cuts the shape open. A surface the camera sees from inside the solid (a hole seen from within the material, or a mesh whose orientation is inverted) is tinted, so that it cannot be mistaken for an outside. Other views (ViewMode) show the depth, an x-ray of every surface, or the cost of each camera ray; chosen primitives can be seen through, and a part's inside filled. Each pixel is computed by a trivially copyable functor callable on a device (PixelQuery for the shaded view), so Renderer::render() runs it on the host's threads and Renderer::renderOnDevice() runs the same functor through GPU::parallelFor(). Render::view() (EBGeometry_Viewer.hpp) shows a shape in an interactive window, rendered this way.

Author
Robert Marskar

Enumeration Type Documentation

◆ Backdrop

enum class EBGeometry::Render::Backdrop : uint8_t
strong

What is drawn behind the shape, where a camera ray hits nothing (Settings::m_backdrop).

Enumerator
Sky 

Settings::m_skyHorizon to Settings::m_skyZenith by the ray's elevation above the horizon.

Plain 

Settings::m_background.

Gradient 

Settings::m_gradientFrom at the top of the view to Settings::m_gradientTo at its bottom.

Vignette 

Settings::m_gradientFrom at the center of the view to Settings::m_gradientTo at its corners.

◆ ColorBy

enum class EBGeometry::Render::ColorBy : uint8_t
strong

How surfaces are colored.

Enumerator
Uniform 

One color (Settings::m_color) everywhere.

Primitive 

A color per primitive: per leaf of a Tape, per face of a mesh SDF (see HitT::m_primitive); Settings::m_primitiveColors, then a built-in palette.

Normal 

The surface normal's direction as a color (each component from -1 to 1 mapped to 0 to 1).

◆ CostUnit

enum class EBGeometry::Render::CostUnit : uint8_t
strong

What the costs of a cost view count (Stats::m_costLow, Stats::m_costHigh).

Enumerator
None 

Not a cost view: the costs are 0.

Nanoseconds 

On the host: each pixel's own ray, timed with the steady clock.

Cycles 

On a device: the clock cycles that passed while the pixel's thread traced its ray, as the device counts them (clock64()), with no conversion to time. A pixel keeps its count in 32 bits, so one ray over 2^32 cycles (seconds, far beyond any ray) would wrap.

◆ FloorStyle

enum class EBGeometry::Render::FloorStyle : uint8_t
strong

How the floor under the shape is drawn, when there is one (Settings::m_floor, Settings::m_floorStyle).

Enumerator
Checker 

Squares of side Settings::m_floorCellSize in Settings::m_floorColor, every second a little darker.

Grid 

Settings::m_floorColor with lines in Settings::m_floorLineColor every Settings::m_floorCellSize, every Settings::m_floorMajorEvery-th heavier.

Plain 

Settings::m_floorColor.

ShadowOnly 

The backdrop, darkened where the shape shadows it: no floor is seen, only the shape's shadow.

Mirror 

Settings::m_floorColor, reflecting the shape by Settings::m_floorReflectance: one more trace per pixel of the floor.

◆ Look

enum class EBGeometry::Render::Look : uint8_t
strong

Named combinations of the backdrop and the floor (see setLook()).

Enumerator
Sky 

The sky and the checkered floor (the defaults).

Dark 

A plain dark background and the checkered floor.

Gradient 

A blue-gray to white gradient, no floor: the classic look of mechanical CAD.

ShadowOnly 

A light gray gradient, and only the shape's soft shadow under it.

LightGrid 

A light gradient and a pale floor with a grid.

Studio 

A seamless white backdrop with a very soft shadow, as in product renderings.

Mirror 

A dark gradient and a dark floor that reflects the shape.

DarkGrid 

A dark gray gradient and a faint grid.

Blueprint 

Navy, with light grid lines.

◆ View

enum class EBGeometry::Render::View : uint8_t
strong

A direction to look at a box from, for Camera::fit(): along the axes of the plane perpendicular to the up axis (with the default up axis +y, Front looks from +z and Right from +x), or along the up axis.

Enumerator
Front 

Yaw 0, pitch 0.

Back 

Yaw 180, pitch 0.

Right 

Yaw 90, pitch 0.

Left 

Yaw -90, pitch 0.

Top 

Pitch 90: straight down the up axis.

Bottom 

Pitch -90: straight up the up axis.

Default 

The default yaw (35) and pitch (25), from above at an angle.

◆ ViewMode

enum class EBGeometry::Render::ViewMode : uint8_t
strong

What a render shows at each pixel.

Enumerator
Shaded 

Lit surfaces, colored by Settings::m_colorBy.

Depth 

How far from the eye the first surface is, near (bright) to far (dark) across the shape's box; the shape alone, cut by the section plane, without the floor or the plane's contour and sheet.

XRay 

On black, every surface a ray crosses glows faintly (more seen edge-on), with modest highlights.

CostHit 

What each pixel's firstHit() cost, one ray through its center (Settings::m_supersampling ignored): nanoseconds on the host, clock cycles on a device (see CostUnit), on a log scale over the frame (see Stats::m_costLow, costPlace(), costColor()).

CostCrossing 

What each pixel's firstCrossing() cost, as CostHit.

Function Documentation

◆ costColor()

uint32_t EBGeometry::Render::costColor ( double  a_place)
inlinenoexcept

The color a cost view gives a place on its scale, dark (0) to bright (1), as it colors the pixels.

Parameters
[in]a_placeThe place, clamped to [0, 1] (see costPlace()).
Returns
The color, 0xRRGGBBAA.

◆ costPlace()

double EBGeometry::Render::costPlace ( const Stats &  a_stats,
double  a_cost 
)
inlinenoexcept

Where a cost sits on a cost view's color scale: 0 at a_stats.m_costLow, 1 at a_stats.m_costHigh, on the log scale the frame's pixels were colored on, clamped to [0, 1]. With costColor(), what a colorbar matching the image needs.

Parameters
[in]a_statsThe frame's Stats, from a render in ViewMode::CostHit or ViewMode::CostCrossing.
[in]a_costA cost, in a_stats.m_costUnit.
Returns
The place on the scale; 0 when the frame is not a cost view or its pixels all cost the same.

◆ lookName()

const char * EBGeometry::Render::lookName ( Look  a_look)
inlinenoexcept

A look's name, as the .ebg view block writes it: "sky", "dark", "gradient", "shadow_only", "light_grid", "studio", "mirror", "dark_grid" or "blueprint".

Parameters
[in]a_lookThe look.
Returns
Its name.

◆ setLook()

template<class T >
void EBGeometry::Render::setLook ( Settings< T > &  a_settings,
Look  a_look 
)
inlinenoexcept

Set the backdrop and the floor to a named look.

Sets m_backdrop, its colors (m_skyHorizon, m_skyZenith, m_background, m_gradientFrom, m_gradientTo), m_floor, m_floorStyle, the floor's colors and lines, m_floorFade, m_floorReflectance and m_lightSize; leaves the rest (the shape's colors, the light's direction, the section) as it is. Change any of these afterwards to adjust a look.

Template Parameters
TFloating-point precision.
Parameters
[in,out]a_settingsSettings.
[in]a_lookThe look.

◆ toCode()

template<class T >
std::string EBGeometry::Render::toCode ( const Camera< T > &  a_camera,
const Settings< T > &  a_settings 
)
inline

A camera and settings as C++ statements that recreate them, for pasting a view found by hand (in Render::view(), key C prints them) into a program.

Writes camera.m_... = ...; and settings.m_... = ...; for every field that differs from its default, after declarations of camera and settings; T is the precision's name in the code.

Template Parameters
TFloating-point precision.
Parameters
[in]a_cameraCamera.
[in]a_settingsSettings.
Returns
The statements, one per line.

◆ writeImage()

bool EBGeometry::Render::writeImage ( const Image &  a_image,
const std::string &  a_filename 
)
inline

Write an image to a file, as binary PPM (P6: 8 bits per channel, no alpha), which most image programs read.

Parameters
[in]a_imageImage.
[in]a_filenameFile to write.
Returns
Whether the file was written (not for an image with fewer pixels than its size).

Variable Documentation

◆ primitivesAreFaces

template<class S >
constexpr bool EBGeometry::Render::primitivesAreFaces = false
inlineconstexpr

Whether a shape's primitives (HitT::m_primitive) are the faces of one object rather than objects: true for the mesh SDFs, whose primitive is a face of the mesh; false for every other shape: a Tape (whose primitives are its leaves), a fused composition and an analytic shape (one object, primitive 0), and a BVH union (a BVHUnion names its members, a BVHSmoothUnion 0).

Template Parameters
SShape type.

◆ primitivesAreFaces< FlatMeshSDF< T > >

template<class T >
constexpr bool EBGeometry::Render::primitivesAreFaces< FlatMeshSDF< T > > = true
inlineconstexpr

See primitivesAreFaces.

Template Parameters
TFloating-point precision.

◆ primitivesAreFaces< MeshSDF< T, K > >

template<class T , size_t K>
constexpr bool EBGeometry::Render::primitivesAreFaces< MeshSDF< T, K > > = true
inlineconstexpr

See primitivesAreFaces.

Template Parameters
TFloating-point precision.
KBranching factor.

◆ primitivesAreFaces< TriMeshSDF< T, K, W > >

template<class T , size_t K, size_t W>
constexpr bool EBGeometry::Render::primitivesAreFaces< TriMeshSDF< T, K, W > > = true
inlineconstexpr

See primitivesAreFaces.

Template Parameters
TFloating-point precision.
KBranching factor.
WSIMD width.