diff --git a/include/viennaray/rayParticle.hpp b/include/viennaray/rayParticle.hpp index 4a00617..ad8e0db 100644 --- a/include/viennaray/rayParticle.hpp +++ b/include/viennaray/rayParticle.hpp @@ -54,6 +54,10 @@ template class rayAbstractParticle { /// Set the power of the cosine source distribution for this particle. virtual NumericType getSourceDistributionPower() const = 0; + // Set the mean free path of the particle. If the mean free path is negative, + // the mean free path is infinite. + virtual NumericType getMeanFreePath() const = 0; + /// Set the number of required data vectors for this particle to /// collect data. If an empty vector is returned, no local data will be /// provided @@ -92,6 +96,7 @@ class rayParticle : public rayAbstractParticle { rayRNG &Rng) override { // collect data for this hit } virtual NumericType getSourceDistributionPower() const override { return 1.; } + virtual NumericType getMeanFreePath() const override { return -1.; } virtual std::vector getLocalDataLabels() const override { return {}; } diff --git a/include/viennaray/raySource.hpp b/include/viennaray/raySource.hpp index 6864a9c..8c95db0 100644 --- a/include/viennaray/raySource.hpp +++ b/include/viennaray/raySource.hpp @@ -3,17 +3,12 @@ #include #include -template class raySource { -protected: - raySource() = default; - ~raySource() = default; - +template class raySource { public: - Derived &derived() { return static_cast(*this); } - const Derived &derived() const { return static_cast(*this); } + virtual ~raySource() = default; - void fillRay(RTCRay &ray, const size_t idx, rayRNG &RngState) const { - derived().fillRay(ray, idx, RngState); - } - size_t getNumPoints() const { return derived().getNumPoints(); } + virtual rayPair> + getOriginAndDirection(const size_t idx, rayRNG &RngState) const = 0; + virtual size_t getNumPoints() const = 0; + virtual NumericType getInitialRayWeight(const size_t idx) const { return 1.; } }; diff --git a/include/viennaray/raySourceGrid.hpp b/include/viennaray/raySourceGrid.hpp index 93f6bf1..a370e39 100644 --- a/include/viennaray/raySourceGrid.hpp +++ b/include/viennaray/raySourceGrid.hpp @@ -3,7 +3,7 @@ #include template -class raySourceGrid : public raySource> { +class raySourceGrid : public raySource { public: raySourceGrid(std::vector> &sourceGrid, NumericType cosinePower, @@ -13,30 +13,15 @@ class raySourceGrid : public raySource> { secondDir_(traceSettings[2]), minMax_(traceSettings[3]), posNeg_(traceSettings[4]), ee_(((NumericType)2) / (cosinePower + 1)) {} - void fillRay(RTCRay &ray, const size_t idx, rayRNG &RngState) const { + rayPair> + getOriginAndDirection(const size_t idx, rayRNG &RngState) const override { auto origin = sourceGrid_[idx % numPoints_]; auto direction = getDirection(RngState); -#ifdef ARCH_X86 - reinterpret_cast<__m128 &>(ray) = - _mm_set_ps(1e-4f, (float)origin[2], (float)origin[1], (float)origin[0]); - - reinterpret_cast<__m128 &>(ray.dir_x) = _mm_set_ps( - 0.0f, (float)direction[2], (float)direction[1], (float)direction[0]); -#else - ray.org_x = (float)origin[0]; - ray.org_y = (float)origin[1]; - ray.org_z = (float)origin[2]; - ray.tnear = 1e-4f; - - ray.dir_x = (float)direction[0]; - ray.dir_y = (float)direction[1]; - ray.dir_z = (float)direction[2]; - ray.tnear = 0.0f; -#endif + return {origin, direction}; } - size_t getNumPoints() const { return numPoints_; } + size_t getNumPoints() const override { return numPoints_; } private: rayTriple getDirection(rayRNG &RngState) const { diff --git a/include/viennaray/raySourceRandom.hpp b/include/viennaray/raySourceRandom.hpp index 62c924c..572a0fb 100644 --- a/include/viennaray/raySourceRandom.hpp +++ b/include/viennaray/raySourceRandom.hpp @@ -3,7 +3,7 @@ #include template -class raySourceRandom : public raySource> { +class raySourceRandom : public raySource { using boundingBoxType = rayPair>; public: @@ -19,7 +19,8 @@ class raySourceRandom : public raySource> { customDirection_(customDirection), orthonormalBasis_(orthonormalBasis) { } - void fillRay(RTCRay &ray, const size_t idx, rayRNG &RngState) const { + rayPair> + getOriginAndDirection(const size_t idx, rayRNG &RngState) const override { auto origin = getOrigin(RngState); rayTriple direction; if (customDirection_) { @@ -28,26 +29,10 @@ class raySourceRandom : public raySource> { direction = getDirection(RngState); } -#ifdef ARCH_X86 - reinterpret_cast<__m128 &>(ray) = - _mm_set_ps(1e-4f, (float)origin[2], (float)origin[1], (float)origin[0]); - - reinterpret_cast<__m128 &>(ray.dir_x) = _mm_set_ps( - 0.0f, (float)direction[2], (float)direction[1], (float)direction[0]); -#else - ray.org_x = (float)origin[0]; - ray.org_y = (float)origin[1]; - ray.org_z = (float)origin[2]; - ray.tnear = 1e-4f; - - ray.dir_x = (float)direction[0]; - ray.dir_y = (float)direction[1]; - ray.dir_z = (float)direction[2]; - ray.time = 0.0f; -#endif + return {origin, direction}; } - size_t getNumPoints() const { return numPoints_; } + size_t getNumPoints() const override { return numPoints_; } private: rayTriple getOrigin(rayRNG &RngState) const { diff --git a/include/viennaray/rayTrace.hpp b/include/viennaray/rayTrace.hpp index 84019bf..6bf0fec 100644 --- a/include/viennaray/rayTrace.hpp +++ b/include/viennaray/rayTrace.hpp @@ -38,9 +38,10 @@ template class rayTrace { std::array, 3> orthonormalBasis; if (usePrimaryDirection_) orthonormalBasis = rayInternal::getOrthonormalBasis(primaryDirection_); - auto raySource = raySourceRandom( - boundingBox, pParticle_->getSourceDistributionPower(), traceSettings, - geometry_.getNumPoints(), usePrimaryDirection_, orthonormalBasis); + if (!pSource_) + pSource_ = std::make_unique>( + boundingBox, pParticle_->getSourceDistributionPower(), traceSettings, + geometry_.getNumPoints(), usePrimaryDirection_, orthonormalBasis); auto localDataLabels = pParticle_->getLocalDataLabels(); if (!localDataLabels.empty()) { @@ -52,10 +53,10 @@ template class rayTrace { } } - rayTraceKernel tracer(device_, geometry_, boundary, raySource, pParticle_, - dataLog_, numberOfRaysPerPoint_, numberOfRaysFixed_, - useRandomSeeds_, calcFlux_, lambda_, runNumber_++, - hitCounter_, RTInfo_); + rayTraceKernel tracer(device_, geometry_, boundary, std::move(pSource_), + pParticle_, dataLog_, numberOfRaysPerPoint_, + numberOfRaysFixed_, useRandomSeeds_, calcFlux_, + runNumber_++, hitCounter_, RTInfo_); tracer.setTracingData(&localData_, pGlobalData_); tracer.apply(); @@ -121,6 +122,16 @@ template class rayTrace { } } + /// Set a custom source for the ray tracing. Per default a random source is + /// set up. The source has to be a user defined object that has to interface + /// the raySource class. + void setSource(std::unique_ptr> source) { + pSource_ = std::move(source); + } + + /// Reset the source to the default random source. + void resetSource() { pSource_.reset(); } + /// Set the number of rays per geometry point. /// The total number of rays, that are traced, is the set number set here /// times the number of points in the geometry. @@ -151,8 +162,6 @@ template class rayTrace { usePrimaryDirection_ = true; } - void setMeanFreePath(const NumericType lambda) { lambda_ = lambda; } - /// Set whether random seeds for the internal random number generators /// should be used. void setUseRandomSeeds(const bool useRand) { useRandomSeeds_ = useRand; } @@ -371,21 +380,26 @@ template class rayTrace { private: RTCDevice device_; + rayGeometry geometry_; std::unique_ptr> pParticle_ = nullptr; + std::unique_ptr> pSource_ = nullptr; + size_t numberOfRaysPerPoint_ = 1000; size_t numberOfRaysFixed_ = 0; NumericType diskRadius_ = 0; NumericType gridDelta_ = 0; + rayBoundaryCondition boundaryConditions_[D] = {}; rayTraceDirection sourceDirection_ = rayTraceDirection::POS_Z; rayTriple primaryDirection_ = {0.}; + bool usePrimaryDirection_ = false; bool useRandomSeeds_ = false; size_t runNumber_ = 0; bool calcFlux_ = true; bool checkError_ = true; - NumericType lambda_ = -1.; + rayHitCounter hitCounter_; rayTracingData localData_; rayTracingData *pGlobalData_ = nullptr; diff --git a/include/viennaray/rayTraceKernel.hpp b/include/viennaray/rayTraceKernel.hpp index 251e32b..e38f474 100644 --- a/include/viennaray/rayTraceKernel.hpp +++ b/include/viennaray/rayTraceKernel.hpp @@ -9,25 +9,24 @@ #include #include -template -class rayTraceKernel { +template class rayTraceKernel { public: - rayTraceKernel(RTCDevice &device, rayGeometry &rtcGeometry, - rayBoundary &rtcBoundary, - raySource &source, + rayTraceKernel(RTCDevice &device, rayGeometry &geometry, + rayBoundary &boundary, + std::unique_ptr> source, std::unique_ptr> &particle, rayDataLog &dataLog, const size_t numRaysPerPoint, const size_t numRaysFixed, const bool useRandomSeed, - const bool calcFlux, const NumericType lambda, - const size_t runNumber, rayHitCounter &hitCounter, + const bool calcFlux, const size_t runNumber, + rayHitCounter &hitCounter, rayTraceInfo &traceInfo) - : device_(device), geometry_(rtcGeometry), boundary_(rtcBoundary), - source_(source), pParticle_(particle->clone()), - numRays_(numRaysFixed == 0 ? source.getNumPoints() * numRaysPerPoint + : device_(device), geometry_(geometry), boundary_(boundary), + pSource_(std::move(source)), pParticle_(particle->clone()), + numRays_(numRaysFixed == 0 ? pSource_->getNumPoints() * numRaysPerPoint : numRaysFixed), useRandomSeeds_(useRandomSeed), runNumber_(runNumber), - calcFlux_(calcFlux), lambda_(lambda), hitCounter_(hitCounter), - traceInfo_(traceInfo), dataLog_(dataLog) { + calcFlux_(calcFlux), hitCounter_(hitCounter), traceInfo_(traceInfo), + dataLog_(dataLog) { assert(rtcGetDeviceProperty(device_, RTC_DEVICE_PROPERTY_VERSION) >= 30601 && "Error: The minimum version of Embree is 3.6.1"); @@ -42,13 +41,12 @@ class rayTraceKernel { // Selecting higher build quality results in better rendering performance // but slower scene commit times. The default build quality for a scene is // RTC_BUILD_QUALITY_MEDIUM. - auto bbquality = RTC_BUILD_QUALITY_HIGH; - rtcSetSceneBuildQuality(rtcScene, bbquality); + rtcSetSceneBuildQuality(rtcScene, RTC_BUILD_QUALITY_HIGH); auto rtcGeometry = geometry_.getRTCGeometry(); auto rtcBoundary = boundary_.getRTCGeometry(); - auto boundaryID = rtcAttachGeometry(rtcScene, rtcBoundary); - auto geometryID = rtcAttachGeometry(rtcScene, rtcGeometry); + auto const boundaryID = rtcAttachGeometry(rtcScene, rtcBoundary); + auto const geometryID = rtcAttachGeometry(rtcScene, rtcGeometry); assert(rtcGetDeviceError(device_) == RTC_ERROR_NONE && "Embree device error"); @@ -56,6 +54,7 @@ class rayTraceKernel { size_t nongeohitc = 0; size_t totaltraces = 0; size_t particlehitc = 0; + auto const lambda = pParticle_->getMeanFreePath(); // thread local data storage const int numThreads = omp_get_max_threads(); @@ -108,9 +107,6 @@ class rayTraceKernel { auto &myHitCounter = threadLocalHitCounter[threadID]; auto &myDataLog = threadLocalDataLog[threadID]; - // probabilistic weight - const NumericType initialRayWeight = 1.; - #if VIENNARAY_EMBREE_VERSION < 4 auto rtcContext = RTCIntersectContext{}; rtcInitIntersectContext(&rtcContext); @@ -126,9 +122,15 @@ class rayTraceKernel { particle->initNew(RngState); particle->logData(myDataLog); + + // probabilistic weight + const NumericType initialRayWeight = pSource_->getInitialRayWeight(idx); NumericType rayWeight = initialRayWeight; - source_.fillRay(rayHit.ray, idx, RngState); // fills also tnear + auto originAndDirection = + pSource_->getOriginAndDirection(idx, RngState); + rayInternal::fillRay(rayHit.ray, originAndDirection[0], + originAndDirection[1]); #ifdef VIENNARAY_USE_RAY_MASKING rayHit.ray.mask = -1; @@ -164,20 +166,17 @@ class rayTraceKernel { break; } - if (lambda_ > 0.) { + if (lambda > 0.) { std::uniform_real_distribution dist(0., 1.); NumericType scatterProbability = - 1 - std::exp(-rayHit.ray.tfar / lambda_); + 1 - std::exp(-rayHit.ray.tfar / lambda); auto rndm = dist(RngState); if (rndm < scatterProbability) { const auto &ray = rayHit.ray; - const rayInternal::rtcNumericType xx = - ray.org_x + ray.dir_x * ray.tfar * rndm; - const rayInternal::rtcNumericType yy = - ray.org_y + ray.dir_y * ray.tfar * rndm; - const rayInternal::rtcNumericType zz = - ray.org_z + ray.dir_z * ray.tfar * rndm; + std::array origin = { + ray.org_x + ray.dir_x * rndm, ray.org_y + ray.dir_y * rndm, + ray.org_z + ray.dir_z * rndm}; std::array direction{0, 0, 0}; for (int i = 0; i < D; ++i) { @@ -186,22 +185,8 @@ class rayTraceKernel { rayInternal::Normalize(direction); // Update ray direction and origin -#ifdef ARCH_X86 - reinterpret_cast<__m128 &>(rayHit.ray) = - _mm_set_ps(1e-4f, zz, yy, xx); - reinterpret_cast<__m128 &>(rayHit.ray.dir_x) = - _mm_set_ps(0.0f, direction[2], direction[1], direction[0]); -#else - rayHit.ray.org_x = xx; - rayHit.ray.org_y = yy; - rayHit.ray.org_z = zz; - rayHit.ray.tnear = 1e-4f; - - rayHit.ray.dir_x = direction[0]; - rayHit.ray.dir_y = direction[1]; - rayHit.ray.dir_z = direction[2]; - rayHit.ray.time = 0.0f; -#endif + rayInternal::fillRay(rayHit.ray, origin, direction); + particlehitc++; reflect = true; continue; @@ -216,12 +201,10 @@ class rayTraceKernel { // Calculate point of impact const auto &ray = rayHit.ray; - const rayInternal::rtcNumericType xx = - ray.org_x + ray.dir_x * ray.tfar; - const rayInternal::rtcNumericType yy = - ray.org_y + ray.dir_y * ray.tfar; - const rayInternal::rtcNumericType zz = - ray.org_z + ray.dir_z * ray.tfar; + const std::array hitPoint = { + ray.org_x + ray.dir_x * ray.tfar, + ray.org_y + ray.dir_y * ray.tfar, + ray.org_z + ray.dir_z * ray.tfar}; /* -------- Hit from back -------- */ const auto rayDir = @@ -240,11 +223,11 @@ class rayTraceKernel { reflect = true; #ifdef ARCH_X86 reinterpret_cast<__m128 &>(rayHit.ray) = - _mm_set_ps(1e-4f, zz, yy, xx); + _mm_set_ps(1e-4f, hitPoint[2], hitPoint[1], hitPoint[0]); #else - rayHit.ray.org_x = xx; - rayHit.ray.org_y = yy; - rayHit.ray.org_z = zz; + rayHit.ray.org_x = hitPoint[0]; + rayHit.ray.org_y = hitPoint[1]; + rayHit.ray.org_z = hitPoint[2]; rayHit.ray.tnear = 1e-4f; #endif // keep ray direction as it is @@ -265,7 +248,7 @@ class rayTraceKernel { const auto &diskOrigin = *reinterpret_cast< rayTriple const *>(&disk); impactDistances.push_back( - rayInternal::Distance({xx, yy, zz}, diskOrigin) + + rayInternal::Distance(hitPoint, diskOrigin) + 1e-6f); // add eps to avoid division by 0 } #endif @@ -332,27 +315,8 @@ class rayTraceKernel { } // Update ray direction and origin -#ifdef ARCH_X86 - reinterpret_cast<__m128 &>(rayHit.ray) = - _mm_set_ps(1e-4f, zz, yy, xx); - reinterpret_cast<__m128 &>(rayHit.ray.dir_x) = _mm_set_ps( - 0.0f, (rayInternal::rtcNumericType)stickingDirection.second[2], - (rayInternal::rtcNumericType)stickingDirection.second[1], - (rayInternal::rtcNumericType)stickingDirection.second[0]); -#else - rayHit.ray.org_x = xx; - rayHit.ray.org_y = yy; - rayHit.ray.org_z = zz; - rayHit.ray.tnear = 1e-4f; - - rayHit.ray.dir_x = - (rayInternal::rtcNumericType)stickingDirection.second[0]; - rayHit.ray.dir_y = - (rayInternal::rtcNumericType)stickingDirection.second[1]; - rayHit.ray.dir_z = - (rayInternal::rtcNumericType)stickingDirection.second[2]; - rayHit.ray.time = 0.0f; -#endif + rayInternal::fillRay(rayHit.ray, hitPoint, stickingDirection.second); + } while (reflect); } // end ray tracing for loop @@ -636,15 +600,13 @@ class rayTraceKernel { rayGeometry &geometry_; rayBoundary const &boundary_; - raySource const &source_; - - std::unique_ptr> const pParticle_ = nullptr; + std::unique_ptr> const pSource_; + std::unique_ptr> const pParticle_; const long long numRays_; const bool useRandomSeeds_; const size_t runNumber_; const bool calcFlux_; - const NumericType lambda_; rayTracingData *pLocalData_ = nullptr; rayTracingData const *pGlobalData_ = nullptr; diff --git a/include/viennaray/rayUtil.hpp b/include/viennaray/rayUtil.hpp index 53ee9ec..176db60 100644 --- a/include/viennaray/rayUtil.hpp +++ b/include/viennaray/rayUtil.hpp @@ -244,8 +244,8 @@ void adjustBoundingBox(rayPair> &bdBox, [[nodiscard]] inline std::array getTraceSettings(rayTraceDirection sourceDir) { - // Trace Settings: sourceDir, boundaryDir1, boundaryDir2, minMax bdBox source, - // posNeg dir + // Trace Settings: sourceDir, boundaryDir1, boundaryDir2, minMax bdBox + // source, posNeg dir std::array set{0, 0, 0, 0, 0}; switch (sourceDir) { case rayTraceDirection::POS_X: { @@ -300,6 +300,53 @@ getTraceSettings(rayTraceDirection sourceDir) { return set; } + +template +void fillRay(RTCRay &ray, const rayTriple &origin, + const rayTriple &direction, const float tnear = 1e-4f, + const float time = 0.0f) { +#ifdef ARCH_X86 + reinterpret_cast<__m128 &>(ray) = + _mm_set_ps(tnear, (float)origin[2], (float)origin[1], (float)origin[0]); + + reinterpret_cast<__m128 &>(ray.dir_x) = _mm_set_ps( + time, (float)direction[2], (float)direction[1], (float)direction[0]); +#else + ray.org_x = (float)origin[0]; + ray.org_y = (float)origin[1]; + ray.org_z = (float)origin[2]; + ray.tnear = tnear; + + ray.dir_x = (float)direction[0]; + ray.dir_y = (float)direction[1]; + ray.dir_z = (float)direction[2]; + ray.time = time; +#endif +} + +template <> +void fillRay(RTCRay &ray, const rayTriple &origin, + const rayTriple &direction, const float tnear, + const float time) { +#ifdef ARCH_X86 + reinterpret_cast<__m128 &>(ray) = + _mm_set_ps(tnear, origin[2], origin[1], origin[0]); + + reinterpret_cast<__m128 &>(ray.dir_x) = + _mm_set_ps(time, direction[2], direction[1], direction[0]); +#else + ray.org_x = origin[0]; + ray.org_y = origin[1]; + ray.org_z = origin[2]; + ray.tnear = tnear; + + ray.dir_x = direction[0]; + ray.dir_y = direction[1]; + ray.dir_z = direction[2]; + ray.time = time; +#endif +} + /* ------------------------------------------------------ */ template @@ -336,8 +383,8 @@ getOrthonormalBasis(const rayTriple &vec) { rayTriple candidate0{rr[0][2], rr[0][2], -(rr[0][0] + rr[0][1])}; rayTriple candidate1{rr[0][1], -(rr[0][0] + rr[0][2]), rr[0][1]}; rayTriple candidate2{-(rr[0][1] + rr[0][2]), rr[0][0], rr[0][0]}; - // We choose the candidate which maximizes the sum of its components, because - // we want to avoid numeric errors and that the result is (0, 0, 0). + // We choose the candidate which maximizes the sum of its components, + // because we want to avoid numeric errors and that the result is (0, 0, 0). std::array, 3> cc = {candidate0, candidate1, candidate2}; auto sumFun = [](const rayTriple &oo) { diff --git a/tests/createRay/createRay.cpp b/tests/createRay/createRay.cpp index 5dbe49b..de057ae 100644 --- a/tests/createRay/createRay.cpp +++ b/tests/createRay/createRay.cpp @@ -47,7 +47,9 @@ int main() { alignas(128) auto rayhit = RTCRayHit{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; for (size_t i = 0; i < 10; ++i) { - source.fillRay(rayhit.ray, 0, rngstate1); + auto originAndDirection = source.getOriginAndDirection(0, rngstate1); + rayInternal::fillRay(rayhit.ray, originAndDirection[0], + originAndDirection[1]); RAYTEST_ASSERT(rayhit.ray.dir_z < 0.) RAYTEST_ASSERT_ISCLOSE(rayhit.ray.org_z, (1. + 2 * gridDelta), eps) } @@ -67,7 +69,9 @@ int main() { alignas(128) auto rayhit = RTCRayHit{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; for (size_t i = 0; i < 10; ++i) { - source.fillRay(rayhit.ray, 0, rngstate1); + auto originAndDirection = source.getOriginAndDirection(0, rngstate1); + rayInternal::fillRay(rayhit.ray, originAndDirection[0], + originAndDirection[1]); RAYTEST_ASSERT(rayhit.ray.dir_z > 0.) RAYTEST_ASSERT_ISCLOSE(rayhit.ray.org_z, (-1. - 2 * gridDelta), eps) } @@ -87,7 +91,9 @@ int main() { alignas(128) auto rayhit = RTCRayHit{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; for (size_t i = 0; i < 10; ++i) { - source.fillRay(rayhit.ray, 0, rngstate1); + auto originAndDirection = source.getOriginAndDirection(0, rngstate1); + rayInternal::fillRay(rayhit.ray, originAndDirection[0], + originAndDirection[1]); RAYTEST_ASSERT(rayhit.ray.dir_x < 0.) RAYTEST_ASSERT_ISCLOSE(rayhit.ray.org_x, (1. + 2 * gridDelta), eps) } @@ -107,7 +113,9 @@ int main() { alignas(128) auto rayhit = RTCRayHit{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; for (size_t i = 0; i < 10; ++i) { - source.fillRay(rayhit.ray, 0, rngstate1); + auto originAndDirection = source.getOriginAndDirection(0, rngstate1); + rayInternal::fillRay(rayhit.ray, originAndDirection[0], + originAndDirection[1]); RAYTEST_ASSERT(rayhit.ray.dir_x > 0.) RAYTEST_ASSERT_ISCLOSE(rayhit.ray.org_x, (-1. - 2 * gridDelta), eps) } @@ -127,7 +135,9 @@ int main() { alignas(128) auto rayhit = RTCRayHit{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; for (size_t i = 0; i < 10; ++i) { - source.fillRay(rayhit.ray, 0, rngstate1); + auto originAndDirection = source.getOriginAndDirection(0, rngstate1); + rayInternal::fillRay(rayhit.ray, originAndDirection[0], + originAndDirection[1]); RAYTEST_ASSERT(rayhit.ray.dir_y < 0.) RAYTEST_ASSERT_ISCLOSE(rayhit.ray.org_y, (1. + 2 * gridDelta), eps) } @@ -147,7 +157,9 @@ int main() { alignas(128) auto rayhit = RTCRayHit{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; for (size_t i = 0; i < 10; ++i) { - source.fillRay(rayhit.ray, 0, rngstate1); + auto originAndDirection = source.getOriginAndDirection(0, rngstate1); + rayInternal::fillRay(rayhit.ray, originAndDirection[0], + originAndDirection[1]); RAYTEST_ASSERT(rayhit.ray.dir_y > 0.) RAYTEST_ASSERT_ISCLOSE(rayhit.ray.org_y, (-1. - 2 * gridDelta), eps) } @@ -170,7 +182,9 @@ int main() { alignas(128) auto rayhit = RTCRayHit{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; for (size_t i = 0; i < 10; ++i) { - source.fillRay(rayhit.ray, 0, rngstate1); + auto originAndDirection = source.getOriginAndDirection(0, rngstate1); + rayInternal::fillRay(rayhit.ray, originAndDirection[0], + originAndDirection[1]); RAYTEST_ASSERT(rayhit.ray.dir_z < 0.) RAYTEST_ASSERT_ISCLOSE(rayhit.ray.org_z, (1. + 2 * gridDelta), eps) } diff --git a/tests/createSourceGrid/createSourceGrid.cpp b/tests/createSourceGrid/createSourceGrid.cpp index 0dd2527..d0598ba 100644 --- a/tests/createSourceGrid/createSourceGrid.cpp +++ b/tests/createSourceGrid/createSourceGrid.cpp @@ -34,7 +34,9 @@ int main() { alignas(128) auto rayhit = RTCRayHit{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; for (size_t i = 0; i < numGridPoints; ++i) { - source.fillRay(rayhit.ray, i, rngstate); + auto originAndDirection = source.getOriginAndDirection(i, rngstate); + rayInternal::fillRay(rayhit.ray, originAndDirection[0], + originAndDirection[1]); RAYTEST_ASSERT(rayhit.ray.dir_z < 0.) RAYTEST_ASSERT_ISCLOSE(rayhit.ray.org_z, (1. + 2 * gridDelta), eps) diff --git a/tests/diskAreas/diskAreas.cpp b/tests/diskAreas/diskAreas.cpp index 178e44d..f668ad2 100644 --- a/tests/diskAreas/diskAreas.cpp +++ b/tests/diskAreas/diskAreas.cpp @@ -39,7 +39,7 @@ int main() { auto boundary = rayBoundary(device, boundingBox, boundaryConds, traceSettings); std::array, 3> orthoBasis; - auto raySource = raySourceRandom( + auto raySource = std::make_unique>( boundingBox, 1., traceSettings, geometry.getNumPoints(), false, orthoBasis); @@ -48,8 +48,9 @@ int main() { rayDataLog log; rayTraceInfo info; - auto tracer = rayTraceKernel(device, geometry, boundary, raySource, cp, log, - 1, 0, false, true, 0.f, 0, hitCounter, info); + rayTraceKernel tracer(device, geometry, boundary, + std::move(raySource), cp, log, 1, 0, + false, true, 0, hitCounter, info); tracer.setTracingData(&localData, &globalData); tracer.apply(); auto diskAreas = hitCounter.getDiskAreas(); diff --git a/tests/traceInterface/traceInterface.cpp b/tests/traceInterface/traceInterface.cpp index 90aac56..5b2c2e9 100644 --- a/tests/traceInterface/traceInterface.cpp +++ b/tests/traceInterface/traceInterface.cpp @@ -2,6 +2,21 @@ #include #include +template +class MySource : public raySource { +public: + MySource() {} + + rayPair> + getOriginAndDirection(const size_t idx, rayRNG &RngState) const override { + std::array origin = {0., 0., 0.}; + std::array direction = {0., 0., 1.}; + return {origin, direction}; + } + + size_t getNumPoints() const override { return 0; } +}; + int main() { constexpr int D = 3; using NumericType = float; @@ -29,6 +44,11 @@ int main() { rayTracer.setNumberOfRaysPerPoint(10); rayTracer.setUseRandomSeeds(false); rayTracer.setMaterialIds(matIds); + + auto mySource = std::make_unique>(); + rayTracer.setSource(std::move(mySource)); + rayTracer.resetSource(); + rayTracer.apply(); auto info = rayTracer.getRayTraceInfo();