From 42e6c167ee783ba27c7951cafc015f96302080a7 Mon Sep 17 00:00:00 2001 From: David Cattermole Date: Sun, 2 Jan 2022 12:25:55 +1100 Subject: [PATCH] 'mmSolver -sceneGraphMode' command flag; use Maya DAG or mmSceneGraph. Use '0' for Maya DAG (the default value for now), or use '1' for mmSceneGraph. The Maya DAG should be used for backwards compatibility and the full feature set, but mmSceneGraph should provide improved performance for simplier use-cases. Issue #114. --- docs/source/commands.rst | 1 + src/MMSolverCmd.cpp | 15 ++++++++++++--- src/MMSolverCmd.h | 4 ++++ src/core/bundleAdjust_base.cpp | 2 +- src/core/bundleAdjust_data.h | 4 ++-- src/core/bundleAdjust_defines.h | 8 ++++++++ src/core/bundleAdjust_solveFunc.cpp | 4 ++-- 7 files changed, 30 insertions(+), 8 deletions(-) diff --git a/docs/source/commands.rst b/docs/source/commands.rst index 1f90ad985..76fac9b08 100644 --- a/docs/source/commands.rst +++ b/docs/source/commands.rst @@ -24,6 +24,7 @@ Flag Type Description -attrStiffness (-asf) string, string, string, string Node attribute, weight plug name, variance plug name, value plug name. None -attrSmoothness (-asm) string, string, string, string Node attribute, weight plug name, variance plug name, value plug name. None -solverType (-st) unsigned int Type of solver to use. +-sceneGraphMode (-sgm) unsigned int The Scene Graph used; 0=Maya DAG, 1=MM Scene Graph 0 (Maya DAG) -timeEvalMode (-tem) unsigned int How to evalulate values at different times, 0=DG Context 1=Set TIme 0 (DG Context) -iterations (-it) unsigned int Maximum number of iterations 20 -tauFactor (-t) double Initial Damping Factor 1E-03 diff --git a/src/MMSolverCmd.cpp b/src/MMSolverCmd.cpp index 099e32c82..5264ebf66 100644 --- a/src/MMSolverCmd.cpp +++ b/src/MMSolverCmd.cpp @@ -113,6 +113,8 @@ void createSolveInfoSyntax(MSyntax &syntax) { syntax.addFlag(REMOVE_UNUSED_ATTRIBUTES_FLAG, REMOVE_UNUSED_ATTRIBUTES_FLAG_LONG, MSyntax::kBoolean); + syntax.addFlag(SCENE_GRAPH_MODE_FLAG, SCENE_GRAPH_MODE_FLAG_LONG, + MSyntax::kUnsigned); syntax.addFlag(TIME_EVAL_MODE_FLAG, TIME_EVAL_MODE_FLAG_LONG, MSyntax::kUnsigned); } @@ -187,6 +189,7 @@ MStatus parseSolveInfoArguments(const MArgDatabase &argData, int &out_robustLossType, double &out_robustLossScale, int &out_solverType, + SceneGraphMode &out_sceneGraphMode, int &out_timeEvalMode, bool &out_acceptOnlyBetter, bool &out_supportAutoDiffForward, @@ -212,6 +215,14 @@ MStatus parseSolveInfoArguments(const MArgDatabase &argData, CHECK_MSTATUS_AND_RETURN_IT(status); } + // Get 'Scene Graph Mode' + uint32_t sceneGraphMode = SCENE_GRAPH_MODE_DEFAULT_VALUE; + if (argData.isFlagSet(SCENE_GRAPH_MODE_FLAG)) { + status = argData.getFlagArgument(SCENE_GRAPH_MODE_FLAG, 0, sceneGraphMode); + CHECK_MSTATUS_AND_RETURN_IT(status); + } + out_sceneGraphMode = static_cast(sceneGraphMode); + // Get 'Time Evaluation Mode' out_timeEvalMode = TIME_EVAL_MODE_DEFAULT_VALUE; if (argData.isFlagSet(TIME_EVAL_MODE_FLAG)) { @@ -396,6 +407,7 @@ MStatus MMSolverCmd::parseArgs(const MArgList &args) { m_robustLossType, m_robustLossScale, m_solverType, + m_sceneGraphMode, m_timeEvalMode, m_acceptOnlyBetter, m_supportAutoDiffForward, @@ -445,9 +457,6 @@ MStatus MMSolverCmd::doIt(const MArgList &args) { // of edits. m_curveChange.setInteractive(true); - // m_sceneGraphMode = SceneGraphMode::kMaya; - m_sceneGraphMode = SceneGraphMode::kMMSceneGraph; - SolverOptions solverOptions; solverOptions.iterMax = m_iterations; solverOptions.tau = m_tau; diff --git a/src/MMSolverCmd.h b/src/MMSolverCmd.h index 456ee92cb..58015895f 100644 --- a/src/MMSolverCmd.h +++ b/src/MMSolverCmd.h @@ -74,6 +74,10 @@ #define SOLVER_TYPE_FLAG "-st" #define SOLVER_TYPE_FLAG_LONG "-solverType" +// The Scene Graph used for evaluation. +#define SCENE_GRAPH_MODE_FLAG "-sgm" +#define SCENE_GRAPH_MODE_FLAG_LONG "-sceneGraphMode" + // Time Evaluation Mode // // How should the solver evaluate time? Should we use DG Context, or diff --git a/src/core/bundleAdjust_base.cpp b/src/core/bundleAdjust_base.cpp index b440dbfa9..caa54e8de 100644 --- a/src/core/bundleAdjust_base.cpp +++ b/src/core/bundleAdjust_base.cpp @@ -1300,7 +1300,7 @@ bool solve(SolverOptions &solverOptions, auto mmsgBundleNodes = std::vector(); auto mmsgMarkerNodes = std::vector(); auto mmsgAttrIdList = std::vector(); - if (solverOptions.sceneGraphMode == SceneGraphMode::kMaya) { + if (solverOptions.sceneGraphMode == SceneGraphMode::kMayaDag) { } else if (solverOptions.sceneGraphMode == SceneGraphMode::kMMSceneGraph) { status = construct_scene_graph( cameraList, diff --git a/src/core/bundleAdjust_data.h b/src/core/bundleAdjust_data.h index 5e4d6dccc..ca967c765 100644 --- a/src/core/bundleAdjust_data.h +++ b/src/core/bundleAdjust_data.h @@ -68,8 +68,8 @@ struct SolverTimer { enum class SceneGraphMode { - kMaya = 0, - kMMSceneGraph = 1, + kMayaDag = SCENE_GRAPH_MODE_MAYA_DAG, + kMMSceneGraph = SCENE_GRAPH_MODE_MM_SCENE_GRAPH, kNumSceneGraphModes, }; diff --git a/src/core/bundleAdjust_defines.h b/src/core/bundleAdjust_defines.h index 4e0dacaa6..1d313de28 100644 --- a/src/core/bundleAdjust_defines.h +++ b/src/core/bundleAdjust_defines.h @@ -68,6 +68,14 @@ #define TIME_EVAL_MODE_DG_CONTEXT (0) #define TIME_EVAL_MODE_SET_TIME (1) +// What Scene Graph should we use for evaluation? +// +// These are the possible values: +#define SCENE_GRAPH_MODE_MAYA_DAG (0) +#define SCENE_GRAPH_MODE_MM_SCENE_GRAPH (1) +// The default value +#define SCENE_GRAPH_MODE_DEFAULT_VALUE SCENE_GRAPH_MODE_MAYA_DAG + // Print Statistics for mmSolver command. // // These are the possible values: diff --git a/src/core/bundleAdjust_solveFunc.cpp b/src/core/bundleAdjust_solveFunc.cpp index 1e8aebc77..05627ff22 100644 --- a/src/core/bundleAdjust_solveFunc.cpp +++ b/src/core/bundleAdjust_solveFunc.cpp @@ -295,7 +295,7 @@ void setParameters( #endif const SceneGraphMode sceneGraphMode = ud->solverOptions->sceneGraphMode; - if (sceneGraphMode == SceneGraphMode::kMaya) { + if (sceneGraphMode == SceneGraphMode::kMayaDag) { setParameters_mayaDag( numberOfParameters, parameters, @@ -731,7 +731,7 @@ void measureErrors( assert(ud->frameList.length() > 0); const SceneGraphMode sceneGraphMode = ud->solverOptions->sceneGraphMode; - if (sceneGraphMode == SceneGraphMode::kMaya) { + if (sceneGraphMode == SceneGraphMode::kMayaDag) { measureErrors_mayaDag( numberOfErrors, numberOfMarkerErrors,