MCPcopy Create free account
hub / github.com/AcademySoftwareFoundation/MaterialX / flattenSubgraphs

Method flattenSubgraphs

source/MaterialXCore/Node.cpp:251–404  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

249}
250
251void GraphElement::flattenSubgraphs(const string& target, NodePredicate filter)
252{
253 vector<NodePtr> nodeQueue = getNodes();
254 while (!nodeQueue.empty())
255 {
256 // Determine which nodes require processing, and precompute declarations
257 // and graph implementations for these nodes.
258 using PortElementVec = vector<PortElementPtr>;
259 std::vector<NodePtr> processNodeVec;
260 std::unordered_map<NodePtr, NodeGraphPtr> graphImplMap;
261 std::unordered_map<NodePtr, ConstInterfaceElementPtr> declarationMap;
262 std::unordered_map<NodePtr, PortElementVec> downstreamPortMap;
263 for (NodePtr node : nodeQueue)
264 {
265 if (filter && !filter(node))
266 {
267 continue;
268 }
269
270 InterfaceElementPtr implement = node->getImplementation(target);
271 if (implement && implement->isA<NodeGraph>())
272 {
273 processNodeVec.push_back(node);
274 graphImplMap[node] = implement->asA<NodeGraph>();
275 declarationMap[node] = node->getDeclaration(target);
276 downstreamPortMap[node] = node->getDownstreamPorts();
277 for (NodePtr sourceSubNode : implement->asA<NodeGraph>()->getNodes())
278 {
279 downstreamPortMap[sourceSubNode] = sourceSubNode->getDownstreamPorts();
280 }
281 }
282 }
283 nodeQueue.clear();
284
285 // Iterate through nodes with graph implementations.
286 for (NodePtr processNode : processNodeVec)
287 {
288 NodeGraphPtr sourceSubGraph = graphImplMap[processNode];
289 std::unordered_map<NodePtr, NodePtr> subNodeMap;
290
291 // Create a new instance of each original subnode.
292 for (NodePtr sourceSubNode : sourceSubGraph->getNodes())
293 {
294 string origName = sourceSubNode->getName();
295 string destName = createValidChildName(origName);
296 NodePtr destSubNode = addNode(sourceSubNode->getCategory(), destName);
297
298 destSubNode->copyContentFrom(sourceSubNode);
299 setChildIndex(destSubNode->getName(), getChildIndex(processNode->getName()));
300
301 // Store the mapping between subgraphs.
302 subNodeMap[sourceSubNode] = destSubNode;
303
304 // Add the subnode to the queue, allowing processing of nested subgraphs.
305 nodeQueue.push_back(destSubNode);
306 }
307
308 // Update properties of generated subnodes.

Callers 3

Node.cppFile · 0.80
XmlIo.cppFile · 0.80
loadDocumentMethod · 0.80

Calls 15

getNodesFunction · 0.85
filterFunction · 0.85
createValidChildNameFunction · 0.85
addNodeFunction · 0.85
getDocumentFunction · 0.85
removeNodeFunction · 0.85
push_backMethod · 0.80
getDownstreamPortsMethod · 0.80
getCategoryMethod · 0.80
copyContentFromMethod · 0.80
countMethod · 0.80
getActiveInputMethod · 0.80

Tested by

no test coverage detected