public static Path3D LoadPathFromFile(string filePath)
        {
            Path3D path = new Path3D();
            const string pointPattern = @"[xyz=:\-\s](\d+(?:(?:\.|,)\d+)*)";
            StreamReader reader = new StreamReader(filePath);
            using (reader)
            {
                string line = reader.ReadLine();

                while (line != null)
                {
                    MatchCollection matches = Regex.Matches(line, pointPattern);
                    if (matches.Count == 3)
                    {
                        double x = double.Parse(matches[0].Groups[1].Value);
                        double y = double.Parse(matches[1].Groups[1].Value);
                        double z = double.Parse(matches[2].Groups[1].Value);

                        Point3D point = new Point3D(x, y, z);
                        path.AddPoint(point);
                    }

                    line = reader.ReadLine();
                }

            }
            return path;
        }
Esempio n. 2
0
        public static void LoadPathFromFile(Path3D path, string file)
        {
            string line;
            string[] input;

            try
            {
                using (StreamReader sr = new StreamReader(file))
                {
                    while((line = sr.ReadLine()) != null)
                    {
                        input = line.Split('|');
                        path.AddPoint(new Point3D(Convert.ToDouble(input[0]),
                            Convert.ToDouble(input[1]),
                            Convert.ToDouble(input[2])));
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            }
        }