mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-08-03 00:38:41 +02:00
Ignore "Publish" nodes when loading a template unless specified otherwise
This commit adds an option to the "load" method, "publishOutputs", that determines whether "Publish" nodes in a template project file should be ignored during the graph's creation. If "publishOutputs=True", then the "Publish" nodes from the template will be added to the graph. "Publish" nodes in a project file that is not a template will not be affected by this and will always be added to the graph, as any other node. This allows to have templates that are compatible with meshroom_batch, which requires a "Publish" node when the --output option is specified, while not having unneeded nodes in the UI or unneeded operations: when --output is specified in meshroom_batch, "publishOutputs=True", otherwise it will be set to False so that the "Publish" nodes are not executed needlessly.
This commit is contained in:
parent
fd5fc8e3ba
commit
99b82e601f
4 changed files with 24 additions and 18 deletions
|
@ -91,15 +91,6 @@ if args.verbose:
|
|||
logging.getLogger().setLevel(logStringToPython[args.verbose])
|
||||
|
||||
|
||||
def getOnlyNodeOfType(g, nodeType):
|
||||
""" Helper function to get a node of 'nodeType' in the graph 'g' and raise if no or multiple candidates. """
|
||||
nodes = g.nodesOfType(nodeType)
|
||||
if len(nodes) != 1:
|
||||
raise RuntimeError("meshroom_batch requires a pipeline graph with exactly one '{}' node, {} found."
|
||||
.format(nodeType, len(nodes)))
|
||||
return nodes[0]
|
||||
|
||||
|
||||
def getInitNode(g):
|
||||
"""
|
||||
Helper function to get the Init node in the graph 'g' and raise an exception if there is no or
|
||||
|
@ -124,10 +115,10 @@ with multiview.GraphModification(graph):
|
|||
# initialize template pipeline
|
||||
loweredPipelineTemplates = dict((k.lower(), v) for k, v in meshroom.core.pipelineTemplates.items())
|
||||
if args.pipeline.lower() in loweredPipelineTemplates:
|
||||
graph.load(loweredPipelineTemplates[args.pipeline.lower()], setupProjectFile=False)
|
||||
graph.load(loweredPipelineTemplates[args.pipeline.lower()], setupProjectFile=False, publishOutputs=True if args.output else False)
|
||||
else:
|
||||
# custom pipeline
|
||||
graph.load(args.pipeline, setupProjectFile=False)
|
||||
graph.load(args.pipeline, setupProjectFile=False, publishOutputs=True if args.output else False)
|
||||
|
||||
# get init node and initialize it
|
||||
initNode = getInitNode(graph)
|
||||
|
@ -140,8 +131,15 @@ with multiview.GraphModification(graph):
|
|||
graph.setVerbose(args.verbose)
|
||||
|
||||
if args.output:
|
||||
publish = getOnlyNodeOfType(graph, 'Publish')
|
||||
publish.output.value = args.output
|
||||
# if there is more than 1 Publish node, they will all be set to the same output;
|
||||
# depending on what they are connected to, some input files might be overwritten in the output folder
|
||||
# (e.g. if two Publish nodes are connected to two Texturing nodes)
|
||||
publishNodes = graph.nodesOfType('Publish')
|
||||
if len(publishNodes) > 0:
|
||||
for node in publishNodes:
|
||||
node.output.value = args.output
|
||||
else:
|
||||
raise RuntimeError("meshroom_batch requires a pipeline graph with at least one Publish node, none found.")
|
||||
|
||||
if args.overrides:
|
||||
import json
|
||||
|
|
|
@ -241,7 +241,7 @@ class Graph(BaseObject):
|
|||
return Graph.IO.getFeaturesForVersion(self.header.get(Graph.IO.Keys.FileVersion, "0.0"))
|
||||
|
||||
@Slot(str)
|
||||
def load(self, filepath, setupProjectFile=True, importProject=False):
|
||||
def load(self, filepath, setupProjectFile=True, importProject=False, publishOutputs=False):
|
||||
"""
|
||||
Load a meshroom graph ".mg" file.
|
||||
|
||||
|
@ -249,6 +249,9 @@ class Graph(BaseObject):
|
|||
filepath: project filepath to load
|
||||
setupProjectFile: Store the reference to the project file and setup the cache directory.
|
||||
If false, it only loads the graph of the project file as a template.
|
||||
importProject: True if the project that is loaded will be imported in the current graph, instead
|
||||
of opened.
|
||||
publishOutputs: True if "Publish" nodes from templates should not be ignored.
|
||||
"""
|
||||
if not importProject:
|
||||
self.clear()
|
||||
|
@ -284,6 +287,11 @@ class Graph(BaseObject):
|
|||
if "version" not in nodeData:
|
||||
nodeData["version"] = nodesVersions.get(nodeData["nodeType"], "0.0")
|
||||
|
||||
# if the node is a "Publish" node and comes from a template file, it should be ignored
|
||||
# unless publishOutputs is True
|
||||
if isTemplate and not publishOutputs and nodeData["nodeType"] == "Publish":
|
||||
continue
|
||||
|
||||
n = nodeFactory(nodeData, nodeName, template=isTemplate)
|
||||
|
||||
# Add node to the graph with raw attributes values
|
||||
|
|
|
@ -350,9 +350,9 @@ class UIGraph(QObject):
|
|||
self._chunksMonitor.stop()
|
||||
|
||||
@Slot(str, result=bool)
|
||||
def loadGraph(self, filepath, setupProjectFile=True):
|
||||
def loadGraph(self, filepath, setupProjectFile=True, publishOutputs=False):
|
||||
g = Graph('')
|
||||
status = g.load(filepath, setupProjectFile)
|
||||
status = g.load(filepath, setupProjectFile, importProject=False, publishOutputs=publishOutputs)
|
||||
if not os.path.exists(g.cacheDir):
|
||||
os.mkdir(g.cacheDir)
|
||||
self.setGraph(g)
|
||||
|
|
|
@ -488,9 +488,9 @@ class Reconstruction(UIGraph):
|
|||
self.load(p, setupProjectFile=False)
|
||||
|
||||
@Slot(str, result=bool)
|
||||
def load(self, filepath, setupProjectFile=True):
|
||||
def load(self, filepath, setupProjectFile=True, publishOutputs=False):
|
||||
try:
|
||||
status = super(Reconstruction, self).loadGraph(filepath, setupProjectFile)
|
||||
status = super(Reconstruction, self).loadGraph(filepath, setupProjectFile, publishOutputs)
|
||||
# warn about pre-release projects being automatically upgraded
|
||||
if Version(self._graph.fileReleaseVersion).major == "0":
|
||||
self.warning.emit(Message(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue