|
| 1 | +__version__ = "1.0" |
| 2 | + |
| 3 | +from meshroom.core import desc |
| 4 | +from meshroom.core.utils import VERBOSE_LEVEL |
| 5 | + |
| 6 | + |
| 7 | +class SfMChecking(desc.Node): |
| 8 | + |
| 9 | + category = "Utils" |
| 10 | + documentation = """ |
| 11 | + Check an input SfM for validity. |
| 12 | + Throw an error if the SfM does not satisfy constraints. |
| 13 | + """ |
| 14 | + |
| 15 | + inputs = [ |
| 16 | + desc.File( |
| 17 | + name="input", |
| 18 | + label="SfMData", |
| 19 | + description="Input SfMData file.", |
| 20 | + value="", |
| 21 | + ), |
| 22 | + desc.FloatParam( |
| 23 | + name="poseCompletion", |
| 24 | + label="Completion Percentage", |
| 25 | + description="Minimal percent of the views reconstructed.", |
| 26 | + value=80.0, |
| 27 | + range=(0.0, 100.0, 1.0), |
| 28 | + ), |
| 29 | + desc.ChoiceParam( |
| 30 | + name="verboseLevel", |
| 31 | + label="Verbose Level", |
| 32 | + description="Verbosity level (fatal, error, warning, info, debug, trace).", |
| 33 | + values=VERBOSE_LEVEL, |
| 34 | + value="info", |
| 35 | + ) |
| 36 | + ] |
| 37 | + |
| 38 | + outputs = [ |
| 39 | + desc.File( |
| 40 | + name="output", |
| 41 | + label="SfM File", |
| 42 | + description="Path to the output SfM file.", |
| 43 | + value=desc.Node.internalFolder + "sfmData.abc", |
| 44 | + ) |
| 45 | + ] |
| 46 | + |
| 47 | + def processChunk(self, chunk): |
| 48 | + from pyalicevision import sfmData as avsfmdata |
| 49 | + from pyalicevision import sfmDataIO as avsfmdataio |
| 50 | + |
| 51 | + chunk.logManager.start(chunk.node.verboseLevel.value) |
| 52 | + chunk.logger.info("Open input file") |
| 53 | + |
| 54 | + data = avsfmdata.SfMData() |
| 55 | + ret = avsfmdataio.load(data, chunk.node.input.value, avsfmdataio.ALL) |
| 56 | + if not ret: |
| 57 | + chunk.logger.error("Cannot open input") |
| 58 | + chunk.logManager.end() |
| 59 | + raise RuntimeError() |
| 60 | + |
| 61 | + total = len(data.getViews()) |
| 62 | + valid = len(data.getValidViews()) |
| 63 | + ratio = (100.0 * float(valid)) / float(total) |
| 64 | + |
| 65 | + chunk.logger.info(f"Total views: {total}") |
| 66 | + chunk.logger.info(f"Reconstructed views: {valid}") |
| 67 | + chunk.logger.info(f"Percentage of reconstructed views: {ratio}") |
| 68 | + |
| 69 | + if ratio < chunk.node.poseCompletion.value: |
| 70 | + chunk.logger.error("Percentage of reconstructed views is insufficient.") |
| 71 | + chunk.logger.error(f"Expected {chunk.node.poseCompletion.value}, got {ratio}.") |
| 72 | + chunk.logManager.end() |
| 73 | + raise RuntimeError() |
| 74 | + |
| 75 | + avsfmdataio.save(data, chunk.node.output.value, avsfmdataio.ALL) |
| 76 | + |
| 77 | + chunk.logManager.end() |
0 commit comments