Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve command line arguments #632

Merged
merged 12 commits into from
Sep 26, 2019
Merged

Improve command line arguments #632

merged 12 commits into from
Sep 26, 2019

Conversation

fabiencastan
Copy link
Member

@fabiencastan fabiencastan commented Sep 12, 2019

Description

This PR improves meshroom_photogrammetry and meshroom command lines.

Features list

  • meshroom_photogrammetry: "--save" does not disable the computation so you can save your batch reconstruction project and open it later interactively in meshroom. Additionnal --compute option if you need only to create a meshroom project file from this command line.
  • "meshroom -h / --help": now provides command line documentation
  • meshroom: new positional argument to set project file
  • meshroom: new "--pipeline" option to override the default pipeline with your own project file. It also supports an environment variable MESHROOM_DEFAULT_PIPELINE.
  • meshroom_photogrammetry: new "--paramOverrides NODE.param=value" allows to set a parameter directly from the command line.

Implementation

  • minor change in photogrammetry() to keep the whole graph creation in a single GraphModification.

…save, add --compute

- add short names for input/output
- change --save option which allow to save the graph used but now do not
replace the computation
- new option to disable the computation (makes sense only if you want to
only save the created project)
- "meshroom -h / --help": now provides command line documentation (so
argparse is done before GUI creation)
- new positional argument to set project file or input folder
- new "--pipeline" option to set a default pipeline, also support an
environment variable
@fabiencastan fabiencastan changed the title Dev/commandline args Improve command line arguments Sep 12, 2019

Args:
filepath: project filepath to load
fileLink: Setup link to the project file, like setup cacheDir, keep filepath for save, etc.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fileLink: Setup link to the project file, like setup cacheDir, keep filepath for save, etc.
fileLink: if false, it only loads the project file as a template (all the data is discarded) and only the bare structure of the graph is preserved.

I found Setup link to the project file, like setup cacheDir, keep filepath for save, etc. a bit obscure/confusing

@@ -234,7 +234,15 @@ def fileFeatures(self):
return Graph.IO.getFeaturesForVersion(self.header.get(Graph.IO.Keys.FileVersion, "0.0"))

@Slot(str)
def load(self, filepath):
def load(self, filepath, fileLink=True):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fileLink is a bit obscure.
why not turn the table and use asTemplate=False. I know that then all the conditions should be negate but it is less obscure than fileLink IMO.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to avoid inverted negation: asTemplate=False will do more actions (setup the cacheDir, etc.) and asTemplate=True to do nothing.
I pushed a proposition for another name that doesn't negate the option: setupFileRef.
Does that sound fine to you?

r.loadUrl(QUrl.fromLocalFile(args.project))
r.load(args.project)

if args.input:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't input and project be exclusive?

At least if project and input both contain a .mg. In this case, I think it would be better to throw an error to let the user know that there is something wrong. (unless it is able to load both projects?)

And if we give project and input with folders, does it add the images to the current project? Something in the same spirit of meshroom_photogrammetry https://github.com/alicevision/meshroom/pull/632/files#diff-4f70151d95f3b3a1c7ea377cbaef3f10R114

# initialize photogrammetry pipeline
if args.pipeline:
    # custom pipeline
    graph = meshroom.core.graph.loadGraph(args.pipeline)
    cameraInit = getOnlyNodeOfType(graph, 'CameraInit')
    # reset graph inputs
    cameraInit.viewpoints.resetValue()
    cameraInit.intrinsics.resetValue()
    # add views and intrinsics (if any) read from args.input
    cameraInit.viewpoints.extend(views)
    cameraInit.intrinsics.extend(intrinsics)

    if not graph.canComputeLeaves:
        raise RuntimeError("Graph cannot be computed. Check for compatibility issues.")

    if args.output:
        publish = getOnlyNodeOfType(graph, 'Publish')
        publish.output.value = args.output
else:
    # default pipeline
    graph = multiview.photogrammetry(inputViewpoints=views, inputIntrinsics=intrinsics, output=args.output)
    cameraInit = getOnlyNodeOfType(graph, 'CameraInit')

if images:
    views, intrinsics = cameraInit.nodeDesc.buildIntrinsics(cameraInit, images)
    cameraInit.viewpoints.value = views
    cameraInit.intrinsics.value = intrinsics

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there is no error for now but that's the usage intention.
So you're right, we can enforce the fact that it should be exclusive.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is changed and I have also added another argument "--import".

@fabiencastan fabiencastan added this to the Meshroom 2019.3.0 milestone Sep 14, 2019
-  explicit error messages
-  allow to combine multiple inputs with new --import and --importRecursive options
@@ -61,9 +61,13 @@ def __init__(self, args):

parser.add_argument('input', metavar='INPUT', type=str, nargs='?',
help='Meshroom project file (e.g. myProject.mg) or folder with images to reconstruct.')
parser.add_argument('--project', metavar='MESHROOM_FILE', type=str, required=False,
parser.add_argument('-i', '--import', metavar='IMAGES/FOLDERS', type=str, nargs='*',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't now the arguments a little bit too redundant?
We can get rid of input at this point and just use project and the imports. It makes life easier, it's more readable and less confusing, and we don't need to check for conflicts. And too bad if we break compatibility, we already broke it with photogrammetry.

@@ -234,14 +234,14 @@ def fileFeatures(self):
return Graph.IO.getFeaturesForVersion(self.header.get(Graph.IO.Keys.FileVersion, "0.0"))

@Slot(str)
def load(self, filepath, fileLink=True):
def load(self, filepath, setupFileRef=True):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about overrideProjectFile?


Args:
filepath: project filepath to load
setupFileRef: Setup reference to the project file, like setup cacheDir, keep filepath for save, etc.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
setupFileRef: Setup reference to the project file, like setup cacheDir, keep filepath for save, etc.
overrideProjectFile: Override the input project file (any changes will be overwritten on the file) and use its cache directories. If false, it only loads the graph of the project file as a template.

@simogasp simogasp added cli anything related to the command line type:enhancement type:pr pull request issue labels Sep 25, 2019
@simogasp simogasp self-assigned this Sep 25, 2019
n.attribute(param).value = value
elif t == '.':
print('Overrides {node}.{param}={value}'.format(node=node, param=param, value=value))
graph.findNode(node).attribute(param).value = value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just asking, findNode(node) can fail in the same way as nodesByType(node)? Shall we manage the error?
Also, very minor thing, I'd put the print after the setting is done so it is not print in case of failure (hopefully findNode(node) or attribute(param) will print or raise some kind of error?)

In case, the same for the previous nodesByType(node)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

findNode is looking for one specific node and fails with an explicit message if it doesn't find it.
nodesByType looks for all nodes of a specific type and can return an empty list without error (that's why there is a specific check to provide an error message).
I put the print before so it's more visible in the error message :s, the last NODE.PARAM is printed and then you have the error message saying that it doesn't find PARAM for instance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli anything related to the command line type:enhancement type:pr pull request issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants