Loading...
Searching...
No Matches
coordSysPrimSceneIndex.h
1//
2// Copyright 2023 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_IMAGING_HDSI_COORD_SYS_PRIM_SCENE_INDEX_H
8#define PXR_IMAGING_HDSI_COORD_SYS_PRIM_SCENE_INDEX_H
9
10#include "pxr/imaging/hdsi/api.h"
11
12#include "pxr/imaging/hd/filteringSceneIndex.h"
13
14PXR_NAMESPACE_OPEN_SCOPE
15
17
66{
67public:
68
71 static HdsiCoordSysPrimSceneIndexRefPtr New(
72 HdSceneIndexBaseRefPtr const &inputScene)
73 {
74 return TfCreateRefPtr(
75 new HdsiCoordSysPrimSceneIndex(inputScene));
76 }
77
78 HDSI_API
79 HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override;
80
81 HDSI_API
82 SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override;
83
84protected:
85
86 HDSI_API
88 HdSceneIndexBaseRefPtr const &inputScene);
89
90 // satisfying HdSingleInputFilteringSceneIndexBase
91 void _PrimsAdded(
92 const HdSceneIndexBase &sender,
93 const HdSceneIndexObserver::AddedPrimEntries &entries) override;
94
95 void _PrimsRemoved(
96 const HdSceneIndexBase &sender,
97 const HdSceneIndexObserver::RemovedPrimEntries &entries) override;
98
99 void _PrimsDirtied(
100 const HdSceneIndexBase &sender,
101 const HdSceneIndexObserver::DirtiedPrimEntries &entries) override;
102
103 struct _Binding
104 {
105 TfToken name;
106 SdfPath path;
107 };
108 using _Bindings = std::vector<_Binding>;
109 using _PrimToBindings = std::map<SdfPath, _Bindings>;
110
111 // Record coordSys bindings of prim at primPath. That is, add entries to the
112 // below data structures if needed and increase ref-counts.
113 // Optionally, return prims of type coord system that this scene index needs
114 // to add.
115 void _AddBindingsForPrim(const SdfPath &primPath,
116 SdfPathSet * addedCoordSysPrims = nullptr);
117 // Compute the coordSys bindings of the prim at primPath from the input
118 // scene. Does not modify any data structures and is thread-safe.
119 _Bindings _ComputeBindingsForPrim(const SdfPath &primPath) const;
120 // Record the given bindings for the prim at primPath. Same as
121 // _AddBindingsForPrim but with the bindings already computed.
122 void _AddBindings(const SdfPath &primPath,
123 _Bindings &&bindings,
124 SdfPathSet * addedCoordSysPrims);
125 // Remove coordSys bindings. That is, decrease ref-counts and remove entries
126 // from below data structures if needed.
127 // Optionally, return prims of type coord system that this scene index needs
128 // to remove.
129 void _RemoveBindings(const _Bindings &bindings,
130 SdfPathSet * removedCoordSysPrims);
131 // Similar to above, but give the prim path explicitly to look-up bindings
132 // in map.
133 void _RemoveBindingsForPrim(const SdfPath &primPath,
134 SdfPathSet * removedCoordSysPrims);
135 // Removes bindings for given prim and all its descendants stored in below
136 // data structures.
137 void _RemoveBindingsForSubtree(const SdfPath &primPath,
138 SdfPathSet * removedCoordSysPrims);
139
140 // If path is for coord sys prim added by this scene index, give the
141 // prim source for it.
142 HdContainerDataSourceHandle _GetCoordSysPrimSource(
143 const SdfPath &primPath) const;
144
145private:
146 using _NameToRefCount =
147 std::unordered_map<TfToken, size_t, TfToken::HashFunctor>;
148 using _PrimToNameToRefCount =
149 std::unordered_map<SdfPath, _NameToRefCount, SdfPath::Hash>;
150 // Maps prim which is targeted by coord sys binding to name of binding to
151 // count how many bindings are referencing that prim using that name.
152 //
153 // We delete an inner entry when there is no longer any coord sys binding
154 // with that name targeting the prim.
155 // We delete a prim when it is no longer targeted by any binding.
156 //
157 // This map is used to determine which coord sys prims we need to create
158 // under the targeted prim.
159 //
160 //
161 // In the above example, the content of the map will be:
162 //
163 // {
164 // /MyXform: {
165 // FOO: 1
166 // }
167 // }
168 //
169 _PrimToNameToRefCount _targetedPrimToNameToRefCount;
170
171 // Maps prim to the coord sys bindings of that prim.
172 //
173 // Used to decrease ref counts when a prim gets deleted or modified.
174 //
175 // In the above example, the content of the map will be:
176 //
177 // { /MyPrim: [(FOO, /MyXform)] }
178 //
179 _PrimToBindings _primToBindings;
180};
181
182PXR_NAMESPACE_CLOSE_SCOPE
183
184#endif
Abstract interface to scene data.
Definition sceneIndex.h:55
An abstract base class for a filtering scene index that observes a single input scene index.
This is a utility scene index to aid emulation of Hydra 1 style coordinate systems,...
HDSI_API HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override
Returns a pair of (prim type, datasource).
static HdsiCoordSysPrimSceneIndexRefPtr New(HdSceneIndexBaseRefPtr const &inputScene)
Creates a new coord sys prim scene index.
HDSI_API SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override
Returns the paths of all scene index prims located immediately below primPath.
A path value used to locate objects in layers or scenegraphs.
Definition path.h:281
Token for efficient comparison, assignment, and hashing of known strings.
Definition token.h:81
#define TF_DECLARE_REF_PTRS(type)
Define standard ref pointer types.
Definition declarePtrs.h:58
Small struct representing a 'prim' in the Hydra scene index.
Definition sceneIndex.h:36