Beispiel #1
0
        /// <summary>
        /// Constructor for loading a session indexed by id into Session instance.
        /// </summary>
        /// <param name="id">SessionId to be loaded</param>
        public SessionViewModel(int id)
        {
            _xmlSessionDoc = new XmlDocument();
            string xmlFilename = System.Configuration.ConfigurationManager.AppSettings["xmlSessionsFile"];

            _xmlSessionDoc.Load(xmlFilename);

            string xpath = "/Sessions/Session[@Id='{0}']";

            xpath = String.Format(xpath, id);

            XmlNode xNode = null;

            xNode = _xmlSessionDoc.DocumentElement.SelectSingleNode(xpath);

            _session = LoadSession(xNode);
        }
        /// <summary>
        /// Loads specific information of the selected session.
        /// </summary>
        public void LoadExecutionModel()
        {
            _selectedId = _app.SessionsViewModel.SelectedSessionId;

            // If there is a selected session, loads it, everytime the tab is selected.
            if (_selectedId > 0)
            {
                _sessionVM = new SessionViewModel(_selectedId);
                _session   = _sessionVM.Session;

                SelectedName   = _session.SessionName;
                HasCalibration = _session.Calibration != null && _session.Calibration.Position != null ? true : false;
            }
            else
            {
                SelectedName = "Selected name not defined.";
            }

            Records = null;
            Records = new List <CameraSpacePoint[]>();
        }
Beispiel #3
0
        /// <summary>
        /// Constructor for editing or removing an existing session.
        /// </summary>
        /// <param name="app">Application View Model - controller of Navigation</param>
        /// <param name="id">Session ID</param>
        /// <param name="isRemove">Flag: true -> Remove Id, false -> Edit</param>
        public SessionViewModel(ApplicationViewModel app, int id, bool isRemove)
        {
            _appViewModel = app;
            _previousPage = app.CurrentPageViewModel;

            // Finds the session and loads its information onto a local object.
            LoadSessions();
            IEnumerable <SessionModel> s = AllSessions.Where(x => x.SessionId == id);

            _session = s.FirstOrDefault();
            _appViewModel.SessionsViewModel.CurrentSession = _session;

            if (!isRemove)
            {
                Operation = "Edit";
            }
            else
            {
                Operation   = "Remove";
                _buttonText = "Confirm?";
            }
        }
Beispiel #4
0
        /// <summary>
        /// Load calibration data of the selected ID. (if a calibration had already been performed.)
        /// Returns the filename of the selected video for calibration
        /// Update calibration information of calibration view model.
        /// </summary>
        /// <param name="onlyFilename">Gets only filename or load full information</param>
        public string LoadCalibrationData(bool onlyFilename)
        {
            string filename = null;

            // This attribution is not inside the constructor method because it may be called every time the page is loaded.
            SessionsViewModel sessionsCtrl = (SessionsViewModel)_app.PageViewModels[0];

            _selectedId = sessionsCtrl.SelectedSessionId;

            if (_selectedId > 0)
            {
                var page = _app.PageViewModels.Where(p => p.Name == "Session View");

                // If exist already an instance of SessionViewModel, then use it, or instantiate one.
                if (page.Any())
                {
                    _sessionVM = (SessionViewModel)page;
                }
                else
                {
                    _sessionVM = new SessionViewModel(_app);
                }

                // Gets persistent Session information.
                xmlSessionDoc = _sessionVM.XmlSessionDoc;

                // Find the selected session in order to pick up the calibration video.
                string xpath = "/Sessions/Session[@Id='{0}']";
                xpath = String.Format(xpath, _selectedId);
                xNode = xmlSessionDoc.DocumentElement.SelectSingleNode(xpath);

                if (xNode != null)
                {
                    _session     = _sessionVM.LoadSession(xNode);
                    SelectedName = _session.SessionName;

                    foreach (VideoModel video in _session.VideoList)
                    {
                        if (video.IsCalibration)
                        {
                            filename = video.Filename;
                        }
                    }

                    if (_session.Calibration != null && !onlyFilename)
                    {
                        _jointType           = _session.Calibration.JointType;
                        NumFrames            = _session.Calibration.NumFrames;
                        CalibrationResult    = _session.Calibration.Position;
                        CalibrationThreshold = _session.Calibration.Threshold;
                        CalibrationSD        = _session.Calibration.SD;
                        InitialTime          = _session.Calibration.InitialTime;
                        CalibrationEstimated = _session.Calibration.Estimated;
                        RightShankLength     = _session.Calibration.RightShankLength;
                        RightThighLength     = _session.Calibration.RightThighLength;
                        LeftShankLength      = _session.Calibration.LeftShankLength;
                        LeftThighLength      = _session.Calibration.LeftThighLength;
                        ConvertSelectedJointIndex();
                        _app.SessionsViewModel.CurrentSession = _session;
                    }
                }
            }

            if (filename == null)
            {
                CalibrationStatus    = "Configuring ....";
                ProcessedFrames      = 0;
                CalibrationResult    = new Vector3(0, 0, 0);
                CalibrationSD        = new Vector3(0, 0, 0);
                CalibrationThreshold = new Vector3(0, 0, 0);
                CalibrationEstimated = new Vector3(0, 0, 0);
                RightThighLength     = 0;
                RightShankLength     = 0;
                LeftThighLength      = 0;
                LeftShankLength      = 0;
                InitialTime          = 0;
                SelectedJointIndex   = 0;
                NumFrames            = 0;
            }

            return(filename);
        }
