Skip to content

Commit

Permalink
Ensure backside of boundary is opaque to rays (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
tobre1 authored May 15, 2024
1 parent 67dfefc commit df6adb9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
17 changes: 15 additions & 2 deletions include/viennaray/rayBoundary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ template <typename NumericType, int D> class rayBoundary {
void processHit(RTCRayHit &rayHit, bool &reflect) const {
const auto primID = rayHit.hit.primID;

// Ray hits backside of boundary
const auto rayDir = rayTriple<NumericType>{
rayHit.ray.dir_x, rayHit.ray.dir_y, rayHit.ray.dir_z};
const auto boundaryNormal = rayTriple<NumericType>{
rayHit.hit.Ng_x, rayHit.hit.Ng_y, rayHit.hit.Ng_z};
if (rayInternal::DotProduct(rayDir, boundaryNormal) > 0) {
// let ray pass through
reflect = true;
const auto impactCoords = getNewOrigin(rayHit.ray);
assignRayCoords(rayHit, impactCoords);
return;
}

if constexpr (D == 2) {
assert((primID == 0 || primID == 1 || primID == 2 || primID == 3) &&
"Assumption");
Expand Down Expand Up @@ -111,8 +124,8 @@ template <typename NumericType, int D> class rayBoundary {

void releaseGeometry() {
// Attention:
// This function must not be called when the RTCGeometry reference count is
// > 1 Doing so leads to leaked memory buffers
// This function must not be called when the RTCGeometry reference count
// is > 1 Doing so leads to leaked memory buffers
if (pTriangleBuffer_ == nullptr || pVertexBuffer_ == nullptr ||
pRtcBoundary_ == nullptr) {
return;
Expand Down
10 changes: 5 additions & 5 deletions include/viennaray/rayTrace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ template <class NumericType, int D> class rayTrace {
if (usePrimaryDirection_)
orthonormalBasis = rayInternal::getOrthonormalBasis(primaryDirection_);
if (!pSource_)
pSource_ = std::make_unique<raySourceRandom<NumericType, D>>(
pSource_ = std::make_shared<raySourceRandom<NumericType, D>>(
boundingBox, pParticle_->getSourceDistributionPower(), traceSettings,
geometry_.getNumPoints(), usePrimaryDirection_, orthonormalBasis);

Expand All @@ -53,10 +53,10 @@ template <class NumericType, int D> class rayTrace {
}
}

rayTraceKernel tracer(device_, geometry_, boundary, std::move(pSource_),
pParticle_, dataLog_, numberOfRaysPerPoint_,
numberOfRaysFixed_, useRandomSeeds_, calcFlux_,
runNumber_++, hitCounter_, RTInfo_);
rayTraceKernel tracer(device_, geometry_, boundary, pSource_, pParticle_,
dataLog_, numberOfRaysPerPoint_, numberOfRaysFixed_,
useRandomSeeds_, calcFlux_, runNumber_++, hitCounter_,
RTInfo_);
tracer.setTracingData(&localData_, pGlobalData_);
tracer.apply();

Expand Down

0 comments on commit df6adb9

Please sign in to comment.