#include <Raytracer.h>
Public Types | |
enum | ReductionMethod { MPI_REDUCE, MPI_GATHER } |
Which method to use when reducing the process-local image to a global one. More... | |
enum | Algorithm { RAYTRACE_HASHGRIDS, RAYTRACE_NAIVE, RAYTRACE_COMPARE_BOTH, RAYTRACE_COMPARE_BOTH_STRICTLY } |
Which algorithm to use when doing ray-object intersection finding. More... | |
Public Member Functions | |
Constructors | |
Raytracer (const shared_ptr< BlockStorage > &forest, const BlockDataID storageID, const shared_ptr< BodyStorage > &globalBodyStorage, const BlockDataID ccdID, uint16_t pixelsHorizontal, uint16_t pixelsVertical, real_t fov_vertical, uint16_t antiAliasFactor, const Vec3 &cameraPosition, const Vec3 &lookAtPoint, const Vec3 &upVector, const Lighting &lighting, const Color &backgroundColor=Color(real_t(0.1), real_t(0.1), real_t(0.1)), const std::function< ShadingParameters(const BodyID)> &bodyToShadingParamsFunc=defaultBodyTypeDependentShadingParams, const std::function< bool(const BodyID)> &isBodyVisibleFunc=defaultIsBodyVisible) | |
Instantiation constructor for the Raytracer class. More... | |
Raytracer (const shared_ptr< BlockStorage > &forest, const BlockDataID storageID, const shared_ptr< BodyStorage > &globalBodyStorage, const BlockDataID ccdID, const Config::BlockHandle &config, const std::function< ShadingParameters(const BodyID)> &bodyToShadingParamsFunction=defaultBodyTypeDependentShadingParams, const std::function< bool(const BodyID)> &isBodyVisibleFunc=defaultIsBodyVisible) | |
Instantiation constructor for the Raytracer class using a config object for view setup. More... | |
Get functions | |
uint16_t | getPixelsHorizontal () const |
Returns the horizontal amount of pixels of the generated image. More... | |
uint16_t | getPixelsVertical () const |
Returns the vertical amount of pixels of the generated image. More... | |
real_t | getFOVVertical () const |
Returns the vertical field-of-view of the camera. More... | |
const Vec3 & | getCameraPosition () const |
Returns the position of the camera in the global world frame. More... | |
const Vec3 & | getLookAtPoint () const |
Returns the point the camera looks at in the global world frame. More... | |
const Vec3 & | getUpVector () const |
Returns the vector indicating the upwards direction of the camera. More... | |
const Color & | getBackgroundColor () const |
Returns the background color of the scene. More... | |
bool | getImageOutputEnabled () const |
Returns true if image output to a file is enabled. More... | |
bool | getLocalImageOutputEnabled () const |
Returns true if local image output to a file is enabled. More... | |
const std::string & | getImageOutputDirectory () const |
Returns the directory where the images will be saved in. More... | |
uint8_t | getFilenameTimestepWidth () const |
Returns width of the timestep number in output filenames. More... | |
bool | getConfinePlanesToDomain () const |
Returns whether the rendering of planes gets confined in the simulation domain. More... | |
Set functions | |
void | setBackgroundColor (const Color &color) |
Set the background color of the scene. More... | |
void | setImageOutputEnabled (const bool enabled) |
Enable / disable outputting images in the specified directory. More... | |
void | setLocalImageOutputEnabled (const bool enabled) |
Enable / disable outputting local images in the specified directory. More... | |
void | setImageOutputDirectory (const std::string &path) |
Enable outputting images in the specified directory. More... | |
void | setFilenameTimestepWidth (uint8_t width) |
Set width of timestep number in output filenames. More... | |
void | setRaytracingAlgorithm (Algorithm algorithm) |
Set the algorithm to use while ray tracing. More... | |
void | setReductionMethod (ReductionMethod reductionMethod) |
Set the algorithm to use while reducing. More... | |
void | setConfinePlanesToDomain (bool confinePlanesToOrigin) |
Set if the rendering of planes should get confined to the simulation domain. More... | |
Private Attributes | |
Member variables | |
const shared_ptr< BlockStorage > | forest_ |
The BlockForest the raytracer operates on. More... | |
const BlockDataID | storageID_ |
The storage ID of the block data storage the raytracer operates on. More... | |
const shared_ptr< BodyStorage > | globalBodyStorage_ |
The global body storage the raytracer operates on. More... | |
const BlockDataID | ccdID_ |
The ID of the hash grids block data. More... | |
uint16_t | pixelsHorizontal_ |
The horizontal amount of pixels of the generated image. More... | |
uint16_t | pixelsVertical_ |
The vertical amount of pixels of the generated image. More... | |
real_t | fov_vertical_ |
The vertical field-of-view of the camera. More... | |
uint16_t | antiAliasFactor_ |
Factor used for oversampling. More... | |
Vec3 | cameraPosition_ |
The position of the camera in the global world frame. More... | |
Vec3 | lookAtPoint_ |
The point the camera looks at in the global world frame, marks the center of the view plane. More... | |
Vec3 | upVector_ |
The vector indicating the upwards direction of the camera. More... | |
Lighting | lighting_ |
The lighting of the scene. More... | |
Color | backgroundColor_ |
Background color of the scene. More... | |
bool | imageOutputEnabled_ |
Enable / disable writing images to file. More... | |
bool | localImageOutputEnabled_ |
Enable / disable writing images of the local process to file. More... | |
std::string | imageOutputDirectory_ |
Path to the image output directory. More... | |
uint8_t | filenameTimestepWidth_ |
Width of the timestep number in output filenames. More... | |
uint8_t | filenameRankWidth_ |
Width of the mpi rank part in a filename. More... | |
bool | confinePlanesToDomain_ |
Enable to render only the parts of planes within the simulation domain. More... | |
std::function< ShadingParameters(const BodyID)> | bodyToShadingParamsFunc_ |
Function which returns a ShadingParameters struct for the specified body. More... | |
std::function< bool(const BodyID)> | isBodyVisibleFunc_ |
Function which returns a boolean indicating if a given body should be visible in the final image. More... | |
Algorithm | raytracingAlgorithm_ |
Algorithm to use while intersection testing. More... | |
ReductionMethod | reductionMethod_ |
Reduction method used for assembling the image from all processes. More... | |
Member variables for raytracing geometry | |
Vec3 | n_ |
The normal vector of the viewing plane. More... | |
Vec3 | u_ |
The vector spanning the viewing plane in the "right direction". More... | |
Vec3 | v_ |
The vector spanning the viewing plane in the "up direction". More... | |
real_t | d_ |
The the distance from camera to viewing plane. More... | |
real_t | aspectRatio_ |
The aspect ratio of the generated image and viewing plane. More... | |
real_t | viewingPlaneHeight_ |
The viewing plane height in the world frame. More... | |
real_t | viewingPlaneWidth_ |
The viewing plane width in the world frame. More... | |
Vec3 | viewingPlaneOrigin_ |
The origin of the viewing plane. More... | |
real_t | pixelWidth_ |
The width of a pixel of the generated image in the viewing plane. More... | |
real_t | pixelHeight_ |
The height of a pixel of the generated image in the viewing plane. More... | |
MPI_Op | bodyIntersectionInfo_reduction_op |
MPI_Datatype | bodyIntersectionInfo_mpi_type |
Functions | |
template<typename BodyTypeTuple > | |
void | generateImage (const size_t timestep, WcTimingTree *tt=nullptr) |
Does one raytracing step. More... | |
void | setupView_ () |
Utility function for setting up the view plane and calculating required variables. More... | |
void | setupFilenameRankWidth_ () |
Utility function for initializing the attribute filenameRankWidth. More... | |
void | setupMPI_ () |
Utility function for setting up the MPI datatype and operation. More... | |
void | localOutput (const std::vector< BodyIntersectionInfo > &intersectionsBuffer, size_t timestep, WcTimingTree *tt=nullptr) |
void | output (const std::vector< BodyIntersectionInfo > &intersectionsBuffer, size_t timestep, WcTimingTree *tt=nullptr) |
std::string | getOutputFilename (const std::string &base, size_t timestep, bool isGlobalImage) const |
Generates the filename for output files. More... | |
void | writeImageToFile (const std::vector< BodyIntersectionInfo > &intersectionsBuffer, size_t timestep, bool isGlobalImage=false) const |
Writes the image of the current intersection buffer to a file in the image output directory. More... | |
void | writeImageToFile (const std::vector< BodyIntersectionInfo > &intersectionsBuffer, const std::string &fileName) const |
Writes the image of the current intersection buffer to a file in the image output directory. More... | |
void | syncImageUsingMPIReduce (std::vector< BodyIntersectionInfo > &intersectionsBuffer, WcTimingTree *tt=nullptr) |
Conflate the intersectionsBuffer of each process onto the root process using MPI_Reduce. More... | |
void | syncImageUsingMPIGather (std::vector< BodyIntersectionInfo > &intersections, std::vector< BodyIntersectionInfo > &intersectionsBuffer, WcTimingTree *tt=nullptr) |
Conflate the intersectionsBuffer of each process onto the root process using MPI_Gather. More... | |
bool | isPlaneVisible (const PlaneID plane, const Ray &ray) const |
Checks if a plane should get rendered. More... | |
size_t | coordinateToArrayIndex (size_t x, size_t y) const |
Converts a coordinate to an array index. More... | |
template<typename BodyTypeTuple > | |
void | traceRayInGlobalBodyStorage (const Ray &ray, BodyID &body_closest, real_t &t_closest, Vec3 &n_closest) const |
Traces a ray in the global body storage and finds the closest ray-body intersection. More... | |
template<typename BodyTypeTuple > | |
void | traceRayNaively (const Ray &ray, BodyID &body_closest, real_t &t_closest, Vec3 &n_closest) const |
Traces a ray naively and finds the closest ray-body intersection. More... | |
template<typename BodyTypeTuple > | |
void | traceRayInHashGrids (const Ray &ray, BodyID &body_closest, real_t &t_closest, Vec3 &n_closest) const |
Traces a ray in the global body storage and finds the closest ray-body intersection. More... | |
Color | getColor (const BodyID body, const Ray &ray, real_t t, const Vec3 &n) const |
Computes the color for a certain intersection. More... | |
Which algorithm to use when doing ray-object intersection finding.
|
explicit |
Instantiation constructor for the Raytracer class.
forest | BlockForest the raytracer operates on. |
storageID | Block data ID for the storage the raytracer operates on. |
globalBodyStorage | Pointer to the global body storage. |
ccdID | Block data ID for HashGrids. |
pixelsHorizontal | Horizontal amount of pixels of the generated image. |
pixelsVertical | Vertical amount of pixels of the generated image. |
fov_vertical | Vertical field-of-view of the camera. |
cameraPosition | Position of the camera in the global world frame. |
lookAtPoint | Point the camera looks at in the global world frame. |
upVector | Vector indicating the upwards direction of the camera. |
backgroundColor | Background color of the scene. |
bodyToShadingParamsFunc | A function mapping a BodyID to ShadingParameters for this body. This can be used to customize the color and shading of bodies. |
isBodyVisibleFunc | A function which returns a boolean indicating if a given body should be visible in the final image. |
|
explicit |
Instantiation constructor for the Raytracer class using a config object for view setup.
forest | BlockForest the raytracer operates on. |
storageID | Storage ID of the block data storage the raytracer operates on. |
globalBodyStorage | Pointer to the global body storage. |
ccdID | Block data ID for HashGrids. |
config | Config block for the raytracer. |
bodyToShadingParamsFunc | A function mapping a BodyID to ShadingParameters for this body. This can be used to customize the color and shading of bodies. |
isBodyVisibleFunc | A function which returns a boolean indicating if a given body should be visible in the final image. |
The config block has to contain image_x (int), image_y (int) and fov_vertical (real, in degrees). Additionally a vector of reals for each of cameraPosition, lookAt and the upVector for the view setup are required. Optional is antiAliasFactor (uint, usually between 1 and 4) for supersampling and backgroundColor (Vec3). For image output after raytracing, set image_output_directory (string); for local image output additionally set local_image_output_enabled (bool) to true. outputFilenameTimestepZeroPadding (int) sets the zero padding for timesteps in output filenames. For the lighting a config block within the Raytracer config block named Lighting has to be defined, information about its contents is in the Lighting class.
|
inlineprivate |
Converts a coordinate to an array index.
x | X component of the coordinate. |
y | Y component of the coordinate. |
void walberla::pe::raytracing::Raytracer::generateImage | ( | const size_t | timestep, |
WcTimingTree * | tt = nullptr |
||
) |
Does one raytracing step.
timestep | The timestep after which the raytracing starts. |
tt | Optional TimingTree. |
|
inline |
|
inline |
Returns the position of the camera in the global world frame.
Returns the position of the camera in the global world frame.
|
inlineprivate |
Computes the color for a certain intersection.
body | Intersected body. |
ray | Ray which intersected the body. |
t | Distance from eye to intersection point. |
n | Intersection normal at the intersection point. |
|
inline |
Returns whether the rendering of planes gets confined in the simulation domain.
|
inline |
Returns width of the timestep number in output filenames.
|
inline |
Returns the vertical field-of-view of the camera.
|
inline |
Returns the directory where the images will be saved in.
|
inline |
Returns true if image output to a file is enabled.
|
inline |
Returns true if local image output to a file is enabled.
|
inline |
Returns the point the camera looks at in the global world frame.
Returns the point the camera looks at in the global world frame, which also marks the center of the view plane.
|
private |
Generates the filename for output files.
base | String that precedes the timestep and rank info. |
timestep | Timestep this image is from. |
isGlobalImage | Whether this image is the fully stitched together one. |
|
inline |
Returns the horizontal amount of pixels of the generated image.
|
inline |
Returns the vertical amount of pixels of the generated image.
|
inline |
Returns the vector indicating the upwards direction of the camera.
Returns the vector indicating the upwards direction of the camera.
|
inlineprivate |
Checks if a plane should get rendered.
Checks if a plane should get rendered by comparing the planes normal and the ray direction. If the rays direction vectors projection on the planes normal is positive, the plane is considered invisible.
|
private |
|
private |
|
inline |
Set the background color of the scene.
color | New background color. |
|
inline |
Set if the rendering of planes should get confined to the simulation domain.
confinePlanesToDomain | True if the rendering of planes should get confined to the simulation domain. |
|
inline |
Set width of timestep number in output filenames.
width | Width of timestep part in a filename. |
|
inline |
Enable outputting images in the specified directory.
path | Directory for image output. |
|
inline |
Enable / disable outputting images in the specified directory.
enabled | Set to true / false to enable / disable image output. |
|
inline |
Enable / disable outputting local images in the specified directory.
enabled | Set to true / false to enable / disable image output. |
|
inline |
Set the algorithm to use while ray tracing.
algorithm | One of RAYTRACE_HASHGRIDS, RAYTRACE_NAIVE, RAYTRACE_COMPARE_BOTH, RAYTRACE_COMPARE_BOTH_STRICTLY (abort on errors). |
|
inline |
Set the algorithm to use while reducing.
reductionMethod | One of MPI_GATHER or MPI_REDUCE (latter one only works on MPI builds). |
void walberla::pe::raytracing::Raytracer::setupFilenameRankWidth_ | ( | ) |
Utility function for initializing the attribute filenameRankWidth.
void walberla::pe::raytracing::Raytracer::setupMPI_ | ( | ) |
Utility function for setting up the MPI datatype and operation.
void walberla::pe::raytracing::Raytracer::setupView_ | ( | ) |
Utility function for setting up the view plane and calculating required variables.
|
private |
Conflate the intersectionsBuffer of each process onto the root process using MPI_Gather.
intersections | Intersections to conflate. |
intersectionsBuffer | Buffer containing intersections. |
tt | Optional TimingTree. |
This function conflates the intersectionsBuffer of each process onto the root process using the MPI_Gather routine. It only sends information for hits.
|
private |
Conflate the intersectionsBuffer of each process onto the root process using MPI_Reduce.
intersectionsBuffer | Buffer containing all intersections for entire image (including non-hits). |
tt | Optional TimingTree. |
This function conflates the intersectionsBuffer of each process onto the root process using the MPI_Reduce routine. It requires sending intersection info structs for the entire image instead of only the ones of the hits.
|
inlineprivate |
Traces a ray in the global body storage and finds the closest ray-body intersection.
ray | Ray which is shot. |
body_closest | Reference where the closest body will be stored in. |
t_closest | Reference where the distance of the currently closest body is stored in, will get updated if closer intersection found. |
n_closest | Reference where the intersection normal will be stored in. |
|
inlineprivate |
Traces a ray in the global body storage and finds the closest ray-body intersection.
ray | Ray which is shot. |
body_closest | Reference where the closest body will be stored in. |
t_closest | Reference where the distance of the currently closest body is stored in, will get updated if closer intersection found. |
n_closest | Reference where the intersection normal will be stored in. |
|
inlineprivate |
Traces a ray naively and finds the closest ray-body intersection.
ray | Ray which is shot. |
body_closest | Reference where the closest body will be stored in. |
t_closest | Reference where the distance of the currently closest body is stored in, will get updated if closer intersection found. |
n_closest | Reference where the intersection normal will be stored in. |
|
private |
Writes the image of the current intersection buffer to a file in the image output directory.
intersectionsBuffer | Buffer with intersection info for each pixel. |
fileName | Name of the output file. |
|
private |
Writes the image of the current intersection buffer to a file in the image output directory.
intersectionsBuffer | Buffer with intersection info for each pixel. |
timestep | Timestep this image is from. |
isGlobalImage | Whether this image is the fully stitched together one. |
|
private |
Factor used for oversampling.
Should be between 1 (fast, but jagged edges) and 4 (16 times slower, very smooth edges).
|
private |
The aspect ratio of the generated image and viewing plane.
|
private |
Background color of the scene.
|
private |
|
private |
|
private |
Function which returns a ShadingParameters struct for the specified body.
|
private |
The position of the camera in the global world frame.
|
private |
The ID of the hash grids block data.
|
private |
Enable to render only the parts of planes within the simulation domain.
|
private |
The the distance from camera to viewing plane.
|
private |
Width of the mpi rank part in a filename.
|
private |
Width of the timestep number in output filenames.
Use e.g. 5 for ranges from 1 to 99 999: Will result in filenames like image_00001.png up to image_99999.png.
|
private |
The BlockForest the raytracer operates on.
|
private |
The vertical field-of-view of the camera.
|
private |
The global body storage the raytracer operates on.
|
private |
Path to the image output directory.
|
private |
Enable / disable writing images to file.
|
private |
Function which returns a boolean indicating if a given body should be visible in the final image.
|
private |
The lighting of the scene.
|
private |
Enable / disable writing images of the local process to file.
|
private |
The point the camera looks at in the global world frame, marks the center of the view plane.
|
private |
The normal vector of the viewing plane.
|
private |
The height of a pixel of the generated image in the viewing plane.
|
private |
The horizontal amount of pixels of the generated image.
|
private |
The vertical amount of pixels of the generated image.
|
private |
The width of a pixel of the generated image in the viewing plane.
|
private |
Algorithm to use while intersection testing.
|
private |
Reduction method used for assembling the image from all processes.
|
private |
The storage ID of the block data storage the raytracer operates on.
|
private |
The vector spanning the viewing plane in the "right direction".
|
private |
The vector indicating the upwards direction of the camera.
|
private |
The vector spanning the viewing plane in the "up direction".
|
private |
The viewing plane height in the world frame.
|
private |
The origin of the viewing plane.
|
private |
The viewing plane width in the world frame.