HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
isolatedSubnetwork.h
Go to the documentation of this file.
1 //
2 // Copyright 2025 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_EXEC_VDF_ISOLATED_SUBNETWORK_H
8 #define PXR_EXEC_VDF_ISOLATED_SUBNETWORK_H
9 
10 /// \file
11 
12 #include "pxr/pxr.h"
13 
14 #include "pxr/exec/vdf/api.h"
15 #include "pxr/exec/vdf/types.h"
16 
20 
21 #include <vector>
22 
24 
25 class VdfNetwork;
26 class VdfNode;
27 
28 ////////////////////////////////////////////////////////////////////////////////
29 ///
30 /// A VdfIsolatedSubnetwork builds a collection of VdfNode%s and VdfConnection%s
31 /// that are disconnected from the owning network.
32 ///
33 /// Building an isolated subnetwork proceeds in three phases:
34 ///
35 /// 1. A traversal starts from one or more nodes or connections and proceeds in
36 /// the input direction, and identifies all reachable objects that are not
37 /// otherwise connected to the network. I.e., the traversal stops at nodes
38 /// that have output connections that are not part of the isolated
39 /// subnetwork.
40 ///
41 /// 2. Isolated objects are removed from the network, which causes WillDelete
42 /// notices to be sent, out even though objects have not yet been deleted.
43 /// This process transfers ownership of network objects from the VdfNetwork
44 /// to the VdfIsolatedSubnetwork.
45 ///
46 /// 3. The objects are deleted when the VdfIsolatedSubnetwork is deleted.
47 ///
49 {
50 public:
53 
54  VDF_API
56 
57  /// A set of isolated connections.
59 
60  /// A function that returns `true` if the given node is allowed to be
61  /// isolated and deleted.
63 
64  /// Isolates all nodes and connections reachable via input connections from
65  /// \p connection that are not connected via additional output connections
66  /// to other parts of the network.
67  ///
68  /// Note that \p connection is added to the set of isolated objects.
69  ///
70  /// The \p canDelete object is used to prune the traversal.
71  ///
72  /// Removes the isolated objects from the network and returns a unique
73  /// pointer to the isolated network object that holds onto the isolated
74  /// nodes and connections. When the isolated network object is deleted, the
75  /// isolated nodes and connections are deleted.
76  ///
77  VDF_API static
78  std::unique_ptr<VdfIsolatedSubnetwork> IsolateBranch(
79  VdfConnection *connection,
80  EditFilter canDelete);
81 
82  /// Isolates all nodes and connections reachable via input connections from
83  /// \p node that are not connected via additional output connections to
84  /// other parts of the network.
85  ///
86  /// The \p canDelete object is used to prune the traversal.
87  ///
88  /// Removes the isolated objects from the network and returns a strong
89  /// reference to the isolated network object that holds onto the isolated
90  /// nodes and connections. When the isolated network object is deleted, the
91  /// isolated nodes and connections are deleted.
92  ///
93  /// \note
94  /// An error is emitted if \p node has output connections.
95  ///
96  VDF_API static
97  std::unique_ptr<VdfIsolatedSubnetwork> IsolateBranch(
98  VdfNode *node,
99  EditFilter canDelete);
100 
101  /// Creates an empty isolated subnetwork.
102  ///
103  /// The subnetwork can be populated via calls to the AddIsolatedBranch
104  /// methods.
105  ///
106  VDF_API static
107  std::unique_ptr<VdfIsolatedSubnetwork> New(VdfNetwork *network);
108 
109  /// Isolates all nodes and connections reachable via input connections from
110  /// \p connection that are not connected via additional output connections
111  /// to other parts of the network.
112  ///
113  /// Note that \p connection is added to the set of isolated objects.
114  ///
115  /// The \p canDelete object is used to prune the traversal.
116  ///
117  /// \note
118  /// Isolated objects are not immediately removed from the network. See
119  /// RemoveIsolatedObjectsFromNetwork.
120  ///
121  VDF_API
122  bool AddIsolatedBranch(
123  VdfConnection *connection,
124  EditFilter canDelete);
125 
126  /// Isolates all nodes and connections reachable via input connections from
127  /// \p node that are not connected via additional output connections to
128  /// other parts of the network.
129  ///
130  /// The \p canDelete object is used to prune the traversal.
131  ///
132  /// \note
133  /// If \p node has output connections or \p canDelete returns `false` for \p
134  /// node, no objects are added to the isolated subnetwork and `false` is
135  /// returned.
136  ///
137  /// \note
138  /// Isolated objects are not immediately removed from the network. See
139  /// RemoveIsolatedObjectsFromNetwork.
140  ///
141  VDF_API
142  bool AddIsolatedBranch(
143  VdfNode *node,
144  EditFilter canDelete);
145 
146  /// Removes all isolated objects from the network.
147  ///
148  /// This method is called upon destruction, if it isn't called before then.
149  ///
150  VDF_API
152 
153  /// Returns the set of isolated nodes.
154  const std::vector<VdfNode *> &GetIsolatedNodes() const {
155  return _nodes;
156  }
157 
158  /// Returns the set of isolated nodes.
160  return _connections;
161  }
162 
163 private:
165 
166  // Helper that checks if we can traverse past \p sourceNode.
167  bool _CanTraverse(
168  const VdfNode &sourceNode,
169  EditFilter canDelete);
170 
171  // Helper that traverses a branch.
172  void _TraverseBranch(
173  VdfConnection *connection,
174  EditFilter canDelete);
175 
176 private:
177 
178  // The network
179  VdfNetwork *_network;
180 
181  // The set of isolated nodes.
182  std::vector<VdfNode *> _nodes;
183 
184  // The set of isolated connections.
185  ConnectionSet _connections;
186 
187  // Used to keep track of the number of remaining output connections for a
188  // given node that have not yet been determined to be part of the isolated
189  // subnetwork.
191  _unisolatedOutputConnections;
192 
193  // Flag that indicates whether or not RemoveIsolatedObjectsFromNetwork has
194  // been called.
195  bool _removedIsolatedObjects = false;
196 };
197 
199 
200 #endif
const ConnectionSet & GetIsolatedConnections() const
Returns the set of isolated nodes.
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
Definition: node.h:52
VDF_API bool AddIsolatedBranch(VdfConnection *connection, EditFilter canDelete)
#define VDF_API
Definition: api.h:25
VdfIsolatedSubnetwork & operator=(const VdfIsolatedSubnetwork &)=delete
static VDF_API std::unique_ptr< VdfIsolatedSubnetwork > IsolateBranch(VdfConnection *connection, EditFilter canDelete)
static VDF_API std::unique_ptr< VdfIsolatedSubnetwork > New(VdfNetwork *network)
VdfIsolatedSubnetwork(const VdfIsolatedSubnetwork &)=delete
pxr_tsl::robin_set< VdfConnection *, TfHash > ConnectionSet
A set of isolated connections.
VDF_API ~VdfIsolatedSubnetwork()
TfFunctionRef< bool(const VdfNode *)> EditFilter
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
const std::vector< VdfNode * > & GetIsolatedNodes() const
Returns the set of isolated nodes.
VDF_API void RemoveIsolatedObjectsFromNetwork()