Skip to content

Commit

Permalink
Adding an XDG creation method to hide mesh implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
pshriwise committed Jan 17, 2024
1 parent 77cd3a6 commit ec1f26e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
7 changes: 5 additions & 2 deletions include/xdg/xdg.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class XDG {
XDG(std::shared_ptr<MeshManager> mesh_manager) :
mesh_manager_(mesh_manager) {}

// factor method that allows for specification of a backend mesh library
static std::shared_ptr<XDG> create(MeshLibrary library);

// Methods
void prepare_raytracer();

Expand Down Expand Up @@ -69,8 +72,8 @@ Direction surface_normal(MeshID surface,
return ray_tracing_interface_;
}

const MeshManager* mesh_manager() const {
return mesh_manager_.get();
const std::shared_ptr<MeshManager>& mesh_manager() const {
return mesh_manager_;
}

// Private methods
Expand Down
1 change: 0 additions & 1 deletion src/ray_tracing_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ void error(void* dum, RTCError code, const char* str) {
fatal_error("Embree error: {}", str);
}


RayTracer::RayTracer()
{
device_ = rtcNewDevice(nullptr);
Expand Down
19 changes: 19 additions & 0 deletions src/xdg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

#include "xdg/xdg.h"

// mesh manager concrete implementations
#include "xdg/moab/mesh_manager.h"

#include "xdg/constants.h"
#include "xdg/geometry/measure.h"
namespace xdg {
Expand All @@ -14,6 +17,22 @@ void XDG::prepare_raytracer()
}
}


std::shared_ptr<XDG> XDG::create(MeshLibrary library)
{
std::shared_ptr<XDG> xdg = std::make_shared<XDG>();

switch (library)
{
case MeshLibrary::MOAB:
xdg->set_mesh_manager_interface(std::make_shared<MOABMeshManager>());
break;
default:
break;
}
return xdg;
}

MeshID XDG::find_volume(const Position& point,
const Direction& direction) const
{
Expand Down
13 changes: 9 additions & 4 deletions tests/test_moab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ TEST_CASE("Test BVH Build")

TEST_CASE("Test Ray Fire MOAB")
{
std::shared_ptr<MeshManager> mesh_manager = std::make_shared<MOABMeshManager>();

std::shared_ptr<XDG> xdg = XDG::create(MeshLibrary::MOAB);
REQUIRE(xdg->mesh_manager()->mesh_library() == MeshLibrary::MOAB);
const auto& mesh_manager = xdg->mesh_manager();
mesh_manager->load_file("cube.h5m");
mesh_manager->init();
REQUIRE(mesh_manager->mesh_library() == MeshLibrary::MOAB);
std::shared_ptr<XDG> xdg = std::make_shared<XDG>(mesh_manager);
xdg->prepare_raytracer();


MeshID volume = mesh_manager->volumes()[0];

Position origin {0.0, 0.0, 0.0};
Expand All @@ -98,4 +98,9 @@ TEST_CASE("Test Ray Fire MOAB")
origin = {-10.0, 0.0, 0.0};
xdg->ray_fire(volume, origin, direction, intersection_distance);
REQUIRE_THAT(intersection_distance, Catch::Matchers::WithinAbs(15.0, 1e-6));
}

TEST_CASE("TEST XDG Factory Method")
{

}

0 comments on commit ec1f26e

Please sign in to comment.