DHART
Loading...
Searching...
No Matches
DHARTAPI.RayTracing.EmbreeBVH Class Reference

A Bounding Volume Hierarchy for the EmbreeRaytracer. More...

+ Inheritance diagram for DHARTAPI.RayTracing.EmbreeBVH:

Public Member Functions

 EmbreeBVH (MeshInfo MI, bool use_precise=false)
 Generate a BVH for an instance of MeshInfo. More...
 
 EmbreeBVH (MeshInfo[] MI)
 Construct a BVH from an array of meshes. More...
 
void AddMesh (MeshInfo MI)
 Add a new mesh to the BVH. More...
 
void AddMesh (MeshInfo[] MI)
 Multiple new meshes to the BVH. More...
 
- Public Member Functions inherited from DHARTAPI.NativeUtils.NativeObject
void UpdatePressure (int new_pressure)
 Update the pressure of this object.
 

Protected Member Functions

override bool ReleaseHandle ()
 Free the native memory managed by this class. More...
 

Additional Inherited Members

- Public Attributes inherited from DHARTAPI.NativeUtils.NativeObject
int pressure
 the size of the object pointed to in unmanaged memory in bytes. Used to exert pressure on the GC. More...
 
- Properties inherited from DHARTAPI.NativeUtils.NativeObject
override bool IsInvalid [get]
 There is no way to invalidate this class without destroying it, so will always return false.
 

Detailed Description

A Bounding Volume Hierarchy for the EmbreeRaytracer.

Upon calling the constructor for this class, a Bounding Volume Hierarchy is generated for the RayTracing.EmbreeRaytracer. Without this structure, the raytracer cannot be used.

Remarks
A more detailed description of Embree's BVH is available in intel's paper: Embree: A Kernel Framework for Efficient CPU Ray Tracing http://cseweb.ucsd.edu/~ravir/274/15/papers/a143-wald.pdf.
See also
EmbreeRaytracer for functions to use this BVH for ray intersections.

Constructor & Destructor Documentation

◆ EmbreeBVH() [1/2]

DHARTAPI.RayTracing.EmbreeBVH.EmbreeBVH ( MeshInfo  MI,
bool  use_precise = false 
)

Generate a BVH for an instance of MeshInfo.

Parameters
MIMesh to generate the BVH from.
use_preciseIncrease the accuracy of all ray intersections at the cost of performance.
Exceptions
ExceptionEmbree failed to create a BVH for the given mesh.
Example
// Load an OBJ from a filepath into a new meshinfo instance
string good_mesh_path = "ExampleModels/plane.obj";
// Construct a BVH from the mesh
EmbreeBVH BVH = new EmbreeBVH(Mesh);
A collection of rotations that are frequently useful in DHARTAPI.
Definition: CommonRotations.cs:7
static Vector3D Yup_To_Zup
Will rotate a mesh from Y-Up to Z-Up.
Definition: CommonRotations.cs:16
A collection of vertices and indices representing geometry.
Definition: MeshInfo.cs:50
Load mesh geometry from OBJ files on disk.
Definition: OBJLoader.cs:26
static MeshInfo LoadOBJ(string path, float xrot=0, float yrot=0, float zrot=0)
Load an obj from the OBJ file at the given filepath.
Definition: OBJLoader.cs:50
A Bounding Volume Hierarchy for the EmbreeRaytracer.
Definition: EmbreeBVH.cs:31

◆ EmbreeBVH() [2/2]

DHARTAPI.RayTracing.EmbreeBVH.EmbreeBVH ( MeshInfo[]  MI)

Construct a BVH from an array of meshes.

\params MI Meshes to build the BVH from.

References DHARTAPI.NativeUtils.NativeObject.pressure, and DHARTAPI.NativeUtils.NativeObject.UpdatePressure().

Member Function Documentation

◆ AddMesh() [1/2]

void DHARTAPI.RayTracing.EmbreeBVH.AddMesh ( MeshInfo  MI)

Add a new mesh to the BVH.

