Esempio n. 1
0
        private void loadPhaseSpace(PhaseSpaceDataReader reader)
        {
            WaitForForm waitForm = new WaitForForm(ctrl => {
                try {
                    _dataSet.ClearFrame();
                    _dataSet.ClearObject();
                    Dictionary <int, uint> index2id = new Dictionary <int, uint>();
                    int count = 1;
                    while (!reader.EndOfStream)
                    {
                        PhaseSpaceFrame inFrame = reader.ReadFrame();

                        MotionFrame outFrame = new MotionFrame(_dataSet, inFrame.Time);
                        for (int i = 0; i < inFrame.Markers.Length; i++)
                        {
                            uint id;
                            if (!index2id.TryGetValue(i, out id))
                            {
                                MotionObjectInfo newInfo = new MotionObjectInfo(typeof(PointObject));
                                newInfo.Name             = PathEx.CombineName("unnamed", (i + 1).ToString());
                                _dataSet.AddObject(newInfo);
                                id = index2id[i] = newInfo.Id;
                            }
                            if (inFrame.Markers[i].Condition > 0)
                            {
                                outFrame[id] = new PointObject(new Vector3(inFrame.Markers[i].X, inFrame.Markers[i].Y, inFrame.Markers[i].Z));
                            }
                        }
                        _dataSet.AddFrame(outFrame);

                        ctrl.ReportProgress(99 - 990000 / (count + 10000), string.Format("Load Frame: {0} ({1} sec)", count, inFrame.Time.ToString("0.00")));
                        count++;
                    }
                    ctrl.ReportProgress(100, string.Format("Done"));
                    ctrl.DialogResult = DialogResult.OK;
                } catch (Exception) {
                    _dataSet.ClearObject();
                    _dataSet.ClearFrame();
                    _dataSet.DoObjectInfoSetChanged();
                    _dataSet.DoFrameListChanged();
                    throw;
                }
            });

            if (waitForm.ShowDialog() == DialogResult.OK)
            {
                _dataSet.DoObjectInfoSetChanged();
                _dataSet.DoFrameListChanged();
            }
        }
Esempio n. 2
0
 public static void OutputAsPhaseSpace(string inputFile, string outputFile, decimal offset)
 {
     using (TrcReader reader = new TrcReader(inputFile)) {
         using (PhaseSpaceDataWriter writer = new PhaseSpaceDataWriter(outputFile)) {
             decimal ratio = 1 / decimal.Parse(reader.Header.DataRate);
             while (!reader.EndOfStream)
             {
                 TrcFrame trc = reader.ReadFrame();
                 trc = trc.TrimUnnamed(reader.Header);
                 PhaseSpaceFrame motion = FrameConverter.GetMotionFrame(trc);
                 motion.Time = offset + ratio * writer.Frames;
                 writer.WriteFrame(motion);
             }
         }
     }
 }
Esempio n. 3
0
        private void addPhaseSpace(PhaseSpaceDataReader reader)
        {
            WaitForForm waitForm = new WaitForForm(ctrl => {
                try {
                    Dictionary <int, uint> index2id = new Dictionary <int, uint>();
                    int count = 1;
                    int index = 0;
                    PhaseSpaceFrame prevInFrame = new PhaseSpaceFrame();
                    bool first = true;
                    Action <PhaseSpaceFrame, int> import = (inFrame, endIndex) => {
                        for (; index < endIndex && index < _dataSet.FrameLength; index++)
                        {
                            MotionFrame frame = _dataSet.GetFrameByIndex(index);
                            if (frame == null)
                            {
                                continue;
                            }
                            for (int i = 0; i < inFrame.Markers.Length; i++)
                            {
                                uint id;
                                if (!index2id.TryGetValue(i, out id))
                                {
                                    MotionObjectInfo newInfo = new MotionObjectInfo(typeof(PointObject));
                                    newInfo.Name             = PathEx.CombineName("unnamed", (i + 1).ToString());
                                    _dataSet.AddObject(newInfo);
                                    id = index2id[i] = newInfo.Id;
                                }
                                if (inFrame.Markers[i].Condition > 0)
                                {
                                    frame[id] = new PointObject(new Vector3(inFrame.Markers[i].X, inFrame.Markers[i].Y, inFrame.Markers[i].Z));
                                }
                            }
                        }
                    };
                    while (!reader.EndOfStream)
                    {
                        PhaseSpaceFrame inFrame = reader.ReadFrame();
                        int inIndex             = _dataSet.GetFrameIndexAt(inFrame.Time);
                        MotionFrame tmp         = _dataSet.GetFrameByIndex(inIndex);
                        if (tmp == null || tmp.Time == inFrame.Time)
                        {
                            inIndex++;
                        }
                        if (first)
                        {
                            first = false;
                        }
                        else
                        {
                            import(prevInFrame, inIndex);
                        }
                        prevInFrame = inFrame;
                        ctrl.ReportProgress(99 - 990000 / (count + 10000), string.Format("Load Frame Data: {0} ({1} sec)", count, inFrame.Time.ToString("0.00")));
                        count++;
                    }
                    if (!first)
                    {
                        import(prevInFrame, _dataSet.FrameLength);
                    }
                    ctrl.ReportProgress(100, string.Format("Done"));
                    ctrl.DialogResult = DialogResult.OK;
                } catch (Exception) {
                    _dataSet.ClearObject();
                    _dataSet.ClearFrame();
                    _dataSet.DoObjectInfoSetChanged();
                    _dataSet.DoFrameListChanged();
                    throw;
                }
            });

            if (waitForm.ShowDialog() == DialogResult.OK)
            {
                _dataSet.DoObjectInfoSetChanged();
                _dataSet.DoFrameListChanged();
            }
        }