All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
collectionCache.h
Go to the documentation of this file.
1//
2// Copyright 2018 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_USD_IMAGING_USD_IMAGING_COLLECTION_CACHE_H
8#define PXR_USD_IMAGING_USD_IMAGING_COLLECTION_CACHE_H
9
11
12#include "pxr/pxr.h"
13#include "pxr/usdImaging/usdImaging/api.h"
15
16#include <tbb/concurrent_unordered_map.h>
17#include <tbb/concurrent_queue.h>
18#include <mutex>
19#include <unordered_map>
20
21PXR_NAMESPACE_OPEN_SCOPE
22
41class UsdImaging_CollectionCache {
42public:
43 UsdImaging_CollectionCache() = default;
44 UsdImaging_CollectionCache(const UsdImaging_CollectionCache&) = delete;
45 UsdImaging_CollectionCache& operator=(const UsdImaging_CollectionCache&) = delete;
46
49
56 USDIMAGING_API
57 bool
58 UpdateCollection(UsdCollectionAPI const& collection);
59
61 USDIMAGING_API
62 size_t
63 RemoveCollection(UsdStageWeakPtr const& stage, SdfPath const& path);
64
66 USDIMAGING_API
68 GetIdForCollection(UsdCollectionAPI const& collection);
69
71 // the given path.
72 USDIMAGING_API
74 ComputeCollectionsContainingPath(SdfPath const& path) const;
75
78 USDIMAGING_API
79 SdfPathSet const&
80 GetDirtyPaths() const;
81
83 USDIMAGING_API
84 void
85 ClearDirtyPaths();
86
87private:
88 // The cache boils down to tracking the correspondence of
89 // collection paths, their computed queries, and the id
90 // assigned to each unique query:
91 //
92 // CollectionPath <=> MembershipQuery <=> AssignedId
93 //
94 // In this scheme, the assigned id provides a compact but
95 // potentially human-meaningful reference to the query,
96 // which we can pass to the renderer.
97 //
98 std::unordered_map<Query, TfToken, Query::Hash> _idForQuery;
99 std::unordered_map<TfToken, Query, TfToken::HashFunctor> _queryForId;
100 std::unordered_map<SdfPath, TfToken, SdfPath::Hash> _idForPath;
101 std::unordered_map<Query, SdfPathSet, Query::Hash> _pathsForQuery;
102
103 void
104 _MarkCollectionContentDirty(
105 UsdStageWeakPtr const& stage,
107
108 SdfPathSet _dirtyPaths;
109
110 std::mutex _mutex;
111};
112
113
114PXR_NAMESPACE_CLOSE_SCOPE
115
116#endif // PXR_USD_IMAGING_USD_IMAGING_COLLECTION_CACHE_H
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:274
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
A general purpose API schema used to describe a collection of prims and properties within a scene.
Represents a flattened view of a collection.
Represents an arbitrary dimensional rectangular container class.
Definition: array.h:211