Beispiel #1
0
        public static bool CutFramesTrackFile(string inputFile, string outputFile, int cutFrames, bool onTail)
        {
            if (cutFrames < 0)
            {
                return(false);
            }
            bool ret = true;

            using (TrcReader reader = new TrcReader(inputFile)) {
                TrcHeader outHeader = reader.Header;
                outHeader.FilePath   = outputFile;
                outHeader.NumFrames -= cutFrames;
                if (outHeader.NumFrames < 0)
                {
                    outHeader.NumFrames = 0;
                }
                using (TrcWriter writer = new TrcWriter(outHeader, outputFile)) {
                    if (onTail)
                    {
                        for (int i = 0; i < outHeader.NumFrames && !reader.EndOfStream; i++)
                        {
                            writer.WriteFrame(reader.ReadFrame());
                        }
                    }
                    else
                    {
                        for (int i = 0; i < cutFrames && !reader.EndOfStream; i++)
                        {
                            reader.ReadFrame();
                        }
                        while (!reader.EndOfStream)
                        {
                            writer.WriteFrame(reader.ReadFrame());
                        }
                    }
                }
            }
            return(ret);
        }
Beispiel #2
0
        public static bool AddFramesTrackFile(string inputFile, string outputFile, int addFrames, bool onTail)
        {
            if (addFrames < 0)
            {
                return(false);
            }
            bool ret = true;

            // 一行読んだのでもう一回
            using (TrcReader reader = new TrcReader(inputFile)) {
                TrcHeader outHeader = reader.Header;
                outHeader.FilePath   = outputFile;
                outHeader.NumFrames += addFrames;
                using (TrcWriter writer = new TrcWriter(outHeader, outputFile)) {
                    if (onTail)
                    {
                        while (!reader.EndOfStream)
                        {
                            writer.WriteFrame(reader.ReadFrame());
                        }
                    }
                    for (int i = 0; i < addFrames; i++)
                    {
                        writer.WriteFrame(new TrcFrame());
                        if (!onTail)
                        {
                            while (!reader.EndOfStream)
                            {
                                writer.WriteFrame(reader.ReadFrame());
                            }
                        }
                    }
                }
                return(ret);
            }
        }
Beispiel #3
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);
             }
         }
     }
 }
Beispiel #4
0
 public static bool TrimUnnamedFile(string inputFile, string outputFile)
 {
     if (inputFile == null)
     {
         throw new ArgumentNullException("inputFiles is null");
     }
     if (outputFile == null)
     {
         throw new ArgumentNullException("outputFile is null");
     }
     using (TrcReader reader = new TrcReader(inputFile)) {
         TrcHeader outHeader = reader.Header;
         outHeader.FilePath = outputFile;
         using (TrcWriter writer = new TrcWriter(outHeader, outputFile)) {
             while (!reader.EndOfStream)
             {
                 writer.WriteFrame(reader.ReadFrame().TrimUnnamed(reader.Header));
             }
         }
     }
     return(true);
 }
Beispiel #5
0
        /// <summary>
        /// Tracked ASCIIファイルを指定されたフレーム数以下のフレームを含む複数のファイルに分割します。
        /// </summary>
        /// <param title="filename">分割ファイル名</param>
        /// <param title="limit">各出力ファイルのフレーム数の上限</param>
        /// <returns>ファイルを分割する必要があったか</returns>
        /// <exception cref="System.IO.InvalidDataException"></exception>
        /// <exception cref="System.ArgumentException"></exception>
        /// <exception cref="System.IO.IOException"></exception>
        /// <exception cref="System.IO.PathTooLongException"></exception>
        /// <exception cref="System.IO.DirectoryNotFoundException"></exception>
        /// <exception cref="System.IO.FileNotFoundException"></exception>
        public static bool SplitTrackFile(string filename, int limit)
        {
            using (TrcReader reader = new TrcReader(filename)) {
                int split = (int)Math.Ceiling((double)reader.Header.NumFrames / limit);
                if (split <= 1)
                {
                    return(false);
                }

                int restLines = reader.Header.NumFrames;
                int onceLines = (int)Math.Ceiling((double)restLines / split);
                for (int i = 0; i < split && restLines > 0; i++)
                {
                    string    outfile   = GetSplitFilename(filename, i + 1);
                    TrcHeader outHeader = reader.Header;
                    outHeader.FilePath = outfile;
                    if (onceLines > restLines)
                    {
                        onceLines = restLines;
                    }
                    outHeader.NumFrames = onceLines;
                    using (TrcWriter writer = new TrcWriter(outHeader, outfile)) {
                        try {
                            for (int j = 0; j < onceLines; j++)
                            {
                                writer.WriteFrame(reader.ReadFrame());
                            }
                            restLines -= onceLines;
                        } catch (Exception) {
                            restLines = 0;
                        }
                    }
                }
            }
            return(true);
        }
Beispiel #6
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();
            }
        }