Loading...
Searching...
No Matches
coordSysPrimSceneIndex.h
1//
2// Copyright 2023 Pixar
3//
4// Licensed under the Apache License, Version 2.0 (the "Apache License")
5// with the following modification; you may not use this file except in
6// compliance with the Apache License and the following modification to it:
7// Section 6. Trademarks. is deleted and replaced with:
8//
9// 6. Trademarks. This License does not grant permission to use the trade
10// names, trademarks, service marks, or product names of the Licensor
11// and its affiliates, except as required to comply with Section 4(c) of
12// the License and to reproduce the content of the NOTICE file.
13//
14// You may obtain a copy of the Apache License at
15//
16// http://www.apache.org/licenses/LICENSE-2.0
17//
18// Unless required by applicable law or agreed to in writing, software
19// distributed under the Apache License with the above modification is
20// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21// KIND, either express or implied. See the Apache License for the specific
22// language governing permissions and limitations under the Apache License.
23//
24#ifndef PXR_IMAGING_HDSI_COORD_SYS_PRIM_SCENE_INDEX_H
25#define PXR_IMAGING_HDSI_COORD_SYS_PRIM_SCENE_INDEX_H
26
27#include "pxr/imaging/hdsi/api.h"
28
29#include "pxr/imaging/hd/filteringSceneIndex.h"
30
31PXR_NAMESPACE_OPEN_SCOPE
32
34
80{
81public:
82
85 static HdsiCoordSysPrimSceneIndexRefPtr New(
86 HdSceneIndexBaseRefPtr const &inputScene)
87 {
88 return TfCreateRefPtr(
89 new HdsiCoordSysPrimSceneIndex(inputScene));
90 }
91
92 HDSI_API
93 HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override;
94
95 HDSI_API
96 SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override;
97
98protected:
99
100 HDSI_API
102 HdSceneIndexBaseRefPtr const &inputScene);
103
104 // satisfying HdSingleInputFilteringSceneIndexBase
105 void _PrimsAdded(
106 const HdSceneIndexBase &sender,
107 const HdSceneIndexObserver::AddedPrimEntries &entries) override;
108
109 void _PrimsRemoved(
110 const HdSceneIndexBase &sender,
111 const HdSceneIndexObserver::RemovedPrimEntries &entries) override;
112
113 void _PrimsDirtied(
114 const HdSceneIndexBase &sender,
115 const HdSceneIndexObserver::DirtiedPrimEntries &entries) override;
116
117 struct _Binding
118 {
119 TfToken name;
120 SdfPath path;
121 };
122 using _Bindings = std::vector<_Binding>;
123 using _PrimToBindings = std::map<SdfPath, _Bindings>;
124
125 // Record coordSys bindings of prim at primPath. That is, add entries to the
126 // below data structures if needed and increase ref-counts.
127 // Optionally, return prims of type coord system that this scene index needs
128 // to add.
129 void _AddBindingsForPrim(const SdfPath &primPath,
130 SdfPathSet * addedCoordSysPrims = nullptr);
131 // Remove coordSys bindings. That is, decrease ref-counts and remove entries
132 // from below data structures if needed.
133 // Optionally, return prims of type coord system that this scene index needs
134 // to remove.
135 void _RemoveBindings(const _Bindings &bindings,
136 SdfPathSet * removedCoordSysPrims);
137 // Similar to above, but give the prim path explicitly to look-up bindings
138 // in map.
139 void _RemoveBindingsForPrim(const SdfPath &primPath,
140 SdfPathSet * removedCoordSysPrims);
141 // Removes bindings for given prim and all its descendants stored in below
142 // data structures.
143 void _RemoveBindingsForSubtree(const SdfPath &primPath,
144 SdfPathSet * removedCoordSysPrims);
145
146 // If path is for coord sys prim added by this scene index, give the
147 // prim source for it.
148 HdContainerDataSourceHandle _GetCoordSysPrimSource(
149 const SdfPath &primPath) const;
150
151private:
152 using _NameToRefCount =
153 std::unordered_map<TfToken, size_t, TfToken::HashFunctor>;
154 using _PrimToNameToRefCount =
155 std::unordered_map<SdfPath, _NameToRefCount, SdfPath::Hash>;
156 // Maps prim which is targeted by coord sys binding to name of binding to
157 // count how many bindings are referencing that prim using that name.
158 //
159 // We delete an inner entry when there is no longer any coord sys binding
160 // with that name targeting the prim.
161 // We delete a prim when it is no longer targeted by any binding.
162 //
163 // This map is used to determine which coord sys prims we need to create
164 // under the targeted prim.
165 //
166 //
167 // In the above example, the content of the map will be:
168 //
169 // {
170 // /MyXform: {
171 // FOO: 1
172 // }
173 // }
174 //
175 _PrimToNameToRefCount _targetedPrimToNameToRefCount;
176
177 // Maps prim to the coord sys bindings of that prim.
178 //
179 // Used to decrease ref counts when a prim gets deleted or modified.
180 //
181 // In the above example, the content of the map will be:
182 //
183 // { /MyPrim: [(FOO, /MyXform)] }
184 //
185 _PrimToBindings _primToBindings;
186};
187
188PXR_NAMESPACE_CLOSE_SCOPE
189
190#endif
Abstract interface to scene data.
Definition: sceneIndex.h:65
An abstract base class for a filtering scene index that observes a single input scene index.
If prim P has a coord sys binding FOO to another prim Q, the scene index will add a coord sys prim Q....
HDSI_API HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override
Returns a pair of (prim type, datasource) for the object at primPath.
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:290
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:88
#define TF_DECLARE_REF_PTRS(type)
Define standard ref pointer types.
Definition: declarePtrs.h:75
Small struct representing a 'prim' in the Hydra scene index.
Definition: sceneIndex.h:52