Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure backside of boundary is opaque to rays #57

Merged
merged 1 commit into from
May 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions include/viennaray/rayBoundary.hpp
Original file line number Diff line number Diff line change
@@ -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");
@@ -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;
10 changes: 5 additions & 5 deletions include/viennaray/rayTrace.hpp
Original file line number Diff line number Diff line change
@@ -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);

@@ -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();