Ejemplo n.º 1
0
        /// <inheritdoc/>
        public override void SectionAdditionalParameters()
        {
            SerializedObject serializedObject = new SerializedObject(this);

            serializedObject.Update();
            SerializedProperty propertyGlobalMeshPath = serializedObject.FindProperty(_propertyNameGlobalMeshPathAbsolute);

            // Enable the user to select another mesh by modifying the path.
            if (string.IsNullOrEmpty(_globalMeshPathAbsolute))
            {
                string[]   extensionsArray = new string[] { ".asset", ".obj", ".fbx" };
                FileInfo[] files           = GeneralToolkit.GetFilesByExtension(dataHandler.dataDirectory, extensionsArray);
                if (files.Length > 0)
                {
                    _globalMeshPathAbsolute = files[0].FullName;
                }
            }
            string searchTitle = "Select global mesh";
            string tooltip     = "Select the global mesh to use for rendering.";
            string extensions  = "FBX,fbx,OBJ,obj,ASSET,asset";
            string outPath;
            bool   clicked;

            GeneralToolkit.EditorPathSearch(out clicked, out outPath, PathType.File, _globalMeshPathAbsolute, searchTitle, tooltip, Color.grey, true, extensions);
            propertyGlobalMeshPath.stringValue = outPath;
            serializedObject.ApplyModifiedProperties();
        }
Ejemplo n.º 2
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."));
        }
 /// <summary>
 /// Checks the source data directory for color images, depth maps, and meshes.
 /// </summary>
 public void CheckStatusOfSourceData()
 {
     string[] extensions = new string[] { ".png", ".jpg" };
     // Check the color directory for color images.
     if (Directory.Exists(colorDirectory))
     {
         sourceColorCount = GeneralToolkit.GetFilesByExtension(colorDirectory, extensions).Length;
     }
     else
     {
         sourceColorCount = 0;
     }
     // Check the depth directory for depth maps.
     if (Directory.Exists(depthDirectory))
     {
         sourcePerViewCount = GeneralToolkit.GetFilesByExtension(depthDirectory, extensions).Length;
     }
     else
     {
         sourcePerViewCount = 0;
     }
     extensions = new string[] { ".asset", ".obj", ".fbx" };
     // Check the root directory for meshes.
     sourceGlobalCount = GeneralToolkit.GetFilesByExtension(dataDirectory, extensions).Length;
     // Compile all of this information into an output string for the processing caller.
     if (_processingCaller != null)
     {
         string colorInfo = sourceColorCount + " color image" + ((sourceColorCount == 1) ? string.Empty : "s") + ", ";
         string depthInfo = sourcePerViewCount + " depth map" + ((sourcePerViewCount == 1) ? string.Empty : "s") + ", ";
         string meshInfo  = sourceGlobalCount + " mesh" + ((sourceGlobalCount == 1) ? string.Empty : "es") + ".";
         _processingCaller.sourceDataInfo = "This directory contains: " + colorInfo + depthInfo + meshInfo;
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Checks the source data directory for color images, depth maps, and meshes.
        /// </summary>
        /// <param name="colorCount"></param> Outputs the number of color data samples.
        /// <param name="perViewCount"></param> Outputs the number of per-view geometry samples.
        /// <param name="globalCount"></param> Outputs the number of global geometry samples.
        /// <param name="summary"></param> Outputs a summary of this information as a text string.
        public void CheckStatusOfSourceData(out int colorCount, out int perViewCount, out int globalCount, out string summaryInfo)
        {
            string[] extensions = new string[] { ".png", ".jpg" };
            // Check the color directory for color images.
            if (Directory.Exists(colorDirectory))
            {
                colorCount = GeneralToolkit.GetFilesByExtension(colorDirectory, extensions).Length;
            }
            else
            {
                colorCount = 0;
            }
            // Check the depth directory for depth maps.
            if (Directory.Exists(depthDirectory))
            {
                perViewCount = GeneralToolkit.GetFilesByExtension(depthDirectory, extensions).Length;
            }
            else
            {
                perViewCount = 0;
            }
            extensions = new string[] { ".asset", ".obj", ".fbx" };
            // Check the root directory for meshes.
            globalCount = GeneralToolkit.GetFilesByExtension(dataDirectory, extensions).Length;
            // Compile all of this information into an output string.
            string colorInfo = colorCount + " color image" + ((colorCount == 1) ? string.Empty : "s") + ", ";
            string depthInfo = perViewCount + " depth map" + ((perViewCount == 1) ? string.Empty : "s") + ", ";
            string meshInfo  = globalCount + " mesh" + ((globalCount == 1) ? string.Empty : "es") + ".";

            summaryInfo = "This directory contains: " + colorInfo + depthInfo + meshInfo;
        }
        /// <summary>
        /// Updates the processing information file with the processed asset names.
        /// </summary>
        public void UpdateProcessedAssets()
        {
            FileInfo[]    processedAssetFiles = GeneralToolkit.GetFilesByExtension(processedDataDirectory, ".asset");
            StringBuilder stringBuilder       = new StringBuilder();

            stringBuilder.AppendLine(processingInfoHeader);
            for (int i = 0; i < processedAssetFiles.Length; i++)
            {
                stringBuilder.AppendLine(processedAssetFiles[i].Name.Replace(processedAssetFiles[i].Extension, string.Empty));
            }
            File.WriteAllText(processingInfoFilePath, stringBuilder.ToString());
        }