Beispiel #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;
        }
Beispiel #2
0
        public KinematicAnimatorVM(KinematicVM kinematic, MotionData motionData)
        {
            this.Kinematic  = kinematic;
            this.MotionData = motionData;

            // setup commands
            PlayCommand   = new RelayCommand(Play, CanPlay);
            PauseCommand  = new RelayCommand(Pause, CanPause);
            RecordCommand = new RelayCommand(Record, CanRecord);
            ClearCommand  = new RelayCommand(ClearData, CanClear);

            timer = new DispatcherTimer(DispatcherPriority.Normal);
            TimeSpan interval = TimeSpan.FromSeconds(1.0 / motionData.FPS);

            timer.Interval = interval;
            timer.Tick    += OnTimerTick;
        }
Beispiel #3
0
        private void LoadBVHFile(string file)
        {
            if (StopCaptureCommand.CanExecute(null))
            {
                StopCaptureCommand.Execute(null);
            }

            BVHMotionData bvhMotionData;
            BVHNode       bvhroot = BVHReaderWriter.ReadBvh(file, out bvhMotionData);

            MotionData newMotionData = new MotionData();

            newMotionData.FPS = 1.0 / bvhMotionData.FrameTime;
            Bone newRoot = BVHConverter.ToBones(bvhroot, null, bvhMotionData, newMotionData);

            // create & assign a new kinematic view model. BoneVMs are also created in this process.
            Kinematic = new KinematicVM(new Core.KinematicStructure(newRoot));
            Animator  = new KinematicAnimatorVM(Kinematic, newMotionData);
        }