Пример #1
0
        public AppVM()
        {
            server              = new Server();
            server.SensorAdded += OnSensorAdded;

            // setup sensor-bone links
            SensorBoneMap            = new SensorBoneMap();
            sensorBoneLinkVMs        = new Dictionary <SensorBoneLink, SensorBoneLinkVM>();
            SensorBoneMap.LinkAdded += (link) =>
            {
                sensorBoneLinkVMs.Add(link, new SensorBoneLinkVM(link, sensorVMs[link.Sensor], Kinematic.BoneVMMap[link.Bone]));
                RootVisual3D.Children.Add(sensorBoneLinkVMs[link].Visual);
            };
            SensorBoneMap.LinkRemoved += (link) =>
            {
                RootVisual3D.Children.Remove(sensorBoneLinkVMs[link].Visual);
                sensorBoneLinkVMs.Remove(link);
            };

            // setup sensors collection
            sensors   = new ObservableCollection <SensorVM>();
            sensorVMs = new Dictionary <Sensor, SensorVM>();
            Sensors   = new ReadOnlyObservableCollection <SensorVM>(sensors);
            foreach (var item in server.Sensors.Values)
            {
                sensors.Add(new SensorVM(item));
                sensorVMs.Add(item, sensors.Last());
            }

            // setup kinematic chain
            Kinematic = new KinematicVM(new KinematicStructure());

            // setup animator
            Animator = new KinematicAnimatorVM(Kinematic, new MotionData());

            // setup commands
            LoadBVHFileCommand            = new RelayCommand <string>(LoadBVHFile);
            SaveBVHFileCommand            = new RelayCommand <string>(SaveBVHFile);
            AssignSensorToBoneCommand     = new RelayCommand <Tuple <BoneVM, SensorVM> >(AssignSensorToBone);
            StartCaptureCommand           = new RelayCommand(StartCapture, CanStartCapture);
            StopCaptureCommand            = new RelayCommand(StopCapture, CanStopCapture);
            SetBaseRotationCommand        = new RelayCommand(SetBaseRotation);
            StartSensorCalibrationCommand = new RelayCommand <SensorBoneLinkVM>(StartSensorCalibration, CanStartSensorCalibration);
            StopSensorCalibrationCommand  = new RelayCommand(StopAxisCalibration);

            // ui update timer
            refreshTimer          = new DispatcherTimer(DispatcherPriority.Background);
            refreshTimer.Interval = TimeSpan.FromMilliseconds(30);
            refreshTimer.Start();
            refreshTimer.Tick += OnRefreshTick;
        }
Пример #2
0
        /// <summary>
        /// is called by the refreshTimer. Raises UI updates
        /// </summary>
        private void OnRefreshTick(object sender, EventArgs e)
        {
            foreach (var item in Sensors)
            {
                item.Refresh();
            }

            foreach (var item in sensorBoneLinkVMs.Values)
            {
                item.Refresh();
            }

            if (State == AppState.Running)
            {
                var orientations = SensorBoneMap.GetCalibratedSensorOrientations();
                Kinematic.Model.ApplyWorldRotations(orientations);
            }

            Kinematic.Refresh();
        }
Пример #3
0
        /// <summary>
        /// assign a sensor to a bone
        /// </summary>
        private void AssignSensorToBone(Tuple <BoneVM, SensorVM> pair)
        {
            var bone   = pair.Item1;
            var sensor = pair.Item2;

            SensorBoneLink newLink = null;

            if (sensor == null)
            { //remove existing links
                SensorBoneMap.RemoveLink(bone.Model);
            }
            else
            { //add new link
                newLink = SensorBoneMap.CreateLink(bone.Model, sensor.Model);
            }

            if (newLink != null)
            {
                bone.SensorBoneLink = sensorBoneLinkVMs[newLink];
            }
        }