/// <summary>
        /// Fetches the global mesh and initializes the camera and materials.
        /// </summary>
        private void InitializePerCall()
        {
            // Deactivate any other renderer in the scene.
            _deactivatedRendererGOs = GeneralToolkit.DeactivateOtherActiveComponents <Renderer>(gameObject);
            // Create a preview camera manager and initialize it with the camera model's pose and parameters.
            _previewCameraModel = CameraModel.CreateCameraModel();
            _previewCameraModel.transform.position = Vector3.zero;
            _previewCameraModel.transform.rotation = Quaternion.identity;
            _previewCameraModel.fieldOfView        = 60f * Vector2.one;
            float focalLength = Camera.FieldOfViewToFocalLength(_previewCameraModel.fieldOfView.x, 1f);

            _previewCameraManager = new GameObject("Preview Camera Manager").AddComponent <PreviewCameraManager>();
            Transform previewCameraTransform = new GameObject("Preview Camera").transform;

            GeneralToolkit.CreateRenderTexture(ref _previewCameraManager.targetTexture, Vector2Int.one, 0, RenderTextureFormat.ARGB32, false, FilterMode.Point, TextureWrapMode.Clamp);
            _previewCameraManager.CreatePreviewCamera(_previewCameraManager.gameObject, previewCameraTransform, _previewCameraModel);
            _previewCameraManager.previewCamera.clearFlags      = CameraClearFlags.Color;
            _previewCameraManager.previewCamera.backgroundColor = Color.clear;
            // Create the materials.
            _renderToTextureMapMat = new Material(GeneralToolkit.shaderProcessingGlobalTextureMap);
            _renderToTextureMapMat.SetFloat(_shaderNameFocalLength, focalLength);
            _normalizeByAlphaMat = new Material(GeneralToolkit.shaderNormalizeByAlpha);
            // Initialize the helper object for ULR.
            _helperULR = gameObject.AddComponent <Rendering.Helper_ULR>();
            _helperULR.Reset();
            _helperULR.InitializeLinks();
            _helperULR.blendCamCount         = Rendering.Helper_ULR.maxBlendCamCount;
            _helperULR.numberOfSourceCameras = PMColorTextureArray.colorData.depth;
            _helperULR.CreateULRBuffersAndArrays();
            _helperULR.InitializeBlendingMaterialParameters(ref _renderToTextureMapMat);
            _helperULR.currentBlendingMaterial = _renderToTextureMapMat;
            _helperULR.initialized             = true;
        }
        /// <summary>
        /// Parses the basic parameters of any COLMAP camera model.
        /// </summary>
        /// <param name="split"></param> The split string from which to parse information.
        /// <param name="isOmnidirectional"></param> True if the camera model is omnidirectional, false otherwise.
        /// <returns></returns> A camera model containing the parsed parameters.
        private static CameraModel BasicParse(string[] split, bool isOmnidirectional)
        {
            CameraModel cameraModel = CameraModel.CreateCameraModel();

            // The camera's projection type is not handled by COLMAP, and has to be specified.
            cameraModel.isOmnidirectional = isOmnidirectional;
            // The camera's index is given by the first parameter in the .txt file.
            cameraModel.SetCameraReferenceIndexAndImageName(GeneralToolkit.ParseInt(split[0]), cameraModel.imageName);
            // The camera's pixel resolution is given by the second and third parameters in the .txt file.
            cameraModel.pixelResolution = new Vector2Int(GeneralToolkit.ParseInt(split[2]), GeneralToolkit.ParseInt(split[3]));
            // Return the camera model.
            return(cameraModel);
        }
 /// <summary>
 /// Resets the camera parameters and geometry processing parameters.
 /// </summary>
 void Reset()
 {
     // Reset the camera parameters.
     if (cameraModel == null)
     {
         cameraModel = CameraModel.CreateCameraModel(transform);
     }
     cameraModel.Reset();
     // Reset the geometry processing parameters.
     _geometryProcessingMethod = GeneralToolkit.GetOrCreateChildComponent <COLIBRIVR.Processing.PerViewMeshesQSTR>(transform);
     _geometryProcessingMethod.Reset();
     // Get the preview camera manager.
     _previewCameraManager = GeneralToolkit.GetOrCreateChildComponent <PreviewCameraManager>(transform);
     // Update the displayed preview.
     previewIndex = -1;
     Selected();
 }
        /// <summary>
        /// In play mode, loads the rendered view and the evaluation metric for preview.
        /// </summary>
        public void LoadRenderedViewAsPreview()
        {
            RenderTexture.active = null;
            if (_previewEvalTexture != null)
            {
                DestroyImmediate(_previewEvalTexture);
            }
            if (_previewRenderTexture != null)
            {
                DestroyImmediate(_previewRenderTexture);
            }
            // Check that there are camera models, that the application is playing, and that the object is active.
            if (processing.cameraSetup.cameraModels == null || !Application.isPlaying || !gameObject.activeInHierarchy || !_launched)
            {
                return;
            }
            int previewMaxIndex = processing.cameraSetup.cameraModels.Length - 1;
            // Get the camera model for this index.
            CameraModel tempCameraModel = CameraModel.CreateCameraModel();

            tempCameraModel.ParametersFromCameraModel(processing.cameraSetup.cameraModels[processing.cameraSetup.previewIndex]);
            tempCameraModel.pixelResolution = PreviewWindow.GetPreviewResolution(tempCameraModel.pixelResolution);
            // Display a preview of the rendered view.
            if (selectedBlendingMethod != null && selectedEvaluationMethod != null)
            {
                // Inform the blending method to exclude the source view if desired.
                if (selectedEvaluationMethod.excludeSourceView)
                {
                    selectedBlendingMethod.ExcludeSourceView(processing.cameraSetup.previewIndex);
                }
                // Create a preview camera manager and initialize it with the camera model's pose and parameters.
                PreviewCameraManager previewCameraManager   = new GameObject("Preview Camera Manager").AddComponent <PreviewCameraManager>();
                Transform            previewCameraTransform = new GameObject("Preview Camera").transform;
                GeneralToolkit.CreateRenderTexture(ref previewCameraManager.targetTexture, Vector2Int.one, 0, RenderTextureFormat.ARGB32, false, FilterMode.Point, TextureWrapMode.Clamp);
                previewCameraManager.CreatePreviewCamera(previewCameraManager.gameObject, previewCameraTransform, tempCameraModel);
                previewCameraManager.previewCamera.clearFlags      = CameraClearFlags.Color;
                previewCameraManager.previewCamera.backgroundColor = Color.black;
                // Render the preview camera to a target texture, and display it in the preview window.
                previewCameraManager.RenderPreviewToTarget(ref previewCameraManager.targetTexture, false);
                GeneralToolkit.CreateRenderTexture(ref _previewRenderTexture, tempCameraModel.pixelResolution, 0, RenderTextureFormat.ARGB32, false, FilterMode.Point, TextureWrapMode.Clamp);
                Graphics.Blit(previewCameraManager.targetTexture, _previewRenderTexture);
                PreviewWindow.DisplayImage(_renderCallerName, _previewRenderTexture, previewMaxIndex);
                // Destroy the preview camera manager.
                previewCameraManager.DestroyPreviewCamera();
                DestroyImmediate(previewCameraManager.gameObject);
                // Inform the blending method that it should no longer exclude the source view.
                selectedBlendingMethod.ExcludeSourceView(-1);
            }
            DestroyImmediate(tempCameraModel.gameObject);
            // Display the evaluation metric as an RGB color texture.
            if (selectedEvaluationMethod != null && selectedEvaluationMethod.evaluationMaterial != null)
            {
                // Use a shader to compute the evaluation metric for each pixel and display it as a color value.
                GeneralToolkit.CreateRenderTexture(ref _previewEvalTexture, tempCameraModel.pixelResolution, 0, RenderTextureFormat.ARGB32, true, FilterMode.Point, TextureWrapMode.Clamp);
                selectedEvaluationMethod.evaluationMaterial.SetTexture(EvaluationMethod.shaderNameTextureOne, processing.previewSourceTexture);
                selectedEvaluationMethod.evaluationMaterial.SetTexture(EvaluationMethod.shaderNameTextureTwo, _previewRenderTexture);
                Graphics.Blit(null, _previewEvalTexture, selectedEvaluationMethod.evaluationMaterial);
                // Display the created texture in the preview window.
                PreviewWindow.DisplayImage(_evalCallerName, _previewEvalTexture, previewMaxIndex);
            }
        }