/// <summary>
        /// Resets the object's properties.
        /// </summary>
        void Reset()
        {
            // Set the default values.
            UpdateRenderingObjectsList();
            launchOrderIndex      = renderingObjectCount;
            readyToBeLaunched     = false;
            _launchOnAwake        = true;
            _launched             = false;
            _previewRenderTexture = null;
            _previewEvalTexture   = null;
            // Get the processing component. If this was not called on AddComponent, reset it as well.
            _processing = GeneralToolkit.GetOrAddComponent <Processing.Processing>(gameObject);
            if (_processing.renderingCaller != null)
            {
                _processing.Reset();
            }
            else
            {
                _processing.renderingCaller = this;
            }
            // Initialize the rendering methods and helpers. This has to be done after the processing component has been reset.
            _renderingMethods = RenderingMethod.CreateOrResetRenderingMethods(transform);
            Method[] methods = GetComponentsInChildren <Method>();
            for (int iter = 0; iter < methods.Length; iter++)
            {
                methods[iter].InitializeLinks();
            }
            // Initialize the evaluation methods.
            _evaluationMethods = EvaluationMethod.GetOrCreateEvaluationMethods(transform);
#if UNITY_EDITOR
            UnityEditorInternal.InternalEditorUtility.SetIsInspectorExpanded(processing, false);
#endif //UNITY_EDITOR
        }
示例#2
0
 /// <summary>
 /// Resets the camera parameters and geometry processing parameters.
 /// </summary>
 void Reset()
 {
     // Reset the processing object.
     processing = GeneralToolkit.GetOrCreateChildComponent <Processing.Processing>(transform);
     processing.Reset();
     // Reset the geometry processing parameters.
     _geometryProcessingMethod = (Processing.PerViewMeshesQSTR)processing.processingMethods[ProcessingMethod.indexPerViewMeshesQSTR];
 }