Beispiel #5
0
        /// <summary>
        /// Loads Xml data of a specific node into SessionModel instance.
        /// </summary>
        /// <param name="node">XMLNode to be loaded int SessionModel instance</param>
        /// <returns></returns>
        public SessionModel LoadSession(XmlNode node)
        {
            SessionModel s = new SessionModel();

            s.SessionId   = Int32.Parse(node.Attributes["Id"].Value);
            s.SessionName = node.Attributes["Name"].Value;
            s.ThighLength = Double.Parse(node.Attributes["Thigh"].Value);
            s.ShankLength = Double.Parse(node.Attributes["Shank"].Value);
            s.SessionDate = node.Attributes["Date"].Value;
            s.Modality    = node.Attributes["Modality"].Value;
            s.SessionType = node.Attributes["Type"].Value;
            s.VideoList   = new ObservableCollection <VideoModel>();

            foreach (XmlNode child in node)
            {
                // Has to check if child is not Calibration
                if (child.Name == "Video")
                {
                    VideoModel video = new VideoModel();

                    video.Sequence = Int32.Parse(child.Attributes["Sequence"].Value);
                    video.Power    = Int32.Parse(child.Attributes["Power"].Value);

                    if (child.Attributes["Calibration"].Value == "True")
                    {
                        video.IsCalibration = true;
                    }
                    else
                    {
                        video.IsCalibration = false;
                    }

                    video.Filename = child.InnerText;

                    s.VideoList.Add(video);
                }
                else if (child.Name == "Calibration")
                {
                    if (s.Calibration == null)
                    {
                        s.Calibration = new CalibrationModel();
                    }
                    s.Calibration.CalSessionId = s.SessionId;
                    s.Calibration.NumFrames    = Int32.Parse(child.Attributes["NumFrames"].Value);
                    s.Calibration.JointType    = (JointType)Int32.Parse(child.Attributes["JointType"].Value);

                    s.Calibration.InitialTime = Int64.Parse(child.Attributes["InitialTime"].Value);

                    // Gets calibration information
                    float x, y, z;
                    x = float.Parse(child.Attributes["X"].Value);
                    y = float.Parse(child.Attributes["Y"].Value);
                    z = float.Parse(child.Attributes["Z"].Value);
                    s.Calibration.Position = new Vector3(x, y, z);

                    // Gets threshold information
                    x = float.Parse(child.Attributes["TX"].Value);
                    y = float.Parse(child.Attributes["TY"].Value);
                    z = float.Parse(child.Attributes["TZ"].Value);
                    s.Calibration.Threshold = new Vector3(x, y, z);

                    // Gets standard deviation information
                    x = float.Parse(child.Attributes["SDX"].Value);
                    y = float.Parse(child.Attributes["SDY"].Value);
                    z = float.Parse(child.Attributes["SDZ"].Value);
                    s.Calibration.SD = new Vector3(x, y, z);

                    // Gets estimated initial joint position information
                    x = float.Parse(child.Attributes["EX"].Value);
                    y = float.Parse(child.Attributes["EY"].Value);
                    z = float.Parse(child.Attributes["EZ"].Value);
                    s.Calibration.Estimated = new Vector3(x, y, z);

                    // Gets segments lengths
                    s.Calibration.LeftShankLength  = double.Parse(child.Attributes["LShank"].Value);
                    s.Calibration.LeftThighLength  = double.Parse(child.Attributes["LThigh"].Value);
                    s.Calibration.RightShankLength = double.Parse(child.Attributes["RShank"].Value);
                    s.Calibration.RightThighLength = double.Parse(child.Attributes["RThigh"].Value);
                }
            }
            return(s);
        }