Пример #1
0
 public void AddSnapshot(Snapshot newSnapshot)
 {
     _snapshots.Add(newSnapshot);
 }
        private Snapshot ParseSnapshot(Pair<int, int> snapshotRange, Topology topology)
        {
            Snapshot snapshot = new Snapshot();
            Console.Write("Parsing snapshot... ");

            int index = _pyon.IndexOf("[\n", snapshotRange.First);
            String snap = _pyon.Substring(index, snapshotRange.Second - snapshotRange.First);
            MatchCollection tokens = Regex.Matches(snap, @"(?<=\[)(([^\[]*?))(?=\])");

            char[] split = new char[]{','};
            foreach (Match token in tokens)
            {
                String[] lines = token.Value.Replace("\r", "").Replace("\n", "").Split(split, StringSplitOptions.RemoveEmptyEntries);
                snapshot.AddPosition(new Vector3(float.Parse(lines[0]), float.Parse(lines[1]), float.Parse(lines[2])));
            }

            /*
            int count = 0;
            while (index < snapshotRange.Second)
            {
                float x = float.Parse(_pyon.Substring(index + 2));//(float)atof(_pyon + index + 2);
                index = _pyon.IndexOf(",\n", index) + 2;
                float y = float.Parse(_pyon.Substring(index));//(float)atof(_pyon + index);
                index = _pyon.IndexOf(",\n", index) + 2;
                float z = float.Parse(_pyon.Substring(index));//(float)atof(_pyon + index);
                index = _pyon.IndexOf("[\n", index);

                snapshot.AddPosition(new Vector3(x, y, z));
                count++;
            }*/

            Console.WriteLine("done.");
            return snapshot;
        }