Parameters
MIMeshinfo to add to this bvh. The ID of this MeshInfo will be updated if that ID is already occupied by another mesh in the BVH.
Example
Demonstrating that the BVH changes after the addition of new meshes.
// Load a lot of submeshes from sponza
var MeshInfos = OBJLoader.LoadOBJSubmeshes("ExampleModels/sponza.obj", GROUP_METHOD.BY_GROUP);
var Plane = OBJLoader.LoadOBJ("ExampleModels/plane.obj");
// Construct a BVH from the plane
EmbreeBVH bvh = new EmbreeBVH(Plane);
// Cast rays and print the results
Debug.WriteLine("--- Just Plane---");
Vector3D[] origins = { new Vector3D(1, 1, 1), new Vector3D(1, 1, 1) };
Vector3D[] directions = { new Vector3D(0, 0, -1), new Vector3D(0, -1, 0) };
bool[] results = EmbreeRaytracer.IntersectOccluded(bvh, origins, directions);
string out_str = directions[0].ToString() + (results[0] ? "Intersected" : "Did not Intersect") + "\n";
out_str += directions[1].ToString() + (results[1] ? "Intersected" : "Did not Intersect");
Debug.WriteLine(out_str);
// Add meshes to the BVH
bvh.AddMesh(MeshInfos);
// Cast rays again and see if the second ray connects
Debug.WriteLine("--- After Addition---");
bool[] post_addition_results = EmbreeRaytracer.IntersectOccluded(bvh, origins, directions);
string post_addition_out_str = directions[0].ToString() + (post_addition_results[0] ? "Intersected" : "Did not Intersect") + "\n";
post_addition_out_str += directions[1].ToString() + (post_addition_results[1] ? "Intersected" : "Did not Intersect");
Debug.WriteLine(post_addition_out_str);
static MeshInfo[] LoadOBJSubmeshes(string path, GROUP_METHOD gm, float xrot=0, float yrot=0, float zrot=0)
Load an obj from the OBJ file at the given filepath.
Definition: OBJLoader.cs:86
void AddMesh(MeshInfo MI)
Add a new mesh to the BVH.
Definition: EmbreeBVH.cs:118
GROUP_METHOD
Methods for seperating meshes when loading from OBJ.
Definition: OBJLoader.cs:12
A three dimensional vector with built in utility functions.
Definition: CommonTypes.cs:40
override string ToString()
Construct a string representation of this vector's x, y, and z coordinates.
Definition: CommonTypes.cs:111
--- Just Plane---
(0, 0, -1)Did not Intersect
(0, -1, 0)Intersected
--- After Addition---
(0, 0, -1)Intersected
(0, -1, 0)Intersected

References DHARTAPI.NativeUtils.NativeObject.pressure, and DHARTAPI.NativeUtils.NativeObject.UpdatePressure().

◆ AddMesh() [2/2]

void DHARTAPI.RayTracing.EmbreeBVH.AddMesh ( MeshInfo[]  MI)

Multiple new meshes to the BVH.

Parameters
MIMeshinfo to add to this bvh. The ID of this MeshInfo will be updated if that ID is already occupied by another mesh in the BVH.
Example
Demonstrating that the BVH changes after the addition of new meshes.
// Load a lot of submeshes from sponza
var MeshInfos = OBJLoader.LoadOBJSubmeshes("ExampleModels/sponza.obj", GROUP_METHOD.BY_GROUP);
var Plane = OBJLoader.LoadOBJ("ExampleModels/plane.obj");
// Construct a BVH from the plane
EmbreeBVH bvh = new EmbreeBVH(Plane);
// Cast rays and print the results
Debug.WriteLine("--- Just Plane---");
Vector3D[] origins = { new Vector3D(1, 1, 1), new Vector3D(1, 1, 1) };
Vector3D[] directions = { new Vector3D(0, 0, -1), new Vector3D(0, -1, 0) };
bool[] results = EmbreeRaytracer.IntersectOccluded(bvh, origins, directions);
string out_str = directions[0].ToString() + (results[0] ? "Intersected" : "Did not Intersect") + "\n";
out_str += directions[1].ToString() + (results[1] ? "Intersected" : "Did not Intersect");
Debug.WriteLine(out_str);
// Add meshes to the BVH
bvh.AddMesh(MeshInfos);
// Cast rays again and see if the second ray connects
Debug.WriteLine("--- After Addition---");
bool[] post_addition_results = EmbreeRaytracer.IntersectOccluded(bvh, origins, directions);
string post_addition_out_str = directions[0].ToString() + (post_addition_results[0] ? "Intersected" : "Did not Intersect") + "\n";
post_addition_out_str += directions[1].ToString() + (post_addition_results[1] ? "Intersected" : "Did not Intersect");
Debug.WriteLine(post_addition_out_str);
--- Just Plane---
(0, 0, -1)Did not Intersect
(0, -1, 0)Intersected
--- After Addition---
(0, 0, -1)Intersected
(0, -1, 0)Intersected

References DHARTAPI.NativeUtils.NativeObject.pressure, and DHARTAPI.NativeUtils.NativeObject.UpdatePressure().

◆ ReleaseHandle()

override bool DHARTAPI.RayTracing.EmbreeBVH.ReleaseHandle ( )
protected

Free the native memory managed by this class.

Note
the garbage collector will handle this automatically
Warning
Do not attempt to use this class after freeing it!
Returns
True. This is guaranteed to execute properly.

The documentation for this class was generated from the following file: