VTK  9.7.1
vtkDataObjectMeshCache.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
3 
4 #ifndef vtkDataObjectMeshCache_h
5 #define vtkDataObjectMeshCache_h
6 
7 #include "vtkCommonCacheModule.h" // Export macro
8 
9 #include "vtkObject.h"
10 #include "vtkSetGet.h" // for Set/Get macros
11 #include "vtkSmartPointer.h" // for smart pointer
12 #include "vtkWeakPointer.h" // for weak pointer
13 
14 #include <set> // for set
15 #include <string> // for string
16 
17 VTK_ABI_NAMESPACE_BEGIN
18 
19 class vtkAlgorithm;
20 class vtkDataObject;
21 class vtkDataSet;
23 
73 class VTKCOMMONCACHE_EXPORT vtkDataObjectMeshCache : public vtkObject
74 {
75 public:
76  static vtkDataObjectMeshCache* New();
78  void PrintSelf(ostream& os, vtkIndent indent) override;
79 
86  struct Status
87  {
91  bool OriginalDataDefined = false;
95  bool ConsumerDefined = false;
100  bool CacheDefined = false;
104  bool OriginalMeshUnmodified = false;
108  bool ConsumerUnmodified = false;
112  bool AttributesIdsExists = true;
113 
117  bool enabled()
118  {
119  return this->OriginalDataDefined && this->ConsumerDefined && this->CacheDefined &&
120  this->ConsumerUnmodified && this->OriginalMeshUnmodified && this->AttributesIdsExists;
121  }
122 
127  bool operator==(const Status& other) const
128  {
129  return other.OriginalDataDefined == this->OriginalDataDefined &&
130  other.ConsumerDefined == this->ConsumerDefined &&
131  other.CacheDefined == this->CacheDefined &&
132  other.OriginalMeshUnmodified == this->OriginalMeshUnmodified &&
133  other.ConsumerUnmodified == this->ConsumerUnmodified &&
134  other.AttributesIdsExists == this->AttributesIdsExists;
135  }
136 
141  bool operator!=(const Status& other) const { return !(*this == other); }
142 
146  void PrintSelf(ostream& os, vtkIndent indent);
147  };
148 
152 
158  void SetConsumer(vtkAlgorithm* consumer);
159 
168  void SetOriginalDataObject(vtkDataObject* original);
170 
177 
182  void AddOriginalIds(int attribute, const std::string& name);
183 
188  void RemoveOriginalIds(int attribute);
189 
194  void ClearOriginalIds();
195 
202  void ForwardAttribute(int attribute);
203 
210  void AddPreservedInputAttributes(int);
212  void ClearPreservedInputAttributes();
213  void PreservedInputAllAttributes();
214  std::set<int> GetPreservedInputAttributes();
216 
220  static std::string GetDefaultIdsName();
221 
227  static void CreateTemporaryOriginalIdsArrays(vtkDataObject* object);
228 
233  static void CleanupTemporaryOriginalIds(vtkDataObject* object);
235 
245  static vtkMTimeType GetDataObjectMeshMTime(vtkDataObject* object);
246 
252  static std::map<unsigned int, vtkMTimeType> GetDataObjectMeshMTimes(vtkDataObject* object);
253 
259  Status GetStatus() const;
260 
266  void CopyCacheToDataObject(vtkDataObject* output);
267 
269 
276  void AddPreservedCachedArray(const std::string& arrayName);
277  void ClearPreservedCachedArray();
278  std::set<std::string> GetPreservedCachedArrays();
280 
285  void UpdateCache(vtkDataObject* newObject);
286 
291  void InvalidateCache();
292 
296  bool IsSupportedData(vtkDataObject* dataobject) const;
297 
298 protected:
299  vtkDataObjectMeshCache() = default;
300  ~vtkDataObjectMeshCache() override = default;
306  void ForwardAttributes(vtkDataSet* input, vtkDataSet* cache, vtkDataSet* output, int attribute,
308  const std::string& name);
309  void ForwardAttributesToDataSet(vtkDataSet* input, vtkDataSet* cache, vtkDataSet* output);
310  void ForwardAttributesToComposite(vtkCompositeDataSet* input, vtkCompositeDataSet* output);
312 
313 private:
315  void operator=(const vtkDataObjectMeshCache&) = delete;
316 
320  vtkDataObject* GetOriginalDataObject() const;
321 
325  vtkMTimeType GetOriginalMeshTime() const;
326 
330  std::set<vtkMTimeType> GetOriginalMeshTimes() const;
331 
338  vtkIdType GetNumberOfDataSets(vtkDataObject* dataobject) const;
339 
346  bool CacheHasRequestedIds() const;
347 
351  void ClearAttributes(vtkDataObject*);
352 
357  bool HasConsumerNoInputPort() const;
358 
360 
364  vtkWeakPointer<vtkDataSet> OriginalDataSet;
365  vtkWeakPointer<vtkCompositeDataSet> OriginalCompositeDataSet;
367 
369 
372  std::map<int, std::string> OriginalIdsName;
373  std::set<int> PreservedInputAttributes;
374  std::set<std::string> PreservedCachedArrays;
376 
378 
382  vtkMTimeType CachedConsumerTime = 0;
383  std::map<unsigned int, vtkMTimeType> CachedOriginalLeavesTime;
385 };
386 
387 VTK_ABI_NAMESPACE_END
388 #endif
bool ConsumerUnmodified
True if Consumer was not modified since last cache update.
abstract base class for most VTK objects
Definition: vtkObject.h:52
bool OriginalMeshUnmodified
True if OriginalDataSet mesh was not modified since last cache update.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:318
abstract class to specify dataset behavior
Definition: vtkDataSet.h:56
Structure to handle the current cache status.
int vtkIdType
Definition: vtkType.h:363
bool enabled()
Return true if the cache can safely and meaningfully be used.
Superclass for all sources, filters, and sinks in VTK.
Definition: vtkAlgorithm.h:53
abstract superclass for composite (multi-block or AMR) datasets
a simple class to control print indentation
Definition: vtkIndent.h:28
bool CacheDefined
True if Cache with initialized.
bool operator==(const Status &other) const
Return true if and only if every members are equals.
vtkDataObjectMeshCache is a class to store and reuse the mesh of a vtkDataSet, while forwarding data ...
bool operator!=(const Status &other) const
Return true if both object are not equals.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
bool OriginalDataDefined
True if OriginalDataObject is set.
general representation of visualization data
Definition: vtkDataObject.h:55
bool ConsumerDefined
True if Consumer is set.
bool AttributesIdsExists
True if attributes ids exists.