示例#3
0
        /// <summary>
        /// Coroutine that converts a .PLY mesh to a .OBJ file.
        /// </summary>
        /// <param name="caller"></param> The processing object calling this method.
        /// <param name="inputFilePath"></param> The full path to the input .PLY file.
        /// <param name="outputFilePath"></param> The full path to the output .OBJ file.
        /// <param name="storeFaceCount"></param> Action that stores the mesh's face count.
        /// <returns></returns>
        public static IEnumerator RunConvertPLYtoOBJCoroutine(Processing.Processing caller, string inputFilePath, string outputFilePath, System.Diagnostics.DataReceivedEventHandler storeFaceCount)
        {
            // Initialize the coroutine.
            bool displayProgressBar; bool stopOnError; string[] progressBarParams;

            InitBlenderCoroutine(true, out displayProgressBar, out stopOnError, out progressBarParams);
            progressBarParams[1] = "Convert .PLY to .OBJ";
            // Launch the command.
            string command = FormatBlenderCommand(_convertPLYtoOBJFileName, inputFilePath, outputFilePath);

            yield return(caller.StartCoroutine(GeneralToolkit.RunCommandCoroutine(typeof(BlenderConnector), command, _externalPythonScriptsDir, displayProgressBar, storeFaceCount, _harmlessWarnings, stopOnError, progressBarParams)));

            // Clear the coroutine.
            ClearBlenderCoroutine();
            // Update the GUI to indicate that a mesh has been created.
            caller.Deselected();
            caller.Selected();
        }
 /// <inheritdoc/>
 public override void OnEnable()
 {
     base.OnEnable();
     _targetProcessing = ((PerViewMeshesQSTREF)_targetObject).processing;
 }
        /// <summary>
        /// Coroutine that runs the sparse reconstruction process.
        /// </summary>
        /// <param name="caller"></param> The processing object calling this method.
        /// <param name="workspace"></param> The workspace from which to perform this method.
        /// <param name="COLMAPCameraIndex"></param> The index of the type of source camera (in the list of COLMAP cameras).
        /// <param name="isSingleCamera"></param> True if the source images were acquired by the same camera, false otherwise.
        /// <param name="maxImageSize"></param> The maximum image size for the undistortion step.
        /// <returns></returns>
        public static IEnumerator RunSparseReconstructionCoroutine(Processing.Processing caller, string workspace, int COLMAPCameraIndex, bool isSingleCamera, int maxImageSize)
        {
            // Indicate to the user that the process has started.
            GeneralToolkit.ResetCancelableProgressBar(true, true);
            // Create or clear the folders needed for the reconstruction.
            GeneralToolkit.Delete(GetDatabaseFile(workspace));
            GeneralToolkit.CreateOrClear(PathType.Directory, GetSparseDir(workspace));
            GeneralToolkit.CreateOrClear(PathType.Directory, GetSparse0Dir(workspace));
            GeneralToolkit.CreateOrClear(PathType.Directory, GetDenseDir(workspace));
            GeneralToolkit.CreateOrClear(PathType.Directory, GetDense0Dir(workspace));
            // Initialize the command parameters.
            bool displayProgressBar = true;
            bool stopOnError        = true;

            string[] progressBarParams = new string[3];
            int      maxStep           = 6;

            progressBarParams[0] = GeneralToolkit.ToString(maxStep);
            progressBarParams[2] = "Processing canceled by user.";
            // Launch the different steps of the sparse reconstruction process.
            float focalLengthFactor = 0;

            for (int step = 1; step <= maxStep; step++)
            {
                // Step one: launch feature extraction.
                if (step == 1)
                {
                    progressBarParams[1] = GetProgressBarParamsOne("Feature extraction", true, step, maxStep);
                    CameraModel[] cameraModels = caller.cameraSetup.cameraModels;
                    if (cameraModels != null && cameraModels.Length > 0)
                    {
                        CameraModel cameraParams = cameraModels[0];
                        float       focalLength  = Camera.FieldOfViewToFocalLength(cameraParams.fieldOfView.x, cameraParams.pixelResolution.x);
                        focalLengthFactor = focalLength / Mathf.Max(cameraParams.pixelResolution.x, cameraParams.pixelResolution.y);
                    }
                    yield return(caller.StartCoroutine(RunFeatureExtractionCommand(caller, workspace, displayProgressBar, stopOnError, progressBarParams, COLMAPCameraIndex, isSingleCamera, focalLengthFactor)));
                }
                // Step two: launch feature matching.
                else if (step == 2)
                {
                    progressBarParams[1] = GetProgressBarParamsOne("Feature matching", true, step, maxStep);
                    yield return(caller.StartCoroutine(RunFeatureMatchingCommand(caller, workspace, displayProgressBar, stopOnError, progressBarParams)));
                }
                // Step three: launch mapping.
                else if (step == 3)
                {
                    progressBarParams[1] = GetProgressBarParamsOne("Mapping", true, step, maxStep);
                    yield return(caller.StartCoroutine(RunMappingCommand(caller, workspace, displayProgressBar, stopOnError, progressBarParams, (focalLengthFactor > 0))));
                }
                // Step four: launch exporting original camera setup as text.
                else if (step == 4)
                {
                    progressBarParams[1] = GetProgressBarParamsOne("Exporting camera setup (original) as text", true, step, maxStep);
                    yield return(caller.StartCoroutine(RunExportModelAsTextCommand(caller, workspace, displayProgressBar, stopOnError, progressBarParams)));
                }
                // Step five: launch image undistortion.
                else if (step == 5)
                {
                    // Launch undistortion.
                    progressBarParams[1] = GetProgressBarParamsOne("Undistortion", true, step, maxStep);
                    yield return(caller.StartCoroutine(RunUndistortionCommand(caller, workspace, displayProgressBar, stopOnError, progressBarParams, maxImageSize)));
                    // Change the workspace and the data directory to the one created in the dense folder.
                    // workspace = GetDense0Dir(workspace);
                    // caller.dataHandler.ChangeDataDirectory(caller, workspace);
                    // Debug.Log(GeneralToolkit.FormatScriptMessage(typeof(COLMAPConnector), "Changed data directory to: " + workspace));
                }
                // Step six: launch exporting undistorted camera setup as text.
                else if (step == 6)
                {
                    // Launch export process.
                    progressBarParams[1] = GetProgressBarParamsOne("Exporting camera setup (undistorted) as text", true, step, maxStep);
                    yield return(caller.StartCoroutine(RunExportModelAsTextCommand(caller, GetDense0Dir(workspace), displayProgressBar, stopOnError, progressBarParams)));

                    // Display the parsed camera setup in the Scene view.
                    caller.Deselected();
                    caller.Selected();
                    yield return(null);
                }
                // For each step, continue only if the user does not cancel the process.
                if (GeneralToolkit.progressBarCanceled)
                {
                    break;
                }
            }
            // Change the data directory to the one created in the dense folder.
            if (!GeneralToolkit.progressBarCanceled)
            {
                Debug.Log(GeneralToolkit.FormatScriptMessage(typeof(COLMAPConnector), "Sparse reconstruction was a success."));
            }
            // Indicate to the user that the process has ended.
            GeneralToolkit.ResetCancelableProgressBar(false, false);
        }