32#include <memory_resource>
35#include <unordered_map>
52 using SPMap = std::pmr::unordered_map<SpecularPathId, SpecularPathData<Vec3>>;
53 using SPEntry = std::pair<SpecularPathId, SpecularPathData<Vec3>>;
54 using SPArray = std::pmr::vector<SPEntry>;
64 [[nodiscard]] JPL_INLINE
std::
size_t GetNumPaths()
const {
return mValidPaths.size() + mInvalidPaths.size(); }
65 [[nodiscard]] JPL_INLINE std::size_t
GetNumValidPaths()
const {
return mValidPaths.size(); }
74 std::span<const int> nodes,
75 const Vec3& imageSource,
86 template<
class SceneType>
87 void Validate(
const SceneType& scene);
89 JPL_INLINE std::span<const SPEntry>
GetValidPaths()
const {
return mValidPaths; }
90 JPL_INLINE std::span<const SPEntry>
GetInvalidPaths()
const {
return mInvalidPaths; }
100 JPL_INLINE
void ClearInvalidPaths()
102 for (
auto&& [pathKey, path] : mInvalidPaths)
104 DeallocatePathData(path);
106 mInvalidPaths.clear();
110 JPL_INLINE
void ClearValidPaths()
112 for (
auto&& [pathKey, path] : mValidPaths)
114 DeallocatePathData(path);
119 JPL_INLINE
void DeallocatePathData(SpecularPathData<Vec3>& path)
147 for (
SPArray& pathsArray : { std::ref(mValidPaths), std::ref(mInvalidPaths) })
149 for (
auto&& [
id, data] : pathsArray)
151 allocator.deallocate(data.Nodes.data(), data.Nodes.size());
159 auto hasId = [pathId](
const SPEntry& entry) {
return entry.first == pathId; };
160 return std::ranges::find_if(mValidPaths, hasId) != std::ranges::end(mValidPaths)
161 || std::ranges::find_if(mInvalidPaths, hasId) != std::ranges::end(mInvalidPaths);
171 std::copy(nodes.begin(), nodes.end(), nodeData);
173 auto& pathsArray = isPathValid ? mValidPaths : mInvalidPaths;
175 pathsArray.emplace_back(path,
177 .Nodes = std::span(nodeData, nodes.size()),
179 .ImageSource = imageSource,
180 .bValid = isPathValid
185 template<
class SceneType>
197 for (
auto&& [pathKey, path] : mValidPaths)
200 "Path contains only source and listener verices, no reflections.");
202 JPL_ASSERT(path.Nodes.size() <= cMaxOrder + 2,
203 "Path is deeper than max order allowed.");
213 auto isValid = [](
const SPEntry& entry)
215 return entry.second.bValid;
218 auto invalidRange = std::ranges::partition(mValidPaths, isValid);
222 mInvalidPaths.reserve(mInvalidPaths.size() + invalidRange.size());
223 std::ranges::move(invalidRange, std::back_inserter(mInvalidPaths));
225 for (
auto&& [pathKey, path] : invalidRange)
227 DeallocatePathData(path);
230 mValidPaths.erase(invalidRange.begin(), mValidPaths.end());
#define JPL_ASSERT(inExpression,...)
Main assert macro, usage: JPL_ASSERT(condition, message) or JPL_ASSERT(condition)
Definition ErrorReporting.h:80
A very experimental scene interface for specular ray tracing.
Definition SceneInterface.h:35
static bool ValidatePath(const SceneType &scene, std::span< const int > triCache, std::span< const Vec3 > imageSources, const Vec3 &receiver)
Definition SceneInterface.h:82
A very experimental specular path cache.
Definition SpecularPathCache.h:49
JPL_INLINE bool Contains(SpecularPathId pathId) const
Definition SpecularPathCache.h:157
JPL_INLINE std::size_t GetNumPaths() const
Definition SpecularPathCache.h:64
std::pair< SpecularPathId, SpecularPathData< Vec3 > > SPEntry
Definition SpecularPathCache.h:53
SpecularPathCache()=default
JPL_INLINE std::span< const SPEntry > GetValidPaths() const
Definition SpecularPathCache.h:89
void Add(SpecularPathId path, std::span< const int > nodes, const Vec3 &imageSource, const EnergyBands &energy, bool isPathValid)
Definition SpecularPathCache.h:165
std::pmr::unordered_map< SpecularPathId, SpecularPathData< Vec3 > > SPMap
Definition SpecularPathCache.h:52
JPL_INLINE std::size_t GetNumInvalidPaths() const
Definition SpecularPathCache.h:66
JPL_INLINE std::span< const SPEntry > GetInvalidPaths() const
Definition SpecularPathCache.h:90
static constexpr std::size_t cMaxOrder
Definition SpecularPathCache.h:56
JPL_INLINE std::size_t GetNumValidPaths() const
Definition SpecularPathCache.h:65
JPL_INLINE void Clear()
Definition SpecularPathCache.h:92
std::pmr::vector< SPEntry > SPArray
Definition SpecularPathCache.h:54
void Validate(const SceneType &scene)
Definition SpecularPathCache.h:186
~SpecularPathCache() noexcept
Definition SpecularPathCache.h:143
Definition AcousticMaterial.h:36
std::pmr::memory_resource * GetDefaultMemoryResource() noexcept
Definition Memory.h:42
JPL_INLINE PmrAllocator< T > GetDefaultPmrAllocator()
Definition Memory.h:186
Definition ChannelMap.h:272
Definition SpecularPath.h:57
A very experimental specular path definition.
Definition SpecularPath.h:40
Minimal 4-wide 32-bit float vector implementation for SIMD.
Definition SIMD.h:60