Пример #1
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);
             }
         }
     }
 }
Пример #2
0
        public static bool JoinTracks(string[] inputFiles, string outputFile)
        {
            if (inputFiles == null)
            {
                throw new ArgumentNullException("inputFiles is null");
            }
            if (inputFiles.Length == 0)
            {
                throw new ArgumentException("inputFiles has no element");
            }

            TrcReader[] readers = new TrcReader[inputFiles.Length];
            try {
                for (int i = 0; i < inputFiles.Length; i++)
                {
                    readers[i] = new TrcReader(inputFiles[i]);
                }
                int numFrames = readers[0].Header.NumFrames;
                for (int i = 1; i < readers.Length; i++)
                {
                    if (readers[i].Header.NumFrames != numFrames)
                    {
                        throw new InvalidDataException("Frame Length of Track Files mismatch. :" + inputFiles[i]);
                    }
                }
                TrcHeader outHeader = readers[0].Header;
                outHeader.FilePath = outputFile;
                List <string> outMarkers = new List <string>();
                for (int i = 0; i < inputFiles.Length; i++)
                {
                    string prefix = Path.GetFileNameWithoutExtension(inputFiles[i]) + "_";
                    foreach (var marker in readers[i].Header.Markers)
                    {
                        outMarkers.Add(prefix + marker);
                    }
                }
                outHeader.Markers    = outMarkers.ToArray();
                outHeader.NumMarkers = outHeader.Markers.Length;
                using (TrcWriter writer = new TrcWriter(outHeader, outputFile)) {
                    while (true)
                    {
                        // 全部EOFなら終わり
                        if (readers.All(x => { return(x.EndOfStream); }))
                        {
                            break;
                        }
                        // 半端にEOFならエラー
                        if (readers.Any(x => { return(x.EndOfStream); }))
                        {
                            throw new InvalidDataException("Actual Frame Length mismatch");
                        }
                        // 各行の入力
                        TrcFrame[] frames = new TrcFrame[readers.Length];
                        for (int i = 0; i < readers.Length; i++)
                        {
                            frames[i] = readers[i].ReadFrame().TrimUnnamed(readers[i].Header);
                        }
                        // 各行の出力
                        TrcFrame outFrame = new TrcFrame();
                        outFrame.Markers = new TrcMarker?[0];
                        outFrame         = outFrame.JoinAll(frames);
                        writer.WriteFrame(outFrame);
                    }
                }
            } finally {
                foreach (var reader in readers)
                {
                    try {
                        if (reader != null)
                        {
                            reader.Dispose();
                        }
                    } catch (Exception) { }
                }
            }
            return(true);
        }
Пример #3
0
        private void loadEVaRTTrc(TrcReader reader)
        {
            WaitForForm waitForm = new WaitForForm(ctrl => {
                try {
                    _dataSet.ClearFrame();
                    _dataSet.ClearObject();
                    Dictionary <int, uint> index2id = new Dictionary <int, uint>();
                    int length = reader.Header.NumFrames;
                    int count  = 0;
                    for (int i = 0; i < reader.Header.NumMarkers; i++)
                    {
                        MotionObjectInfo newInfo = new MotionObjectInfo(typeof(PointObject));
                        newInfo.Name             = reader.Header.Markers[i];
                        _dataSet.AddObject(newInfo);
                        index2id[i] = newInfo.Id;
                    }

                    while (!reader.EndOfStream)
                    {
                        TrcFrame 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].HasValue)
                            {
                                float x, y, z;
                                if (float.TryParse(inFrame.Markers[i].Value.X, out x) && float.TryParse(inFrame.Markers[i].Value.Y, out y) && float.TryParse(inFrame.Markers[i].Value.Z, out z))
                                {
                                    outFrame[id] = new PointObject(new Vector3(x, y, z));
                                }
                            }
                        }
                        _dataSet.AddFrame(outFrame);
                        if (length < count)
                        {
                            length = count;
                        }
                        if (length <= 0)
                        {
                            length = 1;
                        }
                        ctrl.ReportProgress(100 * count / length, string.Format("Load Frame: {0}/{1} ({2} sec)", count, length, 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();
            }
        }