VTK  9.4.20241218
vtkOSPRayCache.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
16#ifndef vtkOSPRayCache_h
17#define vtkOSPRayCache_h
18
19#include "vtkRenderingRayTracingModule.h" // For export macro
20#include "vtkSystemIncludes.h" //dll warning suppression
21#include <map> // for stl
22#include <memory>
23
24#include "RTWrapper/RTWrapper.h" // for handle types
25
26VTK_ABI_NAMESPACE_BEGIN
27template <class T>
28class VTKRENDERINGRAYTRACING_EXPORT vtkOSPRayCache
29{
30public:
31 vtkOSPRayCache() { this->Size = 0; }
32
33 ~vtkOSPRayCache() { this->Empty(); }
34
38 void Set(double tstep, std::shared_ptr<T> payload)
39 {
40 if (this->Contents.size() >= this->Size)
41 {
42 return;
43 }
44 this->Contents[tstep] = payload;
45 }
46
51 std::shared_ptr<T> Get(double tstep)
52 {
53 auto ret = this->Contents.find(tstep);
54 if (ret != this->Contents.end())
55 {
56 return ret->second;
57 }
58 return nullptr;
59 }
60
62
66 void SetSize(size_t sz)
67 {
68 if (sz == this->Size)
69 {
70 return;
71 }
72 if (sz < this->Size)
73 {
74 this->Empty();
75 }
76 this->Size = sz;
77 }
78 size_t GetSize() { return this->Size; }
80
84 bool Contains(double tstep) { return this->Get(tstep) != nullptr; }
85
89 bool HasRoom() { return this->Contents.size() < this->Size; }
90
91private:
92 // deletes all of the content in the cache
93 void Empty()
94 {
95 this->Contents.clear();
96 this->Size = 0;
97 }
98
99 size_t Size;
100
101 std::map<double, std::shared_ptr<T>> Contents;
102};
103
105{
106public:
108 : backend(be)
109 {
110 object = obj;
111 }
113 OSPObject object{ nullptr };
114 size_t size{ 0 };
116};
117
118VTK_ABI_NAMESPACE_END
119#endif // vtkOSPRayCache_h
120// VTK-HeaderTest-Exclude: vtkOSPRayCache.h
#define ospRelease
Definition RTWrapper.h:160
#define OSPObject
Definition RTWrapper.h:17
vtkOSPRayCacheItemObject(RTW::Backend *be, OSPObject obj)
temporal cache ospray structures to speed flipbooks
void SetSize(size_t sz)
Set/Get the number of slots available in the cache.
std::shared_ptr< T > Get(double tstep)
Obtain an object from the cache.
bool Contains(double tstep)
Query whether cache contains tstep.
size_t GetSize()
Set/Get the number of slots available in the cache.
bool HasRoom()
Check if the cache has space left.
void Set(double tstep, std::shared_ptr< T > payload)
Insert a new object into the cache.