VTK  9.1.0
vtkOSPRayCache.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkOSPRayCache.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
28 #ifndef vtkOSPRayCache_h
29 #define vtkOSPRayCache_h
30 
31 #include "vtkRenderingRayTracingModule.h" // For export macro
32 #include "vtkSystemIncludes.h" //dll warning suppression
33 #include <map> // for stl
34 #include <memory>
35 
36 #include "RTWrapper/RTWrapper.h" // for handle types
37 
38 template <class T>
39 class VTKRENDERINGRAYTRACING_EXPORT vtkOSPRayCache
40 {
41 public:
42  vtkOSPRayCache() { this->Size = 0; }
43 
44  ~vtkOSPRayCache() { this->Empty(); }
45 
49  void Set(double tstep, std::shared_ptr<T> payload)
50  {
51  if (this->Contents.size() >= this->Size)
52  {
53  return;
54  }
55  this->Contents[tstep] = payload;
56  }
57 
62  std::shared_ptr<T> Get(double tstep)
63  {
64  auto ret = this->Contents.find(tstep);
65  if (ret != this->Contents.end())
66  {
67  return ret->second;
68  }
69  return nullptr;
70  }
71 
73 
77  void SetSize(size_t sz)
78  {
79  if (sz == this->Size)
80  {
81  return;
82  }
83  if (sz < this->Size)
84  {
85  this->Empty();
86  }
87  this->Size = sz;
88  }
89  size_t GetSize() { return this->Size; }
91 
95  bool Contains(double tstep) { return this->Get(tstep) != nullptr; }
96 
100  bool HasRoom() { return this->Contents.size() < this->Size; }
101 
102 private:
103  // deletes all of the content in the cache
104  void Empty()
105  {
106  this->Contents.clear();
107  this->Size = 0;
108  }
109 
110  size_t Size;
111 
112  std::map<double, std::shared_ptr<T>> Contents;
113 };
114 
116 {
117 public:
119  : backend(be)
120  {
121  object = obj;
122  }
124  OSPObject object{ nullptr };
125  size_t size{ 0 };
126  RTW::Backend* backend = nullptr;
127 };
128 
129 #endif // vtkOSPRayCache_h
130 // VTK-HeaderTest-Exclude: vtkOSPRayCache.h
#define ospRelease
Definition: RTWrapper.h:154
#define OSPObject
Definition: RTWrapper.h:14
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.
bool Contains(double tstep)
Query whether cache contains tstep.
size_t GetSize()
Set/Get the number of slots available in the cache.
std::shared_ptr< T > Get(double tstep)
Obtain an object from 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.