Ejemplo n.º 1
0
        /// <summary>
        /// Parses the camera setup from a directory containing an "images" folder with an image dataset from the Stanford Light Field Archive, and saves the parsed setup in this directory.
        /// </summary>
        public void ParseCameraSetup()
        {
            // Inform of process start.
            Debug.Log(GeneralToolkit.FormatScriptMessage(this.GetType(), "Started parsing camera setup for an image dataset from the Stanford Light Field Archive located at: " + dataHandler.colorDirectory + "."));
            // Get the files in the "images" folder.
            FileInfo[] fileInfos = GeneralToolkit.GetFilesByExtension(dataHandler.colorDirectory, ".png");
            // Determine the pixel resolution of the images.
            Texture2D tempTex = new Texture2D(1, 1);

            GeneralToolkit.LoadTexture(fileInfos[0].FullName, ref tempTex);
            Vector2Int pixelResolution = new Vector2Int(tempTex.width, tempTex.height);

            DestroyImmediate(tempTex);
            // Prepare repositioning around center if it is selected.
            Vector3 meanPos = Vector3.zero;

            // Reset the camera models to fit the color count.
            _cameraSetup.ResetCameraModels();
            _cameraSetup.cameraModels = new CameraModel[dataHandler.sourceColorCount];
            // Iteratively add each camera model to the setup.
            for (int iter = 0; iter < dataHandler.sourceColorCount; iter++)
            {
                CameraModel cameraModel = _cameraSetup.AddCameraModel(iter);
                // Store the image's pixel resolution in the camera model.
                cameraModel.pixelResolution = pixelResolution;
                // Store the image's name in the camera model.
                FileInfo fileInfo = fileInfos[iter];
                cameraModel.SetCameraReferenceIndexAndImageName(cameraModel.cameraReferenceIndex, fileInfo.Name);
                // Store the image's position in the model.
                string[] split     = fileInfo.Name.Split('_');
                float    positionY = -GeneralToolkit.ParseFloat(split[split.Length - 3]);
                float    positionX = GeneralToolkit.ParseFloat(split[split.Length - 2]);
                Vector3  pos       = scaleFactor * new Vector3(positionX, positionY, 0);
                cameraModel.transform.position = pos;
                meanPos += pos;
            }
            // If it is selected, reposition the camera setup around its center position.
            if (repositionAroundCenter)
            {
                meanPos /= dataHandler.sourceColorCount;
                for (int iter = 0; iter < dataHandler.sourceColorCount; iter++)
                {
                    CameraModel cameraModel = _cameraSetup.cameraModels[iter];
                    cameraModel.transform.position = cameraModel.transform.position - meanPos;
                }
            }
            // Temporarily move the color images to a safe location.
            string tempDirectoryPath = Path.Combine(GeneralToolkit.GetDirectoryBefore(dataHandler.dataDirectory), "temp");

            GeneralToolkit.Move(PathType.Directory, dataHandler.colorDirectory, tempDirectoryPath);
            // Save the camera setup information (this would also have cleared the "images" folder if it was still there).
            Acquisition.Acquisition.SaveAcquisitionInformation(dataHandler, cameraSetup);
            // Move the color images back into their original location.
            GeneralToolkit.Delete(dataHandler.colorDirectory);
            GeneralToolkit.Move(PathType.Directory, tempDirectoryPath, dataHandler.colorDirectory);
            // Update the camera models of the setup object.
            _cameraSetup.FindCameraModels();
            // Inform of end of process.
            Debug.Log(GeneralToolkit.FormatScriptMessage(this.GetType(), "Finished parsing camera setup. Result can be previewed in the Scene view."));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Processes color and/or depth data.
        /// </summary>
        /// <returns></returns>
        private IEnumerator ProcessDataCoroutine()
        {
            // Inform the user that the process has started.
            GeneralToolkit.ResetCancelableProgressBar(true, true);
            Debug.Log(GeneralToolkit.FormatScriptMessage(typeof(Processing), "Started processing data."));
            processingCanceled = false;
            // Save the current position, rotation, and scale for later.
            Vector3    position = transform.position;
            Quaternion rotation = transform.rotation;
            Vector3    scale    = transform.localScale;

            // Reset the transform, and wait for the camera models to be updated accordingly.
            GeneralToolkit.SetTransformValues(transform, false, Vector3.zero, Quaternion.identity, Vector3.one);
            yield return(null);

            // Create the processed data directory and initialize the processing information file.
            dataHandler.CreateProcessingInfoFile();
            // Move the processed data directory to the temporary directory.
            GeneralToolkit.Move(PathType.Directory, dataHandler.processedDataDirectory, GeneralToolkit.tempDirectoryAbsolutePath, false);
            AssetDatabase.Refresh();
            if (!Directory.Exists(GeneralToolkit.tempDirectoryAbsolutePath))
            {
                processingCanceled = true;
            }
            // Execute the processing methods.
            for (int iter = 0; iter < processingMethods.Length; iter++)
            {
                ProcessingMethod processingMethod = processingMethods[iter];
                if (!processingMethod.IsGUINested() && processingMethod.shouldExecute)
                {
                    yield return(StartCoroutine(processingMethod.ExecuteAndDisplayLog()));
                }
                if (processingCanceled)
                {
                    break;
                }
            }
            // Unload loaded assets.
            Resources.UnloadUnusedAssets();
            EditorUtility.UnloadUnusedAssetsImmediate();
            yield return(null);

            // Move the processed data directory back to its original position.
            GeneralToolkit.Move(PathType.Directory, GeneralToolkit.tempDirectoryAbsolutePath, dataHandler.processedDataDirectory, false);
            AssetDatabase.Refresh();
            // Update the processed asset information.
            dataHandler.UpdateProcessedAssets();
            // Inform the user of the end of the process.
            if (!processingCanceled)
            {
                Debug.Log(GeneralToolkit.FormatScriptMessage(typeof(Processing), "Finished processing data."));
            }
            else
            {
                Debug.Log(GeneralToolkit.FormatScriptMessage(typeof(Processing), "Processing was canceled."));
            }
            // Perform a check to verify whether data was processed.
            dataHandler.CheckStatusOfDataProcessingAndBundling(out isDataReadyForBundling, out isDataBundled, out processedDataInfo);
            // Return the transform's values to their previous ones.
            GeneralToolkit.SetTransformValues(transform, false, position, rotation, scale);
            // Reset the progress bar.
            GeneralToolkit.ResetCancelableProgressBar(false, false);
        }