private void Start() { Services.StudyManager().SessionFilterEventBroadcast.AddListener(OnSessionFilterChange); Services.StudyManager().TimeFilterEventBroadcast.AddListener(OnTimeFilterUpdate); Services.StudyManager().StudyChangeBroadcast.AddListener(OnStudyChange); Init(); }
/// <summary> /// Loads the study with the provided index. /// </summary> /// <param name="studyIndex">The index of the study to load.</param> public async void LoadStudy(int studyIndex) { _ = ProgressIndicator.StartProgressIndicator("Loading data..."); // tell other clients to also load the study var command = new MessageLoadStudy(studyIndex); Services.NetworkManager().SendMessage(command.Pack()); // delete all current Visualizations Services.VisManager().DeleteAllVisualizations(false); // load the actual data await Services.DataManager().LoadStudyAsync(studyIndex); StudyChangeBroadcast.Invoke(studyIndex); // set session filter (also remotely) Services.StudyManager().UpdateSessionFilter(new List <int> { 0 }, new List <int> { 0 }); _ = ProgressIndicator.StopProgressIndicator(); }
/// <summary> /// Unity start function. /// </summary> public void Start() { Services.NetworkManager().RegisterMessageHandler(MessageContainer.MessageType.CREATE_VISUALIZATION, OnCreateVisualization); Services.NetworkManager().RegisterMessageHandler(MessageContainer.MessageType.CREATE_CONTAINER, OnCreateVisContainer); Services.NetworkManager().RegisterMessageHandler(MessageContainer.MessageType.UPDATE_VISUALIZATION, OnUpdateVisualization); Services.NetworkManager().RegisterMessageHandler(MessageContainer.MessageType.DELETE_VISUALIZATION, OnDeleteVisualization); Services.NetworkManager().RegisterMessageHandler(MessageContainer.MessageType.DELETE_ALL_VISUALIZATIONS, OnDeleteAllVisualizations); Services.NetworkManager().RegisterMessageHandler(MessageContainer.MessageType.DELETE_ALL_CONTAINERS, OnDeleteAllContainers); Services.NetworkManager().RegisterMessageHandler(MessageContainer.MessageType.CENTER_DATA, OnCenterData); Services.StudyManager().SessionFilterEventBroadcast.AddListener(OnSessionFilterChange); Services.StudyManager().StudyChangeBroadcast.AddListener(OnStudyLoaded); }
/// <summary> /// Initializes the <see cref="ViewContainerManager"/>. /// </summary> public void Init() { if (isInitialized) { Reset(); // reset if we are already initialized } if (Services.DataManager() == null || Services.DataManager().CurrentStudy == null) { // no study loaded return; // vis is now reset, we return because there is nothing to load } UpdateSessionFilter(); // update the list of sessions and conditions for (int i = 0; i < Services.DataManager().DataSets.Count; i++) { dataSets.Add(Services.DataManager().DataSets[i]); } // get filter min/max if (Services.StudyManager() != null) { // get min and max time stamp foreach (int s in sessions) { foreach (int c in conditions) { foreach (var dataSet in dataSets) { minTimestamp = Math.Min(dataSet.GetMinTimestamp(s, c), minTimestamp); maxTimestamp = Math.Max(dataSet.GetMaxTimestamp(s, c), maxTimestamp); } } } // set filtered min and max, based on filter value [0,1] and global min/max currentTimeFilterMin = (long)(Services.StudyManager().CurrentTimeFilter.MinTime *(maxTimestamp - minTimestamp)) + minTimestamp; currentTimeFilterMax = (long)(Services.StudyManager().CurrentTimeFilter.MaxTime *(maxTimestamp - minTimestamp)) + minTimestamp; } isInitialized = true; }
private void UpdateViewContainers() { var containers = Services.VisManager().ViewContainers; long currentTime = Services.StudyManager().CurrentTimestamp; foreach (var element in containers) { var id = element.Key; var viewContainer = element.Value; if (viewContainer.ParentId != -1) { // This view container has a parent and could have changed its transform. // get the AnalysisObject that is this container's parent var parent = dataSets.Find( delegate(AnalysisObject obj) { return(obj.Id == viewContainer.ParentId); }); // skip this container if the parent is not part of our list of AnalysisObjects if (parent == null) { viewContainer.gameObject.SetActive(false); continue; } // skip this container if more than one session or condition is selected if (sessions.Count != 1 || conditions.Count != 1) { viewContainer.gameObject.SetActive(false); continue; // ToDo: support multiple sessions and conditions. Ideally, automatically create one ViewContainer per session/condition, keep its settings synced to the others and only show data for the current session/condition } else { // (Settings.Sessions.Count == 1 && Settings.Conditions.Count == 1) if (currentTime < currentTimeFilterMin || currentTime > currentTimeFilterMax) { viewContainer.gameObject.SetActive(false); continue; } viewContainer.gameObject.SetActive(true); // get parent position and orientation at current time stamp int session = sessions[0]; int condition = conditions[0]; Vector3 parentPosition; Quaternion parentOrientation; int earlierIndex = parent.GetIndexFromTimestamp(currentTime, session, condition); var earlierSample = parent.GetInfoObjects(session, condition)[earlierIndex]; if (earlierIndex + 1 >= parent.GetInfoObjects(session, condition).Count || earlierSample.Timestamp >= currentTime) { parentPosition = earlierSample.Position; parentOrientation = earlierSample.Rotation; } else { int laterIndex = earlierIndex + 1; var laterSample = parent.GetInfoObjects(session, condition)[laterIndex]; float interpolant = (currentTime - earlierSample.Timestamp) * 1.0f / (laterSample.Timestamp - earlierSample.Timestamp) * 1.0f; parentPosition = Vector3.Lerp(earlierSample.Position, laterSample.Position, interpolant); parentOrientation = Quaternion.Lerp(earlierSample.Rotation, laterSample.Rotation, interpolant); } // update child container transform accordingly Quaternion newRotation = parentOrientation; Vector3 newPosition = parentPosition + (newRotation * viewContainer.PositionOffset); if (newRotation != viewContainer.transform.localRotation || newPosition != viewContainer.transform.localPosition) { viewContainer.UpdateTransform(newPosition, newRotation); ////viewContainer.transform.localRotation = newRotation; ////viewContainer.transform.localPosition = newPosition; ////viewContainer.transform.hasChanged = true; } } } } }
private void UpdateSessionFilter() { sessions = Services.StudyManager().CurrentStudySessions; conditions = Services.StudyManager().CurrentStudyConditions; }
private void OnSessionFilterChange() { UpdateSessionFilter(Services.StudyManager().CurrentStudySessions, Services.StudyManager().CurrentStudyConditions); }