private static void UpdateDatabaseQuality(AugmentedImageDatabase database) { lock (_updatedQualityScores) { if (_updatedQualityScores.Count == 0) { return; } for (int i = 0; i < database.Count; ++i) { if (_updatedQualityScores.ContainsKey(database[i].TextureGUID)) { AugmentedImageDatabaseEntry updatedImage = database[i]; updatedImage.Quality = _updatedQualityScores[updatedImage.TextureGUID]; database[i] = updatedImage; } } _updatedQualityScores.Clear(); } // For refreshing inspector UI for updated quality scores. EditorUtility.SetDirty(database); }
private static void _RunDirtyQualityJobs(AugmentedImageDatabase database) { if (database == null) { return; } if (s_DatabaseForQualityJobs != database) { // If another database is already running quality evaluation, // stop all pending jobs to prioritise the current database. if (s_DatabaseForQualityJobs != null) { s_QualityBackgroundExecutor.RemoveAllPendingJobs(); } s_DatabaseForQualityJobs = database; } _UpdateDatabaseQuality(database); // Set database dirty to refresh inspector UI for each frame that there are still pending jobs. // Otherwise if there exists one frame with no newly finished jobs, the UI will never get refreshed. // EditorUtility.SetDirty can only be called from main thread. if (s_QualityBackgroundExecutor.PendingJobsCount > 0) { EditorUtility.SetDirty(database); return; } List <AugmentedImageDatabaseEntry> dirtyEntries = database.GetDirtyQualityEntries(); if (dirtyEntries.Count == 0) { return; } string cliBinaryPath; if (!AugmentedImageDatabase.FindCliBinaryPath(out cliBinaryPath)) { return; } for (int i = 0; i < dirtyEntries.Count; ++i) { AugmentedImageDatabaseEntry image = dirtyEntries[i]; var imagePath = AssetDatabase.GetAssetPath(image.Texture); var textureGUID = image.TextureGUID; s_QualityBackgroundExecutor.PushJob(() => { string quality; string error; ShellHelper.RunCommand(cliBinaryPath, string.Format("eval-img --input_image_path \"{0}\"", imagePath), out quality, out error); if (!string.IsNullOrEmpty(error)) { Debug.LogWarning(error); return; } lock (s_UpdatedQualityScores) { s_UpdatedQualityScores.Add(textureGUID, quality); } }); } // For refreshing inspector UI as new jobs have been enqueued. EditorUtility.SetDirty(database); }
private void _DrawImageField(AugmentedImageDatabaseEntry image, out AugmentedImageDatabaseEntry updatedImage, out bool wasRemoved) { updatedImage = new AugmentedImageDatabaseEntry(); EditorGUILayout.BeginVertical(); GUILayout.Space(5); EditorGUILayout.BeginHorizontal(); GUILayout.Space(15); var buttonStyle = new GUIStyle(GUI.skin.button); buttonStyle.margin = new RectOffset(10, 10, 13, 0); wasRemoved = GUILayout.Button("X", buttonStyle); var textFieldStyle = new GUIStyle(GUI.skin.textField); textFieldStyle.margin = new RectOffset(5, 5, 15, 0); updatedImage.Name = EditorGUILayout.TextField(image.Name, textFieldStyle, GUILayout.MaxWidth(80f)); GUILayout.Space(5); updatedImage.Width = EditorGUILayout.FloatField(image.Width, textFieldStyle, GUILayout.MaxWidth(80f)); var labelStyle = new GUIStyle(GUI.skin.label); labelStyle.alignment = TextAnchor.MiddleLeft; GUILayout.Space(5); EditorGUILayout.LabelField(_QualityForDisplay(image.Quality), labelStyle, GUILayout.Height(42), GUILayout.MaxWidth(80f)); GUILayout.FlexibleSpace(); updatedImage.Texture = EditorGUILayout.ObjectField(image.Texture, typeof(Texture2D), false, GUILayout.Height(45), GUILayout.Width(45)) as Texture2D; if (updatedImage.TextureGUID == image.TextureGUID) { updatedImage.Quality = image.Quality; } GUILayout.Space(15); EditorGUILayout.EndHorizontal(); GUILayout.Space(5); EditorGUILayout.EndVertical(); }
public MatchingImage(int databaseIndex_, AugmentedImageDatabaseEntry entry_) { hashCode_ = GetHashCode(); this.databaseIndex_ = databaseIndex_; databaseEntry_ = entry_; databaseEntryTexture_ = entry_.Texture; databaseEntryName_ = entry_.Name; databaseEntryQuality_ = entry_.Quality; databaseEntryWidth_ = entry_.Width; }