コード例 #1
0
ファイル: Frame.cs プロジェクト: rospoly/F-Formation
 public Frame getCopyFrame()
 {
     return(FactoryFrame.createFrame(IdFrame, new List <Person>(Persons)));
 }
コード例 #2
0
        public List <Frame> readData()
        {
            Thread.CurrentThread.CurrentCulture   = new CultureInfo("en-US");
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");

            List <Frame> frames = new List <Frame>();

            string[] dataLines = null;

            //read lines from data file
            try
            {
                dataLines = File.ReadAllLines(DataFile);
            }
            catch (FileNotFoundException e)
            {
                Console.Write("Errore file data: ");
                Console.WriteLine(e.Message);
            }

            int i = 0; //counter on data lines

            // int j = 0; //counter on gt lines
            while (i < dataLines?.Length)
            {
                //first line has to be a frame header in both files
                Match dataMatch = Regex.Match(dataLines[i], framePattern);
                if (dataMatch.Success)
                {
                    int           id       = Int32.Parse(dataMatch.Groups[1].Value); //frame id
                    int           n_people = Int32.Parse(dataMatch.Groups[2].Value); //people inside frame
                    List <Person> people   = new List <Person>();
                    // Frame newFrame = FactoryFrame.createEmptyFrame(id); //create empty frame

                    for (int k = 1; k <= n_people; k++)
                    {
                        Match p = Regex.Match(dataLines[i + k], personPattern);
                        if (p.Success)
                        {
                            int    pId   = Int32.Parse(p.Groups[1].Value);
                            double x     = Double.Parse(p.Groups[2].Value);
                            double y     = Double.Parse(p.Groups[3].Value);
                            double theta = Double.Parse(p.Groups[4].Value);
                            people.Add(FactoryPerson.createPerson(pId, x, y, theta, k - 1)); //add the person to the list
                        }
                    }

                    //create the frame
                    frames.Add(FactoryFrame.createFrame(id, people));

                    //update i
                    i = i + n_people + 1;
                }
                else
                {
                    i++;
                }
            }
            Debug.WriteLine("Parser: Frames created: " + frames.Count + " frames");
            return(frames);
        }